mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-16 23:35:43 +00:00
chainHead/follow: Provide multiple block hashes to the initialized event (#3445)
This PR extends the Initialized event of the chainHead_follow subscription. Now, the event provides multiple finalized block hashes. This information allows clients that are disconnected, and that want to reconnect, to not lose information about the state of the chain. At the moment, the spec encourages servers to provide at least 1 minute of finalized blocks (~10 blocks). The users are responsible for unpinning these blocks at a later time. This PR tries to report at least 1 finalized block and at most 16 blocks, if they are available. Closes: https://github.com/paritytech/polkadot-sdk/issues/3432 cc @paritytech/subxt-team --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
@@ -173,7 +173,7 @@ async fn follow_subscription_produces_blocks() {
|
||||
// Initialized must always be reported first.
|
||||
let event: FollowEvent<String> = get_next_event(&mut sub).await;
|
||||
let expected = FollowEvent::Initialized(Initialized {
|
||||
finalized_block_hash: format!("{:?}", finalized_hash),
|
||||
finalized_block_hashes: vec![format!("{:?}", finalized_hash)],
|
||||
finalized_block_runtime: None,
|
||||
with_runtime: false,
|
||||
});
|
||||
@@ -255,7 +255,7 @@ async fn follow_with_runtime() {
|
||||
Some(RuntimeEvent::Valid(RuntimeVersionEvent { spec: runtime.clone().into() }));
|
||||
// Runtime must always be reported with the first event.
|
||||
let expected = FollowEvent::Initialized(Initialized {
|
||||
finalized_block_hash: format!("{:?}", finalized_hash),
|
||||
finalized_block_hashes: vec![format!("{:?}", finalized_hash)],
|
||||
finalized_block_runtime,
|
||||
with_runtime: false,
|
||||
});
|
||||
@@ -1344,7 +1344,7 @@ async fn follow_generates_initial_blocks() {
|
||||
// Initialized must always be reported first.
|
||||
let event: FollowEvent<String> = get_next_event(&mut sub).await;
|
||||
let expected = FollowEvent::Initialized(Initialized {
|
||||
finalized_block_hash: format!("{:?}", finalized_hash),
|
||||
finalized_block_hashes: vec![format!("{:?}", finalized_hash)],
|
||||
finalized_block_runtime: None,
|
||||
with_runtime: false,
|
||||
});
|
||||
@@ -1896,7 +1896,7 @@ async fn follow_prune_best_block() {
|
||||
// Initialized must always be reported first.
|
||||
let event: FollowEvent<String> = get_next_event(&mut sub).await;
|
||||
let expected = FollowEvent::Initialized(Initialized {
|
||||
finalized_block_hash: format!("{:?}", finalized_hash),
|
||||
finalized_block_hashes: vec![format!("{:?}", finalized_hash)],
|
||||
finalized_block_runtime: None,
|
||||
with_runtime: false,
|
||||
});
|
||||
@@ -2081,6 +2081,7 @@ async fn follow_forks_pruned_block() {
|
||||
// ^^^ finalized
|
||||
// -> block 1 -> block 2_f -> block 3_f
|
||||
//
|
||||
let finalized_hash = client.info().finalized_hash;
|
||||
|
||||
let block_1 = BlockBuilderBuilder::new(&*client)
|
||||
.on_parent_block(client.chain_info().genesis_hash)
|
||||
@@ -2090,6 +2091,7 @@ async fn follow_forks_pruned_block() {
|
||||
.build()
|
||||
.unwrap()
|
||||
.block;
|
||||
let block_1_hash = block_1.header.hash();
|
||||
client.import(BlockOrigin::Own, block_1.clone()).await.unwrap();
|
||||
|
||||
let block_2 = BlockBuilderBuilder::new(&*client)
|
||||
@@ -2100,6 +2102,7 @@ async fn follow_forks_pruned_block() {
|
||||
.build()
|
||||
.unwrap()
|
||||
.block;
|
||||
let block_2_hash = block_2.header.hash();
|
||||
client.import(BlockOrigin::Own, block_2.clone()).await.unwrap();
|
||||
|
||||
let block_3 = BlockBuilderBuilder::new(&*client)
|
||||
@@ -2156,7 +2159,12 @@ async fn follow_forks_pruned_block() {
|
||||
// Initialized must always be reported first.
|
||||
let event: FollowEvent<String> = get_next_event(&mut sub).await;
|
||||
let expected = FollowEvent::Initialized(Initialized {
|
||||
finalized_block_hash: format!("{:?}", block_3_hash),
|
||||
finalized_block_hashes: vec![
|
||||
format!("{:?}", finalized_hash),
|
||||
format!("{:?}", block_1_hash),
|
||||
format!("{:?}", block_2_hash),
|
||||
format!("{:?}", block_3_hash),
|
||||
],
|
||||
finalized_block_runtime: None,
|
||||
with_runtime: false,
|
||||
});
|
||||
@@ -2310,7 +2318,7 @@ async fn follow_report_multiple_pruned_block() {
|
||||
// Initialized must always be reported first.
|
||||
let event: FollowEvent<String> = get_next_event(&mut sub).await;
|
||||
let expected = FollowEvent::Initialized(Initialized {
|
||||
finalized_block_hash: format!("{:?}", finalized_hash),
|
||||
finalized_block_hashes: vec![format!("{:?}", finalized_hash)],
|
||||
finalized_block_runtime: None,
|
||||
with_runtime: false,
|
||||
});
|
||||
@@ -2632,7 +2640,7 @@ async fn follow_finalized_before_new_block() {
|
||||
let finalized_hash = client.info().finalized_hash;
|
||||
let event: FollowEvent<String> = get_next_event(&mut sub).await;
|
||||
let expected = FollowEvent::Initialized(Initialized {
|
||||
finalized_block_hash: format!("{:?}", finalized_hash),
|
||||
finalized_block_hashes: vec![format!("{:?}", finalized_hash)],
|
||||
finalized_block_runtime: None,
|
||||
with_runtime: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user