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

Return error when unpinning duplicate hashes #1728

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
59 changes: 46 additions & 13 deletions light-base/src/json_rpc_service/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2333,22 +2333,55 @@ pub(super) async fn run<TPlat: PlatformRef>(
}
};

// TODO: what if duplicate hashes
if !all_hashes
.clone()
.all(|hash| subscription.pinned_blocks_headers.contains_key(hash))
{
let _ = me
.responses_tx
.send(parse::build_error_response(
request_id_json,
parse::ErrorResponse::InvalidParams,
None,
))
.await;
let checks_passed = {
let mut dedup_check = hashbrown::HashSet::with_capacity_and_hasher(
0,
SipHasherBuild::new({
let mut seed = [0; 16];
me.randomness.fill_bytes(&mut seed);
seed
})
);
let mut all_hashes = all_hashes.clone();

loop {
let Some(hash) = all_hashes.next()
else {
break true;
};

if !dedup_check.insert(hash) {
let _ = me
.responses_tx
.send(parse::build_error_response(
request_id_json,
parse::ErrorResponse::ApplicationDefined(-32804, "duplicate block hash"),
None,
))
.await;
break false;
}

if !subscription.pinned_blocks_headers.contains_key(hash) {
let _ = me
.responses_tx
.send(parse::build_error_response(
request_id_json,
parse::ErrorResponse::InvalidParams,
None,
))
.await;
break false;
}
}
};

if !checks_passed {
continue;
}

// The logic below assumes that all hashes are unique, which is ensured
// above.
for hash in all_hashes {
subscription.pinned_blocks_headers.remove(hash);
if let Some(subscription_id) =
Expand Down
4 changes: 4 additions & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
- JSON-RPC functions that require access to the runtime (for example `state_call`) now cache older runtimes that had to be downloaded, rather than downloading the runtime from scratch every single time. ([#1685](https://github.com/smol-dot/smoldot/pull/1685))
- Smoldot is no longer compiled with the `bulk-memory-operations` and `sign-extensions-ops` WebAssembly features enabled due to the Rust compiler considering target features as unstable. ([#1716](https://github.com/smol-dot/smoldot/pull/1716))

### Fixed

- The `chainHead_unstable_unpin` JSON-RPC function no longer panics if multiple identical block hashes are passed. ([#1728](https://github.com/smol-dot/smoldot/pull/1728))

## 2.0.22 - 2024-03-04

### Fixed
Expand Down
Loading