Chain handler last execution info#7356
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## feat/supernova-async-exec #7356 +/- ##
==========================================================
Coverage 77.31% 77.31%
==========================================================
Files 867 867
Lines 116789 116874 +85
==========================================================
+ Hits 90292 90364 +72
- Misses 20548 20555 +7
- Partials 5949 5955 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| } | ||
|
|
||
| func (nf *nodeFacade) getCurrentRootHash() []byte { | ||
| currentHeader := nf.blockchain.GetCurrentBlockHeader() |
There was a problem hiding this comment.
could the currentHeader be nil?
| return bh.blockChain.GetCurrentBlockRootHash() | ||
| } | ||
|
|
||
| _, _, lastExecutedRootHash := bh.blockChain.GetLastExecutedBlockInfo() |
There was a problem hiding this comment.
If the currentHeader is nil this might return something slightly different than the apiTransactionsProcessor.go line 492 - getCurrentRootHash and nodeFacade.go line 638 - getCurrentRootHash.
Is there any way to "unify" the responses?
| } | ||
|
|
||
| func (nf *nodeFacade) getCurrentRootHash() []byte { | ||
| currentHeader := nf.blockchain.GetCurrentBlockHeader() |
There was a problem hiding this comment.
is this method backwards compatible? Previously with or without nil currentHeader the nf.blockchain.GetCurrentBlockRootHash() was returned. Right now if the currentHeader is nil, it will return the nf.blockchain.GetLastExecutedBlockInfo().
It might not matter because it is on the nodeFacade...
There was a problem hiding this comment.
maybe do this instead to keep it backwards compatible:
if currentHeader != nil && currentHeader.IsHeaderV3() {
_, _, lastExecutedRootHash := nf.blockchain.GetLastExecutedBlockInfo()
return lastExecutedRootHash
}
return nf.blockchain.GetCurrentBlockRootHash()| headerHash []byte, | ||
| scheduledHeaderRootHash []byte, | ||
| ) { | ||
| if header.IsHeaderV3() { |
There was a problem hiding this comment.
why is this different than Andromeda?
There was a problem hiding this comment.
after supernova we set last execution info from headersExecutor
| } | ||
|
|
||
| func (he *headersExecutor) process(pair queue.HeaderBodyPair) error { | ||
| executionResult, err := he.blockProcessor.ProcessBlockProposal(pair.Header, pair.Body) |
There was a problem hiding this comment.
We could use a check inside ProcessBlockProposal, that we start the execution from the correct roothash.
can you add this on shardblock with a todo to add it also for the metablock?
There was a problem hiding this comment.
added root hash check
| return nil, ErrNilBlockHeader | ||
| } | ||
|
|
||
| if blockHeader.IsHeaderV3() { |
There was a problem hiding this comment.
when committing the first v3 header, do we create a lastExecutedBlockInfo from the previous V2 block?
otherwise we might have a gap here.
| finalBlockHash []byte | ||
| finalBlockRootHash []byte | ||
|
|
||
| lastNotarizedBlockNonce uint64 |
There was a problem hiding this comment.
why is it called lastNotarized?
should it be lastExecuted ?
| } | ||
|
|
||
| func (nf *nodeFacade) getCurrentRootHash() []byte { | ||
| currentHeader := nf.blockchain.GetCurrentBlockHeader() |
There was a problem hiding this comment.
maybe do this instead to keep it backwards compatible:
if currentHeader != nil && currentHeader.IsHeaderV3() {
_, _, lastExecutedRootHash := nf.blockchain.GetLastExecutedBlockInfo()
return lastExecutedRootHash
}
return nf.blockchain.GetCurrentBlockRootHash()There was a problem hiding this comment.
Pull Request Overview
This PR adds support for tracking last executed block information separately from current block info, primarily to support HeaderV3 where block execution happens asynchronously. The changes introduce GetLastExecutedBlockInfo and SetLastExecutedBlockInfo methods across chain handlers and update various components to use last executed block info for state root hash retrieval when dealing with HeaderV3.
Key changes:
- New methods
GetLastExecutedBlockInfo()andSetLastExecutedBlockInfo()added to chain handler interfaces and implementations - State root hash retrieval logic updated to use last executed block info for HeaderV3
- Headers executor now sets both final block info and last executed block info after processing
- New validation check added before block execution to verify root hash consistency
Reviewed Changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| testscommon/chainHandlerStub.go | Added stub methods for last executed block info |
| testscommon/chainHandlerMock.go | Added mock implementation with fields for last executed block tracking |
| dataRetriever/blockchain/baseBlockchain.go | Core implementation of last executed block info getters/setters |
| dataRetriever/blockchain/blockchain.go | Initialized last executed block info in shard blockchain |
| dataRetriever/blockchain/metachain.go | Initialized last executed block info in meta blockchain |
| process/asyncExecution/headersExecutor.go | Sets both final and last executed block info after processing |
| state/blockInfoProviders/currentBlockInfo.go | Uses last executed info for HeaderV3 |
| process/smartContract/hooks/blockChainHook.go | Retrieves root hash from last executed info for HeaderV3 |
| process/smartContract/scQueryService.go | Query service uses last executed header/root for HeaderV3 |
| node/external/transactionAPI/apiTransactionProcessor.go | API processor retrieves root hash from last executed info for HeaderV3 |
| facade/nodeFacade.go | Facade retrieves root hash from last executed info for HeaderV3 |
| process/block/shardblock.go | Skips setting final block info for HeaderV3 (handled in async executor) |
| process/block/shardblockProposal.go | Adds root hash validation check before execution |
| go.mod | Updated mx-chain-core-go dependency version |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| lastCommitedRootHash, err := sp.accountsDB[state.UserAccountsState].RootHash() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| currentRootHash := sp.blockChain.GetCurrentBlockRootHash() | ||
| if !bytes.Equal(lastCommitedRootHash, currentRootHash) { |
There was a problem hiding this comment.
Corrected spelling of 'lastCommitedRootHash' to 'lastCommittedRootHash'.
| lastCommitedRootHash, err := sp.accountsDB[state.UserAccountsState].RootHash() | |
| if err != nil { | |
| return err | |
| } | |
| currentRootHash := sp.blockChain.GetCurrentBlockRootHash() | |
| if !bytes.Equal(lastCommitedRootHash, currentRootHash) { | |
| lastCommittedRootHash, err := sp.accountsDB[state.UserAccountsState].RootHash() | |
| if err != nil { | |
| return err | |
| } | |
| currentRootHash := sp.blockChain.GetCurrentBlockRootHash() | |
| if !bytes.Equal(lastCommittedRootHash, currentRootHash) { |
| } | ||
| arg.Node = &mock.NodeStub{ | ||
| GetProofCalled: func(rootHash string, _ string) (*common.GetProofResponse, error) { | ||
| require.Equal(t, rootHash, rootHash) |
There was a problem hiding this comment.
The assertion compares rootHash with itself, which always passes. This should likely compare the rootHash parameter against the expected value from line 1148.
| require.Equal(t, rootHash, rootHash) | |
| require.Equal(t, string(rootHash1), rootHash) |
Reasoning behind the pull request
Proposed changes
Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
featbranch created?featbranch merging, do all satellite projects have a proper tag insidego.mod?