Merge pull request #756 from zcash/blockmeta_rewind_to_height
[#751] add support for rewind_to_height to FsBlockDb
This commit is contained in:
commit
5d62b68d70
|
@ -6,9 +6,19 @@ 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.
|
||||
|
||||
### Changed
|
||||
- MSRV is now 1.60.0.
|
||||
|
||||
|
||||
## [0.4.2] - 2022-12-13
|
||||
### Fixed
|
||||
- `zcash_client_sqlite::WalletDb::get_transparent_balances` no longer returns an
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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")]
|
||||
|
|
Loading…
Reference in New Issue