Skip to content

Commit 39255d7

Browse files
fjljagdeep sidhu
authored and
jagdeep sidhu
committed
ethclient: fix unmarshaling of ethereum.SyncProgress (ethereum#24199)
SyncProgress was modified in PR ethereum#23576 to add the fields reported for snap sync. The PR also changed ethclient to use the SyncProgress struct directly instead of wrapping it for hex-decoding. This broke the SyncProgress method. Fix it by putting back the custom wrapper. While here, also put back the fast sync related fields because SyncProgress is stable API and thus removing fields is not allowed. Fixes ethereum#24180 Fixes ethereum#24176
1 parent 9cd19ae commit 39255d7

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

ethclient/ethclient.go

+51-3
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ func (ec *Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, err
298298
if err := json.Unmarshal(raw, &syncing); err == nil {
299299
return nil, nil // Not syncing (always false)
300300
}
301-
var progress *ethereum.SyncProgress
302-
if err := json.Unmarshal(raw, &progress); err != nil {
301+
var p *rpcProgress
302+
if err := json.Unmarshal(raw, &p); err != nil {
303303
return nil, err
304304
}
305-
return progress, nil
305+
return p.toSyncProgress(), nil
306306
}
307307

308308
// SubscribeNewHead subscribes to notifications about the current blockchain head
@@ -542,3 +542,51 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
542542
}
543543
return arg
544544
}
545+
546+
// rpcProgress is a copy of SyncProgress with hex-encoded fields.
547+
type rpcProgress struct {
548+
StartingBlock hexutil.Uint64
549+
CurrentBlock hexutil.Uint64
550+
HighestBlock hexutil.Uint64
551+
552+
PulledStates hexutil.Uint64
553+
KnownStates hexutil.Uint64
554+
555+
SyncedAccounts hexutil.Uint64
556+
SyncedAccountBytes hexutil.Uint64
557+
SyncedBytecodes hexutil.Uint64
558+
SyncedBytecodeBytes hexutil.Uint64
559+
SyncedStorage hexutil.Uint64
560+
SyncedStorageBytes hexutil.Uint64
561+
HealedTrienodes hexutil.Uint64
562+
HealedTrienodeBytes hexutil.Uint64
563+
HealedBytecodes hexutil.Uint64
564+
HealedBytecodeBytes hexutil.Uint64
565+
HealingTrienodes hexutil.Uint64
566+
HealingBytecode hexutil.Uint64
567+
}
568+
569+
func (p *rpcProgress) toSyncProgress() *ethereum.SyncProgress {
570+
if p == nil {
571+
return nil
572+
}
573+
return &ethereum.SyncProgress{
574+
StartingBlock: uint64(p.StartingBlock),
575+
CurrentBlock: uint64(p.CurrentBlock),
576+
HighestBlock: uint64(p.HighestBlock),
577+
PulledStates: uint64(p.PulledStates),
578+
KnownStates: uint64(p.KnownStates),
579+
SyncedAccounts: uint64(p.SyncedAccounts),
580+
SyncedAccountBytes: uint64(p.SyncedAccountBytes),
581+
SyncedBytecodes: uint64(p.SyncedBytecodes),
582+
SyncedBytecodeBytes: uint64(p.SyncedBytecodeBytes),
583+
SyncedStorage: uint64(p.SyncedStorage),
584+
SyncedStorageBytes: uint64(p.SyncedStorageBytes),
585+
HealedTrienodes: uint64(p.HealedTrienodes),
586+
HealedTrienodeBytes: uint64(p.HealedTrienodeBytes),
587+
HealedBytecodes: uint64(p.HealedBytecodes),
588+
HealedBytecodeBytes: uint64(p.HealedBytecodeBytes),
589+
HealingTrienodes: uint64(p.HealingTrienodes),
590+
HealingBytecode: uint64(p.HealingBytecode),
591+
}
592+
}

interfaces.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ type SyncProgress struct {
102102
CurrentBlock uint64 // Current block number where sync is at
103103
HighestBlock uint64 // Highest alleged block number in the chain
104104

105-
// Fields belonging to snap sync
105+
// "fast sync" fields. These used to be sent by geth, but are no longer used
106+
// since version v1.10.
107+
PulledStates uint64 // Number of state trie entries already downloaded
108+
KnownStates uint64 // Total number of state trie entries known about
109+
110+
// "snap sync" fields.
106111
SyncedAccounts uint64 // Number of accounts downloaded
107112
SyncedAccountBytes uint64 // Number of account trie bytes persisted to disk
108113
SyncedBytecodes uint64 // Number of bytecodes downloaded

0 commit comments

Comments
 (0)