From 38f48753b22c12e9514d2e8e3e2d0aeef51f48b9 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Tue, 5 Mar 2019 15:55:09 +0200 Subject: [PATCH] Comments on #117 addressed (#154) --- beacon_chain/sync_protocol.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/beacon_chain/sync_protocol.nim b/beacon_chain/sync_protocol.nim index c651d63deb..f635ebb2d9 100644 --- a/beacon_chain/sync_protocol.nim +++ b/beacon_chain/sync_protocol.nim @@ -29,13 +29,15 @@ func toHeader(b: BeaconBlock): BeaconBlockHeader = body: hash_tree_root_final(b.body) ) -proc fromHeader(b: var BeaconBlock, h: BeaconBlockHeader) = +proc fromHeaderAndBody(b: var BeaconBlock, h: BeaconBlockHeader, body: BeaconBlockBody) = + assert(hash_tree_root_final(body) == h.body) b.slot = h.slot b.parent_root = h.parent_root b.state_root = h.state_root b.randao_reveal = h.randao_reveal b.eth1_data = h.eth1_data b.signature = h.signature + b.body = body proc importBlocks(node: BeaconNode, roots: openarray[(Eth2Digest, uint64)], headers: openarray[BeaconBlockHeader], bodies: openarray[BeaconBlockBody]) = var bodyMap = initTable[Eth2Digest, int]() @@ -48,8 +50,7 @@ proc importBlocks(node: BeaconNode, roots: openarray[(Eth2Digest, uint64)], head let iBody = bodyMap.getOrDefault(h.body, -1) if iBody >= 0: var blk: BeaconBlock - blk.fromHeader(h) - blk.body = bodies[iBody] + blk.fromHeaderAndBody(h, bodies[iBody]) node.onBeaconBlock(blk) inc goodBlocks else: @@ -115,7 +116,7 @@ p2pProtocol BeaconSync(version = 1, requestResponse: proc getBeaconBlockHeaders(peer: Peer, blockRoot: Eth2Digest, slot: uint64, maxHeaders: int, skipSlots: int) = - # TODO: validate maxHeaders + # TODO: validate maxHeaders and implement slipSlots var s = slot var headers = newSeqOfCap[BeaconBlockHeader](maxHeaders) let db = peer.networkState.db