Skip to content

feat: add Electra attestation V2 endpoints - #6951

Merged
wemeetagain merged 21 commits into
electra-fork-rebasejul30from
nc/attestation-api-v2
Aug 5, 2024
Merged

feat: add Electra attestation V2 endpoints#6951
wemeetagain merged 21 commits into
electra-fork-rebasejul30from
nc/attestation-api-v2

Conversation

@ensi321

@ensi321 ensi321 commented Jul 15, 2024

Copy link
Copy Markdown
Member

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

Comment thread packages/beacon-node/src/api/impl/beacon/pool/index.ts
@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

@nflaig nflaig left a comment

Copy link
Copy Markdown
Member

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

Comment thread packages/api/src/beacon/routes/beacon/block.ts Outdated
Comment thread packages/api/src/beacon/routes/beacon/block.ts Outdated
Comment thread packages/api/src/beacon/routes/beacon/pool.ts Outdated
Comment thread packages/api/src/beacon/routes/beacon/pool.ts Outdated
Comment thread packages/api/src/beacon/routes/beacon/pool.ts Outdated
Comment thread packages/api/src/beacon/routes/beacon/pool.ts Outdated
Comment thread packages/api/src/beacon/routes/beacon/pool.ts Outdated
Comment thread packages/validator/src/services/attestation.ts
Comment thread packages/validator/test/utils/apiStub.ts
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
Copy Markdown
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
Copy Markdown
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[]

Comment thread packages/api/src/beacon/routes/beacon/pool.ts
Comment thread packages/beacon-node/src/api/impl/validator/index.ts

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

Copy link
Copy Markdown
Member

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
Copy Markdown
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

}

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

Copy link
Copy Markdown
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
Copy Markdown
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)

@ensi321 ensi321 Jul 31, 2024

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ForkElectraOnwards?

Copy link
Copy Markdown
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


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

Copy link
Copy Markdown
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

};
try {
(await this.api.beacon.submitPoolAttestations({signedAttestations})).assertOk();
// TODO Electra: Ensure calling V2 works in pre-electra

@nflaig nflaig Jul 30, 2024

Copy link
Copy Markdown
Member

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

res: undefined,
},
submitPoolAttestationsV2: {
args: {signedAttestations: [ssz.phase0.Attestation.defaultValue()]},

Copy link
Copy Markdown
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

@nflaig nflaig left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member

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

@ensi321

ensi321 commented Aug 1, 2024

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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 force-pushed the nc/attestation-api-v2 branch from c6e1cca to c9394c6 Compare August 5, 2024 04:19
@ensi321
ensi321 changed the base branch from electra-fork to electra-fork-rebasejul30 August 5, 2024 04:20

@wemeetagain wemeetagain left a comment

Copy link
Copy Markdown
Member

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
@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 <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

* Address comment

* Add api stub back

* Add todos

* Review PR

* Fix rebase

* Lint

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
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 <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

* Address comment

* Add api stub back

* Add todos

* Review PR

* Fix rebase

* Lint

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
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 <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

* Address comment

* Add api stub back

* Add todos

* Review PR

* Fix rebase

* Lint

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
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 <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

* Address comment

* Add api stub back

* Add todos

* Review PR

* Fix rebase

* Lint

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
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 <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

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

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

* Address comment

* Add api stub back

* Add todos

* Review PR

* Fix rebase

* Lint

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
@wemeetagain

Copy link
Copy Markdown
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