-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat: Add preFinalizeBlockHook to allow VE persistence #16898
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ae4394e
feat: Add preFinalizeBlockHook to allow VE persistence
facundomedica d303a53
cl++
facundomedica a254bf7
remove GetFinalizeBlockStateCtx
facundomedica bc261cd
add test
facundomedica 2f94387
lint
facundomedica eb692fb
add docs
facundomedica 72a98e6
Merge branch 'main' into facu/fix-ve-persistence
facundomedica 9a77d65
Merge branch 'main' into facu/fix-ve-persistence
alexanderbez 9eadffc
Merge branch 'main' into facu/fix-ve-persistence
facundomedica 22eb4f8
lint and cl
facundomedica 2426d96
Merge branch 'main' into facu/fix-ve-persistence
alexanderbez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,13 +45,14 @@ func (app *BaseApp) InitChain(req *abci.RequestInitChain) (*abci.ResponseInitCha | |
// On a new chain, we consider the init chain block height as 0, even though | ||
// req.InitialHeight is 1 by default. | ||
initHeader := cmtproto.Header{ChainID: req.ChainId, Time: req.Time} | ||
app.initialHeight = req.InitialHeight | ||
|
||
app.logger.Info("InitChain", "initialHeight", req.InitialHeight, "chainID", req.ChainId) | ||
|
||
// Set the initial height, which will be used to determine if we are proposing | ||
// or processing the first block or not. | ||
app.initialHeight = req.InitialHeight | ||
if app.initialHeight == 0 { // If initial height is 0, set it to 1 | ||
app.initialHeight = 1 | ||
} | ||
|
||
// if req.InitialHeight is > 1, then we set the initial version on all stores | ||
if req.InitialHeight > 1 { | ||
|
@@ -675,53 +676,50 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.Respons | |
AppHash: app.LastCommitID().Hash, | ||
} | ||
|
||
// Initialize the FinalizeBlock state. If this is the first block, it should | ||
// already be initialized in InitChain. Otherwise app.finalizeBlockState will be | ||
// nil, since it is reset on Commit. | ||
// finalizeBlockState should be set on InitChain or ProcessProposal. If it is | ||
// nil, it means we are replaying this block and we need to set the state here | ||
// given that during block replay ProcessProposal is not executed by CometBFT. | ||
if app.finalizeBlockState == nil { | ||
app.setState(execModeFinalize, header) | ||
} else { | ||
// In the first block, app.finalizeBlockState.ctx will already be initialized | ||
// by InitChain. Context is now updated with Header information. | ||
app.finalizeBlockState.ctx = app.finalizeBlockState.ctx. | ||
WithBlockHeader(header). | ||
WithBlockHeight(req.Height). | ||
WithHeaderInfo(coreheader.Info{ | ||
ChainID: app.chainID, | ||
Height: req.Height, | ||
Time: req.Time, | ||
Hash: req.Hash, | ||
AppHash: app.LastCommitID().Hash, | ||
}) | ||
} | ||
|
||
gasMeter := app.getBlockGasMeter(app.finalizeBlockState.ctx) | ||
|
||
// Context is now updated with Header information. | ||
app.finalizeBlockState.ctx = app.finalizeBlockState.ctx. | ||
WithBlockGasMeter(gasMeter). | ||
WithBlockHeader(header). | ||
WithHeaderHash(req.Hash). | ||
WithConsensusParams(app.GetConsensusParams(app.finalizeBlockState.ctx)). | ||
WithVoteInfos(req.DecidedLastCommit.Votes). | ||
WithExecMode(sdk.ExecModeFinalize). | ||
WithHeaderInfo(coreheader.Info{ | ||
ChainID: app.chainID, | ||
Height: req.Height, | ||
Time: req.Time, | ||
Hash: req.Hash, | ||
AppHash: app.LastCommitID().Hash, | ||
}).WithCometInfo(cometInfo{ | ||
Misbehavior: req.Misbehavior, | ||
ValidatorsHash: req.NextValidatorsHash, | ||
ProposerAddress: req.ProposerAddress, | ||
LastCommit: req.DecidedLastCommit, | ||
}) | ||
}). | ||
WithConsensusParams(app.GetConsensusParams(app.finalizeBlockState.ctx)). | ||
WithVoteInfos(req.DecidedLastCommit.Votes). | ||
WithExecMode(sdk.ExecModeFinalize). | ||
WithCometInfo(cometInfo{ | ||
Misbehavior: req.Misbehavior, | ||
ValidatorsHash: req.NextValidatorsHash, | ||
ProposerAddress: req.ProposerAddress, | ||
LastCommit: req.DecidedLastCommit, | ||
}) | ||
|
||
// GasMeter must be set after we get a context with updated consensus params. | ||
gasMeter := app.getBlockGasMeter(app.finalizeBlockState.ctx) | ||
app.finalizeBlockState.ctx = app.finalizeBlockState.ctx.WithBlockGasMeter(gasMeter) | ||
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. The lines above are to simplify context setting. The stuff done in the |
||
|
||
if app.checkState != nil { | ||
app.checkState.ctx = app.checkState.ctx. | ||
WithBlockGasMeter(gasMeter). | ||
WithHeaderHash(req.Hash) | ||
} | ||
|
||
if app.preFinalizeBlockHook != nil { | ||
if err := app.preFinalizeBlockHook(app.finalizeBlockState.ctx, req); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
beginBlock := app.beginBlock(req) | ||
events = append(events, beginBlock.Events...) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Bringing this from the PR that was reverted in order to make sure that PrepareProposal/ProcessProposal get the right context on the first block.