diff --git a/.changelog/unreleased/improvements/2928-remove-redundant-verifyblock-call-in-finalize-commit.md b/.changelog/unreleased/improvements/2928-remove-redundant-verifyblock-call-in-finalize-commit.md new file mode 100644 index 00000000000..ac975738453 --- /dev/null +++ b/.changelog/unreleased/improvements/2928-remove-redundant-verifyblock-call-in-finalize-commit.md @@ -0,0 +1,2 @@ +- `[consensus/state]` Remove a redundant `VerifyBlock` call in `FinalizeCommit` + ([\#2928](https://github.com/cometbft/cometbft/pull/2928)) \ No newline at end of file diff --git a/blocksync/reactor.go b/blocksync/reactor.go index 7fa2bbf73be..3349bf7e34d 100644 --- a/blocksync/reactor.go +++ b/blocksync/reactor.go @@ -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)) diff --git a/consensus/state.go b/consensus/state.go index 6fb202af23c..9249e2b1acb 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -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(), diff --git a/state/execution.go b/state/execution.go index 6a460d4bfe9..dced97233ba 100644 --- a/state/execution.go +++ b/state/execution.go @@ -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,