Skip to content
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

chore: updates builder to use signet-sdk #62

Open
wants to merge 6 commits into
base: 03-16-updates_bundler_to_streaming_actor_pattern
Choose a base branch
from
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
20 changes: 15 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ name = "transaction-submitter"
path = "bin/submit_transaction.rs"

[dependencies]
init4-bin-base = "0.1.0"

zenith-types = "0.13"

alloy = { version = "0.7.3", features = ["full", "json-rpc", "signer-aws", "rpc-types-mev", "rlp"] }
init4-bin-base = { git = "https://github.com/init4tech/bin-base.git" }

signet-bundle = { git = "https://github.com/init4tech/signet-sdk", branch = "main" }
signet-types = { git = "https://github.com/init4tech/signet-sdk", branch = "main" }
signet-zenith = { git = "https://github.com/init4tech/signet-sdk", branch = "main" }

alloy = { version = "0.12.6", features = [
"full",
"json-rpc",
"signer-aws",
"rpc-types-mev",
"rlp",
"node-bindings",
"serde",
] }

aws-config = "1.1.7"
aws-sdk-kms = "1.15.0"
Expand Down
3 changes: 1 addition & 2 deletions bin/submit_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ async fn connect_from_config() -> (Provider, Address, u64) {
let signer = AwsSigner::new(client, kms_key_id.to_string(), Some(chain_id)).await.unwrap();

let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(EthereumWallet::from(signer))
.on_builtin(&rpc_url)
.connect(&rpc_url)
.await
.unwrap();

Expand Down
48 changes: 24 additions & 24 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use alloy::{
WalletFiller,
},
},
transports::BoxTransport,
};
use signet_zenith::Zenith;
use std::{borrow::Cow, env, num, str::FromStr};
use zenith_types::Zenith;

// Keys for .env variables that need to be set to configure the builder.
const HOST_CHAIN_ID: &str = "HOST_CHAIN_ID";
Expand Down Expand Up @@ -125,7 +124,7 @@ impl ConfigError {
}
}

/// Provider type used to read & write.
/// Type alias for the provider used in the builder.
pub type Provider = FillProvider<
JoinFill<
JoinFill<
Expand All @@ -134,26 +133,22 @@ pub type Provider = FillProvider<
>,
WalletFiller<EthereumWallet>,
>,
RootProvider<BoxTransport>,
BoxTransport,
RootProvider,
Ethereum,
>;

/// Provider type used to read-only.
/// Type alias for the provider used in the builder, without a wallet.
pub type WalletlessProvider = FillProvider<
JoinFill<
Identity,
JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>,
>,
RootProvider<BoxTransport>,
BoxTransport,
RootProvider,
Ethereum,
>;

/// A Zenith contract instance, using some provider `P` (defaults to
/// [`Provider`]).
pub type ZenithInstance<P = Provider> =
Zenith::ZenithInstance<BoxTransport, P, alloy::network::Ethereum>;
/// A [`Zenith`] contract instance using [`Provider`] as the provider.
pub type ZenithInstance<P = Provider> = Zenith::ZenithInstance<(), P, alloy::network::Ethereum>;

impl BuilderConfig {
/// Load the builder configuration from environment variables.
Expand Down Expand Up @@ -210,32 +205,36 @@ impl BuilderConfig {

/// Connect to the Rollup rpc provider.
pub async fn connect_ru_provider(&self) -> Result<WalletlessProvider, ConfigError> {
ProviderBuilder::new()
.with_recommended_fillers()
.on_builtin(&self.ru_rpc_url)
let provider = ProviderBuilder::new()
.connect(&self.ru_rpc_url)
.await
.map_err(Into::into)
.map_err(ConfigError::Provider)?;

Ok(provider)
}

/// Connect to the Host rpc provider.
pub async fn connect_host_provider(&self) -> Result<Provider, ConfigError> {
let builder_signer = self.connect_builder_signer().await?;
ProviderBuilder::new()
.with_recommended_fillers()
let provider = ProviderBuilder::new()
.wallet(EthereumWallet::from(builder_signer))
.on_builtin(&self.host_rpc_url)
.connect(&self.host_rpc_url)
.await
.map_err(Into::into)
.map_err(ConfigError::Provider)?;

Ok(provider)
}

/// Connect additional broadcast providers.
pub async fn connect_additional_broadcast(
&self,
) -> Result<Vec<RootProvider<BoxTransport>>, ConfigError> {
let mut providers = Vec::with_capacity(self.tx_broadcast_urls.len());
) -> Result<Vec<WalletlessProvider>, ConfigError> {
let mut providers: Vec<WalletlessProvider> =
Vec::with_capacity(self.tx_broadcast_urls.len());
for url in self.tx_broadcast_urls.iter() {
let provider =
ProviderBuilder::new().on_builtin(url).await.map_err(Into::<ConfigError>::into)?;
ProviderBuilder::new().connect(url).await.map_err(ConfigError::Provider)?;

providers.push(provider);
}
Ok(providers)
Expand Down Expand Up @@ -278,5 +277,6 @@ pub fn load_url(key: &str) -> Result<Cow<'static, str>, ConfigError> {
/// Load an address from an environment variable.
pub fn load_address(key: &str) -> Result<Address, ConfigError> {
let address = load_string(key)?;
Address::from_str(&address).map_err(Into::into)
Address::from_str(&address)
.map_err(|_| ConfigError::Var(format!("Invalid address format for {}", key)))
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ pub mod tasks;
/// Utilities.
pub mod utils;

// Anonymous import suppresses warnings about unused imports.
use openssl as _;
11 changes: 6 additions & 5 deletions src/tasks/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ use super::oauth::Authenticator;
use super::tx_poller::TxPoller;
use crate::config::{BuilderConfig, WalletlessProvider};
use alloy::{
consensus::{SidecarBuilder, SidecarCoder, TxEnvelope},
consensus::{SidecarBuilder, SidecarCoder, transaction::TxEnvelope},
eips::eip2718::Decodable2718,
primitives::{B256, Bytes, keccak256},
providers::Provider as _,
rlp::Buf,
};
use signet_bundle::SignetEthBundle;
use signet_zenith::{Alloy2718Coder, encode_txns};
use std::time::{SystemTime, UNIX_EPOCH};
use std::{sync::OnceLock, time::Duration};
use tokio::{sync::mpsc, task::JoinHandle};
use tracing::{Instrument, debug, error, info, trace};
use zenith_types::{Alloy2718Coder, ZenithEthBundle, encode_txns};

/// Ethereum's slot time in seconds.
pub const ETHEREUM_SLOT_TIME: u64 = 12;
Expand Down Expand Up @@ -183,7 +184,7 @@ impl BlockBuilder {
}

/// Simulates a Zenith bundle against the rollup state
async fn simulate_bundle(&mut self, bundle: &ZenithEthBundle) -> eyre::Result<()> {
async fn simulate_bundle(&mut self, bundle: &SignetEthBundle) -> eyre::Result<()> {
// TODO: Simulate bundles with the Simulation Engine
// [ENG-672](https://linear.app/initiates/issue/ENG-672/add-support-for-bundles)
debug!(hash = ?bundle.bundle.bundle_hash(), block_number = ?bundle.block_number(), "bundle simulations is not implemented yet - skipping simulation");
Expand Down Expand Up @@ -269,7 +270,7 @@ mod tests {
rpc::types::{TransactionRequest, mev::EthSendBundle},
signers::local::PrivateKeySigner,
};
use zenith_types::ZenithEthBundle;
use signet_bundle::SignetEthBundle;

/// Create a mock bundle for testing with a single transaction
async fn create_mock_bundle(wallet: &EthereumWallet) -> Bundle {
Expand All @@ -294,7 +295,7 @@ mod tests {
replacement_uuid: Some("replacement_uuid".to_owned()),
};

let zenith_bundle = ZenithEthBundle { bundle: eth_bundle, host_fills: None };
let zenith_bundle = SignetEthBundle { bundle: eth_bundle, host_fills: None };

Bundle { id: "mock_bundle".to_owned(), bundle: zenith_bundle }
}
Expand Down
5 changes: 2 additions & 3 deletions src/tasks/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel};
use tokio::task::JoinHandle;
use tokio::time;
use tracing::{Instrument, debug, trace};
use zenith_types::ZenithEthBundle;

use signet_bundle::SignetEthBundle;
/// Holds a bundle from the cache with a unique ID and a Zenith bundle.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Bundle {
/// Cache identifier for the bundle
pub id: String,
/// The Zenith bundle for this bundle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: update comment Zenith bundle -> Signet bundle ?

pub bundle: ZenithEthBundle,
pub bundle: SignetEthBundle,
}

/// Response from the tx-pool containing a list of bundles.
Expand Down
16 changes: 8 additions & 8 deletions src/tasks/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ use alloy::{
use eyre::{bail, eyre};
use init4_bin_base::deps::metrics::{counter, histogram};
use oauth2::TokenResponse;
use signet_types::{SignRequest, SignResponse};
use signet_zenith::{
BundleHelper::{self, BlockHeader, FillPermit2, submitCall},
Zenith::IncorrectHostBlock,
};
use std::time::Instant;
use tokio::{sync::mpsc, task::JoinHandle};
use tracing::{debug, error, instrument, trace};
use zenith_types::{
BundleHelper::{self, FillPermit2},
SignRequest, SignResponse,
Zenith::IncorrectHostBlock,
};

macro_rules! spawn_provider_send {
($provider:expr, $tx:expr) => {
Expand Down Expand Up @@ -127,7 +127,7 @@ impl SubmitTask {
s: FixedBytes<32>,
in_progress: &InProgressBlock,
) -> eyre::Result<TransactionRequest> {
let data = zenith_types::BundleHelper::submitCall { fills, header, v, r, s }.abi_encode();
let data = submitCall { fills, header, v, r, s }.abi_encode();

let sidecar = in_progress.encode_blob::<SimpleCoder>().build()?;
Ok(TransactionRequest::default()
Expand All @@ -151,7 +151,7 @@ impl SubmitTask {
) -> eyre::Result<ControlFlow> {
let (v, r, s) = extract_signature_components(&resp.sig);

let header = zenith_types::BundleHelper::BlockHeader {
let header = BlockHeader {
hostBlockNumber: resp.req.host_block_number,
rollupChainId: U256::from(self.config.ru_chain_id),
gasLimit: resp.req.gas_limit,
Expand All @@ -167,7 +167,7 @@ impl SubmitTask {
.with_gas_limit(1_000_000);

if let Err(TransportError::ErrorResp(e)) =
self.host_provider.call(&tx).block(BlockNumberOrTag::Pending.into()).await
self.host_provider.call(tx.clone()).block(BlockNumberOrTag::Pending.into()).await
{
error!(
code = e.code,
Expand Down
Loading