Update VC and BN APIs for naive aggregation (#950)

* Refactor `Attestation` production

* Add constant

* Start refactor for aggregation

* Return early when no attesting validators

* Refactor into individual functions

* Tidy, add comments

* Add first draft of NaiveAggregationPool

* Further progress on naive aggregation pool

* Fix compile errors in VC

* Change locking logic for naive pool

* Introduce AttesationType

* Add pruning, comments

* Add MAX_ATTESTATIONS_PER_SLOT restriction

* Add pruning based on slot

* Update BN for new aggregation fns

* Fix test compile errors

* Fix failing rest_api test

* Move SignedAggregateAndProof into own file

* Update docs, fix warning

* Tidy some formatting in validator API

* Remove T::default_spec from signing

* Fix failing rest test

* Tidy

* Add test, fix bug

* Improve naive pool tests

* Add max attestations test

* Revert changes to the op_pool

* Refactor timer
This commit is contained in:
Paul Hauner
2020-03-25 21:14:05 +11:00
committed by GitHub
parent 58111cddb2
commit fbcf0f8e2e
30 changed files with 1407 additions and 752 deletions

View File

@@ -17,7 +17,8 @@ use types::{
generate_deterministic_keypair, AttesterSlashingTestTask, ProposerSlashingTestTask,
},
BeaconBlock, BeaconState, ChainSpec, Domain, Epoch, EthSpec, MinimalEthSpec, PublicKey,
RelativeEpoch, Signature, SignedBeaconBlock, SignedRoot, Slot, Validator,
RelativeEpoch, Signature, SignedAggregateAndProof, SignedBeaconBlock, SignedRoot, Slot,
Validator,
};
use version;
@@ -134,7 +135,31 @@ fn validator_produce_attestation() {
.expect("should fetch duties from http api");
let duties = &duties[0];
// Try publishing the attestation without a signature, ensure it is flagged as invalid.
// Try publishing the attestation without a signature or a committee bit set, ensure it is
// raises an error.
let publish_result = env.runtime().block_on(
remote_node
.http
.validator()
.publish_attestations(vec![attestation.clone()]),
);
assert!(
publish_result.is_err(),
"the unsigned published attestation should return error"
);
// Set the aggregation bit.
attestation
.aggregation_bits
.set(
duties
.attestation_committee_position
.expect("should have committee position"),
true,
)
.expect("should set attestation bit");
// Try publishing with an aggreagation bit set, but an invalid signature.
let publish_status = env
.runtime()
.block_on(
@@ -143,12 +168,23 @@ fn validator_produce_attestation() {
.validator()
.publish_attestations(vec![attestation.clone()]),
)
.expect("should publish attestation");
.expect("should publish attestation with invalid signature");
assert!(
!publish_status.is_valid(),
"the unsigned published attestation should not be valid"
);
// Un-set the aggregation bit, so signing doesn't error.
attestation
.aggregation_bits
.set(
duties
.attestation_committee_position
.expect("should have committee position"),
false,
)
.expect("should un-set attestation bit");
attestation
.sign(
&keypair.sk,
@@ -167,13 +203,48 @@ fn validator_produce_attestation() {
remote_node
.http
.validator()
.publish_attestations(vec![attestation]),
.publish_attestations(vec![attestation.clone()]),
)
.expect("should publish attestation");
assert!(
publish_status.is_valid(),
"the signed published attestation should be valid"
);
// Try obtaining an aggregated attestation with a matching attestation data to the previous
// one.
let aggregated_attestation = env
.runtime()
.block_on(
remote_node
.http
.validator()
.produce_aggregate_attestation(&attestation.data),
)
.expect("should fetch aggregated attestation from http api");
let signed_aggregate_and_proof = SignedAggregateAndProof::from_aggregate(
validator_index as u64,
aggregated_attestation,
&keypair.sk,
&state.fork,
spec,
);
// Publish the signed aggregate.
let publish_status = env
.runtime()
.block_on(
remote_node
.http
.validator()
.publish_aggregate_and_proof(vec![signed_aggregate_and_proof]),
)
.expect("should publish aggregate and proof");
assert!(
publish_status.is_valid(),
"the signed aggregate and proof should be valid"
);
}
#[test]