Electra attestation changes rm decode impl (#5856)

* Remove Crappy Decode impl for Attestation

* Remove Inefficient Attestation Decode impl

* Implement Schema Upgrade / Downgrade

* Update beacon_node/beacon_chain/src/schema_change/migration_schema_v20.rs

Co-authored-by: Michael Sproul <micsproul@gmail.com>

---------

Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
ethDreamer
2024-05-30 17:34:14 +02:00
committed by GitHub
parent 3e10e68c1d
commit 75432e1135
10 changed files with 354 additions and 130 deletions

View File

@@ -12,7 +12,9 @@ use smallvec::{smallvec, SmallVec};
use ssz::{Decode, Encode};
use ssz_derive::{Decode, Encode};
use std::marker::PhantomData;
use types::{AttesterSlashing, AttesterSlashingOnDisk, AttesterSlashingRefOnDisk};
use types::{
AttesterSlashing, AttesterSlashingBase, AttesterSlashingOnDisk, AttesterSlashingRefOnDisk,
};
use types::{
BeaconState, ChainSpec, Epoch, EthSpec, Fork, ForkVersion, ProposerSlashing,
SignedBlsToExecutionChange, SignedVoluntaryExit,
@@ -366,6 +368,49 @@ impl<E: EthSpec> TransformPersist for AttesterSlashing<E> {
}
}
// TODO: Remove this once we no longer support DB schema version 17
impl<E: EthSpec> TransformPersist for types::AttesterSlashingBase<E> {
type Persistable = Self;
type PersistableRef<'a> = &'a Self;
fn as_persistable_ref(&self) -> Self::PersistableRef<'_> {
self
}
fn from_persistable(persistable: Self::Persistable) -> Self {
persistable
}
}
// TODO: Remove this once we no longer support DB schema version 17
impl<E: EthSpec> From<SigVerifiedOp<AttesterSlashingBase<E>, E>>
for SigVerifiedOp<AttesterSlashing<E>, E>
{
fn from(base: SigVerifiedOp<AttesterSlashingBase<E>, E>) -> Self {
SigVerifiedOp {
op: AttesterSlashing::Base(base.op),
verified_against: base.verified_against,
_phantom: PhantomData,
}
}
}
// TODO: Remove this once we no longer support DB schema version 17
impl<E: EthSpec> TryFrom<SigVerifiedOp<AttesterSlashing<E>, E>>
for SigVerifiedOp<AttesterSlashingBase<E>, E>
{
type Error = String;
fn try_from(slashing: SigVerifiedOp<AttesterSlashing<E>, E>) -> Result<Self, Self::Error> {
match slashing.op {
AttesterSlashing::Base(base) => Ok(SigVerifiedOp {
op: base,
verified_against: slashing.verified_against,
_phantom: PhantomData,
}),
AttesterSlashing::Electra(_) => Err("non-base attester slashing".to_string()),
}
}
}
impl TransformPersist for ProposerSlashing {
type Persistable = Self;
type PersistableRef<'a> = &'a Self;