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

[WIP] Notifications and pubsub transports #10

Closed
wants to merge 25 commits into from
Closed

Conversation

prestwich
Copy link
Member

Motivation

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@prestwich prestwich added the enhancement New feature or request label Sep 12, 2023
@prestwich prestwich self-assigned this Sep 12, 2023
@@ -9,6 +9,30 @@ pub enum Id {
None,
}

impl PartialOrd for Id {
Copy link
Member Author

@prestwich prestwich Sep 12, 2023

Choose a reason for hiding this comment

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

allows use as key in btreemaps. implementation is arbitrary, but totally ordered

use serde::{ser::SerializeMap, Deserialize, Serialize, Serializer};

#[derive(Debug, Deserialize)]
pub struct EthNotification<T = Box<serde_json::value::RawValue>> {
Copy link
Member Author

Choose a reason for hiding this comment

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

these are distinct from JSON-PRC notifications (which are ID-less requests)

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

Superficial review

crates/json-rpc/src/notification.rs Outdated Show resolved Hide resolved
crates/json-rpc/src/request.rs Outdated Show resolved Hide resolved
Comment on lines +9 to +11
/// The backend SHOULD shut down when the handle is dropped (as indicated by
/// the shutdown channel).
pub struct ConnectionHandle {
Copy link
Member

Choose a reason for hiding this comment

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

Should this impl Drop? Then fn shutdown just drops self

Copy link
Member Author

Choose a reason for hiding this comment

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

so this is a bit of a trick with oneshot channels sending (). because dropping the sender causes the Receiver to error on future recv attempts, if you're using the channel to communicate "I've gone away" without any additional info, you never actually need to .send(()). you can just drop the sender, and have the task owning the receiver treat the error as the communication

Copy link
Member Author

@prestwich prestwich Oct 1, 2023

Choose a reason for hiding this comment

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

we could do this with the receiver half of to_socket

however, doing it that way would always result in the channel being drained into the socket before the task knows it should shut down. Using a separate channel prevents that extra work

crates/transports/src/pubsub/service.rs Outdated Show resolved Hide resolved
}

/// The reciprocal of [`ConnectionHandle`].
pub struct ConnectionInterface {
Copy link
Member Author

Choose a reason for hiding this comment

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

needs better name

@prestwich
Copy link
Member Author

will be superseded

@prestwich prestwich closed this Oct 22, 2023
@prestwich prestwich deleted the prestwich/pubsub branch October 28, 2023 18:55
@prestwich prestwich restored the prestwich/pubsub branch October 28, 2023 18:55
@DaniPopes DaniPopes deleted the prestwich/pubsub branch March 11, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants