8000 feat(providers/api): multi-solana-client [BLO-1067] by nivasan1 · Pull Request #308 · skip-mev/connect · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

feat(providers/api): multi-solana-client [BLO-1067] #308

Merged
merged 36 commits into from
Apr 8, 2024

Conversation

nivasan1
Copy link
Contributor
@nivasan1 nivasan1 commented Apr 4, 2024

In This PR

  • I introduce an Endpoints field to the config, where we can place node-urls / authentication, etc
  • I introduce a MultiClient to raydium to permit querying across multiple separated node-providers + aggregating repsonses from among them

Copy link
codecov bot 8000 commented Apr 4, 2024

Codecov Report

Attention: Patch coverage is 57.83133% with 35 lines in your changes are missing coverage. Please review.

Project coverage is 62.46%. Comparing base (0fe0900) to head (8026a69).

Files Patch % Lines
cmd/slinky-config/main.go 0.00% 13 Missing ⚠️
providers/apis/defi/raydium/price_fetcher.go 41.17% 7 Missing and 3 partials ⚠️
providers/apis/defi/raydium/multi_client.go 80.95% 7 Missing and 1 partial ⚠️
providers/apis/defi/raydium/options.go 0.00% 3 Missing ⚠️
cmd/client/main.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #308   +/-   ##
=======================================
  Coverage   62.46%   62.46%           
=======================================
  Files         220      222    +2     
  Lines        9734     9798   +64     
=======================================
+ Hits         6080     6120   +40     
- Misses       3102     3122   +20     
- Partials      552      556    +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nivasan1 nivasan1 force-pushed the nv/implement-raydium-query-handler branch from 369e64c to 6f60353 Compare April 4, 2024 20:06
@nivasan1 nivasan1 force-pushed the nv/implement-multi-solana-client branch from eab5cba to 3407a12 Compare April 4, 2024 20:26
@nivasan1 nivasan1 force-pushed the nv/implement-raydium-query-handler branch from 5739225 to f279e4c Compare April 5, 2024 18:43
@nivasan1 nivasan1 force-pushed the nv/implement-multi-solana-client branch from 76d4f58 to ff34ce4 Compare April 5, 2024 19:20
@nivasan1 nivasan1 changed the base branch from nv/implement-raydium-query-handler to main April 5, 2024 19:20
@nivasan1 nivasan1 requested a review from aljo242 April 5, 2024 19:22
Comment on lines 378 to 384
nodes := strings.Split(solanaNodeURLs, ",")

for _, node := range nodes {
cfg.Endpoints = append(cfg.Endpoints, config.Endpoint{
URL: node,
})
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The solanaNodeURLs flag should just be a StringSliceVarP. It eliminates all of this code.

@nivasan1 nivasan1 requested a review from Eric-Warehime April 5, 2024 19:32
Comment on lines 49 to 81
// Create a channel to receive the responses from the underlying clients
responsesCh := make(chan *rpc.GetMultipleAccountsResult, len(c.clients))

// spawn a goroutine for each client to fetch the accounts
var wg sync.WaitGroup
wg.Add(len(c.clients))

for i := range c.clients {
go func(client SolanaJSONRPCClient) {
defer wg.Done()
resp, err := client.GetMultipleAccountsWithOpts(ctx, accounts, opts)
if err != nil {
c.logger.Error("failed to fetch accounts", zap.Error(err))
return
}
responsesCh <- resp
}(c.clients[i])
}

// close the channel once all responses are received, or the context is cancelled
go func() {
select {
case <-ctx.Done():
c.logger.Error("context cancelled")
case <-channelForWaitGroup(&wg):
}
close(responsesCh)
}()

responses := make([]*rpc.GetMultipleAccountsResult, 0, len(c.clients))
for resp := range responsesCh {
responses = append(responses, resp)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Create a channel to receive the responses from the underlying clients
responsesCh := make(chan *rpc.GetMultipleAccountsResult, len(c.clients))
// spawn a goroutine for each client to fetch the accounts
var wg sync.WaitGroup
wg.Add(len(c.clients))
for i := range c.clients {
go func(client SolanaJSONRPCClient) {
defer wg.Done()
resp, err := client.GetMultipleAccountsWithOpts(ctx, accounts, opts)
if err != nil {
c.logger.Error("failed to fetch accounts", zap.Error(err))
return
}
responsesCh <- resp
}(c.clients[i])
}
// close the channel once all responses are received, or the context is cancelled
go func() {
select {
case <-ctx.Done():
c.logger.Error("context cancelled")
case <-channelForWaitGroup(&wg):
}
close(responsesCh)
}()
responses := make([]*rpc.GetMultipleAccountsResult, 0, len(c.clients))
for resp := range responsesCh {
responses = append(responses, resp)
}
responses := make([]*rpc.GetMultipleAccountsResult, 0, len(c.clients))
// spawn a goroutine for each client to fetch the accounts
var wg sync.WaitGroup
wg.Add(len(c.clients))
for i := range c.clients {
go func(client SolanaJSONRPCClient) {
defer wg.Done()
resp, err := client.GetMultipleAccountsWithOpts(ctx, accounts, opts)
if err != nil {
c.logger.Error("failed to fetch accounts", zap.Error(err))
return
}
responses[i] = resp
}(c.clients[i])
}
wg.Wait()

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm struggling to see why we need anything more than parallelized fetches here. Anything that errors out will properly have no results, and we block on all the responses returning no matter what.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic defers to context closure over all clients finishing their outbound requests. Agreed that the behavior is the same if the underlying client defers to context closure

@nivasan1 nivasan1 requested a review from Eric-Warehime April 5, 2024 22:32
@nivasan1 nivasan1 merged commit aab0e63 into main Apr 8, 2024
@zrbecker zrbecker deleted the nv/implement-multi-solana-client branch November 5, 2024 21:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0