Skip to content

Commit

Permalink
WIP: Electra fork
Browse files Browse the repository at this point in the history
  • Loading branch information
povi committed May 8, 2024
1 parent b81448d commit 7ba8f3a
Show file tree
Hide file tree
Showing 93 changed files with 7,583 additions and 700 deletions.
9 changes: 6 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions benches/benches/fork_choice_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use once_cell::unsync::Lazy;
use std_ext::ArcExt as _;
use transition_functions::{combined, unphased::StateRootPolicy};
use types::{
combined::SignedBeaconBlock,
combined::{Attestation, SignedBeaconBlock},
config::Config,
phase0::{containers::Attestation, primitives::Slot},
phase0::primitives::Slot,
preset::{Mainnet, Preset},
traits::{BeaconState as _, SignedBeaconBlock as _},
};
Expand Down Expand Up @@ -81,7 +81,10 @@ impl Criterion {
}

for attestation in holesky::aggregate_attestations_by_slot(slot) {
process_attestation(&mut store, Arc::new(attestation))?;
process_attestation(
&mut store,
Arc::new(Attestation::Phase0(attestation)),
)?;
}
}

Expand Down Expand Up @@ -190,7 +193,7 @@ fn process_attestation<P: Preset>(
store: &mut Store<P>,
attestation: Arc<Attestation<P>>,
) -> Result<()> {
let slot = attestation.data.slot;
let slot = attestation.data().slot;
let origin = AttestationOrigin::<Never>::Test;
let attestation_action = store.validate_attestation(attestation, &origin)?;

Expand All @@ -203,7 +206,7 @@ fn process_attestation<P: Preset>(
};

let valid_attestation = ValidAttestation {
data: attestation.data,
data: attestation.data(),
attesting_indices,
is_from_block: false,
};
Expand Down
2 changes: 1 addition & 1 deletion consensus-spec-tests
33 changes: 29 additions & 4 deletions eth1_api/src/eth1_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use enum_iterator::Sequence as _;
use ethereum_types::H64;
use execution_engine::{
EngineGetPayloadV1Response, EngineGetPayloadV2Response, EngineGetPayloadV3Response,
ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3, ForkChoiceStateV1,
ForkChoiceUpdatedResponse, PayloadAttributes, PayloadId, PayloadStatusV1,
EngineGetPayloadV4Response, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3,
ExecutionPayloadV4, ForkChoiceStateV1, ForkChoiceUpdatedResponse, PayloadAttributes, PayloadId,
PayloadStatusV1,
};
use futures::{channel::mpsc::UnboundedSender, lock::Mutex, Future};
use log::warn;
Expand Down Expand Up @@ -227,6 +228,21 @@ impl Eth1Api {
];
self.execute("engine_newPayloadV3", params).await
}
(
ExecutionPayload::Electra(payload),
Some(ExecutionPayloadParams::Deneb {
versioned_hashes,
parent_beacon_block_root,
}),
) => {
let payload_v4 = ExecutionPayloadV4::from(payload);
let params = vec![
serde_json::to_value(payload_v4)?,
serde_json::to_value(versioned_hashes)?,
serde_json::to_value(parent_beacon_block_root)?,
];
self.execute("engine_newPayloadV4", params).await
}
_ => bail!(Error::InvalidParameters),
}
}
Expand Down Expand Up @@ -270,10 +286,11 @@ impl Eth1Api {
Phase::Bellatrix => self.execute("engine_forkchoiceUpdatedV1", params).await?,
Phase::Capella => self.execute("engine_forkchoiceUpdatedV2", params).await?,
Phase::Deneb => self.execute("engine_forkchoiceUpdatedV3", params).await?,
Phase::Electra => self.execute("engine_forkchoiceUpdatedV3", params).await?,
_ => {
// This match arm will silently match any new phases.
// Cause a compilation error if a new phase is added.
const_assert_eq!(Phase::CARDINALITY, 5);
const_assert_eq!(Phase::CARDINALITY, 6);

bail!(Error::PhasePreBellatrix)
}
Expand All @@ -283,10 +300,11 @@ impl Eth1Api {
Phase::Bellatrix => payload_id.map(PayloadId::Bellatrix),
Phase::Capella => payload_id.map(PayloadId::Capella),
Phase::Deneb => payload_id.map(PayloadId::Deneb),
Phase::Electra => payload_id.map(PayloadId::Electra),
_ => {
// This match arm will silently match any new phases.
// Cause a compilation error if a new phase is added.
const_assert_eq!(Phase::CARDINALITY, 5);
const_assert_eq!(Phase::CARDINALITY, 6);

bail!(Error::PhasePreBellatrix)
}
Expand Down Expand Up @@ -332,6 +350,13 @@ impl Eth1Api {
.await
.map(Into::into)
}
PayloadId::Electra(payload_id) => {
let params = vec![serde_json::to_value(payload_id)?];

self.execute::<EngineGetPayloadV4Response<P>>("engine_getPayloadV4", params)
.await
.map(Into::into)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion eth2_libp2p
2 changes: 1 addition & 1 deletion execution_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ workspace = true

[dependencies]
anyhow = { workspace = true }
derive_more = { workspace = true }
bls = { workspace = true }
either = { workspace = true }
ethereum-types = { workspace = true }
futures = { workspace = true }
Expand Down
7 changes: 4 additions & 3 deletions execution_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ pub use crate::{
execution_engine::{ExecutionEngine, MockExecutionEngine, NullExecutionEngine},
types::{
EngineGetPayloadV1Response, EngineGetPayloadV2Response, EngineGetPayloadV3Response,
ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3, ForkChoiceStateV1,
ForkChoiceUpdatedResponse, PayloadAttributes, PayloadAttributesV1, PayloadAttributesV2,
PayloadAttributesV3, PayloadId, PayloadStatusV1, PayloadValidationStatus,
EngineGetPayloadV4Response, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3,
ExecutionPayloadV4, ForkChoiceStateV1, ForkChoiceUpdatedResponse, PayloadAttributes,
PayloadAttributesV1, PayloadAttributesV2, PayloadAttributesV3, PayloadId, PayloadStatusV1,
PayloadValidationStatus,
},
};

Expand Down
Loading

0 comments on commit 7ba8f3a

Please sign in to comment.