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 panic with unpinning pruned blocks #2386

Merged
merged 5 commits into from
Jun 14, 2022

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Jun 14, 2022

Fixes a panic introduced in #2373

Imagine the following situation:
Block A has two children: block B and block C. The latest finalized block is currently block A. All three blocks are pinned.

Now, imagine that block B gets finalized. Block A, B, and C all stay pinned. The number of pinned blocks remaining is decreased by 1.

When the user then unpins block C, we check height(block_C) <= height(current_finalized_block), which returns true, and we add 1 to the number of pinned blocks remaining.
When the user then unpins block A, the same happens, and we add 1 again to the number of pinned blocks remaining.

This leads to an overflow when that number of pinned blocks is usize::max_value().

This PR fixes this problem by tracking in pinned_blocks whether the block counts towards the limit.

Copy link
Contributor

@mergify mergify bot left a comment

Choose a reason for hiding this comment

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

Automatically approving tomaka's pull requests. This auto-approval will be removed once more maintainers are active.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 14, 2022

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
        +726 ┊ alloc::collections::btree::remove::<impl alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::KV>>::remove_leaf_kv::h1d96892f0412a914
        -726 ┊ alloc::collections::btree::remove::<impl alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::KV>>::remove_leaf_kv::h657e6722127b262a
        -682 ┊ <slab::Slab<T> as core::iter::traits::collect::FromIterator<(usize,T)>>::from_iter::h376b5c161a9769d4
        +682 ┊ <slab::Slab<T> as core::iter::traits::collect::FromIterator<(usize,T)>>::from_iter::h49f7d6b7a1e0c471
        -679 ┊ alloc::collections::btree::fix::<impl alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::LeafOrInternal>>::fix_node_through_parent::h8ea3a51f3a27c350
        +679 ┊ alloc::collections::btree::fix::<impl alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::LeafOrInternal>>::fix_node_through_parent::hf26bd6dd1bd0bdba
        +668 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_right::h5e84fa32c6c968c9
        -668 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_right::hb6957039477bac16
        -631 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_left::h80360c6cbf16b36b
        +631 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_left::h9a2e883301ee3517
        +552 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::h4d90002156329b51
        +552 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::h8e728e34943db055
        -552 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::hcfa9ee5033320a8b
        -552 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::hf5a152619aeede29
        -518 ┊ alloc::collections::btree::search::<impl alloc::collections::btree::node::NodeRef<BorrowType,K,V,alloc::collections::btree::node::marker::LeafOrInternal>>::search_tree_for_bifurcation::ha1fa2275d67d2b1a
        +518 ┊ alloc::collections::btree::search::<impl alloc::collections::btree::node::NodeRef<BorrowType,K,V,alloc::collections::btree::node::marker::LeafOrInternal>>::search_tree_for_bifurcation::hb1d6464214f62c02
        +510 ┊ alloc::collections::btree::navigate::<impl alloc::collections::btree::node::NodeRef<BorrowType,K,V,alloc::collections::btree::node::marker::LeafOrInternal>>::find_leaf_edges_spanning_range::h96cc3b78a48daa22
        -510 ┊ alloc::collections::btree::navigate::<impl alloc::collections::btree::node::NodeRef<BorrowType,K,V,alloc::collections::btree::node::marker::LeafOrInternal>>::find_leaf_edges_spanning_range::hc24797ad29f7ec18
        +498 ┊ alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::Edge>::insert_recursing::h12e4ca7cd7896daa
        -492 ┊ alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::Edge>::insert_recursing::h7abbcaf30d032e4e
        -322 ┊ ... and 201 more.
       -1545 ┊ Σ [221 Total Rows]

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

👍

@tomaka tomaka added the automerge Automatically merge pull request as soon as possible label Jun 14, 2022
@mergify mergify bot merged commit 87d47d2 into paritytech:main Jun 14, 2022
@tomaka tomaka deleted the bugfix-pinning-pruned branch June 14, 2022 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge pull request as soon as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants