Skip to content

Commit

Permalink
test: cleanup & clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOsiris committed Oct 22, 2024
1 parent b1e71eb commit 91e855f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 32 deletions.
26 changes: 6 additions & 20 deletions world-chain-builder/src/payload/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use reth_db::transaction::DbTx;
use reth_evm::ConfigureEvm;
use std::sync::Arc;

Expand All @@ -18,7 +17,7 @@ use reth_basic_payload_builder::{
PayloadBuilder, PayloadConfig, WithdrawalsOutcome,
};
use reth_chain_state::ExecutedBlock;
use reth_db::{Database, DatabaseEnv, DatabaseError, DatabaseWriteOperation};
use reth_db::DatabaseEnv;
use reth_evm::system_calls::SystemCaller;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism;
Expand All @@ -43,7 +42,6 @@ use revm_primitives::{
};
use tracing::{debug, trace, warn};

use crate::pbh::db::set_pbh_nullifier;
use crate::pool::noop::NoopWorldChainTransactionPool;
use crate::pool::tx::WorldChainPoolTransaction;

Expand All @@ -53,25 +51,19 @@ pub struct WorldChainPayloadBuilder<EvmConfig> {
inner: OptimismPayloadBuilder<EvmConfig>,
/// The percentage of the blockspace that should be reserved for verified transactions
verified_blockspace_capacity: u8,
pbh_db: Arc<DatabaseEnv>,
}

impl<EvmConfig> WorldChainPayloadBuilder<EvmConfig>
where
EvmConfig: ConfigureEvm<Header = Header>,
{
/// `OptimismPayloadBuilder` constructor.
pub const fn new(
evm_config: EvmConfig,
verified_blockspace_capacity: u8,
pbh_db: Arc<DatabaseEnv>,
) -> Self {
pub const fn new(evm_config: EvmConfig, verified_blockspace_capacity: u8) -> Self {
let inner = OptimismPayloadBuilder::new(evm_config);

Self {
inner,
verified_blockspace_capacity,
pbh_db,
}
}
}
Expand All @@ -96,7 +88,6 @@ where

worldchain_payload(
self.inner.evm_config.clone(),
self.pbh_db.clone(),
args,
cfg_env,
block_env,
Expand Down Expand Up @@ -132,7 +123,6 @@ where

worldchain_payload(
self.inner.evm_config.clone(),
self.pbh_db.clone(),
args,
cfg_env,
block_env,
Expand Down Expand Up @@ -179,11 +169,8 @@ where
) -> eyre::Result<PayloadBuilderHandle<OptimismEngineTypes>> {
let evm_config = OptimismEvmConfig::new(Arc::new((*ctx.chain_spec()).clone()));

let payload_builder = WorldChainPayloadBuilder::new(
evm_config,
self.verified_blockspace_capacity,
self.pbh_db,
);
let payload_builder =
WorldChainPayloadBuilder::new(evm_config, self.verified_blockspace_capacity);

let conf = ctx.payload_builder_config();

Expand Down Expand Up @@ -222,7 +209,6 @@ where
#[inline]
pub(crate) fn worldchain_payload<EvmConfig, Pool, Client>(
evm_config: EvmConfig,
pbh_db: Arc<DatabaseEnv>,
args: BuildArguments<Pool, Client, OptimismPayloadBuilderAttributes, OptimismBuiltPayload>,
initialized_cfg: CfgEnvWithHandlerCfg,
initialized_block_env: BlockEnv,
Expand Down Expand Up @@ -741,7 +727,7 @@ mod tests {
// Init the payload builder
let verified_blockspace_cap = 50;
let world_chain_payload_builder =
WorldChainPayloadBuilder::new(evm_config, verified_blockspace_cap, db.clone());
WorldChainPayloadBuilder::new(evm_config, verified_blockspace_cap);

// Insert transactions into the pool
let unverified_transactions = generate_mock_pooled_transactions(50, 100000, false);
Expand Down Expand Up @@ -857,7 +843,7 @@ mod tests {
// Init the payload builder
let verified_blockspace_cap = 10;
let world_chain_payload_builder =
WorldChainPayloadBuilder::new(evm_config, verified_blockspace_cap, db.clone());
WorldChainPayloadBuilder::new(evm_config, verified_blockspace_cap);

// Insert transactions into the pool
let unverified_transactions = generate_mock_pooled_transactions(50, 100000, false);
Expand Down
1 change: 0 additions & 1 deletion world-chain-builder/src/pbh/db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use alloy_primitives::TxHash;
use bytes::BufMut;
use reth_db::cursor::DbCursorRW;
use reth_db::mdbx::tx::Tx;
Expand Down
2 changes: 1 addition & 1 deletion world-chain-builder/src/pool/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub mod tests {
use crate::pbh::payload::{PbhPayload, Proof};
use crate::pool::ordering::WorldChainOrdering;
use crate::pool::root::{LATEST_ROOT_SLOT, OP_WORLD_ID};
use crate::test::{get_non_pbh_transaction, get_pbh_transaction, world_chain_validator};
use crate::test::{get_pbh_transaction, world_chain_validator};

#[tokio::test]
async fn validate_pbh_transaction() {
Expand Down
17 changes: 7 additions & 10 deletions world-chain-builder/src/test/e2e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,25 +322,22 @@ async fn test_dup_pbh_nonce() -> eyre::Result<()> {

let raw_tx_0 = ctx.raw_pbh_tx_bytes(signer.clone(), 0, 0).await;
ctx.node.rpc.inject_tx(raw_tx_0.clone()).await?;

let raw_tx_1 = ctx.raw_pbh_tx_bytes(signer.clone(), 0, 1).await;
ctx.node.rpc.inject_tx(raw_tx_1.clone()).await?;

// Now that the nullifier has successfully been stored in
// the `ExecutedPbhNullifierTable`, inserting a new tx with the
// same pbh_nonce should fail to validate.
assert!(ctx.node.rpc.inject_tx(raw_tx_1.clone()).await.is_err());

let (payload, _) = ctx
.node
.advance_block(vec![], optimism_payload_attributes)
.await?;

// Both transactions should be successfully validated
// but only one should be included in the block
// One transaction should be successfully validated
// and included in the block.
assert_eq!(payload.block().body.transactions.len(), 1);

// Now that the nullifier has successfully been stored in
// the `ExecutedPbhNullifierTable`, inserting a new tx with the
// same pbh_nonce should fail to validate.
let raw_tx_2 = ctx.raw_pbh_tx_bytes(signer.clone(), 0, 2).await;
assert!(ctx.node.rpc.inject_tx(raw_tx_2.clone()).await.is_err());

Ok(())
}

Expand Down

0 comments on commit 91e855f

Please sign in to comment.