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

Make Round dyn-safe #94

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Make Round dyn-safe #94

wants to merge 8 commits into from

Conversation

fjarri
Copy link
Member

@fjarri fjarri commented Feb 16, 2025

  • Bump serde-encoded-bytes to 0.2
  • Rename Payload::try_to_typed() and Artifact::try_to_typed() to downcast() (for uniformity with Box and BoxedRound)
  • Fix a copy-paste artifact in a comment
  • Round methods take dyn CryptoRngCore. This lead to an avalanche of changes, see below.

dyn-safe Round

I started with adding ?Sized to CryptoRngCore in Round methods and removing BoxedRng. For now it is a separate commit. But with that, ObjectSafeRound became extremely close to Round, so I tried removing it completely and make Round itself dyn-safe.

As a result:

  • serializer/deserializer args are merged into BoxedFormat (since we need both in Misbehave, even if the round itself only needs a serializer to serialize messages)
  • Round::finalize has self: Box<Self> as the first parameter instead of just self

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

coveralls commented Feb 16, 2025

Pull Request Test Coverage Report for Build 13443457877

Details

  • 140 of 185 (75.68%) changed or added relevant lines in 9 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.5%) to 72.893%

Changes Missing Coverage Covered Lines Changed/Added Lines %
manul/src/combinators/misbehave.rs 23 25 92.0%
manul/src/protocol/round.rs 10 12 83.33%
manul/src/session/echo.rs 7 9 77.78%
manul/src/session/session.rs 15 18 83.33%
manul/src/session/evidence.rs 8 18 44.44%
manul/src/combinators/chain.rs 33 45 73.33%
manul/src/protocol/boxed_round.rs 24 38 63.16%
Files with Coverage Reduction New Missed Lines %
manul/src/session/evidence.rs 1 53.88%
Totals Coverage Status
Change from base Build 13401865846: -0.5%
Covered Lines: 2162
Relevant Lines: 2966

💛 - Coveralls

@dvdplm
Copy link
Contributor

dvdplm commented Feb 17, 2025

Remove Payload::empty() and instead have receive_message() return Option? The reason for the asymmetry between payloads and artifacts is that receive_message() usually returns a payload, so in most cases users would have to write Some(); while for the artifacts it's the opposite, so it's convenient to be able to just return None.

The only comment I have on this is that we have a fair bit of work to do to design our error handling – in particular what to do about panics and our usage of asserts. Do you think we should return Result here? Is there a risk that we'll end up with Return<Option<T>, OurError> down the line?

Rename object_safe.rs module and ObjectSafeRound, which is obsolete terminology, to something aligning with the new one, which is "dyn compatible"?

I think they now refer to it as "dyn safety". I don't think it's a great name but I think we should use it.

Since crypto-bigint now supports dyn RngCore args in all methods, should we get rid of BoxedRng, and just take dyn RngCore too everywhere?

Sounds reasonable.

@fjarri
Copy link
Member Author

fjarri commented Feb 18, 2025

The only comment I have on this is that we have a fair bit of work to do to design our error handling – in particular what to do about panics and our usage of asserts.

We only have a few outside of dev. Specifically in RoundId methods we can perhaps return LocalError.

Do you think we should return Result here? Is there a risk that we'll end up with Return<Option, OurError> down the line?

What method are you referring to?

@fjarri fjarri marked this pull request as ready for review February 19, 2025 08:11
@fjarri fjarri requested a review from dvdplm February 20, 2025 19:48
@fjarri fjarri changed the title Housekeeping Make Round dyn-safe Feb 20, 2025
@dvdplm
Copy link
Contributor

dvdplm commented Mar 3, 2025

  • Round methods take dyn CryptoRngCore.

I haven't read the code yet, but can you elaborate on why you prefer dyn CryptoRngCore to impl CryptoRngCore? Was there an issue linked to this I should read perhaps?

@fjarri
Copy link
Member Author

fjarri commented Mar 3, 2025

Dyn-safe traits cannot have impl arguments. The Round in this PR basically takes place of ObjectSafeRound which we use in Box<dyn>.

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

Comment on lines +440 to +445
Ok(FinalizeOutcome::AnotherRound(BoxedRound::new_dynamic(ChainedRound::<
Id,
T,
> {
state: ChainState::Protocol2(round),
})))
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe do something like this to help with the wonky formatting here?

Suggested change
Ok(FinalizeOutcome::AnotherRound(BoxedRound::new_dynamic(ChainedRound::<
Id,
T,
> {
state: ChainState::Protocol2(round),
})))
let round = entry_point2.make_round(rng, &shared_randomness, &id)?;
let round = BoxedRound::new_dynamic(ChainedRound::<_, T> {
state: ChainState::Protocol2(round),
});
Ok(FinalizeOutcome::AnotherRound(round))

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.

3 participants