Remove sender_i from DkgShares

It was a piece of duplicated data used to achieve context-less
de)serialization. This new Vec code is a bit tricker to first read, yet overall
clean and removes a potential fault.

Saves 2 bytes from DkgShares messages.
This commit is contained in:
Luke Parker
2023-09-01 00:03:53 -04:00
parent 5113ab9ec4
commit fa8ff62b09
5 changed files with 65 additions and 90 deletions

View File

@@ -160,18 +160,17 @@ async fn dkg_test() {
for (k, key) in keys.iter().enumerate() {
let attempt = 0;
let mut shares = HashMap::new();
let mut shares = vec![];
for i in 0 .. keys.len() {
if i != k {
let mut share = vec![0; 256];
OsRng.fill_bytes(&mut share);
shares.insert(Participant::new((i + 1).try_into().unwrap()).unwrap(), share);
shares.push(share);
}
}
let mut tx = Transaction::DkgShares {
attempt,
sender_i: Participant::new((k + 1).try_into().unwrap()).unwrap(),
shares,
confirmation_nonces: crate::tributary::dkg_confirmation_nonces(key, &spec),
signed: Transaction::empty_signed(),
@@ -219,10 +218,15 @@ async fn dkg_test() {
.enumerate()
.filter_map(|(l, tx)| {
if let Transaction::DkgShares { shares, .. } = tx {
shares
.get(&Participant::new((i + 1).try_into().unwrap()).unwrap())
.cloned()
.map(|share| (Participant::new((l + 1).try_into().unwrap()).unwrap(), share))
if i == l {
None
} else {
let relative_i = i - (if i > l { 1 } else { 0 });
Some((
Participant::new((l + 1).try_into().unwrap()).unwrap(),
shares[relative_i].clone(),
))
}
} else {
panic!("txs had non-shares");
}