Skip to content

Commit 8a4d304

Browse files
committed
fix index
1 parent b7a296f commit 8a4d304

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

crates/op-rbuilder/src/builders/flashblocks/builder_tx.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,17 @@ impl BuilderTransactions<FlashblocksExtraCtx> for FlashblocksBuilderTx {
124124
db: &mut State<impl Database>,
125125
) -> Result<Vec<BuilderTransactionCtx>, BuilderTransactionError> {
126126
let mut builder_txs = Vec::<BuilderTransactionCtx>::new();
127-
let flashblocks_builder_tx = self.simulate_builder_tx(ctx, db)?;
128-
builder_txs.extend(flashblocks_builder_tx.clone());
129-
if let Some(flashtestations_builder_tx) = &self.flashtestations_builder_tx {
130-
// We only include flashtestations txs in the last flashblock
131-
if ctx.flashblock_index() == ctx.target_flashblock_count() - 1 {
127+
if ctx.is_first_fallback_block() {
128+
let flashblocks_builder_tx = self.simulate_builder_tx(ctx, db)?;
129+
builder_txs.extend(flashblocks_builder_tx.clone());
130+
}
131+
132+
if ctx.is_last_flashblock() {
133+
let flashblocks_builder_tx = self.simulate_builder_tx(ctx, db)?;
134+
builder_txs.extend(flashblocks_builder_tx.clone());
135+
if let Some(flashtestations_builder_tx) = &self.flashtestations_builder_tx {
136+
// We only include flashtestations txs in the last flashblock
137+
132138
let mut simulation_state = self.simulate_builder_txs_state::<FlashblocksExtraCtx>(
133139
state_provider.clone(),
134140
flashblocks_builder_tx.iter().collect(),

crates/op-rbuilder/src/builders/flashblocks/payload.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub struct FlashblocksExtraCtx {
6565
pub flashblock_index: u64,
6666
/// Target flashblock count
6767
pub target_flashblock_count: u64,
68+
/// Whether the current flashblock is the first fallback block
69+
pub is_first_fallback_block: bool,
6870
}
6971

7072
impl OpPayloadBuilderCtx<FlashblocksExtraCtx> {
@@ -78,6 +80,11 @@ impl OpPayloadBuilderCtx<FlashblocksExtraCtx> {
7880
self.extra_ctx.target_flashblock_count
7981
}
8082

83+
/// Returns if the flashblock is the first fallback block
84+
pub fn is_first_fallback_block(&self) -> bool {
85+
self.extra_ctx.is_first_fallback_block
86+
}
87+
8188
/// Increments the flashblock index
8289
pub fn increment_flashblock_index(&mut self) -> u64 {
8390
self.extra_ctx.flashblock_index += 1;
@@ -90,6 +97,11 @@ impl OpPayloadBuilderCtx<FlashblocksExtraCtx> {
9097
self.extra_ctx.target_flashblock_count
9198
}
9299

100+
/// Sets the first fallback block flag
101+
pub fn set_first_fallback_block(&mut self, is_first_fallback_block: bool) {
102+
self.extra_ctx.is_first_fallback_block = is_first_fallback_block;
103+
}
104+
93105
/// Returns if the flashblock is the last one
94106
pub fn is_last_flashblock(&self) -> bool {
95107
self.flashblock_index() == self.target_flashblock_count() - 1
@@ -250,6 +262,7 @@ where
250262
extra_ctx: FlashblocksExtraCtx {
251263
flashblock_index: 0,
252264
target_flashblock_count: self.config.flashblocks_per_block(),
265+
is_first_fallback_block: true,
253266
},
254267
};
255268

@@ -286,6 +299,8 @@ where
286299
self.ws_pub
287300
.publish(&fb_payload)
288301
.map_err(PayloadBuilderError::other)?;
302+
// We set the first fallback block flag to false after building the first fallback block
303+
ctx.set_first_fallback_block(false);
289304

290305
info!(
291306
target: "payload_builder",

0 commit comments

Comments
 (0)