ensure MAX_CHUNK_SIZE usage consistent in sync_protocol (#3615)

This commit is contained in:
tersec 2022-05-05 09:17:14 +00:00 committed by GitHub
parent 4a372410a4
commit 7bb40d28ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View File

@ -614,10 +614,10 @@ when useNativeSnappy:
else:
include libp2p_streams_backend
func maxChunkSize(t: typedesc[bellatrix.SignedBeaconBlock]): uint32 =
func maxChunkSize*(t: typedesc[bellatrix.SignedBeaconBlock]): uint32 =
MAX_CHUNK_SIZE_BELLATRIX
func maxChunkSize(t: typedesc): uint32 =
func maxChunkSize*(t: typedesc): uint32 =
MAX_CHUNK_SIZE
proc makeEth2Request(peer: Peer, protocolId: string, requestBytes: Bytes,

View File

@ -69,6 +69,11 @@ type
BlockRootsList* = List[Eth2Digest, Limit MAX_REQUEST_BLOCKS]
template readChunkPayload*(
conn: Connection, peer: Peer, MsgType: type ForkySignedBeaconBlock):
Future[NetRes[MsgType]] =
readChunkPayload(conn, peer, maxChunkSize(MsgType), MsgType)
proc readChunkPayload*(
conn: Connection, peer: Peer, maxChunkSize: uint32,
MsgType: type (ref ForkedSignedBeaconBlock)):
@ -82,22 +87,19 @@ proc readChunkPayload*(
# Ignores maxChunkSize; needs to be consistent formal parameters,
# but this function is where that's determined.
if contextBytes == peer.network.forkDigests.phase0:
let res = await readChunkPayload(
conn, peer, MAX_CHUNK_SIZE, phase0.SignedBeaconBlock)
let res = await readChunkPayload(conn, peer, phase0.SignedBeaconBlock)
if res.isOk:
return ok newClone(ForkedSignedBeaconBlock.init(res.get))
else:
return err(res.error)
elif contextBytes == peer.network.forkDigests.altair:
let res = await readChunkPayload(
conn, peer, MAX_CHUNK_SIZE, altair.SignedBeaconBlock)
let res = await readChunkPayload(conn, peer, altair.SignedBeaconBlock)
if res.isOk:
return ok newClone(ForkedSignedBeaconBlock.init(res.get))
else:
return err(res.error)
elif contextBytes == peer.network.forkDigests.bellatrix:
let res = await readChunkPayload(
conn, peer, MAX_CHUNK_SIZE_BELLATRIX, bellatrix.SignedBeaconBlock)
let res = await readChunkPayload(conn, peer, bellatrix.SignedBeaconBlock)
if res.isOk:
return ok newClone(ForkedSignedBeaconBlock.init(res.get))
else: