-
Notifications
You must be signed in to change notification settings - Fork 67
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
Update our state upon broadcasting a transaction #1010
Update our state upon broadcasting a transaction #1010
Conversation
b699d7c
to
0963c0a
Compare
// Finally, update our state with the changes from this transaction. | ||
let (tx, rx) = mpsc::channel(); | ||
if let Err(e) = self.poller_sender.send(PollerMessage::PollNow(tx)) { | ||
log::error!("Error requesting update from poller: {}", e); |
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 think it is not useful to make the broadcast command wait for the return of the poller, the broadcast did happen since the bitcoind received the tx to broadcast, and the notification to poll now makes the lapse of time of "unsync" db very very short, but If you prefer it, I am ok with it
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'm not sure to follow. Not waiting for the completion of the poll introduces a significant race condition (we'll probably return before the poll is complete), which makes the whole point of doing this moot?
8eead79
to
c9b4e3d
Compare
This is inspired from the work in wizardsardine#909 (specifically wizardsardine@d8c59e3) to externalize the management of the poller thread. However, there may be only one poller thread. Starting more than one can lead to a crash or potentially to data corruption. Therefore it feels safer to manage it internally. Instead of exposing the management of the poller to the user of the library, we manage both threads inside the `DaemonHandle` data structure and expose a way for a user to check for errors which may have occured in any of the threads. This makes it possible to: 1. Eventually propagate errors from the threads to the user of the daemon (wizardsardine#909); 2. Communicate internally with the poller thread, for instance to trigger a poll immediately (following commits).
We now provide a way for a user of the daemon to poll for errors in the threads, so aborting the process on a thread panic shouldn't be necessary anymore.
c9b4e3d
to
38ff395
Compare
0ffcad8
to
4836dd0
Compare
We'll need to ask the poller thread another thing besides to shut down, so it's cleaner to start using proper messages. The mpsc channel in the std lib was buggy for awhile but since they merged crossbeam and are using this behind the hood now it should be fine starting with Rust 1.67. That's (slightly) higher than our MSRV but it's what we use for releases so that's reasonable. See rust-lang/rust#39364 for details.
This is a temporary hack. We should improve this API.
4836dd0
to
58c71c7
Compare
ACK 58c71c7 -- did another pass and Edouard tested this in the GUI. |
Fixes #887.
This takes a couple commits from #909 but takes the approach from there in another direction: we don't externalize the poller, since only a single instance must be ran. Instead we properly keep track of the (up to) two threads we manage in the
DaemonHandle
and provide a way for a user of the library to check for errors in any of the threads.This approach allows us to 1) communicate with the poller thread from inside the Liana library/daemon (here we leverage this to tell it to poll) 2) eventually (#909) expose all internal errors from the library to the user instead of panic'ing internally.
See the commit messages for details.