Separate rewind from rescan
This commit is contained in:
parent
c30f2bb7f3
commit
e530ac1104
|
@ -64,7 +64,9 @@ char *send_multi_payment(char *recipients_json,
|
||||||
|
|
||||||
void skip_to_last_height(uint8_t coin);
|
void skip_to_last_height(uint8_t coin);
|
||||||
|
|
||||||
uint32_t rewind_to_height(uint32_t height, bool exact);
|
uint32_t rewind_to(uint32_t height);
|
||||||
|
|
||||||
|
void rescan_from(uint32_t height);
|
||||||
|
|
||||||
int64_t mempool_sync(void);
|
int64_t mempool_sync(void);
|
||||||
|
|
||||||
|
|
|
@ -328,8 +328,15 @@ pub async unsafe extern "C" fn skip_to_last_height(coin: u8) {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub async unsafe extern "C" fn rewind_to_height(height: u32, exact: bool) -> u32 {
|
pub async unsafe extern "C" fn rewind_to(height: u32) -> u32 {
|
||||||
let res = crate::api::sync::rewind_to_height(height, exact).await;
|
let res = crate::api::sync::rewind_to(height).await;
|
||||||
|
log_result(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
#[no_mangle]
|
||||||
|
pub async unsafe extern "C" fn rescan_from(height: u32) {
|
||||||
|
let res = crate::api::sync::rescan_from(height).await;
|
||||||
log_result(res)
|
log_result(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,16 +94,20 @@ pub async fn skip_to_last_height(coin: u8) -> anyhow::Result<()> {
|
||||||
// and get the tree_state from the server
|
// and get the tree_state from the server
|
||||||
// this option is used when we rescan from a given height
|
// this option is used when we rescan from a given height
|
||||||
// We ignore any transaction that occurred before
|
// We ignore any transaction that occurred before
|
||||||
pub async fn rewind_to_height(height: u32, exact: bool) -> anyhow::Result<u32> {
|
pub async fn rewind_to(height: u32) -> anyhow::Result<u32> {
|
||||||
let c = CoinConfig::get_active();
|
let c = CoinConfig::get_active();
|
||||||
let height = c.db()?.trim_to_height(height, exact)?;
|
let height = c.db()?.trim_to_height(height)?;
|
||||||
if exact {
|
|
||||||
let mut client = c.connect_lwd().await?;
|
|
||||||
fetch_and_store_tree_state(c.coin, &mut client, height).await?;
|
|
||||||
}
|
|
||||||
Ok(height)
|
Ok(height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn rescan_from(height: u32) -> anyhow::Result<()> {
|
||||||
|
let c = CoinConfig::get_active();
|
||||||
|
c.db()?.truncate_sync_data()?;
|
||||||
|
let mut client = c.connect_lwd().await?;
|
||||||
|
fetch_and_store_tree_state(c.coin, &mut client, height).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn fetch_and_store_tree_state(
|
async fn fetch_and_store_tree_state(
|
||||||
coin: u8,
|
coin: u8,
|
||||||
client: &mut CompactTxStreamerClient<Channel>,
|
client: &mut CompactTxStreamerClient<Channel>,
|
||||||
|
|
|
@ -441,7 +441,6 @@ impl DecryptNode {
|
||||||
blocks: Vec<CompactBlock>,
|
blocks: Vec<CompactBlock>,
|
||||||
) -> Vec<DecryptedBlock> {
|
) -> Vec<DecryptedBlock> {
|
||||||
let use_gpu = { *USE_GPU.lock().unwrap() };
|
let use_gpu = { *USE_GPU.lock().unwrap() };
|
||||||
log::info!("use gpu = {}", use_gpu);
|
|
||||||
if use_gpu {
|
if use_gpu {
|
||||||
#[cfg(feature = "cuda")]
|
#[cfg(feature = "cuda")]
|
||||||
return self.cuda_decrypt_blocks(network, blocks);
|
return self.cuda_decrypt_blocks(network, blocks);
|
||||||
|
|
28
src/db.rs
28
src/db.rs
|
@ -207,21 +207,17 @@ impl DbAdapter {
|
||||||
Ok(fvks)
|
Ok(fvks)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trim_to_height(&mut self, height: u32, exact: bool) -> anyhow::Result<u32> {
|
pub fn trim_to_height(&mut self, height: u32) -> anyhow::Result<u32> {
|
||||||
// snap height to an existing checkpoint
|
// snap height to an existing checkpoint
|
||||||
let height = if exact {
|
let height = self.connection.query_row(
|
||||||
height
|
"SELECT MAX(height) from blocks WHERE height <= ?1",
|
||||||
} else {
|
params![height],
|
||||||
let height = self.connection.query_row(
|
|row| {
|
||||||
"SELECT MAX(height) from blocks WHERE height <= ?1",
|
let height: Option<u32> = row.get(0)?;
|
||||||
params![height],
|
Ok(height)
|
||||||
|row| {
|
},
|
||||||
let height: Option<u32> = row.get(0)?;
|
)?;
|
||||||
Ok(height)
|
let height = height.unwrap_or(0);
|
||||||
},
|
|
||||||
)?;
|
|
||||||
height.unwrap_or(0)
|
|
||||||
};
|
|
||||||
log::info!("Rewind to height: {}", height);
|
log::info!("Rewind to height: {}", height);
|
||||||
|
|
||||||
let tx = self.connection.transaction()?;
|
let tx = self.connection.transaction()?;
|
||||||
|
@ -825,7 +821,7 @@ impl DbAdapter {
|
||||||
pub fn delete_incomplete_scan(&mut self) -> anyhow::Result<()> {
|
pub fn delete_incomplete_scan(&mut self) -> anyhow::Result<()> {
|
||||||
let synced_height = self.get_last_sync_height()?;
|
let synced_height = self.get_last_sync_height()?;
|
||||||
if let Some(synced_height) = synced_height {
|
if let Some(synced_height) = synced_height {
|
||||||
self.trim_to_height(synced_height, true)?;
|
self.trim_to_height(synced_height)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1060,7 +1056,7 @@ impl DbAdapter {
|
||||||
}
|
}
|
||||||
self.connection.execute("INSERT INTO blocks(height,hash,timestamp,sapling_tree) VALUES (?1,?2,?3,?4) ON CONFLICT(height) DO NOTHING",
|
self.connection.execute("INSERT INTO blocks(height,hash,timestamp,sapling_tree) VALUES (?1,?2,?3,?4) ON CONFLICT(height) DO NOTHING",
|
||||||
params![account_info.height, hex::decode(&account_info.hash)?, account_info.timestamp, hex::decode(&account_info.sapling_tree)?])?;
|
params![account_info.height, hex::decode(&account_info.hash)?, account_info.timestamp, hex::decode(&account_info.sapling_tree)?])?;
|
||||||
self.trim_to_height(account_info.height, true)?;
|
self.trim_to_height(account_info.height)?;
|
||||||
Ok(ids)
|
Ok(ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ pub async fn sync(offset: Option<u32>) -> Result<(), Error> {
|
||||||
|
|
||||||
#[post("/rewind?<height>")]
|
#[post("/rewind?<height>")]
|
||||||
pub async fn rewind(height: u32) -> Result<(), Error> {
|
pub async fn rewind(height: u32) -> Result<(), Error> {
|
||||||
warp_api_ffi::api::sync::rewind_to_height(height).await?;
|
warp_api_ffi::api::sync::rewind_to(height).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue