Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 34 additions & 24 deletions client/src/cbf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use spaces_wallet::bdk_wallet::{KeychainKind, Update};
use spaces_wallet::bitcoin::bip158::BlockFilter;
use spaces_wallet::bitcoin::ScriptBuf;
use spaces_wallet::SpacesWallet;
use crate::calc_progress;
use crate::client::{BlockSource, BlockchainInfo};
use crate::source::BitcoinBlockSource;
use crate::wallets::WalletProgressUpdate;
use crate::wallets::{WalletStatus, WalletProgressUpdate};

pub struct CompactFilterSync {
graph: IndexedTxGraph<ConfirmationBlockTime, KeychainTxOutIndex<KeychainKind>>,
Expand All @@ -29,7 +30,7 @@ pub struct CompactFilterSync {
total_filters: u32,
wait: Option<Instant>,
state: SyncState,
filters_queued: bool
filters_queued: bool,
}

enum SyncState {
Expand Down Expand Up @@ -136,7 +137,7 @@ impl CompactFilterSync {
}
if info.headers != info.blocks {
info!("Source still syncing, retrying...");
*progress = WalletProgressUpdate::Syncing;
*progress = WalletProgressUpdate::new(WalletStatus::Syncing, None);
self.wait = Some(Instant::now());
return Ok(());
}
Expand All @@ -147,10 +148,16 @@ impl CompactFilterSync {
}

info!("Filters syncing, retrying...");
*progress = WalletProgressUpdate::CbfFilterSync {
total: info.filter_headers.unwrap_or(0),
completed: info.filters.unwrap_or(0),
};
*progress = WalletProgressUpdate::new(WalletStatus::CbfFilterSync, Some(
calc_progress(
info.checkpoint.map(|c| c.height).unwrap_or(0),
info.filters.unwrap_or(0),
std::cmp::max(
info.prune_height.unwrap_or(0),
info.filter_headers.unwrap_or(0)
),
)
));
self.wait = Some(Instant::now());
return Ok(());
}
Expand Down Expand Up @@ -205,10 +212,12 @@ impl CompactFilterSync {
} else {
info!("wallet({}) processed block filter {} - no match", wallet.name(), height);
}
*progress = WalletProgressUpdate::CbfProcessFilters {
total: self.total_filters,
completed: self.total_filters - self.queued_filters.len() as u32,
};

let completed = self.total_filters as f32 - self.queued_filters.len() as f32;
*progress = WalletProgressUpdate::new(
WalletStatus::CbfProcessFilters,
Some(completed / self.total_filters as f32)
);
}
SyncState::QueueBlocks => {
if !self.queued_blocks.is_empty() {
Expand All @@ -231,12 +240,12 @@ impl CompactFilterSync {
// The client has a global state for pending blocks in the queue
// so we cap it just in case other things are queuing blocks
// at the same time
let pending = std::cmp::min(status.pending, self.block_matches);
*progress = WalletProgressUpdate::CbfDownloadMatchingBlocks {
total: self.block_matches,
completed: self.block_matches - pending,
};

let pending = std::cmp::min(status.pending, self.block_matches) as f32;
let completed = self.block_matches as f32 - pending;
*progress = WalletProgressUpdate::new(
WalletStatus::CbfDownloadMatchingBlocks,
Some(completed / self.block_matches as f32)
);
self.wait = Some(Instant::now());
return Ok(());
}
Expand All @@ -251,7 +260,7 @@ impl CompactFilterSync {
SyncState::ProcessBlocks => {
let (height, hash) = match self.queued_blocks.pop_first() {
None => {
*progress = WalletProgressUpdate::CbfApplyUpdate;
*progress = WalletProgressUpdate::new(WalletStatus::CbfApplyUpdate, None);
self.state = SyncState::ApplyUpdate;
return Ok(());
}
Expand All @@ -262,10 +271,11 @@ impl CompactFilterSync {
.ok_or(anyhow!("block {} {} not found", height, hash))?;
self.chain_changeset.insert(height, Some(hash));
let _ = self.graph.apply_block_relevant(&block, height);
*progress = WalletProgressUpdate::CbfProcessMatchingBlocks {
total: self.block_matches,
completed: self.block_matches - self.queued_blocks.len() as u32 ,
};
let completed = self.block_matches - self.queued_blocks.len() as u32;
*progress = WalletProgressUpdate::new(
WalletStatus::CbfProcessMatchingBlocks,
Some(completed as f32 / self.block_matches as f32)
);
}
SyncState::ApplyUpdate => {
info!("wallet({}): updating wallet tip to {}", wallet.name(), self.filters_tip);
Expand All @@ -280,9 +290,9 @@ impl CompactFilterSync {
info!("wallet({}): compact filter sync portion complete at {}", wallet.name(), self.filters_tip);
self.state = SyncState::Synced;
// Only CBF portion is done
*progress = WalletProgressUpdate::Syncing
*progress = WalletProgressUpdate::new(WalletStatus::Syncing, None);
}
SyncState::Synced => {},
SyncState::Synced => {}
}
Ok(())
}
Expand Down
43 changes: 23 additions & 20 deletions client/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
rpc::ServerInfo,
wallets::{ListSpacesResponse, TxInfo, TxResponse, WalletResponse},
};
use crate::wallets::{WalletInfoWithProgress, WalletProgressUpdate};
use crate::wallets::{WalletInfoWithProgress, WalletStatus};

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, ValueEnum, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
Expand Down Expand Up @@ -188,36 +188,39 @@ pub fn print_wallet_info(prog: WalletInfoWithProgress, format: Format) {

// Print sync status
println!(" Sync Status:");
match prog.status {
WalletProgressUpdate::SourceSync { total, completed } => {
println!(" Source Syncing: {}/{} ({:.1}%)", completed, total,
(completed as f64 / total as f64) * 100.0);
let p = prog.sync.progress.unwrap_or(0.0);
match prog.sync.status {
WalletStatus::HeadersSync => {
println!(" Syncing block headers");
}
WalletProgressUpdate::CbfFilterSync { total, completed } => {
println!(" Filters Syncing: {}/{} ({:.1}%)", completed, total,
(completed as f64 / total as f64) * 100.0);
WalletStatus::ChainSync => {
println!(" Chain Syncing: {:.1}%", p * 100.0);
}
WalletProgressUpdate::CbfProcessFilters { total, completed } => {
println!(" Processing Filters: {}/{} ({:.1}%)", completed, total,
(completed as f64 / total as f64) * 100.0);
WalletStatus::SpacesSync => {
println!(" Spaces Syncing: {:.1}%", p * 100.0);
}
WalletProgressUpdate::CbfDownloadMatchingBlocks { total, completed } => {
println!(" Downloading Matching Blocks: {}/{} ({:.1}%)", completed, total,
(completed as f64 / total as f64) * 100.0);
WalletStatus::CbfFilterSync => {
println!(" Filters Syncing: {:.1}%", p * 100.0);
}
WalletProgressUpdate::CbfProcessMatchingBlocks { total, completed } => {
println!(" Processing Matching Blocks: {}/{} ({:.1}%)", completed, total,
(completed as f64 / total as f64) * 100.0);
WalletStatus::CbfProcessFilters => {
println!(" Processing Filters: {:.1}%", p* 100.0);
}
WalletProgressUpdate::Syncing => {
WalletStatus::CbfDownloadMatchingBlocks => {
println!(" Downloading Matching Blocks: {:.1}%", p * 100.0);
}
WalletStatus::CbfProcessMatchingBlocks => {
println!(" Processing Matching Blocks: {:.1}%",p * 100.0);
}
WalletStatus::Syncing => {
println!(" Syncing: In progress ({:.1}%):", prog.info.progress * 100.0);
}
WalletProgressUpdate::CbfApplyUpdate => {
WalletStatus::CbfApplyUpdate => {
println!(" Applying compact filters update");
}
WalletProgressUpdate::Complete => {
WalletStatus::Complete => {
println!(" Complete");
}

}

println!();
Expand Down
Loading
Loading