mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-04-06 09:57:29 +00:00
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.
This commit is contained in:
parent
a608ac94ec
commit
d8cb8a962b
10 changed files with 40 additions and 16 deletions
|
|
@ -476,7 +476,7 @@ func (bc *BlockChain) TxIndexProgress() (TxIndexProgress, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateIndexProgress returns the historical state indexing progress.
|
// StateIndexProgress returns the historical state indexing progress.
|
||||||
func (bc *BlockChain) StateIndexProgress() (uint64, error) {
|
func (bc *BlockChain) StateIndexProgress() (uint64, uint64, error) {
|
||||||
return bc.triedb.IndexProgress()
|
return bc.triedb.IndexProgress()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -414,9 +414,10 @@ func (b *EthAPIBackend) SyncProgress(ctx context.Context) ethereum.SyncProgress
|
||||||
prog.TxIndexFinishedBlocks = txProg.Indexed
|
prog.TxIndexFinishedBlocks = txProg.Indexed
|
||||||
prog.TxIndexRemainingBlocks = txProg.Remaining
|
prog.TxIndexRemainingBlocks = txProg.Remaining
|
||||||
}
|
}
|
||||||
remain, err := b.eth.blockchain.StateIndexProgress()
|
stateRemain, trienodeRemain, err := b.eth.blockchain.StateIndexProgress()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
prog.StateIndexRemaining = remain
|
prog.StateIndexRemaining = stateRemain
|
||||||
|
prog.TrienodeIndexRemaining = trienodeRemain
|
||||||
}
|
}
|
||||||
return prog
|
return prog
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,10 @@ func (api *DownloaderAPI) eventLoop() {
|
||||||
prog.TxIndexFinishedBlocks = txProg.Indexed
|
prog.TxIndexFinishedBlocks = txProg.Indexed
|
||||||
prog.TxIndexRemainingBlocks = txProg.Remaining
|
prog.TxIndexRemainingBlocks = txProg.Remaining
|
||||||
}
|
}
|
||||||
remain, err := api.chain.StateIndexProgress()
|
stateRemain, trienodeRemain, err := api.chain.StateIndexProgress()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
prog.StateIndexRemaining = remain
|
prog.StateIndexRemaining = stateRemain
|
||||||
|
prog.TrienodeIndexRemaining = trienodeRemain
|
||||||
}
|
}
|
||||||
return prog
|
return prog
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -838,6 +838,7 @@ type rpcProgress struct {
|
||||||
TxIndexFinishedBlocks hexutil.Uint64
|
TxIndexFinishedBlocks hexutil.Uint64
|
||||||
TxIndexRemainingBlocks hexutil.Uint64
|
TxIndexRemainingBlocks hexutil.Uint64
|
||||||
StateIndexRemaining hexutil.Uint64
|
StateIndexRemaining hexutil.Uint64
|
||||||
|
TrienodeIndexRemaining hexutil.Uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *rpcProgress) toSyncProgress() *ethereum.SyncProgress {
|
func (p *rpcProgress) toSyncProgress() *ethereum.SyncProgress {
|
||||||
|
|
@ -865,6 +866,7 @@ func (p *rpcProgress) toSyncProgress() *ethereum.SyncProgress {
|
||||||
TxIndexFinishedBlocks: uint64(p.TxIndexFinishedBlocks),
|
TxIndexFinishedBlocks: uint64(p.TxIndexFinishedBlocks),
|
||||||
TxIndexRemainingBlocks: uint64(p.TxIndexRemainingBlocks),
|
TxIndexRemainingBlocks: uint64(p.TxIndexRemainingBlocks),
|
||||||
StateIndexRemaining: uint64(p.StateIndexRemaining),
|
StateIndexRemaining: uint64(p.StateIndexRemaining),
|
||||||
|
TrienodeIndexRemaining: uint64(p.TrienodeIndexRemaining),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1531,6 +1531,9 @@ func (s *SyncState) TxIndexRemainingBlocks() hexutil.Uint64 {
|
||||||
func (s *SyncState) StateIndexRemaining() hexutil.Uint64 {
|
func (s *SyncState) StateIndexRemaining() hexutil.Uint64 {
|
||||||
return hexutil.Uint64(s.progress.StateIndexRemaining)
|
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
|
// 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:
|
// yet received the latest block headers from its peers. In case it is synchronizing:
|
||||||
|
|
|
||||||
|
|
@ -139,8 +139,9 @@ type SyncProgress struct {
|
||||||
TxIndexFinishedBlocks uint64 // Number of blocks whose transactions are already indexed
|
TxIndexFinishedBlocks uint64 // Number of blocks whose transactions are already indexed
|
||||||
TxIndexRemainingBlocks uint64 // Number of blocks whose transactions are not indexed yet
|
TxIndexRemainingBlocks uint64 // Number of blocks whose transactions are not indexed yet
|
||||||
|
|
||||||
// "historical state indexing" fields
|
// "historical data indexing" fields
|
||||||
StateIndexRemaining uint64 // Number of states remain unindexed
|
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.
|
// 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 {
|
if prog.CurrentBlock < prog.HighestBlock {
|
||||||
return false
|
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
|
// ChainSyncReader wraps access to the node's current sync status. If there's no
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,7 @@ func (api *EthereumAPI) Syncing(ctx context.Context) (interface{}, error) {
|
||||||
"txIndexFinishedBlocks": hexutil.Uint64(progress.TxIndexFinishedBlocks),
|
"txIndexFinishedBlocks": hexutil.Uint64(progress.TxIndexFinishedBlocks),
|
||||||
"txIndexRemainingBlocks": hexutil.Uint64(progress.TxIndexRemainingBlocks),
|
"txIndexRemainingBlocks": hexutil.Uint64(progress.TxIndexRemainingBlocks),
|
||||||
"stateIndexRemaining": hexutil.Uint64(progress.StateIndexRemaining),
|
"stateIndexRemaining": hexutil.Uint64(progress.StateIndexRemaining),
|
||||||
|
"trienodeIndexRemaining": hexutil.Uint64(progress.TrienodeIndexRemaining),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
// IndexProgress returns the indexing progress made so far. It provides the
|
||||||
// number of states that remain unindexed.
|
// 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)
|
pdb, ok := db.backend.(*pathdb.Database)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, errors.New("not supported")
|
return 0, 0, errors.New("not supported")
|
||||||
}
|
}
|
||||||
return pdb.IndexProgress()
|
return pdb.IndexProgress()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -626,11 +626,26 @@ func (db *Database) HistoryRange() (uint64, uint64, error) {
|
||||||
|
|
||||||
// IndexProgress returns the indexing progress made so far. It provides the
|
// IndexProgress returns the indexing progress made so far. It provides the
|
||||||
// number of states that remain unindexed.
|
// number of states that remain unindexed.
|
||||||
func (db *Database) IndexProgress() (uint64, error) {
|
func (db *Database) IndexProgress() (uint64, uint64, error) {
|
||||||
if db.stateIndexer == nil {
|
var (
|
||||||
return 0, nil
|
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
|
// AccountIterator creates a new account iterator for the specified root hash and
|
||||||
|
|
|
||||||
|
|
@ -987,7 +987,7 @@ func TestDatabaseIndexRecovery(t *testing.T) {
|
||||||
t.Fatalf("Unexpected state history found, %d", i)
|
t.Fatalf("Unexpected state history found, %d", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remain, err := env.db.IndexProgress()
|
remain, _, err := env.db.IndexProgress()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to obtain the progress, %v", err)
|
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))
|
panic(fmt.Errorf("failed to update state changes, err: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remain, err = env.db.IndexProgress()
|
remain, _, err = env.db.IndexProgress()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to obtain the progress, %v", err)
|
t.Fatalf("Failed to obtain the progress, %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue