diff --git a/crates/astria-bridge-withdrawer/build.rs b/crates/astria-bridge-withdrawer/build.rs index 3540920d12..18a400b907 100644 --- a/crates/astria-bridge-withdrawer/build.rs +++ b/crates/astria-bridge-withdrawer/build.rs @@ -12,21 +12,21 @@ fn main() -> Result<(), Box> { "./astria-bridge-contracts/out/IAstriaWithdrawer.sol/IAstriaWithdrawer.json", )? .generate()? - .write_to_file("./src/withdrawer/ethereum/generated/astria_withdrawer_interface.rs")?; + .write_to_file("./src/bridge_withdrawer/ethereum/generated/astria_withdrawer_interface.rs")?; Abigen::new( "AstriaWithdrawer", "./astria-bridge-contracts/out/AstriaWithdrawer.sol/AstriaWithdrawer.json", )? .generate()? - .write_to_file("./src/withdrawer/ethereum/generated/astria_withdrawer.rs")?; + .write_to_file("./src/bridge_withdrawer/ethereum/generated/astria_withdrawer.rs")?; Abigen::new( "AstriaBridgeableERC20", "./astria-bridge-contracts/out/AstriaBridgeableERC20.sol/AstriaBridgeableERC20.json", )? .generate()? - .write_to_file("./src/withdrawer/ethereum/generated/astria_bridgeable_erc20.rs")?; + .write_to_file("./src/bridge_withdrawer/ethereum/generated/astria_bridgeable_erc20.rs")?; Ok(()) } diff --git a/crates/astria-bridge-withdrawer/src/api.rs b/crates/astria-bridge-withdrawer/src/api.rs index 25e7e786f3..81eb2fa13e 100644 --- a/crates/astria-bridge-withdrawer/src/api.rs +++ b/crates/astria-bridge-withdrawer/src/api.rs @@ -21,7 +21,7 @@ use hyper::server::conn::AddrIncoming; use serde::Serialize; use tokio::sync::watch; -use crate::withdrawer::StateSnapshot; +use crate::bridge_withdrawer::StateSnapshot; pub(crate) type ApiServer = axum::Server>; diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/batch.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/batch.rs similarity index 100% rename from crates/astria-bridge-withdrawer/src/withdrawer/batch.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/batch.rs diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/convert.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/convert.rs similarity index 98% rename from crates/astria-bridge-withdrawer/src/withdrawer/ethereum/convert.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/convert.rs index 4743328008..7507ec2e27 100644 --- a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/convert.rs +++ b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/convert.rs @@ -34,7 +34,7 @@ use serde::{ Serialize, }; -use crate::withdrawer::ethereum::astria_withdrawer_interface::{ +use crate::bridge_withdrawer::ethereum::astria_withdrawer_interface::{ Ics20WithdrawalFilter, SequencerWithdrawalFilter, }; @@ -195,7 +195,7 @@ mod tests { use asset::default_native_asset; use super::*; - use crate::withdrawer::ethereum::astria_withdrawer_interface::SequencerWithdrawalFilter; + use crate::bridge_withdrawer::ethereum::astria_withdrawer_interface::SequencerWithdrawalFilter; #[test] fn event_to_bridge_unlock() { diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/generated/astria_bridgeable_erc20.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/generated/astria_bridgeable_erc20.rs similarity index 100% rename from crates/astria-bridge-withdrawer/src/withdrawer/ethereum/generated/astria_bridgeable_erc20.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/generated/astria_bridgeable_erc20.rs diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/generated/astria_withdrawer.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/generated/astria_withdrawer.rs similarity index 100% rename from crates/astria-bridge-withdrawer/src/withdrawer/ethereum/generated/astria_withdrawer.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/generated/astria_withdrawer.rs diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/generated/astria_withdrawer_interface.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/generated/astria_withdrawer_interface.rs similarity index 100% rename from crates/astria-bridge-withdrawer/src/withdrawer/ethereum/generated/astria_withdrawer_interface.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/generated/astria_withdrawer_interface.rs diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/generated/mod.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/generated/mod.rs similarity index 100% rename from crates/astria-bridge-withdrawer/src/withdrawer/ethereum/generated/mod.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/generated/mod.rs diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/mod.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/mod.rs similarity index 100% rename from crates/astria-bridge-withdrawer/src/withdrawer/ethereum/mod.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/mod.rs diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/test_utils.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/test_utils.rs similarity index 99% rename from crates/astria-bridge-withdrawer/src/withdrawer/ethereum/test_utils.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/test_utils.rs index b98bcfbb2a..1e1c3c1962 100644 --- a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/test_utils.rs +++ b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/test_utils.rs @@ -11,7 +11,7 @@ use ethers::{ utils::AnvilInstance, }; -use crate::withdrawer::ethereum::{ +use crate::bridge_withdrawer::ethereum::{ astria_bridgeable_erc20::{ ASTRIABRIDGEABLEERC20_ABI, ASTRIABRIDGEABLEERC20_BYTECODE, diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/watcher.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/watcher.rs similarity index 98% rename from crates/astria-bridge-withdrawer/src/withdrawer/ethereum/watcher.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/watcher.rs index 3c7247e02a..812bec4e32 100644 --- a/crates/astria-bridge-withdrawer/src/withdrawer/ethereum/watcher.rs +++ b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/watcher.rs @@ -42,7 +42,7 @@ use tracing::{ warn, }; -use crate::withdrawer::{ +use crate::bridge_withdrawer::{ batch::Batch, ethereum::{ astria_withdrawer_interface::IAstriaWithdrawer, @@ -118,7 +118,9 @@ pub(crate) struct Watcher { impl Watcher { pub(crate) async fn run(mut self) -> Result<()> { let (provider, contract, fee_asset_id, asset_withdrawal_divisor, next_rollup_block_height) = - self.startup().await?; + self.startup() + .await + .wrap_err("watcher failed to start up")?; let Self { contract_address: _contract_address, @@ -197,7 +199,11 @@ impl Watcher { let SequencerStartupInfo { fee_asset_id, next_batch_rollup_height, - } = self.submitter_handle.recv_startup_info().await?; + } = self + .submitter_handle + .recv_startup_info() + .await + .wrap_err("failed to get sequencer startup info")?; // connect to eth node let retry_config = tryhard::RetryFutureConfig::new(1024) @@ -379,7 +385,7 @@ impl Batcher { block_number: meta.block_number, transaction_hash: meta.transaction_hash, }; - let action = event_to_action(event_with_metadata, self.fee_asset_id, self.rollup_asset_denom.clone(), self.asset_withdrawal_divisor, self.bridge_address)?; + let action = event_to_action(event_with_metadata, self.fee_asset_id, self.rollup_asset_denom.clone(), self.asset_withdrawal_divisor, self.bridge_address).wrap_err("failed to convert event to action")?; if meta.block_number.as_u64() == curr_batch.rollup_height { // block number was the same; add event to current batch @@ -446,7 +452,7 @@ mod tests { use tokio::sync::oneshot; use super::*; - use crate::withdrawer::ethereum::{ + use crate::bridge_withdrawer::ethereum::{ astria_bridgeable_erc20::AstriaBridgeableERC20, astria_withdrawer::AstriaWithdrawer, astria_withdrawer_interface::{ diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/mod.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/mod.rs similarity index 99% rename from crates/astria-bridge-withdrawer/src/withdrawer/mod.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/mod.rs index fd85ce447d..795eefda32 100644 --- a/crates/astria-bridge-withdrawer/src/withdrawer/mod.rs +++ b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/mod.rs @@ -50,7 +50,7 @@ mod ethereum; mod state; mod submitter; -pub struct Service { +pub struct BridgeWithdrawer { // Token to signal all subtasks to shut down gracefully. shutdown_token: CancellationToken, api_server: api::ApiServer, @@ -59,7 +59,7 @@ pub struct Service { state: Arc, } -impl Service { +impl BridgeWithdrawer { /// Instantiates a new `Service`. /// /// # Errors diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/state.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/state.rs similarity index 100% rename from crates/astria-bridge-withdrawer/src/withdrawer/state.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/state.rs diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/submitter/builder.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/builder.rs similarity index 99% rename from crates/astria-bridge-withdrawer/src/withdrawer/submitter/builder.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/builder.rs index 227a34b23f..782f9c4362 100644 --- a/crates/astria-bridge-withdrawer/src/withdrawer/submitter/builder.rs +++ b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/builder.rs @@ -14,11 +14,11 @@ use tracing::info; use super::state::State; use crate::{ - metrics::Metrics, - withdrawer::{ + bridge_withdrawer::{ submitter::Batch, SequencerStartupInfo, }, + metrics::Metrics, }; const BATCH_QUEUE_SIZE: usize = 256; diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/submitter/mod.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/mod.rs similarity index 96% rename from crates/astria-bridge-withdrawer/src/withdrawer/submitter/mod.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/mod.rs index e40beb9192..b1e6fdc3d1 100644 --- a/crates/astria-bridge-withdrawer/src/withdrawer/submitter/mod.rs +++ b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/mod.rs @@ -70,8 +70,8 @@ use super::{ SequencerStartupInfo, }; use crate::{ + bridge_withdrawer::ethereum::convert::BridgeUnlockMemo, metrics::Metrics, - withdrawer::ethereum::convert::BridgeUnlockMemo, }; mod builder; @@ -95,7 +95,10 @@ pub(super) struct Submitter { impl Submitter { pub(super) async fn run(mut self) -> eyre::Result<()> { // call startup - let startup = self.startup().await?; + let startup = self + .startup() + .await + .wrap_err("submitter failed to start up")?; self.startup_tx .send(startup) .map_err(|_startup| eyre!("failed to send startup info to watcher"))?; @@ -174,7 +177,8 @@ impl Submitter { async fn startup(&mut self) -> eyre::Result { let actual_chain_id = get_sequencer_chain_id(self.sequencer_cometbft_client.clone(), self.state.clone()) - .await?; + .await + .wrap_err("failed to get chain id from sequencer")?; ensure!( self.sequencer_chain_id == actual_chain_id.to_string(), "sequencer_chain_id provided in config does not match chain_id returned from sequencer" @@ -183,7 +187,8 @@ impl Submitter { // confirm that the fee asset ID is valid let allowed_fee_asset_ids_resp = get_allowed_fee_asset_ids(self.sequencer_cometbft_client.clone(), self.state.clone()) - .await?; + .await + .wrap_err("failed to get allowed fee asset ids from sequencer")?; ensure!( allowed_fee_asset_ids_resp .fee_asset_ids @@ -197,7 +202,8 @@ impl Submitter { self.state.clone(), self.signer.address, ) - .await?; + .await + .wrap_err("failed to get latest balance")?; let fee_asset_balance = fee_asset_balances .balances .into_iter() @@ -210,7 +216,10 @@ impl Submitter { ); // sync to latest on-chain state - let next_batch_rollup_height = self.get_next_rollup_height().await?; + let next_batch_rollup_height = self + .get_next_rollup_height() + .await + .wrap_err("failed to get next rollup block height")?; self.state.set_submitter_ready(); @@ -242,7 +251,10 @@ impl Submitter { /// 3. The last transaction by the bridge account did not contain a withdrawal action /// 4. The memo of the last transaction by the bridge account could not be parsed async fn get_next_rollup_height(&mut self) -> eyre::Result { - let signed_transaction = self.get_last_transaction().await?; + let signed_transaction = self + .get_last_transaction() + .await + .wrap_err("failed to get the bridge account's last sequencer transaction")?; let next_batch_rollup_height = if let Some(signed_transaction) = signed_transaction { rollup_height_from_signed_transaction(&signed_transaction).wrap_err( "failed to extract rollup height from last transaction by the bridge account", @@ -321,7 +333,8 @@ async fn process_batch( state.clone(), metrics, ) - .await?; + .await + .wrap_err("failed to get nonce from sequencer")?; debug!(nonce, "fetched latest nonce"); let unsigned = UnsignedTransaction { diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/submitter/signer.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/signer.rs similarity index 50% rename from crates/astria-bridge-withdrawer/src/withdrawer/submitter/signer.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/signer.rs index a75e6a5137..ce4cbe1dbd 100644 --- a/crates/astria-bridge-withdrawer/src/withdrawer/submitter/signer.rs +++ b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/signer.rs @@ -13,23 +13,34 @@ use astria_core::{ use astria_eyre::eyre::{ self, eyre, - WrapErr as _, + Context, }; -pub(super) struct SequencerKey { - pub(super) address: Address, - pub(super) signing_key: SigningKey, +pub(crate) struct SequencerKey { + pub(crate) address: Address, + pub(crate) signing_key: SigningKey, } impl SequencerKey { /// Construct a `SequencerKey` from a file. /// /// The file should contain a hex-encoded ed25519 secret key. - pub(super) fn try_from_path>(path: P) -> eyre::Result { - let hex = fs::read_to_string(path)?; - let bytes: [u8; 32] = hex::decode(hex.trim())? + pub(crate) fn try_from_path>(path: P) -> eyre::Result { + let hex = fs::read_to_string(path.as_ref()).wrap_err_with(|| { + format!( + "failed to read sequencer key from path: {}", + path.as_ref().display() + ) + })?; + let bytes: [u8; 32] = hex::decode(hex.trim()) + .wrap_err_with(|| format!("failed to decode hex: {}", path.as_ref().display()))? .try_into() - .map_err(|_| eyre!("invalid private key length; must be 32 bytes"))?; + .map_err(|_| { + eyre!( + "invalid private key length; must be 32 bytes: {}", + path.as_ref().display() + ) + })?; let signing_key = SigningKey::from(bytes); Ok(Self { diff --git a/crates/astria-bridge-withdrawer/src/withdrawer/submitter/tests.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/tests.rs similarity index 99% rename from crates/astria-bridge-withdrawer/src/withdrawer/submitter/tests.rs rename to crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/tests.rs index 9d94048b27..05f177445f 100644 --- a/crates/astria-bridge-withdrawer/src/withdrawer/submitter/tests.rs +++ b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/submitter/tests.rs @@ -82,13 +82,13 @@ use wiremock::{ use super::Submitter; use crate::{ - metrics::Metrics, - withdrawer::{ + bridge_withdrawer::{ batch::Batch, ethereum::convert::BridgeUnlockMemo, state, submitter, }, + metrics::Metrics, }; const SEQUENCER_CHAIN_ID: &str = "test_sequencer-1000"; diff --git a/crates/astria-bridge-withdrawer/src/lib.rs b/crates/astria-bridge-withdrawer/src/lib.rs index a2af44ab9e..8ce4dae86e 100644 --- a/crates/astria-bridge-withdrawer/src/lib.rs +++ b/crates/astria-bridge-withdrawer/src/lib.rs @@ -1,11 +1,11 @@ pub(crate) mod api; +pub mod bridge_withdrawer; mod build_info; pub(crate) mod config; pub(crate) mod metrics; -pub mod withdrawer; +#[cfg(test)] +pub(crate) use bridge_withdrawer::astria_address; +pub use bridge_withdrawer::BridgeWithdrawer; pub use build_info::BUILD_INFO; pub use config::Config; -#[cfg(test)] -pub(crate) use withdrawer::astria_address; -pub use withdrawer::Service; diff --git a/crates/astria-bridge-withdrawer/src/main.rs b/crates/astria-bridge-withdrawer/src/main.rs index a3b87a36df..60b61e286b 100644 --- a/crates/astria-bridge-withdrawer/src/main.rs +++ b/crates/astria-bridge-withdrawer/src/main.rs @@ -1,8 +1,8 @@ use std::process::ExitCode; use astria_bridge_withdrawer::{ + BridgeWithdrawer, Config, - Service, BUILD_INFO, }; use astria_eyre::eyre::WrapErr as _; @@ -52,7 +52,8 @@ async fn main() -> ExitCode { let mut sigterm = signal(SignalKind::terminate()) .expect("setting a SIGTERM listener should always work on Unix"); - let (withdrawer, shutdown_handle) = Service::new(cfg).expect("could not initialize withdrawer"); + let (withdrawer, shutdown_handle) = + BridgeWithdrawer::new(cfg).expect("could not initialize withdrawer"); let withdrawer_handle = tokio::spawn(withdrawer.run()); let shutdown_token = shutdown_handle.token();