mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-12 03:57:05 +00:00
* Update sync scheduler pool mode why: The pool mode allows to loop over active peers one after another. This is ideal for soft re-starting peers. As this is a two tier experience (start/stop, setup/release) the loop must be run twice. This is controlled by a more rigid re-definition of how to use the `poolMode` flag. * Mitigate RLP serialiser deficiency why: Currently, serialising the `BlockBody` in not conevrtible and need to be checked in the `eth` module. Currently a local fix for the wire protocol applies. Unit tests will stay (after this local solution will have been removed.) * Code cosmetics and massage details: Main part is `types.toStr()` as a unified function for logging block numbers. * Allow to use a logical genesis replacement (start of history) why: Snap sync will set up an arbitrary pivot at a block number different from zero. In fact, the higher the block number the better. details: A non-genesis start of history will currently only affect the score values which were derived from the difficulty. * Provide function to store the snap pivot block header in chain db why: Together with the start of history facility, this allows to proceed with full syncing once snap has finished. details: Snap db storage was switched from a sub-tables to the flat chain db. * Provide database completeness and sanity checker details: For debugging on smaller databases, only * Implement snap -> full sync switch
121 lines
3.3 KiB
Nim
121 lines
3.3 KiB
Nim
# Nimbus
|
|
# Copyright (c) 2021 Status Research & Development GmbH
|
|
# Licensed under either of
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
# http://opensource.org/licenses/MIT)
|
|
# at your option. This file may not be copied, modified, or distributed
|
|
# except according to those terms.
|
|
|
|
{.push raises: [].}
|
|
|
|
import
|
|
chronos,
|
|
eth/[common, p2p],
|
|
stew/byteutils,
|
|
"../../.."/[protocol, types],
|
|
../../worker_desc,
|
|
./com_error
|
|
|
|
logScope:
|
|
topics = "snap-fetch"
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public functions
|
|
# ------------------------------------------------------------------------------
|
|
|
|
proc getBlockHeader*(
|
|
buddy: SnapBuddyRef;
|
|
num: BlockNumber;
|
|
): Future[Result[BlockHeader,ComError]]
|
|
{.async.} =
|
|
## Get single block header
|
|
let
|
|
peer = buddy.peer
|
|
reqLen = 1u
|
|
hdrReq = BlocksRequest(
|
|
startBlock: HashOrNum(
|
|
isHash: false,
|
|
number: num),
|
|
maxResults: reqLen,
|
|
skip: 0,
|
|
reverse: false)
|
|
|
|
trace trEthSendSendingGetBlockHeaders, peer, header=num.toStr, reqLen
|
|
|
|
var hdrResp: Option[blockHeadersObj]
|
|
try:
|
|
hdrResp = await peer.getBlockHeaders(hdrReq)
|
|
except CatchableError as e:
|
|
trace trSnapRecvError & "waiting for GetByteCodes reply", peer,
|
|
error=e.msg
|
|
return err(ComNetworkProblem)
|
|
|
|
var hdrRespLen = 0
|
|
if hdrResp.isSome:
|
|
hdrRespLen = hdrResp.get.headers.len
|
|
if hdrRespLen == 0:
|
|
trace trEthRecvReceivedBlockHeaders, peer, reqLen, respose="n/a"
|
|
return err(ComNoHeaderAvailable)
|
|
|
|
if hdrRespLen == 1:
|
|
let
|
|
header = hdrResp.get.headers[0]
|
|
blockNumber = header.blockNumber
|
|
trace trEthRecvReceivedBlockHeaders, peer, hdrRespLen, blockNumber
|
|
return ok(header)
|
|
|
|
trace trEthRecvReceivedBlockHeaders, peer, reqLen, hdrRespLen
|
|
return err(ComTooManyHeaders)
|
|
|
|
|
|
proc getBlockHeader*(
|
|
buddy: SnapBuddyRef;
|
|
hash: Hash256;
|
|
): Future[Result[BlockHeader,ComError]]
|
|
{.async.} =
|
|
## Get single block header
|
|
let
|
|
peer = buddy.peer
|
|
reqLen = 1u
|
|
hdrReq = BlocksRequest(
|
|
startBlock: HashOrNum(
|
|
isHash: true,
|
|
hash: hash),
|
|
maxResults: reqLen,
|
|
skip: 0,
|
|
reverse: false)
|
|
|
|
trace trEthSendSendingGetBlockHeaders, peer,
|
|
header=hash.data.toHex, reqLen
|
|
|
|
var hdrResp: Option[blockHeadersObj]
|
|
try:
|
|
hdrResp = await peer.getBlockHeaders(hdrReq)
|
|
except CatchableError as e:
|
|
trace trSnapRecvError & "waiting for GetByteCodes reply", peer,
|
|
error=e.msg
|
|
return err(ComNetworkProblem)
|
|
|
|
var hdrRespLen = 0
|
|
if hdrResp.isSome:
|
|
hdrRespLen = hdrResp.get.headers.len
|
|
if hdrRespLen == 0:
|
|
trace trEthRecvReceivedBlockHeaders, peer, reqLen, respose="n/a"
|
|
return err(ComNoHeaderAvailable)
|
|
|
|
if hdrRespLen == 1:
|
|
let
|
|
header = hdrResp.get.headers[0]
|
|
blockNumber = header.blockNumber
|
|
trace trEthRecvReceivedBlockHeaders, peer, hdrRespLen, blockNumber
|
|
return ok(header)
|
|
|
|
trace trEthRecvReceivedBlockHeaders, peer, reqLen, hdrRespLen
|
|
return err(ComTooManyHeaders)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# End
|
|
# ------------------------------------------------------------------------------
|