[rpc] query node for syncing calls (#4309)

* [rpc] query node for syncing calls

Resolves #3966

* fix(downloader): do not underflow
pull/4312/head
Max 2 years ago committed by GitHub
parent 29bcc0c48b
commit b11800fe3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      hmy/downloader/downloader.go
  2. 21
      rpc/harmony.go

@ -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

@ -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.

Loading…
Cancel
Save