* Remove NetworkId from processor-messages

Because intent binds to the sender/receiver, it's not needed for intent.

The processor knows what the network is.

The coordinator knows which to use because it's sending this message to the
processor for that network.

Also removes the unused zeroize.

* ProcessorMessage::Completed use Session instead of key

* Move SubstrateSignId to Session

* Finish replacing key with session
This commit is contained in:
Luke Parker
2023-11-26 12:14:23 -05:00
committed by GitHub
parent b79cf8abde
commit 571195bfda
31 changed files with 304 additions and 455 deletions

View File

@@ -15,6 +15,7 @@ use serai_client::{
in_instructions::primitives::{
InInstruction, InInstructionWithBalance, Batch, SignedBatch, batch_message,
},
validator_sets::primitives::Session,
};
use processor::networks::{Network, Bitcoin, Monero};
@@ -23,12 +24,12 @@ use crate::{*, tests::*};
pub(crate) async fn recv_batch_preprocesses(
coordinators: &mut [Coordinator],
substrate_key: &[u8; 32],
session: Session,
batch: &Batch,
attempt: u32,
) -> (SubstrateSignId, HashMap<Participant, [u8; 64]>) {
let id = SubstrateSignId {
key: *substrate_key,
session,
id: SubstrateSignableId::Batch((batch.network, batch.id).encode().try_into().unwrap()),
attempt,
};
@@ -171,7 +172,6 @@ pub(crate) async fn substrate_block(
match block.clone() {
messages::substrate::CoordinatorMessage::SubstrateBlock {
context: _,
network: sent_network,
block: sent_block,
burns: _,
batches: _,
@@ -179,13 +179,8 @@ pub(crate) async fn substrate_block(
coordinator.send_message(block).await;
match coordinator.recv_message().await {
messages::ProcessorMessage::Coordinator(
messages::coordinator::ProcessorMessage::SubstrateBlockAck {
network: recvd_network,
block: recvd_block,
plans,
},
messages::coordinator::ProcessorMessage::SubstrateBlockAck { block: recvd_block, plans },
) => {
assert_eq!(recvd_network, sent_network);
assert_eq!(recvd_block, sent_block);
plans
}
@@ -214,7 +209,7 @@ fn batch_test() {
coordinators[0].sync(&ops, &coordinators[1 ..]).await;
// Generate keys
let key_pair = key_gen(&mut coordinators, network).await;
let key_pair = key_gen(&mut coordinators).await;
// Now we we have to mine blocks to activate the key
// (the first key is activated when the network's time as of a block exceeds the Serai time
@@ -284,7 +279,7 @@ fn batch_test() {
// Make sure the processors picked it up by checking they're trying to sign a batch for it
let (mut id, mut preprocesses) =
recv_batch_preprocesses(&mut coordinators, &key_pair.0 .0, &expected_batch, 0).await;
recv_batch_preprocesses(&mut coordinators, Session(0), &expected_batch, 0).await;
// Trigger a random amount of re-attempts
for attempt in 1 ..= u32::try_from(OsRng.next_u64() % 4).unwrap() {
// TODO: Double check how the processor handles this ID field
@@ -298,8 +293,7 @@ fn batch_test() {
.await;
}
(id, preprocesses) =
recv_batch_preprocesses(&mut coordinators, &key_pair.0 .0, &expected_batch, attempt)
.await;
recv_batch_preprocesses(&mut coordinators, Session(0), &expected_batch, attempt).await;
}
// Continue with signing the batch
@@ -319,7 +313,6 @@ fn batch_test() {
serai_time,
network_latest_finalized_block: batch.batch.block,
},
network,
block: substrate_block_num + u64::from(i),
burns: vec![],
batches: vec![batch.batch.id],

View File

@@ -4,14 +4,14 @@ use dkg::{Participant, ThresholdParams, tests::clone_without};
use serai_client::{
primitives::{NetworkId, BlockHash, PublicKey},
validator_sets::primitives::{Session, ValidatorSet, KeyPair},
validator_sets::primitives::{Session, KeyPair},
};
use messages::{SubstrateContext, key_gen::KeyGenId, CoordinatorMessage, ProcessorMessage};
use crate::{*, tests::*};
pub(crate) async fn key_gen(coordinators: &mut [Coordinator], network: NetworkId) -> KeyPair {
pub(crate) async fn key_gen(coordinators: &mut [Coordinator]) -> KeyPair {
// Perform an interaction with all processors via their coordinators
async fn interact_with_all<
FS: Fn(Participant) -> messages::key_gen::CoordinatorMessage,
@@ -33,7 +33,7 @@ pub(crate) async fn key_gen(coordinators: &mut [Coordinator], network: NetworkId
}
// Order a key gen
let id = KeyGenId { set: ValidatorSet { session: Session(0), network }, attempt: 0 };
let id = KeyGenId { session: Session(0), attempt: 0 };
let mut commitments = HashMap::new();
interact_with_all(
@@ -132,7 +132,7 @@ pub(crate) async fn key_gen(coordinators: &mut [Coordinator], network: NetworkId
.send_message(CoordinatorMessage::Substrate(
messages::substrate::CoordinatorMessage::ConfirmKeyPair {
context,
set: id.set,
session: id.session,
key_pair: key_pair.clone(),
},
))
@@ -158,7 +158,7 @@ fn key_gen_test() {
.map(|(handles, key)| Coordinator::new(network, &ops, handles, key))
.collect::<Vec<_>>();
key_gen(&mut coordinators, network).await;
key_gen(&mut coordinators).await;
});
}
}

View File

@@ -9,8 +9,9 @@ use messages::{sign::SignId, SubstrateContext};
use serai_client::{
primitives::{BlockHash, NetworkId},
in_instructions::primitives::Batch,
coins::primitives::{OutInstruction, OutInstructionWithBalance},
in_instructions::primitives::Batch,
validator_sets::primitives::Session,
};
use crate::{*, tests::*};
@@ -18,7 +19,7 @@ use crate::{*, tests::*};
#[allow(unused)]
pub(crate) async fn recv_sign_preprocesses(
coordinators: &mut [Coordinator],
key: Vec<u8>,
session: Session,
attempt: u32,
) -> (SignId, HashMap<Participant, Vec<u8>>) {
let mut id = None;
@@ -33,7 +34,7 @@ pub(crate) async fn recv_sign_preprocesses(
preprocesses: mut these_preprocesses,
}) => {
if id.is_none() {
assert_eq!(&this_id.key, &key);
assert_eq!(&this_id.session, &session);
assert_eq!(this_id.attempt, attempt);
id = Some(this_id.clone());
}
@@ -62,6 +63,7 @@ pub(crate) async fn recv_sign_preprocesses(
#[allow(unused)]
pub(crate) async fn sign_tx(
coordinators: &mut [Coordinator],
session: Session,
id: SignId,
preprocesses: HashMap<Participant, Vec<u8>>,
) -> Vec<u8> {
@@ -120,11 +122,11 @@ pub(crate) async fn sign_tx(
if preprocesses.contains_key(&i) {
match coordinator.recv_message().await {
messages::ProcessorMessage::Sign(messages::sign::ProcessorMessage::Completed {
key,
session: this_session,
id: this_id,
tx: this_tx,
}) => {
assert_eq!(&key, &id.key);
assert_eq!(session, this_session);
assert_eq!(&this_id, &id.id);
if tx.is_none() {
@@ -158,7 +160,7 @@ fn send_test() {
coordinators[0].sync(&ops, &coordinators[1 ..]).await;
// Generate keys
let key_pair = key_gen(&mut coordinators, network).await;
let key_pair = key_gen(&mut coordinators).await;
// Now we we have to mine blocks to activate the key
// (the first key is activated when the network's time as of a block exceeds the Serai time
@@ -195,7 +197,7 @@ fn send_test() {
// Make sure the proceessors picked it up by checking they're trying to sign a batch for it
let (id, preprocesses) =
recv_batch_preprocesses(&mut coordinators, &key_pair.0 .0, &expected_batch, 0).await;
recv_batch_preprocesses(&mut coordinators, Session(0), &expected_batch, 0).await;
// Continue with signing the batch
let batch = sign_batch(&mut coordinators, key_pair.0 .0, id, preprocesses).await;
@@ -216,7 +218,6 @@ fn send_test() {
serai_time,
network_latest_finalized_block: batch.batch.block,
},
network,
block: substrate_block_num,
burns: vec![OutInstructionWithBalance {
instruction: OutInstruction { address: wallet.address(), data: None },
@@ -237,9 +238,8 @@ fn send_test() {
// Start signing the TX
let (mut id, mut preprocesses) =
recv_sign_preprocesses(&mut coordinators, key_pair.1.to_vec(), 0).await;
// TODO: Should this use the Substrate key?
assert_eq!(id, SignId { key: key_pair.1.to_vec(), id: plans[0].id, attempt: 0 });
recv_sign_preprocesses(&mut coordinators, Session(0), 0).await;
assert_eq!(id, SignId { session: Session(0), id: plans[0].id, attempt: 0 });
// Trigger a random amount of re-attempts
for attempt in 1 ..= u32::try_from(OsRng.next_u64() % 4).unwrap() {
@@ -251,12 +251,11 @@ fn send_test() {
.send_message(messages::sign::CoordinatorMessage::Reattempt { id: id.clone() })
.await;
}
(id, preprocesses) =
recv_sign_preprocesses(&mut coordinators, key_pair.1.to_vec(), attempt).await;
(id, preprocesses) = recv_sign_preprocesses(&mut coordinators, Session(0), attempt).await;
}
let participating = preprocesses.keys().cloned().collect::<Vec<_>>();
let tx_id = sign_tx(&mut coordinators, id.clone(), preprocesses).await;
let tx_id = sign_tx(&mut coordinators, Session(0), id.clone(), preprocesses).await;
// Make sure all participating nodes published the TX
let participating =
@@ -276,7 +275,7 @@ fn send_test() {
// Tell them of it as a completion of the relevant signing nodess
coordinator
.send_message(messages::sign::CoordinatorMessage::Completed {
key: key_pair.1.to_vec(),
session: Session(0),
id: id.id,
tx: tx_id.clone(),
})
@@ -284,11 +283,11 @@ fn send_test() {
// Verify they send Completed back
match coordinator.recv_message().await {
messages::ProcessorMessage::Sign(messages::sign::ProcessorMessage::Completed {
key,
session,
id: this_id,
tx: this_tx,
}) => {
assert_eq!(&key, &id.key);
assert_eq!(session, Session(0));
assert_eq!(&this_id, &id.id);
assert_eq!(this_tx, tx_id);
}