Skip to content

Commit

Permalink
Fix state_getKeys and state_getKeysPaged almost always erroneousl…
Browse files Browse the repository at this point in the history
…y returning an empty result (#2491)

* Fix `state_getKeys` and `state_getKeysPaged` almost always erroneously returning an empty result

* PR number

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
tomaka and mergify[bot] authored Jul 11, 2022
1 parent b38bf70 commit 40266c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- Fix `state_getKeys` and `state_getKeysPaged` almost always erroneously returning an empty result. ([#2491](https://github.com/paritytech/smoldot/pull/2491))

## 0.6.22 - 2022-07-11

### Changed
Expand Down
15 changes: 9 additions & 6 deletions src/trie/prefix_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
// TODO: usage example

// TODO: this code is entirely untested; no idea if it works

use super::{nibble, proof_verify};

use alloc::{vec, vec::Vec};
Expand Down Expand Up @@ -89,6 +87,7 @@ impl PrefixScan {
// Controls whether we continue iterating.
let mut any_successful_proof = false;

debug_assert!(!self.next_queries.is_empty());
for query in &self.next_queries {
let info = match proof_verify::trie_node_info(proof_verify::TrieNodeInfoConfig {
requested_key: query.iter().copied(),
Expand Down Expand Up @@ -128,6 +127,14 @@ impl PrefixScan {
}
}

// If we have failed to make any progress during this iteration, return `InProgress`.
if !any_successful_proof {
debug_assert!(next.is_empty());
// Errors are immediately returned if `is_first_iteration`.
debug_assert!(!is_first_iteration);
break;
}

// Finished when nothing more to request.
if next.is_empty() {
return Ok(ResumeOutcome::Success {
Expand All @@ -137,10 +144,6 @@ impl PrefixScan {

// Update `next_queries` for the next iteration.
self.next_queries = next;

if !any_successful_proof {
break;
}
}

Ok(ResumeOutcome::InProgress(self))
Expand Down

0 comments on commit 40266c8

Please sign in to comment.