perf(spf): index the Tempo node pool once per batch - #1390
Open
mattsse wants to merge 1 commit into
Open
Conversation
`prove_zone_batch` imports a Tempo checkpoint for every Zone block, and `with_imported_checkpoint` rebuilt the sparse trie from the raw node pool each time. Because `StatelessSparseTrie::new` starts by keccak-hashing and indexing every node in the pool, a batch of N blocks re-hashed the entire Tempo witness N times, making the Tempo side of replay quadratic in batch length even though the pool is fixed for the whole batch. The pool is now hashed and indexed once in `from_tempo_state_witness` and shared as an `Arc<B256Map<Bytes>>`, so each checkpoint only walks the proof reachable from its own state root. A checkpoint whose state root equals the previous one also reuses the already revealed trie instead of revealing it again. Error behaviour is unchanged for the witnesses that can reach this code: the initial header is still decoded before the pool is indexed, so `InvalidTempoHeader` still precedes `DuplicateNodeHash`, and `MissingStateRootNode` still maps to an inactive reader.
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.
prove_zone_batchimports a Tempo checkpoint for every zone block, and each import rebuilt the sparse trie from the raw node pool, keccak-hashing and indexing every node again. The pool is fixed for the batch, so the Tempo side of replay was quadratic in batch length.The pool is now hashed and indexed once in
from_tempo_state_witnessand shared as anArc<B256Map<Bytes>>; each checkpoint only reveals the proof reachable from its own state root, and a checkpoint carrying the previous root reuses the revealed trie. Error behaviour is preserved: the initial header is still decoded before indexing, soInvalidTempoHeaderstill precedesDuplicateNodeHash, andMissingStateRootNodestill leaves the reader inactive.Measured with a throwaway harness replaying the Tempo side of
prove_zone_batchover a pool with one distinct checkpoint root per block, dev profile: a 256-block batch with an 8257-node, 4.3 MB pool goes from 142 s to 255 ms, a 64-block batch with a 2065-node, 1.1 MB pool from 7.95 s to 64 ms. In an optimized build, indexing the 8257-node pool costs 11.2 ms, which is what every block paid before.