2022-01-26 12:20:08 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
2022-01-26 12:20:08 +00:00
|
|
|
# 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.
|
|
|
|
|
2024-02-29 13:24:08 +00:00
|
|
|
{.push raises: [].}
|
2022-01-26 12:20:08 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
unittest2,
|
|
|
|
../beacon_chain/spec/forks,
|
2023-03-09 00:34:17 +00:00
|
|
|
../beacon_chain/spec/datatypes/[phase0, deneb],
|
2022-01-26 12:20:08 +00:00
|
|
|
../beacon_chain/consensus_object_pools/block_quarantine
|
|
|
|
|
2022-02-17 11:53:55 +00:00
|
|
|
func makeBlock(slot: Slot, parent: Eth2Digest): ForkedSignedBeaconBlock =
|
2022-01-26 12:20:08 +00:00
|
|
|
var
|
|
|
|
b = phase0.SignedBeaconBlock(
|
|
|
|
message: phase0.BeaconBlock(slot: slot, parent_root: parent))
|
|
|
|
b.root = hash_tree_root(b.message)
|
|
|
|
ForkedSignedBeaconBlock.init(b)
|
|
|
|
|
2023-04-13 19:11:40 +00:00
|
|
|
func makeBlobbyBlock(slot: Slot, parent: Eth2Digest): deneb.SignedBeaconBlock =
|
|
|
|
var
|
|
|
|
b = deneb.SignedBeaconBlock(
|
|
|
|
message: deneb.BeaconBlock(slot: slot, parent_root: parent))
|
|
|
|
b.root = hash_tree_root(b.message)
|
|
|
|
b
|
|
|
|
|
2022-01-26 12:20:08 +00:00
|
|
|
suite "Block quarantine":
|
|
|
|
test "Unviable smoke test":
|
|
|
|
let
|
2022-06-18 04:57:37 +00:00
|
|
|
b0 = makeBlock(Slot 0, ZERO_HASH)
|
2022-01-26 12:20:08 +00:00
|
|
|
b1 = makeBlock(Slot 1, b0.root)
|
|
|
|
b2 = makeBlock(Slot 2, b1.root)
|
|
|
|
b3 = makeBlock(Slot 3, b2.root)
|
|
|
|
b4 = makeBlock(Slot 4, b2.root)
|
2023-04-13 19:11:40 +00:00
|
|
|
b5 = makeBlobbyBlock(Slot 4, b3.root)
|
|
|
|
b6 = makeBlobbyBlock(Slot 4, b4.root)
|
2022-01-26 12:20:08 +00:00
|
|
|
|
|
|
|
var quarantine: Quarantine
|
|
|
|
|
|
|
|
quarantine.addMissing(b1.root)
|
|
|
|
check:
|
2023-07-11 16:22:02 +00:00
|
|
|
FetchRecord(root: b1.root) in quarantine.checkMissing(32)
|
2022-01-26 12:20:08 +00:00
|
|
|
|
2023-05-21 17:47:00 +00:00
|
|
|
quarantine.addOrphan(Slot 0, b1).isOk
|
2022-01-26 12:20:08 +00:00
|
|
|
|
2023-07-11 16:22:02 +00:00
|
|
|
FetchRecord(root: b1.root) notin quarantine.checkMissing(32)
|
2022-01-26 12:20:08 +00:00
|
|
|
|
2023-05-21 17:47:00 +00:00
|
|
|
quarantine.addOrphan(Slot 0, b2).isOk
|
|
|
|
quarantine.addOrphan(Slot 0, b3).isOk
|
|
|
|
quarantine.addOrphan(Slot 0, b4).isOk
|
2022-01-26 12:20:08 +00:00
|
|
|
|
2023-04-13 19:11:40 +00:00
|
|
|
quarantine.addBlobless(Slot 0, b5)
|
|
|
|
quarantine.addBlobless(Slot 0, b6)
|
|
|
|
|
2022-01-26 12:20:08 +00:00
|
|
|
(b4.root, ValidatorSig()) in quarantine.orphans
|
2023-04-16 08:37:56 +00:00
|
|
|
b5.root in quarantine.blobless
|
|
|
|
b6.root in quarantine.blobless
|
2022-01-26 12:20:08 +00:00
|
|
|
|
|
|
|
quarantine.addUnviable(b4.root)
|
|
|
|
|
|
|
|
check:
|
|
|
|
(b4.root, ValidatorSig()) notin quarantine.orphans
|
|
|
|
|
2023-04-16 08:37:56 +00:00
|
|
|
b5.root in quarantine.blobless
|
|
|
|
b6.root notin quarantine.blobless
|
2023-04-13 19:11:40 +00:00
|
|
|
|
2022-01-26 12:20:08 +00:00
|
|
|
quarantine.addUnviable(b1.root)
|
|
|
|
|
|
|
|
check:
|
|
|
|
(b1.root, ValidatorSig()) notin quarantine.orphans
|
|
|
|
(b2.root, ValidatorSig()) notin quarantine.orphans
|
|
|
|
(b3.root, ValidatorSig()) notin quarantine.orphans
|
2023-04-13 19:11:40 +00:00
|
|
|
|
2023-04-16 08:37:56 +00:00
|
|
|
b5.root notin quarantine.blobless
|
|
|
|
b6.root notin quarantine.blobless
|
2024-03-21 18:41:05 +00:00
|
|
|
|
|
|
|
test "Recursive missing parent":
|
|
|
|
let
|
|
|
|
b0 = makeBlock(Slot 0, ZERO_HASH)
|
|
|
|
b1 = makeBlock(Slot 1, b0.root)
|
|
|
|
b2 = makeBlock(Slot 2, b1.root)
|
|
|
|
|
|
|
|
var quarantine: Quarantine
|
|
|
|
check:
|
|
|
|
b0.root notin quarantine.missing
|
|
|
|
b1.root notin quarantine.missing
|
|
|
|
b2.root notin quarantine.missing
|
|
|
|
|
|
|
|
# Add b2
|
|
|
|
quarantine.addOrphan(Slot 0, b2).isOk
|
|
|
|
b0.root notin quarantine.missing
|
|
|
|
b1.root in quarantine.missing
|
|
|
|
b2.root notin quarantine.missing
|
|
|
|
|
|
|
|
# Add b1
|
|
|
|
quarantine.addOrphan(Slot 0, b1).isOk
|
|
|
|
b0.root in quarantine.missing
|
|
|
|
b1.root notin quarantine.missing
|
|
|
|
b2.root notin quarantine.missing
|
|
|
|
|
|
|
|
# Re-add b2
|
|
|
|
quarantine.addOrphan(Slot 0, b2).isOk
|
|
|
|
b0.root in quarantine.missing
|
|
|
|
b1.root notin quarantine.missing
|
|
|
|
b2.root notin quarantine.missing
|
|
|
|
|
|
|
|
# Empty missing
|
|
|
|
while quarantine.missing.len > 0:
|
|
|
|
discard quarantine.checkMissing(max = 5)
|
|
|
|
|
|
|
|
check:
|
|
|
|
# Re-add b2
|
|
|
|
quarantine.addOrphan(Slot 0, b2).isOk
|
|
|
|
b0.root in quarantine.missing
|
|
|
|
b1.root notin quarantine.missing
|
2024-08-05 13:57:39 +00:00
|
|
|
b2.root notin quarantine.missing
|