Skip to content

Commit

Permalink
feat: add transaction hash to reward call error
Browse files Browse the repository at this point in the history
This commit adds the transaction hash to the reward call error metric if
it exists.
  • Loading branch information
rickstaa committed Dec 18, 2023
1 parent 1cf3645 commit 772806c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
22 changes: 14 additions & 8 deletions eth/rewardservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ func (s *RewardService) Start(ctx context.Context) error {
}
case <-roundSink:
go func() {
err := s.tryReward()
tx, err := s.tryReward()
if err != nil {
glog.Errorf("Error trying to call reward err=%q", err)
var txHash string
if tx != nil {
txHash = tx.Hash().String()
}
if monitor.Enabled {
monitor.RewardCallError(ctx, err.Error(), s.tw.LastInitializedRound())
monitor.RewardCallError(ctx, err.Error(), s.tw.LastInitializedRound(), txHash)
}
}
}()
Expand All @@ -85,31 +89,33 @@ func (s *RewardService) IsWorking() bool {
return s.working
}

func (s *RewardService) tryReward() error {
// tryReward will try to call the reward if the last reward round is less than the current round
// and the transcoder is active.
func (s *RewardService) tryReward() (*types.Transaction, error) {
s.mu.Lock()
defer s.mu.Unlock()

currentRound := s.tw.LastInitializedRound()

t, err := s.client.GetTranscoder(s.client.Account().Address)
if err != nil {
return err
return nil, err
}

if t.LastRewardRound.Cmp(currentRound) == -1 && t.Active {
tx, err := s.client.Reward()
if err != nil {
return err
return nil, err
}

if err := s.client.CheckTx(tx); err != nil {
return err
return tx, err
}

glog.Infof("Called reward for round %v", currentRound)

return nil
return tx, nil
}

return nil
return nil, nil
}
16 changes: 9 additions & 7 deletions monitor/census.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type (
kOrchestratorAddress tag.Key
kFVErrorType tag.Key
kRound tag.Key
kTxHash tag.Key
mSegmentSourceAppeared *stats.Int64Measure
mSegmentEmerged *stats.Int64Measure
mSegmentEmergedUnprocessed *stats.Int64Measure
Expand Down Expand Up @@ -256,6 +257,7 @@ func InitCensus(nodeType NodeType, version string) {
census.kFVErrorType = tag.MustNewKey("fverror_type")
census.kSegClassName = tag.MustNewKey("seg_class_name")
census.kRound = tag.MustNewKey("round")
census.kTxHash = tag.MustNewKey("tx_hash")
census.ctx, err = tag.New(ctx, tag.Insert(census.kNodeType, string(nodeType)), tag.Insert(census.kNodeID, NodeID))
if err != nil {
glog.Exit("Error creating context", err)
Expand Down Expand Up @@ -793,7 +795,7 @@ func InitCensus(nodeType NodeType, version string) {
Name: "reward_call_errors",
Measure: census.mRewardCallError,
Description: "Errors when calling rewards",
TagKeys: append([]tag.Key{census.kErrorCode, census.kRound}, baseTags...),
TagKeys: append([]tag.Key{census.kErrorCode, census.kRound, census.kTxHash}, baseTags...),
Aggregation: view.Sum(),
},

Expand Down Expand Up @@ -1701,24 +1703,24 @@ func TranscodingPrice(sender string, price *big.Rat) {
}

// RewardCallError records an error from reward calling
func RewardCallError(ctx context.Context, errStr string, round *big.Int) {
func RewardCallError(ctx context.Context, err string, round *big.Int, txHash string) {

var errCode string
if strings.Contains(errStr, "current round is not initialized") {
if strings.Contains(err, "current round is not initialized") {
errCode = "RoundNotInitialized"
} else if strings.Contains(errStr, "transaction failed") {
} else if strings.Contains(err, "transaction failed") {
errCode = "TransactionFailed"
} else if strings.Contains(errStr, "timed out waiting for transaction") {
} else if strings.Contains(err, "timed out waiting for transaction") {
errCode = "TransactionTimeout"
} else if strings.Contains(errStr, "gas price exceeds maximum") {
} else if strings.Contains(err, "gas price exceeds maximum") {
errCode = "GasPriceExceedsMax"
} else {
errCode = "RewardCallError"
}

roundStr := round.Text(10)
if err := stats.RecordWithTags(census.ctx,
[]tag.Mutator{tag.Insert(census.kErrorCode, errCode), tag.Insert(census.kRound, roundStr)},
[]tag.Mutator{tag.Insert(census.kErrorCode, errCode), tag.Insert(census.kRound, roundStr), tag.Insert(census.kTxHash, txHash)},
census.mRewardCallError.M(1)); err != nil {

glog.Errorf("Error recording metrics err=%q", err)
Expand Down

0 comments on commit 772806c

Please sign in to comment.