Skip to content

Commit 39875b5

Browse files
authored
chore: clean up pipeline with conditional steps (#42)
1 parent a871ada commit 39875b5

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jemalloc = ["rblib/jemalloc"]
3434
debug = ["tokio/full", "tokio/tracing", "dep:console-subscriber"]
3535

3636
[dependencies]
37-
rblib = { git = "https://github.com/flashbots/rblib", rev = "b0e1ba3cfba5e190479e6dbcc95889422f0444ad" }
37+
rblib = { git = "https://github.com/flashbots/rblib", rev = "66c5c15a8834a6f677bec0d6b34f54ffc7cdd4ff" }
3838

3939
futures = "0.3"
4040
tokio = "1.46"
@@ -77,7 +77,7 @@ console-subscriber = { version = "0.4", optional = true }
7777
tracing-subscriber = "0.3.20"
7878

7979
[dev-dependencies]
80-
rblib = { git = "https://github.com/flashbots/rblib", rev = "b0e1ba3cfba5e190479e6dbcc95889422f0444ad", features = [
80+
rblib = { git = "https://github.com/flashbots/rblib", rev = "66c5c15a8834a6f677bec0d6b34f54ffc7cdd4ff", features = [
8181
"test-utils",
8282
] }
8383

src/flashtestations/step.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct State {
3535
impl FlashtestationsPrologue {
3636
pub fn try_new(
3737
args: FlashtestationsArgs,
38-
builder_key: Option<BuilderSigner>,
38+
builder_key: BuilderSigner,
3939
) -> eyre::Result<Self> {
4040
if !args.flashtestations_enabled {
4141
return Ok(Self {
@@ -44,10 +44,7 @@ impl FlashtestationsPrologue {
4444
});
4545
}
4646

47-
let manager = FlashtestationsManager::try_new(
48-
args,
49-
builder_key.context("builder key required for flashtestations")?,
50-
)?;
47+
let manager = FlashtestationsManager::try_new(args, builder_key)?;
5148

5249
Ok(Self {
5350
manager: Some(manager),

src/main.rs

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use {
55
limits::FlashblockLimits,
66
publish::{PublishFlashblock, WebSocketSink},
77
rpc::TransactionStatusRpc,
8+
signer::BuilderSigner,
89
state::FlashblockNumber,
910
stop::BreakAfterMaxFlashblocks,
1011
},
@@ -18,7 +19,6 @@ use {
1819
},
1920
reth_optimism_rpc::OpEthApiBuilder,
2021
std::sync::Arc,
21-
tracing::warn,
2222
};
2323

2424
mod args;
@@ -96,54 +96,50 @@ fn build_pipeline(
9696

9797
let ws = Arc::new(WebSocketSink::new(cli_args.flashblocks_args.ws_address)?);
9898

99-
let flashblock_building_pipeline_steps = if cli_args.revert_protection {
100-
(
101-
AppendOrders::from_pool(pool).with_ok_on_limit(),
102-
OrderByPriorityFee::default(),
103-
RemoveRevertedTransactions::default(),
104-
BreakAfterDeadline,
105-
)
106-
.into_pipeline()
107-
} else {
108-
(
109-
AppendOrders::from_pool(pool).with_ok_on_limit(),
110-
OrderByPriorityFee::default(),
111-
BreakAfterDeadline,
112-
)
113-
.into_pipeline()
114-
};
115-
116-
let flashblock_building_pipeline_steps = if let Some(ref signer) =
117-
cli_args.builder_signer
118-
{
119-
flashblock_building_pipeline_steps.with_epilogue(
120-
BuilderEpilogue::with_signer(signer.clone().into())
121-
.with_message(|block| format!("Block Number: {}", block.number())),
122-
)
123-
} else {
124-
warn!("BUILDER_SECRET_KEY is not specified, skipping builder transactions");
125-
flashblock_building_pipeline_steps
126-
};
99+
// TODO: Think about a better way to conditionally add steps so we don't
100+
// have to default to a random signer.
101+
let builder_signer = cli_args
102+
.builder_signer
103+
.clone()
104+
.unwrap_or(BuilderSigner::random());
127105

128106
// Multiple steps need to access flashblock number state, so we need to
129107
// initialize it outside
130108
let flashblock_number = Arc::new(FlashblockNumber::new());
131109

132-
let pipeline = Pipeline::<Flashblocks>::named("flashblocks")
110+
let pipeline = Pipeline::<Flashblocks>::named("top")
133111
.with_step(OptimismPrologue)
134-
.with_step(FlashtestationsPrologue::try_new(
135-
cli_args.flashtestations.clone(),
136-
cli_args.builder_signer.clone(),
137-
)?)
112+
.with_step_if(
113+
cli_args.flashtestations.flashtestations_enabled
114+
&& cli_args.builder_signer.is_some(),
115+
FlashtestationsPrologue::try_new(
116+
cli_args.flashtestations.clone(),
117+
builder_signer.clone(),
118+
)?,
119+
)
138120
.with_pipeline(
139121
Loop,
140-
Pipeline::default()
122+
Pipeline::named("n_flashblocks")
141123
.with_pipeline(
142124
Once,
143-
Pipeline::default()
125+
Pipeline::named("single_flashblock")
144126
.with_pipeline(
145127
Loop,
146-
flashblock_building_pipeline_steps
128+
Pipeline::named("flashblock_steps")
129+
.with_step(AppendOrders::from_pool(pool).with_ok_on_limit())
130+
.with_step(OrderByPriorityFee::default())
131+
.with_step_if(
132+
cli_args.revert_protection,
133+
RemoveRevertedTransactions::default(),
134+
)
135+
.with_step(BreakAfterDeadline)
136+
.with_epilogue_if(
137+
cli_args.builder_signer.is_some(),
138+
BuilderEpilogue::with_signer(builder_signer.clone().into())
139+
.with_message(|block| {
140+
format!("Block Number: {}", block.number())
141+
}),
142+
)
147143
.with_epilogue(PublishFlashblock::new(
148144
ws.clone(),
149145
flashblock_number.clone(),

0 commit comments

Comments
 (0)