Skip to content

Reproduction Unknown Payload #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ impl EngineApiServer for RollupBoostServer {
let span = tracing::Span::current();
if let Some(payload_id) = l2_response.payload_id {
span.record("payload_id", payload_id.to_string());

info!(
"received fork_choice_updated_v3, payload_id: {}",
payload_id
);
}

let (should_send_to_builder, has_attributes, use_tx_pool) =
Expand Down Expand Up @@ -394,7 +399,7 @@ impl EngineApiServer for RollupBoostServer {
&self,
payload_id: PayloadId,
) -> RpcResult<OpExecutionPayloadEnvelopeV3> {
info!("received get_payload_v3");
info!("received get_payload_v3, payload_id: {}", payload_id);

match self.get_payload(payload_id, Version::V3).await? {
OpExecutionPayloadEnvelope::V3(v3) => Ok(v3),
Expand Down
26 changes: 1 addition & 25 deletions tests/builder_full_delay.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
use common::RollupBoostTestHarnessBuilder;
use common::proxy::ProxyHandler;
use futures::FutureExt;
use serde_json::Value;
use std::pin::Pin;
use common::proxy_delay::DelayHandler;
use std::sync::{Arc, Mutex};
use std::time::Duration;

mod common;

// Create a dynamic handler that delays all the calls by 2 seconds
struct DelayHandler {
delay: Arc<Mutex<Duration>>,
}

impl ProxyHandler for DelayHandler {
fn handle(
&self,
_method: String,
_params: Value,
_result: Value,
) -> Pin<Box<dyn Future<Output = Option<Value>> + Send>> {
let delay = *self.delay.lock().unwrap();
async move {
tokio::time::sleep(delay).await;
None
}
.boxed()
}
}

#[tokio::test]
async fn builder_full_delay() -> eyre::Result<()> {
let delay = Arc::new(Mutex::new(Duration::from_secs(0)));
Expand Down
14 changes: 12 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub static TEST_DATA: LazyLock<String> =
LazyLock::new(|| format!("{}/tests/common/test_data", env!("CARGO_MANIFEST_DIR")));

pub mod proxy;
pub mod proxy_delay;
pub mod services;

pub struct LoggingConsumer {
Expand Down Expand Up @@ -383,6 +384,8 @@ pub struct SimpleBlockGenerator {
engine_api: EngineApi,
latest_hash: B256,
timestamp: u64,
version: Version,
set_block_time: u64,
genesis: Genesis,
current_block_number: u64,
}
Expand All @@ -397,12 +400,19 @@ impl SimpleBlockGenerator {
validator,
engine_api,
latest_hash: B256::ZERO, // temporary value
version: Version::V3,
set_block_time: 1,
timestamp: genesis.timestamp,
genesis,
current_block_number: 0,
}
}

/// Set the block time for the block generator
pub fn set_block_time(&mut self, block_time: u64) {
self.set_block_time = block_time;
}

/// Initialize the block generator by fetching the latest block
pub async fn init(&mut self) -> eyre::Result<()> {
let latest_block = self.engine_api.latest().await?.expect("block not found");
Expand Down Expand Up @@ -466,8 +476,8 @@ impl SimpleBlockGenerator {

let payload_id = result.payload_id.expect("missing payload id");

if !empty_blocks {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
if !empty_blocks && self.set_block_time != 0 {
tokio::time::sleep(tokio::time::Duration::from_secs(self.set_block_time)).await;
}

let payload = self.engine_api.get_payload(version, payload_id).await?;
Expand Down
35 changes: 35 additions & 0 deletions tests/common/proxy_delay.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::common::proxy::ProxyHandler;
use futures::FutureExt;
use serde_json::Value;
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::time::Duration;

// Create a dynamic handler that delays all the calls by 2 seconds
pub struct DelayHandler {
pub delay: Arc<Mutex<Duration>>,
}

impl DelayHandler {
pub fn new(delay: Duration) -> Self {
Self {
delay: Arc::new(Mutex::new(delay)),
}
}
}

impl ProxyHandler for DelayHandler {
fn handle(
&self,
_method: String,
_params: Value,
_result: Value,
) -> Pin<Box<dyn Future<Output = Option<Value>> + Send>> {
let delay = *self.delay.lock().unwrap();
async move {
tokio::time::sleep(delay).await;
None
}
.boxed()
}
}
36 changes: 36 additions & 0 deletions tests/fcu_precedes_get_payload.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
mod common;

use common::RollupBoostTestHarnessBuilder;
use common::proxy_delay::DelayHandler;
use std::sync::Arc;
use std::time::Duration;

#[tokio::test]
async fn fcu_precedes_get_payload() -> eyre::Result<()> {
let delay = DelayHandler::new(Duration::from_millis(200));

let harness = RollupBoostTestHarnessBuilder::new("fcu_precedes_get_payload")
.proxy_handler(Arc::new(delay))
.build()
.await?;
let mut block_generator = harness.block_generator().await?;
block_generator.set_block_time(0);

for _ in 0..300 {
let (_block, _block_creator) = block_generator.generate_block(false).await?;
}

// Count occurrences of "Unknown payload" in the Rollup-boost logs
// TODO: Do not rely on reading logs, maybe use a metric?
let content = std::fs::read_to_string(harness.rollup_boost.args().log_file.clone().unwrap())?;
let unknown_payload_count = content.matches("Unknown payload").count();

// TODO: The first iteration of the loop always fails to get the payload.
// That is why we are expecting at most one error.
assert!(
unknown_payload_count <= 1,
"Expected at most one 'Unknown payload' error, got {unknown_payload_count}"
);

Ok(())
}
Loading