From d8cb8a962b2de18cac5f2b6a820a3dea5d33db0e Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Sat, 4 Apr 2026 21:00:07 +0800 Subject: [PATCH] core, eth, ethclient, triedb: report trienode index progress (#34633) The trienode history indexing progress is also exposed via an RPC endpoint and contributes to the eth_syncing status. --- core/blockchain_reader.go | 2 +- eth/api_backend.go | 5 +++-- eth/downloader/api.go | 5 +++-- ethclient/ethclient.go | 2 ++ graphql/graphql.go | 3 +++ interfaces.go | 7 ++++--- internal/ethapi/api.go | 1 + triedb/database.go | 4 ++-- triedb/pathdb/database.go | 23 +++++++++++++++++++---- triedb/pathdb/database_test.go | 4 ++-- 10 files changed, 40 insertions(+), 16 deletions(-) diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index 8b026680d2..3614702d1a 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -476,7 +476,7 @@ func (bc *BlockChain) TxIndexProgress() (TxIndexProgress, error) { } // StateIndexProgress returns the historical state indexing progress. -func (bc *BlockChain) StateIndexProgress() (uint64, error) { +func (bc *BlockChain) StateIndexProgress() (uint64, uint64, error) { return bc.triedb.IndexProgress() } diff --git a/eth/api_backend.go b/eth/api_backend.go index fe2105f47b..a4e976b1b8 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -414,9 +414,10 @@ func (b *EthAPIBackend) SyncProgress(ctx context.Context) ethereum.SyncProgress prog.TxIndexFinishedBlocks = txProg.Indexed prog.TxIndexRemainingBlocks = txProg.Remaining } - remain, err := b.eth.blockchain.StateIndexProgress() + stateRemain, trienodeRemain, err := b.eth.blockchain.StateIndexProgress() if err == nil { - prog.StateIndexRemaining = remain + prog.StateIndexRemaining = stateRemain + prog.TrienodeIndexRemaining = trienodeRemain } return prog } diff --git a/eth/downloader/api.go b/eth/downloader/api.go index f97371de5f..1fea35775e 100644 --- a/eth/downloader/api.go +++ b/eth/downloader/api.go @@ -81,9 +81,10 @@ func (api *DownloaderAPI) eventLoop() { prog.TxIndexFinishedBlocks = txProg.Indexed prog.TxIndexRemainingBlocks = txProg.Remaining } - remain, err := api.chain.StateIndexProgress() + stateRemain, trienodeRemain, err := api.chain.StateIndexProgress() if err == nil { - prog.StateIndexRemaining = remain + prog.StateIndexRemaining = stateRemain + prog.TrienodeIndexRemaining = trienodeRemain } return prog } diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index bc4eaad6fa..85286ec919 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -838,6 +838,7 @@ type rpcProgress struct { TxIndexFinishedBlocks hexutil.Uint64 TxIndexRemainingBlocks hexutil.Uint64 StateIndexRemaining hexutil.Uint64 + TrienodeIndexRemaining hexutil.Uint64 } func (p *rpcProgress) toSyncProgress() *ethereum.SyncProgress { @@ -865,6 +866,7 @@ func (p *rpcProgress) toSyncProgress() *ethereum.SyncProgress { TxIndexFinishedBlocks: uint64(p.TxIndexFinishedBlocks), TxIndexRemainingBlocks: uint64(p.TxIndexRemainingBlocks), StateIndexRemaining: uint64(p.StateIndexRemaining), + TrienodeIndexRemaining: uint64(p.TrienodeIndexRemaining), } } diff --git a/graphql/graphql.go b/graphql/graphql.go index f25bfd127a..dadc91fac0 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -1531,6 +1531,9 @@ func (s *SyncState) TxIndexRemainingBlocks() hexutil.Uint64 { func (s *SyncState) StateIndexRemaining() hexutil.Uint64 { return hexutil.Uint64(s.progress.StateIndexRemaining) } +func (s *SyncState) TrienodeIndexRemaining() hexutil.Uint64 { + return hexutil.Uint64(s.progress.TrienodeIndexRemaining) +} // Syncing returns false in case the node is currently not syncing with the network. It can be up-to-date or has not // yet received the latest block headers from its peers. In case it is synchronizing: diff --git a/interfaces.go b/interfaces.go index 21d42c6d34..8b3dbe3a42 100644 --- a/interfaces.go +++ b/interfaces.go @@ -139,8 +139,9 @@ type SyncProgress struct { TxIndexFinishedBlocks uint64 // Number of blocks whose transactions are already indexed TxIndexRemainingBlocks uint64 // Number of blocks whose transactions are not indexed yet - // "historical state indexing" fields - StateIndexRemaining uint64 // Number of states remain unindexed + // "historical data indexing" fields + StateIndexRemaining uint64 // Number of states remain unindexed + TrienodeIndexRemaining uint64 // Number of trienodes remain unindexed } // Done returns the indicator if the initial sync is finished or not. @@ -148,7 +149,7 @@ func (prog SyncProgress) Done() bool { if prog.CurrentBlock < prog.HighestBlock { return false } - return prog.TxIndexRemainingBlocks == 0 && prog.StateIndexRemaining == 0 + return prog.TxIndexRemainingBlocks == 0 && prog.StateIndexRemaining == 0 && prog.TrienodeIndexRemaining == 0 } // ChainSyncReader wraps access to the node's current sync status. If there's no diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 694fbf9c15..149e12c5b8 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -180,6 +180,7 @@ func (api *EthereumAPI) Syncing(ctx context.Context) (interface{}, error) { "txIndexFinishedBlocks": hexutil.Uint64(progress.TxIndexFinishedBlocks), "txIndexRemainingBlocks": hexutil.Uint64(progress.TxIndexRemainingBlocks), "stateIndexRemaining": hexutil.Uint64(progress.StateIndexRemaining), + "trienodeIndexRemaining": hexutil.Uint64(progress.TrienodeIndexRemaining), }, nil } diff --git a/triedb/database.go b/triedb/database.go index e7e47bb91a..c1abe93462 100644 --- a/triedb/database.go +++ b/triedb/database.go @@ -367,10 +367,10 @@ func (db *Database) StorageIterator(root common.Hash, account common.Hash, seek // IndexProgress returns the indexing progress made so far. It provides the // number of states that remain unindexed. -func (db *Database) IndexProgress() (uint64, error) { +func (db *Database) IndexProgress() (uint64, uint64, error) { pdb, ok := db.backend.(*pathdb.Database) if !ok { - return 0, errors.New("not supported") + return 0, 0, errors.New("not supported") } return pdb.IndexProgress() } diff --git a/triedb/pathdb/database.go b/triedb/pathdb/database.go index 86a42c69f4..a61d302b1d 100644 --- a/triedb/pathdb/database.go +++ b/triedb/pathdb/database.go @@ -626,11 +626,26 @@ func (db *Database) HistoryRange() (uint64, uint64, error) { // IndexProgress returns the indexing progress made so far. It provides the // number of states that remain unindexed. -func (db *Database) IndexProgress() (uint64, error) { - if db.stateIndexer == nil { - return 0, nil +func (db *Database) IndexProgress() (uint64, uint64, error) { + var ( + stateProgress uint64 + trieProgress uint64 + ) + if db.stateIndexer != nil { + prog, err := db.stateIndexer.progress() + if err != nil { + return 0, 0, err + } + stateProgress = prog } - return db.stateIndexer.progress() + if db.trienodeIndexer != nil { + prog, err := db.trienodeIndexer.progress() + if err != nil { + return 0, 0, err + } + trieProgress = prog + } + return stateProgress, trieProgress, nil } // AccountIterator creates a new account iterator for the specified root hash and diff --git a/triedb/pathdb/database_test.go b/triedb/pathdb/database_test.go index 8ece83cad7..e70a3ec2a2 100644 --- a/triedb/pathdb/database_test.go +++ b/triedb/pathdb/database_test.go @@ -987,7 +987,7 @@ func TestDatabaseIndexRecovery(t *testing.T) { t.Fatalf("Unexpected state history found, %d", i) } } - remain, err := env.db.IndexProgress() + remain, _, err := env.db.IndexProgress() if err != nil { t.Fatalf("Failed to obtain the progress, %v", err) } @@ -1001,7 +1001,7 @@ func TestDatabaseIndexRecovery(t *testing.T) { panic(fmt.Errorf("failed to update state changes, err: %w", err)) } } - remain, err = env.db.IndexProgress() + remain, _, err = env.db.IndexProgress() if err != nil { t.Fatalf("Failed to obtain the progress, %v", err) }