From 5fbf4e165aeb34e8c0ebc6990ac02b8c24d28cd9 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Wed, 13 Sep 2023 17:52:11 -0400 Subject: [PATCH 1/5] Compute Pending Block --- crates/payload/basic/src/lib.rs | 4 +++- crates/payload/basic/src/optimism.rs | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index 8a5b83f4d458..52c05c68e984 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -444,6 +444,9 @@ where let maybe_better = self.pending_block.take(); let mut empty_payload = None; + #[cfg(feature = "optimism")] + let maybe_better = self.config.compute_pending_block.then(|| maybe_better).flatten(); + if best_payload.is_none() { // if no payload has been built yet self.metrics.inc_requested_empty_payload(); @@ -598,7 +601,6 @@ struct PayloadConfig { /// The chain spec. chain_spec: Arc, /// The rollup's compute pending block configuration option. - /// TODO(clabby): Implement this feature. #[cfg(feature = "optimism")] #[allow(dead_code)] compute_pending_block: bool, diff --git a/crates/payload/basic/src/optimism.rs b/crates/payload/basic/src/optimism.rs index 5e04c5350fa4..878eb8152c7a 100644 --- a/crates/payload/basic/src/optimism.rs +++ b/crates/payload/basic/src/optimism.rs @@ -34,6 +34,7 @@ where parent_block, attributes, chain_spec, + compute_pending_block, .. } = config; From a9699cf9b6a02e3d46d1e5c2d8773341d1985a7e Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Wed, 13 Sep 2023 18:10:32 -0400 Subject: [PATCH 2/5] Remove pending block from op payload builder --- crates/payload/basic/src/optimism.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/payload/basic/src/optimism.rs b/crates/payload/basic/src/optimism.rs index 878eb8152c7a..5e04c5350fa4 100644 --- a/crates/payload/basic/src/optimism.rs +++ b/crates/payload/basic/src/optimism.rs @@ -34,7 +34,6 @@ where parent_block, attributes, chain_spec, - compute_pending_block, .. } = config; From 090ba9259f82f086077a1e414e6f19fd91e05843 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Wed, 13 Sep 2023 18:24:35 -0400 Subject: [PATCH 3/5] Skip pending block compution entirely --- crates/payload/basic/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index 52c05c68e984..e35a99fba08d 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -341,6 +341,13 @@ where return Poll::Ready(Ok(())) } + // If compute pending block is disabled, only build the best payload + // when the interval is reached or the future is resolved. + #[cfg(feature = "optimism")] + if !self.config.compute_pending_block { + return Poll::Pending + } + // 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 @@ -602,7 +609,6 @@ struct PayloadConfig { chain_spec: Arc, /// The rollup's compute pending block configuration option. #[cfg(feature = "optimism")] - #[allow(dead_code)] compute_pending_block: bool, } From 726896687d66d37723c1e313ac3ee171844a7d64 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Wed, 13 Sep 2023 19:28:05 -0400 Subject: [PATCH 4/5] Compute Pending Block --- crates/payload/basic/src/lib.rs | 67 +++++++++++++++++---------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index e35a99fba08d..90835b2d3a56 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -341,11 +341,15 @@ where return Poll::Ready(Ok(())) } - // If compute pending block is disabled, only build the best payload - // when the interval is reached or the future is resolved. + // 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 !self.config.compute_pending_block { - return Poll::Pending + if !this.config.compute_pending_block { + return Poll::Ready(Ok(())); } // check if the interval is reached @@ -451,8 +455,34 @@ 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")] - let maybe_better = self.config.compute_pending_block.then(|| maybe_better).flatten(); + 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 @@ -466,33 +496,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); } From 75d1a6a1df2548b5d81f27666acfd7f35227c52d Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Wed, 13 Sep 2023 19:32:31 -0400 Subject: [PATCH 5/5] Compute Pending Block --- crates/payload/basic/src/lib.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index 90835b2d3a56..f92af18f126d 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -349,7 +349,7 @@ where // 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(())); + return Poll::Ready(Ok(())) } // check if the interval is reached @@ -467,18 +467,13 @@ where cancel: Cancelled::default(), best_payload: None, }; - if let Ok(BuildOutcome::Better { payload, cached_reads }) = - self.builder.try_build(args) + 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, - }, + ResolveBestPayload { best_payload: Some(payload), maybe_better, empty_payload }, KeepPayloadJobAlive::Yes, ) }