Refactor storing Ethereum block specific data
This commit is contained in:
parent
d93a58c423
commit
ec510811cd
@ -307,26 +307,23 @@ func (b *BulkConnect) connectBlockEthereumType(block *bchain.Block, storeBlockTx
|
||||
defer wb.Destroy()
|
||||
bac := b.bulkAddressesCount
|
||||
if sa || b.bulkAddressesCount > maxBulkAddresses {
|
||||
if err := b.storeBulkAddresses(wb); err != nil {
|
||||
if err = b.storeBulkAddresses(wb); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := b.d.storeInternalDataEthereumType(wb, b.ethBlockTxs); err != nil {
|
||||
if err = b.d.storeInternalDataEthereumType(wb, b.ethBlockTxs); err != nil {
|
||||
return err
|
||||
}
|
||||
b.ethBlockTxs = b.ethBlockTxs[:0]
|
||||
blockSpecificData, _ := block.CoinSpecificData.(*bchain.EthereumBlockSpecificData)
|
||||
if blockSpecificData != nil && blockSpecificData.InternalDataError != "" {
|
||||
if err := b.d.storeBlockInternalDataErrorEthereumType(wb, block, blockSpecificData.InternalDataError); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = b.d.storeBlockSpecificDataEthereumType(wb, block); err != nil {
|
||||
return err
|
||||
}
|
||||
if storeBlockTxs {
|
||||
if err := b.d.storeAndCleanupBlockTxsEthereumType(wb, block, blockTxs); err != nil {
|
||||
if err = b.d.storeAndCleanupBlockTxsEthereumType(wb, block, blockTxs); err != nil {
|
||||
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
|
||||
}
|
||||
if bac > b.bulkAddressesCount {
|
||||
@ -338,7 +335,7 @@ func (b *BulkConnect) connectBlockEthereumType(block *bchain.Block, storeBlockTx
|
||||
if blockSpecificData != nil && blockSpecificData.InternalDataError != "" {
|
||||
wb := gorocksdb.NewWriteBatch()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -484,11 +484,8 @@ func (d *RocksDB) ConnectBlock(block *bchain.Block) error {
|
||||
if err := d.storeInternalDataEthereumType(wb, blockTxs); err != nil {
|
||||
return err
|
||||
}
|
||||
blockSpecificData, _ := block.CoinSpecificData.(*bchain.EthereumBlockSpecificData)
|
||||
if blockSpecificData != nil && blockSpecificData.InternalDataError != "" {
|
||||
if err := d.storeBlockInternalDataErrorEthereumType(wb, block, blockSpecificData.InternalDataError); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = d.storeBlockSpecificDataEthereumType(wb, block); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.storeAndCleanupBlockTxsEthereumType(wb, block, blockTxs); err != nil {
|
||||
return err
|
||||
|
||||
@ -215,8 +215,8 @@ func addToContract(c *AddrContract, contractIndex int, index int32, contract bch
|
||||
aggregate = func(s, v *big.Int) {
|
||||
s.Sub(s, v)
|
||||
if s.Sign() < 0 {
|
||||
glog.Warningf("rocksdb: addToContracts: contract %s, from %s, negative aggregate", transfer.Contract, transfer.From)
|
||||
s.SetInt64(0)
|
||||
// glog.Warningf("rocksdb: addToContracts: contract %s, from %s, negative aggregate", transfer.Contract, transfer.From)
|
||||
s.SetUint64(0)
|
||||
}
|
||||
}
|
||||
} 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
|
||||
// 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 {
|
||||
c.IdValues = append(c.IdValues, t)
|
||||
c.IdValues = append(c.IdValues, bchain.TokenTransferIdValue{
|
||||
Id: t.Id,
|
||||
Value: *new(big.Int).Set(&t.Value),
|
||||
})
|
||||
}
|
||||
nextTransfer:
|
||||
}
|
||||
@ -665,6 +669,17 @@ func (d *RocksDB) storeBlockInternalDataErrorEthereumType(wb *gorocksdb.WriteBat
|
||||
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
|
||||
// the position is updated as the data is unpacked and returned to the caller
|
||||
func unpackBlockTx(buf []byte, pos int) (*ethBlockTx, int, error) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user