Skip to content

Commit

Permalink
vsp: Introduce VSPTicket struct.
Browse files Browse the repository at this point in the history
All of the fields necessary to register a ticket with a VSP are set upon
creation of a VSPTicket struct. This helps to ensure no invalid tickets
are ever added to a VSP client, and removes a lot of duplicated logic
from feePayment.
  • Loading branch information
jholdstock committed Aug 10, 2023
1 parent a87fa84 commit 9a84573
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 180 deletions.
28 changes: 25 additions & 3 deletions internal/rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -3491,7 +3491,17 @@ func (s *Server) processUnmanagedTicket(ctx context.Context, icmd interface{}) (
return nil, err
}

err = vspClient.Process(ctx, ticketHash, nil)
w, ok := s.walletLoader.LoadedWallet()
if !ok {
return nil, errUnloadedWallet
}

ticket, err := w.NewVSPTicket(ctx, ticketHash)
if err != nil {
return nil, err
}

err = vspClient.Process(ctx, ticket, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -4671,7 +4681,13 @@ func (s *Server) updateVSPVoteChoices(ctx context.Context, w *wallet.Wallet, tic
if err != nil {
return err
}
err = vspClient.SetVoteChoice(ctx, ticketHash, choices, tspendPolicy, treasuryPolicy)

ticket, err := w.NewVSPTicket(ctx, ticketHash)
if err != nil {
return err
}

err = vspClient.SetVoteChoice(ctx, ticket, choices, tspendPolicy, treasuryPolicy)
return err
}

Expand All @@ -4688,9 +4704,15 @@ func (s *Server) updateVSPVoteChoices(ctx context.Context, w *wallet.Wallet, tic
if err != nil {
return err
}

ticket, err := w.NewVSPTicket(ctx, hash)
if err != nil {
return err
}

// Never return errors here, so all tickets are tried.
// The first error will be returned to the user.
err = vspClient.SetVoteChoice(ctx, hash, choices, tspendPolicy, treasuryPolicy)
err = vspClient.SetVoteChoice(ctx, ticket, choices, tspendPolicy, treasuryPolicy)
if err != nil {
return err
}
Expand Down
23 changes: 17 additions & 6 deletions internal/rpc/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4161,14 +4161,21 @@ func (s *walletServer) SyncVSPFailedTickets(ctx context.Context, req *pb.SyncVSP
return nil, status.Errorf(codes.Unknown, "TicketBuyerV3 instance failed to start. Error: %v", err)
}

// process tickets fee if needed.
// Process tickets fee if needed.
for _, ticketHash := range failedTicketsFee {

// If it fails to process again, we log it and continue with
// the wallet start.
// Not sure we need to log here since it's already warned elsewhere

t, err := s.wallet.NewVSPTicket(ctx, &ticketHash)
if err != nil {
continue
}
feeTx := new(wire.MsgTx)
err := vspClient.Process(ctx, &ticketHash, feeTx)
err = vspClient.Process(ctx, t, feeTx)
if err != nil {
// if it fails to process again, we log it and continue with
// the wallet start.
// Not sure we need to log here since it's already warned elsewhere
continue
}
}
return &pb.SyncVSPTicketsResponse{}, nil
Expand Down Expand Up @@ -4325,7 +4332,11 @@ func (s *walletServer) SetVspdVoteChoices(ctx context.Context, req *pb.SetVspdVo
return err
}
if ticketHost == vspHost {
err = vspClient.SetVoteChoice(ctx, hash, choices, tSpendChoices, treasuryChoices)
ticket, err := s.wallet.NewVSPTicket(ctx, hash)
if err != nil {
return err
}
err = vspClient.SetVoteChoice(ctx, ticket, choices, tSpendChoices, treasuryChoices)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 9a84573

Please sign in to comment.