Skip to content

Commit

Permalink
use passed context for GetTicketInfo stakepoold rpc call
Browse files Browse the repository at this point in the history
  • Loading branch information
itswisdomagain committed Mar 19, 2020
1 parent be5e840 commit f5bbac5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion controllers/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ type tStakepooldManager struct {
qItem func() queueItem
}

func (m *tStakepooldManager) GetTicketInfo(hash string) (*pb.GetTicketInfoResponse, error) {
func (m *tStakepooldManager) GetTicketInfo(_ context.Context, hash string) (*pb.GetTicketInfoResponse, error) {
item := m.qItem()
thing, _ := item.thing.(*pb.GetTicketInfoResponse)
return thing, item.err
Expand Down
6 changes: 3 additions & 3 deletions stakepooldclient/stakepooldclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (

// Manager is satisfied by stakepooldManager.
type Manager interface {
GetTicketInfo(hash string) (*pb.GetTicketInfoResponse, error)
GetTicketInfo(ctx context.Context, hash string) (*pb.GetTicketInfoResponse, error)
GetAddedLowFeeTickets(context.Context) (map[chainhash.Hash]string, error)
GetIgnoredLowFeeTickets(context.Context) (map[chainhash.Hash]string, error)
GetLiveTickets(context.Context) (map[chainhash.Hash]string, error)
Expand Down Expand Up @@ -138,10 +138,10 @@ func (s *stakepooldManager) connected(ctx context.Context) error {
// GetTicketInfo performs gRPC GetTicketInfo requests against
// all stakepoold instances and returns the first result fetched
// without errors. Returns an error if all RPC requests fail.
func (s *stakepooldManager) GetTicketInfo(hash string) (*pb.GetTicketInfoResponse, error) {
func (s *stakepooldManager) GetTicketInfo(ctx context.Context, hash string) (*pb.GetTicketInfoResponse, error) {
for _, conn := range s.grpcConnections {
client := pb.NewStakepooldServiceClient(conn)
resp, err := client.GetTicketInfo(context.Background(), &pb.GetTicketInfoRequest{Hash: hash})
resp, err := client.GetTicketInfo(ctx, &pb.GetTicketInfoRequest{Hash: hash})
if err != nil {
log.Warnf("GetTicketInfo RPC failed on stakepoold instance %s: %v", conn.Target(), err)
continue
Expand Down
5 changes: 3 additions & 2 deletions system/api-auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package system

import (
"context"
"encoding/base64"
"fmt"
"math"
Expand Down Expand Up @@ -41,7 +42,7 @@ func (application *Application) validateToken(authHeader string) (int64, error)
}
}

func (application *Application) validateTicketOwnership(authHeader string) (string, error) {
func (application *Application) validateTicketOwnership(ctx context.Context, authHeader string) (string, error) {
timestamp, timestampSignature, ticketHash := extractTicketAuthParams(strings.TrimPrefix(authHeader, "TicketAuth "))
if timestamp == "" || timestampSignature == "" || ticketHash == "" {
return "", fmt.Errorf("invalid ticket auth header value %s", authHeader)
Expand Down Expand Up @@ -75,7 +76,7 @@ func (application *Application) validateTicketOwnership(authHeader string) (stri

// Get ticket info using ticket hash, also checks if the ticket is watched by this vsp.
// todo: may be better to maintain a memory map of tickets-userWalletAddresses
ticketInfo, err := application.stakepooldManager.GetTicketInfo(ticketHash)
ticketInfo, err := application.stakepooldManager.GetTicketInfo(ctx, ticketHash)
if err != nil {
return "", fmt.Errorf("ticket auth, get ticket info failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion system/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (application *Application) ApplyAPI(c *web.C, h http.Handler) http.Handler
}
} else if strings.HasPrefix(authHeader, "TicketAuth ") {
var userMsa string
userMsa, err = application.validateTicketOwnership(authHeader)
userMsa, err = application.validateTicketOwnership(r.Context(), authHeader)
if err == nil {
user, err = models.GetUserByMSA(dbMap, userMsa)
}
Expand Down

0 comments on commit f5bbac5

Please sign in to comment.