Skip to content

New header body pair cache#7620

Merged
AdoAdoAdo merged 46 commits into
feat/supernova-async-execfrom
header-cache
Feb 2, 2026
Merged

New header body pair cache#7620
AdoAdoAdo merged 46 commits into
feat/supernova-async-execfrom
header-cache

Conversation

@miiu96

@miiu96 miiu96 commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

Reasoning behind the pull request

  • New header body pair cache

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@miiu96 miiu96 self-assigned this Jan 16, 2026
@miiu96 miiu96 changed the base branch from feat/supernova-async-exec to fix-referenced-gaps January 16, 2026 13:30
# Conflicts:
#	process/asyncExecution/headersExecutor.go
#	process/asyncExecution/headersExecutor_test.go
#	testscommon/processMocks/executionManagerMock.go

headerNonce := pair.Header.GetNonce()
c.cacheByNonce[headerNonce] = pair
c.lastAddedNonce = headerNonce

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if this is called with a lower nonce? in this case, I think we should remove all headers with higher nonces from cache

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored this
last added nonce is no longer needed, also is no need to remove the pairs with higher nonce
because with this implementation we will fetch pairs by providing the correct nonce.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, indeed we have RemoveAtNonceAndHigher that does that

c.mutex.Lock()
defer c.mutex.Unlock()

delete(c.cacheByNonce, nonce)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update lastAddedNonce nonce as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored

require.False(t, found)
}

func TestHeaderBodyCache_ConcurrentAccess(t *testing.T) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add one more test that calls all methods concurrently


// blocking operation
headerBodyPair, ok := he.blocksQueue.Pop()
/// get pair by nonce from blockchain

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// get pair by nonce from blockchain
// get pair by nonce from blockchain

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

headerBodyPair, ok := he.blocksQueue.Pop()
/// get pair by nonce from blockchain
lastExecutedHeader := he.blockChain.GetLastExecutedBlockHeader()
if lastExecutedHeader == nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if lastExecutedHeader == nil {
if check.IfNil(lastExecutedHeader) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

continue
}

if check.IfNil(headerBodyPair.Header) || check.IfNil(headerBodyPair.Body) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be removed now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

lastExecutionResult := he.blockChain.GetLastExecutionResult()
if lastExecutionResult != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if lastExecutionResult != nil {
if check.IfNil(lastExecutionResult) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

args := createMockArgs()
blocksQueue := queue.NewBlocksQueue()
args.BlocksQueue = blocksQueue
blocksQueue := cache.NewHeaderBodyCache()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
blocksQueue := cache.NewHeaderBodyCache()
blocksCache := cache.NewHeaderBodyCache()

Comment thread process/interface.go
RemoveAtNonceAndHigher(nonce uint64) []uint64
ValidateQueueIntegrity() error
Clean(lastAddedNonce uint64)
GetByNonce(nonce uint64) (cache.HeaderBodyPair, bool)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename interface as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored

Comment thread integrationTests/testProcessorNode.go Outdated

executionResultsTracker := executionTrack.NewExecutionResultsTracker()
tpn.BlocksQueue = queue.NewBlocksQueue()
tpn.BlocksQueue = headersCache.NewHeaderBodyCache()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to BlocksCache

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

sstanculeanu
sstanculeanu previously approved these changes Jan 20, 2026
@mariusmihaic mariusmihaic self-requested a review January 20, 2026 11:19
Comment on lines +58 to +68
c.mutex.Lock()
defer c.mutex.Unlock()

nonces := make([]uint64, 0)
for nonce := range c.cacheByNonce {
if nonce >= providedNonce {
delete(c.cacheByNonce, nonce)
nonces = append(nonces, nonce)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move the mutex to be used only for this for, up until sort.Slice

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +95 to +97
// Should be pair2 (note: they are different pointers for Header/Body so Equal check works if pointer comparison)
// Wait, slice/map/func in structs make Go equality tricky unless pointers.
// These are pointers to structs, so it should be fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps remove these AI generated comments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

require.True(t, found)
// Should be pair2 (note: they are different pointers for Header/Body so Equal check works if pointer comparison)
// Wait, slice/map/func in structs make Go equality tricky unless pointers.
// These are pointers to structs, so it should be fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually tests pointer comparison.
It should require that retrievedPair == pair

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment removed.

log.Warn("executionManager.Close - failed to close headers executor", "error", err)
}

em.blocksQueue.Close()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we clean the cache here? Does it make sense?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not needed, because at the restart the cache will be initialized again.

Base automatically changed from fix-referenced-gaps to feat/supernova-async-exec January 20, 2026 14:59
@sstanculeanu sstanculeanu dismissed their stale review January 20, 2026 14:59

The base branch was changed.

@miiu96 miiu96 changed the base branch from feat/supernova-async-exec to fix-edge-on-bootstrap January 20, 2026 15:01
Base automatically changed from fix-edge-on-bootstrap to feat/supernova-async-exec January 20, 2026 15:54
An error occurred while trying to automatically change base from fix-edge-on-bootstrap to feat/supernova-async-exec January 20, 2026 15:54
@miiu96 miiu96 changed the base branch from feat/supernova-async-exec to proper-fix-on-consensus-revert January 21, 2026 08:20
Base automatically changed from proper-fix-on-consensus-revert to dynamic-time-for-selection January 21, 2026 10:54
Base automatically changed from dynamic-time-for-selection to feat/supernova-async-exec January 21, 2026 12:30
@codecov

codecov Bot commented Jan 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.82609% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.60%. Comparing base (8c69291) to head (629fc30).
⚠️ Report is 47 commits behind head on feat/supernova-async-exec.

Files with missing lines Patch % Lines
process/asyncExecution/headersExecutor.go 52.83% 19 Missing and 6 partials ⚠️
...xecution/executionTrack/executionResultsTracker.go 48.48% 16 Missing and 1 partial ⚠️
process/sync/baseSync.go 75.00% 6 Missing and 2 partials ⚠️
node/chainSimulator/process/processor.go 30.00% 7 Missing ⚠️
...syncExecution/executionManager/executionManager.go 55.55% 3 Missing and 1 partial ⚠️
process/common.go 57.14% 3 Missing ⚠️
process/coordinator/process.go 40.00% 1 Missing and 2 partials ⚠️
process/asyncExecution/cache/headerBodyCache.go 96.55% 1 Missing and 1 partial ⚠️
process/block/preprocess/basePreProcess.go 66.66% 1 Missing and 1 partial ⚠️
process/block/preprocess/transactionsV2.go 90.00% 1 Missing and 1 partial ⚠️
... and 2 more
Additional details and impacted files
@@                      Coverage Diff                      @@
##           feat/supernova-async-exec    #7620      +/-   ##
=============================================================
- Coverage                      77.62%   77.60%   -0.03%     
=============================================================
  Files                            877      877              
  Lines                         121763   121752      -11     
=============================================================
- Hits                           94515    94480      -35     
- Misses                         20987    21004      +17     
- Partials                        6261     6268       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

sstanculeanu
sstanculeanu previously approved these changes Jan 22, 2026
AdoAdoAdo and others added 25 commits January 23, 2026 18:13
# Conflicts:
#	process/asyncExecution/queue/blocksQueue.go
#	process/asyncExecution/queue/blocksQueue_test.go
# Conflicts:
#	node/chainSimulator/process/processor.go
…balance

fix unexecutable tx due to initial balance
fix on concurrent header execution and revert
# Conflicts:
#	process/sync/baseSync.go
# Conflicts:
#	factory/processing/processComponents.go
#	integrationTests/testFullNode.go
#	integrationTests/testProcessorNode.go
#	integrationTests/testSyncNode.go
#	integrationTests/vm/staking/metaBlockProcessorCreator.go
#	process/asyncExecution/headersExecutor_test.go
#	process/asyncExecution/queue/blocksQueue.go
#	process/asyncExecution/queue/blocksQueue_test.go
#	process/block/baseProcess_test.go
#	process/block/export_test.go
Header body queue capacity in config.toml
@AdoAdoAdo AdoAdoAdo merged commit c635e8b into feat/supernova-async-exec Feb 2, 2026
9 of 11 checks passed
@AdoAdoAdo AdoAdoAdo deleted the header-cache branch February 2, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants