More chatty syncing
This commit is contained in:
parent
b3d23c052c
commit
406df9d44f
|
@ -393,8 +393,7 @@ proc fetchBlocks(node: BeaconNode, roots: seq[Eth2Digest]) =
|
|||
|
||||
proc onFetchBlocks(node: BeaconNode, roots: seq[Eth2Digest]) =
|
||||
# TODO placeholder logic for block recovery
|
||||
debug "fetchBlocks received",
|
||||
roots = roots.len
|
||||
debug "fetchBlocks received", roots = roots.len
|
||||
for root in roots:
|
||||
if (let blck = node.db.getBlock(root); blck.isSome()):
|
||||
# TODO should never fail - asyncCheck is wrong here..
|
||||
|
@ -421,6 +420,8 @@ proc onBeaconBlock(node: BeaconNode, blck: BeaconBlock) =
|
|||
|
||||
if node.blockPool.add(node.state, blockRoot, blck).isNil:
|
||||
# TODO this will cause us to fetch parent, even for invalid blocks.. fix
|
||||
debug "Missing block detected. Fetching from network",
|
||||
`block` = blck.previous_block_root
|
||||
node.fetchBlocks(@[blck.previous_block_root])
|
||||
return
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import
|
||||
hashes, math, json,
|
||||
eth/[common, rlp],
|
||||
chronicles, eth/[common, rlp],
|
||||
./bitfield, ./crypto, ./digest
|
||||
|
||||
# TODO Data types:
|
||||
|
@ -618,6 +618,11 @@ func shortLog*(v: AttestationData): tuple[
|
|||
shortLog(v.crosslink_data_root)
|
||||
)
|
||||
|
||||
chronicles.formatIt Slot: it.humaneSlotNum
|
||||
chronicles.formatIt Epoch: it.humaneEpochNum
|
||||
chronicles.formatIt BeaconBlock: it.shortLog
|
||||
chronicles.formatIt AttestationData: it.shortLog
|
||||
|
||||
import nimcrypto, json_serialization
|
||||
export json_serialization
|
||||
export writeValue, readValue, append, read
|
||||
|
|
|
@ -97,6 +97,8 @@ p2pProtocol BeaconSync(version = 1,
|
|||
# where it needs to sync and it should execute the sync algorithm with a certain
|
||||
# number of randomly selected peers. The algorithm itself must be extracted in a proc.
|
||||
try:
|
||||
debug "Peer connected. Initiating sync", peer
|
||||
|
||||
let bestDiff = cmp((latestFinalizedEpoch, bestSlot), (m.latestFinalizedEpoch, m.bestSlot))
|
||||
if bestDiff == 0:
|
||||
# Nothing to do?
|
||||
|
@ -115,16 +117,23 @@ p2pProtocol BeaconSync(version = 1,
|
|||
for r in blockPool.blockRootsForSlot(i.Slot):
|
||||
roots.add((r, i.Slot))
|
||||
|
||||
debug "Sending block roots", peer, coveredSlots = roots.len
|
||||
await peer.beaconBlockRoots(roots)
|
||||
else:
|
||||
# Receive roots
|
||||
debug "Waiting for block roots", fromPeer = peer
|
||||
let roots = await peer.nextMsg(BeaconSync.beaconBlockRoots)
|
||||
|
||||
debug "Block roots received. Requesting block headers", bestRoot, bestSlot
|
||||
let headers = await peer.getBeaconBlockHeaders(bestRoot, bestSlot, roots.roots.len, 0)
|
||||
var bodiesRequest = newSeqOfCap[Eth2Digest](roots.roots.len)
|
||||
for r in roots.roots:
|
||||
bodiesRequest.add(r[0])
|
||||
|
||||
debug "Block headers received. Requesting block bodies", blocks = bodiesRequest
|
||||
let bodies = await peer.getBeaconBlockBodies(bodiesRequest)
|
||||
node.importBlocks(roots.roots, headers.get.blockHeaders, bodies.get.blockBodies)
|
||||
|
||||
except CatchableError:
|
||||
warn "Failed to sync with peer", peer, err = getCurrentExceptionMsg()
|
||||
|
||||
|
|
|
@ -8,12 +8,15 @@ source "$NETWORK_NAME.env"
|
|||
|
||||
cd ..
|
||||
|
||||
NIM_FLAGS="-d:release --lineTrace:on -d:SECONDS_PER_SLOT=$SECONDS_PER_SLOT -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH"
|
||||
nim c $NIM_FLAGS beacon_chain/beacon_node
|
||||
NIM_FLAGS="-d:release --lineTrace:on -d:chronicles_log_level=DEBUG -d:SECONDS_PER_SLOT=$SECONDS_PER_SLOT -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH"
|
||||
|
||||
BEACON_NODE_BIN=${NETWORK_NAME}_node
|
||||
|
||||
nim c $NIM_FLAGS -o:$BEACON_NODE_BIN beacon_chain/beacon_node
|
||||
|
||||
if [ ! -d ~/.cache/nimbus/BeaconNode/$NETWORK_NAME/validators ]; then
|
||||
beacon_chain/beacon_node --network=$NETWORK_NAME importValidator
|
||||
$BEACON_NODE_BIN --network=$NETWORK_NAME importValidator
|
||||
fi
|
||||
|
||||
beacon_chain/beacon_node --network=$NETWORK_NAME
|
||||
$BEACON_NODE_BIN --network=$NETWORK_NAME
|
||||
|
||||
|
|
Loading…
Reference in New Issue