ensure MAX_CHUNK_SIZE usage consistent in sync_protocol (#3615)
This commit is contained in:
parent
4a372410a4
commit
7bb40d28ae
|
@ -614,10 +614,10 @@ when useNativeSnappy:
|
||||||
else:
|
else:
|
||||||
include libp2p_streams_backend
|
include libp2p_streams_backend
|
||||||
|
|
||||||
func maxChunkSize(t: typedesc[bellatrix.SignedBeaconBlock]): uint32 =
|
func maxChunkSize*(t: typedesc[bellatrix.SignedBeaconBlock]): uint32 =
|
||||||
MAX_CHUNK_SIZE_BELLATRIX
|
MAX_CHUNK_SIZE_BELLATRIX
|
||||||
|
|
||||||
func maxChunkSize(t: typedesc): uint32 =
|
func maxChunkSize*(t: typedesc): uint32 =
|
||||||
MAX_CHUNK_SIZE
|
MAX_CHUNK_SIZE
|
||||||
|
|
||||||
proc makeEth2Request(peer: Peer, protocolId: string, requestBytes: Bytes,
|
proc makeEth2Request(peer: Peer, protocolId: string, requestBytes: Bytes,
|
||||||
|
|
|
@ -69,6 +69,11 @@ type
|
||||||
|
|
||||||
BlockRootsList* = List[Eth2Digest, Limit MAX_REQUEST_BLOCKS]
|
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*(
|
proc readChunkPayload*(
|
||||||
conn: Connection, peer: Peer, maxChunkSize: uint32,
|
conn: Connection, peer: Peer, maxChunkSize: uint32,
|
||||||
MsgType: type (ref ForkedSignedBeaconBlock)):
|
MsgType: type (ref ForkedSignedBeaconBlock)):
|
||||||
|
@ -82,22 +87,19 @@ proc readChunkPayload*(
|
||||||
# Ignores maxChunkSize; needs to be consistent formal parameters,
|
# Ignores maxChunkSize; needs to be consistent formal parameters,
|
||||||
# but this function is where that's determined.
|
# but this function is where that's determined.
|
||||||
if contextBytes == peer.network.forkDigests.phase0:
|
if contextBytes == peer.network.forkDigests.phase0:
|
||||||
let res = await readChunkPayload(
|
let res = await readChunkPayload(conn, peer, phase0.SignedBeaconBlock)
|
||||||
conn, peer, MAX_CHUNK_SIZE, phase0.SignedBeaconBlock)
|
|
||||||
if res.isOk:
|
if res.isOk:
|
||||||
return ok newClone(ForkedSignedBeaconBlock.init(res.get))
|
return ok newClone(ForkedSignedBeaconBlock.init(res.get))
|
||||||
else:
|
else:
|
||||||
return err(res.error)
|
return err(res.error)
|
||||||
elif contextBytes == peer.network.forkDigests.altair:
|
elif contextBytes == peer.network.forkDigests.altair:
|
||||||
let res = await readChunkPayload(
|
let res = await readChunkPayload(conn, peer, altair.SignedBeaconBlock)
|
||||||
conn, peer, MAX_CHUNK_SIZE, altair.SignedBeaconBlock)
|
|
||||||
if res.isOk:
|
if res.isOk:
|
||||||
return ok newClone(ForkedSignedBeaconBlock.init(res.get))
|
return ok newClone(ForkedSignedBeaconBlock.init(res.get))
|
||||||
else:
|
else:
|
||||||
return err(res.error)
|
return err(res.error)
|
||||||
elif contextBytes == peer.network.forkDigests.bellatrix:
|
elif contextBytes == peer.network.forkDigests.bellatrix:
|
||||||
let res = await readChunkPayload(
|
let res = await readChunkPayload(conn, peer, bellatrix.SignedBeaconBlock)
|
||||||
conn, peer, MAX_CHUNK_SIZE_BELLATRIX, bellatrix.SignedBeaconBlock)
|
|
||||||
if res.isOk:
|
if res.isOk:
|
||||||
return ok newClone(ForkedSignedBeaconBlock.init(res.get))
|
return ok newClone(ForkedSignedBeaconBlock.init(res.get))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue