mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-23 03:59:22 +00:00
Only emit Preprocesses/Shares when participating
This commit is contained in:
parent
2702384c70
commit
8c1d8a2658
1 changed files with 139 additions and 110 deletions
|
@ -157,7 +157,7 @@ fn read_known_to_exist_data<D: Db, G: Get>(
|
|||
attempt: u32,
|
||||
bytes: Vec<u8>,
|
||||
signed: Option<&Signed>,
|
||||
) -> HashMap<Participant, Vec<u8>> {
|
||||
) -> Option<HashMap<Participant, Vec<u8>>> {
|
||||
let mut data = HashMap::new();
|
||||
for validator in spec.validators().iter().map(|validator| validator.0) {
|
||||
data.insert(
|
||||
|
@ -175,16 +175,19 @@ fn read_known_to_exist_data<D: Db, G: Get>(
|
|||
}
|
||||
assert_eq!(data.len(), usize::from(needed));
|
||||
|
||||
// Remove our own piece of data
|
||||
assert!(data
|
||||
// Remove our own piece of data, if we were involved
|
||||
if data
|
||||
.remove(
|
||||
&spec
|
||||
.i(Ristretto::generator() * key.deref())
|
||||
.expect("handling a message for a Tributary we aren't part of")
|
||||
.expect("handling a message for a Tributary we aren't part of"),
|
||||
)
|
||||
.is_some());
|
||||
|
||||
data
|
||||
.is_some()
|
||||
{
|
||||
Some(data)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dkg_confirmation_nonces(
|
||||
|
@ -204,7 +207,7 @@ pub fn generated_key_pair<D: Db>(
|
|||
TributaryDb::<D>::save_currently_completing_key_pair(txn, spec.genesis(), key_pair);
|
||||
|
||||
let attempt = 0; // TODO
|
||||
let preprocesses = read_known_to_exist_data::<D, _>(
|
||||
let Some(preprocesses) = read_known_to_exist_data::<D, _>(
|
||||
txn,
|
||||
spec,
|
||||
key,
|
||||
|
@ -214,7 +217,9 @@ pub fn generated_key_pair<D: Db>(
|
|||
attempt,
|
||||
vec![],
|
||||
None,
|
||||
);
|
||||
) else {
|
||||
panic!("wasn't a participant in confirming a key pair");
|
||||
};
|
||||
DkgConfirmer::share(spec, key, preprocesses, key_pair)
|
||||
}
|
||||
|
||||
|
@ -317,9 +322,8 @@ pub async fn handle_application_tx<
|
|||
|
||||
match tx {
|
||||
Transaction::DkgCommitments(attempt, bytes, signed) => {
|
||||
if let Some(commitments) =
|
||||
handle(txn, Zone::Dkg, b"dkg_commitments", spec.n(), [0; 32], attempt, bytes, &signed)
|
||||
{
|
||||
match handle(txn, Zone::Dkg, b"dkg_commitments", spec.n(), [0; 32], attempt, bytes, &signed) {
|
||||
Some(Some(commitments)) => {
|
||||
log::info!("got all DkgCommitments for {}", hex::encode(genesis));
|
||||
processors
|
||||
.send(
|
||||
|
@ -331,6 +335,9 @@ pub async fn handle_application_tx<
|
|||
)
|
||||
.await;
|
||||
}
|
||||
Some(None) => panic!("wasn't a participant in DKG commitments"),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
Transaction::DkgShares { attempt, sender_i, mut shares, confirmation_nonces, signed } => {
|
||||
|
@ -366,9 +373,8 @@ pub async fn handle_application_tx<
|
|||
confirmation_nonces.to_vec(),
|
||||
&signed,
|
||||
);
|
||||
if let Some(shares) =
|
||||
handle(txn, Zone::Dkg, b"dkg_shares", spec.n(), [0; 32], attempt, bytes, &signed)
|
||||
{
|
||||
match handle(txn, Zone::Dkg, b"dkg_shares", spec.n(), [0; 32], attempt, bytes, &signed) {
|
||||
Some(Some(shares)) => {
|
||||
log::info!("got all DkgShares for {}", hex::encode(genesis));
|
||||
assert!(confirmation_nonces.is_some());
|
||||
processors
|
||||
|
@ -380,13 +386,14 @@ pub async fn handle_application_tx<
|
|||
}),
|
||||
)
|
||||
.await;
|
||||
} else {
|
||||
assert!(confirmation_nonces.is_none());
|
||||
}
|
||||
Some(None) => panic!("wasn't a participant in DKG shares"),
|
||||
None => assert!(confirmation_nonces.is_none()),
|
||||
}
|
||||
}
|
||||
|
||||
Transaction::DkgConfirmed(attempt, shares, signed) => {
|
||||
if let Some(shares) = handle(
|
||||
match handle(
|
||||
txn,
|
||||
Zone::Dkg,
|
||||
DKG_CONFIRMATION_SHARES,
|
||||
|
@ -396,9 +403,10 @@ pub async fn handle_application_tx<
|
|||
shares.to_vec(),
|
||||
&signed,
|
||||
) {
|
||||
Some(Some(shares)) => {
|
||||
log::info!("got all DkgConfirmed for {}", hex::encode(genesis));
|
||||
|
||||
let preprocesses = read_known_to_exist_data::<D, _>(
|
||||
let Some(preprocesses) = read_known_to_exist_data::<D, _>(
|
||||
txn,
|
||||
spec,
|
||||
key,
|
||||
|
@ -408,7 +416,9 @@ pub async fn handle_application_tx<
|
|||
attempt,
|
||||
vec![],
|
||||
None,
|
||||
);
|
||||
) else {
|
||||
panic!("wasn't a participant in DKG confirmation nonces");
|
||||
};
|
||||
|
||||
let key_pair = TributaryDb::<D>::currently_completing_key_pair(txn, genesis)
|
||||
.unwrap_or_else(|| {
|
||||
|
@ -428,6 +438,9 @@ pub async fn handle_application_tx<
|
|||
)
|
||||
.await;
|
||||
}
|
||||
Some(None) => panic!("wasn't a participant in DKG confirmination shares"),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
Transaction::ExternalBlock(block) => {
|
||||
|
@ -453,7 +466,7 @@ pub async fn handle_application_tx<
|
|||
}
|
||||
|
||||
Transaction::BatchPreprocess(data) => {
|
||||
if let Some(preprocesses) = handle(
|
||||
match handle(
|
||||
txn,
|
||||
Zone::Batch,
|
||||
b"batch_preprocess",
|
||||
|
@ -463,6 +476,7 @@ pub async fn handle_application_tx<
|
|||
data.data,
|
||||
&data.signed,
|
||||
) {
|
||||
Some(Some(preprocesses)) => {
|
||||
processors
|
||||
.send(
|
||||
spec.set().network,
|
||||
|
@ -473,9 +487,12 @@ pub async fn handle_application_tx<
|
|||
)
|
||||
.await;
|
||||
}
|
||||
Some(None) => {}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
Transaction::BatchShare(data) => {
|
||||
if let Some(shares) = handle(
|
||||
match handle(
|
||||
txn,
|
||||
Zone::Batch,
|
||||
b"batch_share",
|
||||
|
@ -485,6 +502,7 @@ pub async fn handle_application_tx<
|
|||
data.data,
|
||||
&data.signed,
|
||||
) {
|
||||
Some(Some(shares)) => {
|
||||
processors
|
||||
.send(
|
||||
spec.set().network,
|
||||
|
@ -498,10 +516,13 @@ pub async fn handle_application_tx<
|
|||
)
|
||||
.await;
|
||||
}
|
||||
Some(None) => {}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
Transaction::SignPreprocess(data) => {
|
||||
if let Some(preprocesses) = handle(
|
||||
match handle(
|
||||
txn,
|
||||
Zone::Sign,
|
||||
b"sign_preprocess",
|
||||
|
@ -511,6 +532,7 @@ pub async fn handle_application_tx<
|
|||
data.data,
|
||||
&data.signed,
|
||||
) {
|
||||
Some(Some(preprocesses)) => {
|
||||
processors
|
||||
.send(
|
||||
spec.set().network,
|
||||
|
@ -521,9 +543,12 @@ pub async fn handle_application_tx<
|
|||
)
|
||||
.await;
|
||||
}
|
||||
Some(None) => {}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
Transaction::SignShare(data) => {
|
||||
if let Some(shares) = handle(
|
||||
match handle(
|
||||
txn,
|
||||
Zone::Sign,
|
||||
b"sign_share",
|
||||
|
@ -533,6 +558,7 @@ pub async fn handle_application_tx<
|
|||
data.data,
|
||||
&data.signed,
|
||||
) {
|
||||
Some(Some(shares)) => {
|
||||
processors
|
||||
.send(
|
||||
spec.set().network,
|
||||
|
@ -543,6 +569,9 @@ pub async fn handle_application_tx<
|
|||
)
|
||||
.await;
|
||||
}
|
||||
Some(None) => {}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
Transaction::SignCompleted(_, _, _) => todo!(),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue