From 284913e5f224a52306345ddd0d6f2bd2eba1743d Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Mon, 11 Mar 2024 23:26:49 +0100 Subject: [PATCH] address grumbles --- .../backend/unstable/follow_stream_unpin.rs | 21 ++++++++++++------- .../src/full_client/client/unstable_rpcs.rs | 20 +++++++----------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/subxt/src/backend/unstable/follow_stream_unpin.rs b/subxt/src/backend/unstable/follow_stream_unpin.rs index d4164a9d903..6a01f35e9ba 100644 --- a/subxt/src/backend/unstable/follow_stream_unpin.rs +++ b/subxt/src/backend/unstable/follow_stream_unpin.rs @@ -115,15 +115,20 @@ impl Stream for FollowStreamUnpin { } FollowStreamMsg::Event(FollowEvent::Initialized(details)) => { // The first finalized block gets the starting block_num. - let rel_block_num = this.rel_block_num; - // Pin this block, but note that it can be unpinned any time since it won't show up again (except - // as a parent block, which we are ignoring at the moment). + let mut rel_block_num = this.rel_block_num; - let finalized_block_hashes = details - .finalized_block_hashes - .iter() - .map(|h| this.pin_unpinnable_block_at(rel_block_num, *h)) - .collect(); + let mut finalized_block_hashes = + Vec::with_capacity(details.finalized_block_hashes.len()); + + for finalized_block in &details.finalized_block_hashes { + // Pin this block, but note that it can be unpinned any time since it won't show up again (except + // as a parent block, which we are ignoring at the moment). + let block_ref = + this.pin_unpinnable_block_at(rel_block_num, *finalized_block); + + finalized_block_hashes.push(block_ref); + rel_block_num += 1; + } FollowStreamMsg::Event(FollowEvent::Initialized(Initialized { finalized_block_hashes, diff --git a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs index d32a5d9deac..3752b397479 100644 --- a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs @@ -97,12 +97,11 @@ async fn chainhead_unstable_header() { let mut blocks = rpc.chainhead_unstable_follow(false).await.unwrap(); let event = blocks.next().await.unwrap().unwrap(); - let hashes = match event { - FollowEvent::Initialized(init) => init.finalized_block_hashes, + let hash = match event { + FollowEvent::Initialized(init) => init.finalized_block_hashes.last().unwrap().clone(), _ => panic!("Unexpected event"), }; let sub_id = blocks.subscription_id().unwrap(); - let hash = hashes[0]; let new_header = legacy_rpc .chain_get_header(Some(hash)) @@ -126,12 +125,11 @@ async fn chainhead_unstable_storage() { let mut blocks = rpc.chainhead_unstable_follow(false).await.unwrap(); let event = blocks.next().await.unwrap().unwrap(); - let hashes = match event { - FollowEvent::Initialized(init) => init.finalized_block_hashes, + let hash = match event { + FollowEvent::Initialized(init) => init.finalized_block_hashes.last().unwrap().clone(), _ => panic!("Unexpected event"), }; let sub_id = blocks.subscription_id().unwrap(); - let hash = hashes[0]; let alice: AccountId32 = dev::alice().public_key().into(); let addr = node_runtime::storage().system().account(alice); @@ -172,12 +170,11 @@ async fn chainhead_unstable_call() { let mut blocks = rpc.chainhead_unstable_follow(true).await.unwrap(); let event = blocks.next().await.unwrap().unwrap(); - let hashes = match event { - FollowEvent::Initialized(init) => init.finalized_block_hashes, + let hash = match event { + FollowEvent::Initialized(init) => init.finalized_block_hashes.last().unwrap().clone(), _ => panic!("Unexpected event"), }; let sub_id = blocks.subscription_id().unwrap(); - let hash = hashes[0]; let alice_id = dev::alice().public_key().to_account_id(); // Runtime API call. @@ -210,12 +207,11 @@ async fn chainhead_unstable_unpin() { let mut blocks = rpc.chainhead_unstable_follow(true).await.unwrap(); let event = blocks.next().await.unwrap().unwrap(); - let hashes = match event { - FollowEvent::Initialized(init) => init.finalized_block_hashes, + let hash = match event { + FollowEvent::Initialized(init) => init.finalized_block_hashes.last().unwrap().clone(), _ => panic!("Unexpected event"), }; let sub_id = blocks.subscription_id().unwrap(); - let hash = hashes[0]; assert!(rpc.chainhead_unstable_unpin(sub_id, hash).await.is_ok()); // The block was already unpinned.