diff --git a/subxt/src/backend/unstable/follow_stream_unpin.rs b/subxt/src/backend/unstable/follow_stream_unpin.rs index d4164a9d90..6a01f35e9b 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 d32a5d9dea..66fcffdc9d 100644 --- a/testing/integration-tests/src/full_client/client/unstable_rpcs.rs +++ b/testing/integration-tests/src/full_client/client/unstable_rpcs.rs @@ -65,17 +65,14 @@ async fn chainhead_unstable_body() { 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(); // Fetch the block's body. - let response = rpc - .chainhead_unstable_body(sub_id, hashes[0]) - .await - .unwrap(); + let response = rpc.chainhead_unstable_body(sub_id, hash).await.unwrap(); let operation_id = match response { MethodResponse::Started(started) => started.operation_id, MethodResponse::LimitReached => panic!("Expected started response"), @@ -97,12 +94,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 +122,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 +167,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 +204,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.