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 best_output_block_updated erroneously remaining at false #2029

Merged
merged 2 commits into from
Nov 8, 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
34 changes: 20 additions & 14 deletions lib/src/chain/async_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ where
if let Some(input_finalized_index) = self.input_finalized_index {
// Finding a new finalized block.
// We always take the first node on the path towards `input_finalized_index`, in
// order to finalized blocks one by one.
// order to finalize blocks one by one.
let new_finalized = {
self.non_finalized_blocks
.root_to_node_path(input_finalized_index)
Expand All @@ -915,6 +915,13 @@ where
let mut pruned_finalized = None;
let mut best_output_block_updated = false;

// Since we change the finalized block, if the output best block is equal to this
// finalized block, that means it is modified, even though its value might remain
// at `None`.
if self.output_best_block_index.is_none() {
best_output_block_updated = true;
}
Comment on lines +918 to +923
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the bugfix. The rest of the changes are one typo, and clarifications.


for pruned in self.non_finalized_blocks.prune_ancestors(new_finalized) {
debug_assert_ne!(Some(pruned.index), self.input_finalized_index);

Expand Down Expand Up @@ -963,26 +970,25 @@ where
// Try to advance the output best block to the `Finished` block with the highest
// weight.
// Weight of the current output best block.
let mut current_runtime_service_best_block_weight =
match self.output_best_block_index {
None => self.output_finalized_block_weight,
Some(idx) => {
self.non_finalized_blocks
.get(idx)
.unwrap()
.input_best_block_weight
}
};
let mut previously_reported_best_block_weight = match self.output_best_block_index {
None => self.output_finalized_block_weight,
Some(idx) => {
self.non_finalized_blocks
.get(idx)
.unwrap()
.input_best_block_weight
}
};

for (node_index, block) in self.non_finalized_blocks.iter_unordered() {
// Check uniqueness of weights.
debug_assert!(
block.input_best_block_weight != current_runtime_service_best_block_weight
block.input_best_block_weight != previously_reported_best_block_weight
|| block.input_best_block_weight == 0
|| self.output_best_block_index == Some(node_index)
);

if block.input_best_block_weight <= current_runtime_service_best_block_weight {
if block.input_best_block_weight <= previously_reported_best_block_weight {
continue;
}

Expand All @@ -994,7 +1000,7 @@ where
}

// Input best can be updated to the block being iterated.
current_runtime_service_best_block_weight = block.input_best_block_weight;
previously_reported_best_block_weight = block.input_best_block_weight;
self.output_best_block_index = Some(node_index);
best_output_block_updated = true;

Expand Down
4 changes: 4 additions & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- Fix panic in transactions service when the runtime service resets after having lost track of the head of the chain. ([#2029](https://github.com/smol-dot/smoldot/pull/2029))

## 2.0.30 - 2024-08-16

### Added
Expand Down
Loading