mschneider / solcpp

A fast Solana and Mango Markets C++ SDK
Other
40 stars 13 forks source link

Solana: port websocket api from web3.js #41

Open mschneider opened 1 year ago

mschneider commented 1 year ago

onAccountChange onLogs onProgramAccountChange onRootChange onSignature onSignatureWithOptions onSlotChange onSlotUpdate removeAccountChangeListener removeOnLogsListener removeProgramAccountChangeListener removeRootChangeListener removeSignatureListener removeSlotChangeListener removeSlotUpdateListener

pSN0W commented 1 year ago

@mschneider willing to work on this issue.

mschneider commented 1 year ago

alright! please make sure you check the progress on issue #9 the connected PR is still unmerged

pSN0W commented 1 year ago

Hey, Sorry to bother you, but what's the update on the connected PR. It contain's AccountSubscriber which is useful for the functionalities I am trying to implement. How do you propose I move forward?

mschneider commented 1 year ago

use account subscriber and focus on issue 41 mango v3 functionality is not important at this point

pSN0W commented 1 year ago

Alright I will.

pSN0W commented 1 year ago

Hey, I am done with the code, before making a pull request I am just sharing the implementation detail for the same. The websocket works by creating two threads one thread is used for continuously reading from the websocket while other one is use to continuously writing to the socket. The implementation uses:

In the write thread :

In the read thread, it can read two types of response. One is the notification for the subscription and another is the response to the subscription or unsubscription request. The way this thread works is :

I am also attaching a diagram explaining the same workflow. websocket_workflow websocket_workflow.pdf

The advantage I see of this implementation is that we are limiting everything to two threads and to do more subscription only the subscriptions are required to be pushed to the pendingSubscription map. @aniketfuryrocks has volunteered to look at my code and point out the necessary optimisations.@mschneider and @godmodegalactus can you look at this implementation and suggest required changes so that I can move forward towards making a PR for the same.

mschneider commented 1 year ago

For a review of an architecture proposal it's easier to look at the interfaces / declaration, rather than the control flow logic. Header file and some pseudo code for tests to see the API in use would be perfect.

@aniketfuryrocks please focus on rust, @OmkarAcharekar should help with review from your end.

godmodegalactus commented 1 year ago

Yes I agree with @mschneider, Could you please create a PR to understand your progress on this subject.