Review comments by Dmitriy

This commit is contained in:
benbierens 2024-12-05 10:00:20 +01:00
parent 64e691b824
commit ed3e91cbde
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
2 changed files with 36 additions and 30 deletions

View File

@ -399,33 +399,15 @@ proc wantListHandler*(
address = e.address
wantType = $e.wantType
# Update metrics
if e.wantType == WantType.WantHave:
codex_block_exchange_want_have_lists_received.inc()
elif e.wantType == WantType.WantBlock:
codex_block_exchange_want_block_lists_received.inc()
# Update peerCtx
if idx < 0: # new entry
peerCtx.peerWants.add(e)
let
have = await e.address in b.localStore
price = @(
b.pricing.get(Pricing(price: 0.u256))
.price.toBytesBE)
if e.wantType == WantType.WantHave:
codex_block_exchange_want_have_lists_received.inc()
elif e.wantType == WantType.WantBlock:
codex_block_exchange_want_block_lists_received.inc()
if not have and e.sendDontHave:
presence.add(
BlockPresence(
address: e.address,
`type`: BlockPresenceType.DontHave,
price: price))
elif have and e.wantType == WantType.WantHave:
presence.add(
BlockPresence(
address: e.address,
`type`: BlockPresenceType.Have,
price: price))
else: # update existing entry
# peer doesn't want this block anymore
if e.cancel:
@ -435,13 +417,37 @@ proc wantListHandler*(
# different want params
peerCtx.peerWants[idx] = e # update entry
if not e.cancel:
# Respond to wantHaves immediately
if e.wantType == WantType.WantHave:
let
have = await e.address in b.localStore
price = @(
b.pricing.get(Pricing(price: 0.u256))
.price.toBytesBE)
if not have and e.sendDontHave:
presence.add(
BlockPresence(
address: e.address,
`type`: BlockPresenceType.DontHave,
price: price))
elif have:
presence.add(
BlockPresence(
address: e.address,
`type`: BlockPresenceType.Have,
price: price))
# Schedule handling of wantBlocks
if e.wantType == WantType.WantBlock:
if not b.scheduleTask(peerCtx):
warn "Unable to schedule task for peer", peer
if presence.len > 0:
trace "Sending presence to remote", items = presence.mapIt($it).join(",")
await b.network.request.sendPresence(peer, presence)
if not b.scheduleTask(peerCtx):
warn "Unable to schedule task for peer", peer
proc accountHandler*(
engine: BlockExcEngine,
peer: PeerId,

View File

@ -32,7 +32,7 @@ logScope:
type
PeerCtxStore* = ref object of RootObj
peers*: OrderedTable[PeerId, BlockExcPeerCtx]
PeersForBlock* = ref object of RootObj
PeersForBlock* = object of RootObj
with*: seq[BlockExcPeerCtx]
without*: seq[BlockExcPeerCtx]