Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions chain-signatures/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::mesh::Mesh;
use crate::node_client::{self, NodeClient};
use crate::protocol::message::MessageChannel;
use crate::protocol::presignature::Presignature;
use crate::protocol::signature::SignatureSpawnerTask;
use crate::protocol::state::Node;
use crate::protocol::sync::SyncTask;
use crate::protocol::{spawn_system_metrics, MpcSignProtocol};
Expand All @@ -22,8 +23,7 @@ use mpc_keys::hpke;
use near_account_id::AccountId;
use near_crypto::{InMemorySigner, PublicKey, SecretKey};
use sha3::Digest;
use std::sync::Arc;
use tokio::sync::{mpsc, watch, RwLock};
use tokio::sync::{mpsc, watch};
use url::Url;

const DEFAULT_WEB_PORT: u16 = 3000;
Expand Down Expand Up @@ -315,21 +315,34 @@ pub async fn run(cmd: Cli) -> anyhow::Result<()> {
contract_watcher.clone(),
)
.await;

// Start the signature spawner task immediately.
// It will wait for the contract to reach Running state before processing requests,
// and dynamically obtains governance info from the contract state.
let sign_task = SignatureSpawnerTask::run(
account_id.clone(),
sign_rx,
contract_watcher.clone(),
config_rx.clone(),
presignature_storage.clone(),
mesh_state.clone(),
msg_channel.clone(),
rpc_channel.clone(),
backlog.clone(),
);

let protocol = MpcSignProtocol {
my_account_id: account_id.clone(),
rpc_channel,
msg_channel: msg_channel.clone(),
generating: msg_channel.subscribe_generation().await,
resharing: msg_channel.subscribe_resharing().await,
ready: msg_channel.subscribe_ready().await,
sign_rx: Arc::new(RwLock::new(sign_rx)),
sign_task,
secret_storage: key_storage,
triple_storage: triple_storage.clone(),
presignature_storage: presignature_storage.clone(),
contract: contract_watcher.clone(),
config: config_rx,
mesh_state: mesh_state.clone(),
backlog: backlog.clone(),
};

tracing::info!("protocol initialized");
Expand Down
18 changes: 0 additions & 18 deletions chain-signatures/node/src/protocol/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use super::state::{
use super::MpcSignProtocol;
use crate::protocol::contract::primitives::Participants;
use crate::protocol::presignature::PresignatureSpawnerTask;
use crate::protocol::signature::SignatureSpawnerTask;
use crate::protocol::state::GeneratingState;
use crate::protocol::triple::TripleSpawnerTask;
use crate::protocol::Governance;
Expand Down Expand Up @@ -107,14 +106,6 @@ impl<G: Governance> ConsensusProtocol<G> for StartedState {
&public_key,
);

let sign_task = SignatureSpawnerTask::run(
me,
contract_state.threshold,
epoch,
ctx,
public_key,
);

NodeState::Running(RunningState {
epoch,
me,
Expand All @@ -124,7 +115,6 @@ impl<G: Governance> ConsensusProtocol<G> for StartedState {
public_key,
triple_task,
presign_task,
sign_task,
})
}
}
Expand Down Expand Up @@ -408,13 +398,6 @@ impl<G: Governance> ConsensusProtocol<G> for WaitingForConsensusState {
&self.private_share,
&self.public_key,
);
let sign_task = SignatureSpawnerTask::run(
me,
self.threshold,
self.epoch,
ctx,
self.public_key,
);

NodeState::Running(RunningState {
epoch: self.epoch,
Expand All @@ -425,7 +408,6 @@ impl<G: Governance> ConsensusProtocol<G> for WaitingForConsensusState {
public_key: self.public_key,
triple_task,
presign_task,
sign_task,
})
}
},
Expand Down
17 changes: 9 additions & 8 deletions chain-signatures/node/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,43 @@ pub use mpc_primitives::Chain;
pub use signature::{IndexedSignRequest, Sign};
pub use state::{Node, NodeState};

use crate::backlog::Backlog;
use crate::config::Config;
use crate::mesh::MeshState;
use crate::protocol::consensus::ConsensusProtocol;
use crate::protocol::cryptography::CryptographicProtocol;
use crate::protocol::message::{GeneratingMessage, ReadyMessage, ResharingMessage};
use crate::protocol::signature::SignatureSpawnerTask;
use crate::respond_bidirectional::RespondBidirectionalTx;
use crate::rpc::{ContractStateWatcher, RpcChannel};
use crate::rpc::ContractStateWatcher;
use crate::storage::presignature_storage::PresignatureStorage;
use crate::storage::secret_storage::SecretNodeStorageBox;
use crate::storage::triple_storage::TripleStorage;

use near_account_id::AccountId;
use semver::Version;
use std::path::Path;
use std::sync::Arc;
use std::time::{Duration, Instant};
use sysinfo::{CpuRefreshKind, Disks, RefreshKind, System};
use tokio::sync::RwLock;
use tokio::sync::{mpsc, watch};

pub struct MpcSignProtocol {
pub(crate) my_account_id: AccountId,
pub(crate) secret_storage: SecretNodeStorageBox,
pub(crate) triple_storage: TripleStorage,
pub(crate) presignature_storage: PresignatureStorage,
pub(crate) sign_rx: Arc<RwLock<mpsc::Receiver<Sign>>>,
pub(crate) sign_task: SignatureSpawnerTask,
pub(crate) generating: mpsc::Receiver<GeneratingMessage>,
pub(crate) resharing: mpsc::Receiver<ResharingMessage>,
pub(crate) ready: mpsc::Receiver<ReadyMessage>,
pub(crate) msg_channel: MessageChannel,
pub(crate) rpc_channel: RpcChannel,
pub(crate) contract: ContractStateWatcher,
pub(crate) config: watch::Receiver<Config>,
pub(crate) mesh_state: watch::Receiver<MeshState>,
pub(crate) backlog: Backlog,
}

impl Drop for MpcSignProtocol {
fn drop(&mut self) {
self.sign_task.abort();
}
}

/// Interface required by the [`MpcSignProtocol`] to participate in the
Expand Down
Loading
Loading