Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ethclient: fix unmarshaling of ethereum.SyncProgress #24199

Merged
merged 1 commit into from Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 51 additions & 3 deletions ethclient/ethclient.go
Expand Up @@ -298,11 +298,11 @@ func (ec *Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, err
if err := json.Unmarshal(raw, &syncing); err == nil {
return nil, nil // Not syncing (always false)
}
var progress *ethereum.SyncProgress
if err := json.Unmarshal(raw, &progress); err != nil {
var p *rpcProgress
if err := json.Unmarshal(raw, &p); err != nil {
return nil, err
}
return progress, nil
return p.toSyncProgress(), nil
}

// SubscribeNewHead subscribes to notifications about the current blockchain head
Expand Down Expand Up @@ -542,3 +542,51 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
}
return arg
}

// rpcProgress is a copy of SyncProgress with hex-encoded fields.
type rpcProgress struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these have json tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They didn't have before because all the fields work with the default mapping, and this struct is only used for decoding.

StartingBlock hexutil.Uint64
CurrentBlock hexutil.Uint64
HighestBlock hexutil.Uint64

PulledStates hexutil.Uint64
KnownStates hexutil.Uint64

SyncedAccounts hexutil.Uint64
SyncedAccountBytes hexutil.Uint64
SyncedBytecodes hexutil.Uint64
SyncedBytecodeBytes hexutil.Uint64
SyncedStorage hexutil.Uint64
SyncedStorageBytes hexutil.Uint64
HealedTrienodes hexutil.Uint64
HealedTrienodeBytes hexutil.Uint64
HealedBytecodes hexutil.Uint64
HealedBytecodeBytes hexutil.Uint64
HealingTrienodes hexutil.Uint64
HealingBytecode hexutil.Uint64
}

func (p *rpcProgress) toSyncProgress() *ethereum.SyncProgress {
if p == nil {
return nil
}
return &ethereum.SyncProgress{
StartingBlock: uint64(p.StartingBlock),
CurrentBlock: uint64(p.CurrentBlock),
HighestBlock: uint64(p.HighestBlock),
PulledStates: uint64(p.PulledStates),
KnownStates: uint64(p.KnownStates),
SyncedAccounts: uint64(p.SyncedAccounts),
SyncedAccountBytes: uint64(p.SyncedAccountBytes),
SyncedBytecodes: uint64(p.SyncedBytecodes),
SyncedBytecodeBytes: uint64(p.SyncedBytecodeBytes),
SyncedStorage: uint64(p.SyncedStorage),
SyncedStorageBytes: uint64(p.SyncedStorageBytes),
HealedTrienodes: uint64(p.HealedTrienodes),
HealedTrienodeBytes: uint64(p.HealedTrienodeBytes),
HealedBytecodes: uint64(p.HealedBytecodes),
HealedBytecodeBytes: uint64(p.HealedBytecodeBytes),
HealingTrienodes: uint64(p.HealingTrienodes),
HealingBytecode: uint64(p.HealingBytecode),
}
}
7 changes: 6 additions & 1 deletion interfaces.go
Expand Up @@ -102,7 +102,12 @@ type SyncProgress struct {
CurrentBlock uint64 // Current block number where sync is at
HighestBlock uint64 // Highest alleged block number in the chain

// Fields belonging to snap sync
// "fast sync" fields. These used to be sent by geth, but are no longer used
// since version v1.10.
PulledStates uint64 // Number of state trie entries already downloaded
KnownStates uint64 // Total number of state trie entries known about

// "snap sync" fields.
SyncedAccounts uint64 // Number of accounts downloaded
SyncedAccountBytes uint64 // Number of account trie bytes persisted to disk
SyncedBytecodes uint64 // Number of bytecodes downloaded
Expand Down