Skip to content

Commit

Permalink
vsp: Unparam Policy.
Browse files Browse the repository at this point in the history
Passing Policy into the funcs of Client seems to be unnecessary and unused.
  • Loading branch information
jholdstock authored and jrick committed Apr 24, 2023
1 parent bf8e7a0 commit d95475b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion dcrwallet.go
Expand Up @@ -432,7 +432,7 @@ func run(ctx context.Context) error {

loader.RunAfterLoad(func(w *wallet.Wallet) {
if vspClient != nil && cfg.VSPOpts.Sync {
vspClient.ProcessManagedTickets(ctx, vspClient.Policy)
vspClient.ProcessManagedTickets(ctx)
}

if cfg.SPV {
Expand Down
6 changes: 3 additions & 3 deletions internal/rpc/rpcserver/server.go
Expand Up @@ -4153,7 +4153,7 @@ func (s *walletServer) SyncVSPFailedTickets(ctx context.Context, req *pb.SyncVSP
// process tickets fee if needed.
for _, ticketHash := range failedTicketsFee {
feeTx := new(wire.MsgTx)
err := vspClient.ProcessWithPolicy(ctx, &ticketHash, feeTx, policy)
err := vspClient.Process(ctx, &ticketHash, feeTx)
if err != nil {
// if it fails to process again, we log it and continue with
// the wallet start.
Expand Down Expand Up @@ -4191,7 +4191,7 @@ func (s *walletServer) ProcessManagedTickets(ctx context.Context, req *pb.Proces
return nil, status.Errorf(codes.Unknown, "VSPClient instance failed to start. Error: %v", err)
}

err = vspClient.ProcessManagedTickets(ctx, policy)
err = vspClient.ProcessManagedTickets(ctx)
if err != nil {
return nil, status.Errorf(codes.Unknown, "ProcessManagedTickets failed. Error: %v", err)
}
Expand Down Expand Up @@ -4236,7 +4236,7 @@ func (s *walletServer) ProcessUnmanagedTickets(ctx context.Context, req *pb.Proc
return nil
})
if errors.Is(err, errUnmanagedTickets) {
vspClient.ProcessUnprocessedTickets(ctx, policy)
vspClient.ProcessUnprocessedTickets(ctx)
}

return &pb.ProcessUnmanagedTicketsResponse{}, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/vsp/feepayment.go
Expand Up @@ -180,7 +180,7 @@ func (fp *feePayment) remove(reason string) {

// feePayment returns an existing managed fee payment, or creates and begins
// processing a fee payment for a ticket.
func (c *Client) feePayment(ctx context.Context, ticketHash *chainhash.Hash, policy Policy, paidConfirmed bool) (fp *feePayment) {
func (c *Client) feePayment(ctx context.Context, ticketHash *chainhash.Hash, paidConfirmed bool) (fp *feePayment) {
c.mu.Lock()
fp = c.jobs[*ticketHash]
c.mu.Unlock()
Expand Down Expand Up @@ -215,7 +215,7 @@ func (c *Client) feePayment(ctx context.Context, ticketHash *chainhash.Hash, pol
client: c,
ctx: ctx,
ticketHash: *ticketHash,
policy: policy,
policy: c.Policy,
}

// No VSP interaction is required for spent tickets.
Expand Down
20 changes: 6 additions & 14 deletions internal/vsp/vsp.go
Expand Up @@ -96,7 +96,7 @@ func (c *Client) FeePercentage(ctx context.Context) (float64, error) {

// ProcessUnprocessedTickets processes all tickets that don't currently have
// any association with a VSP.
func (c *Client) ProcessUnprocessedTickets(ctx context.Context, policy Policy) {
func (c *Client) ProcessUnprocessedTickets(ctx context.Context) {
var wg sync.WaitGroup
c.wallet.ForUnspentUnexpiredTickets(ctx, func(hash *chainhash.Hash) error {
// Skip tickets which have a fee tx already associated with
Expand Down Expand Up @@ -151,7 +151,7 @@ func (c *Client) ProcessTicket(ctx context.Context, hash *chainhash.Hash) error
// a VSP and begins syncing them in the background. This is used to recover VSP
// tracking after seed restores, and is only performed on unspent and unexpired
// tickets.
func (c *Client) ProcessManagedTickets(ctx context.Context, policy Policy) error {
func (c *Client) ProcessManagedTickets(ctx context.Context) error {
err := c.wallet.ForUnspentUnexpiredTickets(ctx, func(hash *chainhash.Hash) error {
// We only want to process tickets that haven't been confirmed yet.
confirmed, err := c.wallet.IsVSPTicketConfirmed(ctx, hash)
Expand Down Expand Up @@ -200,10 +200,10 @@ func (c *Client) ProcessManagedTickets(ctx context.Context, policy Policy) error
if err != nil {
return err
}
_ = c.feePayment(ctx, hash, policy, true)
_ = c.feePayment(ctx, hash, true)
} else {
// Fee hasn't been paid at the provided VSP, so this should do that if needed.
_ = c.feePayment(ctx, hash, policy, false)
_ = c.feePayment(ctx, hash, false)
}

return nil
Expand All @@ -220,14 +220,6 @@ func (c *Client) ProcessManagedTickets(ctx context.Context, policy Policy) error
// error. The fee transaction is also recorded as unpublised in the wallet, and
// the fee hash is associated with the ticket.
func (c *Client) Process(ctx context.Context, ticketHash *chainhash.Hash, feeTx *wire.MsgTx) error {
return c.ProcessWithPolicy(ctx, ticketHash, feeTx, c.Policy)
}

// ProcessWithPolicy is the same as Process but allows a fee payment policy to
// be specified, instead of using the client's default policy.
func (c *Client) ProcessWithPolicy(ctx context.Context, ticketHash *chainhash.Hash, feeTx *wire.MsgTx,
policy Policy) error {

vspTicket, err := c.wallet.VSPTicketInfo(ctx, ticketHash)
if err != nil && !errors.Is(err, errors.NotExist) {
return err
Expand All @@ -241,7 +233,7 @@ func (c *Client) ProcessWithPolicy(ctx context.Context, ticketHash *chainhash.Ha
case udb.VSPFeeProcessStarted, udb.VSPFeeProcessErrored:
// If VSPTicket has been started or errored then attempt to create a new fee
// transaction, submit it then confirm.
fp := c.feePayment(ctx, ticketHash, policy, false)
fp := c.feePayment(ctx, ticketHash, false)
if fp == nil {
err := c.wallet.UpdateVspTicketFeeToErrored(ctx, ticketHash, c.Client.URL, c.Client.PubKey)
if err != nil {
Expand Down Expand Up @@ -280,7 +272,7 @@ func (c *Client) ProcessWithPolicy(ctx context.Context, ticketHash *chainhash.Ha
// Cannot confirm a paid ticket that is already with another VSP.
return fmt.Errorf("ticket already paid or confirmed with another vsp")
}
fp := c.feePayment(ctx, ticketHash, policy, true)
fp := c.feePayment(ctx, ticketHash, true)
if fp == nil {
// Don't update VSPStatus to Errored if it was already paid or
// confirmed.
Expand Down

0 comments on commit d95475b

Please sign in to comment.