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