Skip to content

Commit 9a171e1

Browse files
committed
Batch p2p messages in one round instead of flushing immediately
Signed-off-by: maurges <nikita@dfns.co>
1 parent c669185 commit 9a171e1

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cggmp21-keygen/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ serde = { workspace = true, features = ["derive"] }
2828
serde_with = { workspace = true }
2929
hex = { workspace = true, features = ["serde"] }
3030

31+
futures = { workspace = true }
32+
3133
displaydoc = { workspace = true }
3234
thiserror = { workspace = true, optional = true }
3335

cggmp21-keygen/src/threshold.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,16 @@ where
277277
.await
278278
.map_err(IoError::send_message)?;
279279

280-
for j in utils::iter_peers(i, n) {
280+
let messages = utils::iter_peers(i, n).map(|j| {
281281
let message = MsgRound2Uni {
282282
sigma: sigmas[usize::from(j)],
283283
};
284-
outgoings
285-
.send(Outgoing::p2p(j, Msg::Round2Uni(message)))
286-
.await
287-
.map_err(IoError::send_message)?;
288-
}
284+
Outgoing::p2p(j, Msg::Round2Uni(message))
285+
});
286+
outgoings
287+
.send_all(&mut futures::stream::iter(messages.map(Ok)))
288+
.await
289+
.map_err(IoError::send_message)?;
289290
tracer.msg_sent();
290291

291292
// Round 3

cggmp21/src/signing.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -715,13 +715,12 @@ where
715715
)
716716
.map_err(|e| Bug::PiEnc(BugSource::psi0, e))?;
717717

718-
tracer.send_msg();
719718
outgoings
720-
.send(Outgoing::p2p(j, Msg::Round1b(MsgRound1b { psi0 })))
719+
.feed(Outgoing::p2p(j, Msg::Round1b(MsgRound1b { psi0 })))
721720
.await
722721
.map_err(IoError::send_message)?;
723-
tracer.msg_sent();
724722
}
723+
outgoings.flush().await.map_err(IoError::send_message)?;
725724

726725
// Round 2
727726
tracer.round_begins();
@@ -950,9 +949,8 @@ where
950949
.map_err(|e| Bug::PiLog(BugSource::psi_prime, e))?;
951950
runtime.yield_now().await;
952951

953-
tracer.send_msg();
954952
outgoings
955-
.send(Outgoing::p2p(
953+
.feed(Outgoing::p2p(
956954
j,
957955
Msg::Round2(MsgRound2 {
958956
Gamma: Gamma_i,
@@ -967,8 +965,8 @@ where
967965
))
968966
.await
969967
.map_err(IoError::send_message)?;
970-
tracer.msg_sent();
971968
}
969+
outgoings.flush().await.map_err(IoError::send_message)?;
972970

973971
// Round 3
974972
tracer.round_begins();
@@ -1124,9 +1122,8 @@ where
11241122
)
11251123
.map_err(|e| Bug::PiLog(BugSource::psi_prime_prime, e))?;
11261124

1127-
tracer.send_msg();
11281125
outgoings
1129-
.send(Outgoing::p2p(
1126+
.feed(Outgoing::p2p(
11301127
j,
11311128
Msg::Round3(MsgRound3 {
11321129
delta: delta_i,
@@ -1136,8 +1133,8 @@ where
11361133
))
11371134
.await
11381135
.map_err(IoError::send_message)?;
1139-
tracer.msg_sent();
11401136
}
1137+
outgoings.flush().await.map_err(IoError::send_message)?;
11411138

11421139
// Output
11431140
tracer.named_round_begins("Presig output");

0 commit comments

Comments
 (0)