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: add Electra attestation V2 endpoints #6951

Merged
merged 21 commits into from
Aug 5, 2024

Conversation

ensi321
Copy link
Contributor

@ensi321 ensi321 commented Jul 15, 2024

This PR adds definition of the new attestation related V2 endpoints in Electra. It also reverts some of the hacks we made to some V1 endpoints during devnet-0.

Note some of the V1 and V2 endpoints are not functioning properly. TODOs are added to ensure their functionalities

Endpoints added:

  • GET /eth/v2/validator/aggregate_attestation
  • GET /eth/v2/beacon/blocks/{block_id}/attestations
  • GET /eth/v2/beacon/pool/attestations
  • POST /eth/v2/beacon/pool/attestations
  • GET /eth/v2/beacon/pool/attester_slashings
  • POST /eth/v2/beacon/pool/attester_slashings (Only support pre-electra request)
  • POST /eth/v2/validator/aggregate_and_proofs

Endpoints modified:

  • GET /eth/v1/validator/aggregate_attestation (Broken)
  • GET /eth/v1/beacon/blocks/{block_id}/attestations
  • GET /eth/v1/beacon/pool/attestations
  • GET /eth/v1/beacon/pool/attester_slashings

Remaining todos:

  • Modify attestation pool to handle pre-electra attestation properly (Related to GET /eth/v1/validator/aggregate_attestation)
  • Review submitPoolAttesterSlashings flow to handle electra.AttesterSlashing (Related to POST /eth/v2/beacon/pool/attester_slashings)

Passes oapi spec test with the latest master branch of ethereum/beacon-APIs

Partially closes #6895

@ensi321 ensi321 marked this pull request as ready for review July 17, 2024 20:35
@ensi321 ensi321 requested a review from a team as a code owner July 17, 2024 20:35
Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

The diff in PR is kinda strange in a few places because we had the hacks previously.

I see two options

  • either we remove the hacks separately and then rebase this branch on top
  • or we merge this, do another review on electra branch, and submit fixes afterwards if any

I guess option (2) is favorable as (1) might be too much effort for what it's worth

packages/api/src/beacon/routes/beacon/block.ts Outdated Show resolved Hide resolved
packages/api/src/beacon/routes/beacon/block.ts Outdated Show resolved Hide resolved
packages/api/src/beacon/routes/beacon/pool.ts Outdated Show resolved Hide resolved
packages/api/src/beacon/routes/beacon/pool.ts Outdated Show resolved Hide resolved
packages/api/src/beacon/routes/beacon/pool.ts Outdated Show resolved Hide resolved
packages/api/src/beacon/routes/beacon/pool.ts Outdated Show resolved Hide resolved
packages/api/src/beacon/routes/beacon/pool.ts Outdated Show resolved Hide resolved
packages/validator/test/utils/apiStub.ts Show resolved Hide resolved

async getPoolAttestationsV2({slot, committeeIndex}) {
// Already filtered by slot
let attestations = chain.aggregatedAttestationPool.getAll(slot);
const fork = chain.config.getForkName(slot ?? attestations[0].data.slot) ?? ForkName.phase0;
Copy link
Member

Choose a reason for hiding this comment

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

This logic is unsafe and also incorrect, need to be careful with accessing items in array as typescript does not properly warn here

If array is empty, this will give an error attestations[0].data.slot, need to do attestations[0]?.data.slot

I would also favor a logic like this

const fork = chain.config.getForkName(slot ?? attestations[0]?.data.slot ?? chain.clock.currentSlot);

Copy link
Member

Choose a reason for hiding this comment

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

Honestly what we should do across the code base is type all arrays like this

(Attestation | undefined)[]

instead of

Attestation[]

@@ -258,7 +258,7 @@ export class AttestationService {
}

this.logger.verbose("Aggregating attestations", logCtx);
const res = await this.api.validator.getAggregatedAttestation({
const res = await this.api.validator.getAggregatedAttestationV2({
Copy link
Contributor

Choose a reason for hiding this comment

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

same to the above, vc should follow the spec to call correct api depending on the clock slot. Note that lodestar vc could call bn from other clients as well

Copy link
Member

Choose a reason for hiding this comment

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

we can do a kurtosis run before we merge electra branch to unstable, I have a config which tests interop will all other clients but we will need to use v1 apis pre-electra in any case becasue we don't know if users updated their clients, similar to how we transitioned to block v3 api

@@ -47,3 +47,9 @@ export type ForkBlobs = Exclude<ForkName, ForkPreBlobs>;
export function isForkBlobs(fork: ForkName): fork is ForkBlobs {
return isForkWithdrawals(fork) && fork !== ForkName.capella;
}

export type ForkPreElectra = ForkPreBlobs | ForkName.deneb;
export type ForkElectra = Exclude<ForkName, ForkPreElectra>;
Copy link
Member

Choose a reason for hiding this comment

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

anyone has an idea for a fancy name here? Looks we like we usually don't use the fork name but rather a feature added in the fork

cc @g11tech

Copy link
Member

Choose a reason for hiding this comment

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

Yes ForkElectra is a little confusing here imo.

Maybe ForkPostElectra.

I'd also be in favor of using that same naming for the other forks (eg ForkPostBellatrix instead of ForkExecution)

Copy link
Contributor Author

@ensi321 ensi321 Jul 31, 2024

Choose a reason for hiding this comment

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

I'd also be in favor of using that same naming for the other forks (eg ForkPostBellatrix instead of ForkExecution)

Yea I guess back in the days, each hard fork has a single signature feature (or theme) that you can name after. For electra, there is a bunch of new features that are significant, so naming convention like ForkExecution can't apply to electra.

Copy link
Contributor

Choose a reason for hiding this comment

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

ForkElectraOnwards?

Copy link
Member

Choose a reason for hiding this comment

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

in favor of pre / post fork terminology, it seems most commonly used and the most concise

@@ -258,7 +258,7 @@ export class AttestationService {
}

this.logger.verbose("Aggregating attestations", logCtx);
const res = await this.api.validator.getAggregatedAttestation({
const res = await this.api.validator.getAggregatedAttestationV2({
Copy link
Member

Choose a reason for hiding this comment

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

we can do a kurtosis run before we merge electra branch to unstable, I have a config which tests interop will all other clients but we will need to use v1 apis pre-electra in any case becasue we don't know if users updated their clients, similar to how we transitioned to block v3 api

@@ -225,7 +225,8 @@ export class AttestationService {
...(this.opts?.disableAttestationGrouping && {index: attestationNoCommittee.index}),
};
try {
(await this.api.beacon.submitPoolAttestations({signedAttestations})).assertOk();
// TODO Electra: Ensure calling V2 works in pre-electra
Copy link
Member

@nflaig nflaig Jul 30, 2024

Choose a reason for hiding this comment

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

just a note here, while all apis should be backward compatible, i.e. work pre-electra, we still can't use them until the fork happens. After the electra fork, we can safely remove all v1 calls and only use v2

@@ -114,10 +129,18 @@ export const testData: GenericServerTestCases<Endpoints> = {
args: {signedAttestations: [ssz.phase0.Attestation.defaultValue()]},
res: undefined,
},
submitPoolAttestationsV2: {
args: {signedAttestations: [ssz.phase0.Attestation.defaultValue()]},
Copy link
Member

Choose a reason for hiding this comment

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

I opened an issue to test this with electra data #6987

Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

LGTM - can solve remaining todos separately to make it easier to review

req: {
writeReqJson: ({signedAttestations}) => {
const fork = config.getForkName(signedAttestations[0].data.slot);
const fork = config.getForkName(signedAttestations[0]?.data.slot ?? 0);
Copy link
Member

Choose a reason for hiding this comment

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

In practice, we won't be calling this api with an empty array but it's possible based on the types and the spec does not explicitly state that the array is not allowed to be empty.

We don't have access to the clock here, so it's hard as far as I can see to determine the current fork but passing 0 (translating to phase0) should be fine as well since array is empty anyways.

@wemeetagain
Copy link
Member

Are we waiting on merging this until electra-fork branch is rebased on unstable? Or merging now?

@ensi321
Copy link
Contributor Author

ensi321 commented Aug 1, 2024

Are we waiting on merging this until electra-fork branch is rebased on unstable? Or merging now?

@wemeetagain Yes we will wait until the electra-fork branch is rebased

@wemeetagain
Copy link
Member

Ok, can you base this PR on electra-fork-rebasejul30 in that case?

@wemeetagain wemeetagain mentioned this pull request Aug 1, 2024
@ensi321 ensi321 changed the base branch from electra-fork to electra-fork-rebasejul30 August 5, 2024 04:20
Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

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

merging, we can continue the next round of review there

@wemeetagain wemeetagain merged commit d0c6d21 into electra-fork-rebasejul30 Aug 5, 2024
12 of 17 checks passed
@wemeetagain wemeetagain deleted the nc/attestation-api-v2 branch August 5, 2024 19:53
g11tech pushed a commit that referenced this pull request Aug 9, 2024
* Initial commit

* getAggregatedAttestationV2

* Lint

* Fix minor flaw

* Add publishAggregateAndProofsV2

* Fix spelling

* Fix CI

* Fix spec test

* Clean up events api

* Run against latest beacon api spec

* Revert changes to emitted events

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Address comment

* Add api stub back

* Add todos

* Review PR

* Fix rebase

* Lint

---------

Co-authored-by: Nico Flaig <[email protected]>
g11tech pushed a commit that referenced this pull request Aug 9, 2024
* Initial commit

* getAggregatedAttestationV2

* Lint

* Fix minor flaw

* Add publishAggregateAndProofsV2

* Fix spelling

* Fix CI

* Fix spec test

* Clean up events api

* Run against latest beacon api spec

* Revert changes to emitted events

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Address comment

* Add api stub back

* Add todos

* Review PR

* Fix rebase

* Lint

---------

Co-authored-by: Nico Flaig <[email protected]>
g11tech pushed a commit that referenced this pull request Aug 23, 2024
* Initial commit

* getAggregatedAttestationV2

* Lint

* Fix minor flaw

* Add publishAggregateAndProofsV2

* Fix spelling

* Fix CI

* Fix spec test

* Clean up events api

* Run against latest beacon api spec

* Revert changes to emitted events

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Address comment

* Add api stub back

* Add todos

* Review PR

* Fix rebase

* Lint

---------

Co-authored-by: Nico Flaig <[email protected]>
g11tech pushed a commit that referenced this pull request Aug 27, 2024
* Initial commit

* getAggregatedAttestationV2

* Lint

* Fix minor flaw

* Add publishAggregateAndProofsV2

* Fix spelling

* Fix CI

* Fix spec test

* Clean up events api

* Run against latest beacon api spec

* Revert changes to emitted events

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Address comment

* Add api stub back

* Add todos

* Review PR

* Fix rebase

* Lint

---------

Co-authored-by: Nico Flaig <[email protected]>
philknows pushed a commit that referenced this pull request Sep 3, 2024
* Initial commit

* getAggregatedAttestationV2

* Lint

* Fix minor flaw

* Add publishAggregateAndProofsV2

* Fix spelling

* Fix CI

* Fix spec test

* Clean up events api

* Run against latest beacon api spec

* Revert changes to emitted events

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Update packages/api/src/beacon/routes/beacon/pool.ts

Co-authored-by: Nico Flaig <[email protected]>

* Address comment

* Add api stub back

* Add todos

* Review PR

* Fix rebase

* Lint

---------

Co-authored-by: Nico Flaig <[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