Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
109 changes: 35 additions & 74 deletions lib/src/json_rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ define_methods! {
// These functions are a custom addition in smoldot. As of the writing of this comment, there
// is no plan to standardize them. See <https://github.com/paritytech/smoldot/issues/2245> and
// <https://github.com/paritytech/smoldot/issues/2456>.
network_unstable_subscribeEvents() -> Cow<'a, str>,
network_unstable_unsubscribeEvents(subscription: Cow<'a, str>) -> (),
sudo_network_unstable_watch() -> Cow<'a, str>,
sudo_network_unstable_unwatch(subscription: Cow<'a, str>) -> (),
chainHead_unstable_finalizedDatabase(#[rename = "maxSizeBytes"] max_size_bytes: Option<u64>) -> Cow<'a, str>,
}

Expand All @@ -525,7 +525,7 @@ define_methods! {

// This function is a custom addition in smoldot. As of the writing of this comment, there is
// no plan to standardize it. See https://github.com/paritytech/smoldot/issues/2245.
network_unstable_event(subscription: Cow<'a, str>, result: NetworkEvent<'a>) -> (),
sudo_networkState_event(subscription: Cow<'a, str>, result: NetworkEvent) -> (),
}

#[derive(Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -849,90 +849,51 @@ pub struct TransactionWatchEventBlock {
/// See <https://github.com/paritytech/smoldot/issues/2245>.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(tag = "event")]
pub enum NetworkEvent<'a> {
#[serde(rename = "startConnect")]
StartConnect {
when: u64,
#[serde(rename = "connectionId")]
connection_id: u32,
multiaddr: Cow<'a, str>,
},
#[serde(rename = "connected")]
Connected {
when: u64,
pub enum NetworkEvent {
#[serde(rename = "connectionState")]
ConnectionState {
#[serde(rename = "connectionId")]
connection_id: u32,
},
#[serde(rename = "handshakeFinished")]
HandshakeFinished {
#[serde(rename = "targetPeerId", skip_serializing_if = "Option::is_none")]
target_peer_id: Option<String>,
#[serde(rename = "targetMultiaddr")]
target_multiaddr: String,
status: NetworkEventStatus,
direction: NetworkEventDirection,
when: u64,
#[serde(rename = "connectionId")]
connection_id: u32,
#[serde(rename = "peerId")]
peer_id: Cow<'a, str>,
},
#[serde(rename = "stop")]
Stop {
when: u64,
#[serde(rename = "connectionId")]
connection_id: u32,
reason: Cow<'a, str>,
},
#[serde(rename = "out-slot-assign")]
OutSlotAssign {
when: u64,
#[serde(rename = "peerId")]
peer_id: Cow<'a, str>,
},
#[serde(rename = "out-slot-unassign")]
OutSlotUnassign {
when: u64,
#[serde(rename = "peerId")]
peer_id: Cow<'a, str>,
},
#[serde(rename = "in-slot-assign")]
InSlotAssign {
when: u64,
#[serde(rename = "peerId")]
peer_id: Cow<'a, str>,
},
#[serde(rename = "in-slot-unassign")]
InSlotUnassign {
when: u64,
#[serde(rename = "peerId")]
peer_id: Cow<'a, str>,
},
#[serde(rename = "in-slot-to-out-slot")]
InSlotToOutSlot {
when: u64,
#[serde(rename = "peerId")]
peer_id: Cow<'a, str>,
},
#[serde(rename = "substream-out-open")]
SubstreamOutOpen {
when: u64,
#[serde(rename = "substreamState")]
SubstreamState {
#[serde(rename = "connectionId")]
connection_id: u32,
#[serde(rename = "substreamId")]
substream_id: u32,
status: NetworkEventStatus,
#[serde(rename = "protocolName")]
protocol_name: Cow<'a, str>,
},
#[serde(rename = "substream-out-accept")]
SubstreamOutAccept {
when: u64,
#[serde(rename = "substreamId")]
substream_id: u32,
},
#[serde(rename = "substream-out-stop")]
SubstreamOutStop {
protocol_name: String,
direction: NetworkEventDirection,
when: u64,
#[serde(rename = "substreamId")]
substream_id: u32,
reason: Cow<'a, str>,
},
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum NetworkEventStatus {
#[serde(rename = "connecting")]
Connecting,
#[serde(rename = "open")]
Open,
#[serde(rename = "closed")]
Close,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum NetworkEventDirection {
#[serde(rename = "in")]
In,
#[serde(rename = "out")]
Out,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Header {
#[serde(rename = "parentHash")]
Expand Down
16 changes: 6 additions & 10 deletions lib/src/json_rpc/service/client_main_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ impl ClientMainTask {
| methods::MethodCall::state_subscribeRuntimeVersion { .. }
| methods::MethodCall::state_subscribeStorage { .. }
| methods::MethodCall::transaction_unstable_submitAndWatch { .. }
| methods::MethodCall::network_unstable_subscribeEvents { .. }
| methods::MethodCall::sudo_network_unstable_watch { .. }
| methods::MethodCall::chainHead_unstable_follow { .. } => {
// Subscription starting requests.

Expand Down Expand Up @@ -541,9 +541,7 @@ impl ClientMainTask {
| methods::MethodCall::state_unsubscribeRuntimeVersion { subscription, .. }
| methods::MethodCall::state_unsubscribeStorage { subscription, .. }
| methods::MethodCall::transaction_unstable_unwatch { subscription, .. }
| methods::MethodCall::network_unstable_unsubscribeEvents {
subscription, ..
}
| methods::MethodCall::sudo_network_unstable_unwatch { subscription, .. }
| methods::MethodCall::chainHead_unstable_unfollow {
follow_subscription: subscription,
..
Expand All @@ -568,9 +566,9 @@ impl ClientMainTask {
methods::MethodCall::transaction_unstable_unwatch {
..
} => methods::Response::transaction_unstable_unwatch(()),
methods::MethodCall::network_unstable_unsubscribeEvents {
methods::MethodCall::sudo_network_unstable_unwatch {
..
} => methods::Response::network_unstable_unsubscribeEvents(()),
} => methods::Response::sudo_network_unstable_unwatch(()),
methods::MethodCall::chainHead_unstable_unfollow { .. } => {
methods::Response::chainHead_unstable_unfollow(())
}
Expand Down Expand Up @@ -1164,10 +1162,8 @@ impl SubscriptionStartProcess {
&self.subscription_id,
))
}
methods::MethodCall::network_unstable_subscribeEvents { .. } => {
methods::Response::network_unstable_subscribeEvents(Cow::Borrowed(
&self.subscription_id,
))
methods::MethodCall::sudo_network_unstable_watch { .. } => {
methods::Response::sudo_network_unstable_watch(Cow::Borrowed(&self.subscription_id))
}
methods::MethodCall::chainHead_unstable_follow { .. } => {
methods::Response::chainHead_unstable_follow(Cow::Borrowed(&self.subscription_id))
Expand Down
10 changes: 5 additions & 5 deletions light-base/src/json_rpc_service/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ impl<TPlat: PlatformRef> Background<TPlat> {
| methods::MethodCall::sudo_unstable_version { .. }
| methods::MethodCall::transaction_unstable_submitAndWatch { .. }
| methods::MethodCall::transaction_unstable_unwatch { .. }
| methods::MethodCall::network_unstable_subscribeEvents { .. }
| methods::MethodCall::network_unstable_unsubscribeEvents { .. }
| methods::MethodCall::sudo_network_unstable_watch { .. }
| methods::MethodCall::sudo_network_unstable_unwatch { .. }
| methods::MethodCall::chainHead_unstable_finalizedDatabase { .. } => {}
}

Expand Down Expand Up @@ -629,8 +629,8 @@ impl<TPlat: PlatformRef> Background<TPlat> {
| methods::MethodCall::sudo_unstable_version { .. }
| methods::MethodCall::transaction_unstable_submitAndWatch { .. }
| methods::MethodCall::transaction_unstable_unwatch { .. }
| methods::MethodCall::network_unstable_subscribeEvents { .. }
| methods::MethodCall::network_unstable_unsubscribeEvents { .. }
| methods::MethodCall::sudo_network_unstable_watch { .. }
| methods::MethodCall::sudo_network_unstable_unwatch { .. }
| methods::MethodCall::chainHead_unstable_finalizedDatabase { .. } => {}
}

Expand All @@ -654,7 +654,7 @@ impl<TPlat: PlatformRef> Background<TPlat> {
self.submit_and_watch_transaction(request).await
}

_method @ methods::MethodCall::network_unstable_subscribeEvents { .. } => {
_method @ methods::MethodCall::sudo_network_unstable_watch { .. } => {
// TODO: implement the ones that make sense to implement ^
log!(
&self.platform,
Expand Down