-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Background
Currently, Java-tron does not support Archive Node. An archive node can query historical state data from the blockchain. Unlike a fullnode, an archive node not only saves the most recent blockchain state data but also completely records all historical state data from the genesis block to the latest block. This allows users to directly query state data such as account balances and contract storage at any block height without needing to recalculate from the genesis block (replay transactions), greatly improving the efficiency of historical state data queries.
Rationale
Why should this feature exist?
Fullnodes only store the current latest block state (used to verify new blocks), while archive nodes additionally store state snapshots of each historical block (e.g., balances for each address, contract storage data, etc.). Archive nodes can support historical state queries. For example, querying the balance of an address at block height 10,000 cannot be directly provided by a fullnode, but an archive node can do this.
What are the use-cases?
- DApp developers: testing and verifying smart contract behavior under different historical states
- Data analysis services: providing advanced analytical functions based on historical states
- Researchers: analyzing historical transaction patterns, state changes, and network behavior
Specification
Support Ethereum-compatible interfaces, including but not limited to:
- eth_getBalance: query an account's balance at a specific block height
- eth_getCode: query contract bytecode at a specific block height
- eth_getStorageAt: query the value at a specific position in contract storage at a specific block height
- eth_call: execute read-only contract calls on the state at a specific block height
Implementation
Archive nodes need a world state trie, which TRON needs to implement.
Ethereum state trie implementation
Ethereum supported a state trie in its initial version, implementing core state trie logic:
- The block header contains three roots: transactionRoot, receiptRoot, and stateRoot
- Every block state data change is reflected in the stateRoot
- Account data, including contracts (nonce, balance, storageRoot, codeHash), is all uniformly encapsulated in the account
- Uses MPT (Merkle Patricia Trie) for state data storage (including CRUD operations)
TRON's current situation
-
The block header contains 2 roots: txTrieRoot and accountStateRoot. TxTrieRoot is consistent with Ethereum's transactionRoot, but accountState only includes balance (the proposal is not enabled) and does not include contract data (storageRoot, codeHash) like ETH does.
-
Supports historical account balance queries: After enabling balance.history.lookup, account balances at specific heights can be queried via wallet/getaccountbalance.
-
State data is quite dispersed and not fully encapsulated in accounts (e.g., contract data, TRC10 are stored separately in different DBs). After organization, 25 databases need state statistics, including account data, TRC10 data, contract data, voting data, delegation data, etc. All state data needs to be organized and collected to generate the stateRoot
Implementation considerations for Archive nodes:
-
stateRoot generation
TRON's state data is quite dispersed, involving many state databases. Unlike ETH, which generates root directly based on accounts, TRON needs to collect dispersed state data to generate a stateRoot. -
Should stateRoot participate in consensus?
Consensus issues:- A proposal is needed to generate stateRoot at a specified height, requiring consideration of how to calculate the initial effective height of stateRoot, whether to generate a genesis stateRoot based on the current state, and if not, how to ensure network-wide data consistency.
- Historical data before this cannot generate stateRoot, and cannot support historical state queries.
- Generating and verifying state roots impacts performance, potentially reducing TPS and transaction execution efficiency, affecting SRs and the ordinary fullNode.
-
Compatibility with all ETH state query interfaces
- Support for eth_getBalance, eth_getCode, eth_getStorageAt, eth_call
- Future support for eth_getBlockReceipts(Implement eth_getBlockReceipts methodย #5910 ) and debug_traceCall(Support the
debug_traceCallAPIย #5778 ) - For discussion: whether to support eth_getTransactionCount (requires adding nonce field to Account, requiring a hard fork proposal) and eth_getProof (requires storageRoot, lite fullnodes, L2 support, etc.)
-
Performance impact
Archive nodes significantly impact block execution and transaction execution efficiency, especially when historical state data is large. The implementation must ensure the normal operation of block synchronization and transaction execution. -
Storage impact
The transaction volume of TRON is far greater than that of ETH, with the archive node data expected to be 3-4 times that of ETH, estimated at 80 T+. Current single disk storage will be limited, requiring consideration of using multiple segmented Archive Nodes combined into a complete historical query collection.
Based on the above analysis, stateRoot will not participate in consensus to reduce the impact on SRs and the ordinary fullnodes during archive node implementation. Segmented multi-disk storage of state data will be used to solve single-disk storage limitations. Additionally, since archive-related functionality implementation involves significant changes affecting many functions, integration into the main branch is not currently considered, and development will first proceed on an independent branch.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
