mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-11 14:54:12 +00:00
rename PeerScoreXyzBlocks
-> PeerScoreXyzValues
(#4318)
The various `PeerScore` constants are used for both beacon blocks and LC objects, and will likely also find use for EIP4844 blob sidecars. Renaming them to use more generically applicable names not referring to blocks explicitly aymore.
This commit is contained in:
parent
94b3df25f8
commit
2eb56f6e1b
@ -28,15 +28,15 @@ const
|
|||||||
## Peer's latest head is lower then ours.
|
## Peer's latest head is lower then ours.
|
||||||
PeerScoreGoodStatus* = 50
|
PeerScoreGoodStatus* = 50
|
||||||
## Peer's `status` answer is fine.
|
## Peer's `status` answer is fine.
|
||||||
PeerScoreNoBlocks* = -100
|
PeerScoreNoValues* = -100
|
||||||
## Peer did not respond in time to a request.
|
## Peer did not respond in time to a request.
|
||||||
PeerScoreGoodBlocks* = 100
|
PeerScoreGoodValues* = 100
|
||||||
## Peer's answer to our request is fine.
|
## Peer's answer to our request is fine.
|
||||||
PeerScoreBadBlocks* = -1000
|
PeerScoreBadValues* = -1000
|
||||||
## Peer's response contains incorrect data.
|
## Peer's response contains incorrect data.
|
||||||
PeerScoreBadResponse* = -1000
|
PeerScoreBadResponse* = -1000
|
||||||
## Peer's response is not in requested range.
|
## Peer's response is not in requested range.
|
||||||
PeerScoreMissingBlocks* = -25
|
PeerScoreMissingValues* = -25
|
||||||
## Peer response contains too much missing data - this can happen either
|
## Peer response contains too much missing data - this can happen either
|
||||||
## because a long reorg happened or the peer is falsely trying to convince
|
## because a long reorg happened or the peer is falsely trying to convince
|
||||||
## us that a long reorg happened.
|
## us that a long reorg happened.
|
||||||
|
@ -245,29 +245,29 @@ proc workerTask[E](
|
|||||||
# Descore, received data is malformed
|
# Descore, received data is malformed
|
||||||
warn "Received invalid value", value = val.shortLog,
|
warn "Received invalid value", value = val.shortLog,
|
||||||
endpoint = E.name, peer, peer_score = peer.getScore()
|
endpoint = E.name, peer, peer_score = peer.getScore()
|
||||||
peer.updateScore(PeerScoreBadBlocks)
|
peer.updateScore(PeerScoreBadValues)
|
||||||
return didProgress
|
return didProgress
|
||||||
else:
|
else:
|
||||||
# Reward, peer returned something useful
|
# Reward, peer returned something useful
|
||||||
applyReward = true
|
applyReward = true
|
||||||
didProgress = true
|
didProgress = true
|
||||||
if applyReward:
|
if applyReward:
|
||||||
peer.updateScore(PeerScoreGoodBlocks)
|
peer.updateScore(PeerScoreGoodValues)
|
||||||
else:
|
else:
|
||||||
peer.updateScore(PeerScoreNoBlocks)
|
peer.updateScore(PeerScoreNoValues)
|
||||||
debug "Failed to receive value on request", value,
|
debug "Failed to receive value on request", value,
|
||||||
endpoint = E.name, peer, peer_score = peer.getScore()
|
endpoint = E.name, peer, peer_score = peer.getScore()
|
||||||
except ResponseError as exc:
|
except ResponseError as exc:
|
||||||
warn "Received invalid response", error = exc.msg,
|
warn "Received invalid response", error = exc.msg,
|
||||||
endpoint = E.name, peer, peer_score = peer.getScore()
|
endpoint = E.name, peer, peer_score = peer.getScore()
|
||||||
peer.updateScore(PeerScoreBadBlocks)
|
peer.updateScore(PeerScoreBadValues)
|
||||||
except CancelledError as exc:
|
except CancelledError as exc:
|
||||||
raise exc
|
raise exc
|
||||||
except PeerPoolError as exc:
|
except PeerPoolError as exc:
|
||||||
debug "Failed to acquire peer", exc = exc.msg
|
debug "Failed to acquire peer", exc = exc.msg
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
if peer != nil:
|
if peer != nil:
|
||||||
peer.updateScore(PeerScoreNoBlocks)
|
peer.updateScore(PeerScoreNoValues)
|
||||||
debug "Unexpected exception while receiving value", exc = exc.msg,
|
debug "Unexpected exception while receiving value", exc = exc.msg,
|
||||||
endpoint = E.name, peer, peer_score = peer.getScore()
|
endpoint = E.name, peer, peer_score = peer.getScore()
|
||||||
raise exc
|
raise exc
|
||||||
|
@ -110,7 +110,7 @@ proc fetchAncestorBlocksFromNetwork(rman: RequestManager,
|
|||||||
notice "Received invalid block",
|
notice "Received invalid block",
|
||||||
peer = peer, blocks = shortLog(items),
|
peer = peer, blocks = shortLog(items),
|
||||||
peer_score = peer.getScore()
|
peer_score = peer.getScore()
|
||||||
peer.updateScore(PeerScoreBadBlocks)
|
peer.updateScore(PeerScoreBadValues)
|
||||||
|
|
||||||
return # Stop processing this junk...
|
return # Stop processing this junk...
|
||||||
else:
|
else:
|
||||||
@ -123,17 +123,17 @@ proc fetchAncestorBlocksFromNetwork(rman: RequestManager,
|
|||||||
peer.updateScore(PeerScoreUnviableFork)
|
peer.updateScore(PeerScoreUnviableFork)
|
||||||
elif gotGoodBlock:
|
elif gotGoodBlock:
|
||||||
# We reward peer only if it returns something.
|
# We reward peer only if it returns something.
|
||||||
peer.updateScore(PeerScoreGoodBlocks)
|
peer.updateScore(PeerScoreGoodValues)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
peer.updateScore(PeerScoreBadResponse)
|
peer.updateScore(PeerScoreBadResponse)
|
||||||
else:
|
else:
|
||||||
peer.updateScore(PeerScoreNoBlocks)
|
peer.updateScore(PeerScoreNoValues)
|
||||||
|
|
||||||
except CancelledError as exc:
|
except CancelledError as exc:
|
||||||
raise exc
|
raise exc
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
peer.updateScore(PeerScoreNoBlocks)
|
peer.updateScore(PeerScoreNoValues)
|
||||||
debug "Error while fetching ancestor blocks", exc = exc.msg,
|
debug "Error while fetching ancestor blocks", exc = exc.msg,
|
||||||
items = shortLog(items), peer = peer, peer_score = peer.getScore()
|
items = shortLog(items), peer = peer, peer_score = peer.getScore()
|
||||||
raise exc
|
raise exc
|
||||||
|
@ -350,7 +350,7 @@ proc syncStep[A, B](man: SyncManager[A, B], index: int, peer: A) {.async.} =
|
|||||||
# However, we include the `backfill` slot in backward sync requests.
|
# However, we include the `backfill` slot in backward sync requests.
|
||||||
# If we receive an empty response to a request covering that slot,
|
# If we receive an empty response to a request covering that slot,
|
||||||
# we know that the response is incomplete and can descore.
|
# we know that the response is incomplete and can descore.
|
||||||
peer.updateScore(PeerScoreNoBlocks)
|
peer.updateScore(PeerScoreNoValues)
|
||||||
man.queue.push(req)
|
man.queue.push(req)
|
||||||
debug "Response does not include known-to-exist block", request = req
|
debug "Response does not include known-to-exist block", request = req
|
||||||
return
|
return
|
||||||
@ -360,7 +360,7 @@ proc syncStep[A, B](man: SyncManager[A, B], index: int, peer: A) {.async.} =
|
|||||||
await man.queue.push(req, data, proc() =
|
await man.queue.push(req, data, proc() =
|
||||||
man.workers[index].status = SyncWorkerStatus.Processing)
|
man.workers[index].status = SyncWorkerStatus.Processing)
|
||||||
else:
|
else:
|
||||||
peer.updateScore(PeerScoreNoBlocks)
|
peer.updateScore(PeerScoreNoValues)
|
||||||
man.queue.push(req)
|
man.queue.push(req)
|
||||||
debug "Failed to receive blocks on request", request = req
|
debug "Failed to receive blocks on request", request = req
|
||||||
return
|
return
|
||||||
|
@ -691,7 +691,7 @@ proc push*[T](sq: SyncQueue[T], sr: SyncRequest[T],
|
|||||||
notice "Received invalid sequence of blocks", request = req,
|
notice "Received invalid sequence of blocks", request = req,
|
||||||
blocks_count = len(item.data),
|
blocks_count = len(item.data),
|
||||||
blocks_map = getShortMap(req, item.data)
|
blocks_map = getShortMap(req, item.data)
|
||||||
req.item.updateScore(PeerScoreBadBlocks)
|
req.item.updateScore(PeerScoreBadValues)
|
||||||
break
|
break
|
||||||
|
|
||||||
# When errors happen while processing blocks, we retry the same request
|
# When errors happen while processing blocks, we retry the same request
|
||||||
@ -705,12 +705,12 @@ proc push*[T](sq: SyncQueue[T], sr: SyncRequest[T],
|
|||||||
if goodBlock.isSome():
|
if goodBlock.isSome():
|
||||||
# If there no error and response was not empty we should reward peer
|
# If there no error and response was not empty we should reward peer
|
||||||
# with some bonus score - not for duplicate blocks though.
|
# with some bonus score - not for duplicate blocks though.
|
||||||
item.request.item.updateScore(PeerScoreGoodBlocks)
|
item.request.item.updateScore(PeerScoreGoodValues)
|
||||||
item.request.item.updateStats(SyncResponseKind.Good, 1'u64)
|
item.request.item.updateStats(SyncResponseKind.Good, 1'u64)
|
||||||
|
|
||||||
# BlockProcessor reports good block, so we can reward all the peers
|
# BlockProcessor reports good block, so we can reward all the peers
|
||||||
# who sent us empty responses.
|
# who sent us empty responses.
|
||||||
sq.rewardForGaps(PeerScoreGoodBlocks)
|
sq.rewardForGaps(PeerScoreGoodValues)
|
||||||
sq.gapList.reset()
|
sq.gapList.reset()
|
||||||
else:
|
else:
|
||||||
# Response was empty
|
# Response was empty
|
||||||
@ -754,7 +754,7 @@ proc push*[T](sq: SyncQueue[T], sr: SyncRequest[T],
|
|||||||
gapsCount = len(sq.gapList)
|
gapsCount = len(sq.gapList)
|
||||||
|
|
||||||
# We should penalize all the peers which responded with gaps.
|
# We should penalize all the peers which responded with gaps.
|
||||||
sq.rewardForGaps(PeerScoreMissingBlocks)
|
sq.rewardForGaps(PeerScoreMissingValues)
|
||||||
sq.gapList.reset()
|
sq.gapList.reset()
|
||||||
|
|
||||||
case sq.kind
|
case sq.kind
|
||||||
@ -769,7 +769,7 @@ proc push*[T](sq: SyncQueue[T], sr: SyncRequest[T],
|
|||||||
blocks_count = len(item.data),
|
blocks_count = len(item.data),
|
||||||
blocks_map = getShortMap(req, item.data),
|
blocks_map = getShortMap(req, item.data),
|
||||||
gaps_count = gapsCount
|
gaps_count = gapsCount
|
||||||
req.item.updateScore(PeerScoreMissingBlocks)
|
req.item.updateScore(PeerScoreMissingValues)
|
||||||
else:
|
else:
|
||||||
if safeSlot < req.slot:
|
if safeSlot < req.slot:
|
||||||
let rewindSlot = sq.getRewindPoint(failSlot, safeSlot)
|
let rewindSlot = sq.getRewindPoint(failSlot, safeSlot)
|
||||||
@ -786,7 +786,7 @@ proc push*[T](sq: SyncQueue[T], sr: SyncRequest[T],
|
|||||||
blocks_count = len(item.data),
|
blocks_count = len(item.data),
|
||||||
blocks_map = getShortMap(req, item.data),
|
blocks_map = getShortMap(req, item.data),
|
||||||
gaps_count = gapsCount
|
gaps_count = gapsCount
|
||||||
req.item.updateScore(PeerScoreBadBlocks)
|
req.item.updateScore(PeerScoreBadValues)
|
||||||
of SyncQueueKind.Backward:
|
of SyncQueueKind.Backward:
|
||||||
if safeSlot > failSlot:
|
if safeSlot > failSlot:
|
||||||
let rewindSlot = sq.getRewindPoint(failSlot, safeSlot)
|
let rewindSlot = sq.getRewindPoint(failSlot, safeSlot)
|
||||||
@ -796,12 +796,12 @@ proc push*[T](sq: SyncQueue[T], sr: SyncRequest[T],
|
|||||||
finalized_slot = safeSlot, blocks_count = len(item.data),
|
finalized_slot = safeSlot, blocks_count = len(item.data),
|
||||||
blocks_map = getShortMap(req, item.data)
|
blocks_map = getShortMap(req, item.data)
|
||||||
resetSlot = some(rewindSlot)
|
resetSlot = some(rewindSlot)
|
||||||
req.item.updateScore(PeerScoreMissingBlocks)
|
req.item.updateScore(PeerScoreMissingValues)
|
||||||
else:
|
else:
|
||||||
error "Unexpected missing parent at safe slot", request = req,
|
error "Unexpected missing parent at safe slot", request = req,
|
||||||
to_slot = safeSlot, blocks_count = len(item.data),
|
to_slot = safeSlot, blocks_count = len(item.data),
|
||||||
blocks_map = getShortMap(req, item.data)
|
blocks_map = getShortMap(req, item.data)
|
||||||
req.item.updateScore(PeerScoreBadBlocks)
|
req.item.updateScore(PeerScoreBadValues)
|
||||||
|
|
||||||
if resetSlot.isSome():
|
if resetSlot.isSome():
|
||||||
await sq.resetWait(resetSlot)
|
await sq.resetWait(resetSlot)
|
||||||
|
@ -508,7 +508,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
|
expectedScore += PeerScoreMissingValues
|
||||||
if response.len >= 1:
|
if response.len >= 1:
|
||||||
# Ensure requested values are past `safeSlot`
|
# Ensure requested values are past `safeSlot`
|
||||||
case kkind
|
case kkind
|
||||||
|
Loading…
x
Reference in New Issue
Block a user