mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-02-07 06:44:11 +00:00
trim stored blocks in the wallet
This commit is contained in:
parent
38393ae0bb
commit
ad15d633ad
@ -545,7 +545,7 @@ impl LightClient {
|
|||||||
// Count how many bytes we've downloaded
|
// Count how many bytes we've downloaded
|
||||||
let bytes_downloaded = Arc::new(AtomicUsize::new(0));
|
let bytes_downloaded = Arc::new(AtomicUsize::new(0));
|
||||||
|
|
||||||
let mut total_reorg = 0u64;
|
let mut total_reorg = 0;
|
||||||
|
|
||||||
// Fetch CompactBlocks in increments
|
// Fetch CompactBlocks in increments
|
||||||
loop {
|
loop {
|
||||||
@ -592,9 +592,9 @@ impl LightClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we're not re-orging too much!
|
// Make sure we're not re-orging too much!
|
||||||
if total_reorg > 99 {
|
if total_reorg > (crate::lightwallet::MAX_REORG - 1) as u64 {
|
||||||
error!("Reorg has now exceeded 100 blocks!");
|
error!("Reorg has now exceeded {} blocks!", crate::lightwallet::MAX_REORG);
|
||||||
return "Reorg has exceeded 100 blocks. Aborting.".to_string();
|
return format!("Reorg has exceeded {} blocks. Aborting.", crate::lightwallet::MAX_REORG);
|
||||||
}
|
}
|
||||||
|
|
||||||
if invalid_height > 0 {
|
if invalid_height > 0 {
|
||||||
|
@ -42,14 +42,13 @@ use crate::LightClientConfig;
|
|||||||
|
|
||||||
use sha2::{Sha256, Digest};
|
use sha2::{Sha256, Digest};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub mod data;
|
pub mod data;
|
||||||
pub mod extended_key;
|
pub mod extended_key;
|
||||||
|
|
||||||
use extended_key::{KeyIndex, ExtendedPrivKey};
|
use extended_key::{KeyIndex, ExtendedPrivKey};
|
||||||
|
|
||||||
const ANCHOR_OFFSET: u32 = 1;
|
const ANCHOR_OFFSET: u32 = 1;
|
||||||
|
pub const MAX_REORG: usize = 100;
|
||||||
|
|
||||||
fn now() -> f64 {
|
fn now() -> f64 {
|
||||||
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as f64
|
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as f64
|
||||||
@ -765,6 +764,8 @@ impl LightWallet {
|
|||||||
.map(|block| block.tree.clone())
|
.map(|block| block.tree.clone())
|
||||||
.unwrap_or(CommitmentTree::new()),
|
.unwrap_or(CommitmentTree::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Create a write lock that will last for the rest of the function.
|
||||||
let mut txs = self.txs.write().unwrap();
|
let mut txs = self.txs.write().unwrap();
|
||||||
|
|
||||||
// Create a Vec containing all unspent nullifiers.
|
// Create a Vec containing all unspent nullifiers.
|
||||||
@ -870,8 +871,18 @@ impl LightWallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store scanned data for this block.
|
{
|
||||||
self.blocks.write().unwrap().push(block_data);
|
let mut blks = self.blocks.write().unwrap();
|
||||||
|
|
||||||
|
// Store scanned data for this block.
|
||||||
|
blks.push(block_data);
|
||||||
|
|
||||||
|
// Trim the old blocks, keeping only as many as needed for a worst-case reorg (i.e. 101 blocks)
|
||||||
|
let len = blks.len();
|
||||||
|
if len > MAX_REORG + 1 {
|
||||||
|
blks.drain(..(len-MAX_REORG+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Print info about the block every 10,000 blocks
|
// Print info about the block every 10,000 blocks
|
||||||
if height % 10_000 == 0 {
|
if height % 10_000 == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user