From b11800fe3f813b682c22f056d5b5ed4809c0da19 Mon Sep 17 00:00:00 2001 From: Max <82761650+MaxMustermann2@users.noreply.github.com> Date: Fri, 25 Nov 2022 16:18:48 +0000 Subject: [PATCH] [rpc] query node for syncing calls (#4309) * [rpc] query node for syncing calls Resolves #3966 * fix(downloader): do not underflow --- hmy/downloader/downloader.go | 8 +++++--- rpc/harmony.go | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/hmy/downloader/downloader.go b/hmy/downloader/downloader.go index c4bc633aa..f5ab8580b 100644 --- a/hmy/downloader/downloader.go +++ b/hmy/downloader/downloader.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 diff --git a/rpc/harmony.go b/rpc/harmony.go index 470ef6b2c..e1f794758 100644 --- a/rpc/harmony.go +++ b/rpc/harmony.go @@ -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.