mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 21:34:46 +00:00
Merge remote-tracking branch 'origin/unstable' into tree-states
This commit is contained in:
@@ -323,8 +323,9 @@ impl ForkChoiceTest {
|
||||
)
|
||||
.unwrap();
|
||||
let slot = self.harness.get_current_slot();
|
||||
let (mut block_tuple, mut state) = self.harness.make_block(state, slot).await;
|
||||
func(&mut block_tuple.0, &mut state);
|
||||
let ((block_arc, _block_blobs), mut state) = self.harness.make_block(state, slot).await;
|
||||
let mut block = (*block_arc).clone();
|
||||
func(&mut block, &mut state);
|
||||
let current_slot = self.harness.get_current_slot();
|
||||
self.harness
|
||||
.chain
|
||||
@@ -332,8 +333,8 @@ impl ForkChoiceTest {
|
||||
.fork_choice_write_lock()
|
||||
.on_block(
|
||||
current_slot,
|
||||
block_tuple.0.message(),
|
||||
block_tuple.0.canonical_root(),
|
||||
block.message(),
|
||||
block.canonical_root(),
|
||||
Duration::from_secs(0),
|
||||
&state,
|
||||
PayloadVerificationStatus::Verified,
|
||||
@@ -366,8 +367,9 @@ impl ForkChoiceTest {
|
||||
)
|
||||
.unwrap();
|
||||
let slot = self.harness.get_current_slot();
|
||||
let (mut block_tuple, mut state) = self.harness.make_block(state, slot).await;
|
||||
mutation_func(&mut block_tuple.0, &mut state);
|
||||
let ((block_arc, _block_blobs), mut state) = self.harness.make_block(state, slot).await;
|
||||
let mut block = (*block_arc).clone();
|
||||
mutation_func(&mut block, &mut state);
|
||||
let current_slot = self.harness.get_current_slot();
|
||||
let err = self
|
||||
.harness
|
||||
@@ -376,8 +378,8 @@ impl ForkChoiceTest {
|
||||
.fork_choice_write_lock()
|
||||
.on_block(
|
||||
current_slot,
|
||||
block_tuple.0.message(),
|
||||
block_tuple.0.canonical_root(),
|
||||
block.message(),
|
||||
block.canonical_root(),
|
||||
Duration::from_secs(0),
|
||||
&state,
|
||||
PayloadVerificationStatus::Verified,
|
||||
|
||||
@@ -90,7 +90,7 @@ async fn invalid_block_header_state_slot() {
|
||||
let slot = state.slot() + Slot::new(1);
|
||||
|
||||
let ((signed_block, _), mut state) = harness.make_block_return_pre_state(state, slot).await;
|
||||
let (mut block, signature) = signed_block.deconstruct();
|
||||
let (mut block, signature) = (*signed_block).clone().deconstruct();
|
||||
*block.slot_mut() = slot + Slot::new(1);
|
||||
|
||||
let mut ctxt = ConsensusContext::new(block.slot());
|
||||
@@ -123,7 +123,7 @@ async fn invalid_parent_block_root() {
|
||||
let ((signed_block, _), mut state) = harness
|
||||
.make_block_return_pre_state(state, slot + Slot::new(1))
|
||||
.await;
|
||||
let (mut block, signature) = signed_block.deconstruct();
|
||||
let (mut block, signature) = (*signed_block).clone().deconstruct();
|
||||
*block.parent_root_mut() = Hash256::from([0xAA; 32]);
|
||||
|
||||
let mut ctxt = ConsensusContext::new(block.slot());
|
||||
@@ -158,7 +158,7 @@ async fn invalid_block_signature() {
|
||||
let ((signed_block, _), mut state) = harness
|
||||
.make_block_return_pre_state(state, slot + Slot::new(1))
|
||||
.await;
|
||||
let (block, _) = signed_block.deconstruct();
|
||||
let (block, _) = (*signed_block).clone().deconstruct();
|
||||
|
||||
let mut ctxt = ConsensusContext::new(block.slot());
|
||||
let result = per_block_processing(
|
||||
|
||||
@@ -39,6 +39,7 @@ pub trait ExecPayload<T: EthSpec>: Debug + Clone + PartialEq + Hash + TreeHash +
|
||||
fn transactions(&self) -> Option<&Transactions<T>>;
|
||||
/// fork-specific fields
|
||||
fn withdrawals_root(&self) -> Result<Hash256, Error>;
|
||||
fn blob_gas_used(&self) -> Result<u64, Error>;
|
||||
|
||||
/// Is this a default payload with 0x0 roots for transactions and withdrawals?
|
||||
fn is_default_with_zero_roots(&self) -> bool;
|
||||
@@ -254,6 +255,13 @@ impl<T: EthSpec> ExecPayload<T> for FullPayload<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn blob_gas_used(&self) -> Result<u64, Error> {
|
||||
match self {
|
||||
FullPayload::Merge(_) | FullPayload::Capella(_) => Err(Error::IncorrectStateVariant),
|
||||
FullPayload::Deneb(ref inner) => Ok(inner.execution_payload.blob_gas_used),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_default_with_zero_roots<'a>(&'a self) -> bool {
|
||||
map_full_payload_ref!(&'a _, self.to_ref(), move |payload, cons| {
|
||||
cons(payload);
|
||||
@@ -372,6 +380,15 @@ impl<'b, T: EthSpec> ExecPayload<T> for FullPayloadRef<'b, T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn blob_gas_used(&self) -> Result<u64, Error> {
|
||||
match self {
|
||||
FullPayloadRef::Merge(_) | FullPayloadRef::Capella(_) => {
|
||||
Err(Error::IncorrectStateVariant)
|
||||
}
|
||||
FullPayloadRef::Deneb(inner) => Ok(inner.execution_payload.blob_gas_used),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_default_with_zero_roots<'a>(&'a self) -> bool {
|
||||
map_full_payload_ref!(&'a _, self, move |payload, cons| {
|
||||
cons(payload);
|
||||
@@ -533,6 +550,15 @@ impl<T: EthSpec> ExecPayload<T> for BlindedPayload<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn blob_gas_used(&self) -> Result<u64, Error> {
|
||||
match self {
|
||||
BlindedPayload::Merge(_) | BlindedPayload::Capella(_) => {
|
||||
Err(Error::IncorrectStateVariant)
|
||||
}
|
||||
BlindedPayload::Deneb(ref inner) => Ok(inner.execution_payload_header.blob_gas_used),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_default_with_zero_roots(&self) -> bool {
|
||||
self.to_ref().is_default_with_zero_roots()
|
||||
}
|
||||
@@ -621,6 +647,15 @@ impl<'b, T: EthSpec> ExecPayload<T> for BlindedPayloadRef<'b, T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn blob_gas_used(&self) -> Result<u64, Error> {
|
||||
match self {
|
||||
BlindedPayloadRef::Merge(_) | BlindedPayloadRef::Capella(_) => {
|
||||
Err(Error::IncorrectStateVariant)
|
||||
}
|
||||
BlindedPayloadRef::Deneb(inner) => Ok(inner.execution_payload_header.blob_gas_used),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_default_with_zero_roots<'a>(&'a self) -> bool {
|
||||
map_blinded_payload_ref!(&'b _, self, move |payload, cons| {
|
||||
cons(payload);
|
||||
@@ -646,7 +681,8 @@ macro_rules! impl_exec_payload_common {
|
||||
$block_type_variant:ident, // Blinded | Full
|
||||
$is_default_with_empty_roots:block,
|
||||
$f:block,
|
||||
$g:block) => {
|
||||
$g:block,
|
||||
$h:block) => {
|
||||
impl<T: EthSpec> ExecPayload<T> for $wrapper_type<T> {
|
||||
fn block_type() -> BlockType {
|
||||
BlockType::$block_type_variant
|
||||
@@ -704,6 +740,11 @@ macro_rules! impl_exec_payload_common {
|
||||
let g = $g;
|
||||
g(self)
|
||||
}
|
||||
|
||||
fn blob_gas_used(&self) -> Result<u64, Error> {
|
||||
let h = $h;
|
||||
h(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec> From<$wrapped_type<T>> for $wrapper_type<T> {
|
||||
@@ -741,6 +782,14 @@ macro_rules! impl_exec_payload_for_fork {
|
||||
wrapper_ref_type.withdrawals_root()
|
||||
};
|
||||
c
|
||||
},
|
||||
{
|
||||
let c: for<'a> fn(&'a $wrapper_type_header<T>) -> Result<u64, Error> =
|
||||
|payload: &$wrapper_type_header<T>| {
|
||||
let wrapper_ref_type = BlindedPayloadRef::$fork_variant(&payload);
|
||||
wrapper_ref_type.blob_gas_used()
|
||||
};
|
||||
c
|
||||
}
|
||||
);
|
||||
|
||||
@@ -820,6 +869,14 @@ macro_rules! impl_exec_payload_for_fork {
|
||||
wrapper_ref_type.withdrawals_root()
|
||||
};
|
||||
c
|
||||
},
|
||||
{
|
||||
let c: for<'a> fn(&'a $wrapper_type_full<T>) -> Result<u64, Error> =
|
||||
|payload: &$wrapper_type_full<T>| {
|
||||
let wrapper_ref_type = FullPayloadRef::$fork_variant(&payload);
|
||||
wrapper_ref_type.blob_gas_used()
|
||||
};
|
||||
c
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -104,6 +104,16 @@ impl<E: EthSpec, Payload: AbstractExecPayload<E>> SignedBeaconBlock<E, Payload>
|
||||
Self::from_ssz_bytes_with(bytes, |bytes| BeaconBlock::from_ssz_bytes(bytes, spec))
|
||||
}
|
||||
|
||||
/// SSZ decode with explicit fork variant.
|
||||
pub fn from_ssz_bytes_for_fork(
|
||||
bytes: &[u8],
|
||||
fork_name: ForkName,
|
||||
) -> Result<Self, ssz::DecodeError> {
|
||||
Self::from_ssz_bytes_with(bytes, |bytes| {
|
||||
BeaconBlock::from_ssz_bytes_for_fork(bytes, fork_name)
|
||||
})
|
||||
}
|
||||
|
||||
/// SSZ decode which attempts to decode all variants (slow).
|
||||
pub fn any_from_ssz_bytes(bytes: &[u8]) -> Result<Self, ssz::DecodeError> {
|
||||
Self::from_ssz_bytes_with(bytes, BeaconBlock::any_from_ssz_bytes)
|
||||
|
||||
Reference in New Issue
Block a user