-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: dev
Are you sure you want to change the base?
Conversation
1f28e17
to
51a5ae9
Compare
There was a problem hiding this 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.
core/src/operator.rs
Outdated
let sig = operator | ||
.signer | ||
.sign_with_tweak(sighash.expect("Expected sig").0, None) | ||
.expect("Error while sigbing with tweak"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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::spawn
s. 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 Result
s will be discarded anyways rn. For today, we can identify which line returned an error while testing.
There was a problem hiding this comment.
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 unwrap
s to avoid panics in our runtime, let's not abuse except
for recoverable errors.
There was a problem hiding this comment.
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/watchtower.rs
Outdated
let (wpk_channel_tx, wpk_channel_rx) = mpsc::channel(winternitz_public_keys.len()); | ||
|
||
tokio::spawn(async move { | ||
for wpk in winternitz_public_keys { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
Description
This PR moves out business logic code from RPC module.
expect()
calls for error handling in tokio threads, soon to be fixed by Handling errors in RPC Tokio tasks #502Linked Issues