Skip to content

Commit

Permalink
feat(payload-builder): error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOsiris committed Dec 13, 2024
1 parent 9ad0569 commit d76dc79
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions world-chain-builder/Cargo.lock

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

1 change: 1 addition & 0 deletions world-chain-builder/crates/world/payload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ alloy-rpc-types-debug.workspace = true
# misc
tracing.workspace = true
jsonrpsee.workspace = true
thiserror.workspace = true
35 changes: 30 additions & 5 deletions world-chain-builder/crates/world/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ use revm_primitives::{
};
use std::fmt::Display;
use std::sync::Arc;
use thiserror::Error;
use tracing::{debug, trace, warn};
use world_chain_builder_pool::noop::NoopWorldChainTransactionPool;
use world_chain_builder_pool::tx::WorldChainPooledTransaction;

use world_chain_builder_pool::tx::WorldChainPoolTransaction;
use world_chain_builder_rpc::eth::validate_conditional_options;
Expand All @@ -67,6 +67,23 @@ pub struct WorldChainPayloadBuilder<EvmConfig, Tx = ()> {
pub verified_blockspace_capacity: u8,
}

#[derive(Debug, Error)]
pub enum WorldChainPoolTransactionError {
#[error("Conditional Validation Failed: {0}")]
ConditionalValidationFailed(B256),
#[error("EVM Error: {0}")]
EVMError(#[from] InvalidTransaction),
}

impl PoolTransactionError for WorldChainPoolTransactionError {
fn is_bad_transaction(&self) -> bool {
match self {
WorldChainPoolTransactionError::ConditionalValidationFailed(_) => true,
WorldChainPoolTransactionError::EVMError(_) => true, // TODO: Should we return false here?
}
}
}

impl<EvmConfig> WorldChainPayloadBuilder<EvmConfig>
where
EvmConfig: ConfigureEvm<Header = Header>,
Expand Down Expand Up @@ -384,7 +401,8 @@ where
// 4. if mem pool transactions are requested we execute them
if !ctx.attributes().no_tx_pool {
//TODO: build pbh payload
let best_txs= pool.best_transactions_with_attributes(ctx.best_transaction_attributes());
let best_txs =
pool.best_transactions_with_attributes(ctx.best_transaction_attributes());

if ctx
.execute_best_transactions::<_, Pool>(&mut info, state, best_txs)?
Expand Down Expand Up @@ -756,7 +774,14 @@ where
let consensus_tx = tx.to_consensus();
if let Some(conditional_options) = pooled_tx.conditional_options() {
if let Err(_) = validate_conditional_options(&conditional_options, &client) {
best_txs.mark_invalid(consensus_tx.signer(), consensus_tx.nonce());
best_txs.mark_invalid(
&tx,
InvalidPoolTransactionError::Other(Box::new(
WorldChainPoolTransactionError::ConditionalValidationFailed(
tx.hash().clone(),
),
)),
);
invalid_txs.push(tx.hash().clone());
continue;
}
Expand All @@ -775,7 +800,7 @@ where
// we can't fit this transaction into the block, so we need to mark it as
// invalid which also removes all dependent transaction from
// the iterator before we can continue
best_txs.mark_invalid(&tx, InvalidPoolTransactionError::Underpriced); // TODO: Update this error
best_txs.mark_invalid(&tx, InvalidPoolTransactionError::Underpriced);
continue;
}

Expand Down Expand Up @@ -814,7 +839,7 @@ where
// descendants
trace!(target: "payload_builder", %err, ?tx, "skipping invalid transaction and its descendants");
best_txs
.mark_invalid(&tx, InvalidPoolTransactionError::Underpriced);
.mark_invalid(&tx, InvalidPoolTransactionError::Other(Box::new(err.into())));
}

continue;
Expand Down

0 comments on commit d76dc79

Please sign in to comment.