Skip to content

Commit

Permalink
fix: two same block height on el when double propose
Browse files Browse the repository at this point in the history
  • Loading branch information
quertc committed Nov 20, 2024
1 parent 3454af5 commit bc2354f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/blockchain/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func NewBlockProcessor(config *config.Config, metrics *metrics.BlockMetrics, log
logger: logger,
metrics: metrics,
client: client,
lastFoundELHeight: 0,
}, nil
}

Expand Down Expand Up @@ -72,8 +73,16 @@ func (p *BlockProcessor) ProcessBlock(block *BlockResponse) error {
}

func (p *BlockProcessor) checkExecutionBlocks(clHeight, expectedELHeight int64) error {
startHeight := expectedELHeight - 2
endHeight := expectedELHeight + 2
const defaultOffset = 2 // Default blocks to check before and after expected height

startHeight := expectedELHeight - defaultOffset
endHeight := expectedELHeight + defaultOffset

// If we have a recent block, start from the next one and maintain the same range size
if p.lastFoundELHeight > 0 && expectedELHeight-p.lastFoundELHeight <= 5 {
startHeight = p.lastFoundELHeight + 1
endHeight = startHeight + (defaultOffset * 2)
}

// Check if consensus block was empty
block, err := GetBlock(httpClient.NewClient(), p.config.RPCEndpoint, clHeight)
Expand Down Expand Up @@ -108,6 +117,7 @@ func (p *BlockProcessor) checkExecutionBlocks(clHeight, expectedELHeight int64)
if block.Coinbase().Hex() == p.config.EVMAddress {
foundBlock = true
p.metrics.ExecutionConfirmed.Inc()
p.lastFoundELHeight = height // Save the found block height
p.logger.WriteJSONLog("success", "Found execution block", map[string]interface{}{
"cl_height": clHeight,
"el_height": height,
Expand Down
1 change: 1 addition & 0 deletions internal/blockchain/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type BlockProcessor struct {
metrics *metrics.BlockMetrics
client EthClientInterface
logger *logger.Logger
lastFoundELHeight int64
}
type EVMChainTx struct {
MsgType uint32
Expand Down

0 comments on commit bc2354f

Please sign in to comment.