Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement subscription support in the client #436

Merged
merged 39 commits into from
Jul 4, 2019

Conversation

dvc94ch
Copy link
Contributor

@dvc94ch dvc94ch commented May 24, 2019

The PR closes #412 and #444 . Currently the jsonrpc client ignores #[pubsub ...]. With these changes it should support the pubsub attribute.

@dvdplm
Copy link
Contributor

dvdplm commented May 24, 2019

Can you add a description to guide reviewers perhaps? What triggered the PR and how it goes about improving the status quo, what are the salient points of the PR etc. Thanks!

@dvc94ch dvc94ch requested review from ascjones and tomusdrw May 25, 2019 00:12
Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Couple of grumbles to address.

core-client/src/lib.rs Outdated Show resolved Hide resolved
core-client/src/lib.rs Outdated Show resolved Hide resolved
core-client/src/lib.rs Outdated Show resolved Hide resolved
core-client/src/transports/duplex.rs Outdated Show resolved Hide resolved
core-client/src/transports/duplex.rs Outdated Show resolved Hide resolved
core-client/src/transports/local.rs Outdated Show resolved Hide resolved
core/examples/params.rs Outdated Show resolved Hide resolved
core/src/types/response.rs Outdated Show resolved Hide resolved
core/src/types/response.rs Outdated Show resolved Hide resolved
core/src/types/response.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ascjones ascjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you've addressed the grumbles and fixed conflicts I'll do another pass

core-client/src/lib.rs Outdated Show resolved Hide resolved
@dvc94ch
Copy link
Contributor Author

dvc94ch commented Jun 14, 2019

Sorry, I got assigned other tasks. I'll try to find some time this weekend.

Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for looking into this!

I've found a few more possible improvements, we don't need to rush it, so feel free to have a look whenever you have some free time.

core-client/transports/src/transports/duplex.rs Outdated Show resolved Hide resolved
core-client/transports/src/transports/duplex.rs Outdated Show resolved Hide resolved
core-client/transports/src/transports/duplex.rs Outdated Show resolved Hide resolved
core/src/types/params.rs Outdated Show resolved Hide resolved
core/src/types/response.rs Outdated Show resolved Hide resolved
@ascjones ascjones mentioned this pull request Jun 28, 2019
6 tasks
@llebout
Copy link

llebout commented Jun 30, 2019

Thanks a lot for this work. I will need this soon!

@dvc94ch dvc94ch requested a review from tomusdrw July 1, 2019 13:37
Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a PR to address most of the grumbles: dvc94ch#2

@dvc94ch please let me know what do you think.

@@ -5,4 +5,7 @@
//!
//! See documentation of [`jsonrpc-client-transports`](../jsonrpc_client_transports/) for more details.

#![deny(missing_docs)]
#![deny(warnings)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't deny(warnings) to prevent uncontrolled build failures in newer versions of the compiler or external crates. Please remove.

@@ -1,6 +1,7 @@
//! JSON-RPC client implementation.

#![deny(missing_docs)]
#![deny(warnings)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

.into_future()
.map(move |(result, _)| {
drop(client);
result.unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check that the message is one of the three we're sending?

let request_str = match msg {
RpcMessage::Call(msg) => {
let (id, request_str) = self.request_builder.call_request(&msg);
if self.pending_requests.contains_key(&id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just check the return value of insert instead of doing an extra lookup.

if self.pending_requests.insert(id, msg.sender).is_some() {
 log::error!(...);
}

if map.contains_key(&id) {
log::error!("reuse of request id {:?}", id);
}
map.insert(id.clone(), subscription);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

RpcMessage::Subscribe(msg) => {
let (id, request_str) = self.request_builder.subscribe_request(
msg.subscription.subscribe.clone(),
msg.subscription.subscribe_params.clone(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to clone here? Couldn't we destructure the msg.subscription also to avoid repetition?

let SubscribeMessage { subscribe, unsubscribe, notification, subscribe_params, ... } = msg.subscription;

/// A map from the subscription name to the subscription.
subscriptions: HashMap<String, HashMap<Id, Subscription>>,
/// A map from subscription id to id.
subscription_ids: HashMap<SubscriptionId, Id>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need so many mappings?
Can't we have:

enum PendingRequest {
  Subscription(Subscription),
  Call(oneshot::Sender<Result<Value, RpcError>>),
}
pending_requests: HashMap<Id, PendingRequest>,
subscriptions: HashMap<SubscriptionId, Subscription>,

?

The user should guarantee uniqueness of Ids no matter what, we don't need to handle having the same Id for different subscription names.

Address review grumbles
@dvc94ch
Copy link
Contributor Author

dvc94ch commented Jul 2, 2019

Yes, much better

Copy link
Contributor

@ascjones ascjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

As mentioned in a comment, my PR dvc94ch#1 is only a partial fix. Fixed properly in dvc94ch#3. Merged

/// Incoming messages from the underlying transport.
stream: TStream,
/// Unprocessed incoming messages.
incoming: VecDeque<(Id, Result<Value, RpcError>, Option<String>, Option<SubscriptionId>)>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

derive/src/to_delegate.rs Outdated Show resolved Hide resolved
* Handle Subscriber wrapped generic type

* Pubsub Subscriber wrapper with multiple generic types
@dvc94ch dvc94ch merged commit 44c501b into paritytech:master Jul 4, 2019
@ascjones ascjones mentioned this pull request Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Client should implement pubsub support
5 participants