From 4cf2ab661ca41b354e84b2f9eb7ad0e071dcd29e Mon Sep 17 00:00:00 2001 From: jangko Date: Mon, 5 Dec 2022 09:51:32 +0700 Subject: [PATCH] connect legacy sync to rpc/eth_syncing and graphql/syncing fix #1333 --- nimbus/sync/legacy.nim | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/nimbus/sync/legacy.nim b/nimbus/sync/legacy.nim index 9273f7540..12eedf5cc 100644 --- a/nimbus/sync/legacy.nim +++ b/nimbus/sync/legacy.nim @@ -61,8 +61,6 @@ type LegacySyncRef* = ref object workQueue: seq[WantedBlocks] - endBlockNumber: BlockNumber - finalizedBlock: BlockNumber # Block which was downloaded and verified chain: ChainRef peerPool: PeerPool trustedPeers: HashSet[Peer] @@ -71,6 +69,24 @@ type knownByPeer: Table[Peer, HashToTime] lastCleanup: Time + +# ------------------------------------------------------------------------------ +# Private functions: sync progress +# ------------------------------------------------------------------------------ + +template endBlockNumber(ctx: LegacySyncRef): BlockNumber = + ctx.chain.com.syncHighest + +template `endBlockNumber=`(ctx: LegacySyncRef, number: BlockNumber) = + ctx.chain.com.syncHighest = number + +# Block which was downloaded and verified +template finalizedBlock(ctx: LegacySyncRef): BlockNumber = + ctx.chain.com.syncCurrent + +template `finalizedBlock=`(ctx: LegacySyncRef, number: BlockNumber) = + ctx.chain.com.syncCurrent = number + # ------------------------------------------------------------------------------ # Private functions: peers related functions # ------------------------------------------------------------------------------ @@ -908,14 +924,16 @@ proc onPeerDisconnected(ctx: LegacySyncRef, p: Peer) = proc new*(T: type LegacySyncRef; ethNode: EthereumNode; chain: ChainRef): T {.gcsafe, raises:[Defect,CatchableError].} = - LegacySyncRef( + result = LegacySyncRef( # workQueue: n/a # endBlockNumber: n/a # hasOutOfOrderBlocks: n/a chain: chain, peerPool: ethNode.peerPool, - trustedPeers: initHashSet[Peer](), - finalizedBlock: chain.db.getCanonicalHead().blockNumber) + trustedPeers: initHashSet[Peer]()) + + # finalizedBlock + chain.com.syncCurrent = chain.db.getCanonicalHead().blockNumber proc start*(ctx: LegacySyncRef) = ## Code for the fast blockchain sync procedure: @@ -937,8 +955,9 @@ proc start*(ctx: LegacySyncRef) = debug "Fast sync is disabled after POS merge" return + ctx.chain.com.syncStart = ctx.finalizedBlock info "Fast Sync: start sync from", - number=ctx.finalizedBlock, + number=ctx.chain.com.syncStart, hash=blockHash except CatchableError as e: