Skip to content

Commit

Permalink
pr suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOsiris committed Dec 10, 2024
1 parent c49fc8d commit 85aed12
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 42 deletions.
71 changes: 38 additions & 33 deletions world-chain-builder/crates/assertor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ use alloy_rpc_types_eth::{erc4337::ConditionalOptions, BlockNumberOrTag};
use alloy_transport::Transport;
use clap::Parser;
use eyre::eyre::{eyre, Result};
use futures::{stream, StreamExt, TryStreamExt};
use serde::Deserialize;
use tokio::time::sleep;
use tracing::{debug, info};

const PBH_FIXTURE: &str = include_str!("../../../../devnet/fixtures/fixture.json");

const CONCURRENCY_LIMIT: usize = 50;
#[derive(Deserialize, Clone)]
pub struct PbhFixture {
pub fixture: Vec<Bytes>,
Expand Down Expand Up @@ -127,38 +128,42 @@ where
P: Provider<T>,
{
let fixture = serde_json::from_str::<PbhFixture>(PBH_FIXTURE)?;
let mut queue = vec![];

// Send half with `eth_sendRawTransaction` and the other half with `eth_sendRawTransactionConditional`
for transaction in fixture.fixture.iter().take(fixture.fixture.len() / 2) {
let tx = builder_provider.send_raw_transaction(transaction).await?;
queue.push(tx);
}

for transaction in fixture.fixture.iter().skip(fixture.fixture.len() / 2) {
let rlp_hex = hex::encode_prefixed(transaction);
let tx_hash = builder_provider
.client()
.request(
"eth_sendRawTransactionConditional",
(rlp_hex, ConditionalOptions::default(),),
)
.await?;
queue.push(PendingTransactionBuilder::new(
builder_provider.root(),
tx_hash,
));
}

let futs = queue.into_iter().map(|builder| async {
let hash = builder.tx_hash().clone();
let receipt = builder.get_receipt().await;
assert!(receipt.is_ok());
debug!(receipt = ?receipt.unwrap(), hash = ?hash, "Transaction Receipt Received");
});

futures::future::join_all(futs).await;

let num_transactions = fixture.fixture.len();
let half = num_transactions / 2;
let builder_provider_clone = builder_provider.clone();
stream::iter(fixture.fixture.iter().enumerate())
.map(Ok)
.try_for_each_concurrent(CONCURRENCY_LIMIT, move |(index, transaction)| {
let builder_provider = builder_provider_clone.clone();
async move {
let tx = if index < half {
// First half, use eth_sendRawTransaction
builder_provider.send_raw_transaction(transaction).await?
} else {
// Second half, use eth_sendRawTransactionConditional
let rlp_hex = hex::encode_prefixed(transaction);
let tx_hash = builder_provider
.client()
.request(
"eth_sendRawTransactionConditional",
(rlp_hex, ConditionalOptions::default()),
)
.await?;
PendingTransactionBuilder::new(builder_provider.root(), tx_hash)
};
let hash = *tx.tx_hash();
let receipt = tx.get_receipt().await;
assert!(receipt.is_ok());
debug!(
receipt = ?receipt.unwrap(),
hash = ?hash,
index = index,
"Transaction Receipt Received"
);
Ok::<(), eyre::Report>(())
}
})
.await?;
Ok(())
}

Expand Down
9 changes: 3 additions & 6 deletions world-chain-builder/src/rpc/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,9 @@ where
known_accounts: HashMap<Address, AccountStorage, FbBuildHasher<20>>,
latest: BlockId,
) -> RpcResult<()> {
let state = self
.provider()
.state_by_block_id(latest)
.map_err(|e| {
ErrorObject::owned(ErrorCode::InternalError.code(), e.to_string(), Some(""))
})?;
let state = self.provider().state_by_block_id(latest).map_err(|e| {
ErrorObject::owned(ErrorCode::InternalError.code(), e.to_string(), Some(""))
})?;

for (address, storage) in known_accounts.into_iter() {
match storage {
Expand Down
6 changes: 3 additions & 3 deletions world-chain-builder/src/test/e2e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use crate::{
primitives::WorldChainPooledTransactionsElement,
rpc::bundle::{EthTransactionsExtServer, WorldChainEthApiExt},
};
use alloy_primitives::bytes;
use alloy_eips::eip2718::Decodable2718;
use alloy_genesis::{Genesis, GenesisAccount};
use alloy_network::eip2718::Encodable2718;
use alloy_network::{Ethereum, EthereumWallet, TransactionBuilder};
use alloy_primitives::bytes;
use alloy_rpc_types::{TransactionInput, TransactionRequest};
use alloy_signer_local::PrivateKeySigner;
use chrono::Utc;
Expand Down Expand Up @@ -269,8 +269,8 @@ async fn test_can_build_pbh_payload() -> eyre::Result<()> {

#[tokio::test]
async fn test_decode_transaction() -> eyre::Result<()> {
let tx = bytes!("02f8698320d5e4800184516d19dd82520894deadbeefdeadbeefdeadbeefdeadbeefdeadbeef8080c080a081ad5010d3f502b279540af054216ceb8fc929e919022088e766cf2ceced894ea053a971501c8e2b426cf5c043f390b9e454d92794562a60029605d397f02bb27ff901518b76312d3132323032342d30a00192a1143ac457fab0cf5a07a852c15db32a1825d9048a2eb406e8aaffadb742a00ac9d5995841e9d09387685c7155e6f08b2a92d984a8a2f282c48d6cc08db3ceb901002b0592638030cd0a68b32ea2a7461d3dc1cfa78280091ec9688d97698011a47b283d6fac359cd0140f11d105b6a01978bd06b47d5eb6f15991ea2916008534e81e5f13adcf1dab880a7b5d9ee6dca817effff98f27e9699bf6071bf1643fb91a27f772e9311c6dfbd4446e83c18c2ebb4eee2df64e4f5a584a70d96ea0637e2f2fc48dfa438fba778bcdbb3b125e4d56b82c4475ee899924c044b5f24ba795de12ee755d5c96bf31dde93857f790db06fda0d0c2262d75fab74ea840c12381cc1857ee75d5ee27fef42ad0f46e54ac8e7dd05d9bb99af3aafc5c13cbab370a61069e42d444daada4fb0a907ee9b9abf22ffb2d21ca4b064de8647cd94586b2fd");
let pooled_tx = WorldChainPooledTransactionsElement::decode_2718(&mut &tx[..])?;
let tx = bytes!("02f8698320d5e4800184516d19dd82520894deadbeefdeadbeefdeadbeefdeadbeefdeadbeef8080c080a081ad5010d3f502b279540af054216ceb8fc929e919022088e766cf2ceced894ea053a971501c8e2b426cf5c043f390b9e454d92794562a60029605d397f02bb27ff901518b76312d3132323032342d30a00192a1143ac457fab0cf5a07a852c15db32a1825d9048a2eb406e8aaffadb742a00ac9d5995841e9d09387685c7155e6f08b2a92d984a8a2f282c48d6cc08db3ceb901002b0592638030cd0a68b32ea2a7461d3dc1cfa78280091ec9688d97698011a47b283d6fac359cd0140f11d105b6a01978bd06b47d5eb6f15991ea2916008534e81e5f13adcf1dab880a7b5d9ee6dca817effff98f27e9699bf6071bf1643fb91a27f772e9311c6dfbd4446e83c18c2ebb4eee2df64e4f5a584a70d96ea0637e2f2fc48dfa438fba778bcdbb3b125e4d56b82c4475ee899924c044b5f24ba795de12ee755d5c96bf31dde93857f790db06fda0d0c2262d75fab74ea840c12381cc1857ee75d5ee27fef42ad0f46e54ac8e7dd05d9bb99af3aafc5c13cbab370a61069e42d444daada4fb0a907ee9b9abf22ffb2d21ca4b064de8647cd94586b2fd");
let pooled_tx = WorldChainPooledTransactionsElement::decode_2718(&mut &tx[..])?;
let root = pooled_tx.pbh_payload.unwrap().root;
println!("{:?}", root);
Ok(())
Expand Down

0 comments on commit 85aed12

Please sign in to comment.