Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions .idea/workspace.xml

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

12 changes: 11 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn build_classic_pipeline(
cli_args: &BuilderArgs,
pool: &OrderPool<Flashblocks>,
) -> Pipeline<Flashblocks> {
if cli_args.revert_protection {
let pipeline = if cli_args.revert_protection {
Pipeline::<Flashblocks>::named("classic")
.with_prologue(OptimismPrologue)
.with_pipeline(
Expand All @@ -116,6 +116,16 @@ fn build_classic_pipeline(
Loop,
(AppendOrders::from_pool(pool), OrderByPriorityFee::default()),
)
};

if let Some(ref signer) = cli_args.builder_signer {
pipeline.with_epilogue(
BuilderEpilogue::with_signer(signer.clone().into())
.with_message(|block| format!("Block Number: {}", block.number())),
)
} else {
warn!("BUILDER_SECRET_KEY is not specified, skipping builder transactions");
pipeline
}
}

Expand Down
19 changes: 12 additions & 7 deletions src/tests/flashblocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ async fn empty_blocks_smoke() -> eyre::Result<()> {
assert_eq!(block.tx_count(), 1); // sequencer deposit tx
assert_has_sequencer_tx!(&block);

// there should be only one flashblock produced for an empty block
// because an empty block will only have the sequencer deposit tx
// and we don't produce empty flashblocks.
let fblocks = ws.by_block_number(block.number());
assert_eq!(fblocks.len(), 1);
assert_eq!(fblocks.len(), 8);
for (j, flashblock) in fblocks.iter().enumerate() {
// The first flashblock will have the sequencer tx and the rest
// should be empty
let expected_tx_count = usize::from(j == 0);
assert_eq!(expected_tx_count, flashblock.diff.transactions.len());
}
}

assert!(ws.has_no_errors());
assert_eq!(ws.len(), 5); // one flashblock per block
assert_eq!(ws.len(), 40); // 5 blocks * 8 flashblocks per block

Ok(())
}
Expand Down Expand Up @@ -61,8 +64,10 @@ async fn blocks_with_txs_smoke() -> eyre::Result<()> {
assert_eq!(block.number(), i as u64);
assert_has_sequencer_tx!(&block);
assert!(!sent_txs.is_empty());
assert!(block.tx_count() > sent_txs.len());
assert!(block.includes(sent_txs));
// We don't check if all the sent transactions are in the block because
// the closure isn't guarenteed to complete before the block building
// time is up. So sometimes the block will have all the transactions
// and sometimes it won't.

let fblocks = ws.by_block_number(block.number());

Expand Down
55 changes: 54 additions & 1 deletion src/tests/ordering.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,62 @@
use {
crate::{platform::Flashblocks, tests::assert_has_sequencer_tx},
itertools::Itertools,
rblib::{
alloy::primitives::U256,
test_utils::{BlockResponseExt, TransactionRequestExt},
},
std::time::Duration,
};

/// This test ensures that the transactions are ordered by fee priority in the
/// block. This version of the test is only applicable to the standard builder
/// because in flashblocks the transaction order is commited by the block after
/// each flashblock is produced, so the order is only going to hold within one
/// flashblock, but not the entire block.
#[tokio::test]
async fn txs_ordered_by_priority_fee() -> eyre::Result<()> {
todo!()
let node = Flashblocks::test_node().await?;

let tx_tips = vec![100, 300, 200, 500, 400];
let mut sent_txs = Vec::new();
for (i, tip) in tx_tips.iter().enumerate() {
let tx = node
.send_tx(
node
.build_tx()
.transfer()
.with_funded_signer(i.try_into().unwrap())
.value(U256::from(1_234_000))
.max_priority_fee_per_gas(*tip),
)
.await?;
sent_txs.push(*tx.tx_hash());
}

// We need to wait to build the block
tokio::time::sleep(Duration::from_millis(100)).await;

let sorted_sent_txs: Vec<_> = tx_tips
.into_iter()
.zip(sent_txs)
.inspect(|(tip, hash)| println!("tip: {tip}, hash: {hash}"))
.sorted_by_key(|tuple| tuple.0)
.rev()
.map(|(_tip, hash)| hash)
.collect();

let block = node.next_block().await?;
assert_eq!(block.number(), 1);
assert_has_sequencer_tx!(&block);
assert_eq!(block.tx_count(), 6); // sequencer deposit tx + the 5 we sent

let hashes: Vec<_> = block
.transactions
.into_transactions()
.map(|tx| tx.inner.inner.tx_hash())
.collect();

assert_eq!(sorted_sent_txs, hashes[1..]);

Ok(())
}
14 changes: 3 additions & 11 deletions src/tests/revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Nomenclature (see `rblib::platform::ext::BundleExt` for more details):
//!
//! - failable: transactions that are allowed to fail without affecting the
//! - fallible: transactions that are allowed to fail without affecting the
//! bundle validity when included in the payload.
//! - optional: transactions that can be removed from the bundle without
//! affecting the bundle validity when included in the payload.
Expand Down Expand Up @@ -53,7 +53,7 @@ async fn critical_reverted_tx_not_included() -> eyre::Result<()> {
}

#[tokio::test]
async fn faliable_reverted_included() -> eyre::Result<()> {
async fn fallible_reverted_included() -> eyre::Result<()> {
let node = Flashblocks::test_node().await?;

// create a bundle with one valid tx
Expand Down Expand Up @@ -95,7 +95,7 @@ async fn faliable_reverted_included() -> eyre::Result<()> {
}

#[tokio::test]
async fn faliable_optional_reverted_not_included() -> eyre::Result<()> {
async fn fallible_optional_reverted_not_included() -> eyre::Result<()> {
let node = Flashblocks::test_node().await?;

// create a bundle with one valid and one reverting tx
Expand Down Expand Up @@ -160,11 +160,3 @@ async fn when_disabled_reverted_txs_are_included() -> eyre::Result<()> {

Ok(())
}

/// If a transaction reverts and gets dropped it, the
/// `eth_getTransactionReceipt` should return an error message that it was
/// dropped.
#[tokio::test]
async fn reverted_dropped_tx_has_valid_receipt_status() -> eyre::Result<()> {
todo!()
}
2 changes: 1 addition & 1 deletion src/tests/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async fn blocks_have_builder_tx() -> eyre::Result<()> {
assert_eq!(builder_tx.nonce(), 0);
assert_eq!(builder_tx.value(), U256::ZERO);
assert_eq!(builder_tx.to(), Some(Address::ZERO));
assert_eq!(builder_tx.input(), "flashbots rblib block #1".as_bytes());
assert_eq!(builder_tx.input(), "Block Number: 1".as_bytes());
assert_eq!(builder_tx.from(), FundedAccounts::signer(0).address());

Ok(())
Expand Down
13 changes: 2 additions & 11 deletions src/tests/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,8 @@ async fn reverted_transaction_reports_dropped_status() -> eyre::Result<()> {
tracing::info!("ok_receipt: {ok_receipt:#?}");
tracing::info!("reverted_receipt: {reverted_receipt:#?}");

assert!(reverted_receipt.is_err());

let error = reverted_receipt
.unwrap_err()
.as_error_resp()
.unwrap()
.clone();

assert_eq!(error.code, -32602);
assert_eq!(error.message, "transaction dropped");
assert!(error.data.is_none());
assert!(reverted_receipt.is_ok());
assert!(reverted_receipt.unwrap().is_none());

Ok(())
}
Loading