Skip to content

Develop#4010

Merged
tjayrush merged 122 commits into
masterfrom
develop
Sep 23, 2025
Merged

Develop#4010
tjayrush merged 122 commits into
masterfrom
develop

Conversation

@tjayrush

Copy link
Copy Markdown
Member

Description

PR Target Branch

  • I am targeting the develop branch for non-release changes.

tjayrush and others added 30 commits May 25, 2025 08:24
Signed-off-by: gcmutator <329964069@qq.com>
chore: fix function name in comment
Signed-off-by: overallteach <cricis@foxmail.com>
This commit fixes issue #3993 where the in-memory balance cache in GetBalanceAt()
doesn't include the chain identifier in its cache key, causing potential collisions
when the same process handles multiple chains.

The issue:
- GetBalanceAt uses an in-memory cache with key format: "address|blockNumber"
- If the same Connection or process handles multiple chains (e.g., mainnet and gnosis),
  the cache could return incorrect balances from a different chain

The fix:
- Changed cache key format to include chain: "chain|address|blockNumber"
- This ensures each chain has separate cache entries in the in-memory map

Note: The filesystem cache already properly separates by chain through directory
structure, so this fix only affects the in-memory cache.

Example scenario that would trigger the bug:
1. Query balance on mainnet: chifra state --chain mainnet <addr> <block>
2. Query same address/block on gnosis: chifra state --chain gnosis <addr> <block>
3. Without this fix, the second query might return the cached mainnet balance\!

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This test verifies that the in-memory balance cache correctly
includes the chain identifier in cache keys to prevent collisions
when the same process handles multiple chains.

The test demonstrates:
- How the fixed cache key format prevents collisions
- What would happen with the old format (one chain overwrites another)
- The exact cache key format for different scenarios

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…n-collision

Wakamex fix/state cache chain collision
This commit fixes the incorrect decimal handling for ERC-20 tokens by:

1. Modified ToFloatString to use a new ToFloatWithDecimals function
   that properly respects the decimals parameter
2. Created ToFloatWithDecimals that calculates the correct divisor
   (10^decimals) instead of always using 1e18
3. Kept ToFloat function for backward compatibility (defaults to 18)

Example fix for USDC (6 decimals):
- Before: 7,500,000,000 displayed as 0.0000000075
- After: 7,500,000,000 displayed as 7500

Added comprehensive tests to verify decimal handling for tokens with
various decimal places (0, 6, 8, 18).

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ndling

Wakamex fix/token decimal handling
@tjayrush
tjayrush merged commit c450c61 into master Sep 23, 2025
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants