cloudhead / nakamoto

Privacy-preserving Bitcoin light-client implementation in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash on First Run

DON-MAC-256 opened this issue · comments

Running the node for the first time results in a crash. The root of the issue lies in the logic for determining the success of the event::Subscriber::publish function.

impl<T: Clone> Subscriber<T> {
    pub fn publish(&self, event: T) -> bool {
        let mut subs = self.subscribers.lock().unwrap();
        subs.retain(|s| s.try_send(event.clone()).is_ok());
        subs.is_empty().not()
    }
}

If there are no subscribers at the time of this call, then failure is returned. This is the case for the loading subscriber in the client.

Workaround:

impl<T: Clone> Subscriber<T> {
    pub fn publish(&self, event: T) -> bool {
        let mut subs = self.subscribers.lock().unwrap();
+++     if subs.is_empty() {
+++         return true;
+++     }
        subs.retain(|s| s.try_send(event.clone()).is_ok());
        subs.is_empty().not()
    }
}

Nice catch, yeah this was recently added and indeed interrupts the node if there is no subscriber. I need to however find a proper solution.

Potential fix here: #114

Closed with #114