2021-10-18 09:11:44 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
unittest2,
|
|
|
|
eth/keys,
|
|
|
|
../beacon_chain/validators/action_tracker
|
|
|
|
|
|
|
|
suite "subnet tracker":
|
Backfill support for ChainDAG (#3171)
In the ChainDAG, 3 block pointers are kept: genesis, tail and head. This
PR adds one more block pointer: the backfill block which represents the
block that has been backfilled so far.
When doing a checkpoint sync, a random block is given as starting point
- this is the tail block, and we require that the tail block has a
corresponding state.
When backfilling, we end up with blocks without corresponding states,
hence we cannot use `tail` as a backfill pointer - there is no state.
Nonetheless, we need to keep track of where we are in the backfill
process between restarts, such that we can answer GetBeaconBlocksByRange
requests.
This PR adds the basic support for backfill handling - it needs to be
integrated with backfill sync, and the REST API needs to be adjusted to
take advantage of the new backfilled blocks when responding to certain
requests.
Future work will also enable moving the tail in either direction:
* pruning means moving the tail forward in time and removing states
* backwards means recreating past states from genesis, such that
intermediate states are recreated step by step all the way to the tail -
at that point, tail, genesis and backfill will match up.
* backfilling is done when backfill != genesis - later, this will be the
WSS checkpoint instead
2021-12-13 13:36:06 +00:00
|
|
|
setup:
|
|
|
|
let rng = keys.newRng()
|
2021-10-18 09:11:44 +00:00
|
|
|
|
|
|
|
test "should register stability subnets on attester duties":
|
|
|
|
var tracker = ActionTracker.init(rng, false)
|
|
|
|
|
|
|
|
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.stabilitySubnets(Slot(0)).countOnes() == 1
|
|
|
|
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(
|
2022-06-23 12:08:13 +00:00
|
|
|
(Epoch(EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION * 2) + 1).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
|
|
|
|
tracker = ActionTracker.init(rng, false)
|
|
|
|
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))
|