[#751] add support for rewind_to_height to FsBlockDb

Closes #751

Ran `cargo fmt`

return the result as an error rather than unwrap

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
This commit is contained in:
Francisco Gindre 2023-01-11 20:07:21 -03:00
parent b83355f7a3
commit 7306b9d2a9
3 changed files with 31 additions and 1 deletions

View File

@ -6,7 +6,13 @@ and this library adheres to Rust's notion of
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- `zcash_client_sqlite::FsBlockDb::rewind_to_height` rewinds the BlockMeta Db
to the specified height following the same logic as homonymous functions on
`WalletDb`. This function does not delete the files referenced by the rows
that might be present and are deleted by this function call.
- `zcash_client_sqlite::chain::blockmetadb_rewind_to_height` implementation
of the function above.
## [0.4.2] - 2022-12-13
### Fixed
- `zcash_client_sqlite::WalletDb::get_transparent_balances` no longer returns an

View File

@ -139,6 +139,16 @@ pub(crate) fn blockmetadb_insert(
}
}
#[cfg(feature = "unstable")]
pub(crate) fn blockmetadb_rewind_to_height(
conn: &Connection,
block_height: BlockHeight,
) -> Result<(), rusqlite::Error> {
conn.prepare("DELETE FROM compactblocks_meta WHERE height > ?")?
.execute(params![u32::from(block_height)])?;
Ok(())
}
#[cfg(feature = "unstable")]
pub(crate) fn blockmetadb_get_max_cached_height(
conn: &Connection,

View File

@ -929,6 +929,20 @@ impl FsBlockDb {
Ok(chain::blockmetadb_insert(&self.conn, block_meta)?)
}
/// Rewinds the BlockMeta Db to the `block_height` provided.
///
/// This doesn't delete any files referenced by the records
/// stored in BlockMeta.
///
/// If the requested height is greater than or equal to the height
/// of the last scanned block, or if the DB is empty, this function
/// does nothing.
pub fn rewind_to_height(&self, block_height: BlockHeight) -> Result<(), FsBlockDbError> {
Ok(chain::blockmetadb_rewind_to_height(
&self.conn,
block_height,
)?)
}
}
#[cfg(feature = "unstable")]