Skip to content

Commit e40c098

Browse files
committed
refactor!: extract mpc into a separate crate
1 parent 2375c17 commit e40c098

42 files changed

Lines changed: 748 additions & 529 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/e2e-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2024"
55

66
[dependencies]
77
hashi = { path = "../hashi" }
8+
mpc = { path = "../mpc" }
89
hashi-screener = { path = "../hashi-screener", features = ["test-utils"] }
910
hashi-types = { path = "../hashi-types" }
1011

crates/e2e-tests/src/lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ mod tests {
655655
mgr.committee.clone()
656656
};
657657
let (refill_tx, _) = tokio::sync::watch::channel(0u32);
658-
let signing_manager = hashi::mpc::SigningManager::new(
658+
let signing_manager = mpc::SigningManager::new(
659659
info.address,
660660
committee,
661661
t,
@@ -679,9 +679,8 @@ mod tests {
679679
epoch: u64,
680680
sui_request_id: sui_sdk_types::Address,
681681
global_presig_index: u64,
682-
) -> Vec<
683-
hashi::mpc::types::SigningResult<fastcrypto::groups::secp256k1::schnorr::SchnorrSignature>,
684-
> {
682+
) -> Vec<mpc::types::SigningResult<fastcrypto::groups::secp256k1::schnorr::SchnorrSignature>>
683+
{
685684
let beacon_value = S::rand(&mut rand::thread_rng());
686685
let sign_futures: Vec<_> = nodes
687686
.iter()
@@ -691,7 +690,7 @@ mod tests {
691690
.signing_manager_for(epoch)
692691
.unwrap_or_else(|| panic!("SigningManager not initialized for epoch {epoch}"));
693692
let onchain_state = node.hashi().onchain_state().clone();
694-
let p2p_channel = hashi::mpc::rpc::RpcP2PChannel::new(
693+
let p2p_channel = hashi::mpc_p2p_channel::RpcP2PChannel::new(
695694
onchain_state,
696695
epoch,
697696
hashi::metrics::MPC_LABEL_SIGNING,
@@ -709,7 +708,7 @@ mod tests {
709708
&beacon,
710709
None,
711710
SIGNING_TIMEOUT,
712-
&metrics,
711+
&metrics.mpc,
713712
)
714713
.await
715714
}
@@ -720,9 +719,7 @@ mod tests {
720719

721720
fn assert_all_signatures_match(
722721
results: Vec<
723-
hashi::mpc::types::SigningResult<
724-
fastcrypto::groups::secp256k1::schnorr::SchnorrSignature,
725-
>,
722+
mpc::types::SigningResult<fastcrypto::groups::secp256k1::schnorr::SchnorrSignature>,
726723
>,
727724
) {
728725
let mut signatures = Vec::new();

crates/hashi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ sui-transaction-builder.workspace = true
1212
sui-futures = { workspace = true }
1313

1414
hashi-types = { path = "../hashi-types" }
15+
mpc = { path = "../mpc" }
1516

1617
# Bitcoin dependencies
1718
bitcoin.workspace = true

crates/hashi/src/constants.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ pub const BITCOIN_SIGNET_CHAIN_ID: &str =
1919
pub const BITCOIN_REGTEST_CHAIN_ID: &str =
2020
"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206";
2121

22-
/// Trigger presignature refill when remaining presignatures drop to
23-
/// `initial_pool_size / PRESIG_REFILL_DIVISOR`.
24-
pub const PRESIG_REFILL_DIVISOR: usize = 2;
22+
pub use mpc::constants::PRESIG_REFILL_DIVISOR;
2523

2624
pub fn is_production_sui_chain(chain_id: &str) -> bool {
2725
chain_id == SUI_MAINNET_CHAIN_ID || chain_id == SUI_TESTNET_CHAIN_ID

crates/hashi/src/db.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use hashi_types::committee::EncryptionPrivateKey;
1818

1919
use serde::de::DeserializeOwned;
2020

21-
use crate::mpc::types::RotationMessages;
21+
use mpc::types::RotationMessages;
2222

2323
pub struct Database {
2424
db: fjall::Database,
@@ -442,13 +442,13 @@ fn prune_keyspace(keyspace: &Keyspace, cutoff_epoch: u64) -> Result<()> {
442442

443443
#[cfg(test)]
444444
mod tests {
445-
use crate::mpc::EncryptionGroupElement;
446445
use fastcrypto_tbls::nodes::Node;
447446
use fastcrypto_tbls::nodes::Nodes;
448447
use fastcrypto_tbls::threshold_schnorr::avss;
449448
use fastcrypto_tbls::threshold_schnorr::batch_avss;
450449
use hashi_types::committee::EncryptionPrivateKey;
451450
use hashi_types::committee::EncryptionPublicKey;
451+
use mpc::EncryptionGroupElement;
452452
use sui_sdk_types::Address;
453453

454454
use super::Database;
@@ -1069,7 +1069,7 @@ mod tests {
10691069
#[test]
10701070
fn test_epoch_store_writes_at_explicit_epoch_not_self_epoch() {
10711071
use crate::storage::EpochPublicMessagesStore;
1072-
use crate::storage::PublicMessagesStore;
1072+
use mpc::PublicMessagesStore;
10731073
use std::collections::BTreeMap;
10741074
use std::num::NonZeroU16;
10751075

crates/hashi/src/grpc/mod.rs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ impl HttpService {
4242
Self { inner: hashi }
4343
}
4444

45-
pub(crate) fn metrics(&self) -> &crate::metrics::Metrics {
46-
&self.inner.metrics
47-
}
48-
4945
pub async fn start(self) -> (std::net::SocketAddr, Service) {
5046
let router = {
5147
let max_decoding_message_size = self.inner.config.grpc_max_decoding_message_size();
5248
let bridge_service =
5349
hashi_types::proto::bridge_service_server::BridgeServiceServer::new(self.clone())
5450
.max_decoding_message_size(max_decoding_message_size);
55-
let mpc_service =
56-
hashi_types::proto::mpc_service_server::MpcServiceServer::new(self.clone())
57-
.max_decoding_message_size(max_decoding_message_size);
51+
let mpc_service = hashi_types::proto::mpc_service_server::MpcServiceServer::new(
52+
mpc::MpcServiceImpl::new(
53+
self.inner.mpc_state.clone(),
54+
Arc::new(self.inner.metrics.mpc.clone()),
55+
),
56+
)
57+
.max_decoding_message_size(max_decoding_message_size);
5858

5959
let (health_reporter, health_service) = tonic_health::server::health_reporter();
6060

@@ -136,32 +136,9 @@ impl HttpService {
136136
(local_addr, service)
137137
}
138138

139-
pub fn mpc_manager(
140-
&self,
141-
) -> Result<Arc<std::sync::RwLock<crate::mpc::MpcManager>>, tonic::Status> {
142-
self.inner
143-
.mpc_manager()
144-
.ok_or_else(|| tonic::Status::unavailable("DKG manager not yet initialized"))
145-
}
146-
147-
pub fn signing_manager_for(
148-
&self,
149-
epoch: u64,
150-
) -> Result<Arc<crate::mpc::SigningManager>, tonic::Status> {
151-
self.inner.signing_manager_for(epoch).ok_or_else(|| {
152-
tonic::Status::unavailable(format!(
153-
"SigningManager not available for epoch {epoch}; retry"
154-
))
155-
})
156-
}
157-
158139
pub fn btc_monitor(&self) -> &crate::btc_monitor::monitor::MonitorClient {
159140
self.inner.btc_monitor()
160141
}
161-
162-
pub fn get_reconfig_signature(&self, epoch: u64) -> Option<Vec<u8>> {
163-
self.inner.get_reconfig_signature(epoch)
164-
}
165142
}
166143

167144
async fn health() -> impl axum::response::IntoResponse {

0 commit comments

Comments
 (0)