-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop Celo L1 at a specific block #2322
Changes from all commits
d502b77
a8a7a93
d9e7f7e
44ef6aa
a74427b
1b5b609
a631566
c1fe248
dca542e
f9ad4ee
13b2208
5789b30
b6ca113
ee7ee61
89f77de
4a6efb7
b18991f
f8a3aac
8a28788
c7bea32
7c56668
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -811,6 +811,14 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error { | |
// | ||
// Note, this function assumes that the `mu` mutex is held! | ||
func (bc *BlockChain) writeHeadBlock(block *types.Block) { | ||
// Normally the check at the end of the function will pass first, but if a node is restarted | ||
// with the same l2-migration-block configured after already reaching and stopping on l2-migration-block, | ||
// this check will pass first and log an error. | ||
if bc.Config().IsL2Migration(block.Number()) { | ||
log.Error("Attempt to insert block number >= l2MigrationBlock, stopping block insertion", "block", block.NumberU64(), "hash", block.Hash()) | ||
bc.StopInsert() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should need to call StopInsert here since this check will effectively prevent any additional blocks being added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think StopInsert() is actually preventing some threads from inserting blocks, as removing it below makes the test fail. Specifically, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure why we need changes to It might be more elegant to discard the blocks when the block fetcher receives than rather then preventing the write here. Suggested commit: 90dbc6c I still don't have the full picture, so let me know if I'm missing something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @karlb that looks pretty neat to me, and the tests seem to work, so I'd be in favour of this approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I've pushed a couple of updates to karlb/stop and removed basically everything except the extra flag, the rejection in the validate function and the e2e test. Tests seem to be working, so I think that would be the way to go now. - https://github.com/celo-org/celo-blockchain/pull/2330/files |
||
return | ||
} | ||
// If the block is on a side chain or an unknown one, force other heads onto it too | ||
updateHeads := rawdb.ReadCanonicalHash(bc.db, block.NumberU64()) != block.Hash() | ||
|
||
|
@@ -837,6 +845,13 @@ func (bc *BlockChain) writeHeadBlock(block *types.Block) { | |
} | ||
bc.currentBlock.Store(block) | ||
headBlockGauge.Update(int64(block.NumberU64())) | ||
|
||
nextBlockNum := new(big.Int).Add(block.Number(), big.NewInt(1)) | ||
if bc.Config().IsL2Migration(nextBlockNum) { | ||
log.Info("The next block is the L2 migration block, stopping block insertion", "currentBlock", block.NumberU64(), "hash", block.Hash(), "nextBlock", nextBlockNum.Uint64()) | ||
bc.StopInsert() | ||
return | ||
} | ||
Comment on lines
+848
to
+854
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this, the check up front should be sufficient. Sopping insertion isn't really important unless there is an attempt to insert the next block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I remove this the long test actually starts failing. I was under the impression bc.StopInsert() was essential to call based on what I saw during testing. The function flips an atomic value that is checked at the beginning of numerous functions related to block insertion, including those in HeaderChain like writeHeaders which you asked about above. |
||
} | ||
|
||
// Genesis retrieves the chain's genesis block. | ||
|
@@ -1085,7 +1100,7 @@ func (bc *BlockChain) Stop() { | |
triedb := bc.stateCache.TrieDB() | ||
triedb.SaveCache(bc.cacheConfig.TrieCleanJournal) | ||
} | ||
log.Info("Blockchain stopped") | ||
log.Info("Blockchain stopped", "number", bc.CurrentBlock().NumberU64(), "hash", bc.CurrentBlock().Hash()) | ||
} | ||
|
||
// StopInsert interrupts all insertion methods, causing them to return | ||
|
@@ -1870,6 +1885,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er | |
// If the chain is terminating, stop processing blocks | ||
if bc.insertStopped() { | ||
log.Debug("Abort during block processing") | ||
if bc.Config().IsL2Migration(block.Number()) { | ||
err = errInsertionInterrupted | ||
} | ||
break | ||
} | ||
// If the header is a banned one, straight out abort | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also
core.HeaderChain.writeHeaders
whererawdb.WriteCanonicalHash
is called. I'm just wondering if this could cause any issues. For example we may sync a header later than the stop block.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that by calling bc.StopInsert() we prevent the HeaderChain code from continuing to update the head header.
writeHeaders
checks something called procInterrupt(), which wraps a call to insertStopped(), which is injected when NewHeaderChain() is called. When we call StopInsert(), it makes procInterrupt() return true in writeHeaders before it updates the head header references etc.