Skip to content

Commit

Permalink
Renamed deposits, added taiko_block, updated imports, added debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
johntaiko committed Jan 3, 2025
1 parent 34bc46b commit 987e66e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 9 deletions.
8 changes: 6 additions & 2 deletions crates/taiko/engine/types/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ pub struct TaikoExecutionPayloadInputV2 {
/// Excess blob gas
#[serde(with = "alloy_serde::quantity::opt")]
pub excess_blob_gas: Option<u64>,
/// Deposits
pub deposits: Option<Vec<TxDeposit>>,
/// Deposit requests
pub deposit_requests: Option<Vec<TxDeposit>>,

/// Is taiko block
#[serde(rename = "TaikoBlock")]
pub taiko_block: bool,
}

/// TxDeposit
Expand Down
77 changes: 70 additions & 7 deletions crates/taiko/node/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ use std::sync::Arc;
use alloy_consensus::{BlockHeader, Header};
use alloy_rpc_types_engine::{ExecutionPayloadSidecar, PayloadError};
use reth_node_builder::{
EngineApiMessageVersion, EngineObjectValidationError, EngineTypes, EngineValidator,
InvalidPayloadAttributesError, PayloadAttributes, PayloadOrAttributes, PayloadTypes,
PayloadValidator,
validate_parent_beacon_block_root_presence, EngineApiMessageVersion,
EngineObjectValidationError, EngineTypes, EngineValidator, InvalidPayloadAttributesError,
MessageValidationKind, PayloadAttributes, PayloadOrAttributes, PayloadTypes, PayloadValidator,
VersionSpecificValidationError,
};
use reth_payload_builder::EthBuiltPayload;
use reth_payload_primitives::validate_version_specific_fields;
use reth_primitives::{Block, SealedBlock};
use reth_primitives::{Block, EthereumHardforks, SealedBlock};
use reth_taiko_chainspec::TaikoChainSpec;
use reth_taiko_engine_primitives::{
ExecutionPayloadEnvelopeV3, ExecutionPayloadEnvelopeV4, ExecutionPayloadV1,
TaikoExecutionPayloadEnvelopeV2, TaikoPayloadBuilderAttributes,
};
use reth_taiko_engine_types::{TaikoExecutionPayload, TaikoPayloadAttributes};
use reth_taiko_payload_validator::TaikoExecutionPayloadValidator;
use reth_tracing::tracing::debug;

/// The types used in the default mainnet ethereum beacon consensus engine.
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -97,15 +98,25 @@ where
version: EngineApiMessageVersion,
payload_or_attrs: PayloadOrAttributes<'_, TaikoPayloadAttributes>,
) -> Result<(), EngineObjectValidationError> {
validate_version_specific_fields(self.chain_spec(), version, payload_or_attrs)
debug!(target: "taiko::engine", version=?version, payload_or_attrs=?payload_or_attrs);
let res = validate_version_specific_fields(self.chain_spec(), version, payload_or_attrs);
debug!(target: "taiko::engine", version=?version, ?res);
res
}

fn ensure_well_formed_attributes(
&self,
version: EngineApiMessageVersion,
attributes: &TaikoPayloadAttributes,
) -> Result<(), EngineObjectValidationError> {
validate_version_specific_fields(self.chain_spec(), version, attributes.into())
debug!(target: "taiko::engine", version=?version, attributes=?attributes);
let res = reth_payload_primitives::validate_version_specific_fields(
self.chain_spec(),
version,
attributes.into(),
);
debug!(target: "taiko::engine", version=?version, ?res);
res
}

fn validate_payload_attributes_against_header(
Expand All @@ -119,3 +130,55 @@ where
Ok(())
}
}

fn validate_withdrawals_presence<T: EthereumHardforks>(
chain_spec: &T,
version: EngineApiMessageVersion,
message_validation_kind: MessageValidationKind,
timestamp: u64,
has_withdrawals: bool,
) -> Result<(), EngineObjectValidationError> {
let is_shanghai_active = chain_spec.is_shanghai_active_at_timestamp(timestamp);

match version {
EngineApiMessageVersion::V1 => {
if has_withdrawals {
return Err(message_validation_kind
.to_error(VersionSpecificValidationError::WithdrawalsNotSupportedInV1))
}
}
EngineApiMessageVersion::V2 | EngineApiMessageVersion::V3 | EngineApiMessageVersion::V4 => {
if !is_shanghai_active && has_withdrawals {
return Err(message_validation_kind
.to_error(VersionSpecificValidationError::HasWithdrawalsPreShanghai))
}
}
};

Ok(())
}

fn validate_version_specific_fields<Type, T>(
chain_spec: &T,
version: EngineApiMessageVersion,
payload_or_attrs: PayloadOrAttributes<'_, Type>,
) -> Result<(), EngineObjectValidationError>
where
Type: PayloadAttributes,
T: EthereumHardforks,
{
validate_withdrawals_presence(
chain_spec,
version,
payload_or_attrs.message_validation_kind(),
payload_or_attrs.timestamp(),
payload_or_attrs.withdrawals().is_some(),
)?;
validate_parent_beacon_block_root_presence(
chain_spec,
version,
payload_or_attrs.message_validation_kind(),
payload_or_attrs.timestamp(),
payload_or_attrs.parent_beacon_block_root().is_some(),
)
}

0 comments on commit 987e66e

Please sign in to comment.