Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ path = "bin/builder.rs"
[dependencies]
init4-bin-base = { version = "0.18.0-rc.0", 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-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" }

Expand Down Expand Up @@ -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" }
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`)
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ pub struct BuilderConfig {
)]
pub max_host_gas_coefficient: Option<u8>,

/// 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,

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod test_utils;
use init4_bin_base::utils::from_env::FromEnv;
// Anonymous import suppresses warnings about unused imports.
use openssl as _;
use signet_bundle as _;
use signet_constants::SignetSystemConstants;
use std::sync::OnceLock;

Expand Down
35 changes: 20 additions & 15 deletions src/tasks/block/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ 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 block_build = BlockBuild::new(
Expand Down Expand Up @@ -227,24 +226,30 @@ 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");

// 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);

let deadline = Instant::now() + Duration::from_secs(remaining);
// 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 = 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(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);
deadline.max(Instant::now())
}
}
2 changes: 1 addition & 1 deletion src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BuiltInConnectionString>()
.map(ProviderConfig::new)
Expand Down Expand Up @@ -54,6 +53,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(),
}
Expand Down