Skip to content

Commit

Permalink
jsonrpc: fix state sync event txn for bor with astrid (#13416)
Browse files Browse the repository at this point in the history
found while running #13415
few apis are missing calls to the new flow with the bridge reader when
run with astrid hence not returning bor state sync txn
  • Loading branch information
taratorio authored Jan 14, 2025
1 parent 9eb0394 commit 85844e6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
9 changes: 5 additions & 4 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import (
"github.com/erigontech/erigon/ethdb/prune"
"github.com/erigontech/erigon/ethstats"
"github.com/erigontech/erigon/node"
"github.com/erigontech/erigon/node/nodecfg"
"github.com/erigontech/erigon/p2p"
"github.com/erigontech/erigon/p2p/enode"
"github.com/erigontech/erigon/p2p/sentry"
Expand Down Expand Up @@ -334,7 +335,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger

// Check if we have an already initialized chain and fall back to
// that if so. Otherwise we need to generate a new genesis spec.
blockReader, blockWriter, allSnapshots, allBorSnapshots, bridgeStore, heimdallStore, agg, err := setUpBlockReader(ctx, rawChainDB, config.Dirs, config, chainConfig, logger, segmentsBuildLimiter)
blockReader, blockWriter, allSnapshots, allBorSnapshots, bridgeStore, heimdallStore, agg, err := setUpBlockReader(ctx, rawChainDB, config.Dirs, config, chainConfig, stack.Config(), logger, segmentsBuildLimiter)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1423,7 +1424,7 @@ func (s *Ethereum) setUpSnapDownloader(ctx context.Context, downloaderCfg *downl
return err
}

func setUpBlockReader(ctx context.Context, db kv.RwDB, dirs datadir.Dirs, snConfig *ethconfig.Config, chainConfig *chain.Config, logger log.Logger, blockSnapBuildSema *semaphore.Weighted) (*freezeblocks.BlockReader, *blockio.BlockWriter, *freezeblocks.RoSnapshots, *heimdall.RoSnapshots, bridge.Store, heimdall.Store, *libstate.Aggregator, error) {
func setUpBlockReader(ctx context.Context, db kv.RwDB, dirs datadir.Dirs, snConfig *ethconfig.Config, chainConfig *chain.Config, nodeConfig *nodecfg.Config, logger log.Logger, blockSnapBuildSema *semaphore.Weighted) (*freezeblocks.BlockReader, *blockio.BlockWriter, *freezeblocks.RoSnapshots, *heimdall.RoSnapshots, bridge.Store, heimdall.Store, *libstate.Aggregator, error) {
var minFrozenBlock uint64

if frozenLimit := snConfig.Sync.FrozenBlockLimit; frozenLimit != 0 {
Expand All @@ -1442,8 +1443,8 @@ func setUpBlockReader(ctx context.Context, db kv.RwDB, dirs datadir.Dirs, snConf
allBorSnapshots = heimdall.NewRoSnapshots(snConfig.Snapshot, dirs.Snap, minFrozenBlock, logger)

if snConfig.PolygonSync {
bridgeStore = bridge.NewSnapshotStore(bridge.NewMdbxStore(dirs.DataDir, logger, false, 0), allBorSnapshots, chainConfig.Bor)
heimdallStore = heimdall.NewSnapshotStore(heimdall.NewMdbxStore(logger, dirs.DataDir, 0), allBorSnapshots)
bridgeStore = bridge.NewSnapshotStore(bridge.NewMdbxStore(dirs.DataDir, logger, false, int64(nodeConfig.Http.DBReadConcurrency)), allBorSnapshots, chainConfig.Bor)
heimdallStore = heimdall.NewSnapshotStore(heimdall.NewMdbxStore(logger, dirs.DataDir, int64(nodeConfig.Http.DBReadConcurrency)), allBorSnapshots)
} else {
bridgeStore = bridge.NewSnapshotStore(bridge.NewDbStore(db), allBorSnapshots, chainConfig.Bor)
heimdallStore = heimdall.NewSnapshotStore(heimdall.NewDbStore(db), allBorSnapshots)
Expand Down
36 changes: 30 additions & 6 deletions turbo/jsonrpc/eth_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,21 @@ func (api *APIImpl) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber
var borTx types.Transaction
var borTxHash common.Hash
if chainConfig.Bor != nil {
borTx = rawdb.ReadBorTransactionForBlock(tx, b.NumberU64())
if borTx != nil {
borTxHash = bortypes.ComputeBorTxHash(b.NumberU64(), b.Hash())
if api.useBridgeReader {
possibleBorTxnHash := bortypes.ComputeBorTxHash(b.NumberU64(), b.Hash())
_, ok, err := api.bridgeReader.EventTxnLookup(ctx, possibleBorTxnHash)
if err != nil {
return nil, err
}
if ok {
borTx = bortypes.NewBorTransaction()
borTxHash = possibleBorTxnHash
}
} else {
borTx = rawdb.ReadBorTransactionForBlock(tx, b.NumberU64())
if borTx != nil {
borTxHash = bortypes.ComputeBorTxHash(b.NumberU64(), b.Hash())
}
}
}

Expand Down Expand Up @@ -318,9 +330,21 @@ func (api *APIImpl) GetBlockByHash(ctx context.Context, numberOrHash rpc.BlockNu
var borTx types.Transaction
var borTxHash common.Hash
if chainConfig.Bor != nil {
borTx = rawdb.ReadBorTransactionForBlock(tx, number)
if borTx != nil {
borTxHash = bortypes.ComputeBorTxHash(number, block.Hash())
if api.useBridgeReader {
possibleBorTxnHash := bortypes.ComputeBorTxHash(block.NumberU64(), block.Hash())
_, ok, err := api.bridgeReader.EventTxnLookup(ctx, possibleBorTxnHash)
if err != nil {
return nil, err
}
if ok {
borTx = bortypes.NewBorTransaction()
borTxHash = possibleBorTxnHash
}
} else {
borTx = rawdb.ReadBorTransactionForBlock(tx, number)
if borTx != nil {
borTxHash = bortypes.ComputeBorTxHash(number, block.Hash())
}
}
}

Expand Down
28 changes: 26 additions & 2 deletions turbo/jsonrpc/eth_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,19 @@ func (api *APIImpl) GetTransactionByBlockHashAndIndex(ctx context.Context, block
if chainConfig.Bor == nil {
return nil, nil // not error
}
borTx := rawdb.ReadBorTransactionForBlock(tx, block.NumberU64())
var borTx types2.Transaction
if api.useBridgeReader {
possibleBorTxnHash := bortypes.ComputeBorTxHash(block.NumberU64(), block.Hash())
_, ok, err := api.bridgeReader.EventTxnLookup(ctx, possibleBorTxnHash)
if err != nil {
return nil, err
}
if ok {
borTx = bortypes.NewBorTransaction()
}
} else {
borTx = rawdb.ReadBorTransactionForBlock(tx, block.NumberU64())
}
if borTx == nil {
return nil, nil // not error
}
Expand Down Expand Up @@ -289,7 +301,19 @@ func (api *APIImpl) GetTransactionByBlockNumberAndIndex(ctx context.Context, blo
if chainConfig.Bor == nil {
return nil, nil // not error
}
borTx := rawdb.ReadBorTransactionForBlock(tx, blockNum)
var borTx types2.Transaction
if api.useBridgeReader {
possibleBorTxnHash := bortypes.ComputeBorTxHash(blockNum, hash)
_, ok, err := api.bridgeReader.EventTxnLookup(ctx, possibleBorTxnHash)
if err != nil {
return nil, err
}
if ok {
borTx = bortypes.NewBorTransaction()
}
} else {
borTx = rawdb.ReadBorTransactionForBlock(tx, blockNum)
}
if borTx == nil {
return nil, nil
}
Expand Down

0 comments on commit 85844e6

Please sign in to comment.