eth: request id dispatcher and direct req/reply APIs (#23576)
* eth: request ID based message dispatcher * eth: fix dispatcher cancellation, rework fetchers idleness tracker * eth/downloader: drop peers who refuse to serve advertised chains
This commit is contained in:
@ -325,10 +325,10 @@ type healTask struct {
|
||||
codeTasks map[common.Hash]struct{} // Set of byte code tasks currently queued for retrieval
|
||||
}
|
||||
|
||||
// syncProgress is a database entry to allow suspending and resuming a snapshot state
|
||||
// SyncProgress is a database entry to allow suspending and resuming a snapshot state
|
||||
// sync. Opposed to full and fast sync, there is no way to restart a suspended
|
||||
// snap sync without prior knowledge of the suspension point.
|
||||
type syncProgress struct {
|
||||
type SyncProgress struct {
|
||||
Tasks []*accountTask // The suspended account tasks (contract tasks within)
|
||||
|
||||
// Status report during syncing phase
|
||||
@ -342,12 +342,15 @@ type syncProgress struct {
|
||||
// Status report during healing phase
|
||||
TrienodeHealSynced uint64 // Number of state trie nodes downloaded
|
||||
TrienodeHealBytes common.StorageSize // Number of state trie bytes persisted to disk
|
||||
TrienodeHealDups uint64 // Number of state trie nodes already processed
|
||||
TrienodeHealNops uint64 // Number of state trie nodes not requested
|
||||
BytecodeHealSynced uint64 // Number of bytecodes downloaded
|
||||
BytecodeHealBytes common.StorageSize // Number of bytecodes persisted to disk
|
||||
BytecodeHealDups uint64 // Number of bytecodes already processed
|
||||
BytecodeHealNops uint64 // Number of bytecodes not requested
|
||||
}
|
||||
|
||||
// SyncPending is analogous to SyncProgress, but it's used to report on pending
|
||||
// ephemeral sync progress that doesn't get persisted into the database.
|
||||
type SyncPending struct {
|
||||
TrienodeHeal uint64 // Number of state trie nodes pending
|
||||
BytecodeHeal uint64 // Number of bytecodes pending
|
||||
}
|
||||
|
||||
// SyncPeer abstracts out the methods required for a peer to be synced against
|
||||
@ -671,7 +674,7 @@ func (s *Syncer) Sync(root common.Hash, cancel chan struct{}) error {
|
||||
// loadSyncStatus retrieves a previously aborted sync status from the database,
|
||||
// or generates a fresh one if none is available.
|
||||
func (s *Syncer) loadSyncStatus() {
|
||||
var progress syncProgress
|
||||
var progress SyncProgress
|
||||
|
||||
if status := rawdb.ReadSnapshotSyncStatus(s.db); status != nil {
|
||||
if err := json.Unmarshal(status, &progress); err != nil {
|
||||
@ -775,7 +778,7 @@ func (s *Syncer) saveSyncStatus() {
|
||||
}
|
||||
}
|
||||
// Store the actual progress markers
|
||||
progress := &syncProgress{
|
||||
progress := &SyncProgress{
|
||||
Tasks: s.tasks,
|
||||
AccountSynced: s.accountSynced,
|
||||
AccountBytes: s.accountBytes,
|
||||
@ -795,6 +798,31 @@ func (s *Syncer) saveSyncStatus() {
|
||||
rawdb.WriteSnapshotSyncStatus(s.db, status)
|
||||
}
|
||||
|
||||
// Progress returns the snap sync status statistics.
|
||||
func (s *Syncer) Progress() (*SyncProgress, *SyncPending) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
progress := &SyncProgress{
|
||||
AccountSynced: s.accountSynced,
|
||||
AccountBytes: s.accountBytes,
|
||||
BytecodeSynced: s.bytecodeSynced,
|
||||
BytecodeBytes: s.bytecodeBytes,
|
||||
StorageSynced: s.storageSynced,
|
||||
StorageBytes: s.storageBytes,
|
||||
TrienodeHealSynced: s.trienodeHealSynced,
|
||||
TrienodeHealBytes: s.trienodeHealBytes,
|
||||
BytecodeHealSynced: s.bytecodeHealSynced,
|
||||
BytecodeHealBytes: s.bytecodeHealBytes,
|
||||
}
|
||||
pending := new(SyncPending)
|
||||
if s.healer != nil {
|
||||
pending.TrienodeHeal = uint64(len(s.healer.trieTasks))
|
||||
pending.BytecodeHeal = uint64(len(s.healer.codeTasks))
|
||||
}
|
||||
return progress, pending
|
||||
}
|
||||
|
||||
// cleanAccountTasks removes account range retrieval tasks that have already been
|
||||
// completed.
|
||||
func (s *Syncer) cleanAccountTasks() {
|
||||
|
Reference in New Issue
Block a user