Skip to content

Commit

Permalink
zcash_client_sqlite: Ensure the end heights of SpendsFromAddress re…
Browse files Browse the repository at this point in the history
…quests do not exceed the chain tip.

`lightwalletd` will return an error in the case that the requested end
height exceeds the chain tip. This should be considered a bug in
lightwalletd, but for now we will work around it in the wallet.
  • Loading branch information
nuttycom committed Aug 19, 2024
1 parent 484659d commit 5a32d3b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion zcash_client_sqlite/src/wallet/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ pub(crate) fn transaction_data_requests<P: consensus::Parameters>(
conn: &rusqlite::Connection,
params: &P,
) -> Result<Vec<TransactionDataRequest>, SqliteClientError> {
// `lightwalletd` will return an error for `GetTaddressTxids` requests having an end height
// greater than the current chain tip height, so we take the chain tip height into account
// here in order to make this pothole easier for clients of the API to avoid.
let chain_tip_height = super::chain_tip_height(conn)?;

// We cannot construct address-based transaction data requests for the case where we cannot
// determine the height at which to begin, so we require that either the target height or mined
// height be set.
Expand All @@ -532,11 +537,16 @@ pub(crate) fn transaction_data_requests<P: consensus::Parameters>(
.query_and_then([], |row| {
let address = TransparentAddress::decode(params, &row.get::<_, String>(0)?)?;
let block_range_start = BlockHeight::from(row.get::<_, u32>(1)?);
let max_end_height = block_range_start + DEFAULT_TX_EXPIRY_DELTA + 1;

Check warning on line 540 in zcash_client_sqlite/src/wallet/transparent.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet/transparent.rs#L540

Added line #L540 was not covered by tests

Ok::<TransactionDataRequest, SqliteClientError>(
TransactionDataRequest::SpendsFromAddress {
address,
block_range_start,
block_range_end: Some(block_range_start + DEFAULT_TX_EXPIRY_DELTA + 1),
block_range_end: Some(
chain_tip_height
.map_or(max_end_height, |h| std::cmp::min(h + 1, max_end_height)),

Check warning on line 548 in zcash_client_sqlite/src/wallet/transparent.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_sqlite/src/wallet/transparent.rs#L546-L548

Added lines #L546 - L548 were not covered by tests
),
},
)
})?
Expand Down

0 comments on commit 5a32d3b

Please sign in to comment.