Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

chainHead: Produce method responses on chainHead_follow #14692

Merged
merged 19 commits into from
Aug 8, 2023
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4787dba
chainHead/api: Make storage/body/call pure RPC methods
lexnv Jul 27, 2023
8050811
chainHead: Add mpsc channel between RPC methods
lexnv Jul 27, 2023
3b30eb3
chainHead/subscriptions: Extract mpsc::Sender via BlockGuard
lexnv Jul 27, 2023
d5305a9
chainHead/subscriptions: Generate and provide the method operation ID
lexnv Jul 27, 2023
50c840d
chainHead: Generate `chainHead_body` response
lexnv Jul 27, 2023
6c5940c
chainHead: Generate `chainHead_call` response
lexnv Jul 27, 2023
589efa8
chainHead: Generate `chainHead_storage` responses
lexnv Jul 27, 2023
8062837
chainHead: Propagate responses of methods to chainHead_follow
lexnv Jul 27, 2023
4f7b445
chainHead/tests: Adjust `chainHead_body` responses
lexnv Jul 31, 2023
53fcd99
chainHead/tests: Adjust `chainHead_call` responses
lexnv Jul 31, 2023
167dd72
chainHead/tests: Adjust `chainHead_call` responses
lexnv Jul 31, 2023
35aca6d
chainHead/tests: Ensure unique operation IDs across methods
lexnv Jul 31, 2023
008fa22
chainHead/events: Remove old method events
lexnv Jul 31, 2023
0773aa2
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_ext…
Jul 31, 2023
2e2fa9c
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_ext…
Aug 1, 2023
1ace528
chainHead: Return `InvalidBlock` error if pinning fails
lexnv Aug 8, 2023
5679aa2
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_ext…
lexnv Aug 8, 2023
e189a73
chainHead: Wrap subscription IDs
lexnv Aug 8, 2023
83afea8
chainHead/tests: Ensure separate operation IDs across subscriptions
lexnv Aug 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chainHead/events: Remove old method events
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
  • Loading branch information
lexnv committed Jul 31, 2023
commit 008fa222006e550c4401ffe57f874d73d6b3ec9f
168 changes: 0 additions & 168 deletions client/rpc-spec-v2/src/chain_head/event.rs
Original file line number Diff line number Diff line change
@@ -276,31 +276,6 @@ pub enum FollowEvent<Hash> {
Stop,
}

/// The result of a chain head method.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChainHeadResult<T> {
/// Result of the method.
pub result: T,
}

/// The event generated by the body / call / storage methods.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "event")]
pub enum ChainHeadEvent<T> {
/// The request completed successfully.
Done(ChainHeadResult<T>),
/// The resources requested are inaccessible.
///
/// Resubmitting the request later might succeed.
Inaccessible(ErrorEvent),
/// An error occurred. This is definitive.
Error(ErrorEvent),
/// The provided subscription ID is stale or invalid.
Disjoint,
}

/// The storage item received as paramter.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -351,35 +326,6 @@ pub enum StorageResultType {
ClosestDescendantMerkleValue(String),
}

/// The event generated by storage method.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[serde(tag = "event")]
pub enum ChainHeadStorageEvent {
/// The request produced multiple result items.
Items(ItemsEvent),
/// The request produced multiple result items.
WaitForContinue,
/// The request completed successfully and all the results were provided.
Done,
/// The resources requested are inaccessible.
///
/// Resubmitting the request later might succeed.
Inaccessible,
/// An error occurred. This is definitive.
Error(ErrorEvent),
/// The provided subscription ID is stale or invalid.
Disjoint,
}

/// The request produced multiple result items.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ItemsEvent {
/// The resulting items.
pub items: Vec<StorageResult>,
}

/// The method respose of `chainHead_body`, `chainHead_call` and `chainHead_storage`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -714,56 +660,6 @@ mod tests {
assert_eq!(event_dec, event);
}

#[test]
fn chain_head_done_event() {
let event: ChainHeadEvent<String> =
ChainHeadEvent::Done(ChainHeadResult { result: "A".into() });

let ser = serde_json::to_string(&event).unwrap();
let exp = r#"{"event":"done","result":"A"}"#;
assert_eq!(ser, exp);

let event_dec: ChainHeadEvent<String> = serde_json::from_str(exp).unwrap();
assert_eq!(event_dec, event);
}

#[test]
fn chain_head_inaccessible_event() {
let event: ChainHeadEvent<String> =
ChainHeadEvent::Inaccessible(ErrorEvent { error: "A".into() });

let ser = serde_json::to_string(&event).unwrap();
let exp = r#"{"event":"inaccessible","error":"A"}"#;
assert_eq!(ser, exp);

let event_dec: ChainHeadEvent<String> = serde_json::from_str(exp).unwrap();
assert_eq!(event_dec, event);
}

#[test]
fn chain_head_error_event() {
let event: ChainHeadEvent<String> = ChainHeadEvent::Error(ErrorEvent { error: "A".into() });

let ser = serde_json::to_string(&event).unwrap();
let exp = r#"{"event":"error","error":"A"}"#;
assert_eq!(ser, exp);

let event_dec: ChainHeadEvent<String> = serde_json::from_str(exp).unwrap();
assert_eq!(event_dec, event);
}

#[test]
fn chain_head_disjoint_event() {
let event: ChainHeadEvent<String> = ChainHeadEvent::Disjoint;

let ser = serde_json::to_string(&event).unwrap();
let exp = r#"{"event":"disjoint"}"#;
assert_eq!(ser, exp);

let event_dec: ChainHeadEvent<String> = serde_json::from_str(exp).unwrap();
assert_eq!(event_dec, event);
}

#[test]
fn chain_head_storage_query() {
// Item with Value.
@@ -855,68 +751,4 @@ mod tests {
let dec: StorageResult = serde_json::from_str(exp).unwrap();
assert_eq!(dec, item);
}

#[test]
fn chain_head_storage_event() {
// Event with Items.
let event = ChainHeadStorageEvent::Items(ItemsEvent {
items: vec![
StorageResult {
key: "0x1".into(),
result: StorageResultType::Value("first".into()),
},
StorageResult {
key: "0x2".into(),
result: StorageResultType::Hash("second".into()),
},
],
});
// Encode
let ser = serde_json::to_string(&event).unwrap();
let exp = r#"{"event":"items","items":[{"key":"0x1","value":"first"},{"key":"0x2","hash":"second"}]}"#;
assert_eq!(ser, exp);
// Decode
let dec: ChainHeadStorageEvent = serde_json::from_str(exp).unwrap();
assert_eq!(dec, event);

// Event with WaitForContinue.
let event = ChainHeadStorageEvent::WaitForContinue;
// Encode
let ser = serde_json::to_string(&event).unwrap();
let exp = r#"{"event":"wait-for-continue"}"#;
assert_eq!(ser, exp);
// Decode
let dec: ChainHeadStorageEvent = serde_json::from_str(exp).unwrap();
assert_eq!(dec, event);

// Event with Done.
let event = ChainHeadStorageEvent::Done;
// Encode
let ser = serde_json::to_string(&event).unwrap();
let exp = r#"{"event":"done"}"#;
assert_eq!(ser, exp);
// Decode
let dec: ChainHeadStorageEvent = serde_json::from_str(exp).unwrap();
assert_eq!(dec, event);

// Event with Inaccessible.
let event = ChainHeadStorageEvent::Inaccessible;
// Encode
let ser = serde_json::to_string(&event).unwrap();
let exp = r#"{"event":"inaccessible"}"#;
assert_eq!(ser, exp);
// Decode
let dec: ChainHeadStorageEvent = serde_json::from_str(exp).unwrap();
assert_eq!(dec, event);

// Event with Inaccessible.
let event = ChainHeadStorageEvent::Error(ErrorEvent { error: "reason".into() });
// Encode
let ser = serde_json::to_string(&event).unwrap();
let exp = r#"{"event":"error","error":"reason"}"#;
assert_eq!(ser, exp);
// Decode
let dec: ChainHeadStorageEvent = serde_json::from_str(exp).unwrap();
assert_eq!(dec, event);
}
}
4 changes: 2 additions & 2 deletions client/rpc-spec-v2/src/chain_head/mod.rs
Original file line number Diff line number Diff line change
@@ -39,8 +39,8 @@ mod subscription;
pub use api::ChainHeadApiServer;
pub use chain_head::ChainHead;
pub use event::{
BestBlockChanged, ChainHeadEvent, ChainHeadResult, ErrorEvent, Finalized, FollowEvent,
Initialized, NewBlock, RuntimeEvent, RuntimeVersionEvent,
BestBlockChanged, ErrorEvent, Finalized, FollowEvent, Initialized, NewBlock, RuntimeEvent,
RuntimeVersionEvent,
};

use sp_core::hexdisplay::{AsBytesRef, HexDisplay};