Skip to content

Commit b5082b8

Browse files
prestwichdylanlott
authored andcommitted
refactor: move some utils to utils, remove an rpc call
1 parent 80ec98c commit b5082b8

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: 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
@@ -2,7 +2,7 @@ use crate::tasks::block::sim::SimResult;
22
use crate::{
33
config::{HostProvider, ZenithInstance},
44
quincey::Quincey,
5-
utils::extract_signature_components,
5+
utils::{self, extract_signature_components},
66
};
77
use alloy::{
88
consensus::{Header, SimpleCoder, constants::GWEI_TO_WEI},
@@ -17,15 +17,16 @@ use alloy::{
1717
use eyre::bail;
1818
use init4_bin_base::deps::{
1919
metrics::{counter, histogram},
20-
tracing::{Instrument, debug, debug_span, error, info, instrument, warn},
20+
tracing::{Instrument, debug, debug_span, error, info, instrument, trace, warn},
2121
};
22+
use signet_constants::SignetSystemConstants;
2223
use signet_sim::BuiltBlock;
2324
use signet_types::{SignRequest, SignResponse};
2425
use signet_zenith::{
2526
BundleHelper::{self, BlockHeader, FillPermit2, submitCall},
2627
Zenith::{self, IncorrectHostBlock},
2728
};
28-
use std::time::{Instant, UNIX_EPOCH};
29+
use std::time::Instant;
2930
use tokio::{
3031
sync::mpsc::{self},
3132
task::JoinHandle,
@@ -190,6 +191,8 @@ pub struct SubmitTask {
190191
pub zenith: ZenithInstance,
191192
/// Quincey
192193
pub quincey: Quincey,
194+
/// Constants
195+
pub constants: SignetSystemConstants,
193196
/// Config
194197
pub config: crate::config::BuilderConfig,
195198
/// Channel over which to send pending transactions
@@ -206,16 +209,18 @@ impl SubmitTask {
206209

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

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

329334
// Extract fills from the built block
330-
let fills = self.extract_fills(block);
335+
let fills = utils::convert_fills(block);
331336
debug!(fill_count = fills.len(), "extracted fills from rollup block");
332337

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

407408
debug!(
408409
host_block_number = %sig_request.host_block_number,
@@ -492,29 +493,12 @@ impl SubmitTask {
492493

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

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

592-
debug!(
576+
trace!(
593577
retry_count,
594578
max_fee_per_gas, priority_fee, max_fee_per_blob_gas, "calculated bumped gas parameters"
595579
);

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)