initiate a regular sync to catch up with updates and import new addresses (no rescan)
(&mut self)
| 85 | |
| 86 | // initiate a regular sync to catch up with updates and import new addresses (no rescan) |
| 87 | pub fn sync(&mut self) -> Result<Vec<IndexChange>> { |
| 88 | let mut changelog = Changelog::new(self.tip.is_some()); |
| 89 | |
| 90 | // detect reorgs and sync the whole history from scratch when they happen |
| 91 | // XXX the reorg test is racey |
| 92 | if let Some(BlockId(tip_height, ref tip_hash)) = self.tip { |
| 93 | let best_chain_hash = self.rpc.get_block_hash(tip_height as u64)?; |
| 94 | if best_chain_hash != *tip_hash { |
| 95 | warn!( |
| 96 | "reorg detected, block height {} was {} and now is {}. fetching history from scratch...", |
| 97 | tip_height, tip_hash, best_chain_hash |
| 98 | ); |
| 99 | |
| 100 | // notify clients about the reorg, but don't collect additional events (apart from |
| 101 | // ChainTip, added below) |
| 102 | changelog.push(|| IndexChange::Reorg(tip_height, *tip_hash, best_chain_hash)); |
| 103 | changelog.track = false; |
| 104 | |
| 105 | // XXX start syncing from N blocks backs instead of from the beginning? |
| 106 | self.tip = None; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | let synced_tip = self.sync_transactions(false, &mut changelog)?; |
| 111 | let tip_updated = self.tip != Some(synced_tip); |
| 112 | self.sync_mempool(/*force_refresh=*/ tip_updated); |
| 113 | self.watcher.do_imports(&self.rpc, /*rescan=*/ false)?; |
| 114 | |
| 115 | let mut changelog = changelog.into_vec(); |
| 116 | |
| 117 | if tip_updated { |
| 118 | info!( |
| 119 | "synced up to height {}{}", |
| 120 | synced_tip.0, |
| 121 | iif!(changelog.is_empty(), "", " (found wallet activity)") |
| 122 | ); |
| 123 | |
| 124 | changelog.push(IndexChange::ChainTip(synced_tip)); |
| 125 | self.tip = Some(synced_tip); |
| 126 | } |
| 127 | |
| 128 | if !changelog.is_empty() && log_enabled!(log::Level::Debug) { |
| 129 | for update in &changelog { |
| 130 | debug!(" - {:?}", update); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | Ok(changelog) |
| 135 | } |
| 136 | |
| 137 | fn sync_transactions( |
| 138 | &mut self, |
nothing calls this directly
no test coverage detected