2023-06-19 22:43:50 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2021-2024 Status Research & Development GmbH
|
2023-06-19 22:43:50 +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: [].}
|
2021-10-18 09:11:44 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
unittest2,
|
|
|
|
../beacon_chain/validators/action_tracker
|
|
|
|
|
|
|
|
suite "subnet tracker":
|
|
|
|
test "should register stability subnets on attester duties":
|
2023-09-11 16:03:34 +00:00
|
|
|
var tracker = ActionTracker.init(default(UInt256), false)
|
2021-10-18 09:11:44 +00:00
|
|
|
|
|
|
|
check:
|
|
|
|
tracker.stabilitySubnets(Slot(0)).countOnes() == 0
|
|
|
|
tracker.aggregateSubnets(Slot(0)).countOnes() == 0
|
|
|
|
|
|
|
|
tracker.registerDuty(Slot(0), SubnetId(0), ValidatorIndex(0), true)
|
|
|
|
|
|
|
|
tracker.updateSlot(Slot(0))
|
|
|
|
|
|
|
|
check:
|
|
|
|
tracker.aggregateSubnets(Slot(0)).countOnes() == 1
|
|
|
|
tracker.aggregateSubnets(Slot(1)).countOnes() == 0
|
|
|
|
|
|
|
|
tracker.registerDuty(Slot(1), SubnetId(1), ValidatorIndex(0), true)
|
|
|
|
check:
|
|
|
|
tracker.aggregateSubnets(Slot(0)).countOnes() == 2
|
|
|
|
tracker.aggregateSubnets(Slot(1)).countOnes() == 1
|
2022-06-23 12:08:13 +00:00
|
|
|
tracker.knownValidators.len() == 1
|
2021-10-18 09:11:44 +00:00
|
|
|
|
|
|
|
tracker.registerDuty(Slot(SUBNET_SUBSCRIPTION_LEAD_TIME_SLOTS), SubnetId(2), ValidatorIndex(0), true)
|
|
|
|
check:
|
|
|
|
tracker.aggregateSubnets(Slot(0)).countOnes() == 2
|
|
|
|
tracker.aggregateSubnets(Slot(1)).countOnes() == 2
|
2022-06-23 12:08:13 +00:00
|
|
|
tracker.knownValidators.len() == 1
|
|
|
|
|
|
|
|
tracker.updateSlot(
|
|
|
|
Slot(SUBNET_SUBSCRIPTION_LEAD_TIME_SLOTS) + KNOWN_VALIDATOR_DECAY + 1)
|
|
|
|
|
|
|
|
check:
|
|
|
|
# Validator should be "forgotten" if they don't register for duty
|
|
|
|
tracker.knownValidators.len() == 0
|
2021-10-18 09:11:44 +00:00
|
|
|
|
|
|
|
# Guaranteed to expire
|
|
|
|
tracker.updateSlot(
|
2023-09-11 16:03:34 +00:00
|
|
|
(Epoch(1025).start_slot() +
|
|
|
|
SUBNET_SUBSCRIPTION_LEAD_TIME_SLOTS + KNOWN_VALIDATOR_DECAY + 1))
|
2021-10-18 09:11:44 +00:00
|
|
|
|
|
|
|
check:
|
|
|
|
tracker.stabilitySubnets(Slot(0)).countOnes() == 0
|
|
|
|
tracker.aggregateSubnets(Slot(0)).countOnes() == 0
|
2022-11-08 11:43:38 +00:00
|
|
|
|
|
|
|
test "should register sync committee duties":
|
|
|
|
var
|
2023-09-11 16:03:34 +00:00
|
|
|
tracker = ActionTracker.init(default(UInt256), false)
|
2022-11-08 11:43:38 +00:00
|
|
|
pk0 = ValidatorPubKey.fromHex("0xb4102a1f6c80e5c596a974ebd930c9f809c3587dc4d1d3634b77ff66db71e376dbc86c3252c6d140ce031f4ec6167798").get()
|
|
|
|
pk1 = ValidatorPubKey.fromHex("0xa00d2954717425ce047e0928e5f4ec7c0e3bbe1058db511303fd659770ddace686ee2e22ac180422e516f4c503eb2228").get()
|
|
|
|
|
|
|
|
check:
|
|
|
|
not tracker.hasSyncDuty(pk0, Epoch(1024))
|
|
|
|
|
|
|
|
tracker.lastSyncUpdate = Opt.some(SyncCommitteePeriod(42))
|
|
|
|
tracker.registerSyncDuty(pk0, Epoch(1024))
|
|
|
|
check:
|
|
|
|
tracker.lastSyncUpdate.isNone()
|
|
|
|
not tracker.hasSyncDuty(pk0, Epoch(1024))
|
|
|
|
not tracker.hasSyncDuty(pk1, Epoch(1023))
|
|
|
|
tracker.hasSyncDuty(pk0, Epoch(1023))
|
|
|
|
|
|
|
|
tracker.registerSyncDuty(pk0, Epoch(1022))
|
|
|
|
|
|
|
|
check: # Should not overwrite longer duties
|
|
|
|
tracker.hasSyncDuty(pk0, Epoch(1023))
|
|
|
|
|
|
|
|
tracker.registerSyncDuty(pk0, Epoch(1025))
|
|
|
|
check: # Should update existing duties
|
|
|
|
tracker.hasSyncDuty(pk0, Epoch(1024))
|
|
|
|
|
|
|
|
tracker.updateSlot(Epoch(1025).start_slot)
|
|
|
|
|
|
|
|
check: # should prune old duties on updateSlot
|
|
|
|
not tracker.hasSyncDuty(pk0, Epoch(1024))
|
|
|
|
|
|
|
|
tracker.registerSyncDuty(pk0, Epoch(1025))
|
|
|
|
|
|
|
|
check: # should not add old duties
|
|
|
|
not tracker.hasSyncDuty(pk0, Epoch(1024))
|