Skip to content

Conversation

@ali-behjati
Copy link
Collaborator

@ali-behjati ali-behjati commented Apr 19, 2023

This PR adds Websocket implementation with price service interface to Hermes. Each websocket connection is wrapped in a Subscriber struct which acts as an actor.

As discussed before, after merging this I am planning to restructure everything to only support accumulator and things gets changed. The current structure is not great and will be changed when the refactor is done.

@ali-behjati ali-behjati requested review from Reisen and thmzlt April 19, 2023 19:14
@vercel
Copy link

vercel bot commented Apr 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
example-oracle-amm ⬜️ Ignored (Inspect) May 1, 2023 5:04pm
xc-admin-frontend ⬜️ Ignored (Inspect) May 1, 2023 5:04pm

@ali-behjati ali-behjati requested a review from jayantk April 28, 2023 11:26
pub struct Subscriber {
id: SubscriberId,
closed: bool,
store: Store,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This kind of dependency is not great. We should rethink about the structure in the coming refactors.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is just saying that each websocket subscriber holds a reference to the same global store of price information? if so, that seems ok to me?

Copy link
Contributor

Choose a reason for hiding this comment

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

actually does this store need a lock to manage writes / reads of a feed across threads?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are locks to prevent misuse (Rust doesn't allow otherwise :D) but I also created the direction of dependency in a way that it doesn't introduce a deadlock.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think generally it's fine. I don't like it much because it's half actor and half part of a global component.

I could store the Subscriber as a global component and let the global dispatcher directly call the methods and I tried. The result wasn't great because the Subscriber has a stream coming from the client and when it gets closed on destruction it should remove itself from the global reference to it (which it has access to the reference) and ...

I think the actor model offers better decoupling but that's a bigger design decision that I didn't want to make on this PR.

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

I don't totally understand how this works but it seems generally reasonable. I think some tests would be nice (though understand why you wouldn't want to do that given you're about to refactor everything)

pub struct Subscriber {
id: SubscriberId,
closed: bool,
store: Store,
Copy link
Contributor

Choose a reason for hiding this comment

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

this is just saying that each websocket subscriber holds a reference to the same global store of price information? if so, that seems ok to me?

pub struct Subscriber {
id: SubscriberId,
closed: bool,
store: Store,
Copy link
Contributor

Choose a reason for hiding this comment

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

actually does this store need a lock to manage writes / reads of a feed across threads?

@ali-behjati ali-behjati merged commit 8a5a74e into main May 1, 2023
@ali-behjati ali-behjati deleted the hermes/ws branch May 1, 2023 17:05
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.

4 participants