zcash_client_sqlite
: BlockSource::with_blocks
impls behave unintuitively with from_height
set to an unknown block
#892
Labels
BlockSource::with_blocks
is documented thusly:librustzcash/zcash_client_backend/src/data_api/chain.rs
Lines 198 to 200 in 81d1928
The documentation is clear that
from_height = Some(h)
means "scan from heighth
", whilefrom_height = None
means "scan from the first available block". However, it is not clear what should happen iffrom_height = Some(h)
buth
is unknown to the cache.The implementations of this trait in
zcash_client_sqlite
behave similarly to theNone
case: up tolimit
blocks are made available starting from the first block with height>= h
that the cache knows about. This is due to the following SQL query being used:librustzcash/zcash_client_sqlite/src/chain.rs
Lines 43 to 54 in 81d1928
(and equivalently for
FsBlockDb
).This behaviour crept in across several refactors:
scan_cached_blocks
queried it inline.with_blocks
method was factored out in 06c1772#diff-e9ee9345e22f7472adbe04051828e130308ab243f6ae047321ce4f70ee9e4abbR115 (as part of Data Access API (Low-level wallet persistence API) #307), but still passing in the inline-queriedfrom_height
insidescan_cached_blocks
.from_height
was replaced with ascan_cached_blocks
argument in 3e358bc (as part of Migrations & data storage for pre-DAG-sync #831).from_height
needed to be passed in by the mobile SDKs (e.g. Electric-Coin-Company/zcash-swift-wallet-sdk@6eb3956), causing bugs therein to be exposed to the Rust layer.I found this issue because in some tests, the iOS SDK incorrectly set
from_height = 0
as a side-effect of earlier logic, but due to the unintuitive behaviour of theFsBlockDb::with_blocks
impl, it "self-corrected" to the intended first block in the database, hiding the bug (until it was exposed due to the change to move continuity testing intoscan_cached_blocks
).We need to decide what the intended behaviour of
BlockSource::with_blocks
is, and then ensure that the documentation and implementations are consistent with it.The text was updated successfully, but these errors were encountered: