fix: do not overwrite correct L1 index on signer startup (#443)

* fix signer worker

* add logs

* bump version

* Fix
This commit is contained in:
Péter Garamvölgyi 2023-08-06 14:22:02 +02:00 committed by GitHub
parent 8f431845c3
commit 69dd39afba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 8 deletions

View file

@ -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, // note: we can insert blocks with header-only ancestors here,
// so queueIndex might not yet be available in DB. // so queueIndex might not yet be available in DB.
if queueIndex != nil { if queueIndex != nil {
numProcessed := uint64(block.NumL1MessagesProcessed(*queueIndex))
// do not overwrite the index written by the miner worker // do not overwrite the index written by the miner worker
if index := rawdb.ReadFirstQueueIndexNotInL2Block(bc.db, block.Hash()); index == nil { 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,
)
} }
} }
@ -1253,9 +1272,28 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
// so the parent will always be inserted first. // so the parent will always be inserted first.
log.Crit("Queue index in DB is nil", "parent", block.ParentHash(), "hash", block.Hash()) 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 // do not overwrite the index written by the miner worker
if index := rawdb.ReadFirstQueueIndexNotInL2Block(bc.db, block.Hash()); index == nil { 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 { if err := blockBatch.Write(); err != nil {

View file

@ -698,11 +698,29 @@ func (w *worker) resultLoop() {
} }
logs = append(logs, receipt.Logs...) logs = append(logs, receipt.Logs...)
} }
// 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. // Store first L1 queue index not processed by this block.
// Note: This accounts for both included and skipped messages. This // Note: This accounts for both included and skipped messages. This
// way, if a block only skips messages, we won't reprocess the same // way, if a block only skips messages, we won't reprocess the same
// messages from the next block. // 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) 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. // Store circuit row consumption.
log.Trace( log.Trace(
"Worker write block row consumption", "Worker write block row consumption",

View file

@ -24,7 +24,7 @@ import (
const ( const (
VersionMajor = 4 // Major version component of the current release VersionMajor = 4 // Major version component of the current release
VersionMinor = 3 // Minor 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 VersionMeta = "sepolia" // Version metadata to append to the version string
) )