Skip to content

Commit

Permalink
fix: don't unpin blocks that may show up again (#1368)
Browse files Browse the repository at this point in the history
* backend(fix): Early unpin for pruned blocks with no active `BlockRef`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* backend/tests: Check unpinning only after max_life time

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* backend/tests: Remove unpinning when droped tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* backend/tests: Ensure new blocks are not unpinned

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* backend: Add only pruned blocks to unpin hashset and add a test

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* backend: Introduce the `UnpinPolicy`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update subxt/src/backend/unstable/follow_stream_unpin.rs

* backend: Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Only unpin blocks that have been pruned by the backend

* Fix comments

* Mark initialized and finalized blocks as 'can_be_unpinned' too and tests

* fmt

* tweak a couple more comments

* tidy tests and fix undeterministic check

* Fix wrong names in comments

* tweak another test to focus it a bit more

* clippy

* wee rename of args in a couple of test helpers

* add some logs and simplify submit_transaction in the same way Alex did

* ditch logging again and keep to the experiment pr

* cargo fmt

* reduce CI timeouts to 30mins

* Handle Init and Stop events in submit_transaction too, just in case

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 17, 2024
1 parent df85e46 commit 5533435
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 96 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
tests:
name: "Test (Native)"
runs-on: ubuntu-latest-16-cores
timeout-minutes: 45
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
unstable_backend_tests:
name: "Test (Unstable Backend)"
runs-on: ubuntu-latest-16-cores
timeout-minutes: 45
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand Down Expand Up @@ -219,7 +219,7 @@ jobs:
light_client_tests:
name: "Test (Light Client)"
runs-on: ubuntu-latest-16-cores
timeout-minutes: 45
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand All @@ -246,7 +246,7 @@ jobs:
wasm_tests:
name: Test (WASM)
runs-on: ubuntu-latest
timeout-minutes: 45
timeout-minutes: 30
env:
# Set timeout for wasm tests to be much bigger than the default 20 secs.
WASM_BINDGEN_TEST_TIMEOUT: 300
Expand Down
16 changes: 11 additions & 5 deletions subxt/src/backend/unstable/follow_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ pub(super) mod test_utils {
}

/// A new block event
pub fn ev_new_block(parent: u64, n: u64) -> FollowEvent<H256> {
pub fn ev_new_block(parent_n: u64, n: u64) -> FollowEvent<H256> {
FollowEvent::NewBlock(NewBlock {
parent_block_hash: H256::from_low_u64_le(parent),
parent_block_hash: H256::from_low_u64_le(parent_n),
block_hash: H256::from_low_u64_le(n),
new_runtime: None,
})
Expand All @@ -265,10 +265,16 @@ pub(super) mod test_utils {
}

/// A finalized event
pub fn ev_finalized(ns: impl IntoIterator<Item = u64>) -> FollowEvent<H256> {
pub fn ev_finalized(
finalized_ns: impl IntoIterator<Item = u64>,
pruned_ns: impl IntoIterator<Item = u64>,
) -> FollowEvent<H256> {
FollowEvent::Finalized(Finalized {
finalized_block_hashes: ns.into_iter().map(H256::from_low_u64_le).collect(),
pruned_block_hashes: vec![],
finalized_block_hashes: finalized_ns
.into_iter()
.map(H256::from_low_u64_le)
.collect(),
pruned_block_hashes: pruned_ns.into_iter().map(H256::from_low_u64_le).collect(),
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions subxt/src/backend/unstable/follow_stream_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ mod test {
Ok(ev_initialized(0)),
Ok(ev_new_block(0, 1)),
Ok(ev_best_block(1)),
Ok(ev_finalized([1])),
Ok(ev_finalized([1], [])),
Err(Error::Other("ended".to_owned())),
]
},
Expand Down Expand Up @@ -465,7 +465,7 @@ mod test {
Ok(ev_initialized(0)),
Ok(ev_new_block(0, 1)),
Ok(ev_best_block(1)),
Ok(ev_finalized([1])),
Ok(ev_finalized([1], [])),
Ok(ev_new_block(1, 2)),
Ok(ev_new_block(2, 3)),
Err(Error::Other("ended".to_owned())),
Expand Down Expand Up @@ -517,7 +517,7 @@ mod test {
Ok(ev_best_block(1)),
Ok(ev_new_block(1, 2)),
Ok(ev_new_block(2, 3)),
Ok(ev_finalized([1])),
Ok(ev_finalized([1], [])),
Err(Error::Other("ended".to_owned())),
]
},
Expand Down
Loading

0 comments on commit 5533435

Please sign in to comment.