Skip to content

Reduce Electra boilerplate #5939

@dapplion

Description

@dapplion

Description

Electra's new attestation type has introduced a match boilerplate.

match self {
Self::Base(body) => body.attestations.len(),
Self::Altair(body) => body.attestations.len(),
Self::Bellatrix(body) => body.attestations.len(),
Self::Capella(body) => body.attestations.len(),
Self::Deneb(body) => body.attestations.len(),
Self::Electra(body) => body.attestations.len(),
}

BeaconBlockBodyRefMut::Base(ref mut blk) => {
blk.attester_slashings
.push(attester_slashing.as_base().unwrap().clone())
.expect("should update attester slashing");
}
BeaconBlockBodyRefMut::Altair(ref mut blk) => {
blk.attester_slashings
.push(attester_slashing.as_base().unwrap().clone())
.expect("should update attester slashing");
}
BeaconBlockBodyRefMut::Bellatrix(ref mut blk) => {
blk.attester_slashings
.push(attester_slashing.as_base().unwrap().clone())
.expect("should update attester slashing");
}
BeaconBlockBodyRefMut::Capella(ref mut blk) => {
blk.attester_slashings
.push(attester_slashing.as_base().unwrap().clone())
.expect("should update attester slashing");
}
BeaconBlockBodyRefMut::Deneb(ref mut blk) => {
blk.attester_slashings
.push(attester_slashing.as_base().unwrap().clone())
.expect("should update attester slashing");
}
BeaconBlockBodyRefMut::Electra(ref mut blk) => {
blk.attester_slashings
.push(attester_slashing.as_electra().unwrap().clone())
.expect("should update attester slashing");
}
}

In previous issues, I stressed how we want fork addition to be as easy as possible to foster innovation. Having to add 1000 lines of mindless code just to develop a new feature is not optimal.

We can use some macro magic to prevent a new ForkName::EIP9999 variant from having to modify all these statements.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions