From ed3ff17ad8138153ea37b1468043aab17ef49483 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 13 Jun 2025 09:29:08 -0400 Subject: [PATCH 1/2] refactor: move some utils to utils, remove an rpc call --- bin/builder.rs | 1 + src/tasks/submit.rs | 50 +++++++++++++++------------------------------ src/utils.rs | 14 +++++++++++++ 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/bin/builder.rs b/bin/builder.rs index 65509ba..6cd2672 100644 --- a/bin/builder.rs +++ b/bin/builder.rs @@ -43,6 +43,7 @@ async fn main() -> eyre::Result<()> { zenith, quincey, config: config.clone(), + constants: constants, outbound_tx_channel: tx_channel, host_provider: host_provider.clone(), }; diff --git a/src/tasks/submit.rs b/src/tasks/submit.rs index 5eb92d7..c427b5a 100644 --- a/src/tasks/submit.rs +++ b/src/tasks/submit.rs @@ -1,7 +1,7 @@ use crate::{ config::{HostProvider, ZenithInstance}, quincey::Quincey, - utils::extract_signature_components, + utils::{self, extract_signature_components}, }; use alloy::{ consensus::{Header, SimpleCoder, constants::GWEI_TO_WEI}, @@ -16,15 +16,16 @@ use alloy::{ use eyre::bail; use init4_bin_base::deps::{ metrics::{counter, histogram}, - tracing::{Instrument, debug, debug_span, error, info, instrument, warn}, + tracing::{Instrument, debug, debug_span, error, info, instrument, trace, warn}, }; +use signet_constants::SignetSystemConstants; use signet_sim::BuiltBlock; use signet_types::{SignRequest, SignResponse}; use signet_zenith::{ BundleHelper::{self, BlockHeader, FillPermit2, submitCall}, Zenith::{self, IncorrectHostBlock}, }; -use std::time::{Instant, UNIX_EPOCH}; +use std::time::Instant; use tokio::{ sync::mpsc::{self}, task::JoinHandle, @@ -191,6 +192,8 @@ pub struct SubmitTask { pub zenith: ZenithInstance, /// Quincey pub quincey: Quincey, + /// Constants + pub constants: SignetSystemConstants, /// Config pub config: crate::config::BuilderConfig, /// Channel over which to send pending transactions @@ -207,16 +210,18 @@ impl SubmitTask { /// Constructs the signing request from the in-progress block passed to it and assigns the /// correct height, chain ID, gas limit, and rollup reward address. - #[instrument(skip_all)] - async fn construct_sig_request(&self, contents: &BuiltBlock) -> eyre::Result { - Ok(SignRequest { - host_block_number: U256::from(self.next_host_block_height().await?), + fn construct_sig_request(&self, contents: &BuiltBlock) -> SignRequest { + let host_block_number = + self.constants.rollup_block_to_host_block_num(contents.block_number()); + + SignRequest { + host_block_number: U256::from(host_block_number), host_chain_id: U256::from(self.config.host_chain_id), ru_chain_id: U256::from(self.config.ru_chain_id), gas_limit: U256::from(self.config.rollup_block_gas_limit), ru_reward_address: self.config.builder_rewards_address, contents: *contents.contents_hash(), - }) + } } /// Encodes the sidecar and then builds the 4844 blob transaction from the provided header and signature values. @@ -328,7 +333,7 @@ impl SubmitTask { debug!(?header.hostBlockNumber, "built rollup block header"); // Extract fills from the built block - let fills = self.extract_fills(block); + let fills = utils::convert_fills(block); debug!(fill_count = fills.len(), "extracted fills from rollup block"); // Create a blob transaction with the blob header and signature values and return it @@ -399,11 +404,7 @@ impl SubmitTask { block: &BuiltBlock, ) -> eyre::Result { info!(retry_count, txns = block.tx_count(), "handling inbound block"); - let Ok(sig_request) = self.construct_sig_request(block).await.inspect_err(|e| { - error!(error = %e, "error constructing signature request"); - }) else { - return Ok(ControlFlow::Skip); - }; + let sig_request = self.construct_sig_request(block); debug!( host_block_number = %sig_request.host_block_number, @@ -493,29 +494,12 @@ impl SubmitTask { /// Calculates and returns the slot number and its start and end timestamps for the current instant. fn calculate_slot_window(&self) -> (u64, u64, u64) { - let now_ts = self.now(); + let now_ts = utils::now(); let current_slot = self.config.slot_calculator.calculate_slot(now_ts); let (start, end) = self.config.slot_calculator.calculate_slot_window(current_slot); (current_slot, start, end) } - /// Returns the current timestamp in seconds since the UNIX epoch. - fn now(&self) -> u64 { - let now = std::time::SystemTime::now(); - now.duration_since(UNIX_EPOCH).unwrap().as_secs() - } - - /// Returns the next host block height. - async fn next_host_block_height(&self) -> eyre::Result { - let block_num = self.provider().get_block_number().await?; - Ok(block_num + 1) - } - - // This function converts &[SignedFill] into [FillPermit2] - fn extract_fills(&self, block: &BuiltBlock) -> Vec { - block.host_fills().iter().map(FillPermit2::from).collect() - } - /// Task future for the submit task. This function runs the main loop of the task. async fn task_future(self, mut inbound: mpsc::UnboundedReceiver) { loop { @@ -590,7 +574,7 @@ pub fn bump_gas_from_retries( let max_fee_per_gas = (basefee as u128) * BASE_MULTIPLIER + (priority_fee as u128); let max_fee_per_blob_gas = blob_basefee * BLOB_MULTIPLIER * (retry_count as u128 + 1); - debug!( + trace!( retry_count, max_fee_per_gas, priority_fee, max_fee_per_blob_gas, "calculated bumped gas parameters" ); diff --git a/src/utils.rs b/src/utils.rs index 9c034f0..211da62 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,18 @@ use alloy::primitives::{B256, Signature}; +use signet_sim::BuiltBlock; +use signet_zenith::BundleHelper::FillPermit2; +use std::time::UNIX_EPOCH; + +/// Returns the current timestamp in seconds since the UNIX epoch. +pub(crate) fn now() -> u64 { + let now = std::time::SystemTime::now(); + now.duration_since(UNIX_EPOCH).unwrap().as_secs() +} + +// This function converts &[SignedFill] into [FillPermit2] +pub(crate) fn convert_fills(block: &BuiltBlock) -> Vec { + block.host_fills().iter().map(FillPermit2::from).collect() +} /// Extracts the components of a signature. /// Currently alloy has no function for extracting the components of a signature. From da4dd5734e5893da9cba7a2466c3233ea62a3e0b Mon Sep 17 00:00:00 2001 From: dylan Date: Fri, 13 Jun 2025 18:21:45 -0600 Subject: [PATCH 2/2] fmt --- bin/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/builder.rs b/bin/builder.rs index 6cd2672..b399b52 100644 --- a/bin/builder.rs +++ b/bin/builder.rs @@ -43,7 +43,7 @@ async fn main() -> eyre::Result<()> { zenith, quincey, config: config.clone(), - constants: constants, + constants, outbound_tx_channel: tx_channel, host_provider: host_provider.clone(), };