Skip to content

Commit

Permalink
fix: do not overwrite correct L1 index on signer startup (ethereum#443)
Browse files Browse the repository at this point in the history
* fix signer worker

* add logs

* bump version

* Fix
  • Loading branch information
Thegaram authored Aug 6, 2023
1 parent 8f43184 commit 69dd39a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
42 changes: 40 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,9 +1186,28 @@ func (bc *BlockChain) writeBlockWithoutState(block *types.Block, td *big.Int) (e
// note: we can insert blocks with header-only ancestors here,
// so queueIndex might not yet be available in DB.
if queueIndex != nil {
numProcessed := uint64(block.NumL1MessagesProcessed(*queueIndex))
// do not overwrite the index written by the miner worker
if index := rawdb.ReadFirstQueueIndexNotInL2Block(bc.db, block.Hash()); index == nil {
rawdb.WriteFirstQueueIndexNotInL2Block(batch, block.Hash(), *queueIndex+uint64(block.NumL1MessagesProcessed(*queueIndex)))
newIndex := *queueIndex + numProcessed
log.Trace(
"Blockchain.writeBlockWithoutState WriteFirstQueueIndexNotInL2Block",
"number", block.Number(),
"hash", block.Hash().String(),
"queueIndex", *queueIndex,
"numProcessed", numProcessed,
"newIndex", newIndex,
)
rawdb.WriteFirstQueueIndexNotInL2Block(batch, block.Hash(), newIndex)
} else {
log.Trace(
"Blockchain.writeBlockWithoutState WriteFirstQueueIndexNotInL2Block: not overwriting existing index",
"number", block.Number(),
"hash", block.Hash().String(),
"queueIndex", *queueIndex,
"numProcessed", numProcessed,
"index", *index,
)
}
}

Expand Down Expand Up @@ -1253,9 +1272,28 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
// so the parent will always be inserted first.
log.Crit("Queue index in DB is nil", "parent", block.ParentHash(), "hash", block.Hash())
}
numProcessed := uint64(block.NumL1MessagesProcessed(*queueIndex))
// do not overwrite the index written by the miner worker
if index := rawdb.ReadFirstQueueIndexNotInL2Block(bc.db, block.Hash()); index == nil {
rawdb.WriteFirstQueueIndexNotInL2Block(blockBatch, block.Hash(), *queueIndex+uint64(block.NumL1MessagesProcessed(*queueIndex)))
newIndex := *queueIndex + numProcessed
log.Trace(
"Blockchain.writeBlockWithState WriteFirstQueueIndexNotInL2Block",
"number", block.Number(),
"hash", block.Hash().String(),
"queueIndex", *queueIndex,
"numProcessed", numProcessed,
"newIndex", newIndex,
)
rawdb.WriteFirstQueueIndexNotInL2Block(blockBatch, block.Hash(), newIndex)
} else {
log.Trace(
"Blockchain.writeBlockWithState WriteFirstQueueIndexNotInL2Block: not overwriting existing index",
"number", block.Number(),
"hash", block.Hash().String(),
"queueIndex", *queueIndex,
"numProcessed", numProcessed,
"index", *index,
)
}

if err := blockBatch.Write(); err != nil {
Expand Down
28 changes: 23 additions & 5 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,29 @@ func (w *worker) resultLoop() {
}
logs = append(logs, receipt.Logs...)
}
// Store first L1 queue index not processed by this block.
// Note: This accounts for both included and skipped messages. This
// way, if a block only skips messages, we won't reprocess the same
// messages from the next block.
rawdb.WriteFirstQueueIndexNotInL2Block(w.eth.ChainDb(), hash, task.nextL1MsgIndex)
// It's possible that we've stored L1 queue index for this block previously,
// in this case do not overwrite it.
if index := rawdb.ReadFirstQueueIndexNotInL2Block(w.eth.ChainDb(), hash); index == nil {
// Store first L1 queue index not processed by this block.
// Note: This accounts for both included and skipped messages. This
// way, if a block only skips messages, we won't reprocess the same
// messages from the next block.
log.Trace(
"Worker WriteFirstQueueIndexNotInL2Block",
"number", block.Number(),
"hash", hash.String(),
"task.nextL1MsgIndex", task.nextL1MsgIndex,
)
rawdb.WriteFirstQueueIndexNotInL2Block(w.eth.ChainDb(), hash, task.nextL1MsgIndex)
} else {
log.Trace(
"Worker WriteFirstQueueIndexNotInL2Block: not overwriting existing index",
"number", block.Number(),
"hash", hash.String(),
"index", *index,
"task.nextL1MsgIndex", task.nextL1MsgIndex,
)
}
// Store circuit row consumption.
log.Trace(
"Worker write block row consumption",
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
VersionMajor = 4 // Major version component of the current release
VersionMinor = 3 // Minor version component of the current release
VersionPatch = 23 // Patch version component of the current release
VersionPatch = 24 // Patch version component of the current release
VersionMeta = "sepolia" // Version metadata to append to the version string
)

Expand Down

0 comments on commit 69dd39a

Please sign in to comment.