Print old state on updates
authorMatt Corallo <git@bluematt.me>
Tue, 21 May 2019 02:05:11 +0000 (22:05 -0400)
committerMatt Corallo <git@bluematt.me>
Tue, 21 May 2019 02:36:47 +0000 (22:36 -0400)
src/datastore.rs
src/main.rs

index 4782027e8736eb78c6956ab011f7b1dae690b368..ba984d23ed167e96d84f786b1469ec73f1ddcd3f 100644 (file)
@@ -315,11 +315,11 @@ impl Store {
                }
        }
 
-       pub fn set_node_state(&self, addr: SocketAddr, state: AddressState, services: u64) -> bool {
+       pub fn set_node_state(&self, addr: SocketAddr, state: AddressState, services: u64) -> AddressState {
                let mut nodes_lock = self.nodes.write().unwrap();
                let nodes = nodes_lock.borrow_mut();
                let state_ref = nodes.nodes_to_state.get_mut(&addr).unwrap();
-               let ret = state != state_ref.state;
+               let ret = state_ref.state;
                let now = Instant::now();
                if (state_ref.state == AddressState::Good || state_ref.state == AddressState::WasGood)
                                && state != AddressState::Good
index a6b71556b558d638607cbe71f0dd62a3e109ccc9..94c7ab813ab00ff41a65eca0eaf7cbcc03712adc 100644 (file)
@@ -173,13 +173,15 @@ pub fn scan_node(scan_time: Instant, node: SocketAddr) {
                let state_lock = final_peer_state.lock().unwrap();
                if state_lock.recvd_version && state_lock.recvd_verack &&
                                state_lock.recvd_addrs && state_lock.recvd_block {
-                       if store.set_node_state(node, AddressState::Good, state_lock.node_services) && state_lock.msg.0 != "" {
-                               printer.add_line(state_lock.msg.0.clone(), state_lock.msg.1);
+                       let old_state = store.set_node_state(node, AddressState::Good, state_lock.node_services);
+                       if old_state != AddressState::Good && state_lock.msg.0 != "" {
+                               printer.add_line(state_lock.msg.0.clone() + " from " + old_state.to_str(), state_lock.msg.1);
                        }
                } else {
                        assert!(state_lock.fail_reason != AddressState::Good);
-                       if store.set_node_state(node, state_lock.fail_reason, 0) && state_lock.msg.0 != "" {
-                               printer.add_line(state_lock.msg.0.clone(), state_lock.msg.1);
+                       let old_state = store.set_node_state(node, state_lock.fail_reason, 0);
+                       if old_state != state_lock.fail_reason && state_lock.msg.0 != "" {
+                               printer.add_line(state_lock.msg.0.clone() + " from " + old_state.to_str(), state_lock.msg.1);
                        }
                }
                future::ok(())