Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make VSP clients respect tor config #2429

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions dcrwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"decred.org/dcrwallet/v5/spv"
"decred.org/dcrwallet/v5/ticketbuyer"
"decred.org/dcrwallet/v5/version"
"decred.org/dcrwallet/v5/vsp"
"decred.org/dcrwallet/v5/wallet"
"github.com/decred/dcrd/addrmgr/v2"
"github.com/decred/dcrd/wire"
Expand Down Expand Up @@ -170,7 +169,7 @@ func run(ctx context.Context) error {
loader := ldr.NewLoader(activeNet.Params, dbDir, cfg.EnableVoting,
cfg.GapLimit, cfg.WatchLast, cfg.AllowHighFees, cfg.RelayFee.Amount,
cfg.AccountGapLimit, cfg.DisableCoinTypeUpgrades, !cfg.Mixing,
cfg.ManualTickets, cfg.MixSplitLimit)
cfg.ManualTickets, cfg.MixSplitLimit, cfg.dial)

// Stop any services started by the loader after the shutdown procedure is
// initialized and this function returns.
Expand All @@ -190,7 +189,7 @@ func run(ctx context.Context) error {
}()

// Open the wallet when --noinitialload was not set.
var vspClient *vsp.Client
var vspClient *wallet.VSPClient
passphrase := []byte{}
if !cfg.NoInitialLoad {
walletPass := []byte(cfg.WalletPass)
Expand Down Expand Up @@ -271,19 +270,16 @@ func run(ctx context.Context) error {
cfg.PurchaseAccount, err)
return err
}
vspCfg := vsp.Config{
vspCfg := wallet.VSPClientConfig{
URL: cfg.VSPOpts.URL,
PubKey: cfg.VSPOpts.PubKey,
Dialer: cfg.dial,
Wallet: w,
Policy: &vsp.Policy{
Policy: &wallet.VSPPolicy{
MaxFee: cfg.VSPOpts.MaxFee.Amount,
FeeAcct: purchaseAcct,
ChangeAcct: changeAcct,
},
Params: w.ChainParams(),
}
vspClient, err = ldr.VSP(vspCfg)
vspClient, err = w.VSP(vspCfg)
if err != nil {
log.Errorf("vsp: %v", err)
return err
Expand Down
7 changes: 6 additions & 1 deletion internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ type Loader struct {
manualTickets bool
relayFee dcrutil.Amount
mixSplitLimit int
dialer wallet.DialFunc

mu sync.Mutex
}

// NewLoader constructs a Loader.
func NewLoader(chainParams *chaincfg.Params, dbDirPath string, votingEnabled bool, gapLimit uint32,
watchLast uint32, allowHighFees bool, relayFee dcrutil.Amount, accountGapLimit int,
disableCoinTypeUpgrades bool, disableMixing bool, manualTickets bool, mixSplitLimit int) *Loader {
disableCoinTypeUpgrades bool, disableMixing bool, manualTickets bool, mixSplitLimit int, dialer wallet.DialFunc) *Loader {

return &Loader{
chainParams: chainParams,
Expand All @@ -69,6 +70,7 @@ func NewLoader(chainParams *chaincfg.Params, dbDirPath string, votingEnabled boo
manualTickets: manualTickets,
relayFee: relayFee,
mixSplitLimit: mixSplitLimit,
dialer: dialer,
}
}

Expand Down Expand Up @@ -176,6 +178,7 @@ func (l *Loader) CreateWatchingOnlyWallet(ctx context.Context, extendedPubKey st
RelayFee: l.relayFee,
MixSplitLimit: l.mixSplitLimit,
Params: l.chainParams,
Dialer: l.dialer,
}
w, err = wallet.Open(ctx, cfg)
if err != nil {
Expand Down Expand Up @@ -262,6 +265,7 @@ func (l *Loader) CreateNewWallet(ctx context.Context, pubPassphrase, privPassphr
AllowHighFees: l.allowHighFees,
RelayFee: l.relayFee,
Params: l.chainParams,
Dialer: l.dialer,
}
w, err = wallet.Open(ctx, cfg)
if err != nil {
Expand Down Expand Up @@ -319,6 +323,7 @@ func (l *Loader) OpenExistingWallet(ctx context.Context, pubPassphrase []byte) (
RelayFee: l.relayFee,
MixSplitLimit: l.mixSplitLimit,
Params: l.chainParams,
Dialer: l.dialer,
}
w, err = wallet.Open(ctx, cfg)
if err != nil {
Expand Down
31 changes: 12 additions & 19 deletions internal/rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ import (

"decred.org/dcrwallet/v5/chain"
"decred.org/dcrwallet/v5/errors"
"decred.org/dcrwallet/v5/internal/loader"
"decred.org/dcrwallet/v5/p2p"
"decred.org/dcrwallet/v5/rpc/client/dcrd"
"decred.org/dcrwallet/v5/rpc/jsonrpc/types"
"decred.org/dcrwallet/v5/spv"
"decred.org/dcrwallet/v5/version"
"decred.org/dcrwallet/v5/vsp"
"decred.org/dcrwallet/v5/wallet"
"decred.org/dcrwallet/v5/wallet/txauthor"
"decred.org/dcrwallet/v5/wallet/txrules"
Expand Down Expand Up @@ -3344,21 +3342,18 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {
}
}

var vspClient *vsp.Client
var vspClient *wallet.VSPClient
if s.cfg.VSPHost != "" {
cfg := vsp.Config{
cfg := wallet.VSPClientConfig{
URL: s.cfg.VSPHost,
PubKey: s.cfg.VSPPubKey,
Dialer: s.cfg.Dial,
Wallet: w,
Policy: &vsp.Policy{
Policy: &wallet.VSPPolicy{
MaxFee: s.cfg.VSPMaxFee,
FeeAcct: account,
ChangeAcct: changeAccount,
},
Params: w.ChainParams(),
}
vspClient, err = loader.VSP(cfg)
vspClient, err = w.VSP(cfg)
if err != nil {
return nil, rpcErrorf(dcrjson.ErrRPCMisc,
"VSP Server instance failed to start: %v", err)
Expand All @@ -3378,11 +3373,8 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {
MixedAccountBranch: mixedAccountBranch,
MixedSplitAccount: mixedSplitAccount,
ChangeAccount: changeAccount,
}

if vspClient != nil {
request.VSPFeePaymentProcess = vspClient.Process
request.VSPFeePercent = vspClient.FeePercentage
VSPClient: vspClient,
}

ticketsResponse, err := w.PurchaseTickets(ctx, n, request)
Expand Down Expand Up @@ -3447,16 +3439,17 @@ func (s *Server) processUnmanagedTicket(ctx context.Context, icmd any) (any, err
if vspHost == "" {
return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter, "vsphost must be set in options")
}
vspClient, err := loader.LookupVSP(vspHost)
if err != nil {
return nil, err
}

w, ok := s.walletLoader.LoadedWallet()
if !ok {
return nil, errUnloadedWallet
}

vspClient, err := w.LookupVSP(vspHost)
if err != nil {
return nil, err
}

ticket, err := w.NewVSPTicket(ctx, hash)
if err != nil {
return nil, err
Expand Down Expand Up @@ -4703,7 +4696,7 @@ func (s *Server) updateVSPVoteChoices(ctx context.Context, w *wallet.Wallet, tic
}
return err
}
vspClient, err := loader.LookupVSP(vspHost)
vspClient, err := w.LookupVSP(vspHost)
if err != nil {
return err
}
Expand All @@ -4726,7 +4719,7 @@ func (s *Server) updateVSPVoteChoices(ctx context.Context, w *wallet.Wallet, tic
}
return err
}
vspClient, err := loader.LookupVSP(vspHost)
vspClient, err := w.LookupVSP(vspHost)
if err != nil {
return err
}
Expand Down
Loading
Loading