2022-01-26 12:20:08 +00:00
|
|
|
# beacon_chain
|
2023-03-09 00:34:17 +00:00
|
|
|
# Copyright (c) 2022-2023 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.
|
|
|
|
|
|
|
|
{.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:
|
|
|
|
FetchRecord(root: b1.root) in quarantine.checkMissing()
|
|
|
|
|
2023-02-27 06:10:22 +00:00
|
|
|
quarantine.addOrphan(Slot 0, b1)
|
2022-01-26 12:20:08 +00:00
|
|
|
|
|
|
|
FetchRecord(root: b1.root) notin quarantine.checkMissing()
|
|
|
|
|
2023-02-27 06:10:22 +00:00
|
|
|
quarantine.addOrphan(Slot 0, b2)
|
|
|
|
quarantine.addOrphan(Slot 0, b3)
|
|
|
|
quarantine.addOrphan(Slot 0, b4)
|
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
|