Skip to content

Commit 5fc9ee5

Browse files
committed
fix all the tests
1 parent f7adf02 commit 5fc9ee5

File tree

6 files changed

+58
-31
lines changed

6 files changed

+58
-31
lines changed

src/limits.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use {
1212
core::time::Duration,
1313
rblib::{alloy::consensus::BlockHeader, prelude::*},
1414
std::sync::{Arc, Mutex},
15+
tracing::debug,
1516
};
1617

1718
/// Specifies the limits for individual flashblocks.
@@ -54,8 +55,12 @@ impl FlashblockState {
5455
}
5556

5657
impl FlashblockLimits {
57-
pub fn new(interval: Duration) -> Self {
58+
pub fn new(
59+
interval: Duration,
60+
target_flashblocks: Arc<TargetFlashblocks>,
61+
) -> Self {
5862
let state = FlashblockState {
63+
target_flashblocks,
5964
..Default::default()
6065
};
6166
FlashblockLimits {
@@ -87,16 +92,22 @@ impl FlashblockLimits {
8792
let elapsed = payload.building_since().elapsed();
8893
let remaining_time = payload_deadline.saturating_sub(elapsed);
8994

90-
let (target_flashblock, first_flashblock_interval) =
95+
let (target_flashblocks, first_flashblock_interval) =
9196
self.calculate_flashblocks(payload, remaining_time);
9297

9398
state.gas_per_flashblock = enclosing
9499
.gas_limit
95-
.checked_div(target_flashblock)
100+
.checked_div(target_flashblocks)
96101
.unwrap_or(enclosing.gas_limit);
97102
state.current_block = Some(payload.block().number());
98103
state.first_flashblock_interval = first_flashblock_interval;
99-
state.target_flashblocks.set(target_flashblock);
104+
state.target_flashblocks.set(target_flashblocks);
105+
106+
debug!(
107+
target_flashblocks = target_flashblocks,
108+
first_flashblock_interval = ?first_flashblock_interval,
109+
"Set flashblock timing for this block"
110+
);
100111
}
101112
}
102113

src/main.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use {
2020
steps::*,
2121
},
2222
std::sync::Arc,
23+
tracing::info,
2324
};
2425

2526
mod args;
@@ -106,6 +107,11 @@ fn build_pipeline(
106107

107108
let target_flashblocks = Arc::new(TargetFlashblocks::new());
108109

110+
info!(
111+
"cli_args.builder_signer.is_some() = {}",
112+
cli_args.builder_signer.is_some()
113+
);
114+
109115
let pipeline = Pipeline::<Flashblocks>::named("top")
110116
.with_step(OptimismPrologue)
111117
.with_step_if(
@@ -123,27 +129,34 @@ fn build_pipeline(
123129
Once,
124130
Pipeline::named("single_flashblock")
125131
.with_pipeline(
126-
Loop,
132+
Once,
127133
Pipeline::named("flashblock_steps")
128-
.with_step(AppendOrders::from_pool(pool).with_ok_on_limit())
129-
.with_step(OrderByPriorityFee::default())
130-
.with_step_if(
131-
cli_args.revert_protection,
132-
RemoveRevertedTransactions::default(),
134+
.with_pipeline(
135+
Loop,
136+
Pipeline::named("inner_flashblock_steps")
137+
.with_step(AppendOrders::from_pool(pool).with_ok_on_limit())
138+
.with_step(OrderByPriorityFee::default())
139+
.with_step_if(
140+
cli_args.revert_protection,
141+
RemoveRevertedTransactions::default(),
142+
)
143+
.with_step(BreakAfterDeadline),
133144
)
134-
.with_step(BreakAfterDeadline)
135-
.with_epilogue_if(
145+
.with_step_if(
136146
cli_args.builder_signer.is_some(),
137147
BuilderEpilogue::with_signer(builder_signer.clone().into())
138148
.with_message(|block| {
139149
format!("Block Number: {}", block.number())
140150
}),
141151
)
142-
.with_epilogue(PublishFlashblock::new(
152+
.with_step(PublishFlashblock::new(
143153
ws.clone(),
144154
cli_args.flashblocks_args.calculate_state_root,
145155
))
146-
.with_limits(FlashblockLimits::new(interval)),
156+
.with_limits(FlashblockLimits::new(
157+
interval,
158+
target_flashblocks.clone(),
159+
)),
147160
)
148161
.with_step(BreakAfterDeadline),
149162
)

src/publish.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl Step<Flashblocks> for PublishFlashblock {
8989
.transactions()
9090
.map(|tx| tx.encoded_2718().into())
9191
.collect();
92+
let num_txs = transactions.len();
9293

9394
let sealed_block = payload.build_payload();
9495
if let Err(e) = sealed_block {
@@ -136,10 +137,11 @@ impl Step<Flashblocks> for PublishFlashblock {
136137
}
137138

138139
info!(
139-
"Published flashblock {}, num_transactions: {}, gas_used: {}",
140-
index,
141-
payload.history().transactions().count(),
142-
payload.gas_used()
140+
index = index,
141+
num_transactions = num_txs,
142+
cumulative_gas_used = payload.gas_used(),
143+
payload_id = ?ctx.block().payload_id(),
144+
"Published flashblock",
143145
);
144146

145147
// block published to WS successfully
@@ -214,21 +216,14 @@ impl Step<Flashblocks> for PublishFlashblock {
214216
}
215217

216218
impl PublishFlashblock {
217-
/// Returns a span that covers all payload checkpoints since the last barrier.
218-
/// Those are the transactions that are going to be published in this
219+
/// Returns a span that covers all payload checkpoints for the current
219220
/// flashblock.
220-
///
221-
/// One exception is the first flashblock, we want to get all checkpoints
222-
/// since the begining of the block, because the `OptimismPrologue` step
223-
/// places a barrier after sequencer transactions and we want to broadcast
224-
/// those transactions as well.
225221
fn unpublished_payload(
226222
payload: &Checkpoint<Flashblocks>,
227223
) -> Span<Flashblocks> {
228-
// If we haven't published flashblock return whole history
229-
let previous_flashblock_number = payload.context().clone();
224+
let current_flashblock_number = payload.context();
230225
payload
231-
.history_since_last_context(&previous_flashblock_number)
226+
.history_since_first_context(current_flashblock_number)
232227
.unwrap_or(payload.history())
233228
}
234229

src/tests/flashblocks.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ async fn empty_blocks_smoke() -> eyre::Result<()> {
2626
// The first flashblock will have the sequencer tx and the rest
2727
// should be empty
2828
let expected_tx_count = usize::from(j == 0);
29-
assert_eq!(expected_tx_count, flashblock.diff.transactions.len());
29+
assert_eq!(
30+
expected_tx_count,
31+
flashblock.diff.transactions.len(),
32+
"expected {expected_tx_count} transactions in flashblock {j}",
33+
);
3034
}
3135
}
3236

src/tests/standard.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ async fn blocks_have_builder_tx() -> eyre::Result<()> {
6969
Box::pin(Flashblocks::test_node_with_builder_signer()).await?;
7070

7171
let block = node.next_block().await?;
72-
debug!("produced block: {block:#?}");
7372

7473
assert_eq!(block.number(), 1);
7574
assert_eq!(block.tx_count(), 9); // sequencer deposit tx + 8 builder txs for each flashblock

src/tests/utils/ws.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ impl Observations {
164164
}
165165

166166
fn record_flashblock(&self, payload: FlashblocksPayloadV1) {
167-
debug!("observed flashblock: {payload:#?}");
167+
debug!(
168+
index = payload.index,
169+
payload_id = ?payload.payload_id,
170+
num_transactions = payload.diff.transactions.len(),
171+
"Observed flashblock"
172+
);
168173
self.flashblocks.push(ObservedFlashblock {
169174
block: payload,
170175
at: Instant::now(),

0 commit comments

Comments
 (0)