fix(tokens): reduce balance correction RPC load#69
Open
tarrencev wants to merge 2 commits into
Open
Conversation
📊 Synthetic Benchmark ResultsComparing against baseline: 20260608T145153Z Performance Summary
Comparison with Baseline
Legend:
Stage Latency Breakdown
Generated by Synthetic Benchmark CI |
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.
Summary
Reduces unnecessary ERC20/ERC1155 balance correction RPC calls in
torii-tokens.This PR has two parts:
--disable-balance-trackingflag for high-volume/global token indexers that do not need ERC20/ERC1155 balance tablesWhy
The token sinks currently fetch historical
balanceOfvalues whenever a sender's locally computed balance would go negative. That is useful for genuinely missing history, but the precheck was only tracking pending debits inside the current batch. It did not apply credits from earlier transfers in the same batch before evaluating later debits.For large block-range batches, this can create false positives. Example:
balanceOf, even though the batch itself funds the sendOn global token indexers this can become a very large number of unnecessary balance correction calls.
Behavior
Balance tracking enabled, default behavior:
When
--disable-balance-trackingis set:The disable flag means balance tables / balance query accuracy should not be relied on for that run mode.
Tests
cargo fmt --manifest-path /tmp/torii-core/Cargo.tomlcargo test -p torii-erc20 balance_adjustment_checkcargo test -p torii-erc1155 balance_adjustment_checkcargo test -p torii-tokens concurrency_flags_parsecargo check -p torii-tokens