fix addKnownToPeer in wire protocol handler

This commit is contained in:
jangko 2022-12-15 22:36:43 +07:00
parent 35e4607f87
commit eb701fd3d7
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 15 additions and 6 deletions

View File

@ -172,8 +172,11 @@ proc cleanupKnownByPeer(ctx: EthWireRef) =
proc addToKnownByPeer(ctx: EthWireRef, txHashes: openArray[Hash256], peer: Peer) =
var map: HashToTime
if not ctx.knownByPeer.take(peer, map):
ctx.knownByPeer.withValue(peer, val) do:
map = val[]
do:
map = newTable[Hash256, Time]()
ctx.knownByPeer[peer] = map
for txHash in txHashes:
if txHash notin map:
@ -184,8 +187,11 @@ proc addToKnownByPeer(ctx: EthWireRef,
peer: Peer,
newHashes: var seq[Hash256]) =
var map: HashToTime
if not ctx.knownByPeer.take(peer, map):
ctx.knownByPeer.withValue(peer, val) do:
map = val[]
do:
map = newTable[Hash256, Time]()
ctx.knownByPeer[peer] = map
newHashes = newSeqOfCap[Hash256](txHashes.len)
for txHash in txHashes:

View File

@ -117,12 +117,15 @@ proc cleanupKnownByPeer(ctx: LegacySyncRef) =
proc addToKnownByPeer(ctx: LegacySyncRef,
blockHash: Hash256,
peer: Peer): bool =
var map: HashToTime
if not ctx.knownByPeer.take(peer, map):
map = newTable[Hash256, Time]()
result = false
else:
ctx.knownByPeer.withValue(peer, val) do:
map = val[]
result = true
do:
map = newTable[Hash256, Time]()
ctx.knownByPeer[peer] = map
result = false
map[blockHash] = getTime()