Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rpc): fix the implementation of get_block_proof for light client #4585

Merged
merged 2 commits into from
Jul 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2115,21 +2115,25 @@ impl Chain {
} else {
let cur_tree_size = (index + 1) * counter;
let maybe_hash = if cur_tree_size > tree_size {
let left_hash = self.get_merkle_tree_node(
index * 2,
level - 1,
counter / 2,
tree_size,
tree_nodes,
)?;
let right_hash = self.reconstruct_merkle_tree_node(
index * 2 + 1,
level - 1,
counter / 2,
tree_size,
tree_nodes,
)?;
Self::combine_maybe_hashes(left_hash, right_hash)
if index * counter <= tree_size {
let left_hash = self.get_merkle_tree_node(
index * 2,
level - 1,
counter / 2,
tree_size,
tree_nodes,
)?;
let right_hash = self.reconstruct_merkle_tree_node(
index * 2 + 1,
level - 1,
counter / 2,
tree_size,
tree_nodes,
)?;
Self::combine_maybe_hashes(left_hash, right_hash)
} else {
None
}
} else {
Some(
*self
Expand Down Expand Up @@ -2216,7 +2220,7 @@ impl Chain {
let mut path = vec![];
let mut tree_nodes = HashMap::new();
let mut iter = tree_size;
while iter >= 1 {
while iter > 1 {
if cur_index % 2 == 0 {
cur_index += 1
} else {
Expand All @@ -2239,7 +2243,7 @@ impl Chain {
path.push(MerklePathItem { hash, direction });
}
cur_index /= 2;
iter /= 2;
iter = (iter + 1) / 2;
level += 1;
counter *= 2;
}
Expand Down