Skip to content

Commit 47ba3a2

Browse files
committed
feat(bundles): flashblock min and max params
1 parent d6597c9 commit 47ba3a2

File tree

6 files changed

+70
-12
lines changed

6 files changed

+70
-12
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 = "198cbe65e59f7467c756d5ba6422155c98402291" }
37+
rblib = { git = "https://github.com/flashbots/rblib", branch = "ak-filter-orders" }
3838

3939
futures = "0.3"
4040
tokio = "1.46"
@@ -75,7 +75,7 @@ console-subscriber = { version = "0.4", optional = true }
7575
tracing-subscriber = "0.3.20"
7676

7777
[dev-dependencies]
78-
rblib = { git = "https://github.com/flashbots/rblib", rev = "198cbe65e59f7467c756d5ba6422155c98402291", features = [
78+
rblib = { git = "https://github.com/flashbots/rblib", branch = "ak-filter-orders", features = [
7979
"test-utils",
8080
] }
8181

src/bundle.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ pub struct FlashblocksBundle {
7878
/// Note: Not recommended because this is subject to the builder node clock.
7979
#[serde(default, skip_serializing_if = "Option::is_none")]
8080
pub max_timestamp: Option<u64>,
81+
82+
/// Minimum flashblock number at which this bundle can be included.
83+
///
84+
/// Flashblocks are preconfirmations that are built incrementally. This
85+
/// field along with `maxFlashblockNumber` allows bundles to be scheduled
86+
/// for more precise execution.
87+
#[serde(
88+
default,
89+
with = "alloy_serde::quantity::opt",
90+
skip_serializing_if = "Option::is_none"
91+
)]
92+
pub min_flashblock_number: Option<u64>,
93+
94+
/// Maximum flashblock number at which this bundle can be included.
95+
///
96+
/// Similar to `minFlashblockNumber`, this sets an upper bound on which
97+
/// flashblocks can include this bundle.
98+
#[serde(
99+
default,
100+
with = "alloy_serde::quantity::opt",
101+
skip_serializing_if = "Option::is_none"
102+
)]
103+
pub max_flashblock_number: Option<u64>,
81104
}
82105

83106
impl FlashblocksBundle {
@@ -93,6 +116,8 @@ impl FlashblocksBundle {
93116
max_block_number: None,
94117
min_timestamp: None,
95118
max_timestamp: None,
119+
min_flashblock_number: None,
120+
max_flashblock_number: None,
96121
}
97122
}
98123
}

src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,14 @@ fn build_flashblocks_pipeline(
141141

142142
let ws = Arc::new(WebSocketSink::new(socket_address)?);
143143

144+
// Multiple steps need to access flashblock number state, so we need to
145+
// initialize it outside
146+
let flashblock_number = Arc::new(FlashblockNumber::new());
147+
144148
let flashblock_building_pipeline_steps = (
145-
AppendOrders::from_pool(pool).with_ok_on_limit(),
149+
AppendOrders::from_pool(pool)
150+
.with_ok_on_limit()
151+
.with_filter(flashblock_number.clone().bundle_filter()),
146152
OrderByPriorityFee::default(),
147153
RemoveRevertedTransactions::default(),
148154
BreakAfterDeadline,
@@ -161,10 +167,6 @@ fn build_flashblocks_pipeline(
161167
flashblock_building_pipeline_steps
162168
};
163169

164-
// Multiple steps need to access flashblock number state, so we need to
165-
// initialize it outside
166-
let flashblock_number = Arc::new(FlashblockNumber::new());
167-
168170
let pipeline = Pipeline::<Flashblocks>::named("flashblocks")
169171
.with_prologue(OptimismPrologue)
170172
.with_pipeline(

src/platform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use {
1414
/// the `Flashblocks` platform.
1515
///
1616
/// See [`rblib::Platform`] for more details on platform definitions.
17-
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
17+
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
1818
pub struct Flashblocks;
1919

2020
impl Platform for Flashblocks {

src/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Step<Flashblocks> for PublishFlashblock {
210210

211211
/// Called during pipeline instantiation before any payload job is served.
212212
/// - Configure metrics scope.
213-
fn setup(
213+
async fn setup(
214214
&mut self,
215215
ctx: InitContext<Flashblocks>,
216216
) -> Result<(), PayloadBuilderError> {

src/state.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
use std::{
2-
fmt::Display,
3-
sync::atomic::{AtomicU64, Ordering},
1+
use {
2+
crate::Flashblocks,
3+
rblib::{pool::Order, prelude::*},
4+
std::{
5+
fmt::Display,
6+
sync::{Arc, atomic::{AtomicU64, Ordering}},
7+
},
48
};
59

610
#[derive(Debug)]
@@ -53,6 +57,33 @@ impl FlashblockNumber {
5357
pub fn reset_current_flashblock(&self) -> u64 {
5458
self.current_flashblock.swap(1, Ordering::Relaxed)
5559
}
60+
61+
pub fn bundle_filter(
62+
self: Arc<Self>,
63+
) -> impl Fn(&Checkpoint<Flashblocks>, &Order<Flashblocks>) -> bool
64+
+ Send
65+
+ Sync
66+
+ 'static {
67+
move |_: &Checkpoint<Flashblocks>, order: &Order<Flashblocks>| -> bool {
68+
let current_flashblock_number = self.current();
69+
70+
if let Order::Bundle(bundle) = order {
71+
if let Some(min_flashblock_number) = bundle.min_flashblock_number {
72+
if current_flashblock_number < min_flashblock_number {
73+
return false;
74+
}
75+
}
76+
77+
if let Some(max_flashblock_number) = bundle.max_flashblock_number {
78+
if max_flashblock_number < current_flashblock_number {
79+
return false;
80+
}
81+
}
82+
}
83+
84+
true
85+
}
86+
}
5687
}
5788

5889
impl Default for FlashblockNumber {

0 commit comments

Comments
 (0)