Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Bug fix where some sapling tree was not verified
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Jun 29, 2021
1 parent f1e872e commit 064ef1c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,8 +1055,8 @@ impl LightClient {
return Ok(true);
}

// Get the first block's details, and make sure we can compute it from the last checkpoint
// Note that we get the first block in the wallet (Not the last one). This is expected to be tip - 100 blocks.
// Get the oldest block's details, and make sure we can compute it from the last checkpoint
// Note that we get the oldest block in the wallet (Not the latest one). This is expected to be tip - 100 blocks.
// We use this block to prevent any reorg risk.
let (end_height, _, end_tree) = match self.wallet.get_wallet_sapling_tree(NodePosition::Oldest).await {
Ok(r) => r,
Expand All @@ -1079,10 +1079,12 @@ impl LightClient {
self.wallet.set_sapling_tree_verified();
} else {
warn!("Sapling tree verification failed!");
warn!(
let e = format!(
"Verification Results:\nCalculated\n{}\nExpected\n{}\n",
start_tree, end_tree
);
warn!("{}", e);
return Err(e);
}

return Ok(verified);
Expand All @@ -1100,7 +1102,8 @@ impl LightClient {

let h1 = tokio::spawn(async move {
let grpc_conn = GrpcConnector::new(uri);
grpc_conn.get_block_range(start_height, end_height, tx).await
// Since both start and end block are inclusive, do start_height+1 to end_height
grpc_conn.get_block_range(start_height + 1, end_height, tx).await
});

let commit_tree = commit_tree_computed.clone();
Expand Down Expand Up @@ -1140,10 +1143,16 @@ impl LightClient {
self.wallet.set_sapling_tree_verified();
} else {
warn!("Sapling tree verification failed!");
warn!(
"Verification Results:\nCalculated\n{}\nExpected\n{}\n",
computed_tree, end_tree
let e = format!(
"Verification Results:\nComputed@{}-{}\n{}\nExpected@{}\n{}\n",
start_height + 1,
end_height,
computed_tree,
end_height,
end_tree
);
warn!("{}", e);
return Err(e);
}

return Ok(verified);
Expand Down

0 comments on commit 064ef1c

Please sign in to comment.