diff --git a/lib/src/chain/async_tree.rs b/lib/src/chain/async_tree.rs index 32afabf450..7e9b2cb5f4 100644 --- a/lib/src/chain/async_tree.rs +++ b/lib/src/chain/async_tree.rs @@ -811,7 +811,10 @@ where assert!(match (self.input_finalized_index, new_best_block) { (Some(f), Some(b)) => self.non_finalized_blocks.is_ancestor(f, b), (Some(_), None) => false, - (None, Some(_)) => true, + (None, Some(b)) => { + assert!(self.non_finalized_blocks.contains(b)); + true + } (None, None) => true, }); @@ -898,10 +901,13 @@ where }; if let Some(new_finalized) = new_finalized { - // Update `input_finalized_index`. + // Update `input_finalized_index` and `input_best_block_index`. if self.input_finalized_index == Some(new_finalized) { self.input_finalized_index = None; } + if self.input_best_block_index == Some(new_finalized) { + self.input_best_block_index = None; + } let mut pruned_blocks = Vec::new(); let mut pruned_finalized = None; diff --git a/lib/src/chain/fork_tree.rs b/lib/src/chain/fork_tree.rs index b758b135b6..126ab9f6d5 100644 --- a/lib/src/chain/fork_tree.rs +++ b/lib/src/chain/fork_tree.rs @@ -162,6 +162,11 @@ impl ForkTree { return_value.map(NodeIndex) } + /// Returns `true` if the given [`NodeIndex`] is valid. + pub fn contains(&self, index: NodeIndex) -> bool { + self.nodes.contains(index.0) + } + /// Returns the value of the node with the given index. pub fn get(&self, index: NodeIndex) -> Option<&T> { self.nodes.get(index.0).map(|n| &n.data) diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index f4e0ad30ce..1625fb09a2 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -11,6 +11,7 @@ - Fix the wrong `parentBlockHash` value being sent in `chainHead_v1_followEvent` notifications. ([#1791](https://github.com/smol-dot/smoldot/pull/1791)) - Fix the `forbidWs` option being ignored when connecting to non-localhost addresses. Smoldot erroneously only took the value of `forbidNonLocalWs` in that situation. Connecting to a non-localhost address is now only done if both `forbidWs` and `forbidNonLocalWs` are `false`. ([#1790](https://github.com/smol-dot/smoldot/pull/1790)) - The `finalizedBlockHash` field of the `initialized` event of `chainHead_v1_followEvent` notifications is now properly named `finalizedBlockHashes` and is now properly an array. ([#1792](https://github.com/smol-dot/smoldot/pull/1792)) +- Fix panic when calling the `system_health` JSON-RPC function when the finalized block is equal to the best block. ([#1798](https://github.com/smol-dot/smoldot/pull/1798)) ## 2.0.24 - 2024-04-16