-
Notifications
You must be signed in to change notification settings - Fork 221
Fix multiple headers not being referenced #7581
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
Fix multiple headers not being referenced #7581
Conversation
…ed after tx selection
…ersx/mx-chain-go into fix-multiple-headers-not-being-referenced # Conflicts: # process/block/gasConsumption.go # testscommon/gasComputationMock.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/supernova-async-exec #7581 +/- ##
==========================================================
Coverage 77.66% 77.66%
==========================================================
Files 874 874
Lines 120635 120689 +54
==========================================================
+ Hits 93694 93739 +45
- Misses 20768 20777 +9
Partials 6173 6173 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…t-being-referenced
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.
Pull request overview
This PR fixes an issue where multiple meta headers were not being properly referenced in proposals when pending mini blocks from different meta blocks were added. The fix ensures that when outgoing transactions are selected and pending mini blocks are included, all corresponding meta headers are tracked and referenced.
Key Changes:
- Added a new method
CanAddPendingIncomingMiniBlocks()to the GasComputation interface to check if more pending mini blocks can fit in the remaining block space - Introduced
pendingMiniBlocksAfterSelectionstruct to associate pending mini blocks with their originating meta headers - Enhanced the logic to reference all meta headers when pending mini blocks are added after transaction selection
- Added comprehensive test coverage for the new gas computation check
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| process/interface.go | Added CanAddPendingIncomingMiniBlocks() method to GasComputation interface |
| testscommon/gasComputationMock.go | Mock implementation of the new interface method |
| process/coordinator/processProposal.go | Fixed transaction count calculation when mini blocks become pending; corrected typo in comment |
| process/coordinator/processProposal_test.go | Updated comment typo and adjusted expected transaction count in test |
| process/block/shardblockProposal.go | Core fix: tracks pending mini blocks with their headers and references all headers when pending blocks are added |
| process/block/shardblockProposal_test.go | Enhanced test to verify multiple meta headers are referenced correctly |
| process/block/gasConsumption.go | Implemented pending gas tracking and the new CanAddPendingIncomingMiniBlocks() method |
| process/block/gasConsumption_test.go | Added comprehensive tests for the new gas computation functionality |
| process/block/export_test.go | Exported internal types and methods for testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pendingMiniBlocks = append(pendingMiniBlocks, &pendingMiniBlocksAfterSelection{ | ||
| headerHash: currentMetaBlockHash, | ||
| header: currentMetaBlock, | ||
| pendingMiniBlocksAndHashes: createIncomingMbsResult.PendingMiniBlocks, | ||
| }) |
Copilot
AI
Dec 29, 2025
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.
The code unconditionally appends to pendingMiniBlocks even when createIncomingMbsResult.PendingMiniBlocks is empty. This could result in appending unnecessary empty entries to the slice. Consider only appending when there are actual pending mini blocks to track.
| pendingMiniBlocks = append(pendingMiniBlocks, &pendingMiniBlocksAfterSelection{ | |
| headerHash: currentMetaBlockHash, | |
| header: currentMetaBlock, | |
| pendingMiniBlocksAndHashes: createIncomingMbsResult.PendingMiniBlocks, | |
| }) | |
| if len(createIncomingMbsResult.PendingMiniBlocks) > 0 { | |
| pendingMiniBlocks = append(pendingMiniBlocks, &pendingMiniBlocksAfterSelection{ | |
| headerHash: currentMetaBlockHash, | |
| header: currentMetaBlock, | |
| pendingMiniBlocksAndHashes: createIncomingMbsResult.PendingMiniBlocks, | |
| }) | |
| } |
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.
should be ok
process/block/gasConsumption.go
Outdated
| hashStr := string(mb.GetHash()) | ||
| gc.transactionsForPendingMiniBlocks[hashStr] = transactions[hashStr] | ||
|
|
||
| transactionsForMB, found := transactions[string(mb.GetHash())] |
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.
can you merge this line and L128?
both appear to be reading the same transactions
e.g do the gc.transactionsForPendingMiniBlocks[hashStr] = transactionsForMB after the !found check?
or do we need to set nil explicitly in the map?
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.
updated, missed it
process/block/gasConsumption.go
Outdated
|
|
||
| gasConsumedByIncomingAfter := gc.totalGasConsumed[incoming] | ||
| gasConsumedByMiniBlock := gasConsumedByIncomingAfter - gasConsumedByIncomingBefore | ||
| if gasConsumedByMiniBlock < gc.totalGasConsumed[pending] { |
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.
for the last pending miniblock I think this condition would be equal.
this relates to the comment below
// should never be false
but for the last one, it will be false.
maybe the conditon should be <= gc.totalGasConsumed[pending]
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.
updated
process/block/gasConsumption.go
Outdated
| gasConsumedByPendingMb, errCheckPending := gc.checkGasConsumedByMiniBlock(mb, transactionsForMB) | ||
| if errCheckPending != nil { | ||
| log.Warn("failed to check gas consumed by pending mini block", "hash", mb.GetHash(), "error", errCheckPending) | ||
| continue |
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.
I think it should break instead of continuing, as that means that it can create miniblock gaps when there's a problem, which would not be ok.
Same with the above continue, I think it should break there as well, as we don't want to create gaps.
Or even better returning error instead of breaking, as we rely now on the computed pending miniblocks consumed gas in the next steps.
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.
right, updated
process/block/shardblockProposal.go
Outdated
| } | ||
|
|
||
| for referencedHash, referencedHeader := range extraHeadersReferenced { | ||
| sp.miniBlocksSelectionSession.AddReferencedHeader(referencedHeader, []byte(referencedHash)) |
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.
the miniblockSelectionSession assumes the referenced headers are added in order, and here you are iterating over a map which does not ensure a specific iteration order.
Can you ensure that the AddReferencedHeader is called in the order of referencing the metablocks? maybe adding the reference into the above loop?
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.
updated as suggested
process/block/gasConsumption.go
Outdated
|
|
||
| gasLeft := maxGasLimitPerBlock - totalGasConsumed | ||
| maxGasLimitPerMiniBlock := gc.maxGasLimitPerMiniBlock(gc.shardCoordinator.SelfId()) | ||
| return totalGasToBeConsumedByPending+maxGasLimitPerMiniBlock < gasLeft |
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.
why do we add the maxGasLimitPerMiniBlock to the total gas to be consumed by pending?
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.
this method checks if there is space for one more mini block left in the block.. checking against the max gas limit, as it does not receive a specific mini block to know how much it would consume
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.
but the miniblock does not necessarily need to be of max size, it can be of any size below the maximum size.
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.
removed it
process/block/shardblockProposal.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func getIndexOfPendingMiniBlock( |
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.
this is called getIndexOfPending.... but it is not getting any index right?
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.
renamed
…t-being-referenced
…t-being-referenced
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?