Skip to content

refactor: migrate to init4-bin-base #93

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

Open
wants to merge 2 commits into
base: main
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
14 changes: 3 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ path = "bin/submit_transaction.rs"
integration = []

[dependencies]
init4-bin-base = "0.3"
init4-bin-base = { version = "0.3.4", features = ["perms"] }

signet-bundle = { git = "https://github.com/init4tech/signet-sdk", branch = "main" }
signet-constants = { git = "https://github.com/init4tech/signet-sdk", branch = "main" }
Expand All @@ -46,24 +46,16 @@ alloy = { version = "0.12.6", features = [
"serde",
] }

aws-config = "1.1.7"
aws-sdk-kms = "1.15.0"

hex = { package = "const-hex", version = "1", default-features = false, features = [
"alloc",
] }

serde = { version = "1.0.197", features = ["derive"] }

axum = "0.7.5"
eyre = "0.6.12"
openssl = { version = "0.10", features = ["vendored"] }
reqwest = { version = "0.11.24", features = ["blocking", "json"] }
serde_json = "1.0"
thiserror = "1.0.68"
tokio = { version = "1.36.0", features = ["full", "macros", "rt-multi-thread"] }

async-trait = "0.1.80"
oauth2 = "4.4.2"
oauth2 = "5"
chrono = "0.4.41"
tokio-stream = "0.1.17"
url = "2.5.4"
13 changes: 3 additions & 10 deletions bin/submit_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use alloy::{
primitives::{Address, U256},
providers::{Provider as _, ProviderBuilder, WalletProvider},
rpc::types::eth::TransactionRequest,
signers::aws::AwsSigner,
};
use builder::config::HostProvider;
use init4_bin_base::{
Expand All @@ -12,7 +11,7 @@ use init4_bin_base::{
tracing,
},
init4,
utils::from_env::FromEnv,
utils::{from_env::FromEnv, signer::LocalOrAwsConfig},
};
use std::time::{Duration, Instant};
use tokio::time::timeout;
Expand All @@ -21,10 +20,7 @@ use tokio::time::timeout;
struct Config {
#[from_env(var = "RPC_URL", desc = "Ethereum RPC URL")]
rpc_url: String,
#[from_env(var = "CHAIN_ID", desc = "Ethereum chain ID")]
chain_id: u64,
#[from_env(var = "AWS_KMS_KEY_ID", desc = "AWS KMS key ID")]
kms_key_id: String,
kms_key_id: LocalOrAwsConfig,
#[from_env(var = "RECIPIENT_ADDRESS", desc = "Recipient address")]
recipient_address: Address,
#[from_env(var = "SLEEP_TIME", desc = "Time to sleep between transactions")]
Expand All @@ -33,10 +29,7 @@ struct Config {

impl Config {
async fn provider(&self) -> HostProvider {
let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
let client = aws_sdk_kms::Client::new(&config);
let signer =
AwsSigner::new(client, self.kms_key_id.clone(), Some(self.chain_id)).await.unwrap();
let signer = self.kms_key_id.connect_remote().await.unwrap();

ProviderBuilder::new()
.wallet(EthereumWallet::from(signer))
Expand Down
48 changes: 15 additions & 33 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use crate::{
quincey::Quincey,
signer::{LocalOrAws, SignerError},
tasks::oauth::{Authenticator, SharedToken},
};
use crate::quincey::Quincey;
use alloy::{
network::{Ethereum, EthereumWallet},
primitives::Address,
Expand All @@ -15,8 +11,14 @@ use alloy::{
},
};
use eyre::Result;
use init4_bin_base::utils::{calc::SlotCalculator, from_env::FromEnv};
use oauth2::url;
use init4_bin_base::{
perms::{Authenticator, OAuthConfig, SharedToken},
utils::{
calc::SlotCalculator,
from_env::FromEnv,
signer::{LocalOrAws, SignerError},
},
};
use signet_zenith::Zenith;
use std::borrow::Cow;

Expand All @@ -41,7 +43,7 @@ pub type HostProvider = FillProvider<

/// Configuration for a builder running a specific rollup on a specific host
/// chain.
#[derive(serde::Deserialize, Debug, Clone, FromEnv)]
#[derive(Debug, Clone, FromEnv)]
pub struct BuilderConfig {
/// The chain ID of the host chain
#[from_env(var = "HOST_CHAIN_ID", desc = "The chain ID of the host chain")]
Expand Down Expand Up @@ -129,30 +131,10 @@ pub struct BuilderConfig {
desc = "Duration in seconds transactions can live in the tx-pool cache"
)]
pub tx_pool_cache_duration: u64,
/// OAuth client ID for the builder.
#[from_env(var = "OAUTH_CLIENT_ID", desc = "OAuth client ID for the builder")]
pub oauth_client_id: String,
/// OAuth client secret for the builder.
#[from_env(var = "OAUTH_CLIENT_SECRET", desc = "OAuth client secret for the builder")]
pub oauth_client_secret: String,
/// OAuth authenticate URL for the builder for performing OAuth logins.
#[from_env(
var = "OAUTH_AUTHENTICATE_URL",
desc = "OAuth authenticate URL for the builder for performing OAuth logins"
)]
pub oauth_authenticate_url: String,
/// OAuth token URL for the builder to get an OAuth2 access token
#[from_env(
var = "OAUTH_TOKEN_URL",
desc = "OAuth token URL for the builder to get an OAuth2 access token"
)]
pub oauth_token_url: String,
/// The oauth token refresh interval in seconds.
#[from_env(
var = "AUTH_TOKEN_REFRESH_INTERVAL",
desc = "The oauth token refresh interval in seconds"
)]
pub oauth_token_refresh_interval: u64,

/// Oauth2 configuration for the builder to connect to ini4 services.
pub oauth: OAuthConfig,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Oauth2 configuration for the builder to connect to ini4 services.
/// Oauth2 configuration for the builder to connect to init4 services.


/// The max number of simultaneous block simulations to run.
#[from_env(
var = "CONCURRENCY_LIMIT",
Expand Down Expand Up @@ -220,7 +202,7 @@ impl BuilderConfig {
static ONCE: std::sync::OnceLock<SharedToken> = std::sync::OnceLock::new();

ONCE.get_or_init(|| {
let authenticator = Authenticator::new(self).unwrap();
let authenticator = Authenticator::new(&self.oauth);
let token = authenticator.token();
authenticator.spawn();
token
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ pub mod quincey;
/// Implements the `/healthcheck` endpoint.
pub mod service;

/// Builder transaction signer.
pub mod signer;

/// Actor-based tasks used to construct a builder.
pub mod tasks;

Expand Down
7 changes: 5 additions & 2 deletions src/quincey.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{signer::LocalOrAws, tasks::oauth::SharedToken};
use alloy::signers::Signer;
use eyre::bail;
use init4_bin_base::deps::tracing::{self, debug, info, instrument, trace};
use init4_bin_base::{
deps::tracing::{self, debug, info, instrument, trace},
perms::SharedToken,
utils::signer::LocalOrAws,
};
use oauth2::TokenResponse;
use reqwest::Client;
use signet_types::{SignRequest, SignResponse};
Expand Down
115 changes: 0 additions & 115 deletions src/signer.rs

This file was deleted.

7 changes: 5 additions & 2 deletions src/tasks/cache/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Bundler service responsible for fetching bundles and sending them to the simulator.
use crate::{config::BuilderConfig, tasks::oauth::SharedToken};
use init4_bin_base::deps::tracing::{Instrument, debug, debug_span, error, trace, warn};
use crate::config::BuilderConfig;
use init4_bin_base::{
deps::tracing::{Instrument, debug, debug_span, error, trace, warn},
perms::SharedToken,
};
use oauth2::TokenResponse;
use reqwest::{Client, Url};
use serde::{Deserialize, Serialize};
Expand Down
3 changes: 0 additions & 3 deletions src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ pub mod cache;
/// Tx submission metric task
pub mod metrics;

/// OAuth token refresh task
pub mod oauth;

/// Tx submission task
pub mod submit;

Expand Down
Loading
Loading