Skip to content
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

perf(consensus/state): Change finalizeCommit to use applyVerifiedBloc… #39

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[consensus/state]` Remove a redundant `VerifyBlock` call in `FinalizeCommit`
([\#2928](https://github.com/cometbft/cometbft/pull/2928))
2 changes: 1 addition & 1 deletion blocksync/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ FOR_LOOP:

// TODO: same thing for app - but we would need a way to
// get the hash without persisting the state
state, err = bcR.blockExec.ApplyVerifiedBlock(state, firstID, first)
state, _, err = bcR.blockExec.ApplyVerifiedBlock(state, firstID, first)
if err != nil {
// TODO This is bad, are we zombie?
panic(fmt.Sprintf("Failed to process committed block (%d:%X): %v", first.Height, first.Hash(), err))
Expand Down
4 changes: 2 additions & 2 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1701,13 +1701,13 @@ func (cs *State) finalizeCommit(height int64) {
stateCopy := cs.state.Copy()

// Execute and commit the block, update and save the state, and update the mempool.
// We use apply verified block here because we have verified the block in this function already.
// NOTE The block.AppHash wont reflect these txs until the next block.
var (
err error
retainHeight int64
)

stateCopy, retainHeight, err = cs.blockExec.ApplyBlock(
stateCopy, retainHeight, err = cs.blockExec.ApplyVerifiedBlock(
stateCopy,
types.BlockID{
Hash: block.Hash(),
Expand Down
5 changes: 2 additions & 3 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ func (blockExec *BlockExecutor) ValidateBlock(state State, block *types.Block) e
// ApplyVerifiedBlock does the same as `ApplyBlock`, but skips verification.
func (blockExec *BlockExecutor) ApplyVerifiedBlock(
state State, blockID types.BlockID, block *types.Block,
) (State, error) {
newState, _, err := blockExec.applyBlock(state, blockID, block)
return newState, err
) (State, int64, error) {
return blockExec.applyBlock(state, blockID, block)
}

// ApplyBlock validates the block against the state, executes it against the app,
Expand Down
Loading