Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - [Altair] Sync committee pools #2321

Closed
wants to merge 222 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
222 commits
Select commit Hold shift + click to select a range
2c52794
Start Altair refactor
michaelsproul Mar 23, 2021
bb397c5
Add AltairConfig
michaelsproul Mar 23, 2021
937a19a
Towards SSZ tests passing
michaelsproul Mar 24, 2021
b199b25
Generate as_base/as_altair with superstruct
michaelsproul Mar 25, 2021
a4d3e70
Most SSZ static tests passing
michaelsproul Mar 25, 2021
ca6bbf9
justification_and_finalization changes
realbigsean Mar 25, 2021
a5c8990
refactor to match eth2 spec, and fix epoch processing EF tests
realbigsean Mar 25, 2021
6585c9d
Merge branch 'consensus-spec-tests' of https://github.com/realbigsean…
realbigsean Mar 25, 2021
20181b7
Make SignedBeaconBlock a superstruct
michaelsproul Mar 26, 2021
3283abc
Merge remote-tracking branch 'origin/unstable' into altair
michaelsproul Mar 26, 2021
1449230
Fix ef_tests for SBB change
michaelsproul Mar 26, 2021
5090cf4
refactors
realbigsean Mar 26, 2021
a0fa7af
Merge branch 'altair' of https://github.com/sigp/lighthouse into alta…
realbigsean Mar 26, 2021
4895348
refactor justification and finalization, begin altair rewards and pen…
realbigsean Mar 27, 2021
9ab858a
get rewards and penalties working for altair
realbigsean Mar 28, 2021
060e3d4
fix some imports
realbigsean Mar 28, 2021
d5cf7a8
Implement basic sync committee functions
michaelsproul Mar 31, 2021
e470fd4
Merge remote-tracking branch 'sean/altair-process-epoch' into altair
michaelsproul Mar 31, 2021
746e99b
Implement process_sync_committee
michaelsproul Mar 31, 2021
3b00f83
Update EF operation tests incl sync agg
michaelsproul Apr 1, 2021
b9f32e0
small refactors
realbigsean Apr 6, 2021
3a364d9
Update attestation/deposit processing
michaelsproul Apr 6, 2021
f68738e
Implement `upgrade_to_altair`, genesis init test
michaelsproul Apr 6, 2021
1815024
Merge branch 'altair' of https://github.com/sigp/lighthouse into more…
realbigsean Apr 6, 2021
84c0441
fix slashings and implement sync committee processing
realbigsean Apr 6, 2021
5c63dcd
refactor common epoch processing methods
realbigsean Apr 6, 2021
97106d4
delete unused imports
realbigsean Apr 6, 2021
4cffdcb
Fix typo in sync_committee_updates
michaelsproul Apr 7, 2021
9ac6850
Update to v1.1.0-alpha.3
michaelsproul Apr 7, 2021
8ffeb33
Fix remaining EF tests/handlers!
michaelsproul Apr 7, 2021
d5f19dc
Fix beacon chain tests non-altair (#2305)
realbigsean Apr 13, 2021
254bd66
Use RefMut
michaelsproul Apr 13, 2021
e873ad9
Reset Cargo.lock to "stable" style
michaelsproul Apr 13, 2021
458828f
Tidy block tree hash
michaelsproul Apr 13, 2021
ace7c45
Merge remote-tracking branch 'origin/unstable' into altair
michaelsproul Apr 13, 2021
a256b06
Temporarily hardcode base fork in op pool
michaelsproul Apr 13, 2021
0cdd19c
Update block proposal & op pool
michaelsproul Apr 14, 2021
1a4145d
Fix bounds check on compute_sync_committee_indices
michaelsproul Apr 14, 2021
d6f2acc
Tidy phase0 op pool
michaelsproul Apr 14, 2021
bfc70cf
Remove global fork schedule (#2314)
michaelsproul Apr 19, 2021
663a9ef
Use superstruct partial getters
michaelsproul Apr 19, 2021
27f41c6
Lots of test refactors (#2315)
realbigsean Apr 20, 2021
610e92b
More test cleanups and fixes
michaelsproul Apr 20, 2021
e490f3c
Use `upgrade_to_altair` in state transition
michaelsproul Apr 20, 2021
af9e2d8
More test fixes
michaelsproul Apr 20, 2021
5316b2a
Begin adding pools related to sync committees
realbigsean Apr 20, 2021
98e26d5
Add fork upgrade test, fix EF spec test
michaelsproul Apr 21, 2021
8158ef3
Merge branch 'altair' of https://github.com/sigp/lighthouse into sync…
realbigsean Apr 21, 2021
54ae49b
Sync committee pool refactors, attempt to get ssz tests working
realbigsean Apr 21, 2021
7395bf0
Revert BitVector change
realbigsean Apr 21, 2021
92d3c33
Update lcli and local testnet scripts
michaelsproul Apr 22, 2021
473a5a9
Fix `SyncCommitteeContribution` bit vector length, fix `SyncCommittee…
realbigsean Apr 22, 2021
2bb1021
update docs and add tests for sync committee operation pool
realbigsean Apr 22, 2021
f8b31f6
More test updates, release-tests might pass now...
michaelsproul Apr 23, 2021
e92e61b
Nuke old store benchmark
michaelsproul Apr 23, 2021
14a15ca
Fix arbitrary instances
michaelsproul Apr 23, 2021
0ded5cb
Participation bits fixes, clippy fixes
michaelsproul Apr 23, 2021
c85e464
Merge branch 'altair' of https://github.com/sigp/lighthouse into sync…
realbigsean Apr 26, 2021
0428acf
add BitVector intersection and union tests
realbigsean Apr 26, 2021
9882bbb
Disable indexing in types & state processing
michaelsproul Apr 27, 2021
5176655
Delete tree hash and state proc benchmarks
michaelsproul Apr 27, 2021
e4b2570
Disable aggressive lints in tests
michaelsproul Apr 27, 2021
eea1708
Appease udeps
michaelsproul Apr 27, 2021
fa3f6f7
Fix the RPC tests without hacks
michaelsproul Apr 27, 2021
a1d9182
Fix double update in github cargo fmt
michaelsproul Apr 27, 2021
d0f63e0
Use published superstruct
michaelsproul Apr 27, 2021
d1d3cba
Try splitting beacon_chain tests out of CI
michaelsproul Apr 28, 2021
d32cc3d
Fix cargo-fmt --all
michaelsproul Apr 28, 2021
95ca4ed
Abstract over fork in beacon_chain tests
michaelsproul Apr 29, 2021
0cf1834
Fix clippy
michaelsproul Apr 29, 2021
a549472
Merge remote-tracking branch 'origin/unstable' into altair
michaelsproul Apr 29, 2021
c89de3b
Maintain backwards compatibility with std config
michaelsproul Apr 30, 2021
bc719f7
Sync committee signature verification work
realbigsean May 5, 2021
d956db5
Add an `Arc` to the `current_sync_committee` field, refactor `sync_co…
realbigsean May 6, 2021
0d84cb6
Clean up imports
realbigsean May 6, 2021
bfc3383
Merge branch 'altair' of https://github.com/sigp/lighthouse into sync…
realbigsean May 6, 2021
6c0e4c4
Move `sync_committee_base_epoch` to `Epoch`
realbigsean May 7, 2021
8210af5
Fmt and fix some lints
realbigsean May 7, 2021
dfcf16e
Add tests for new observation pools
realbigsean May 7, 2021
f93c256
Some op pool work
realbigsean May 7, 2021
f7b82ae
Provide clarity about BeaconState leaf count (#2339)
paulhauner May 10, 2021
1a9c899
Remove sync committee indices cache
michaelsproul May 11, 2021
6705660
- Add beacon harness methods for sync signature create
realbigsean May 11, 2021
abf974c
Merge branch 'altair' of https://github.com/sigp/lighthouse into sync…
realbigsean May 11, 2021
3c12cd6
merge with `altair`
realbigsean May 11, 2021
6d01530
Merge remote-tracking branch 'origin/unstable' into altair
michaelsproul May 13, 2021
967d680
Add tests for decoding state/block with bad slot (#2341)
paulhauner May 14, 2021
ff0d992
Tidy SyncCommittee types
michaelsproul May 17, 2021
14002e9
Merge remote-tracking branch 'origin/altair' into sync-committee-pools
michaelsproul May 17, 2021
2daedc8
More sync committee type cleanups/fallout
michaelsproul May 17, 2021
a6acfbb
Merge pull request #13 from michaelsproul/sync-committee-pools
realbigsean May 17, 2021
e7268f7
merge with `altair`
realbigsean May 17, 2021
0b07c94
merge with `altair`
realbigsean May 17, 2021
e9820d8
Some sync verification fixes and test progress
realbigsean May 18, 2021
ab3cfc0
Add hack to allow harness with altair spec
paulhauner May 19, 2021
4500cb9
Add test for applying base block to altair chain
paulhauner May 19, 2021
70a2fc0
Use graffiti len more consistently (#2348)
paulhauner May 19, 2021
28aa869
Replace a test deleted during Altair update (#2351)
paulhauner May 19, 2021
6c16333
Apply comment fixes from Paul
michaelsproul May 19, 2021
297843d
Add fork_name methods
paulhauner May 19, 2021
f757617
Add fork checks and tests
paulhauner May 19, 2021
7ca7af8
Add tests for applying altair to base
paulhauner May 19, 2021
368543a
Merge branch 'altair' of https://github.com/sigp/lighthouse into sync…
realbigsean May 19, 2021
be88e5d
Allow providing a custom spec to test harness
paulhauner May 20, 2021
dfb4c4e
Fix compile error in network
paulhauner May 20, 2021
3a4cca0
Add tests for slot, epoch processing
paulhauner May 20, 2021
a1feba1
Fix clippy lints
paulhauner May 20, 2021
c661d54
Fix release test
paulhauner May 20, 2021
8778b43
Merge branch 'altair-base-test' of https://github.com/paulhauner/ligh…
realbigsean May 20, 2021
729fe50
Finish op pool sync committee logic, add a couple tests.
realbigsean May 20, 2021
8377565
Avoid slicing in PartialBeaconState (#2361)
paulhauner May 21, 2021
6f6eebf
[Altair] Make anonymous var-length SSZ decoding explicit (#2362)
paulhauner May 21, 2021
e46448b
Merge branch 'altair' of https://github.com/sigp/lighthouse into sync…
realbigsean May 21, 2021
27f671b
Use macros for naive aggregation pool tests.
realbigsean May 21, 2021
17a2fe7
small updates
realbigsean May 21, 2021
76d31cd
[Altair] Rewards tests (#2349)
michaelsproul May 24, 2021
5cb0211
[Altair] Remove duplicate vars, panic on `u64::pow` overflow (#2350)
paulhauner May 24, 2021
06c46f4
[Altair] Applying Base block to Altair chain (#2353)
paulhauner May 24, 2021
97d1807
[Altair] Add check for missed EF tests (#2346)
paulhauner May 24, 2021
81bd93f
Fix beacon chain harness bug in `make_sync_contributions`. Key the `O…
realbigsean May 24, 2021
a217a85
Merge branch 'altair' of https://github.com/sigp/lighthouse into sync…
realbigsean May 24, 2021
3db5576
Accidentally removed a couple constants while merging
realbigsean May 24, 2021
9739552
fix a typo in a const, and a bunch of lints
realbigsean May 24, 2021
dba9dca
Merge branch 'unstable' of github.com:sigp/lighthouse into altair-mer…
paulhauner May 24, 2021
e324310
Merge pull request #2365 from paulhauner/altair-merge-unstable
michaelsproul May 25, 2021
443793b
Restore lost CI YAML
michaelsproul May 25, 2021
6415962
Address review comments
michaelsproul May 25, 2021
49b79b8
Update comment
michaelsproul May 25, 2021
338a2d1
Return an error if total bal is 0 (#2366)
paulhauner May 25, 2021
3789a72
Fix and test selection proof `verify`
michaelsproul May 25, 2021
e9bec20
Fix get_sync_aggregate
michaelsproul May 25, 2021
7cac63d
update op pool tests to correctly use `get_sync_aggregate`
realbigsean May 25, 2021
dc2227a
Minor changes to justification code (#2367)
paulhauner May 25, 2021
7d18521
[Altair] Optimization for `get_unslashed_participating_indices` (#2369)
paulhauner May 26, 2021
b606cc8
Add sync contribution aggregation tests to the op pool and fix an op …
realbigsean May 26, 2021
3a6f255
Only advance state as necessary in sync committee verification tests.…
realbigsean May 27, 2021
851b624
Delete `verify_sync_contributions.rs` and fix a comment.
realbigsean May 27, 2021
bf6324e
Remove `Arc` from `current_sync_committee`
realbigsean May 27, 2021
276f705
Merge branch 'altair' of https://github.com/sigp/lighthouse into sync…
realbigsean May 27, 2021
ef73f5a
Add `max_capacity` to `ObservedAggregates` constructor
realbigsean May 27, 2021
2a7c2b3
Update consensus code to v1.1.0-alpha.6
michaelsproul May 28, 2021
5692ff1
Make the `SyncAggregateId` a fixed-length struct
realbigsean May 28, 2021
5756c2d
Add metrics and update docs
realbigsean May 28, 2021
cb9a7a2
Ripple spec updates
michaelsproul May 31, 2021
46b4619
Revert "Remove `Arc` from `current_sync_committee`"
realbigsean Jun 1, 2021
b6fdda0
Merge branch 'sync-committee-pools' of https://github.com/realbigsean…
realbigsean Jun 1, 2021
633c1bb
fix some pool tests
realbigsean Jun 1, 2021
dfff140
Updates to some docs, general cleanup
realbigsean Jun 1, 2021
65c22b7
Fix default capacity for sync committee observed caches
realbigsean Jun 1, 2021
b4a71c7
Fix default capacity for sync committee observed caches
realbigsean Jun 1, 2021
d4ec7d0
Fix default capacity for sync committee observed caches
realbigsean Jun 1, 2021
16e9f32
Fix more docs and metrics
realbigsean Jun 1, 2021
59a9f3a
Remove `is_valid` methods from `SignedAggregateAndProof` and `SignedC…
realbigsean Jun 1, 2021
3b7b295
remove outdated `FIXME`
realbigsean Jun 1, 2021
bb5d3c8
Fix docs
realbigsean Jun 1, 2021
cf7e7b7
Fix docs
realbigsean Jun 1, 2021
ee8dea8
Implement preset <> config distinction
michaelsproul Jun 2, 2021
b602c90
Update confusing name `SyncCommitteeSubnetSize` -> `SyncSubcommitteeS…
realbigsean Jun 2, 2021
06d2ff2
Merge branch 'altair-latest-spec' of https://github.com/michaelsproul…
realbigsean Jun 2, 2021
d188557
Updates for latest spec merge
realbigsean Jun 2, 2021
7a9b2ac
update client for `lighthouse/spec` endpoint
realbigsean Jun 2, 2021
2238539
Add back accidentally deleted import
realbigsean Jun 2, 2021
897fb7c
Return ConfigAndPreset from VC API
michaelsproul Jun 3, 2021
f08e96f
Don't panic if there aren't any aggregators
michaelsproul Jun 3, 2021
9940cc8
Check state root in transition tests
michaelsproul Jun 3, 2021
c0b20fb
Fix clippy
michaelsproul Jun 3, 2021
f532a92
Fix Pyrmont & Prater configs. Delete Toledo.
michaelsproul Jun 3, 2021
5a556b3
Add compatibility shim for /config/spec
michaelsproul Jun 3, 2021
fa36f34
Merge branch 'altair-latest-spec' of https://github.com/michaelsproul…
realbigsean Jun 3, 2021
d756b1d
Revert "update client for `lighthouse/spec` endpoint"
realbigsean Jun 3, 2021
58a7258
- Update `SYNC_COMMITTEE_SUBNET_COUNT` to alpha.6
realbigsean Jun 3, 2021
6d4327a
- Update `NaiveAggregationPool`'s default capacity so it is specific …
realbigsean Jun 3, 2021
bd31c0a
fix `observed_aggregates` tests
realbigsean Jun 3, 2021
bf518af
PR updates
realbigsean Jun 7, 2021
e4b7d14
fix op pool tests
realbigsean Jun 8, 2021
0a2d57f
Minor cleanups
michaelsproul Jun 8, 2021
bc68a2d
Merge pull request #2373 from michaelsproul/altair-latest-spec
michaelsproul Jun 8, 2021
aa192fb
Calculate `SyncAggregate` on demand
realbigsean Jun 8, 2021
0c445ee
Op pool migration + superstruct
realbigsean Jun 9, 2021
c0ec45c
Fix op pool test
realbigsean Jun 10, 2021
99bffdb
Update to spec v1.1.0-alpha.7
michaelsproul Jun 11, 2021
41414d1
- Fix sync committee verification on slot prior to sync committee per…
realbigsean Jun 11, 2021
b624253
Refactor how we retrieve `PublicKey` for sync signature verification
realbigsean Jun 14, 2021
bb7e9cf
Key `observed_contributors` on `SlotSubcommitteeIndex`
realbigsean Jun 14, 2021
17a0431
Update mainnet preset YAML
michaelsproul Jun 15, 2021
2ee4dc5
Add tests for sync committee verification at slot before sync committ…
realbigsean Jun 15, 2021
04cadec
fix op pool tests
realbigsean Jun 15, 2021
5b80cb9
- Make `SyncSubnetId` a required argument for `verify_sync_signature_…
realbigsean Jun 16, 2021
3227651
fix sync committee verification test macro
realbigsean Jun 16, 2021
c962b88
Merge pull request #2405 from sigp/altair-alpha.7
michaelsproul Jun 16, 2021
8a13d6f
Merge remote-tracking branch 'origin/unstable' into altair
michaelsproul Jun 17, 2021
ffba057
Fix beacon_chain test
michaelsproul Jun 17, 2021
47d4b37
rust 1.53.0 updates
realbigsean Jun 17, 2021
28f668c
add recursion limit to `simulator` crate
realbigsean Jun 17, 2021
bd7f9d9
cargo fmt
realbigsean Jun 17, 2021
f43e710
Merge branch 'altair' of https://github.com/sigp/lighthouse into sync…
realbigsean Jun 17, 2021
98f7a03
`SyncCommitteSignature` -> `SyncCommitteeMessage`
realbigsean Jun 17, 2021
5d4cf0b
Merge branch 'rust-1.53.0-lints' of https://github.com/realbigsean/li…
realbigsean Jun 17, 2021
f56ea57
Updates related to merge with `unstable`
realbigsean Jun 17, 2021
24e0d1d
More updates related to `SyncCommitteMessage` refactor
realbigsean Jun 17, 2021
f32d14e
Couple more `unstable` merge fixes
realbigsean Jun 17, 2021
f14c5e5
Fix `SyncAggregate` field name
realbigsean Jun 17, 2021
186125e
fix the expected error in the sync contribution verification test at …
realbigsean Jun 22, 2021
0a4c4f5
Merge remote-tracking branch 'origin/unstable' into altair
michaelsproul Jun 23, 2021
c878ff5
Updates related to merge with `unstable`
realbigsean Jun 17, 2021
95e3069
Couple more `unstable` merge fixes
realbigsean Jun 17, 2021
ffd2b75
Import some relevant funcs from the VC
michaelsproul Jun 17, 2021
7481e9c
Fix issues with skip slots at fork boundaries
michaelsproul Jun 29, 2021
0ca1662
Fix clippy again
michaelsproul Jun 29, 2021
8386024
Merge remote-tracking branch 'origin/altair' into sync-committee-pools
michaelsproul Jun 29, 2021
ad32be2
alpha.8 updates
realbigsean Jun 30, 2021
e377395
Merge remote-tracking branch 'origin/unstable' into altair
michaelsproul Jul 6, 2021
5d36a6c
Merge remote-tracking branch 'origin/unstable' into altair
michaelsproul Jul 6, 2021
a40826b
Merge remote-tracking branch 'origin/unstable' into altair
michaelsproul Jul 9, 2021
c555e67
Merge branch 'altair' of https://github.com/sigp/lighthouse into sync…
realbigsean Jul 12, 2021
a54bcc5
Merge branch 'unstable' of https://github.com/sigp/lighthouse into sy…
realbigsean Jul 12, 2021
853e984
remove duplicate function from merge
realbigsean Jul 12, 2021
6e2e193
Update EF tests tag from alpha.7 to alpha.8
realbigsean Jul 12, 2021
a2e39fc
remove duplicate import from merge
realbigsean Jul 12, 2021
22da623
fix incorrect method name and update test to ensure off-by-one is inv…
realbigsean Jul 13, 2021
86ba5ce
Merge remote-tracking branch 'origin/unstable' into sync-committee-pools
michaelsproul Jul 15, 2021
8e07e1a
Fix conflict in tests
michaelsproul Jul 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 11 additions & 17 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
//! ```

use crate::{
beacon_chain::{
HEAD_LOCK_TIMEOUT, MAXIMUM_GOSSIP_CLOCK_DISPARITY, VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT,
},
beacon_chain::{MAXIMUM_GOSSIP_CLOCK_DISPARITY, VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT},
metrics,
observed_attestations::ObserveOutcome,
observed_aggregates::ObserveOutcome,
observed_attesters::Error as ObservedAttestersError,
BeaconChain, BeaconChainError, BeaconChainTypes,
};
Expand Down Expand Up @@ -430,7 +428,7 @@ impl<T: BeaconChainTypes> VerifiedAggregatedAttestation<T> {
match chain
.observed_aggregators
.read()
.validator_has_been_observed(attestation, aggregator_index as usize)
.validator_has_been_observed(attestation.data.target.epoch, aggregator_index as usize)
{
Ok(true) => Err(Error::AggregatorAlreadyKnown(aggregator_index)),
Ok(false) => Ok(()),
Expand Down Expand Up @@ -485,7 +483,7 @@ impl<T: BeaconChainTypes> VerifiedAggregatedAttestation<T> {
if let ObserveOutcome::AlreadyKnown = chain
.observed_attestations
.write()
.observe_attestation(attestation, Some(attestation_root))
.observe_item(attestation, Some(attestation_root))
.map_err(|e| Error::BeaconChainError(e.into()))?
{
return Err(Error::AttestationAlreadyKnown(attestation_root));
Expand All @@ -498,7 +496,7 @@ impl<T: BeaconChainTypes> VerifiedAggregatedAttestation<T> {
if chain
.observed_aggregators
.write()
.observe_validator(&attestation, aggregator_index as usize)
.observe_validator(attestation.data.target.epoch, aggregator_index as usize)
.map_err(BeaconChainError::from)?
{
return Err(Error::PriorAttestationKnown {
Expand Down Expand Up @@ -689,7 +687,7 @@ impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<T> {
if chain
.observed_attesters
.read()
.validator_has_been_observed(&attestation, validator_index as usize)
.validator_has_been_observed(attestation.data.target.epoch, validator_index as usize)
.map_err(BeaconChainError::from)?
{
return Err(Error::PriorAttestationKnown {
Expand All @@ -716,7 +714,7 @@ impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<T> {
if chain
.observed_attesters
.write()
.observe_validator(&attestation, validator_index as usize)
.observe_validator(attestation.data.target.epoch, validator_index as usize)
.map_err(BeaconChainError::from)?
{
return Err(Error::PriorAttestationKnown {
Expand Down Expand Up @@ -923,10 +921,8 @@ pub fn verify_attestation_signature<T: BeaconChainTypes>(
.ok_or(BeaconChainError::ValidatorPubkeyCacheLockTimeout)?;

let fork = chain
.canonical_head
.try_read_for(HEAD_LOCK_TIMEOUT)
.ok_or(BeaconChainError::CanonicalHeadLockTimeout)
.map(|head| head.beacon_state.fork())?;
.spec
.fork_at_epoch(indexed_attestation.data.target.epoch);

let signature_set = indexed_attestation_signature_set_from_pubkeys(
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
Expand Down Expand Up @@ -1029,10 +1025,8 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
}

let fork = chain
.canonical_head
.try_read_for(HEAD_LOCK_TIMEOUT)
.ok_or(BeaconChainError::CanonicalHeadLockTimeout)
.map(|head| head.beacon_state.fork())?;
.spec
.fork_at_epoch(indexed_attestation.data.target.epoch);

let signature_sets = vec![
signed_aggregate_selection_proof_signature_set(
Expand Down
229 changes: 219 additions & 10 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@ use crate::eth1_chain::{Eth1Chain, Eth1ChainBackend};
use crate::events::ServerSentEventHandler;
use crate::head_tracker::HeadTracker;
use crate::migrate::BackgroundMigrator;
use crate::naive_aggregation_pool::{Error as NaiveAggregationError, NaiveAggregationPool};
use crate::observed_attestations::{Error as AttestationObservationError, ObservedAttestations};
use crate::observed_attesters::{ObservedAggregators, ObservedAttesters};
use crate::naive_aggregation_pool::{
AggregatedAttestationMap, Error as NaiveAggregationError, NaiveAggregationPool,
SyncContributionAggregateMap,
};
use crate::observed_aggregates::{
Error as AttestationObservationError, ObservedAggregateAttestations, ObservedSyncContributions,
};
use crate::observed_attesters::{
ObservedAggregators, ObservedAttesters, ObservedSyncAggregators, ObservedSyncContributors,
};
use crate::observed_block_producers::ObservedBlockProducers;
use crate::observed_operations::{ObservationOutcome, ObservedOperations};
use crate::persisted_beacon_chain::{PersistedBeaconChain, DUMMY_CANONICAL_HEAD_BLOCK_ROOT};
use crate::persisted_fork_choice::PersistedForkChoice;
use crate::shuffling_cache::{BlockShufflingIds, ShufflingCache};
use crate::snapshot_cache::SnapshotCache;
use crate::sync_committee_verification::{
Error as SyncCommitteeError, VerifiedSyncCommitteeMessage, VerifiedSyncContribution,
};
use crate::timeout_rw_lock::TimeoutRwLock;
use crate::validator_monitor::{
get_block_delay_ms, get_slot_delay_ms, timestamp_now, ValidatorMonitor,
Expand All @@ -39,6 +49,7 @@ use itertools::process_results;
use itertools::Itertools;
use operation_pool::{OperationPool, PersistedOperationPool};
use parking_lot::{Mutex, RwLock};
use safe_arith::SafeArith;
use slasher::Slasher;
use slog::{crit, debug, error, info, trace, warn, Logger};
use slot_clock::SlotClock;
Expand Down Expand Up @@ -221,14 +232,28 @@ pub struct BeaconChain<T: BeaconChainTypes> {
///
/// This pool accepts `Attestation` objects that only have one aggregation bit set and provides
/// a method to get an aggregated `Attestation` for some `AttestationData`.
pub naive_aggregation_pool: RwLock<NaiveAggregationPool<T::EthSpec>>,
pub naive_aggregation_pool: RwLock<NaiveAggregationPool<AggregatedAttestationMap<T::EthSpec>>>,
/// A pool of `SyncCommitteeContribution` dedicated to the "naive aggregation strategy" defined in the eth2
/// specs.
///
/// This pool accepts `SyncCommitteeContribution` objects that only have one aggregation bit set and provides
/// a method to get an aggregated `SyncCommitteeContribution` for some `SyncCommitteeContributionData`.
pub naive_sync_aggregation_pool:
RwLock<NaiveAggregationPool<SyncContributionAggregateMap<T::EthSpec>>>,
/// Contains a store of attestations which have been observed by the beacon chain.
pub(crate) observed_attestations: RwLock<ObservedAttestations<T::EthSpec>>,
pub(crate) observed_attestations: RwLock<ObservedAggregateAttestations<T::EthSpec>>,
/// Contains a store of sync contributions which have been observed by the beacon chain.
pub(crate) observed_sync_contributions: RwLock<ObservedSyncContributions<T::EthSpec>>,
/// Maintains a record of which validators have been seen to attest in recent epochs.
pub(crate) observed_attesters: RwLock<ObservedAttesters<T::EthSpec>>,
/// Maintains a record of which validators have been seen sending sync messages in recent epochs.
pub(crate) observed_sync_contributors: RwLock<ObservedSyncContributors<T::EthSpec>>,
/// Maintains a record of which validators have been seen to create `SignedAggregateAndProofs`
/// in recent epochs.
pub(crate) observed_aggregators: RwLock<ObservedAggregators<T::EthSpec>>,
/// Maintains a record of which validators have been seen to create `SignedContributionAndProofs`
/// in recent epochs.
pub(crate) observed_sync_aggregators: RwLock<ObservedSyncAggregators<T::EthSpec>>,
/// Maintains a record of which validators have proposed blocks for each slot.
pub(crate) observed_block_producers: RwLock<ObservedBlockProducers<T::EthSpec>>,
/// Maintains a record of which validators have submitted voluntary exits.
Expand Down Expand Up @@ -823,6 +848,80 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
})
}

/// Return the sync committee at `slot + 1` from the canonical chain.
///
/// This is useful when dealing with sync committee messages, because messages are signed
/// and broadcast one slot prior to the slot of the sync committee (which is relevant at
/// sync committee period boundaries).
pub fn sync_committee_at_next_slot(
&self,
slot: Slot,
) -> Result<Arc<SyncCommittee<T::EthSpec>>, Error> {
let epoch = slot.safe_add(1)?.epoch(T::EthSpec::slots_per_epoch());
self.sync_committee_at_epoch(epoch)
}

/// Return the sync committee at `epoch` from the canonical chain.
pub fn sync_committee_at_epoch(
&self,
epoch: Epoch,
) -> Result<Arc<SyncCommittee<T::EthSpec>>, Error> {
// Try to read a committee from the head. This will work most of the time, but will fail
// for faraway committees, or if there are skipped slots at the transition to Altair.
let spec = &self.spec;
let committee_from_head =
self.with_head(
|head| match head.beacon_state.get_built_sync_committee(epoch, spec) {
Ok(committee) => Ok(Some(committee.clone())),
Err(BeaconStateError::SyncCommitteeNotKnown { .. })
| Err(BeaconStateError::IncorrectStateVariant) => Ok(None),
Err(e) => Err(Error::from(e)),
},
)?;

if let Some(committee) = committee_from_head {
Ok(committee)
} else {
// Slow path: load a state (or advance the head).
let sync_committee_period = epoch.sync_committee_period(spec)?;
let committee = self
.state_for_sync_committee_period(sync_committee_period)?
.get_built_sync_committee(epoch, spec)?
.clone();
Ok(committee)
}
}

/// Load a state suitable for determining the sync committee for the given period.
///
/// Specifically, the state at the start of the *previous* sync committee period.
///
/// This is sufficient for historical duties, and efficient in the case where the head
/// is lagging the current period and we need duties for the next period (because we only
/// have to transition the head to start of the current period).
///
/// We also need to ensure that the load slot is after the Altair fork.
///
/// **WARNING**: the state returned will have dummy state roots. It should only be used
/// for its sync committees (determining duties, etc).
pub fn state_for_sync_committee_period(
&self,
sync_committee_period: u64,
) -> Result<BeaconState<T::EthSpec>, Error> {
let altair_fork_epoch = self
.spec
.altair_fork_epoch
.ok_or(Error::AltairForkDisabled)?;

let load_slot = std::cmp::max(
self.spec.epochs_per_sync_committee_period * sync_committee_period.saturating_sub(1),
altair_fork_epoch,
)
.start_slot(T::EthSpec::slots_per_epoch());

self.state_at_slot(load_slot, StateSkipConfig::WithoutStateRoots)
}

/// Returns info representing the head block and state.
///
/// A summarized version of `Self::head` that involves less cloning.
Expand Down Expand Up @@ -1270,6 +1369,36 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
})
}

/// Accepts some `SyncCommitteeMessage` from the network and attempts to verify it, returning `Ok(_)` if
/// it is valid to be (re)broadcast on the gossip network.
pub fn verify_sync_committee_message_for_gossip(
&self,
sync_message: SyncCommitteeMessage,
subnet_id: SyncSubnetId,
) -> Result<VerifiedSyncCommitteeMessage, SyncCommitteeError> {
metrics::inc_counter(&metrics::SYNC_MESSAGE_PROCESSING_REQUESTS);
let _timer = metrics::start_timer(&metrics::SYNC_MESSAGE_GOSSIP_VERIFICATION_TIMES);

VerifiedSyncCommitteeMessage::verify(sync_message, subnet_id, self).map(|v| {
metrics::inc_counter(&metrics::SYNC_MESSAGE_PROCESSING_SUCCESSES);
v
})
}

/// Accepts some `SignedContributionAndProof` from the network and attempts to verify it,
/// returning `Ok(_)` if it is valid to be (re)broadcast on the gossip network.
pub fn verify_sync_contribution_for_gossip(
&self,
sync_contribution: SignedContributionAndProof<T::EthSpec>,
) -> Result<VerifiedSyncContribution<T>, SyncCommitteeError> {
metrics::inc_counter(&metrics::SYNC_CONTRIBUTION_PROCESSING_REQUESTS);
let _timer = metrics::start_timer(&metrics::SYNC_CONTRIBUTION_GOSSIP_VERIFICATION_TIMES);
VerifiedSyncContribution::verify(sync_contribution, self).map(|v| {
metrics::inc_counter(&metrics::SYNC_CONTRIBUTION_PROCESSING_SUCCESSES);
v
})
}

/// Accepts some attestation-type object and attempts to verify it in the context of fork
/// choice. If it is valid it is applied to `self.fork_choice`.
///
Expand Down Expand Up @@ -1339,6 +1468,70 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Ok(unaggregated_attestation)
}

/// Accepts a `VerifiedSyncCommitteeMessage` and attempts to apply it to the "naive
/// aggregation pool".
///
/// The naive aggregation pool is used by local validators to produce
/// `SignedContributionAndProof`.
///
/// If the sync message is too old (low slot) to be included in the pool it is simply dropped
/// and no error is returned.
pub fn add_to_naive_sync_aggregation_pool(
&self,
verified_sync_committee_message: VerifiedSyncCommitteeMessage,
) -> Result<VerifiedSyncCommitteeMessage, SyncCommitteeError> {
let sync_message = verified_sync_committee_message.sync_message();
let positions_by_subnet_id: &HashMap<SyncSubnetId, Vec<usize>> =
verified_sync_committee_message.subnet_positions();
for (subnet_id, positions) in positions_by_subnet_id.iter() {
for position in positions {
let _timer =
metrics::start_timer(&metrics::SYNC_CONTRIBUTION_PROCESSING_APPLY_TO_AGG_POOL);
let contribution = SyncCommitteeContribution::from_message(
sync_message,
subnet_id.into(),
*position,
)?;

match self
.naive_sync_aggregation_pool
.write()
.insert(&contribution)
{
Ok(outcome) => trace!(
self.log,
"Stored unaggregated sync committee message";
"outcome" => ?outcome,
"index" => sync_message.validator_index,
"slot" => sync_message.slot.as_u64(),
),
Err(NaiveAggregationError::SlotTooLow {
slot,
lowest_permissible_slot,
}) => {
trace!(
self.log,
"Refused to store unaggregated sync committee message";
"lowest_permissible_slot" => lowest_permissible_slot.as_u64(),
"slot" => slot.as_u64(),
);
}
Err(e) => {
error!(
self.log,
"Failed to store unaggregated sync committee message";
"error" => ?e,
"index" => sync_message.validator_index,
"slot" => sync_message.slot.as_u64(),
);
return Err(Error::from(e).into());
}
};
}
}
Ok(verified_sync_committee_message)
}

/// Accepts a `VerifiedAggregatedAttestation` and attempts to apply it to `self.op_pool`.
///
/// The op pool is used by local block producers to pack blocks with operations.
Expand Down Expand Up @@ -1368,6 +1561,26 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Ok(signed_aggregate)
}

/// Accepts a `VerifiedSyncContribution` and attempts to apply it to `self.op_pool`.
///
/// The op pool is used by local block producers to pack blocks with operations.
pub fn add_contribution_to_block_inclusion_pool(
&self,
contribution: VerifiedSyncContribution<T>,
) -> Result<(), SyncCommitteeError> {
let _timer = metrics::start_timer(&metrics::SYNC_CONTRIBUTION_PROCESSING_APPLY_TO_OP_POOL);

// If there's no eth1 chain then it's impossible to produce blocks and therefore
// useless to put things in the op pool.
if self.eth1_chain.is_some() {
self.op_pool
.insert_sync_contribution(contribution.contribution())
.map_err(Error::from)?;
}

Ok(())
}

/// Filter an attestation from the op pool for shuffling compatibility.
///
/// Use the provided `filter_cache` map to memoize results.
Expand Down Expand Up @@ -1818,11 +2031,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// Iterate through the attestations in the block and register them as an "observed
// attestation". This will stop us from propagating them on the gossip network.
for a in signed_block.message().body().attestations() {
match self
.observed_attestations
.write()
.observe_attestation(a, None)
{
match self.observed_attestations.write().observe_item(a, None) {
// If the observation was successful or if the slot for the attestation was too
// low, continue.
//
Expand Down
Loading