Comments (10)
gm @whymidnight
an RPC client (client := rpc.New(endpoint)
) is meant to be only one and used many times, potentially by many different callers at the same time.
from solana-go.
what's your use-case that requires throw-away clients?
from solana-go.
at one point in the past, i had baked in anchor events and spawned goroutines that contained some logic with many rpc calls upon receiving the message over the rpc websocket. i wasnt sure if this was threadsafe at the time so it seemed more elegant to instead instance a new rpc struct inside the callback so that each goroutine had its own rpc client. however this didnt scale because of the above issue.
additionally, this approach of passing an rpc.Client
pointer to functions that require does not allow for go modules to contain their own rpc lifecycle like - for instance: i have a utilities module for sending transactions, parsing chain state, etc; another module for my chain program; and some arbitrary third module.
if i wanted to import these modules in a disparate codebase, would require to also declare rpc.New
in the main module which could be alleviated if the above modules could instance rpc.New
themselves. however these modules must close their sockets to prevent the main module from exceeding open sockets.
from solana-go.
and you're doing the same thing with websocket clients?
from solana-go.
well i can foresee this applying to websocket clients as well like awaiting for signature confirmations via ws in a confined thread inside the main thread.
from solana-go.
the websocket client is also thread-safe and supports multiple concurrent subscriptions.
from solana-go.
however the http client design means that disparate modules are dependent on the main thread passing a pointer which isn't as elegant when modules could manage their own lifecycle of it. however is actually probably bad design in the bigger scheme of things since this means >1 rpc.Client
versus 1 global rpc.Client
. as the issue of exceeding open sockets could still arise.
from solana-go.
the rpc client is made to be as efficient as possible (reusing TCP connections, enabling gzip compression, etc.)
if you don't want all of that, you'll waste time & resources reconnecting for each RPC call (maybe even having to make a DNS resolution).
from solana-go.
for instance: i have a utilities module for sending transactions, parsing chain state, etc; another module for my chain program; and some arbitrary third module.
great! use 3 rpc clients 😁
from solana-go.
if you don't want all of that, you'll waste time & resources reconnecting for each RPC call (maybe even having to make a DNS resolution).
thats exactly what i needed to hear. it took a discussion to realise this lol. thank you! i'll close this issue now.
much love,
D.
from solana-go.
Related Issues (20)
- Create associated token account idempotent instruction
- BlockSubscribe no data output. HOT 1
- Transaction failed to sanitize accounts offsets correctly HOT 2
- Send SPL Token using this Library HOT 2
- do you suport Raydium dex interface?
- how to get token owner of a token account HOT 4
- panic while decoding Instruction in spl transfer transaction HOT 3
- ws blocksubscribe - does extract rewords
- How to parse Program data from log?
- Versioned transaction HOT 3
- send transaction success,but can not locate transaction on blockchain HOT 3
- How to make transaction extra fees use NewTransaction() on transaction.go files ?
- How can we obtain the real token receiving address?
- Create tx with LUT
- How to register the Token's metadata
- How to get tx receipt with hash
- How can I parse other raw_tx
- Instruction Impl Type Inconsistency: Builder vs Unmarshal
- Using GetParsedTransaction to obtain event data is incorrect
- Inconsistent Signature Order in PartialSign Function HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solana-go.