Commit 536a00a9 authored by Hamdi Allam's avatar Hamdi Allam

nit

parent 51a287b3
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
log "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
const ( const (
......
...@@ -132,15 +132,16 @@ func (b *BridgeProcessor) Start(ctx context.Context) error { ...@@ -132,15 +132,16 @@ func (b *BridgeProcessor) Start(ctx context.Context) error {
err = b.db.Transaction(func(tx *database.DB) error { err = b.db.Transaction(func(tx *database.DB) error {
// In the event where we have a large number of un-observed blocks, group the block range // In the event where we have a large number of un-observed blocks, group the block range
// on the order of 10k blocks at a time. If this turns out to be a bottleneck, we can // on the order of 10k blocks at a time. If this turns out to be a bottleneck, we can
// parallelize these operations for significant improvements as well // parallelize these operations
maxBlockRange := uint64(10_000)
l1BridgeLog := b.log.New("bridge", "l1") l1BridgeLog := b.log.New("bridge", "l1")
l2BridgeLog := b.log.New("bridge", "l2") l2BridgeLog := b.log.New("bridge", "l2")
// FOR OP-MAINNET, OP-GOERLI ONLY! Specially handle the existence of pre-bedrock blocks // FOR OP-MAINNET, OP-GOERLI ONLY! Specially handle the existence of pre-bedrock blocks
// - Since this processor indexes bridge events on available epochs between L1 & L2, we
// can detect when we've switched into bedrock state by comparing the l1 bedrock starting
// height to the range of L1 blocks we are indexing.
if l1BedrockStartingHeight.Cmp(fromL1Height) > 0 { if l1BedrockStartingHeight.Cmp(fromL1Height) > 0 {
l1BridgeLog := l1BridgeLog.New("mode", "legacy")
l2BridgeLog := l2BridgeLog.New("mode", "legacy")
legacyFromL1Height, legacyToL1Height := fromL1Height, toL1Height legacyFromL1Height, legacyToL1Height := fromL1Height, toL1Height
legacyFromL2Height, legacyToL2Height := fromL2Height, toL2Height legacyFromL2Height, legacyToL2Height := fromL2Height, toL2Height
if l1BedrockStartingHeight.Cmp(toL1Height) <= 0 { if l1BedrockStartingHeight.Cmp(toL1Height) <= 0 {
...@@ -148,12 +149,9 @@ func (b *BridgeProcessor) Start(ctx context.Context) error { ...@@ -148,12 +149,9 @@ func (b *BridgeProcessor) Start(ctx context.Context) error {
legacyToL2Height = new(big.Int).Sub(l2BedrockStartingHeight, big.NewInt(1)) legacyToL2Height = new(big.Int).Sub(l2BedrockStartingHeight, big.NewInt(1))
} }
l1BridgeLog := l1BridgeLog.New("mode", "legacy") // First, find all possible initiated bridge events
l2BridgeLog := l2BridgeLog.New("mode", "legacy") l1BlockGroups := bigint.Grouped(legacyFromL1Height, legacyToL1Height, maxBlockRange)
l1BlockGroups := bigint.Grouped(legacyFromL1Height, legacyToL1Height, 10_000) l2BlockGroups := bigint.Grouped(legacyFromL2Height, legacyToL2Height, maxBlockRange)
l2BlockGroups := bigint.Grouped(legacyFromL2Height, legacyToL2Height, 10_000)
// Now that all initiated events have been indexed, it is ensured that all finalization can find their counterpart.
for _, group := range l1BlockGroups { for _, group := range l1BlockGroups {
log := l1BridgeLog.New("from_l1_block_number", group.Start, "to_l1_block_number", group.End) log := l1BridgeLog.New("from_l1_block_number", group.Start, "to_l1_block_number", group.End)
log.Info("scanning for initiated bridge events") log.Info("scanning for initiated bridge events")
...@@ -195,10 +193,9 @@ func (b *BridgeProcessor) Start(ctx context.Context) error { ...@@ -195,10 +193,9 @@ func (b *BridgeProcessor) Start(ctx context.Context) error {
fromL2Height = l2BedrockStartingHeight fromL2Height = l2BedrockStartingHeight
} }
l1BlockGroups := bigint.Grouped(fromL1Height, toL1Height, 10_000)
l2BlockGroups := bigint.Grouped(fromL2Height, toL2Height, 10_000)
// First, find all possible initiated bridge events // First, find all possible initiated bridge events
l1BlockGroups := bigint.Grouped(fromL1Height, toL1Height, maxBlockRange)
l2BlockGroups := bigint.Grouped(fromL2Height, toL2Height, maxBlockRange)
for _, group := range l1BlockGroups { for _, group := range l1BlockGroups {
log := l1BridgeLog.New("from_block_number", group.Start, "to_block_number", group.End) log := l1BridgeLog.New("from_block_number", group.Start, "to_block_number", group.End)
log.Info("scanning for initiated bridge events") log.Info("scanning for initiated bridge events")
......
...@@ -222,7 +222,7 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, fromH ...@@ -222,7 +222,7 @@ func LegacyL2ProcessInitiatedBridgeEvents(log log.Logger, db *database.DB, fromH
// Legacy Bridge Finalization // Legacy Bridge Finalization
// LegacyL1ProcessFinalizedBridgeEvents will query for bridge events within the specified block range // LegacyL1ProcessFinalizedBridgeEvents will query for bridge events within the specified block range
// acording to the pre-bedrock protocol. This follows: // according to the pre-bedrock protocol. This follows:
// 1. L1CrossDomainMessenger // 1. L1CrossDomainMessenger
// 2. L1StandardBridge // 2. L1StandardBridge
func LegacyL1ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, l1Client node.EthClient, chainConfig config.ChainConfig, fromHeight *big.Int, toHeight *big.Int) error { func LegacyL1ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, l1Client node.EthClient, chainConfig config.ChainConfig, fromHeight *big.Int, toHeight *big.Int) error {
...@@ -302,7 +302,7 @@ func LegacyL1ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, l1Cli ...@@ -302,7 +302,7 @@ func LegacyL1ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, l1Cli
} }
// LegacyL2ProcessFinalizedBridgeEvents will query for bridge events within the specified block range // LegacyL2ProcessFinalizedBridgeEvents will query for bridge events within the specified block range
// acording to the pre-bedrock protocol. This follows: // according to the pre-bedrock protocol. This follows:
// 1. L2CrossDomainMessenger // 1. L2CrossDomainMessenger
// 2. L2StandardBridge // 2. L2StandardBridge
func LegacyL2ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, fromHeight *big.Int, toHeight *big.Int) error { func LegacyL2ProcessFinalizedBridgeEvents(log log.Logger, db *database.DB, fromHeight *big.Int, toHeight *big.Int) error {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment