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

feat: implement EIP-7549 #6689

Merged
merged 13 commits into from
May 8, 2024
Merged

feat: implement EIP-7549 #6689

merged 13 commits into from
May 8, 2024

Conversation

ensi321
Copy link
Contributor

@ensi321 ensi321 commented Apr 19, 2024

NOTE FOR REVIEWERS:

Description

General:

  • Add containers & presets
  • Retrieve field values from serialized electra.attestations

Beacon node:

  • Modify processAttestations
  • Update attesting indices parsing from electra.Attestation

p2p:

  • Handle and publish new format of beacon_aggregate_and_proof and beacon_attestation
  • New validation rule

Validator:

  • Use MAX_ATTESTER_SLASHINGS_ELECTRA limit when constructing block body
  • Sign electra.attestations and electra.aggregateAndProof
  • Come up with new algo to get electra.attestations for block body in AggregatedAttestationPool
  • Create valid attestation and aggregate when attesting/aggregating

Misc but important:

@ensi321 ensi321 added the status-do-not-merge Merging this issue will break the build. Do not merge! label Apr 19, 2024
@ensi321 ensi321 marked this pull request as ready for review May 7, 2024 19:09
@ensi321 ensi321 requested a review from a team as a code owner May 7, 2024 19:09
ensi321 and others added 13 commits May 7, 2024 22:13
* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>
const bitIndex = attestation.aggregationBits.getSingleTrueBit();

// Should never happen, attestations are verified against this exact condition before
if (bitIndex === null) {
throw Error("Invalid attestation not exactly one bit set");
}

if ("committeeBits" in attestation && !("committeeBits" in aggregate)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use isElectraAttestation() util, same for below

throw new AttestationError(GossipAction.REJECT, {code: AttestationErrorCode.NOT_EXACTLY_ONE_COMMITTEE_BIT_SET});
}
// [REJECT] aggregate.data.index == 0
if (attData.index === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (attData.index === 0) {
if (attData.index !== 0) {

Copy link
Contributor

@twoeths twoeths May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert.equal should be more convenient
Edit: if (attData.index !== 0) { should be better since it throws gossip error to handle at upper level

}

// [REJECT] aggregate.data.index == 0
if (attData.index === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (attData.index === 0) {
if (attData.index !== 0) {

throw Error("Attempt to aggregate electra attestation into phase0 attestation");
}

if (!("committeeBits" in attestation) && "committeeBits" in aggregate) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need these validation unless we have to for the type assertion
in order to reach this code, attestation data should be the same hence the same type of attestation

subnet: number;
attDataRootHex: RootHex;
};

export type AttestationOrBytes = ApiAttestation | GossipAttestation;

/** attestation from api */
export type ApiAttestation = {attestation: phase0.Attestation; serializedData: null};
export type ApiAttestation = {attestation: phase0.Attestation; serializedData: null}; // TODO Electra: add new attestation type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove TODO?

return {
aggregationBits: BitArray.fromSingleBit(duty.committeeLength, duty.validatorCommitteeIndex),
data: attestationData,
committeeBits: BitArray.fromSingleBit(duty.committeesAtSlot, duty.committeeIndex),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
committeeBits: BitArray.fromSingleBit(duty.committeesAtSlot, duty.committeeIndex),
committeeBits: BitArray.fromSingleBit(MAX_COMMITTEES_PER_SLOT, duty.committeeIndex),

const attestationCommitteeIndex = attestation.committeeBits.getSingleTrueBit();
const aggregateCommitteeIndex = (aggregate as AggregateFastElectra).committeeBits.getSingleTrueBit();

if (attestationCommitteeIndex !== aggregateCommitteeIndex) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now same attestation data could belong to different committee indices so we need to add 1 more level to our cache
implemented in #6744

signature: aggFast.signature.toBytes(PointFormat.compressed),
};
function fastToAttestation(aggFast: AggregateFast): allForks.Attestation {
if ("committeeBits" in aggFast) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ("committeeBits" in aggFast) {
return {...aggFast, signature: aggFast.signature.toBytes(PointFormat.compressed)};

@@ -48,4 +48,4 @@ export type SignedConsolidation = ValueOf<typeof ssz.SignedConsolidation>;

export type PendingBalanceDeposit = ValueOf<typeof ssz.PendingBalanceDeposit>;
export type PartialWithdrawal = ValueOf<typeof ssz.PartialWithdrawal>;
export type PendingConsolidation = ValueOf<typeof ssz.PendingConsolidation>;
export type PendingConsolidation = ValueOf<typeof ssz.PendingConsolidation>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we remove this diff? i think newlines got removed

Copy link
Contributor

@g11tech g11tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging the current work with electra

@g11tech g11tech merged commit 838add9 into electra-fork May 8, 2024
11 of 17 checks passed
@g11tech g11tech deleted the nc/7549 branch May 8, 2024 11:00
@ensi321 ensi321 removed the status-do-not-merge Merging this issue will break the build. Do not merge! label May 8, 2024
g11tech pushed a commit that referenced this pull request May 24, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
g11tech pushed a commit to g11tech/lodestar that referenced this pull request Jun 19, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (ChainSafe#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
g11tech added a commit that referenced this pull request Jun 25, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
g11tech added a commit that referenced this pull request Jun 25, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
g11tech added a commit that referenced this pull request Jul 1, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
g11tech added a commit that referenced this pull request Jul 30, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
g11tech added a commit that referenced this pull request Jul 31, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
g11tech added a commit that referenced this pull request Aug 2, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
g11tech added a commit that referenced this pull request Aug 9, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
g11tech added a commit that referenced this pull request Aug 9, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
g11tech added a commit that referenced this pull request Aug 23, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
g11tech added a commit that referenced this pull request Aug 27, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
philknows pushed a commit that referenced this pull request Sep 3, 2024
* initial commit

* lint

* Add getAttestingIndices and update getIndexedAttestation

* Update gossip validation

* Update attestation gossip validation

* aggregateAndProof validation

* clean up

* Validator

* Misc

* Fix the build erros

* feat: get attestations for electra block (#6732)

* feat: getAttestationsForBlock() for electra

* chore: fix lint

* fix: MAX_ATTESTATIONS_PER_GROUP_ELECTRA and address PR comments

* chore: unit test aggregateConsolidation

* Fix rebase mistake

* Address my own comment :)

---------

Co-authored-by: Navie Chan <[email protected]>

* Fix check-types

* Address comments

---------

Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: tuyennhv <[email protected]>
Co-authored-by: gajinder <[email protected]>
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.22.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants