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: handle electra attester slashing #7397

Open
wants to merge 7 commits into
base: unstable
Choose a base branch
from

Conversation

ensi321
Copy link
Contributor

@ensi321 ensi321 commented Jan 25, 2025

Update various places to handle electra attester slashing type:

  • AttesterSlashingRepository
  • submitPoolAttesterSlashingsV2
  • opPool
  • GossipType
  • processAttesterSlashing

@ensi321 ensi321 requested a review from a team as a code owner January 25, 2025 03:10
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.

Good reminder to review open electra todos, I pushed some minor updates. Only a question regarding the db changes which seem unnecessary to me.

return {data: chain.opPool.getAllAttesterSlashings()};
},

async getPoolAttesterSlashingsV2() {
// TODO Electra: Determine fork based on data returned by api
return {data: chain.opPool.getAllAttesterSlashings(), meta: {version: ForkName.phase0}};
const fork = chain.config.getForkName(chain.clock.currentSlot);
Copy link
Member

@nflaig nflaig Jan 25, 2025

Choose a reason for hiding this comment

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

Note: I think we can just use clock slot here and don't need to filter out phase0 attester slashings as those can be serialized using electra.AttesterSlashing ssz type and should still be able to include them onchain as well

// TODO Electra: Refactor submitPoolAttesterSlashings and submitPoolAttesterSlashingsV2
await this.submitPoolAttesterSlashings({attesterSlashing});
await validateApiAttesterSlashing(chain, attesterSlashing);
chain.opPool.insertAttesterSlashing(ForkName.electra, attesterSlashing);
Copy link
Member

@nflaig nflaig Jan 25, 2025

Choose a reason for hiding this comment

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

Note: hard coding to electra here seems fine since the api already ensures that correct attesting_indices length for pre-electra attester slashings

Edit: after further looking into this we need to use the proper type has hash tree root would be different otherwise

@@ -68,12 +68,21 @@ export function getBeaconPoolApi({
},

async getPoolAttesterSlashings() {
const fork = chain.config.getForkName(chain.clock.currentSlot);

if (isForkPostElectra(fork)) {
Copy link
Member

@nflaig nflaig Jan 25, 2025

Choose a reason for hiding this comment

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

Note: we might not be able to serialize data if this is called post-electra since the limit of attesting_indices is higher, better to throw an error and refer to v2 api

@@ -66,7 +75,7 @@ export class OpPool {
]);

for (const attesterSlashing of attesterSlashings) {
this.insertAttesterSlashing(attesterSlashing.value, attesterSlashing.key);
this.insertAttesterSlashing(ForkName.electra, attesterSlashing.value, attesterSlashing.key);
Copy link
Member

@nflaig nflaig Jan 25, 2025

Choose a reason for hiding this comment

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

Note: same as insert from api, we can just use electra type as it works for both phase0 and electra attester slashing

Edit: on the api we need to pick correct fork type since we calculate the hash tree root but here we pass rootHash which means fork will be unused

import {Bucket, getBucketNameByValue} from "../buckets.js";

// We add a 1-byte prefix where 0 means pre-electra and 1 means post-electra
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this? It should be sufficient to just use ssz.electra.AttesterSlashing to serialize / deserialize data, we already validate on api and gossip (using proper ssz type) that the limit is correct

@nflaig nflaig added this to the v1.26.0 milestone Jan 25, 2025
@@ -26,7 +26,7 @@ export enum Bucket {
phase0_depositData = 12, // [DEPRECATED] index -> DepositData
phase0_exit = 13, // ValidatorIndex -> VoluntaryExit
phase0_proposerSlashing = 14, // ValidatorIndex -> ProposerSlashing
phase0_attesterSlashing = 15, // Root -> AttesterSlashing
allForks_attesterSlashing = 15, // Root -> AttesterSlashing
Copy link
Member

Choose a reason for hiding this comment

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

Note: changing bucket name affects metrics label but I think we are fine with that

Copy link

codecov bot commented Jan 25, 2025

Codecov Report

Attention: Patch coverage is 42.85714% with 8 lines in your changes missing coverage. Please review.

Project coverage is 48.60%. Comparing base (cf23839) to head (27cb3a1).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #7397      +/-   ##
============================================
- Coverage     48.60%   48.60%   -0.01%     
============================================
  Files           603      603              
  Lines         40523    40524       +1     
  Branches       2070     2070              
============================================
  Hits          19698    19698              
- Misses        20787    20788       +1     
  Partials         38       38              

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.

2 participants