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

RPC module de business logicification #500

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from

Conversation

ceyhunsen
Copy link
Member

@ceyhunsen ceyhunsen commented Feb 5, 2025

Description

This PR moves out business logic code from RPC module.

  • Adds another transportation layer (tokio mpsc channels) between actor modules and rpc module (only for streams) in order to achieve this
  • Maintains async nature of the streams
  • Adds temporary expect() calls for error handling in tokio threads, soon to be fixed by Handling errors in RPC Tokio tasks #502
  • Only required changes to the actual code apart from moving the code
  • Tests are untouched to ensure previous working state is preserved

Linked Issues

core/src/verifier.rs Show resolved Hide resolved
core/src/verifier.rs Outdated Show resolved Hide resolved
@ceyhunsen ceyhunsen self-assigned this Feb 8, 2025
@ceyhunsen ceyhunsen force-pushed the ceyhun/rpc_module_de_business_logicify branch from 1f28e17 to 51a5ae9 Compare February 10, 2025 08:13
@ceyhunsen ceyhunsen added enhancement New feature or request code quality Improves code quality while not affecting any other HOLD MERGE Hold the merge while you see this label and removed HOLD MERGE Hold the merge while you see this label labels Feb 10, 2025
@ceyhunsen ceyhunsen marked this pull request as ready for review February 10, 2025 20:37
Copy link

@mmtftr mmtftr left a comment

Choose a reason for hiding this comment

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

I believe we can write the stream operations more clearly. I've added some improvements. Some may be out of scope but I believe some others are much needed simplification of stream handling in our codebase.

let sig = operator
.signer
.sign_with_tweak(sighash.expect("Expected sig").0, None)
.expect("Error while sigbing with tweak");
Copy link

Choose a reason for hiding this comment

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

why are these panics?

these look very much like recoverable errors. Please return recoverable errors here.

Copy link
Member Author

Choose a reason for hiding this comment

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

All of the new expects should be inside tokio::spawns. Because we didn't decided how we will handle this errors yet, I just left them as is. I think it is better to convert them while working on #502 because Results will be discarded anyways rn. For today, we can identify which line returned an error while testing.

Copy link

Choose a reason for hiding this comment

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

I really can't accept including recoverable errors as panics into the codebase when they can be returned properly. I think it's a matter of our code quality standards that we don't include such code. Panics have the ability to put objects in invalid states.

I also disagree that the first solution #502 is an acceptable solution. Panicking should be reserved for unrecoverable errors.

I can't think of a valid reason to keep panics in. We removed unwraps to avoid panics in our runtime, let's not abuse except for recoverable errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, you are right. Fixed in 0b5f52b.

core/src/operator.rs Show resolved Hide resolved
core/src/rpc/operator.rs Show resolved Hide resolved
core/src/rpc/watchtower.rs Show resolved Hide resolved
let (wpk_channel_tx, wpk_channel_rx) = mpsc::channel(winternitz_public_keys.len());

tokio::spawn(async move {
for wpk in winternitz_public_keys {
Copy link

Choose a reason for hiding this comment

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

I believe the following happens here:

This background task will complete immediately, since the buffer length == total items sent.

If that's the case, this doesn't need to be a background task, simply send the entire vec into the channel within the functino. You know for a fact that it won't block. Since the tx is dropped, the rx will drop values as they're consumed.

In fact, the semantics would be even better if you returned:

ReceiverStream::from(stream::iter(winternitz_public_keys))

which will likely have the same effect but gets rid of the extra background task and all the confusing error handling (which is nothing but handling the closure and early dropping of each stream)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. This approach is only useful if calculations can be made async but in this case it is serial. Fixed in 22a9b2c

@ceyhunsen ceyhunsen requested a review from mmtftr February 11, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Improves code quality while not affecting any other enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants