Route the coordinator, fix race conditions in the signers library

This commit is contained in:
Luke Parker
2024-09-08 22:13:42 -04:00
parent 7484eadbbb
commit f07ec7bee0
15 changed files with 356 additions and 172 deletions

View File

@@ -17,6 +17,8 @@ rustdoc-args = ["--cfg", "docsrs"]
workspace = true
[dependencies]
hex = { version = "0.4", default-features = false, features = ["std"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std"] }
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }

View File

@@ -1,3 +1,4 @@
use core::fmt;
use std::collections::HashMap;
use scale::{Encode, Decode};
@@ -85,10 +86,37 @@ pub mod key_gen {
pub mod sign {
use super::*;
#[derive(Clone, PartialEq, Eq, Hash, Debug, Encode, Decode, BorshSerialize, BorshDeserialize)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encode, Decode, BorshSerialize, BorshDeserialize)]
pub enum VariantSignId {
Cosign([u8; 32]),
Batch(u32),
SlashReport([u8; 32]),
Transaction([u8; 32]),
}
impl fmt::Debug for VariantSignId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
Self::Cosign(cosign) => {
f.debug_struct("VariantSignId::Cosign").field("0", &hex::encode(cosign)).finish()
}
Self::Batch(batch) => f.debug_struct("VariantSignId::Batch").field("0", &batch).finish(),
Self::SlashReport(slash_report) => f
.debug_struct("VariantSignId::SlashReport")
.field("0", &hex::encode(slash_report))
.finish(),
Self::Transaction(tx) => {
f.debug_struct("VariantSignId::Transaction").field("0", &hex::encode(tx)).finish()
}
}
}
}
#[derive(
Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, BorshSerialize, BorshDeserialize,
)]
pub struct SignId {
pub session: Session,
pub id: [u8; 32],
pub id: VariantSignId,
pub attempt: u32,
}
@@ -109,11 +137,11 @@ pub mod sign {
None
}
pub fn session(&self) -> Session {
pub fn sign_id(&self) -> &SignId {
match self {
CoordinatorMessage::Preprocesses { id, .. } |
CoordinatorMessage::Shares { id, .. } |
CoordinatorMessage::Reattempt { id, .. } => id.session,
CoordinatorMessage::Reattempt { id, .. } => id,
}
}
}