Skip to content

Commit

Permalink
Use discv5's maxDiscv5TalkRespPayload const for payload size calc (#2643
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kdeme authored Sep 19, 2024
1 parent a9ad10c commit c77c623
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
17 changes: 2 additions & 15 deletions fluffy/network/wire/portal_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,6 @@ const
## value in milliseconds
initialLookups = 1 ## Amount of lookups done when populating the routing table

# TalkResp message is a response message so the session is established and a
# regular discv5 packet is assumed for size calculation.
# Regular message = IV + header + message
# talkResp message = rlp: [request-id, response]
talkRespOverhead =
16 + # IV size
55 + # header size
1 + # talkResp msg id
3 + # rlp encoding outer list, max length will be encoded in 2 bytes
9 + # request id (max = 8) + 1 byte from rlp encoding byte string
3 + # rlp encoding response byte string, max length in 2 bytes
16 # HMAC

# These are the concurrent offers per Portal wire protocol that is running.
# Using the `offerQueue` allows for limiting the amount of offers send and
# thus how many streams can be started.
Expand Down Expand Up @@ -385,7 +372,7 @@ proc handleFindNodes(p: PortalProtocol, fn: FindNodesMessage): seq[byte] =
# will still be passed.
const
nodesOverhead = 1 + 1 + 4 # msg id + total + container offset
maxPayloadSize = maxDiscv5PacketSize - talkRespOverhead - nodesOverhead
maxPayloadSize = maxDiscv5TalkRespPayload - nodesOverhead
enrOverhead = 4 # per added ENR, 4 bytes offset overhead

let enrs = truncateEnrs(nodes, maxPayloadSize, enrOverhead)
Expand All @@ -402,7 +389,7 @@ proc handleFindContent(
): seq[byte] =
const
contentOverhead = 1 + 1 # msg id + SSZ Union selector
maxPayloadSize = maxDiscv5PacketSize - talkRespOverhead - contentOverhead
maxPayloadSize = maxDiscv5TalkRespPayload - contentOverhead
enrOverhead = 4 # per added ENR, 4 bytes offset overhead

let contentId = p.toContentId(fc.contentKey).valueOr:
Expand Down
2 changes: 1 addition & 1 deletion vendor/nim-eth

0 comments on commit c77c623

Please sign in to comment.