Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,6 @@ func (ec *Client) GetTransactionReceiptResult(ctx context.Context, txHash common
return r, result, err
}

type rpcProgress struct {
StartingBlock hexutil.Uint64
CurrentBlock hexutil.Uint64
HighestBlock hexutil.Uint64
PulledStates hexutil.Uint64
KnownStates hexutil.Uint64
}

// SyncProgress retrieves the current progress of the sync algorithm. If there's
// no sync currently running, it returns nil.
func (ec *Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) {
Expand All @@ -330,17 +322,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 *rpcProgress
if err := json.Unmarshal(raw, &progress); err != nil {
var p *rpcProgress
if err := json.Unmarshal(raw, &p); err != nil {
return nil, err
}
return &ethereum.SyncProgress{
StartingBlock: uint64(progress.StartingBlock),
CurrentBlock: uint64(progress.CurrentBlock),
HighestBlock: uint64(progress.HighestBlock),
PulledStates: uint64(progress.PulledStates),
KnownStates: uint64(progress.KnownStates),
}, nil
return p.toSyncProgress(), nil
}

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

// rpcProgress is a copy of SyncProgress with hex-encoded fields.
type rpcProgress struct {
StartingBlock hexutil.Uint64
CurrentBlock hexutil.Uint64
HighestBlock hexutil.Uint64

PulledStates hexutil.Uint64
KnownStates 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),
}
}
7 changes: 5 additions & 2 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ type SyncProgress struct {
StartingBlock uint64 // Block number where sync began
CurrentBlock uint64 // Current block number where sync is at
HighestBlock uint64 // Highest alleged block number in the chain
PulledStates uint64 // Number of state trie entries already downloaded
KnownStates uint64 // Total number of state trie entries known about

// "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
}

// ChainSyncReader wraps access to the node's current sync status. If there's no
Expand Down