From ec86b50eb6ee0c91372b59662fe8004799362464 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile <60601340+lexnv@users.noreply.github.com> Date: Sat, 27 May 2023 23:13:00 +0300 Subject: [PATCH] chain_head: Rename `runtimeUpdates` flag to `withRuntime` (#14244) Signed-off-by: Alexandru Vasile --- client/rpc-spec-v2/src/chain_head/api.rs | 2 +- .../rpc-spec-v2/src/chain_head/chain_head.rs | 10 ++-- .../src/chain_head/chain_head_follow.rs | 14 ++--- client/rpc-spec-v2/src/chain_head/event.rs | 40 ++++++------- .../src/chain_head/subscription/inner.rs | 30 +++++----- client/rpc-spec-v2/src/chain_head/tests.rs | 56 +++++++++---------- 6 files changed, 76 insertions(+), 76 deletions(-) diff --git a/client/rpc-spec-v2/src/chain_head/api.rs b/client/rpc-spec-v2/src/chain_head/api.rs index ad1e58500d51b..ee8caa37bafbe 100644 --- a/client/rpc-spec-v2/src/chain_head/api.rs +++ b/client/rpc-spec-v2/src/chain_head/api.rs @@ -34,7 +34,7 @@ pub trait ChainHeadApi { unsubscribe = "chainHead_unstable_unfollow", item = FollowEvent, )] - fn chain_head_unstable_follow(&self, runtime_updates: bool); + fn chain_head_unstable_follow(&self, with_runtime: bool); /// Retrieves the body (list of transactions) of a pinned block. /// diff --git a/client/rpc-spec-v2/src/chain_head/chain_head.rs b/client/rpc-spec-v2/src/chain_head/chain_head.rs index 763fc5d9acc5d..0f2d55f100929 100644 --- a/client/rpc-spec-v2/src/chain_head/chain_head.rs +++ b/client/rpc-spec-v2/src/chain_head/chain_head.rs @@ -152,7 +152,7 @@ where fn chain_head_unstable_follow( &self, mut sink: SubscriptionSink, - runtime_updates: bool, + with_runtime: bool, ) -> SubscriptionResult { let sub_id = match self.accept_subscription(&mut sink) { Ok(sub_id) => sub_id, @@ -162,7 +162,7 @@ where }, }; // Keep track of the subscription. - let Some(rx_stop) = self.subscriptions.insert_subscription(sub_id.clone(), runtime_updates) else { + let Some(rx_stop) = self.subscriptions.insert_subscription(sub_id.clone(), with_runtime) else { // Inserting the subscription can only fail if the JsonRPSee // generated a duplicate subscription ID. debug!(target: LOG_TARGET, "[follow][id={:?}] Subscription already accepted", sub_id); @@ -179,7 +179,7 @@ where client, backend, subscriptions.clone(), - runtime_updates, + with_runtime, sub_id.clone(), ); @@ -410,8 +410,8 @@ where }; let fut = async move { - // Reject subscription if runtime_updates is false. - if !block_guard.has_runtime_updates() { + // Reject subscription if with_runtime is false. + if !block_guard.has_runtime() { let _ = sink.reject(ChainHeadRpcError::InvalidParam( "The runtime updates flag must be set".into(), )); diff --git a/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs b/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs index f496f07a37b18..cb6af8bd590b3 100644 --- a/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs +++ b/client/rpc-spec-v2/src/chain_head/chain_head_follow.rs @@ -52,7 +52,7 @@ pub struct ChainHeadFollower, Block: BlockT, Client> { /// Subscriptions handle. sub_handle: Arc>, /// Subscription was started with the runtime updates flag. - runtime_updates: bool, + with_runtime: bool, /// Subscription ID. sub_id: String, /// The best reported block by this subscription. @@ -65,10 +65,10 @@ impl, Block: BlockT, Client> ChainHeadFollower, backend: Arc, sub_handle: Arc>, - runtime_updates: bool, + with_runtime: bool, sub_id: String, ) -> Self { - Self { client, backend, sub_handle, runtime_updates, sub_id, best_block_cache: None } + Self { client, backend, sub_handle, with_runtime, sub_id, best_block_cache: None } } } @@ -144,7 +144,7 @@ where parent: Option, ) -> Option { // No runtime versions should be reported. - if !self.runtime_updates { + if !self.with_runtime { return None } @@ -228,7 +228,7 @@ where let initialized_event = FollowEvent::Initialized(Initialized { finalized_block_hash, finalized_block_runtime, - runtime_updates: self.runtime_updates, + with_runtime: self.with_runtime, }); let mut finalized_block_descendants = Vec::with_capacity(initial_blocks.len() + 1); @@ -243,7 +243,7 @@ where block_hash: child, parent_block_hash: parent, new_runtime, - runtime_updates: self.runtime_updates, + with_runtime: self.with_runtime, }); finalized_block_descendants.push(event); @@ -274,7 +274,7 @@ where block_hash, parent_block_hash, new_runtime, - runtime_updates: self.runtime_updates, + with_runtime: self.with_runtime, }); if !is_best_block { diff --git a/client/rpc-spec-v2/src/chain_head/event.rs b/client/rpc-spec-v2/src/chain_head/event.rs index 2e070c7ce6ae7..d0d4d1d43ac03 100644 --- a/client/rpc-spec-v2/src/chain_head/event.rs +++ b/client/rpc-spec-v2/src/chain_head/event.rs @@ -64,7 +64,7 @@ pub struct RuntimeVersionEvent { } /// The runtime event generated if the `follow` subscription -/// has set the `runtime_updates` flag. +/// has set the `with_runtime` flag. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[serde(tag = "type")] @@ -88,7 +88,7 @@ impl From for RuntimeEvent { /// This is the first event generated by the `follow` subscription /// and is submitted only once. /// -/// If the `runtime_updates` flag is set, then this event contains +/// If the `with_runtime` flag is set, then this event contains /// the `RuntimeEvent`, otherwise the `RuntimeEvent` is not present. #[derive(Debug, Clone, PartialEq, Deserialize)] #[serde(rename_all = "camelCase")] @@ -99,23 +99,23 @@ pub struct Initialized { /// /// # Note /// - /// This is present only if the `runtime_updates` flag is set for + /// This is present only if the `with_runtime` flag is set for /// the `follow` subscription. pub finalized_block_runtime: Option, /// Privately keep track if the `finalized_block_runtime` should be /// serialized. #[serde(default)] - pub(crate) runtime_updates: bool, + pub(crate) with_runtime: bool, } impl Serialize for Initialized { /// Custom serialize implementation to include the `RuntimeEvent` depending - /// on the internal `runtime_updates` flag. + /// on the internal `with_runtime` flag. fn serialize(&self, serializer: S) -> Result where S: Serializer, { - if self.runtime_updates { + if self.with_runtime { let mut state = serializer.serialize_struct("Initialized", 2)?; state.serialize_field("finalizedBlockHash", &self.finalized_block_hash)?; state.serialize_field("finalizedBlockRuntime", &self.finalized_block_runtime)?; @@ -140,23 +140,23 @@ pub struct NewBlock { /// /// # Note /// - /// This is present only if the `runtime_updates` flag is set for + /// This is present only if the `with_runtime` flag is set for /// the `follow` subscription. pub new_runtime: Option, /// Privately keep track if the `finalized_block_runtime` should be /// serialized. #[serde(default)] - pub(crate) runtime_updates: bool, + pub(crate) with_runtime: bool, } impl Serialize for NewBlock { /// Custom serialize implementation to include the `RuntimeEvent` depending - /// on the internal `runtime_updates` flag. + /// on the internal `with_runtime` flag. fn serialize(&self, serializer: S) -> Result where S: Serializer, { - if self.runtime_updates { + if self.with_runtime { let mut state = serializer.serialize_struct("NewBlock", 3)?; state.serialize_field("blockHash", &self.block_hash)?; state.serialize_field("parentBlockHash", &self.parent_block_hash)?; @@ -253,7 +253,7 @@ mod tests { let event: FollowEvent = FollowEvent::Initialized(Initialized { finalized_block_hash: "0x1".into(), finalized_block_runtime: None, - runtime_updates: false, + with_runtime: false, }); let ser = serde_json::to_string(&event).unwrap(); @@ -278,7 +278,7 @@ mod tests { let mut initialized = Initialized { finalized_block_hash: "0x1".into(), finalized_block_runtime: Some(runtime_event), - runtime_updates: true, + with_runtime: true, }; let event: FollowEvent = FollowEvent::Initialized(initialized.clone()); @@ -291,8 +291,8 @@ mod tests { assert_eq!(ser, exp); let event_dec: FollowEvent = serde_json::from_str(exp).unwrap(); - // The `runtime_updates` field is used for serialization purposes. - initialized.runtime_updates = false; + // The `with_runtime` field is used for serialization purposes. + initialized.with_runtime = false; assert!(matches!( event_dec, FollowEvent::Initialized(ref dec) if dec == &initialized )); @@ -305,7 +305,7 @@ mod tests { block_hash: "0x1".into(), parent_block_hash: "0x2".into(), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); let ser = serde_json::to_string(&event).unwrap(); @@ -331,7 +331,7 @@ mod tests { block_hash: "0x1".into(), parent_block_hash: "0x2".into(), new_runtime: Some(runtime_event), - runtime_updates: true, + with_runtime: true, }; let event: FollowEvent = FollowEvent::NewBlock(new_block.clone()); @@ -345,8 +345,8 @@ mod tests { assert_eq!(ser, exp); let event_dec: FollowEvent = serde_json::from_str(exp).unwrap(); - // The `runtime_updates` field is used for serialization purposes. - new_block.runtime_updates = false; + // The `with_runtime` field is used for serialization purposes. + new_block.with_runtime = false; assert!(matches!( event_dec, FollowEvent::NewBlock(ref dec) if dec == &new_block )); @@ -356,7 +356,7 @@ mod tests { block_hash: "0x1".into(), parent_block_hash: "0x2".into(), new_runtime: None, - runtime_updates: true, + with_runtime: true, }; let event: FollowEvent = FollowEvent::NewBlock(new_block.clone()); @@ -364,7 +364,7 @@ mod tests { let exp = r#"{"event":"newBlock","blockHash":"0x1","parentBlockHash":"0x2","newRuntime":null}"#; assert_eq!(ser, exp); - new_block.runtime_updates = false; + new_block.with_runtime = false; let event_dec: FollowEvent = serde_json::from_str(exp).unwrap(); assert!(matches!( event_dec, FollowEvent::NewBlock(ref dec) if dec == &new_block diff --git a/client/rpc-spec-v2/src/chain_head/subscription/inner.rs b/client/rpc-spec-v2/src/chain_head/subscription/inner.rs index 8865daa83cba2..bdb14e8de7172 100644 --- a/client/rpc-spec-v2/src/chain_head/subscription/inner.rs +++ b/client/rpc-spec-v2/src/chain_head/subscription/inner.rs @@ -112,8 +112,8 @@ struct BlockState { /// The state of a single subscription ID. struct SubscriptionState { - /// The `runtime_updates` parameter flag of the subscription. - runtime_updates: bool, + /// The `with_runtime` parameter flag of the subscription. + with_runtime: bool, /// Signals the "Stop" event. tx_stop: Option>, /// Track the block hashes available for this subscription. @@ -234,7 +234,7 @@ impl SubscriptionState { /// executing an RPC method call. pub struct BlockGuard> { hash: Block::Hash, - runtime_updates: bool, + with_runtime: bool, backend: Arc, } @@ -242,7 +242,7 @@ pub struct BlockGuard> { // testing. impl> std::fmt::Debug for BlockGuard { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "BlockGuard hash {:?} runtime_updates {:?}", self.hash, self.runtime_updates) + write!(f, "BlockGuard hash {:?} with_runtime {:?}", self.hash, self.with_runtime) } } @@ -250,19 +250,19 @@ impl> BlockGuard { /// Construct a new [`BlockGuard`] . fn new( hash: Block::Hash, - runtime_updates: bool, + with_runtime: bool, backend: Arc, ) -> Result { backend .pin_block(hash) .map_err(|err| SubscriptionManagementError::Custom(err.to_string()))?; - Ok(Self { hash, runtime_updates, backend }) + Ok(Self { hash, with_runtime, backend }) } - /// The `runtime_updates` flag of the subscription. - pub fn has_runtime_updates(&self) -> bool { - self.runtime_updates + /// The `with_runtime` flag of the subscription. + pub fn has_runtime(&self) -> bool { + self.with_runtime } } @@ -310,12 +310,12 @@ impl> SubscriptionsInner { pub fn insert_subscription( &mut self, sub_id: String, - runtime_updates: bool, + with_runtime: bool, ) -> Option> { if let Entry::Vacant(entry) = self.subs.entry(sub_id) { let (tx_stop, rx_stop) = oneshot::channel(); let state = SubscriptionState:: { - runtime_updates, + with_runtime, tx_stop: Some(tx_stop), blocks: Default::default(), }; @@ -501,7 +501,7 @@ impl> SubscriptionsInner { return Err(SubscriptionManagementError::BlockHashAbsent) } - BlockGuard::new(hash, sub.runtime_updates, self.backend.clone()) + BlockGuard::new(hash, sub.with_runtime, self.backend.clone()) } } @@ -608,7 +608,7 @@ mod tests { #[test] fn sub_state_register_twice() { let mut sub_state = SubscriptionState:: { - runtime_updates: false, + with_runtime: false, tx_stop: None, blocks: Default::default(), }; @@ -633,7 +633,7 @@ mod tests { #[test] fn sub_state_register_unregister() { let mut sub_state = SubscriptionState:: { - runtime_updates: false, + with_runtime: false, tx_stop: None, blocks: Default::default(), }; @@ -709,7 +709,7 @@ mod tests { let block = subs.lock_block(&id, hash).unwrap(); // Subscription started with runtime updates - assert_eq!(block.has_runtime_updates(), true); + assert_eq!(block.has_runtime(), true); let invalid_id = "abc-invalid".to_string(); let err = subs.unpin_block(&invalid_id, hash).unwrap_err(); diff --git a/client/rpc-spec-v2/src/chain_head/tests.rs b/client/rpc-spec-v2/src/chain_head/tests.rs index d3d4fc649e3fe..cb6e65f859133 100644 --- a/client/rpc-spec-v2/src/chain_head/tests.rs +++ b/client/rpc-spec-v2/src/chain_head/tests.rs @@ -128,7 +128,7 @@ async fn follow_subscription_produces_blocks() { let expected = FollowEvent::Initialized(Initialized { finalized_block_hash: format!("{:?}", finalized_hash), finalized_block_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -142,7 +142,7 @@ async fn follow_subscription_produces_blocks() { block_hash: format!("{:?}", best_hash), parent_block_hash: format!("{:?}", finalized_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -199,7 +199,7 @@ async fn follow_with_runtime() { let expected = FollowEvent::Initialized(Initialized { finalized_block_hash: format!("{:?}", finalized_hash), finalized_block_runtime, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -214,7 +214,7 @@ async fn follow_with_runtime() { block_hash: format!("{:?}", best_hash), parent_block_hash: format!("{:?}", finalized_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -264,7 +264,7 @@ async fn follow_with_runtime() { block_hash: format!("{:?}", best_hash), parent_block_hash: format!("{:?}", finalized_hash), new_runtime, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); } @@ -492,7 +492,7 @@ async fn call_runtime_without_flag() { FollowEvent::BestBlockChanged(_) ); - // Valid runtime call on a subscription started with `runtime_updates` false. + // Valid runtime call on a subscription started with `with_runtime` false. let alice_id = AccountKeyring::Alice.to_account_id(); let call_parameters = format!("0x{:?}", HexDisplay::from(&alice_id.encode())); let err = api @@ -681,7 +681,7 @@ async fn follow_generates_initial_blocks() { let expected = FollowEvent::Initialized(Initialized { finalized_block_hash: format!("{:?}", finalized_hash), finalized_block_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -691,7 +691,7 @@ async fn follow_generates_initial_blocks() { block_hash: format!("{:?}", block_1_hash), parent_block_hash: format!("{:?}", finalized_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -701,7 +701,7 @@ async fn follow_generates_initial_blocks() { block_hash: format!("{:?}", block_2_hash), parent_block_hash: format!("{:?}", block_1_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); // Check block 3. @@ -710,7 +710,7 @@ async fn follow_generates_initial_blocks() { block_hash: format!("{:?}", block_3_hash), parent_block_hash: format!("{:?}", block_1_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -730,7 +730,7 @@ async fn follow_generates_initial_blocks() { block_hash: format!("{:?}", block_4_hash), parent_block_hash: format!("{:?}", block_2_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -913,7 +913,7 @@ async fn follow_prune_best_block() { let expected = FollowEvent::Initialized(Initialized { finalized_block_hash: format!("{:?}", finalized_hash), finalized_block_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -963,7 +963,7 @@ async fn follow_prune_best_block() { block_hash: format!("{:?}", block_1_hash), parent_block_hash: format!("{:?}", finalized_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); let event: FollowEvent = get_next_event(&mut sub).await; @@ -978,7 +978,7 @@ async fn follow_prune_best_block() { block_hash: format!("{:?}", block_3_hash), parent_block_hash: format!("{:?}", block_1_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); let event: FollowEvent = get_next_event(&mut sub).await; @@ -993,7 +993,7 @@ async fn follow_prune_best_block() { block_hash: format!("{:?}", block_4_hash), parent_block_hash: format!("{:?}", block_3_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); let event: FollowEvent = get_next_event(&mut sub).await; @@ -1008,7 +1008,7 @@ async fn follow_prune_best_block() { block_hash: format!("{:?}", block_2_hash), parent_block_hash: format!("{:?}", block_1_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); let event: FollowEvent = get_next_event(&mut sub).await; @@ -1118,7 +1118,7 @@ async fn follow_forks_pruned_block() { let expected = FollowEvent::Initialized(Initialized { finalized_block_hash: format!("{:?}", block_3_hash), finalized_block_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -1142,7 +1142,7 @@ async fn follow_forks_pruned_block() { block_hash: format!("{:?}", block_6_hash), parent_block_hash: format!("{:?}", block_3_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); let event: FollowEvent = get_next_event(&mut sub).await; @@ -1233,7 +1233,7 @@ async fn follow_report_multiple_pruned_block() { let expected = FollowEvent::Initialized(Initialized { finalized_block_hash: format!("{:?}", finalized_hash), finalized_block_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -1242,7 +1242,7 @@ async fn follow_report_multiple_pruned_block() { block_hash: format!("{:?}", block_1_hash), parent_block_hash: format!("{:?}", finalized_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -1251,7 +1251,7 @@ async fn follow_report_multiple_pruned_block() { block_hash: format!("{:?}", block_2_hash), parent_block_hash: format!("{:?}", block_1_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -1260,7 +1260,7 @@ async fn follow_report_multiple_pruned_block() { block_hash: format!("{:?}", block_3_hash), parent_block_hash: format!("{:?}", block_2_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -1270,7 +1270,7 @@ async fn follow_report_multiple_pruned_block() { block_hash: format!("{:?}", block_4_hash), parent_block_hash: format!("{:?}", block_1_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -1279,7 +1279,7 @@ async fn follow_report_multiple_pruned_block() { block_hash: format!("{:?}", block_5_hash), parent_block_hash: format!("{:?}", block_4_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -1325,7 +1325,7 @@ async fn follow_report_multiple_pruned_block() { block_hash: format!("{:?}", block_6_hash), parent_block_hash: format!("{:?}", block_3_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); let event: FollowEvent = get_next_event(&mut sub).await; @@ -1511,7 +1511,7 @@ async fn follow_finalized_before_new_block() { let expected = FollowEvent::Initialized(Initialized { finalized_block_hash: format!("{:?}", finalized_hash), finalized_block_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -1521,7 +1521,7 @@ async fn follow_finalized_before_new_block() { block_hash: format!("{:?}", block_1_hash), parent_block_hash: format!("{:?}", finalized_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected); @@ -1556,7 +1556,7 @@ async fn follow_finalized_before_new_block() { block_hash: format!("{:?}", block_2_hash), parent_block_hash: format!("{:?}", block_1_hash), new_runtime: None, - runtime_updates: false, + with_runtime: false, }); assert_eq!(event, expected);