8000 refactor: move some utils to utils, remove an rpc call by Evalir · Pull Request #110 · init4tech/builder · GitHub
[go: up one dir, main page]

Skip to content

refactor: move some utils to utils, remove an rpc call #110

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

Merged
merged 2 commits into from
Jun 16, 2025
Merged
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 bin/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async fn main() -> eyre::Result<()> {
zenith,
quincey,
config: config.clone(),
constants,
outbound_tx_channel: tx_channel,
host_provider: host_provider.clone(),
};
Expand Down
50 changes: 17 additions & 33 deletions src/tasks/submit.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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<SignRequest> {
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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -399,11 +404,7 @@ impl SubmitTask {
block: &BuiltBlock,
) -> eyre::Result<ControlFlow> {
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,
Expand Down Expand Up @@ -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<u64> {
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<FillPermit2> {
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<SimResult>) {
loop {
Expand Down Expand Up @@ -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"
);
Expand Down
14 changes: 14 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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<FillPermit2> {
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.
Expand Down
0