Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

feat: Compute Pending Block #123

Open
wants to merge 5 commits into
base: clabby/op-reth
Choose a base branch
from
Open
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
64 changes: 35 additions & 29 deletions crates/payload/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ where
return Poll::Ready(Ok(()))
}

// If compute pending block is disabled, we return early
// since the payload attributes contain the sequencer transactions
// that are used to build the block. So, in the future resolution
// the payload can be built synchronously.
// Also, compute pending block is used to prevent pending transactions
// from showing up in the pending block, which leaks the tx pool.
#[cfg(feature = "optimism")]
if !this.config.compute_pending_block {
return Poll::Ready(Ok(()))
}

// check if the interval is reached
while this.interval.poll_tick(cx).is_ready() {
// start a new job if there is no pending block and we haven't reached the deadline
Expand Down Expand Up @@ -444,6 +455,30 @@ where
let maybe_better = self.pending_block.take();
let mut empty_payload = None;

// If compute pending block is disabled or there is no tx pool,
// the best payload has to be built on future resolve.
#[cfg(feature = "optimism")]
if !self.config.compute_pending_block || self.config.attributes.no_tx_pool {
let args = BuildArguments {
client: self.client.clone(),
pool: self.pool.clone(),
cached_reads: self.cached_reads.take().unwrap_or_default(),
config: self.config.clone(),
cancel: Cancelled::default(),
best_payload: None,
};
if let Ok(BuildOutcome::Better { payload, cached_reads }) = self.builder.try_build(args)
{
self.cached_reads = Some(cached_reads);
trace!("[OPTIMISM] Forced best payload");
let payload = Arc::new(payload);
return (
ResolveBestPayload { best_payload: Some(payload), maybe_better, empty_payload },
KeepPayloadJobAlive::Yes,
)
}
}

if best_payload.is_none() {
// if no payload has been built yet
self.metrics.inc_requested_empty_payload();
Expand All @@ -456,33 +491,6 @@ where
let _ = tx.send(res);
}));

#[cfg(feature = "optimism")]
if self.config.chain_spec.optimism && self.config.attributes.no_tx_pool {
let args = BuildArguments {
client: self.client.clone(),
pool: self.pool.clone(),
cached_reads: self.cached_reads.take().unwrap_or_default(),
config: self.config.clone(),
cancel: Cancelled::default(),
best_payload: None,
};
if let Ok(BuildOutcome::Better { payload, cached_reads }) =
self.builder.try_build(args)
{
self.cached_reads = Some(cached_reads);
trace!("[OPTIMISM] Forced best payload");
let payload = Arc::new(payload);
return (
ResolveBestPayload {
best_payload: Some(payload),
maybe_better,
empty_payload,
},
KeepPayloadJobAlive::Yes,
)
}
}

empty_payload = Some(rx);
}

Expand Down Expand Up @@ -598,9 +606,7 @@ struct PayloadConfig {
/// The chain spec.
chain_spec: Arc<ChainSpec>,
/// The rollup's compute pending block configuration option.
/// TODO(clabby): Implement this feature.
#[cfg(feature = "optimism")]
#[allow(dead_code)]
compute_pending_block: bool,
}

Expand Down