-
Notifications
You must be signed in to change notification settings - Fork 573
Updated blockchainBridge hasStateForBlock to use config instead of st… #9457
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
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| /// <summary> | ||
| /// Gets the block number of the last persisted block. | ||
| /// Used to track the oldest available state after full pruning operations. | ||
| /// </summary> | ||
| long LastPersistedBlockNumber { get; } |
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.
Are you sure this is the OLDEST persisted block number or just LAST (newest) persisted block number?
Not entirely sure if it solves what we expect it does.
@asdacap can you advise?
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.
Its newest
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 removed this
| { | ||
| // Archive mode: but state only available from sync pivot onwards | ||
| // If node was snap/fast synced, state before pivot was never downloaded | ||
| long syncPivotBlock = blockTree.SyncPivot.BlockNumber; |
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.
Are we sure BlockTree.SyncPivot is reliable data here?
Is it 0 for full archive? Is it 1st block with state for archive with snap sync?
@asdacap can you advise?
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.
SyncPivot moves nowadays. So no.
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 removed SyncPivot dependency
| // 3. Current pruning window (head - boundary) | ||
| long lastPersistedBlock = pruningTrieStore.LastPersistedBlockNumber; | ||
| long syncPivotBlock = blockTree.SyncPivot.BlockNumber; | ||
| long pruningWindowStart = headNumber - pruningConfig.PruningBoundary + 1; // +1 for safety margin |
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 calculation is used in both if and else path, let's name it as local method? Or do it before if and name correctly.
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.
not relevant anymore after my last changes
|
I think the fundamental issue is that 'HasStateForBlock |
|
Also, checkout |
Why the existance of root node doesn't imply the existence of the trie? |
|
Its children might get removed during in memory pruning. Thats why. Some of the nodes may not get removed due to memory limitation for tracking. |
Sure but that is deviation from previous assumptions that were commonly used (like in RPC) and to be honest poses a potential for hard to track bugs (though might be necessary for better pruning) |
@asdacap is this relevant for this PR? For RPC calls we don't want to reference state, just base the response on config (e.g. pruning boundary etc) |
| // For archive nodes that were snap synced, check the lowest inserted header | ||
| // We use LowestInsertedHeader (not SyncPivot) because SyncPivot moves forward over time | ||
| // as finalized blocks progress, while LowestInsertedHeader remains at the original starting point | ||
| long? lowestInsertedBlockNumber = blockTree.LowestInsertedHeader?.Number; |
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 false, we always have all headers.
We will probably always have all block bodies too.
| // Pruning nodes: calculate oldest available state based on pruning boundary | ||
| // This is conservative but correct for all pruning node configurations: | ||
| // - Memory pruning: respects the configured boundary | ||
| // - Full pruning: also uses pruning boundary (persisted state within this window) |
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 doesn't work for full pruning only like this
The RPC consult the world state if a state is available or not. The world state is faulty. IMO this check is important especially for triestore as during memory pruning (around 1 to 2 second on mainnet probably every 30 minute), nodes are concurrently removed, so it definitely need to check config like what you did. However, think carefully, now it uses pruning boundary, later its gonna respect finalized block, later again its gonna have special archive node that only have last 1 mil block or something, do you really want to have all that logic in |
|
|
||
| .Map<IWorldStateManager, PruningTrieStateFactoryOutput>((o) => o.WorldStateManager) | ||
| .Map<IStateReader, IWorldStateManager>((m) => m.GlobalStateReader) | ||
| .Map<IPruningTrieStore, MainPruningTrieStoreFactory>((f) => f.PruningTrieStore) |
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 you dont need this anymore. Please dont use IPruningTrieStore. It will make migrating to other world state layout harder.
|
I think you can simply check for |
I would consider putting it in |
|
|
||
| // Conservative: don't claim we have state during state sync | ||
| // This prevents race conditions during the sync process for all node types | ||
| if (ethSyncingInfo.SyncMode.HaveNotSyncedStateYet()) |
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 can be incorrect in edge case - archive node, starting from scratch, archive node should always have state
…ate. Relates to #9408
Changes
Types of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?
Documentation
Remarks
There were no changes done to the snap serving. 128 is hardcoded there so there should be no impact