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 state_getKeys and state_getKeysPaged almost always erroneously returning an empty result #2491

Merged
merged 3 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
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