Skip to content
6 changes: 3 additions & 3 deletions crates/astria-bridge-withdrawer/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"./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(())
}
2 changes: 1 addition & 1 deletion crates/astria-bridge-withdrawer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AddrIncoming, IntoMakeService<Router>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use serde::{
Serialize,
};

use crate::withdrawer::ethereum::astria_withdrawer_interface::{
use crate::bridge_withdrawer::ethereum::astria_withdrawer_interface::{
Ics20WithdrawalFilter,
SequencerWithdrawalFilter,
};
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ethers::{
utils::AnvilInstance,
};

use crate::withdrawer::ethereum::{
use crate::bridge_withdrawer::ethereum::{
astria_bridgeable_erc20::{
ASTRIABRIDGEABLEERC20_ABI,
ASTRIABRIDGEABLEERC20_BYTECODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use tracing::{
warn,
};

use crate::withdrawer::{
use crate::bridge_withdrawer::{
batch::Batch,
ethereum::{
astria_withdrawer_interface::IAstriaWithdrawer,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -59,7 +59,7 @@ pub struct Service {
state: Arc<State>,
}

impl Service {
impl BridgeWithdrawer {
/// Instantiates a new `Service`.
///
/// # Errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ use super::{
SequencerStartupInfo,
};
use crate::{
bridge_withdrawer::ethereum::convert::BridgeUnlockMemo,
metrics::Metrics,
withdrawer::ethereum::convert::BridgeUnlockMemo,
};

mod builder;
Expand All @@ -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"))?;
Expand Down Expand Up @@ -174,7 +177,8 @@ impl Submitter {
async fn startup(&mut self) -> eyre::Result<SequencerStartupInfo> {
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"
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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();

Expand Down Expand Up @@ -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<u64> {
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",
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: AsRef<Path>>(path: P) -> eyre::Result<Self> {
let hex = fs::read_to_string(path)?;
let bytes: [u8; 32] = hex::decode(hex.trim())?
pub(crate) fn try_from_path<P: AsRef<Path>>(path: P) -> eyre::Result<Self> {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions crates/astria-bridge-withdrawer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 3 additions & 2 deletions crates/astria-bridge-withdrawer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::process::ExitCode;

use astria_bridge_withdrawer::{
BridgeWithdrawer,
Config,
Service,
BUILD_INFO,
};
use astria_eyre::eyre::WrapErr as _;
Expand Down Expand Up @@ -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();
Expand Down