Skip to content

Commit e1f2221

Browse files
authored
refactor: move some utils to utils, remove an rpc call (#110)
refactor: move some utils to utils, remove an rpc call fmt
1 parent afa4447 commit e1f2221

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

bin/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ async fn main() -> eyre::Result<()> {
4343
zenith,
4444
quincey,
4545
config: config.clone(),
46+
constants,
4647
outbound_tx_channel: tx_channel,
4748
host_provider: host_provider.clone(),
4849
};

src/tasks/submit.rs

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
config::{HostProvider, ZenithInstance},
33
quincey::Quincey,
4-
utils::extract_signature_components,
4+
utils::{self, extract_signature_components},
55
};
66
use alloy::{
77
consensus::{Header, SimpleCoder, constants::GWEI_TO_WEI},
@@ -16,15 +16,16 @@ use alloy::{
1616
use eyre::bail;
1717
use init4_bin_base::deps::{
1818
metrics::{counter, histogram},
19-
tracing::{Instrument, debug, debug_span, error, info, instrument, warn},
19+
tracing::{Instrument, debug, debug_span, error, info, instrument, trace, warn},
2020
};
21+
use signet_constants::SignetSystemConstants;
2122
use signet_sim::BuiltBlock;
2223
use signet_types::{SignRequest, SignResponse};
2324
use signet_zenith::{
2425
BundleHelper::{self, BlockHeader, FillPermit2, submitCall},
2526
Zenith::{self, IncorrectHostBlock},
2627
};
27-
use std::time::{Instant, UNIX_EPOCH};
28+
use std::time::Instant;
2829
use tokio::{
2930
sync::mpsc::{self},
3031
task::JoinHandle,
@@ -191,6 +192,8 @@ pub struct SubmitTask {
191192
pub zenith: ZenithInstance,
192193
/// Quincey
193194
pub quincey: Quincey,
195+
/// Constants
196+
pub constants: SignetSystemConstants,
194197
/// Config
195198
pub config: crate::config::BuilderConfig,
196199
/// Channel over which to send pending transactions
@@ -207,16 +210,18 @@ impl SubmitTask {
207210

208211
/// Constructs the signing request from the in-progress block passed to it and assigns the
209212
/// correct height, chain ID, gas limit, and rollup reward address.
210-
#[instrument(skip_all)]
211-
async fn construct_sig_request(&self, contents: &BuiltBlock) -> eyre::Result<SignRequest> {
212-
Ok(SignRequest {
213-
host_block_number: U256::from(self.next_host_block_height().await?),
213+
fn construct_sig_request(&self, contents: &BuiltBlock) -> SignRequest {
214+
let host_block_number =
215+
self.constants.rollup_block_to_host_block_num(contents.block_number());
216+
217+
SignRequest {
218+
host_block_number: U256::from(host_block_number),
214219
host_chain_id: U256::from(self.config.host_chain_id),
215220
ru_chain_id: U256::from(self.config.ru_chain_id),
216221
gas_limit: U256::from(self.config.rollup_block_gas_limit),
217222
ru_reward_address: self.config.builder_rewards_address,
218223
contents: *contents.contents_hash(),
219-
})
224+
}
220225
}
221226

222227
/// Encodes the sidecar and then builds the 4844 blob transaction from the provided header and signature values.
@@ -328,7 +333,7 @@ impl SubmitTask {
328333
debug!(?header.hostBlockNumber, "built rollup block header");
329334

330335
// Extract fills from the built block
331-
let fills = self.extract_fills(block);
336+
let fills = utils::convert_fills(block);
332337
debug!(fill_count = fills.len(), "extracted fills from rollup block");
333338

334339
// Create a blob transaction with the blob header and signature values and return it
@@ -399,11 +404,7 @@ impl SubmitTask {
399404
block: &BuiltBlock,
400405
) -> eyre::Result<ControlFlow> {
401406
info!(retry_count, txns = block.tx_count(), "handling inbound block");
402-
let Ok(sig_request) = self.construct_sig_request(block).await.inspect_err(|e| {
403-
error!(error = %e, "error constructing signature request");
404-
}) else {
405-
return Ok(ControlFlow::Skip);
406-
};
407+
let sig_request = self.construct_sig_request(block);
407408

408409
debug!(
409410
host_block_number = %sig_request.host_block_number,
@@ -493,29 +494,12 @@ impl SubmitTask {
493494

494495
/// Calculates and returns the slot number and its start and end timestamps for the current instant.
495496
fn calculate_slot_window(&self) -> (u64, u64, u64) {
496-
let now_ts = self.now();
497+
let now_ts = utils::now();
497498
let current_slot = self.config.slot_calculator.calculate_slot(now_ts);
498499
let (start, end) = self.config.slot_calculator.calculate_slot_window(current_slot);
499500
(current_slot, start, end)
500501
}
501502

502-
/// Returns the current timestamp in seconds since the UNIX epoch.
503-
fn now(&self) -> u64 {
504-
let now = std::time::SystemTime::now();
505-
now.duration_since(UNIX_EPOCH).unwrap().as_secs()
506-
}
507-
508-
/// Returns the next host block height.
509-
async fn next_host_block_height(&self) -> eyre::Result<u64> {
510-
let block_num = self.provider().get_block_number().await?;
511-
Ok(block_num + 1)
512-
}
513-
514-
// This function converts &[SignedFill] into [FillPermit2]
515-
fn extract_fills(&self, block: &BuiltBlock) -> Vec<FillPermit2> {
516-
block.host_fills().iter().map(FillPermit2::from).collect()
517-
}
518-
519503
/// Task future for the submit task. This function runs the main loop of the task.
520504
async fn task_future(self, mut inbound: mpsc::UnboundedReceiver<SimResult>) {
521505
loop {
@@ -590,7 +574,7 @@ pub fn bump_gas_from_retries(
590574
let max_fee_per_gas = (basefee as u128) * BASE_MULTIPLIER + (priority_fee as u128);
591575
let max_fee_per_blob_gas = blob_basefee * BLOB_MULTIPLIER * (retry_count as u128 + 1);
592576

593-
debug!(
577+
trace!(
594578
retry_count,
595579
max_fee_per_gas, priority_fee, max_fee_per_blob_gas, "calculated bumped gas parameters"
596580
);

src/utils.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
use alloy::primitives::{B256, Signature};
2+
use signet_sim::BuiltBlock;
3+
use signet_zenith::BundleHelper::FillPermit2;
4+
use std::time::UNIX_EPOCH;
5+
6+
/// Returns the current timestamp in seconds since the UNIX epoch.
7+
pub(crate) fn now() -> u64 {
8+
let now = std::time::SystemTime::now();
9+
now.duration_since(UNIX_EPOCH).unwrap().as_secs()
10+
}
11+
12+
// This function converts &[SignedFill] into [FillPermit2]
13+
pub(crate) fn convert_fills(block: &BuiltBlock) -> Vec<FillPermit2> {
14+
block.host_fills().iter().map(FillPermit2::from).collect()
15+
}
216

317
/// Extracts the components of a signature.
418
/// Currently alloy has no function for extracting the components of a signature.

0 commit comments

Comments
 (0)