From 7e60374378a930a8afa943feb6fd4cb59a527973 Mon Sep 17 00:00:00 2001 From: dylan Date: Fri, 21 Nov 2025 10:17:58 -0700 Subject: [PATCH 01/10] fix: make block query cutoff properly configurable --- Cargo.lock | 1 + Cargo.toml | 7 ++++--- README.md | 5 +++-- src/config.rs | 8 ++++++++ src/tasks/block/sim.rs | 36 +++++++++++++++++++++++------------- src/tasks/env.rs | 4 ++-- src/test_utils.rs | 1 + 7 files changed, 42 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d89fef32..6e18fe3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2454,6 +2454,7 @@ dependencies = [ "serde", "serde_json", "signet-block-processor", + "signet-bundle", "signet-constants", "signet-genesis", "signet-sim", diff --git a/Cargo.toml b/Cargo.toml index e36b70cc..31b97185 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ signet-constants = { version = "0.16.0-rc.0" } signet-sim = { version = "0.16.0-rc.0" } signet-tx-cache = { version = "0.16.0-rc.0" } signet-types = { version = "0.16.0-rc.0" } +signet-bundle = { version = "0.16.0-rc.0" } signet-zenith = { version = "0.16.0-rc.0" } signet-block-processor = { git = "https://github.com/init4tech/node-components", tag = "v0.16.0-rc.2" } signet-genesis = { git = "https://github.com/init4tech/node-components", tag = "v0.16.0-rc.2" } @@ -64,12 +65,12 @@ alloy-chains = "0.2" # comment / uncomment for local dev # [patch.crates-io] # signet-constants = { path = "../signet-sdk/crates/constants" } +# signet-sim = { path = "../signet-sdk/crates/sim" } +# signet-tx-cache = { path = "../signet-sdk/crates/tx-cache" } # signet-types = { path = "../signet-sdk/crates/types" } # signet-zenith = { path = "../signet-sdk/crates/zenith" } -# signet-sim = { path = "../signet-sdk/crates/sim" } + # signet-evm = { path = "../signet-sdk/crates/evm" } # signet-extract = { path = "../signet-sdk/crates/extract" } # signet-journal = { path = "../signet-sdk/crates/journal" } -# signet-tx-cache = { path = "../signet-sdk/crates/tx-cache" } # signet-bundle = { path = "../signet-sdk/crates/bundle" } -# init4-bin-base = { path = "../bin-base" } diff --git a/README.md b/README.md index ce9053ea..b9d69f25 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Finally, if it's non-empty, the submit task attempts to get a signature for the The Builder is configured via environment variables. The following values are supported for configuration. Key | Required | Description ------------------------------ | -------- | ------------------------------------------------------------------------------ +----------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ `RUST_LOG` | No | The log level of the builder `CHAIN_NAME` | No | The chain name ("pecorino", or the corresponding name) `HOST_RPC_URL` | Yes | RPC endpoint for the host chain @@ -97,7 +97,8 @@ Key | Required | Description `FLASHBOTS_ENDPOINT` | No | Flashbots API to submit blocks to `ROLLUP_BLOCK_GAS_LIMIT` | No | Override for rollup block gas limit `MAX_HOST_GAS_COEFFICIENT` | No | Optional maximum host gas coefficient, as a percentage, to use when building blocks -`BUILDER_KEY` | Yes | AWS KMS key ID _or_ local private key for builder signing +`BUILDER_KEY` | Yes | AWS KMS key ID _or_ local private key for builder signin +`BLOCK_QUERY_CUTOFF_BUFFER` | Yes | Number of milliseconds before the end of the slot to stop querying for new transactions and start the block signing and submission process `AWS_ACCESS_KEY_ID` | No | AWS secret access key ID (required if not using `BUILDER_KEY`) `AWS_SECRET_ACCESS_KEY` | No | AWS secret access key (required if not using `BUILDER_KEY`) `AWS_DEFAULT_REGION` | No | AWS region for the KMS key in question (required if not using `BUILDER_KEY`) diff --git a/src/config.rs b/src/config.rs index a4788285..9705336d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -155,6 +155,14 @@ pub struct BuilderConfig { )] pub max_host_gas_coefficient: Option, + /// Number of seconds before the end of the slot to stop querying for new blocks + #[from_env( + var = "BLOCK_QUERY_CUTOFF_BUFFER", + desc = "Number of milliseconds before the end of the slot to stop querying for new transactions and start the block signing and submission process", + default = 3000 + )] + pub block_query_cutoff_buffer: u64, + /// The slot calculator for the builder. pub slot_calculator: SlotCalculator, diff --git a/src/tasks/block/sim.rs b/src/tasks/block/sim.rs index 29f11571..da102062 100644 --- a/src/tasks/block/sim.rs +++ b/src/tasks/block/sim.rs @@ -127,9 +127,12 @@ impl SimulatorTask { let concurrency_limit = self.config.concurrency_limit(); let rollup_env = sim_env.sim_rollup_env(self.constants(), self.ru_provider.clone()); - let host_env = sim_env.sim_host_env(self.constants(), self.host_provider.clone()); + let ru_number = rollup_env.block().number; + let host_number = host_env.block().number; + debug!(?ru_number, ?host_number, "starting block simulation"); + let block_build = BlockBuild::new( rollup_env, host_env, @@ -226,24 +229,31 @@ impl SimulatorTask { } } - /// Calculates the deadline for the current block simulation. + /// Calculates the deadline for the current block simulation in milliseconds. /// /// # Returns /// - /// An `Instant` representing the simulation deadline, as calculated by - /// determining the time left in the current slot and adding that to the - /// current timestamp in UNIX seconds. + /// An `Instant` representing the simulation deadline as calculated by determining + /// the milliseconds left in the current slot and adding that to the current + /// timestamp in UNIX seconds. pub fn calculate_deadline(&self) -> Instant { - // Get the current timepoint within the slot. - let timepoint = - self.slot_calculator().current_point_within_slot().expect("host chain has started"); + // Get the current number of milliseconds into the slot. + let timepoint_ms = + self.slot_calculator().current_point_within_slot_ms().expect("host chain has started"); + let slot_duration = Duration::from_secs(self.slot_calculator().slot_duration()).as_millis(); + let elapsed_in_slot = Duration::from_millis(timepoint_ms); + let query_cutoff_buffer = Duration::from_millis(self.config.block_query_cutoff_buffer); - // We have the timepoint in seconds into the slot. To find out what's - // remaining, we need to subtract it from the slot duration - // we also subtract 3 seconds to account for the sequencer stopping signing. - let remaining = (self.slot_calculator().slot_duration() - timepoint).saturating_sub(3); + // To find the remaining slot time, subtract the timepoint from the slot duration. + // Then subtract the block query cutoff buffer from the slot duration to account for + // the sequencer stopping signing. + let remaining = slot_duration + .saturating_sub(elapsed_in_slot.as_millis()) + .saturating_sub(query_cutoff_buffer.as_millis()); - let deadline = Instant::now() + Duration::from_secs(remaining); + // The deadline is then calculated by adding the remaining time from this instant. + // NB: Downcast is okay because u64 will work for 500 million+ years. + let deadline = Instant::now() + Duration::from_millis(remaining as u64); deadline.max(Instant::now()) } } diff --git a/src/tasks/env.rs b/src/tasks/env.rs index 33d406b6..d020e950 100644 --- a/src/tasks/env.rs +++ b/src/tasks/env.rs @@ -5,7 +5,7 @@ use crate::{ }; use alloy::{ consensus::Header, - eips::eip1559::BaseFeeParams, + eips::{BlockId, eip1559::BaseFeeParams}, network::Ethereum, primitives::{B256, U256}, providers::{Provider, network::Network}, @@ -67,7 +67,7 @@ impl Environment { /// Create a new [`AlloyDB`] for this environment using the given provider. pub fn alloy_db>(&self, provider: P) -> AlloyDB { - AlloyDB::new(provider, self.prev_header.number.into()) + AlloyDB::new(provider, BlockId::latest()) } } diff --git a/src/test_utils.rs b/src/test_utils.rs index 1384ea38..e35fab13 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -54,6 +54,7 @@ pub fn setup_test_config() -> &'static BuilderConfig { 1740681556, // pecorino start timestamp as sane default 0, 1, ), + block_query_cutoff_buffer: 3000, max_host_gas_coefficient: Some(80), constants: SignetSystemConstants::parmigiana(), } From c8df533542cd4cbd0efd5f92324c15be8aec682d Mon Sep 17 00:00:00 2001 From: dylan Date: Mon, 24 Nov 2025 21:57:33 -0700 Subject: [PATCH 02/10] put alloy db back --- src/tasks/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tasks/env.rs b/src/tasks/env.rs index d020e950..90852358 100644 --- a/src/tasks/env.rs +++ b/src/tasks/env.rs @@ -67,7 +67,7 @@ impl Environment { /// Create a new [`AlloyDB`] for this environment using the given provider. pub fn alloy_db>(&self, provider: P) -> AlloyDB { - AlloyDB::new(provider, BlockId::latest()) + AlloyDB::new(provider, self.prev_header.number.into()) } } From 3e4378e3ce5ea23709e64f1857ad3b37e0e38e60 Mon Sep 17 00:00:00 2001 From: dylan Date: Mon, 24 Nov 2025 22:01:13 -0700 Subject: [PATCH 03/10] fmt --- src/tasks/block/sim.rs | 6 +----- src/tasks/env.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/tasks/block/sim.rs b/src/tasks/block/sim.rs index da102062..166b9ae3 100644 --- a/src/tasks/block/sim.rs +++ b/src/tasks/block/sim.rs @@ -128,11 +128,7 @@ impl SimulatorTask { let rollup_env = sim_env.sim_rollup_env(self.constants(), self.ru_provider.clone()); let host_env = sim_env.sim_host_env(self.constants(), self.host_provider.clone()); - - let ru_number = rollup_env.block().number; - let host_number = host_env.block().number; - debug!(?ru_number, ?host_number, "starting block simulation"); - + let block_build = BlockBuild::new( rollup_env, host_env, diff --git a/src/tasks/env.rs b/src/tasks/env.rs index 90852358..9446c2e8 100644 --- a/src/tasks/env.rs +++ b/src/tasks/env.rs @@ -5,7 +5,7 @@ use crate::{ }; use alloy::{ consensus::Header, - eips::{BlockId, eip1559::BaseFeeParams}, + eips::{eip1559::BaseFeeParams}, network::Ethereum, primitives::{B256, U256}, providers::{Provider, network::Network}, From 834659e02ed771e6bed0fe01163ec7d7f9e97aa4 Mon Sep 17 00:00:00 2001 From: dylan Date: Mon, 24 Nov 2025 22:20:22 -0700 Subject: [PATCH 04/10] fmt --- src/tasks/block/sim.rs | 2 +- src/tasks/env.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tasks/block/sim.rs b/src/tasks/block/sim.rs index 166b9ae3..ca00f8a2 100644 --- a/src/tasks/block/sim.rs +++ b/src/tasks/block/sim.rs @@ -128,7 +128,7 @@ impl SimulatorTask { let rollup_env = sim_env.sim_rollup_env(self.constants(), self.ru_provider.clone()); let host_env = sim_env.sim_host_env(self.constants(), self.host_provider.clone()); - + let block_build = BlockBuild::new( rollup_env, host_env, diff --git a/src/tasks/env.rs b/src/tasks/env.rs index 9446c2e8..33d406b6 100644 --- a/src/tasks/env.rs +++ b/src/tasks/env.rs @@ -5,7 +5,7 @@ use crate::{ }; use alloy::{ consensus::Header, - eips::{eip1559::BaseFeeParams}, + eips::eip1559::BaseFeeParams, network::Ethereum, primitives::{B256, U256}, providers::{Provider, network::Network}, From b58985e41e4a6f35d7f82365cc7004710856d16c Mon Sep 17 00:00:00 2001 From: dylan Date: Tue, 25 Nov 2025 19:49:21 -0700 Subject: [PATCH 05/10] refactor: avoid using Duration --- src/tasks/block/sim.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/tasks/block/sim.rs b/src/tasks/block/sim.rs index ca00f8a2..19e73cf7 100644 --- a/src/tasks/block/sim.rs +++ b/src/tasks/block/sim.rs @@ -236,20 +236,19 @@ impl SimulatorTask { // Get the current number of milliseconds into the slot. let timepoint_ms = self.slot_calculator().current_point_within_slot_ms().expect("host chain has started"); - let slot_duration = Duration::from_secs(self.slot_calculator().slot_duration()).as_millis(); - let elapsed_in_slot = Duration::from_millis(timepoint_ms); - let query_cutoff_buffer = Duration::from_millis(self.config.block_query_cutoff_buffer); + + let slot_duration = self.slot_calculator().slot_duration() * 1000; // convert to milliseconds + let query_cutoff_buffer = self.config.block_query_cutoff_buffer; // To find the remaining slot time, subtract the timepoint from the slot duration. // Then subtract the block query cutoff buffer from the slot duration to account for // the sequencer stopping signing. - let remaining = slot_duration - .saturating_sub(elapsed_in_slot.as_millis()) - .saturating_sub(query_cutoff_buffer.as_millis()); + let remaining = + slot_duration.saturating_sub(timepoint_ms).saturating_sub(query_cutoff_buffer); // The deadline is then calculated by adding the remaining time from this instant. // NB: Downcast is okay because u64 will work for 500 million+ years. - let deadline = Instant::now() + Duration::from_millis(remaining as u64); + let deadline = Instant::now() + Duration::from_millis(remaining); deadline.max(Instant::now()) } } From d8c972364d4d0aff32b5c77278ae728be4160aae Mon Sep 17 00:00:00 2001 From: dylan Date: Mon, 8 Dec 2025 20:11:34 -0700 Subject: [PATCH 06/10] cleanup --- src/test_utils.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test_utils.rs b/src/test_utils.rs index e35fab13..cb9d3e75 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -23,7 +23,6 @@ use trevm::revm::{context::BlockEnv, context_interface::block::BlobExcessGasAndP pub fn setup_test_config() -> &'static BuilderConfig { crate::CONFIG.get_or_init(|| { BuilderConfig { - // host_chain_id: signet_constants::pecorino::HOST_CHAIN_ID, host_rpc: "ws://host-rpc.pecorino.signet.sh" .parse::() .map(ProviderConfig::new) From b81b11e6bd56715b2142e92cab52ba94bfa9d46f Mon Sep 17 00:00:00 2001 From: dylan Date: Tue, 9 Dec 2025 15:35:27 -0700 Subject: [PATCH 07/10] deps: update to signet-sdk@0.16.0-rc.0 to align bin-base version --- Cargo.toml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 31b97185..b3cfe3dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,13 +19,17 @@ path = "bin/builder.rs" [dependencies] init4-bin-base = { version = "0.18.0-rc.0", features = ["perms", "aws"] } +# init4-bin-base = { git = "https://github.com/init4tech/bin-base.git", branch = "main", features = [ +# "perms", +# "aws", +# ] } -signet-constants = { version = "0.16.0-rc.0" } -signet-sim = { version = "0.16.0-rc.0" } -signet-tx-cache = { version = "0.16.0-rc.0" } -signet-types = { version = "0.16.0-rc.0" } -signet-bundle = { version = "0.16.0-rc.0" } -signet-zenith = { version = "0.16.0-rc.0" } +signet-constants = { version = "0.16.0-rc.1" } +signet-sim = { version = "0.16.0-rc.1" } +signet-tx-cache = { version = "0.16.0-rc.1" } +signet-types = { version = "0.16.0-rc.1" } +signet-bundle = { version = "0.16.0-rc.1" } +signet-zenith = { version = "0.16.0-rc.1" } signet-block-processor = { git = "https://github.com/init4tech/node-components", tag = "v0.16.0-rc.2" } signet-genesis = { git = "https://github.com/init4tech/node-components", tag = "v0.16.0-rc.2" } From 98180bb52a425bc60c5b7fb9b3687f61de01d23f Mon Sep 17 00:00:00 2001 From: dylan Date: Fri, 12 Dec 2025 15:54:50 -0700 Subject: [PATCH 08/10] clippy --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index b727a412..55cc8332 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,6 +37,7 @@ use init4_bin_base::utils::from_env::FromEnv; // Anonymous import suppresses warnings about unused imports. use openssl as _; use signet_constants::SignetSystemConstants; +use signet_bundle as _; use std::sync::OnceLock; /// Global static configuration for the Builder binary. From 311180808d6eef064235c7a8ed8be2b569ef9577 Mon Sep 17 00:00:00 2001 From: dylan Date: Fri, 12 Dec 2025 15:56:07 -0700 Subject: [PATCH 09/10] cleanup --- Cargo.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b3cfe3dd..794ffb9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,10 +19,6 @@ path = "bin/builder.rs" [dependencies] init4-bin-base = { version = "0.18.0-rc.0", features = ["perms", "aws"] } -# init4-bin-base = { git = "https://github.com/init4tech/bin-base.git", branch = "main", features = [ -# "perms", -# "aws", -# ] } signet-constants = { version = "0.16.0-rc.1" } signet-sim = { version = "0.16.0-rc.1" } From 8ac4079fa3a506ff774878144335decb91f8ee10 Mon Sep 17 00:00:00 2001 From: dylan Date: Fri, 12 Dec 2025 16:20:08 -0700 Subject: [PATCH 10/10] fmt --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 55cc8332..11667859 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,8 +36,8 @@ pub mod test_utils; use init4_bin_base::utils::from_env::FromEnv; // Anonymous import suppresses warnings about unused imports. use openssl as _; -use signet_constants::SignetSystemConstants; use signet_bundle as _; +use signet_constants::SignetSystemConstants; use std::sync::OnceLock; /// Global static configuration for the Builder binary.