Slightly more validations
This commit is contained in:
parent
54f894fc7e
commit
b916b1e3e4
|
@ -122,6 +122,11 @@ p2pProtocol BeaconSync(version = 1,
|
||||||
let roots = r.get.roots
|
let roots = r.get.roots
|
||||||
debug "Received block roots", len = roots.len, peer
|
debug "Received block roots", len = roots.len, peer
|
||||||
if roots.len != 0:
|
if roots.len != 0:
|
||||||
|
if roots.len > MaxRootsToRequest:
|
||||||
|
# Attack?
|
||||||
|
await peer.disconnect(BreachOfProtocol, true)
|
||||||
|
break
|
||||||
|
|
||||||
let headers = await peer.getBeaconBlockHeaders(bestRoot, s, roots.len, 0)
|
let headers = await peer.getBeaconBlockHeaders(bestRoot, s, roots.len, 0)
|
||||||
var bodiesRequest = newSeqOfCap[Eth2Digest](roots.len)
|
var bodiesRequest = newSeqOfCap[Eth2Digest](roots.len)
|
||||||
for r in roots:
|
for r in roots:
|
||||||
|
@ -132,7 +137,7 @@ p2pProtocol BeaconSync(version = 1,
|
||||||
node.importBlocks(roots, headers.get.blockHeaders, bodies.get.blockBodies)
|
node.importBlocks(roots, headers.get.blockHeaders, bodies.get.blockBodies)
|
||||||
|
|
||||||
let lastSlot = roots[^1][1]
|
let lastSlot = roots[^1][1]
|
||||||
if roots.len >= MaxRootsToRequest:
|
if roots.len == MaxRootsToRequest:
|
||||||
# Next batch of roots starts with the last slot of the current one
|
# Next batch of roots starts with the last slot of the current one
|
||||||
# to make sure we did not miss any roots with this slot that did
|
# to make sure we did not miss any roots with this slot that did
|
||||||
# not fit into the response.
|
# not fit into the response.
|
||||||
|
@ -159,7 +164,7 @@ p2pProtocol BeaconSync(version = 1,
|
||||||
|
|
||||||
requestResponse:
|
requestResponse:
|
||||||
proc getBeaconBlockRoots(peer: Peer, fromSlot: Slot, maxRoots: int) =
|
proc getBeaconBlockRoots(peer: Peer, fromSlot: Slot, maxRoots: int) =
|
||||||
doAssert(maxRoots <= MaxRootsToRequest) # TODO: Validate maxRoots properly
|
let maxRoots = min(MaxRootsToRequest, maxRoots)
|
||||||
var s = fromSlot
|
var s = fromSlot
|
||||||
var roots = newSeqOfCap[(Eth2Digest, Slot)](maxRoots)
|
var roots = newSeqOfCap[(Eth2Digest, Slot)](maxRoots)
|
||||||
let blockPool = peer.networkState.node.blockPool
|
let blockPool = peer.networkState.node.blockPool
|
||||||
|
@ -180,7 +185,8 @@ p2pProtocol BeaconSync(version = 1,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
maxHeaders: int,
|
maxHeaders: int,
|
||||||
skipSlots: int) {.libp2pProtocol("rpc/beacon_block_headers", "1.0.0").} =
|
skipSlots: int) {.libp2pProtocol("rpc/beacon_block_headers", "1.0.0").} =
|
||||||
# TODO: validate maxHeaders and implement slipSlots
|
# TODO: validate implement slipSlots
|
||||||
|
let maxHeaders = min(MaxHeadersToRequest, maxHeaders)
|
||||||
var s = slot
|
var s = slot
|
||||||
var headers = newSeqOfCap[BeaconBlockHeaderRLP](maxHeaders)
|
var headers = newSeqOfCap[BeaconBlockHeaderRLP](maxHeaders)
|
||||||
let db = peer.networkState.db
|
let db = peer.networkState.db
|
||||||
|
|
Loading…
Reference in New Issue