Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a session::tokio module with a convenience function for executing a session #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fjarri
Copy link
Member

@fjarri fjarri commented Feb 6, 2025

Fixes #28

Add session::tokio::run_session() and supporting types. Gated behind the tokio feature.

TODO: deal with #22 as well?

@fjarri fjarri self-assigned this Feb 6, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 13172264691

Details

  • 70 of 77 (90.91%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.6%) to 70.115%

Changes Missing Coverage Covered Lines Changed/Added Lines %
manul/src/session/tokio.rs 70 77 90.91%
Totals Coverage Status
Change from base Build 13062498128: 1.6%
Covered Lines: 1945
Relevant Lines: 2774

💛 - Coveralls

@fjarri
Copy link
Member Author

fjarri commented Feb 6, 2025

@ameba23 this is supposed to be the replacement for https://github.com/entropyxyz/entropy-core/blob/master/crates/protocol/src/execute_protocol.rs#L73 so that you don't have to worry about executing the session correctly. Does the API look okay to you? I noticed that you're taking the channels by value and then returning them; will the proposed API with references work? Also, do you want more/less/different tracing messages?

Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm modulo questions and nitpicks


/// The outgoing message from a local session.
#[derive(Debug)]
pub struct MessageOut<SP: SessionParameters> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MessageOut and MessageIn type do not seem to be tokio-specific. Are they generally useful you reckon or will users want to implement their own versions? If the latter, why would they want that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just named tuples with returned stuff. The user is free to re-wrap it differently.

/// The outgoing message from a local session.
#[derive(Debug)]
pub struct MessageOut<SP: SessionParameters> {
/// The ID of the session that created the message.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this accurate? Given there is a public SessionId type, it is a bit confusing to read this and then read SP::Verifier which boils down to a PartyId. Is it "The ID of the party that created the message in this session" perhaps?

/// The incoming message from a remote session.
#[derive(Debug)]
pub struct MessageIn<SP: SessionParameters> {
/// The ID of the session the message originated from.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

// will be stored here and applied after the messages for this round are sent.
let mut cached_messages = Vec::new();

let key = session.verifier();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let key = session.verifier();
let verifier = session.verifier();

…or something more specific to its role? Maybe just from?

.map_err(|err| {
LocalError::new(format!(
"Failed to send a message from {:?} to {:?}: {err}",
session.verifier(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
session.verifier(),
key,

@ameba23
Copy link

ameba23 commented Feb 6, 2025

@ameba23 this is supposed to be the replacement for https://github.com/entropyxyz/entropy-core/blob/master/crates/protocol/src/execute_protocol.rs#L73 so that you don't have to worry about executing the session correctly. Does the API look okay to you? I noticed that you're taking the channels by value and then returning them; will the proposed API with references work? Also, do you want more/less/different tracing messages?

Great that this is going in and we wont have to worry about / maintain this anymore ⭐

The reason we are returning the channels is so that we can use the same channels and websocket connection for the sub-protocols of the following:

  • 'DKG' is comprised of key init, reshare, and aux gen
  • 'Reshare' is comprised of reshare and aux gen

So if synedrion were to offer these high level protocols in a single session, we would not need to do this and from our point of view everything would be much simpler.

I expect that passing references to the channels will work, but i will check with our current code. But what might be a problem is that the payloads of these channels currently contain both the synedrion message and the session ID, to allow us to have messages from the different subprotocols and be sure that we are processing the right message for the current protocol:

https://github.com/entropyxyz/entropy-core/blob/0fed38b7218f9e850fd2d226196cc323f2c5da7d/crates/protocol/src/execute_protocol.rs#L147

The only other thing that we would lose by using this is that we are calling session.make_message and session.process_message in a separate tokio task. To be honest, the performance gains of doing this have been pretty minimal and that might be because it is not implemented well. But obviously performance here really matters because it effects how big we can make the signing committee.

The amount of logging looks great.

Tagging @JesseAbram @HCastano

@fjarri
Copy link
Member Author

fjarri commented Feb 6, 2025

the payloads of these channels currently contain both the synedrion message and the session ID

This can be included in MessageOut, but it would be strange in MessageIn. Do you need it to be present in both directions?

The only other thing that we would lose by using this is that we are calling session.make_message and session.process_message in a separate tokio task.

That's exactly #22 which I mentioned above, so it'll be included as well. I saw that you have some offloading in place, but I wonder, wouldn't it be better to use spawn_blocking there?

@ameba23
Copy link

ameba23 commented Feb 6, 2025

This can be included in MessageOut, but it would be strange in MessageIn. Do you need it to be present in both directions?

It seems like we do need it in MessageIn. Sometimes a remote party sends the first message on the next protocol before we have finalized the current one. I'll double check but im pretty sure if i take that check out the tests will fail.

That's exactly #22 which I mentioned above, so it'll be included as well.

Thats great!

I saw that you have some offloading in place, but I wonder, wouldn't it be better to use spawn_blocking there?

I've never used spawn_blocking before, but i guess i'll try it and see if it improves things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A session loop implementation for tokio
4 participants