Skip to content

Commit

Permalink
Mock crate separation from binaries (#375)
Browse files Browse the repository at this point in the history
* mock_macro: Add initial.

* mock_macro: Add initialize_database.

* actor: Pilot mock_macro usage.

* mock_macro: Add needed imports for integration tests.

* tests: Use new mock_macro in integration tests.

* mock_macro: Add create_actors.

* mock_macro: Use create_actors everywhere and delete create_actors_grpc.

* mock_macro: Use initialize_database everywhere.

* mock_macro: Use create_test_config_with_thread_name in everywhere.

* test_utils: Rename mock_macro.

* cargo: Delete bin entry of `all_servers`.

* test_utils: Remove create_database and drop_database to add them in initialize_database.

* test_utils: Use get_postgresql_url in initialize_database.

* JsonRPC endpoint removals (#377)

* jsonrpc: Initial remove.

* operator: Remove old rpc test.

* verifier: Convert functions to pub.

* tests: Delete old file.

* cargo: Remove unused features for jsonrpsee.
  • Loading branch information
ceyhunsen authored Dec 16, 2024
1 parent ff43a61 commit 44223f4
Show file tree
Hide file tree
Showing 32 changed files with 1,359 additions and 2,128 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde_json = "1.0.128"
thiserror = "1.0.64"
tracing = { version = "0.1.40", default-features = false }
tracing-subscriber = { version = "0.3.18", features = ["json"] }
jsonrpsee = "0.22.5"
jsonrpsee = { version = "0.22.5", default-features = false }
async-trait = "0.1.83"
clap = "4.5.20"
toml = "0.8.19"
Expand Down
7 changes: 1 addition & 6 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ thiserror = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tokio = { workspace = true, features = ["full"] }
jsonrpsee = { workspace = true, features = ["server", "http-client", "macros"] }
jsonrpsee = { workspace = true, features = ["http-client"] }
async-trait = { workspace = true }
futures = { workspace = true }
clap = { workspace = true, features = ["derive"] }
Expand Down Expand Up @@ -50,11 +50,6 @@ testing = []
name = "server"
path = "src/bin/server.rs"

[[bin]]
name = "all_servers"
path = "src/bin/all_servers.rs"
required-features = ["testing"]

[[bin]]
name = "config_generator"
path = "src/bin/config_generator.rs"
Expand Down
12 changes: 8 additions & 4 deletions core/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,11 @@ impl Actor {
#[cfg(test)]
mod tests {
use super::Actor;
use crate::config::BridgeConfig;
use crate::utils::initialize_logger;
use crate::{
actor::WinternitzDerivationPath, builder::transaction::TxHandler,
mock::database::create_test_config_with_thread_name,
create_test_config_with_thread_name, database::Database, initialize_database,
};
use bitcoin::{
absolute::Height, transaction::Version, Amount, Network, OutPoint, Transaction, TxIn, TxOut,
Expand All @@ -345,7 +347,9 @@ mod tests {
treepp::script,
};
use secp256k1::{rand, Secp256k1, SecretKey};
use std::env;
use std::str::FromStr;
use std::thread;

/// Returns a valid [`TxHandler`].
fn create_valid_mock_tx_handler(actor: &Actor) -> TxHandler {
Expand Down Expand Up @@ -508,7 +512,7 @@ mod tests {

#[tokio::test]
async fn derive_winternitz_pk_uniqueness() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let actor = Actor::new(
config.secret_key,
config.winternitz_secret_key,
Expand All @@ -527,7 +531,7 @@ mod tests {

#[tokio::test]
async fn derive_winternitz_pk_fixed_pk() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let actor = Actor::new(
config.secret_key,
Some(
Expand All @@ -549,7 +553,7 @@ mod tests {

#[tokio::test]
async fn sign_winternitz_signature() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let actor = Actor::new(
config.secret_key,
Some(
Expand Down
52 changes: 0 additions & 52 deletions core/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ use crate::{
clementine_watchtower_client::ClementineWatchtowerClient,
},
},
traits::rpc::AggregatorServer,
utils::handle_taproot_witness_new,
ByteArray32, ByteArray66, EVMAddress, UTXO,
};
use async_trait::async_trait;
use bitcoin::{address::NetworkUnchecked, Address, OutPoint};
use bitcoin::{hashes::Hash, Txid};
use bitcoincore_rpc::RawTx;
Expand Down Expand Up @@ -365,53 +363,3 @@ impl Aggregator {
Ok((move_tx_handler.tx.raw_hex(), txid))
}
}

#[async_trait]
impl AggregatorServer for Aggregator {
async fn aggregate_pub_nonces_rpc(
&self,
pub_nonces: Vec<Vec<MuSigPubNonce>>,
) -> Result<Vec<MuSigAggNonce>, BridgeError> {
self.aggregate_pub_nonces(pub_nonces).await
}

async fn aggregate_slash_or_take_sigs_rpc(
&self,
deposit_outpoint: OutPoint,
kickoff_utxos: Vec<UTXO>,
agg_nonces: Vec<MuSigAggNonce>,
partial_sigs: Vec<Vec<MuSigPartialSignature>>,
) -> Result<Vec<schnorr::Signature>, BridgeError> {
self.aggregate_slash_or_take_sigs(deposit_outpoint, kickoff_utxos, agg_nonces, partial_sigs)
.await
}

async fn aggregate_operator_take_sigs_rpc(
&self,
deposit_outpoint: OutPoint,
kickoff_utxos: Vec<UTXO>,
agg_nonces: Vec<MuSigAggNonce>,
partial_sigs: Vec<Vec<MuSigPartialSignature>>,
) -> Result<Vec<schnorr::Signature>, BridgeError> {
self.aggregate_operator_take_sigs(deposit_outpoint, kickoff_utxos, agg_nonces, partial_sigs)
.await
}

async fn aggregate_move_tx_sigs_rpc(
&self,
deposit_outpoint: OutPoint,
recovery_taproot_address: Address<NetworkUnchecked>,
evm_address: EVMAddress,
agg_nonce: MuSigAggNonce,
partial_sigs: Vec<MuSigPartialSignature>,
) -> Result<(String, Txid), BridgeError> {
self.aggregate_move_tx_sigs(
deposit_outpoint,
recovery_taproot_address,
evm_address,
agg_nonce,
partial_sigs,
)
.await
}
}
49 changes: 0 additions & 49 deletions core/src/bin/all_servers.rs

This file was deleted.

115 changes: 58 additions & 57 deletions core/src/bin/server.rs
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
use clementine_core::servers::create_aggregator_server;
use clementine_core::servers::create_operator_server;
use clementine_core::servers::create_verifier_server;
use clementine_core::utils::get_configuration_for_binaries;
use clementine_core::{database::Database, extended_rpc::ExtendedRpc};
use std::process::exit;
// use clementine_core::servers::create_aggregator_server;
// use clementine_core::servers::create_operator_server;
// use clementine_core::servers::create_verifier_server;
// use clementine_core::utils::get_configuration_for_binaries;
// use clementine_core::{database::Database, extended_rpc::ExtendedRpc};
// use std::process::exit;

#[tokio::main]
async fn main() {
let (mut config, args) = get_configuration_for_binaries();

if !args.verifier_server && !args.operator_server && !args.aggregator_server {
eprintln!("No servers are specified. Please specify one.");
exit(1);
}

let rpc = ExtendedRpc::new(
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
config.bitcoin_rpc_password.clone(),
)
.await;

Database::run_schema_script(&config).await.unwrap();

let mut handles = vec![];

if args.verifier_server {
handles.push(
create_verifier_server(config.clone(), rpc.clone())
.await
.unwrap()
.1
.stopped(),
);
config.port += 1;

println!("Verifier server is started.");
}

if args.operator_server {
handles.push(
create_operator_server(config.clone(), rpc.clone())
.await
.unwrap()
.1
.stopped(),
);
config.port += 1;

println!("Operator server is started.");
}

if args.aggregator_server {
handles.push(create_aggregator_server(config).await.unwrap().1.stopped());

println!("Aggregator server is started.");
}

futures::future::join_all(handles).await;
panic!("grpc switch in progress. please inform us if you get this error.")
// let (mut config, args) = get_configuration_for_binaries();

// if !args.verifier_server && !args.operator_server && !args.aggregator_server {
// eprintln!("No servers are specified. Please specify one.");
// exit(1);
// }

// let rpc = ExtendedRpc::new(
// config.bitcoin_rpc_url.clone(),
// config.bitcoin_rpc_user.clone(),
// config.bitcoin_rpc_password.clone(),
// )
// .await;

// Database::run_schema_script(&config).await.unwrap();

// let mut handles = vec![];

// if args.verifier_server {
// handles.push(
// create_verifier_server(config.clone(), rpc.clone())
// .await
// .unwrap()
// .1
// .stopped(),
// );
// config.port += 1;

// println!("Verifier server is started.");
// }

// if args.operator_server {
// handles.push(
// create_operator_server(config.clone(), rpc.clone())
// .await
// .unwrap()
// .1
// .stopped(),
// );
// config.port += 1;

// println!("Operator server is started.");
// }

// if args.aggregator_server {
// handles.push(create_aggregator_server(config).await.unwrap().1.stopped());

// println!("Aggregator server is started.");
// }

// futures::future::join_all(handles).await;
}
Loading

0 comments on commit 44223f4

Please sign in to comment.