Optimize receipt canonicality with OnUpdateMainChain batching#10446
Open
Optimize receipt canonicality with OnUpdateMainChain batching#10446
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes receipt canonicality updates during multi-block main-chain updates by propagating main-chain update batch metadata through BlockTree events and using that metadata to batch transaction-index writes in PersistentReceiptStorage.
Changes:
- Extend
BlockReplacementEventArgswith main-chain update batching metadata (while preserving existing constructor call sites). - Propagate batch metadata from
BlockTree.UpdateMainChain/MoveToMainintoBlockAddedToMainevents. - Batch canonical tx-index writes in
PersistentReceiptStorageacross a main-chain update (with bounded flushing and stale/out-of-order event hardening) and add targeted tests.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Nethermind/Nethermind.Core/BlockReplacementEventArgs.cs | Adds batch metadata fields and new constructors for compatibility. |
| src/Nethermind/Nethermind.Core/BlockProcessingConstants.cs | Introduces shared constant for bounding uncommitted block processing/batching. |
| src/Nethermind/Nethermind.Consensus/Processing/BranchProcessor.cs | Reuses shared MaxUncommittedBlocks constant instead of a local copy. |
| src/Nethermind/Nethermind.Blockchain/Receipts/PersistentReceiptStorage.cs | Implements canonical tx-index batching keyed by main-chain update metadata; adds bounded flush + stale batch handling. |
| src/Nethermind/Nethermind.Blockchain/BlockTree.cs | Tags BlockAddedToMain events with update-batch metadata during multi-block UpdateMainChain. |
| src/Nethermind/Nethermind.Blockchain.Test/Receipts/PersistentReceiptStorageTests.cs | Adds tests covering commit-on-last behavior, batch-id changes, stale events, and max-batch flush. |
| src/Nethermind/Nethermind.Blockchain.Test/BlockTreeTests.cs | Adds tests validating batch metadata presence for multi-block updates and absence for single-block updates. |
| .gitignore | Ignores /.dotnet_cli. |
Comments suppressed due to low confidence (1)
src/Nethermind/Nethermind.Blockchain/BlockTree.cs:978
- These 'if' statements can be combined.
if (isBatchUpdate)
{
if (blocks[^1].Number < blocks[0].Number)
{
ascendingOrder = false;
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
LukaszRozmej
reviewed
Feb 7, 2026
src/Nethermind/Nethermind.Blockchain/Receipts/PersistentReceiptStorage.cs
Outdated
Show resolved
Hide resolved
LukaszRozmej
reviewed
Feb 8, 2026
src/Nethermind/Nethermind.Blockchain/Receipts/PersistentReceiptStorage.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Blockchain/Receipts/PersistentReceiptStorage.cs
Outdated
Show resolved
Hide resolved
- Remove ConcurrentDictionary.IsEmpty check in FindBlockHash; TryGetValue is lock-free and handles the empty case without acquiring bucket locks. - Simplify DEBUG gap-check loop by starting at i=1 instead of nested if. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
asdacap
reviewed
Feb 9, 2026
LukaszRozmej
reviewed
Feb 9, 2026
src/Nethermind/Nethermind.Blockchain/Receipts/PersistentReceiptStorage.cs
Outdated
Show resolved
Hide resolved
Replace per-block batch accumulation in BlockAddedToMain with a single OnUpdateMainChain handler that writes all tx indices in one WriteBatch. Remove batch metadata from BlockReplacementEventArgs and MoveToMain.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Nethermind/Nethermind.Blockchain.Test/Receipts/PersistentReceiptStorageTests.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Blockchain.Test/Receipts/PersistentReceiptStorageTests.cs
Show resolved
Hide resolved
src/Nethermind/Nethermind.Blockchain/Receipts/PersistentReceiptStorage.cs
Show resolved
Hide resolved
LukaszRozmej
approved these changes
Feb 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
OnUpdateMainChainevent for batched tx-index writes instead of per-blockEnsureCanonicalcalls, reducing write batch overhead during multi-block chain updatesOnUpdateMainChainbefore the per-blockMoveToMainloop so tx indices are committed beforeNewCanonicalReceiptsnotifies JSON-RPC subscribersShouldIndexBlockandWriteCanonicalTxIndexhelpers to share logic between single-block and batch pathsIDisposabletoPersistentReceiptStorageto unsubscribe both event handlersPutSpaninstead ofBytesToArray()for non-compact tx index writes to avoid allocationRemoveBlockTxwhen block has no transactionsBlockTree.UpdateMainChainascending-order check and DEBUG validation loopTypes of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?