Merge pull request #644 from zcash/fix-fsblockdb-cached-height

zcash_client_sqlite: Fix `FsBlockDb::get_max_cached_height`
This commit is contained in:
Kris Nuttycombe 2022-09-16 21:19:25 -06:00 committed by GitHub
commit d1f0c12c02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -12,7 +12,7 @@ use crate::{error::SqliteClientError, BlockDb};
#[cfg(feature = "unstable")]
use {
crate::{BlockHash, FsBlockDb},
rusqlite::{Connection, OptionalExtension, NO_PARAMS},
rusqlite::{Connection, NO_PARAMS},
std::fs::File,
std::io::BufReader,
std::path::{Path, PathBuf},
@ -149,11 +149,12 @@ pub(crate) fn blockmetadb_get_max_cached_height(
"SELECT MAX(height) FROM compactblocks_meta",
NO_PARAMS,
|row| {
let h: u32 = row.get(0)?;
Ok(BlockHeight::from(h))
// `SELECT MAX(_)` will always return a row, but it will return `null` if the
// table is empty, which has no integer type. We handle the optionality here.
let h: Option<u32> = row.get(0)?;
Ok(h.map(BlockHeight::from))
},
)
.optional()
}
/// Implements a traversal of `limit` blocks of the filesystem-backed