Refactor storing Ethereum block specific data

This commit is contained in:
Martin Boehm 2022-01-28 10:06:30 +01:00 committed by Martin
parent d93a58c423
commit ec510811cd
3 changed files with 27 additions and 18 deletions

View File

@ -307,26 +307,23 @@ func (b *BulkConnect) connectBlockEthereumType(block *bchain.Block, storeBlockTx
defer wb.Destroy() defer wb.Destroy()
bac := b.bulkAddressesCount bac := b.bulkAddressesCount
if sa || b.bulkAddressesCount > maxBulkAddresses { if sa || b.bulkAddressesCount > maxBulkAddresses {
if err := b.storeBulkAddresses(wb); err != nil { if err = b.storeBulkAddresses(wb); err != nil {
return err return err
} }
} }
if err := b.d.storeInternalDataEthereumType(wb, b.ethBlockTxs); err != nil { if err = b.d.storeInternalDataEthereumType(wb, b.ethBlockTxs); err != nil {
return err return err
} }
b.ethBlockTxs = b.ethBlockTxs[:0] b.ethBlockTxs = b.ethBlockTxs[:0]
blockSpecificData, _ := block.CoinSpecificData.(*bchain.EthereumBlockSpecificData) if err = b.d.storeBlockSpecificDataEthereumType(wb, block); err != nil {
if blockSpecificData != nil && blockSpecificData.InternalDataError != "" { return err
if err := b.d.storeBlockInternalDataErrorEthereumType(wb, block, blockSpecificData.InternalDataError); err != nil {
return err
}
} }
if storeBlockTxs { if storeBlockTxs {
if err := b.d.storeAndCleanupBlockTxsEthereumType(wb, block, blockTxs); err != nil { if err = b.d.storeAndCleanupBlockTxsEthereumType(wb, block, blockTxs); err != nil {
return err return err
} }
} }
if err := b.d.db.Write(b.d.wo, wb); err != nil { if err = b.d.db.Write(b.d.wo, wb); err != nil {
return err return err
} }
if bac > b.bulkAddressesCount { if bac > b.bulkAddressesCount {
@ -338,7 +335,7 @@ func (b *BulkConnect) connectBlockEthereumType(block *bchain.Block, storeBlockTx
if blockSpecificData != nil && blockSpecificData.InternalDataError != "" { if blockSpecificData != nil && blockSpecificData.InternalDataError != "" {
wb := gorocksdb.NewWriteBatch() wb := gorocksdb.NewWriteBatch()
defer wb.Destroy() defer wb.Destroy()
if err := b.d.storeBlockInternalDataErrorEthereumType(wb, block, blockSpecificData.InternalDataError); err != nil { if err = b.d.storeBlockSpecificDataEthereumType(wb, block); err != nil {
return err return err
} }
} }

View File

@ -484,11 +484,8 @@ func (d *RocksDB) ConnectBlock(block *bchain.Block) error {
if err := d.storeInternalDataEthereumType(wb, blockTxs); err != nil { if err := d.storeInternalDataEthereumType(wb, blockTxs); err != nil {
return err return err
} }
blockSpecificData, _ := block.CoinSpecificData.(*bchain.EthereumBlockSpecificData) if err = d.storeBlockSpecificDataEthereumType(wb, block); err != nil {
if blockSpecificData != nil && blockSpecificData.InternalDataError != "" { return err
if err := d.storeBlockInternalDataErrorEthereumType(wb, block, blockSpecificData.InternalDataError); err != nil {
return err
}
} }
if err := d.storeAndCleanupBlockTxsEthereumType(wb, block, blockTxs); err != nil { if err := d.storeAndCleanupBlockTxsEthereumType(wb, block, blockTxs); err != nil {
return err return err

View File

@ -215,8 +215,8 @@ func addToContract(c *AddrContract, contractIndex int, index int32, contract bch
aggregate = func(s, v *big.Int) { aggregate = func(s, v *big.Int) {
s.Sub(s, v) s.Sub(s, v)
if s.Sign() < 0 { if s.Sign() < 0 {
glog.Warningf("rocksdb: addToContracts: contract %s, from %s, negative aggregate", transfer.Contract, transfer.From) // glog.Warningf("rocksdb: addToContracts: contract %s, from %s, negative aggregate", transfer.Contract, transfer.From)
s.SetInt64(0) s.SetUint64(0)
} }
} }
} else { } else {
@ -254,8 +254,12 @@ func addToContract(c *AddrContract, contractIndex int, index int32, contract bch
} }
} }
// if not found and transfer to, add to the list // if not found and transfer to, add to the list
// it is necessary to add a copy of the value so that subsequent calls to addToContract do not change the transfer value
if index >= 0 { if index >= 0 {
c.IdValues = append(c.IdValues, t) c.IdValues = append(c.IdValues, bchain.TokenTransferIdValue{
Id: t.Id,
Value: *new(big.Int).Set(&t.Value),
})
} }
nextTransfer: nextTransfer:
} }
@ -665,6 +669,17 @@ func (d *RocksDB) storeBlockInternalDataErrorEthereumType(wb *gorocksdb.WriteBat
return nil return nil
} }
func (d *RocksDB) storeBlockSpecificDataEthereumType(wb *gorocksdb.WriteBatch, block *bchain.Block) error {
blockSpecificData, _ := block.CoinSpecificData.(*bchain.EthereumBlockSpecificData)
if blockSpecificData != nil && blockSpecificData.InternalDataError != "" {
glog.Info("storeBlockSpecificDataEthereumType ", block.Height, ": ", blockSpecificData.InternalDataError)
if err := d.storeBlockInternalDataErrorEthereumType(wb, block, blockSpecificData.InternalDataError); err != nil {
return err
}
}
return nil
}
// unpackBlockTx unpacks ethBlockTx from buf, starting at position pos // unpackBlockTx unpacks ethBlockTx from buf, starting at position pos
// the position is updated as the data is unpacked and returned to the caller // the position is updated as the data is unpacked and returned to the caller
func unpackBlockTx(buf []byte, pos int) (*ethBlockTx, int, error) { func unpackBlockTx(buf []byte, pos int) (*ethBlockTx, int, error) {