mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-09 22:06:21 +00:00
f70aceef37
* Harden handling of unviable forks In our current handling of unviable forks, we allow peers to send us blocks that come from a different fork - this is not necessarily an error as it can happen naturally, but it does open up the client to a case where the same unviable fork keeps getting requested - rather than allowing this to happen, we'll now give these peers a small negative score - if it keeps happening, we'll disconnect them. * keep track of unviable forks in quarantine, to avoid filling it with known junk * collect peer scores in single module * descore peers when they send unviable blocks during sync * don't give score for duplicate blocks * increase quarantine size to a level that allows finality to happen under optimal conditions - this helps avoid downloading the same blocks over and over in case of an unviable fork * increase initial score for new peers to make room for one more failure before disconnection * log and score invalid/unviable blocks in requestmanager too * avoid ChainDAG dependency in quarantine * reject gossip blocks with unviable parent * continue processing unviable sync blocks in order to build unviable dag * docs * Update beacon_chain/consensus_object_pools/block_pools_types.nim * add unviable queue test
60 lines
1.8 KiB
Nim
60 lines
1.8 KiB
Nim
# beacon_chain
|
|
# Copyright (c) 2022 Status Research & Development GmbH
|
|
# Licensed and distributed under either of
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
{.used.}
|
|
|
|
import
|
|
chronicles,
|
|
unittest2,
|
|
../beacon_chain/spec/forks,
|
|
../beacon_chain/spec/datatypes/phase0,
|
|
../beacon_chain/consensus_object_pools/block_quarantine
|
|
|
|
proc makeBlock(slot: Slot, parent: Eth2Digest): ForkedSignedBeaconBlock =
|
|
var
|
|
b = phase0.SignedBeaconBlock(
|
|
message: phase0.BeaconBlock(slot: slot, parent_root: parent))
|
|
b.root = hash_tree_root(b.message)
|
|
ForkedSignedBeaconBlock.init(b)
|
|
|
|
suite "Block quarantine":
|
|
test "Unviable smoke test":
|
|
let
|
|
b0 = makeBlock(Slot 0, Eth2Digest())
|
|
b1 = makeBlock(Slot 1, b0.root)
|
|
b2 = makeBlock(Slot 2, b1.root)
|
|
b3 = makeBlock(Slot 3, b2.root)
|
|
b4 = makeBlock(Slot 4, b2.root)
|
|
|
|
var quarantine: Quarantine
|
|
|
|
quarantine.addMissing(b1.root)
|
|
check:
|
|
FetchRecord(root: b1.root) in quarantine.checkMissing()
|
|
|
|
quarantine.addOrphan(Slot 0, b1)
|
|
|
|
FetchRecord(root: b1.root) notin quarantine.checkMissing()
|
|
|
|
quarantine.addOrphan(Slot 0, b2)
|
|
quarantine.addOrphan(Slot 0, b3)
|
|
quarantine.addOrphan(Slot 0, b4)
|
|
|
|
(b4.root, ValidatorSig()) in quarantine.orphans
|
|
|
|
quarantine.addUnviable(b4.root)
|
|
|
|
check:
|
|
(b4.root, ValidatorSig()) notin quarantine.orphans
|
|
|
|
quarantine.addUnviable(b1.root)
|
|
|
|
check:
|
|
(b1.root, ValidatorSig()) notin quarantine.orphans
|
|
(b2.root, ValidatorSig()) notin quarantine.orphans
|
|
(b3.root, ValidatorSig()) notin quarantine.orphans
|