Add varialized interval for intermediate saving during updates
This commit is contained in:
parent
9a0746172f
commit
c3409c4460
@ -21,7 +21,6 @@ impl<'a> WasmSpScanner<'a> {
|
|||||||
owned_outpoints: HashSet<OutPoint>,
|
owned_outpoints: HashSet<OutPoint>,
|
||||||
keep_scanning: &'a AtomicBool,
|
keep_scanning: &'a AtomicBool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
log::info!("Creating WasmSpScanner");
|
|
||||||
Self {
|
Self {
|
||||||
client,
|
client,
|
||||||
updater,
|
updater,
|
||||||
@ -42,6 +41,9 @@ impl<'a> WasmSpScanner<'a> {
|
|||||||
let mut update_time = Instant::now();
|
let mut update_time = Instant::now();
|
||||||
let mut stream = block_data_stream;
|
let mut stream = block_data_stream;
|
||||||
|
|
||||||
|
let save_interval = 10;
|
||||||
|
let mut blocks_scanned = 1;
|
||||||
|
|
||||||
while let Some(blockdata) = stream.next().await {
|
while let Some(blockdata) = stream.next().await {
|
||||||
let blockdata = blockdata?;
|
let blockdata = blockdata?;
|
||||||
let blkheight = blockdata.blkheight;
|
let blkheight = blockdata.blkheight;
|
||||||
@ -55,8 +57,8 @@ impl<'a> WasmSpScanner<'a> {
|
|||||||
|
|
||||||
let mut save_to_storage = false;
|
let mut save_to_storage = false;
|
||||||
|
|
||||||
// always save on last block or after 30 seconds since last save
|
// always save on last block or after scanning some number of blocks
|
||||||
if blkheight == end || update_time.elapsed() > Duration::from_secs(30) {
|
if blkheight == end || blocks_scanned % save_interval == 0 {
|
||||||
save_to_storage = true;
|
save_to_storage = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +81,8 @@ impl<'a> WasmSpScanner<'a> {
|
|||||||
self.save_state()?;
|
self.save_state()?;
|
||||||
update_time = Instant::now();
|
update_time = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blocks_scanned += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user