Skip to content

Commit

Permalink
[rpc] query node for syncing calls (#4309)
Browse files Browse the repository at this point in the history
* [rpc] query node for syncing calls

Resolves #3966

* fix(downloader): do not underflow
  • Loading branch information
MaxMustermann2 authored Nov 25, 2022
1 parent 29bcc0c commit b11800f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
8 changes: 5 additions & 3 deletions hmy/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ func (d *Downloader) NumPeers() int {

// IsSyncing return the current sync status
func (d *Downloader) SyncStatus() (bool, uint64, uint64) {
current := d.bc.CurrentBlock().NumberU64()
syncing, target := d.status.get()
if !syncing {
target = d.bc.CurrentBlock().NumberU64()
if !syncing { // means synced
target = current
}
return syncing, target, 0
// isSyncing, target, blocks to target
return syncing, target, target - current
}

// SubscribeDownloadStarted subscribe download started
Expand Down
21 changes: 12 additions & 9 deletions rpc/harmony.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@ func (s *PublicHarmonyService) ProtocolVersion(
}
}

// 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 pears. In case it is synchronizing:
// - startingBlock: block number this node started to synchronise from
// - currentBlock: block number this node is currently importing
// - highestBlock: block number of the highest block header this node has received from peers
// - pulledStates: number of state entries processed until now
// - knownStates: number of known state entries that still need to be pulled
// Syncing returns false in case the node is in sync with the network
// With the current network height as well as the difference
func (s *PublicHarmonyService) Syncing(
ctx context.Context,
) (interface{}, error) {
// TODO(dm): find our Downloader module for syncing blocks
return false, nil
inSync, target, difference := s.hmy.NodeAPI.SyncStatus(s.hmy.ShardID)
return struct {
InSync bool `json:"in-sync"`
Target uint64 `json:"network-height"`
Delta uint64 `json:"difference"`
}{
InSync: inSync,
Target: target,
Delta: difference,
}, nil
}

// GasPrice returns a suggestion for a gas price.
Expand Down

0 comments on commit b11800f

Please sign in to comment.