mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-11 14:54:12 +00:00
consistent peer scoring for missing non-finalized parent (#3381)
When the sync queue processes results for a blocks by range request, and the requested range contained some slots that are already finalized, `BlockError.MissingParent` currently leads to `PeerScoreBadBlocks` even when the error occurs on a non-finalized slot in the requested range. This patch changes the scoring in that case to `PeerScoreMissingBlocks` for consistency with range requests solely covering non-finalized slots, and, likewise, rewinds the sync queue to the next `rewindSlot`.
This commit is contained in:
parent
0410aec9d8
commit
3ba016d75f
@ -697,7 +697,7 @@ proc push*[T](sq: SyncQueue[T], sr: SyncRequest[T],
|
|||||||
safeSlot = sq.getSafeSlot()
|
safeSlot = sq.getSafeSlot()
|
||||||
case sq.kind
|
case sq.kind
|
||||||
of SyncQueueKind.Forward:
|
of SyncQueueKind.Forward:
|
||||||
if safeSlot < req.slot:
|
if safeSlot < failSlot:
|
||||||
let rewindSlot = sq.getRewindPoint(failSlot, safeSlot)
|
let rewindSlot = sq.getRewindPoint(failSlot, safeSlot)
|
||||||
debug "Unexpected missing parent, rewind happens",
|
debug "Unexpected missing parent, rewind happens",
|
||||||
request = req, rewind_to_slot = rewindSlot,
|
request = req, rewind_to_slot = rewindSlot,
|
||||||
@ -713,7 +713,7 @@ proc push*[T](sq: SyncQueue[T], sr: SyncRequest[T],
|
|||||||
blocks_map = getShortMap(req, item.data)
|
blocks_map = getShortMap(req, item.data)
|
||||||
req.item.updateScore(PeerScoreBadBlocks)
|
req.item.updateScore(PeerScoreBadBlocks)
|
||||||
of SyncQueueKind.Backward:
|
of SyncQueueKind.Backward:
|
||||||
if safeSlot > req.slot:
|
if safeSlot > failSlot:
|
||||||
let rewindSlot = sq.getRewindPoint(failSlot, safeSlot)
|
let rewindSlot = sq.getRewindPoint(failSlot, safeSlot)
|
||||||
# It's quite common peers give us fewer blocks than we ask for
|
# It's quite common peers give us fewer blocks than we ask for
|
||||||
info "Gap in block range response, rewinding", request = req,
|
info "Gap in block range response, rewinding", request = req,
|
||||||
|
@ -17,6 +17,7 @@ import ../beacon_chain/gossip_processing/block_processor,
|
|||||||
|
|
||||||
type
|
type
|
||||||
SomeTPeer = ref object
|
SomeTPeer = ref object
|
||||||
|
score: int
|
||||||
|
|
||||||
proc `$`(peer: SomeTPeer): string =
|
proc `$`(peer: SomeTPeer): string =
|
||||||
"SomeTPeer"
|
"SomeTPeer"
|
||||||
@ -25,7 +26,7 @@ template shortLog(peer: SomeTPeer): string =
|
|||||||
$peer
|
$peer
|
||||||
|
|
||||||
proc updateScore(peer: SomeTPeer, score: int) =
|
proc updateScore(peer: SomeTPeer, score: int) =
|
||||||
discard
|
peer[].score += score
|
||||||
|
|
||||||
func getStaticSlotCb(slot: Slot): GetSlotCallback =
|
func getStaticSlotCb(slot: Slot): GetSlotCallback =
|
||||||
proc getSlot(): Slot =
|
proc getSlot(): Slot =
|
||||||
@ -484,6 +485,7 @@ suite "SyncManager test suite":
|
|||||||
|
|
||||||
let p1 = SomeTPeer()
|
let p1 = SomeTPeer()
|
||||||
|
|
||||||
|
var expectedScore = 0
|
||||||
proc runTest() {.async.} =
|
proc runTest() {.async.} =
|
||||||
while true:
|
while true:
|
||||||
var request = queue.pop(finish, p1)
|
var request = queue.pop(finish, p1)
|
||||||
@ -499,6 +501,7 @@ suite "SyncManager test suite":
|
|||||||
response.delete(response.len - 2)
|
response.delete(response.len - 2)
|
||||||
of SyncQueueKind.Backward:
|
of SyncQueueKind.Backward:
|
||||||
response.delete(1)
|
response.delete(1)
|
||||||
|
expectedScore += PeerScoreMissingBlocks
|
||||||
if response.len >= 1:
|
if response.len >= 1:
|
||||||
# Ensure requested values are past `safeSlot`
|
# Ensure requested values are past `safeSlot`
|
||||||
case kkind
|
case kkind
|
||||||
@ -515,6 +518,7 @@ suite "SyncManager test suite":
|
|||||||
check (counter - 1) == int(finish)
|
check (counter - 1) == int(finish)
|
||||||
of SyncQueueKind.Backward:
|
of SyncQueueKind.Backward:
|
||||||
check (counter + 1) == int(start)
|
check (counter + 1) == int(start)
|
||||||
|
check p1.score >= expectedScore
|
||||||
|
|
||||||
template outOfBandAdvancementTest(kkind: SyncQueueKind, start, finish: Slot,
|
template outOfBandAdvancementTest(kkind: SyncQueueKind, start, finish: Slot,
|
||||||
chunkSize: uint64) =
|
chunkSize: uint64) =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user