From 7bb40d28ae50aaf729824ef5628976e4e995e918 Mon Sep 17 00:00:00 2001 From: tersec Date: Thu, 5 May 2022 09:17:14 +0000 Subject: [PATCH] ensure MAX_CHUNK_SIZE usage consistent in sync_protocol (#3615) --- beacon_chain/networking/eth2_network.nim | 4 ++-- beacon_chain/sync/sync_protocol.nim | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/beacon_chain/networking/eth2_network.nim b/beacon_chain/networking/eth2_network.nim index 2a630d451..86eccac8d 100644 --- a/beacon_chain/networking/eth2_network.nim +++ b/beacon_chain/networking/eth2_network.nim @@ -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, diff --git a/beacon_chain/sync/sync_protocol.nim b/beacon_chain/sync/sync_protocol.nim index e62fe0e20..92b6188b0 100644 --- a/beacon_chain/sync/sync_protocol.nim +++ b/beacon_chain/sync/sync_protocol.nim @@ -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: