fix: concurrent client access
This commit is contained in:
parent
dbd52edcd7
commit
4fd94c2345
|
@ -42,9 +42,10 @@ type Client struct {
|
||||||
upstreamURL string
|
upstreamURL string
|
||||||
UpstreamChainID uint64
|
UpstreamChainID uint64
|
||||||
|
|
||||||
local *gethrpc.Client
|
local *gethrpc.Client
|
||||||
upstream *chain.ClientWithFallback
|
upstream *chain.ClientWithFallback
|
||||||
rpcClients map[uint64]*chain.ClientWithFallback
|
rpcClientsMutex sync.RWMutex
|
||||||
|
rpcClients map[uint64]*chain.ClientWithFallback
|
||||||
|
|
||||||
router *router
|
router *router
|
||||||
NetworkManager *network.Manager
|
NetworkManager *network.Manager
|
||||||
|
@ -107,6 +108,8 @@ func (c *Client) SetWalletNotifier(notifier func(chainID uint64, message string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) getClientUsingCache(chainID uint64) (*chain.ClientWithFallback, error) {
|
func (c *Client) getClientUsingCache(chainID uint64) (*chain.ClientWithFallback, error) {
|
||||||
|
c.rpcClientsMutex.Lock()
|
||||||
|
defer c.rpcClientsMutex.Unlock()
|
||||||
if rpcClient, ok := c.rpcClients[chainID]; ok {
|
if rpcClient, ok := c.rpcClients[chainID]; ok {
|
||||||
if rpcClient.WalletNotifier == nil {
|
if rpcClient.WalletNotifier == nil {
|
||||||
rpcClient.WalletNotifier = c.walletNotifier
|
rpcClient.WalletNotifier = c.walletNotifier
|
||||||
|
|
Loading…
Reference in New Issue