Skip to content
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
10 changes: 10 additions & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,16 @@ type ApiServer struct {
openAudioPool *OpenAudioPool
}

// requestLogger returns app.logger annotated with the current request_id (set
// by the requestid middleware) when available, so handler logs can be
// correlated with access logs.
func (app *ApiServer) requestLogger(c *fiber.Ctx) *zap.Logger {
if requestId, ok := c.Locals("requestId").(string); ok && requestId != "" {
return app.logger.With(zap.String("request_id", requestId))
}
return app.logger
}

func (app *ApiServer) home(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"env": app.config.Env,
Expand Down
17 changes: 15 additions & 2 deletions api/v1_claim_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func getValidatorAttestation(args GetValidatorAttestationParams) (*SenderAttesta
// handling retries and reselection
func fetchAttestations(
ctx context.Context,
logger *zap.Logger,
rewardClaim RewardClaim,
allValidators []config.Node,
excludedOperators []string,
Expand Down Expand Up @@ -321,6 +322,14 @@ func fetchAttestations(

for _, result := range results {
if result.err != nil {
logger.Warn("validator attestation failed",
zap.String("validator", result.node.Endpoint),
zap.String("validatorOwner", result.node.Owner),
zap.String("handle", rewardClaim.Handle),
zap.String("rewardId", rewardClaim.RewardID),
zap.String("specifier", rewardClaim.Specifier),
zap.Error(result.err),
)
badValidators[result.node.Endpoint] = true
continue
}
Expand Down Expand Up @@ -597,6 +606,7 @@ type RelayTransactionResponse struct {
// Claims an individual reward.
func claimReward(
ctx context.Context,
logger *zap.Logger,
rewardClaim RewardClaim,
rewardManagerClient *reward_manager.RewardManagerClient,
rewardAttester *rewards.RewardAttester,
Expand Down Expand Up @@ -639,6 +649,7 @@ func claimReward(
// Fetch AAO and validator attestations
attestations, err := fetchAttestations(
ctx,
logger,
rewardClaim,
validators,
existingValidatorOwners,
Expand Down Expand Up @@ -740,6 +751,7 @@ type ClaimRewardsBody struct {

// Claims all the filtered undisbursed rewards for a user.
func (app *ApiServer) v1ClaimRewards(c *fiber.Ctx) error {
logger := app.requestLogger(c)

body := ClaimRewardsBody{}
err := c.BodyParser(&body)
Expand Down Expand Up @@ -831,6 +843,7 @@ func (app *ApiServer) v1ClaimRewards(c *fiber.Ctx) error {
validators := app.config.ArtistCoinRewardsStaticSenders
sigs, err := claimReward(
ctx,
logger,
rewardClaim,
app.rewardManagerClient,
app.rewardAttester,
Expand All @@ -842,7 +855,7 @@ func (app *ApiServer) v1ClaimRewards(c *fiber.Ctx) error {
if err != nil {
var instrErr *spl.InstructionError
if errors.As(err, &instrErr) {
app.logger.Error("failed to claim challenge reward. transaction failed to send.",
logger.Error("failed to claim challenge reward. transaction failed to send.",
zap.String("handle", row.Handle.String),
zap.String("rewardId", row.ChallengeID),
zap.String("specifier", row.Specifier),
Expand All @@ -851,7 +864,7 @@ func (app *ApiServer) v1ClaimRewards(c *fiber.Ctx) error {
zap.Error(err),
)
} else {
app.logger.Error("failed to claim challenge reward.",
logger.Error("failed to claim challenge reward.",
zap.String("handle", row.Handle.String),
zap.String("rewardId", row.ChallengeID),
zap.String("specifier", row.Specifier),
Expand Down
2 changes: 2 additions & 0 deletions api/v1_claim_rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/OpenAudio/go-openaudio/pkg/rewards"
"github.com/gagliardetto/solana-go"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)

func TestFetchAttestations(t *testing.T) {
Expand Down Expand Up @@ -106,6 +107,7 @@ func TestFetchAttestations(t *testing.T) {
// Call fetchAttestations
attestations, err := fetchAttestations(
context.Background(),
zap.NewNop(),
rewardClaim,
allValidators,
[]string{}, // no excluded operators
Expand Down
22 changes: 20 additions & 2 deletions api/v1_coins_post_redeem.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type CoinRewardParams struct {
}

func (app *ApiServer) v1CoinsPostRedeem(c *fiber.Ctx) error {
logger := app.requestLogger(c)
// #region Validate Params
if app.config.LaunchpadDeterministicSecret == "" {
return fiber.NewError(fiber.StatusInternalServerError, "Claim authority base is not configured")
Expand Down Expand Up @@ -332,6 +333,14 @@ func (app *ApiServer) v1CoinsPostRedeem(c *fiber.Ctx) error {
})

if err != nil {
logger.Warn("validator attestation failed",
zap.String("validator", validator.Endpoint),
zap.String("validatorOwner", validator.Owner),
zap.String("handle", userHandle),
zap.String("rewardId", redeemCode),
zap.String("specifier", specifier),
zap.Error(err),
)
continue
}

Expand All @@ -342,6 +351,15 @@ func (app *ApiServer) v1CoinsPostRedeem(c *fiber.Ctx) error {
}
signatureBytes, err := hex.DecodeString(strings.TrimPrefix(signature, "0x"))
if err != nil {
logger.Warn("validator attestation signature decode failed",
zap.String("validator", validator.Endpoint),
zap.String("validatorOwner", validator.Owner),
zap.String("handle", userHandle),
zap.String("rewardId", redeemCode),
zap.String("specifier", specifier),
zap.String("attestation", response.Attestation),
zap.Error(err),
)
continue
}

Expand Down Expand Up @@ -375,7 +393,7 @@ func (app *ApiServer) v1CoinsPostRedeem(c *fiber.Ctx) error {
if err != nil {
var instrErr *spl.InstructionError
if errors.As(err, &instrErr) {
app.logger.Error("failed to claim challenge reward. transaction failed to send.",
logger.Error("failed to claim challenge reward. transaction failed to send.",
zap.String("handle", userHandle),
zap.String("rewardId", "code"),
zap.String("specifier", specifier),
Expand All @@ -384,7 +402,7 @@ func (app *ApiServer) v1CoinsPostRedeem(c *fiber.Ctx) error {
zap.Error(err),
)
} else {
app.logger.Error("failed to claim challenge reward.",
logger.Error("failed to claim challenge reward.",
zap.String("handle", userHandle),
zap.String("rewardId", "code"),
zap.String("specifier", specifier),
Expand Down
Loading