Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make sign queue use less shared state #91

Merged
merged 59 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
30f61f2
Cleanup triples interface insert
ChaoticTempest Dec 3, 2024
02e6a8e
Added triple store error
ChaoticTempest Dec 3, 2024
d1f65e1
Cleaned presignature store
ChaoticTempest Dec 3, 2024
adeb91d
Upgrade bollard/testcontainers for better test interface
ChaoticTempest Dec 4, 2024
a4d1258
Added node cluster interface
ChaoticTempest Dec 4, 2024
2b72dc5
Added SignAction interface
ChaoticTempest Dec 4, 2024
e7876ca
Added rogue respond to sign interface
ChaoticTempest Dec 4, 2024
7570a2d
Reformat all test with new interface
ChaoticTempest Dec 5, 2024
5d08a93
No more need for wait_for::running_mpc
ChaoticTempest Dec 5, 2024
d26d5b7
Rename to signable
ChaoticTempest Dec 5, 2024
87f9ee5
Remove unnecessary functions
ChaoticTempest Dec 5, 2024
bf42956
signable rename
ChaoticTempest Dec 5, 2024
b2fee59
Remove unnecssary functions
ChaoticTempest Dec 5, 2024
82d5291
Merge branch 'develop' of github.com:sig-net/sig-mpc into phuong/chor…
ChaoticTempest Dec 5, 2024
0edb22a
Resolved comments
ChaoticTempest Dec 5, 2024
25117ca
Merge branch 'develop' of github.com:sig-net/sig-mpc into phuong/chor…
ChaoticTempest Dec 5, 2024
68e9736
Merge branch 'phuong/chore/cleanup-redis' of github.com:sig-net/sig-m…
ChaoticTempest Dec 5, 2024
4d2e292
Merge branch 'develop' of github.com:sig-net/sig-mpc into phuong/chor…
ChaoticTempest Dec 9, 2024
99a899b
Merge branch 'phuong/chore/cleanup-redis' of github.com:sig-net/sig-m…
ChaoticTempest Dec 9, 2024
33fdbd0
fmt
ChaoticTempest Dec 9, 2024
bd8ac54
Merge branch 'phuong/chore/cleanup-redis' of github.com:sig-net/sig-m…
ChaoticTempest Dec 9, 2024
4cf6240
clippy
ChaoticTempest Dec 9, 2024
2558a0c
Merge branch 'phuong/chore/cleanup-redis' of github.com:sig-net/sig-m…
ChaoticTempest Dec 9, 2024
6fbe3d3
Rename vote/leave
ChaoticTempest Dec 9, 2024
695a3ad
Rename proper NodeConfig and NodeEnvConfig
ChaoticTempest Dec 10, 2024
2cba7d7
Merge branch 'develop' of github.com:sig-net/sig-mpc into phuong/chor…
ChaoticTempest Dec 10, 2024
bfefd15
Merge branch 'develop' of github.com:sig-net/sig-mpc into phuong/chor…
ChaoticTempest Dec 10, 2024
41db464
Bump join to 20secs
Dec 12, 2024
ff88bfe
clippy & fmt
ChaoticTempest Dec 12, 2024
20619dd
Internalize triple manager RwLock and tasks to crypto loop
ChaoticTempest Dec 12, 2024
9123d04
Made each generator a task
ChaoticTempest Dec 12, 2024
7e40cd2
Cleaned up triple generation task
ChaoticTempest Dec 13, 2024
063d40d
Merge branch 'develop' of github.com:sig-net/sig-mpc into phuong/chor…
ChaoticTempest Dec 13, 2024
46da477
Added wait for running/joining/resharing on per node
ChaoticTempest Dec 13, 2024
31e4174
Fix mac build
ChaoticTempest Dec 13, 2024
4cba601
Added candidate check
ChaoticTempest Dec 14, 2024
5b2fa45
Merge branch 'phuong/chore/cleanup-testing-interface' of github.com:/…
ChaoticTempest Dec 14, 2024
4098eb9
clippy and better err messages
ChaoticTempest Dec 16, 2024
887443f
Merge branch 'phuong/chore/cleanup-testing-interface' of github.com:s…
ChaoticTempest Dec 16, 2024
60984c4
Made http_client use participant instead of info for less clone
ChaoticTempest Dec 16, 2024
2a64026
Bump reshare test to 900secs
ChaoticTempest Dec 16, 2024
37451f6
Made presignature and signature have execute functions
ChaoticTempest Dec 16, 2024
c435100
Better errors on vote_{join, leave}
ChaoticTempest Dec 16, 2024
f320346
Wait on finality final for running mpc
ChaoticTempest Dec 16, 2024
f4e9c95
Merge branch 'phuong/chore/cleanup-testing-interface' of github.com:s…
ChaoticTempest Dec 16, 2024
b7f1f67
minor optimization
ChaoticTempest Dec 16, 2024
5d61c14
Added debug impl for SignOutcome
ChaoticTempest Dec 17, 2024
9ccf81c
Fix offline test
ChaoticTempest Dec 17, 2024
93611ab
Merge branch 'phuong/chore/cleanup-testing-interface' of github.com:s…
ChaoticTempest Dec 17, 2024
b066ae6
Updated nightly to run 100 sigs
ChaoticTempest Dec 17, 2024
82be71a
Merge branch 'develop' of github.com:sig-net/sig-mpc into phuong/feat…
ChaoticTempest Dec 20, 2024
6082db5
Added iter impls for candidates and participants
ChaoticTempest Dec 20, 2024
b2d585a
Merge branch 'develop' of github.com:sig-net/sig-mpc into phuong/feat…
ChaoticTempest Jan 3, 2025
64e49c4
Clippy
ChaoticTempest Jan 4, 2025
cf825bf
Made sign queue indexer use sign_tx for sending requests
ChaoticTempest Jan 7, 2025
9b2abfe
Made sign_rx be passed around instead of sign queue
ChaoticTempest Jan 7, 2025
ce3b7aa
Made SignatureManager store threshold
ChaoticTempest Jan 7, 2025
d79038b
Merge branch 'develop' of github.com:sig-net/sig-mpc into phuong/feat…
ChaoticTempest Jan 8, 2025
5a70c08
Fix sign_queue::len
ChaoticTempest Jan 8, 2025
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
6 changes: 3 additions & 3 deletions chain-signatures/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> {
mesh_options,
message_options,
} => {
let sign_queue = Arc::new(RwLock::new(SignQueue::new()));
let (sign_tx, sign_rx) = SignQueue::channel();
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?;
Expand Down Expand Up @@ -221,7 +221,7 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> {
&indexer_options,
&mpc_contract_id,
&account_id,
&sign_queue,
sign_tx,
app_data_storage,
rpc_client.clone(),
)?;
Expand Down Expand Up @@ -257,7 +257,7 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> {
rpc_client.clone(),
signer,
receiver,
sign_queue,
sign_rx,
key_storage,
triple_storage,
presignature_storage,
Expand Down
22 changes: 14 additions & 8 deletions chain-signatures/node/src/indexer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::protocol::{SignQueue, SignRequest};
use crate::protocol::SignRequest;
use crate::storage::app_data_storage::AppDataStorage;
use crypto_shared::{derive_epsilon, ScalarExt};
use k256::Scalar;
Expand All @@ -13,7 +13,7 @@ use std::ops::Mul;
use std::sync::Arc;
use std::thread::JoinHandle;
use std::time::{Duration, Instant};
use tokio::sync::RwLock;
use tokio::sync::{mpsc, RwLock};

/// Configures indexer.
#[derive(Debug, Clone, clap::Parser)]
Expand Down Expand Up @@ -169,7 +169,7 @@ impl Indexer {
struct Context {
mpc_contract_id: AccountId,
node_account_id: AccountId,
queue: Arc<RwLock<SignQueue>>,
sign_tx: mpsc::Sender<SignRequest>,
indexer: Indexer,
}

Expand Down Expand Up @@ -267,14 +267,20 @@ async fn handle_block(

// Add the requests after going through the whole block to avoid partial processing if indexer fails somewhere.
// This way we can revisit the same block if we failed while not having added the requests partially.
let mut queue = ctx.queue.write().await;
for request in pending_requests {
queue.add(request);
tracing::info!(
request_id = ?near_primitives::hash::CryptoHash(request.request_id),
payload = hex::encode(request.request.payload.to_bytes()),
entropy = hex::encode(request.entropy),
"new sign request"
);
if let Err(err) = ctx.sign_tx.send(request).await {
tracing::error!(?err, "failed to send the sign request into sign queue");
}
crate::metrics::NUM_SIGN_REQUESTS
.with_label_values(&[ctx.node_account_id.as_str()])
.inc();
}
drop(queue);

let log_indexing_interval = 1000;
if block.block_height() % log_indexing_interval == 0 {
Expand All @@ -292,7 +298,7 @@ pub fn run(
options: &Options,
mpc_contract_id: &AccountId,
node_account_id: &AccountId,
queue: &Arc<RwLock<SignQueue>>,
sign_tx: mpsc::Sender<SignRequest>,
app_data_storage: AppDataStorage,
rpc_client: near_fetch::Client,
) -> anyhow::Result<(JoinHandle<anyhow::Result<()>>, Indexer)> {
Expand All @@ -308,7 +314,7 @@ pub fn run(
let context = Context {
mpc_contract_id: mpc_contract_id.clone(),
node_account_id: node_account_id.clone(),
queue: queue.clone(),
sign_tx,
indexer: indexer.clone(),
};

Expand Down
17 changes: 9 additions & 8 deletions chain-signatures/node/src/protocol/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::state::{
JoiningState, NodeState, PersistentNodeData, RunningState, StartedState,
WaitingForConsensusState,
};
use super::SignQueue;
use crate::config::Config;
use crate::gcp::error::SecretStorageError;
use crate::http_client::MessageQueue;
Expand All @@ -12,6 +11,7 @@ use crate::protocol::presignature::PresignatureManager;
use crate::protocol::signature::SignatureManager;
use crate::protocol::state::{GeneratingState, ResharingState};
use crate::protocol::triple::TripleManager;
use crate::protocol::SignRequest;
use crate::storage::presignature_storage::PresignatureStorage;
use crate::storage::secret_storage::SecretNodeStorageBox;
use crate::storage::triple_storage::TripleStorage;
Expand All @@ -25,7 +25,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use cait_sith::protocol::InitializationError;
use serde_json::json;
use tokio::sync::RwLock;
use tokio::sync::{mpsc, RwLock};
use url::Url;

use near_account_id::AccountId;
Expand All @@ -38,7 +38,7 @@ pub trait ConsensusCtx {
fn signer(&self) -> &InMemorySigner;
fn mpc_contract_id(&self) -> &AccountId;
fn my_address(&self) -> &Url;
fn sign_queue(&self) -> Arc<RwLock<SignQueue>>;
fn sign_rx(&self) -> Arc<RwLock<mpsc::Receiver<SignRequest>>>;
fn secret_storage(&self) -> &SecretNodeStorageBox;
fn triple_storage(&self) -> &TripleStorage;
fn presignature_storage(&self) -> &PresignatureStorage;
Expand Down Expand Up @@ -118,7 +118,6 @@ impl ConsensusProtocol for StartedState {
}
Ordering::Less => Err(ConsensusError::EpochRollback),
Ordering::Equal => {
let sign_queue = ctx.sign_queue();
match contract_state
.participants
.find_participant(ctx.my_account_id())
Expand Down Expand Up @@ -147,9 +146,11 @@ impl ConsensusProtocol for StartedState {
let signature_manager =
Arc::new(RwLock::new(SignatureManager::new(
me,
ctx.my_account_id(),
contract_state.threshold,
public_key,
epoch,
ctx.my_account_id(),
ctx.sign_rx(),
)));

Ok(NodeState::Running(RunningState {
Expand All @@ -158,7 +159,6 @@ impl ConsensusProtocol for StartedState {
threshold: contract_state.threshold,
private_share,
public_key,
sign_queue,
triple_manager,
presignature_manager,
signature_manager,
Expand Down Expand Up @@ -388,9 +388,11 @@ impl ConsensusProtocol for WaitingForConsensusState {

let signature_manager = Arc::new(RwLock::new(SignatureManager::new(
me,
ctx.my_account_id(),
self.threshold,
self.public_key,
self.epoch,
ctx.my_account_id(),
ctx.sign_rx(),
)));

Ok(NodeState::Running(RunningState {
Expand All @@ -399,7 +401,6 @@ impl ConsensusProtocol for WaitingForConsensusState {
threshold: self.threshold,
private_share: self.private_share,
public_key: self.public_key,
sign_queue: ctx.sign_queue(),
triple_manager,
presignature_manager,
signature_manager,
Expand Down
5 changes: 2 additions & 3 deletions chain-signatures/node/src/protocol/cryptography.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,9 @@ impl CryptographicProtocol for RunningState {

let presig_task = PresignatureManager::execute(&self, &active, &cfg.protocol);

let me = ctx.me().await;
let stable = mesh_state.stable_participants;
tracing::debug!(?stable, "stable participants");
let sig_task = SignatureManager::execute(&self, &stable, me, &cfg.protocol, &ctx);
let sig_task = SignatureManager::execute(&self, &stable, &cfg.protocol, &ctx);

match tokio::try_join!(triple_task, presig_task, sig_task) {
Ok(_result) => (),
Expand All @@ -398,7 +397,7 @@ impl CryptographicProtocol for RunningState {

let failures = messages
.send_encrypted(
me,
ctx.me().await,
&cfg.local.network.sign_sk,
ctx.http_client(),
&active,
Expand Down
10 changes: 5 additions & 5 deletions chain-signatures/node/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct Ctx {
signer: InMemorySigner,
rpc_client: near_fetch::Client,
http_client: reqwest::Client,
sign_queue: Arc<RwLock<SignQueue>>,
sign_rx: Arc<RwLock<mpsc::Receiver<SignRequest>>>,
secret_storage: SecretNodeStorageBox,
triple_storage: TripleStorage,
presignature_storage: PresignatureStorage,
Expand Down Expand Up @@ -81,8 +81,8 @@ impl ConsensusCtx for &mut MpcSignProtocol {
&self.ctx.my_address
}

fn sign_queue(&self) -> Arc<RwLock<SignQueue>> {
self.ctx.sign_queue.clone()
fn sign_rx(&self) -> Arc<RwLock<mpsc::Receiver<SignRequest>>> {
self.ctx.sign_rx.clone()
}

fn secret_storage(&self) -> &SecretNodeStorageBox {
Expand Down Expand Up @@ -155,7 +155,7 @@ impl MpcSignProtocol {
rpc_client: near_fetch::Client,
signer: InMemorySigner,
receiver: mpsc::Receiver<MpcMessage>,
sign_queue: Arc<RwLock<SignQueue>>,
sign_rx: mpsc::Receiver<SignRequest>,
secret_storage: SecretNodeStorageBox,
triple_storage: TripleStorage,
presignature_storage: PresignatureStorage,
Expand All @@ -179,7 +179,7 @@ impl MpcSignProtocol {
mpc_contract_id,
rpc_client,
http_client: reqwest::Client::new(),
sign_queue,
sign_rx: Arc::new(RwLock::new(sign_rx)),
signer,
secret_storage,
triple_storage,
Expand Down
Loading
Loading