Review comments by Dmitriy
This commit is contained in:
parent
64e691b824
commit
ed3e91cbde
|
@ -399,33 +399,15 @@ proc wantListHandler*(
|
|||
address = e.address
|
||||
wantType = $e.wantType
|
||||
|
||||
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)
|
||||
|
||||
# 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()
|
||||
|
||||
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))
|
||||
|
||||
# Update peerCtx
|
||||
if idx < 0: # new entry
|
||||
peerCtx.peerWants.add(e)
|
||||
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,
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in New Issue