Skip to content

Commit

Permalink
address grumbles
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 committed Mar 11, 2024
1 parent c2deaa2 commit 284913e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
21 changes: 13 additions & 8 deletions subxt/src/backend/unstable/follow_stream_unpin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,20 @@ impl<Hash: BlockHash> Stream for FollowStreamUnpin<Hash> {
}
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,
Expand Down
20 changes: 8 additions & 12 deletions testing/integration-tests/src/full_client/client/unstable_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 284913e

Please sign in to comment.