connect legacy sync to rpc/eth_syncing and graphql/syncing

fix #1333
This commit is contained in:
jangko 2022-12-05 09:51:32 +07:00
parent 56f169b23e
commit 4cf2ab661c
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 25 additions and 6 deletions

View File

@ -61,8 +61,6 @@ type
LegacySyncRef* = ref object LegacySyncRef* = ref object
workQueue: seq[WantedBlocks] workQueue: seq[WantedBlocks]
endBlockNumber: BlockNumber
finalizedBlock: BlockNumber # Block which was downloaded and verified
chain: ChainRef chain: ChainRef
peerPool: PeerPool peerPool: PeerPool
trustedPeers: HashSet[Peer] trustedPeers: HashSet[Peer]
@ -71,6 +69,24 @@ type
knownByPeer: Table[Peer, HashToTime] knownByPeer: Table[Peer, HashToTime]
lastCleanup: Time 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 # 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 proc new*(T: type LegacySyncRef; ethNode: EthereumNode; chain: ChainRef): T
{.gcsafe, raises:[Defect,CatchableError].} = {.gcsafe, raises:[Defect,CatchableError].} =
LegacySyncRef( result = LegacySyncRef(
# workQueue: n/a # workQueue: n/a
# endBlockNumber: n/a # endBlockNumber: n/a
# hasOutOfOrderBlocks: n/a # hasOutOfOrderBlocks: n/a
chain: chain, chain: chain,
peerPool: ethNode.peerPool, peerPool: ethNode.peerPool,
trustedPeers: initHashSet[Peer](), trustedPeers: initHashSet[Peer]())
finalizedBlock: chain.db.getCanonicalHead().blockNumber)
# finalizedBlock
chain.com.syncCurrent = chain.db.getCanonicalHead().blockNumber
proc start*(ctx: LegacySyncRef) = proc start*(ctx: LegacySyncRef) =
## Code for the fast blockchain sync procedure: ## Code for the fast blockchain sync procedure:
@ -937,8 +955,9 @@ proc start*(ctx: LegacySyncRef) =
debug "Fast sync is disabled after POS merge" debug "Fast sync is disabled after POS merge"
return return
ctx.chain.com.syncStart = ctx.finalizedBlock
info "Fast Sync: start sync from", info "Fast Sync: start sync from",
number=ctx.finalizedBlock, number=ctx.chain.com.syncStart,
hash=blockHash hash=blockHash
except CatchableError as e: except CatchableError as e: