Skip to content

Commit 6a2e518

Browse files
committed
refactor(bridge): improve types/traits
This is based on the discussion in PR [#230](#230)
1 parent 2b17614 commit 6a2e518

File tree

22 files changed

+160
-491
lines changed

22 files changed

+160
-491
lines changed

bin/bridge-client/src/main.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
//! publishing appropriate transactions. Can also perform challenger duties.
55
66
mod args;
7+
pub(crate) mod constants;
78
mod modes;
9+
pub(crate) mod rpc_server;
810

911
use alpen_express_common::logging;
1012
use args::{Args, ModeOfOperation};
@@ -20,11 +22,14 @@ async fn main() {
2022

2123
info!("running bridge client in {} mode", cli_args.mode);
2224

23-
if let ModeOfOperation::Operator = cli_args.mode {
24-
operator::bootstrap()
25-
.await
26-
.expect("bootstrap operator node");
27-
} else {
28-
challenger::bootstrap().await;
25+
match cli_args.mode {
26+
ModeOfOperation::Operator => {
27+
operator::bootstrap()
28+
.await
29+
.expect("bootstrap operator node");
30+
}
31+
ModeOfOperation::Challenger => {
32+
challenger::bootstrap().await;
33+
}
2934
}
3035
}

bin/bridge-client/src/modes/operator/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Defines the main loop for the bridge-client in operator mode.
2-
mod constants;
3-
mod rpc_server;
42
5-
use rpc_server::BridgeRpcImpl;
3+
use crate::rpc_server::{self, BridgeRpcImpl};
64

75
/// Bootstraps the bridge client in Operator mode by hooking up all the required auxiliary services
86
/// including database, rpc server, etc. Threadpool and logging need to be initialized at the call

bin/bridge-client/src/modes/operator/rpc_server.rs renamed to bin/bridge-client/src/rpc_server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use jsonrpsee::{core::RpcResult, RpcModule};
66
use tokio::sync::oneshot;
77
use tracing::{info, warn};
88

9-
use super::constants::{RPC_PORT, RPC_SERVER};
109
use express_bridge_rpc_api::{ExpressBridgeControlApiServer, ExpressBridgeNetworkApiServer};
1110

11+
use crate::constants::{RPC_PORT, RPC_SERVER};
12+
1213
pub(crate) async fn start<T>(rpc_impl: &T) -> anyhow::Result<()>
1314
where
1415
T: ExpressBridgeControlApiServer + ExpressBridgeNetworkApiServer + Clone,

crates/bridge-exec/src/book_keeping/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
55
pub mod checkpoint;
66
pub mod errors;
7-
pub mod report_status;

crates/bridge-exec/src/book_keeping/report_status.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

crates/bridge-exec/src/config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct AddressConfig {
3939

4040
impl Config {
4141
/// Parse the config at the given path and produce the [`Config`].
42-
pub fn from_path(path: &PathBuf) -> ParseConfigResult<Self> {
42+
pub fn load_from_path(path: &PathBuf) -> InitResult<Self> {
4343
let contents = fs::read_to_string(path)?;
4444
let config = toml::from_str::<Config>(contents.as_str())
4545
.map_err(|e| SerdeError::new(contents, e))?;
@@ -59,9 +59,10 @@ pub struct SecretsConfig {
5959
pub_key: PathBuf,
6060
}
6161

62-
/// Error with the configuration.
62+
/// Error during initialization.
63+
// TODO: move this out to a dedicated module or `bin`.
6364
#[derive(Debug, Error)]
64-
pub enum ConfigError {
65+
pub enum InitError {
6566
/// I/O related error while reading config.
6667
#[error("error loading config file: {0}")]
6768
Io(#[from] io::Error),
@@ -72,4 +73,4 @@ pub enum ConfigError {
7273
}
7374

7475
/// Result of parsing the config file which may produce a [`ConfigError`].
75-
pub type ParseConfigResult<T> = Result<T, ConfigError>;
76+
pub type InitResult<T> = Result<T, InitError>;

crates/bridge-exec/src/deposit_handler/handler.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
//! Defines the traits that encapsulates all functionalities that pertain to handling a deposit.
22
3+
use std::sync::Arc;
4+
35
use async_trait::async_trait;
46
use bitcoin::secp256k1::schnorr::Signature;
57

6-
use express_bridge_txm::{DepositInfo, DepositRequest, SignatureInfo};
8+
use alpen_express_rpc_api::AlpenBridgeApiClient;
9+
use express_bridge_txm::{DepositInfo, DepositRequest, Signed, Unsigned};
710

8-
use crate::book_keeping::{checkpoint::ManageCheckpoint, report_status::ReportStatus};
11+
use crate::book_keeping::checkpoint::ManageCheckpoint;
912

1013
use super::errors::DepositExecResult;
1114

15+
/// Holds the context and methods to handle deposit processing.
16+
#[derive(Debug, Clone)]
17+
pub struct DepositHandler<Api: AlpenBridgeApiClient> {
18+
/// The RPC client to communicate with the rollup node for broadcasting messages.
19+
pub rpc_client: Arc<Api>,
20+
// add other useful sfuff such as a database handle.
21+
}
22+
1223
/// Defines the ability to process deposits.
1324
#[async_trait]
14-
pub trait HandleDeposit: ManageCheckpoint + ReportStatus + Clone + Send + Sync + Sized {
25+
pub trait HandleDeposit: ManageCheckpoint + Clone + Send + Sync + Sized {
1526
/// Construct and sign the deposit transaction.
16-
async fn sign_deposit_tx(&self, deposit_info: &DepositInfo)
17-
-> DepositExecResult<SignatureInfo>;
27+
async fn sign_deposit_tx(
28+
&self,
29+
deposit_request: &DepositRequest<Unsigned>,
30+
) -> DepositExecResult<DepositRequest<Signed>>;
1831

1932
/// Add the signature to the already accumulated set of signatures for a deposit transaction and
2033
/// produce the aggregated signature if all operators have signed. Also update the database
2134
/// entry with the signatures accumulated so far.
2235
async fn aggregate_signature(
2336
&self,
24-
deposit_request: &DepositRequest,
37+
deposit_request: &DepositRequest<Signed>,
2538
) -> DepositExecResult<Option<Signature>>;
2639

2740
/// Broadcast the signature to the rest of the bridge operator clients.
2841
async fn broadcast_partial_deposit_sig(
2942
&self,
30-
deposit_info: &DepositInfo,
31-
sig: &SignatureInfo,
43+
deposit_request: &DepositRequest<Signed>,
3244
) -> DepositExecResult<()>;
3345

3446
/// Broadcast the fully signed deposit transaction to the bitcoin p2p (via a full node).

crates/bridge-exec/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ pub mod book_keeping;
77
pub mod challenger;
88
pub mod config;
99
pub mod deposit_handler;
10-
pub mod operator;
1110
pub mod withdrawal_handler;

crates/bridge-exec/src/operator/errors.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)