Skip to content

Commit 255fdf0

Browse files
authored
Added Capella Data Structures to consensus/types (#3637)
* Ran Cargo fmt * Added Capella Data Structures to consensus/types
1 parent 1430b56 commit 255fdf0

File tree

18 files changed

+1592
-170
lines changed

18 files changed

+1592
-170
lines changed

Cargo.lock

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon_node/beacon_chain/src/execution_payload.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use std::sync::Arc;
2525
use tokio::task::JoinHandle;
2626
use tree_hash::TreeHash;
2727
use types::{
28-
BeaconBlockRef, BeaconState, BeaconStateError, Blob, EthSpec, ExecPayload,
29-
ExecutionBlockHash, Hash256, KzgCommitment, SignedBeaconBlock, Slot,
28+
BeaconBlockRef, BeaconState, BeaconStateError, Blob, EthSpec, ExecPayload, ExecutionBlockHash,
29+
Hash256, KzgCommitment, SignedBeaconBlock, Slot,
3030
};
3131

3232
pub type PreparePayloadResult<Payload, E> =

beacon_node/http_api/src/publish_blobs.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ use beacon_chain::validator_monitor::{get_slot_delay_ms, timestamp_now};
33
use beacon_chain::{BeaconChain, BeaconChainTypes};
44
use lighthouse_network::PubsubMessage;
55
use network::NetworkMessage;
6-
use slog::{Logger};
6+
use slog::Logger;
77
use std::sync::Arc;
88
use tokio::sync::mpsc::UnboundedSender;
9-
use types::{
10-
SignedBlobsSidecar,
11-
};
9+
use types::SignedBlobsSidecar;
1210
use warp::Rejection;
1311

1412
/// Handles a request from the HTTP API for full blocks.

beacon_node/network/src/beacon_processor/worker/gossip_methods.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2257,7 +2257,10 @@ impl<T: BeaconChainTypes> Worker<T> {
22572257
BlobError::ProposalSignatureInvalid => {
22582258
self.propagate_validation_result(message_id, peer_id, MessageAcceptance::Reject);
22592259
}
2260-
BlobError::RepeatSidecar { proposer: _, slot: _ } => {
2260+
BlobError::RepeatSidecar {
2261+
proposer: _,
2262+
slot: _,
2263+
} => {
22612264
self.propagate_validation_result(message_id, peer_id, MessageAcceptance::Ignore);
22622265
}
22632266
BlobError::UnknownHeadBlock { beacon_block_root } => {

consensus/types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ regex = "1.5.5"
4444
lazy_static = "1.4.0"
4545
parking_lot = "0.12.0"
4646
itertools = "0.10.0"
47-
superstruct = "0.5.0"
47+
superstruct = "0.6.0"
4848
serde_json = "1.0.74"
4949
smallvec = "1.8.0"
5050
serde_with = "1.13.0"

consensus/types/src/beacon_block.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tree_hash_derive::TreeHash;
1717

1818
/// A block of the `BeaconChain`.
1919
#[superstruct(
20-
variants(Base, Altair, Merge, Eip4844),
20+
variants(Base, Altair, Merge, Capella, Eip4844),
2121
variant_attributes(
2222
derive(
2323
Debug,
@@ -48,7 +48,7 @@ use tree_hash_derive::TreeHash;
4848
#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))]
4949
#[tree_hash(enum_behaviour = "transparent")]
5050
#[ssz(enum_behaviour = "transparent")]
51-
pub struct BeaconBlock<T: EthSpec, Payload: ExecPayload<T> = FullPayload<T>> {
51+
pub struct BeaconBlock<T: EthSpec, Payload: AbstractExecPayload<T> = FullPayload<T>> {
5252
#[superstruct(getter(copy))]
5353
pub slot: Slot,
5454
#[superstruct(getter(copy))]
@@ -64,16 +64,22 @@ pub struct BeaconBlock<T: EthSpec, Payload: ExecPayload<T> = FullPayload<T>> {
6464
pub body: BeaconBlockBodyAltair<T, Payload>,
6565
#[superstruct(only(Merge), partial_getter(rename = "body_merge"))]
6666
pub body: BeaconBlockBodyMerge<T, Payload>,
67+
#[superstruct(only(Capella), partial_getter(rename = "body_capella"))]
68+
pub body: BeaconBlockBodyCapella<T, Payload>,
6769
#[superstruct(only(Eip4844), partial_getter(rename = "body_eip4844"))]
6870
pub body: BeaconBlockBodyEip4844<T, Payload>,
6971
}
7072

7173
pub type BlindedBeaconBlock<E> = BeaconBlock<E, BlindedPayload<E>>;
7274

73-
impl<T: EthSpec, Payload: ExecPayload<T>> SignedRoot for BeaconBlock<T, Payload> {}
74-
impl<'a, T: EthSpec, Payload: ExecPayload<T>> SignedRoot for BeaconBlockRef<'a, T, Payload> {}
75+
impl<T: EthSpec, Payload: AbstractExecPayload<T>> SignedRoot for BeaconBlock<T, Payload> {}
76+
impl<'a, T: EthSpec, Payload: AbstractExecPayload<T>> SignedRoot
77+
for BeaconBlockRef<'a, T, Payload>
78+
{
79+
}
7580

76-
impl<T: EthSpec, Payload: ExecPayload<T>> BeaconBlock<T, Payload> {
81+
impl<T: EthSpec, Payload: AbstractExecPayload<T>> BeaconBlock<T, Payload> {
82+
// FIXME: deal with capella / eip4844 forks here as well
7783
/// Returns an empty block to be used during genesis.
7884
pub fn empty(spec: &ChainSpec) -> Self {
7985
if spec.bellatrix_fork_epoch == Some(T::genesis_epoch()) {
@@ -180,7 +186,7 @@ impl<T: EthSpec, Payload: ExecPayload<T>> BeaconBlock<T, Payload> {
180186
}
181187
}
182188

183-
impl<'a, T: EthSpec, Payload: ExecPayload<T>> BeaconBlockRef<'a, T, Payload> {
189+
impl<'a, T: EthSpec, Payload: AbstractExecPayload<T>> BeaconBlockRef<'a, T, Payload> {
184190
/// Returns the name of the fork pertaining to `self`.
185191
///
186192
/// Will return an `Err` if `self` has been instantiated to a variant conflicting with the fork
@@ -191,6 +197,7 @@ impl<'a, T: EthSpec, Payload: ExecPayload<T>> BeaconBlockRef<'a, T, Payload> {
191197
BeaconBlockRef::Base { .. } => ForkName::Base,
192198
BeaconBlockRef::Altair { .. } => ForkName::Altair,
193199
BeaconBlockRef::Merge { .. } => ForkName::Merge,
200+
BeaconBlockRef::Capella { .. } => ForkName::Capella,
194201
BeaconBlockRef::Eip4844 { .. } => ForkName::Eip4844,
195202
};
196203

@@ -245,12 +252,12 @@ impl<'a, T: EthSpec, Payload: ExecPayload<T>> BeaconBlockRef<'a, T, Payload> {
245252

246253
/// Extracts a reference to an execution payload from a block, returning an error if the block
247254
/// is pre-merge.
248-
pub fn execution_payload(&self) -> Result<&Payload, Error> {
255+
pub fn execution_payload(&self) -> Result<Payload::Ref<'a>, Error> {
249256
self.body().execution_payload()
250257
}
251258
}
252259

253-
impl<'a, T: EthSpec, Payload: ExecPayload<T>> BeaconBlockRefMut<'a, T, Payload> {
260+
impl<'a, T: EthSpec, Payload: AbstractExecPayload<T>> BeaconBlockRefMut<'a, T, Payload> {
254261
/// Convert a mutable reference to a beacon block to a mutable ref to its body.
255262
pub fn body_mut(self) -> BeaconBlockBodyRefMut<'a, T, Payload> {
256263
map_beacon_block_ref_mut_into_beacon_block_body_ref_mut!(&'a _, self, |block, cons| cons(
@@ -259,7 +266,7 @@ impl<'a, T: EthSpec, Payload: ExecPayload<T>> BeaconBlockRefMut<'a, T, Payload>
259266
}
260267
}
261268

262-
impl<T: EthSpec, Payload: ExecPayload<T>> BeaconBlockBase<T, Payload> {
269+
impl<T: EthSpec, Payload: AbstractExecPayload<T>> BeaconBlockBase<T, Payload> {
263270
/// Returns an empty block to be used during genesis.
264271
pub fn empty(spec: &ChainSpec) -> Self {
265272
BeaconBlockBase {
@@ -380,7 +387,7 @@ impl<T: EthSpec, Payload: ExecPayload<T>> BeaconBlockBase<T, Payload> {
380387
}
381388
}
382389

383-
impl<T: EthSpec, Payload: ExecPayload<T>> BeaconBlockAltair<T, Payload> {
390+
impl<T: EthSpec, Payload: AbstractExecPayload<T>> BeaconBlockAltair<T, Payload> {
384391
/// Returns an empty Altair block to be used during genesis.
385392
pub fn empty(spec: &ChainSpec) -> Self {
386393
BeaconBlockAltair {
@@ -439,7 +446,7 @@ impl<T: EthSpec, Payload: ExecPayload<T>> BeaconBlockAltair<T, Payload> {
439446
}
440447
}
441448

442-
impl<T: EthSpec, Payload: ExecPayload<T>> BeaconBlockMerge<T, Payload> {
449+
impl<T: EthSpec, Payload: AbstractExecPayload<T>> BeaconBlockMerge<T, Payload> {
443450
/// Returns an empty Merge block to be used during genesis.
444451
pub fn empty(spec: &ChainSpec) -> Self {
445452
BeaconBlockMerge {
@@ -461,7 +468,7 @@ impl<T: EthSpec, Payload: ExecPayload<T>> BeaconBlockMerge<T, Payload> {
461468
deposits: VariableList::empty(),
462469
voluntary_exits: VariableList::empty(),
463470
sync_aggregate: SyncAggregate::empty(),
464-
execution_payload: Payload::default(),
471+
execution_payload: Payload::Merge::default(),
465472
},
466473
}
467474
}
@@ -536,7 +543,7 @@ macro_rules! impl_from {
536543
parent_root,
537544
state_root,
538545
body,
539-
}, payload)
546+
}, payload.map(Into::into))
540547
}
541548
}
542549
}
@@ -545,6 +552,7 @@ macro_rules! impl_from {
545552
impl_from!(BeaconBlockBase, <E, FullPayload<E>>, <E, BlindedPayload<E>>, |body: BeaconBlockBodyBase<_, _>| body.into());
546553
impl_from!(BeaconBlockAltair, <E, FullPayload<E>>, <E, BlindedPayload<E>>, |body: BeaconBlockBodyAltair<_, _>| body.into());
547554
impl_from!(BeaconBlockMerge, <E, FullPayload<E>>, <E, BlindedPayload<E>>, |body: BeaconBlockBodyMerge<_, _>| body.into());
555+
impl_from!(BeaconBlockCapella, <E, FullPayload<E>>, <E, BlindedPayload<E>>, |body: BeaconBlockBodyCapella<_, _>| body.into());
548556
impl_from!(BeaconBlockEip4844, <E, FullPayload<E>>, <E, BlindedPayload<E>>, |body: BeaconBlockBodyEip4844<_, _>| body.into());
549557

550558
// We can clone blocks with payloads to blocks without payloads, without cloning the payload.
@@ -576,6 +584,7 @@ macro_rules! impl_clone_as_blinded {
576584
impl_clone_as_blinded!(BeaconBlockBase, <E, FullPayload<E>>, <E, BlindedPayload<E>>);
577585
impl_clone_as_blinded!(BeaconBlockAltair, <E, FullPayload<E>>, <E, BlindedPayload<E>>);
578586
impl_clone_as_blinded!(BeaconBlockMerge, <E, FullPayload<E>>, <E, BlindedPayload<E>>);
587+
impl_clone_as_blinded!(BeaconBlockCapella, <E, FullPayload<E>>, <E, BlindedPayload<E>>);
579588
impl_clone_as_blinded!(BeaconBlockEip4844, <E, FullPayload<E>>, <E, BlindedPayload<E>>);
580589

581590
// A reference to a full beacon block can be cloned into a blinded beacon block, without cloning the

0 commit comments

Comments
 (0)