Skip to content

Commit

Permalink
refactor(core): use fork instead of inclusion block
Browse files Browse the repository at this point in the history
  • Loading branch information
petarvujovic98 committed Aug 22, 2024
1 parent 7e48b94 commit 70156fc
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions core/src/preflight/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use raiko_lib::{
};
use reth_evm_ethereum::taiko::decode_anchor;
use reth_primitives::Block;
use reth_revm::primitives::SpecId;
use serde::{Deserialize, Serialize};
use tracing::{debug, error, info, warn};

Expand Down Expand Up @@ -81,7 +82,7 @@ pub async fn prepare_taiko_chain_input(
let anchor_call = decode_anchor(anchor_tx.input())?;
// The L1 blocks we need
let l1_state_block_number = anchor_call.l1BlockId;
let is_preconfirm = l1_inclusion_block_number.is_some();
let fork = taiko_chain_spec.active_fork(block.number, block.timestamp)?;
let l1_inclusion_block_number = l1_inclusion_block_number.unwrap_or(l1_state_block_number + 1);

debug!(
Expand Down Expand Up @@ -115,7 +116,7 @@ pub async fn prepare_taiko_chain_input(
taiko_chain_spec.clone(),
l1_inclusion_block_hash,
block_number,
is_preconfirm,
fork,
)
.await?;

Expand All @@ -127,21 +128,28 @@ pub async fn prepare_taiko_chain_input(
l1_chain_spec,
)
.await?
} else if is_preconfirm {
// Get the tx list data directly from the propose block CalldataTxList event
let calldata_txlist = get_calldata_txlist_event(
provider_l1.provider(),
taiko_chain_spec.clone(),
l1_inclusion_block_hash,
block_number,
)
.await?;
(calldata_txlist.1.txList.as_ref().to_owned(), None)
} else {
// Get the tx list data directly from the propose transaction data
let proposal_call = proposeBlockCall::abi_decode(&proposal_tx.input, false)
.map_err(|_| RaikoError::Preflight("Could not decode proposeBlockCall".to_owned()))?;
(proposal_call.txList.as_ref().to_owned(), None)
match fork {
SpecId::ONTAKE => {
// Get the tx list data directly from the propose block CalldataTxList event
let calldata_txlist = get_calldata_txlist_event(
provider_l1.provider(),
taiko_chain_spec.clone(),
l1_inclusion_block_hash,
block_number,
)
.await?;
(calldata_txlist.1.txList.as_ref().to_owned(), None)
}
_ => {
// Get the tx list data directly from the propose transaction data
let proposal_call = proposeBlockCall::abi_decode(&proposal_tx.input, false)
.map_err(|_| {
RaikoError::Preflight("Could not decode proposeBlockCall".to_owned())
})?;
(proposal_call.txList.as_ref().to_owned(), None)
}
}
};

// Create the input struct without the block data set
Expand Down Expand Up @@ -235,18 +243,17 @@ pub async fn get_block_proposed_event(
chain_spec: ChainSpec,
block_hash: B256,
l2_block_number: u64,
is_preconfirm: bool,
fork: SpecId,
) -> Result<(AlloyRpcTransaction, BlockProposedFork)> {
// Get the address that emitted the event
let Some(l1_address) = chain_spec.l1_contract else {
bail!("No L1 contract address in the chain spec");
};

// Get the event signature (value can differ between chains)
let event_signature = if is_preconfirm {
BlockProposedV2::SIGNATURE_HASH
} else {
BlockProposed::SIGNATURE_HASH
let event_signature = match fork {
SpecId::ONTAKE => BlockProposedV2::SIGNATURE_HASH,
_ => BlockProposed::SIGNATURE_HASH,
};
// Setup the filter to get the relevant events
let filter = Filter::new()
Expand All @@ -266,14 +273,17 @@ pub async fn get_block_proposed_event(
) else {
bail!("Could not create log")
};
let (block_id, data) = if is_preconfirm {
let event = BlockProposedV2::decode_log(&log_struct, false)
.map_err(|_| RaikoError::Anyhow(anyhow!("Could not decode log")))?;
(event.blockId, BlockProposedFork::Ontake(event.data))
} else {
let event = BlockProposed::decode_log(&log_struct, false)
.map_err(|_| RaikoError::Anyhow(anyhow!("Could not decode log")))?;
(event.blockId, BlockProposedFork::Hekla(event.data))
let (block_id, data) = match fork {
SpecId::ONTAKE => {
let event = BlockProposedV2::decode_log(&log_struct, false)
.map_err(|_| RaikoError::Anyhow(anyhow!("Could not decode log")))?;
(event.blockId, BlockProposedFork::Ontake(event.data))
}
_ => {
let event = BlockProposed::decode_log(&log_struct, false)
.map_err(|_| RaikoError::Anyhow(anyhow!("Could not decode log")))?;
(event.blockId, BlockProposedFork::Hekla(event.data))
}
};

if block_id == raiko_lib::primitives::U256::from(l2_block_number) {
Expand Down

0 comments on commit 70156fc

Please sign in to comment.