2021-04-26 20:39:44 +00:00
|
|
|
# beacon_chain
|
2022-01-04 09:45:38 +00:00
|
|
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
2021-04-26 20:39:44 +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
|
2021-09-28 07:44:20 +00:00
|
|
|
# Standard library
|
|
|
|
std/sequtils,
|
2021-04-26 20:39:44 +00:00
|
|
|
# Status lib
|
|
|
|
unittest2,
|
2022-06-07 17:05:06 +00:00
|
|
|
chronos,
|
2021-09-17 00:13:52 +00:00
|
|
|
eth/keys, taskpools,
|
2021-04-26 20:39:44 +00:00
|
|
|
# Internal
|
2021-10-19 14:09:26 +00:00
|
|
|
../beacon_chain/[beacon_clock],
|
2021-04-26 20:39:44 +00:00
|
|
|
../beacon_chain/gossip_processing/[gossip_validation, batch_validation],
|
2022-06-07 17:05:06 +00:00
|
|
|
../beacon_chain/fork_choice/fork_choice,
|
2021-04-26 20:39:44 +00:00
|
|
|
../beacon_chain/consensus_object_pools/[
|
2021-09-28 07:44:20 +00:00
|
|
|
block_quarantine, blockchain_dag, block_clearance, attestation_pool,
|
|
|
|
sync_committee_msg_pool],
|
|
|
|
../beacon_chain/spec/datatypes/[phase0, altair],
|
2021-11-05 07:34:34 +00:00
|
|
|
../beacon_chain/spec/[state_transition, helpers, network, validator],
|
2021-09-28 07:44:20 +00:00
|
|
|
../beacon_chain/validators/validator_pool,
|
2021-04-26 20:39:44 +00:00
|
|
|
# Test utilities
|
2021-04-28 16:41:02 +00:00
|
|
|
./testutil, ./testdbutil, ./testblockutil
|
2021-04-26 20:39:44 +00:00
|
|
|
|
|
|
|
proc pruneAtFinalization(dag: ChainDAGRef, attPool: AttestationPool) =
|
|
|
|
if dag.needStateCachesAndForkChoicePruning():
|
|
|
|
dag.pruneStateCachesDAG()
|
|
|
|
# pool[].prune() # We test logic without att_1_0 pool / fork choice pruning
|
|
|
|
|
2021-04-28 16:41:02 +00:00
|
|
|
suite "Gossip validation " & preset():
|
2021-04-26 20:39:44 +00:00
|
|
|
setup:
|
|
|
|
# Genesis state that results in 3 members per committee
|
|
|
|
var
|
2021-12-20 19:20:31 +00:00
|
|
|
validatorMonitor = newClone(ValidatorMonitor.init())
|
|
|
|
dag = init(
|
|
|
|
ChainDAGRef, defaultRuntimeConfig, makeTestDB(SLOTS_PER_EPOCH * 3),
|
|
|
|
validatorMonitor, {})
|
2021-09-17 00:13:52 +00:00
|
|
|
taskpool = Taskpool.new()
|
2021-12-06 09:49:01 +00:00
|
|
|
verifier = BatchVerifier(rng: keys.newRng(), taskpool: taskpool)
|
|
|
|
quarantine = newClone(Quarantine.init())
|
2021-06-01 11:13:40 +00:00
|
|
|
pool = newClone(AttestationPool.init(dag, quarantine))
|
|
|
|
state = newClone(dag.headState)
|
2021-04-26 20:39:44 +00:00
|
|
|
cache = StateCache()
|
2021-10-13 14:24:36 +00:00
|
|
|
info = ForkedEpochInfo()
|
2021-09-17 00:13:52 +00:00
|
|
|
batchCrypto = BatchCrypto.new(keys.newRng(), eager = proc(): bool = false, taskpool)
|
2021-04-26 20:39:44 +00:00
|
|
|
# Slot 0 is a finalized slot - won't be making attestations for it..
|
|
|
|
check:
|
2021-06-11 17:51:46 +00:00
|
|
|
process_slots(
|
2022-03-16 07:20:40 +00:00
|
|
|
defaultRuntimeConfig, state[], getStateField(state[], slot) + 1,
|
2022-01-17 11:19:58 +00:00
|
|
|
cache, info, {}).isOk()
|
2021-04-26 20:39:44 +00:00
|
|
|
|
2022-01-08 23:28:49 +00:00
|
|
|
test "Empty committee when no committee for slot":
|
2021-08-28 09:00:00 +00:00
|
|
|
template committee(idx: uint64): untyped =
|
|
|
|
get_beacon_committee(
|
2022-03-16 07:20:40 +00:00
|
|
|
dag.headState, dag.head.slot, idx.CommitteeIndex, cache)
|
2021-08-28 09:00:00 +00:00
|
|
|
|
|
|
|
template committeeLen(idx: uint64): untyped =
|
|
|
|
get_beacon_committee_len(
|
2022-03-16 07:20:40 +00:00
|
|
|
dag.headState, dag.head.slot, idx.CommitteeIndex, cache)
|
2021-08-28 09:00:00 +00:00
|
|
|
|
|
|
|
check:
|
|
|
|
committee(0).len > 0
|
2022-01-08 23:28:49 +00:00
|
|
|
committee(63).len == 0
|
2021-08-28 09:00:00 +00:00
|
|
|
|
|
|
|
check:
|
|
|
|
committeeLen(2) > 0
|
2022-01-08 23:28:49 +00:00
|
|
|
committeeLen(63) == 0
|
2021-08-28 09:00:00 +00:00
|
|
|
|
Speed up altair block processing 2x (#3115)
* Speed up altair block processing >2x
Like #3089, this PR drastially speeds up historical REST queries and
other long state replays.
* cache sync committee validator indices
* use ~80mb less memory for validator pubkey mappings
* batch-verify sync aggregate signature (fixes #2985)
* document sync committee hack with head block vs sync message block
* add batch signature verification failure tests
Before:
```
../env.sh nim c -d:release -r ncli_db --db:mainnet_0/db bench --start-slot:-1000
All time are ms
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
5830.675, 0.000, 5830.675, 5830.675, 1, Initialize DB
0.481, 1.878, 0.215, 59.167, 981, Load block from database
8422.566, 0.000, 8422.566, 8422.566, 1, Load state from database
6.996, 1.678, 0.042, 14.385, 969, Advance slot, non-epoch
93.217, 8.318, 84.192, 122.209, 32, Advance slot, epoch
20.513, 23.665, 11.510, 201.561, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
After:
```
7081.422, 0.000, 7081.422, 7081.422, 1, Initialize DB
0.553, 2.122, 0.175, 66.692, 981, Load block from database
5439.446, 0.000, 5439.446, 5439.446, 1, Load state from database
6.829, 1.575, 0.043, 12.156, 969, Advance slot, non-epoch
94.716, 2.749, 88.395, 100.026, 32, Advance slot, epoch
11.636, 23.766, 4.889, 205.250, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
* add comment
2021-11-24 12:43:50 +00:00
|
|
|
test "validateAttestation":
|
2021-04-26 20:39:44 +00:00
|
|
|
var
|
|
|
|
cache: StateCache
|
|
|
|
for blck in makeTestBlocks(
|
2022-03-16 07:20:40 +00:00
|
|
|
dag.headState, cache, int(SLOTS_PER_EPOCH * 5), false):
|
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
|
|
|
let added = dag.addHeadBlock(verifier, blck.phase0Data) do (
|
2021-08-12 13:08:20 +00:00
|
|
|
blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock,
|
2022-07-06 10:33:02 +00:00
|
|
|
epochRef: EpochRef, unrealized: FinalityCheckpoints):
|
2021-04-26 20:39:44 +00:00
|
|
|
# Callback add to fork choice if valid
|
2021-12-21 18:56:08 +00:00
|
|
|
pool[].addForkChoice(
|
2022-07-06 10:33:02 +00:00
|
|
|
epochRef, blckRef, unrealized, signedBlock.message,
|
|
|
|
blckRef.slot.start_beacon_time)
|
2021-04-26 20:39:44 +00:00
|
|
|
|
|
|
|
check: added.isOk()
|
2021-12-06 09:49:01 +00:00
|
|
|
dag.updateHead(added[], quarantine[])
|
2021-06-01 11:13:40 +00:00
|
|
|
pruneAtFinalization(dag, pool[])
|
2021-04-26 20:39:44 +00:00
|
|
|
|
|
|
|
var
|
|
|
|
# Create attestations for slot 1
|
|
|
|
beacon_committee = get_beacon_committee(
|
2022-03-16 07:20:40 +00:00
|
|
|
dag.headState, dag.head.slot, 0.CommitteeIndex, cache)
|
2021-04-26 20:39:44 +00:00
|
|
|
att_1_0 = makeAttestation(
|
2022-03-16 07:20:40 +00:00
|
|
|
dag.headState, dag.head.root, beacon_committee[0], cache)
|
2021-04-26 20:39:44 +00:00
|
|
|
att_1_1 = makeAttestation(
|
2022-03-16 07:20:40 +00:00
|
|
|
dag.headState, dag.head.root, beacon_committee[1], cache)
|
2021-04-26 20:39:44 +00:00
|
|
|
|
|
|
|
committees_per_slot =
|
2022-03-16 07:20:40 +00:00
|
|
|
get_committee_count_per_slot(
|
|
|
|
dag.headState, att_1_0.data.slot.epoch, cache)
|
2021-04-26 20:39:44 +00:00
|
|
|
|
|
|
|
subnet = compute_subnet_for_attestation(
|
|
|
|
committees_per_slot,
|
|
|
|
att_1_0.data.slot, att_1_0.data.index.CommitteeIndex)
|
|
|
|
|
2022-01-11 10:01:54 +00:00
|
|
|
beaconTime = att_1_0.data.slot.start_beacon_time()
|
2021-04-26 20:39:44 +00:00
|
|
|
|
|
|
|
check:
|
|
|
|
validateAttestation(pool, batchCrypto, att_1_0, beaconTime, subnet, true).waitFor().isOk
|
|
|
|
|
|
|
|
# Same validator again
|
|
|
|
validateAttestation(pool, batchCrypto, att_1_0, beaconTime, subnet, true).waitFor().error()[0] ==
|
|
|
|
ValidationResult.Ignore
|
|
|
|
|
|
|
|
pool[].nextAttestationEpoch.setLen(0) # reset for test
|
|
|
|
check:
|
|
|
|
# Wrong subnet
|
2021-05-10 07:13:36 +00:00
|
|
|
validateAttestation(
|
|
|
|
pool, batchCrypto, att_1_0, beaconTime, SubnetId(subnet.uint8 + 1), true).waitFor().isErr
|
2021-04-26 20:39:44 +00:00
|
|
|
|
|
|
|
pool[].nextAttestationEpoch.setLen(0) # reset for test
|
|
|
|
check:
|
|
|
|
# Too far in the future
|
|
|
|
validateAttestation(
|
2021-05-10 07:13:36 +00:00
|
|
|
pool, batchCrypto, att_1_0, beaconTime - 1.seconds, subnet, true).waitFor().isErr
|
2021-04-26 20:39:44 +00:00
|
|
|
|
|
|
|
pool[].nextAttestationEpoch.setLen(0) # reset for test
|
|
|
|
check:
|
|
|
|
# Too far in the past
|
|
|
|
validateAttestation(
|
|
|
|
pool, batchCrypto, att_1_0,
|
|
|
|
beaconTime - (SECONDS_PER_SLOT * SLOTS_PER_EPOCH - 1).int.seconds,
|
2021-05-10 07:13:36 +00:00
|
|
|
subnet, true).waitFor().isErr
|
2021-04-26 20:39:44 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
var broken = att_1_0
|
|
|
|
broken.signature.blob[0] += 1
|
|
|
|
pool[].nextAttestationEpoch.setLen(0) # reset for test
|
|
|
|
check:
|
|
|
|
# Invalid signature
|
|
|
|
validateAttestation(
|
|
|
|
pool, batchCrypto, broken, beaconTime, subnet, true).waitFor().
|
|
|
|
error()[0] == ValidationResult.Reject
|
|
|
|
|
|
|
|
block:
|
|
|
|
var broken = att_1_0
|
|
|
|
broken.signature.blob[5] += 1
|
|
|
|
pool[].nextAttestationEpoch.setLen(0) # reset for test
|
|
|
|
# One invalid, one valid (batched)
|
|
|
|
let
|
|
|
|
fut_1_0 = validateAttestation(
|
|
|
|
pool, batchCrypto, broken, beaconTime, subnet, true)
|
|
|
|
fut_1_1 = validateAttestation(
|
|
|
|
pool, batchCrypto, att_1_1, beaconTime, subnet, true)
|
|
|
|
|
|
|
|
check:
|
|
|
|
fut_1_0.waitFor().error()[0] == ValidationResult.Reject
|
|
|
|
fut_1_1.waitFor().isOk()
|
|
|
|
|
|
|
|
block:
|
|
|
|
var broken = att_1_0
|
|
|
|
# This shouldn't deserialize, which is a different way to break it
|
|
|
|
broken.signature.blob = default(type broken.signature.blob)
|
|
|
|
pool[].nextAttestationEpoch.setLen(0) # reset for test
|
|
|
|
# One invalid, one valid (batched)
|
|
|
|
let
|
|
|
|
fut_1_0 = validateAttestation(
|
|
|
|
pool, batchCrypto, broken, beaconTime, subnet, true)
|
|
|
|
fut_1_1 = validateAttestation(
|
|
|
|
pool, batchCrypto, att_1_1, beaconTime, subnet, true)
|
|
|
|
|
|
|
|
check:
|
|
|
|
fut_1_0.waitFor().error()[0] == ValidationResult.Reject
|
|
|
|
fut_1_1.waitFor().isOk()
|
2021-09-28 07:44:20 +00:00
|
|
|
|
|
|
|
suite "Gossip validation - Extra": # Not based on preset config
|
|
|
|
test "validateSyncCommitteeMessage":
|
|
|
|
const num_validators = SLOTS_PER_EPOCH
|
2021-10-07 13:19:47 +00:00
|
|
|
let
|
2021-09-28 07:44:20 +00:00
|
|
|
cfg = block:
|
|
|
|
var cfg = defaultRuntimeConfig
|
|
|
|
cfg.ALTAIR_FORK_EPOCH = (GENESIS_EPOCH + 1).Epoch
|
|
|
|
cfg
|
2021-12-09 12:56:54 +00:00
|
|
|
taskpool = Taskpool.new()
|
|
|
|
quarantine = newClone(Quarantine.init())
|
|
|
|
batchCrypto = BatchCrypto.new(keys.newRng(), eager = proc(): bool = false, taskpool)
|
|
|
|
var
|
|
|
|
verifier = BatchVerifier(rng: keys.newRng(), taskpool: Taskpool.new())
|
2021-09-28 07:44:20 +00:00
|
|
|
dag = block:
|
2021-12-09 12:56:54 +00:00
|
|
|
let
|
2021-12-20 19:20:31 +00:00
|
|
|
validatorMonitor = newClone(ValidatorMonitor.init())
|
|
|
|
dag = ChainDAGRef.init(
|
|
|
|
cfg, makeTestDB(num_validators), validatorMonitor, {})
|
2021-09-28 07:44:20 +00:00
|
|
|
var cache = StateCache()
|
|
|
|
for blck in makeTestBlocks(
|
2022-03-16 07:20:40 +00:00
|
|
|
dag.headState, cache, int(SLOTS_PER_EPOCH), false, cfg = cfg):
|
2021-10-07 13:19:47 +00:00
|
|
|
let added =
|
2021-09-28 07:44:20 +00:00
|
|
|
case blck.kind
|
|
|
|
of BeaconBlockFork.Phase0:
|
|
|
|
const nilCallback = OnPhase0BlockAdded(nil)
|
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
|
|
|
dag.addHeadBlock(verifier, blck.phase0Data, nilCallback)
|
2021-09-28 07:44:20 +00:00
|
|
|
of BeaconBlockFork.Altair:
|
|
|
|
const nilCallback = OnAltairBlockAdded(nil)
|
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
|
|
|
dag.addHeadBlock(verifier, blck.altairData, nilCallback)
|
2022-01-04 09:45:38 +00:00
|
|
|
of BeaconBlockFork.Bellatrix:
|
2022-01-26 12:21:29 +00:00
|
|
|
const nilCallback = OnBellatrixBlockAdded(nil)
|
2022-01-24 16:23:13 +00:00
|
|
|
dag.addHeadBlock(verifier, blck.bellatrixData, nilCallback)
|
2021-09-28 07:44:20 +00:00
|
|
|
check: added.isOk()
|
2021-12-06 09:49:01 +00:00
|
|
|
dag.updateHead(added[], quarantine[])
|
2021-09-28 07:44:20 +00:00
|
|
|
dag
|
2022-03-16 07:20:40 +00:00
|
|
|
state = assignClone(dag.headState.altairData)
|
2021-11-04 18:22:24 +00:00
|
|
|
slot = state[].data.slot
|
2021-09-28 07:44:20 +00:00
|
|
|
|
2021-11-05 15:39:47 +00:00
|
|
|
subcommitteeIdx = 0.SyncSubcommitteeIndex
|
2021-11-04 18:22:24 +00:00
|
|
|
syncCommittee = @(dag.syncCommitteeParticipants(slot))
|
2021-11-05 15:39:47 +00:00
|
|
|
subcommittee = toSeq(syncCommittee.syncSubcommittee(subcommitteeIdx))
|
Speed up altair block processing 2x (#3115)
* Speed up altair block processing >2x
Like #3089, this PR drastially speeds up historical REST queries and
other long state replays.
* cache sync committee validator indices
* use ~80mb less memory for validator pubkey mappings
* batch-verify sync aggregate signature (fixes #2985)
* document sync committee hack with head block vs sync message block
* add batch signature verification failure tests
Before:
```
../env.sh nim c -d:release -r ncli_db --db:mainnet_0/db bench --start-slot:-1000
All time are ms
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
5830.675, 0.000, 5830.675, 5830.675, 1, Initialize DB
0.481, 1.878, 0.215, 59.167, 981, Load block from database
8422.566, 0.000, 8422.566, 8422.566, 1, Load state from database
6.996, 1.678, 0.042, 14.385, 969, Advance slot, non-epoch
93.217, 8.318, 84.192, 122.209, 32, Advance slot, epoch
20.513, 23.665, 11.510, 201.561, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
After:
```
7081.422, 0.000, 7081.422, 7081.422, 1, Initialize DB
0.553, 2.122, 0.175, 66.692, 981, Load block from database
5439.446, 0.000, 5439.446, 5439.446, 1, Load state from database
6.829, 1.575, 0.043, 12.156, 969, Advance slot, non-epoch
94.716, 2.749, 88.395, 100.026, 32, Advance slot, epoch
11.636, 23.766, 4.889, 205.250, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
* add comment
2021-11-24 12:43:50 +00:00
|
|
|
index = subcommittee[0]
|
|
|
|
expectedCount = subcommittee.count(index)
|
2022-05-30 13:30:42 +00:00
|
|
|
pubkey = state[].data.validators.item(index).pubkey
|
2021-12-22 12:37:31 +00:00
|
|
|
keystoreData = KeystoreData(kind: KeystoreKind.Local,
|
|
|
|
privateKey: MockPrivKeys[index])
|
|
|
|
validator = AttachedValidator(pubkey: pubkey,
|
2022-08-19 21:51:30 +00:00
|
|
|
kind: ValidatorKind.Local, data: keystoreData, index: Opt.some index)
|
2022-06-29 16:53:59 +00:00
|
|
|
resMsg = waitFor getSyncCommitteeMessage(
|
2021-12-09 12:56:54 +00:00
|
|
|
validator, state[].data.fork, state[].data.genesis_validators_root, slot,
|
|
|
|
state[].root)
|
2021-11-30 01:20:21 +00:00
|
|
|
msg = resMsg.get()
|
2021-09-28 07:44:20 +00:00
|
|
|
|
2022-01-24 20:40:59 +00:00
|
|
|
syncCommitteeMsgPool = newClone(SyncCommitteeMsgPool.init(keys.newRng()))
|
2021-12-09 12:56:54 +00:00
|
|
|
res = waitFor validateSyncCommitteeMessage(
|
2021-12-11 15:39:24 +00:00
|
|
|
dag, batchCrypto, syncCommitteeMsgPool, msg, subcommitteeIdx,
|
2022-01-11 10:01:54 +00:00
|
|
|
slot.start_beacon_time(), true)
|
2021-11-05 15:39:47 +00:00
|
|
|
(positions, cookedSig) = res.get()
|
|
|
|
|
2021-11-25 12:20:36 +00:00
|
|
|
syncCommitteeMsgPool[].addSyncCommitteeMessage(
|
2021-11-05 15:39:47 +00:00
|
|
|
msg.slot,
|
|
|
|
msg.beacon_block_root,
|
|
|
|
msg.validator_index,
|
|
|
|
cookedSig,
|
|
|
|
subcommitteeIdx,
|
|
|
|
positions)
|
|
|
|
|
|
|
|
let
|
2021-09-28 07:44:20 +00:00
|
|
|
contribution = block:
|
2022-02-20 20:13:06 +00:00
|
|
|
let contribution = (ref SignedContributionAndProof)()
|
2022-08-09 09:52:11 +00:00
|
|
|
check:
|
|
|
|
syncCommitteeMsgPool[].produceContribution(
|
|
|
|
slot, state[].root, subcommitteeIdx,
|
|
|
|
contribution.message.contribution)
|
|
|
|
let addContributionRes = syncCommitteeMsgPool[].addContribution(
|
2021-11-05 15:39:47 +00:00
|
|
|
contribution[], contribution.message.contribution.signature.load.get)
|
2022-08-09 09:52:11 +00:00
|
|
|
check addContributionRes == newBest
|
2022-06-29 16:53:59 +00:00
|
|
|
let signRes = waitFor validator.getContributionAndProofSignature(
|
|
|
|
state[].data.fork, state[].data.genesis_validators_root,
|
|
|
|
contribution[].message)
|
2021-11-30 01:20:21 +00:00
|
|
|
doAssert(signRes.isOk())
|
2022-06-29 16:53:59 +00:00
|
|
|
contribution[].signature = signRes.get()
|
2021-09-28 07:44:20 +00:00
|
|
|
contribution
|
|
|
|
aggregate = syncCommitteeMsgPool[].produceSyncAggregate(state[].root)
|
|
|
|
|
|
|
|
check:
|
|
|
|
expectedCount > 1 # Cover edge case
|
|
|
|
res.isOk
|
2021-11-05 15:39:47 +00:00
|
|
|
contribution.message.contribution.aggregation_bits.countOnes == expectedCount
|
2021-09-28 07:44:20 +00:00
|
|
|
aggregate.sync_committee_bits.countOnes == expectedCount
|
2021-11-05 15:39:47 +00:00
|
|
|
|
|
|
|
# Same message twice should be ignored
|
|
|
|
validateSyncCommitteeMessage(
|
2021-12-11 15:39:24 +00:00
|
|
|
dag, batchCrypto, syncCommitteeMsgPool, msg, subcommitteeIdx,
|
2022-01-11 10:01:54 +00:00
|
|
|
state[].data.slot.start_beacon_time(), true).waitFor().isErr()
|