Skip to content

Commit

Permalink
add an rpc client dedicated for background ops
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsutton committed Dec 26, 2023
1 parent 9e3b89c commit c3ef437
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions cmd/kaspawallet/daemon/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package server

import (
"fmt"
"github.com/kaspanet/kaspad/version"
"net"
"os"
"sync"
"sync/atomic"
"time"

"github.com/kaspanet/kaspad/version"

"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"

"github.com/kaspanet/kaspad/util/txmass"
Expand All @@ -29,8 +30,9 @@ import (
type server struct {
pb.UnimplementedKaspawalletdServer

rpcClient *rpcclient.RPCClient
params *dagconfig.Params
rpcClient *rpcclient.RPCClient // RPC client for ongoing user requests
backgroundRpcClient *rpcclient.RPCClient // RPC client dedicated for address and UTXO background fetching

Check failure on line 34 in cmd/kaspawallet/daemon/server/server.go

View workflow job for this annotation

GitHub Actions / Tests, ubuntu-latest

struct field backgroundRpcClient should be backgroundRPCClient

Check failure on line 34 in cmd/kaspawallet/daemon/server/server.go

View workflow job for this annotation

GitHub Actions / Tests, macos-latest

struct field backgroundRpcClient should be backgroundRPCClient

Check failure on line 34 in cmd/kaspawallet/daemon/server/server.go

View workflow job for this annotation

GitHub Actions / Tests, ubuntu-latest

struct field backgroundRpcClient should be backgroundRPCClient

Check failure on line 34 in cmd/kaspawallet/daemon/server/server.go

View workflow job for this annotation

GitHub Actions / Tests, macos-latest

struct field backgroundRpcClient should be backgroundRPCClient
params *dagconfig.Params

lock sync.RWMutex
utxosSortedByAmount []*walletUTXO
Expand Down Expand Up @@ -76,6 +78,10 @@ func Start(params *dagconfig.Params, listen, rpcServer string, keysFilePath stri
if err != nil {
return (errors.Wrapf(err, "Error connecting to RPC server %s", rpcServer))
}
backgroundRpcClient, err := connectToRPC(params, rpcServer, timeout)

Check failure on line 81 in cmd/kaspawallet/daemon/server/server.go

View workflow job for this annotation

GitHub Actions / Tests, ubuntu-latest

var backgroundRpcClient should be backgroundRPCClient

Check failure on line 81 in cmd/kaspawallet/daemon/server/server.go

View workflow job for this annotation

GitHub Actions / Tests, macos-latest

var backgroundRpcClient should be backgroundRPCClient

Check failure on line 81 in cmd/kaspawallet/daemon/server/server.go

View workflow job for this annotation

GitHub Actions / Tests, ubuntu-latest

var backgroundRpcClient should be backgroundRPCClient

Check failure on line 81 in cmd/kaspawallet/daemon/server/server.go

View workflow job for this annotation

GitHub Actions / Tests, macos-latest

var backgroundRpcClient should be backgroundRPCClient
if err != nil {
return (errors.Wrapf(err, "Error making a second connection to RPC server %s", rpcServer))
}

log.Infof("Connected, reading keys file %s...", keysFilePath)
keysFile, err := keys.ReadKeysFile(params, keysFilePath)
Expand All @@ -90,6 +96,7 @@ func Start(params *dagconfig.Params, listen, rpcServer string, keysFilePath stri

serverInstance := &server{
rpcClient: rpcClient,
backgroundRpcClient: backgroundRpcClient,
params: params,
utxosSortedByAmount: []*walletUTXO{},
nextSyncStartIndex: 0,
Expand Down
6 changes: 3 additions & 3 deletions cmd/kaspawallet/daemon/server/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *server) collectAddresses(start, end uint32) error {
return err
}

getBalancesByAddressesResponse, err := s.rpcClient.GetBalancesByAddresses(addressSet.strings())
getBalancesByAddressesResponse, err := s.backgroundRpcClient.GetBalancesByAddresses(addressSet.strings())
if err != nil {
return err
}
Expand Down Expand Up @@ -293,12 +293,12 @@ func (s *server) refreshUTXOs() error {
// and not in consensus, and between the calls its spending transaction will be
// added to consensus and removed from the mempool, so `getUTXOsByAddressesResponse`
// will include an obsolete output.
mempoolEntriesByAddresses, err := s.rpcClient.GetMempoolEntriesByAddresses(addresses, true, true)
mempoolEntriesByAddresses, err := s.backgroundRpcClient.GetMempoolEntriesByAddresses(addresses, true, true)
if err != nil {
return err
}

getUTXOsByAddressesResponse, err := s.rpcClient.GetUTXOsByAddresses(addresses)
getUTXOsByAddressesResponse, err := s.backgroundRpcClient.GetUTXOsByAddresses(addresses)
if err != nil {
return err
}
Expand Down

0 comments on commit c3ef437

Please sign in to comment.