Skip to content

Commit

Permalink
refactor: move reward error transaction hash parsing
Browse files Browse the repository at this point in the history
This commit moves the transaction hash parsing into the `rewardCallError`
method to keep all code related to the reward call error in one place.
  • Loading branch information
rickstaa committed Dec 19, 2023
1 parent 923375c commit c4b6153
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 1 addition & 6 deletions eth/rewardservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package eth
import (
"context"
"fmt"
"strings"
"sync"

"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -59,12 +58,8 @@ func (s *RewardService) Start(ctx context.Context) error {
tx, err := s.tryReward()
if err != nil {
glog.Errorf("Error trying to call reward err=%q", err)
var txHash string
if tx != nil && !strings.Contains(err.Error(), "context deadline exceeded") {
txHash = tx.Hash().Hex()
}
if monitor.Enabled {
monitor.RewardCallError(ctx, err.Error(), s.tw.LastInitializedRound(), txHash)
monitor.RewardCallError(ctx, err.Error(), s.tw.LastInitializedRound(), tx)
}

Check warning on line 63 in eth/rewardservice.go

View check run for this annotation

Codecov / codecov/patch

eth/rewardservice.go#L62-L63

Added lines #L62 - L63 were not covered by tests
}
}()
Expand Down
7 changes: 6 additions & 1 deletion monitor/census.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/golang/glog"
"github.com/livepeer/go-livepeer/clog"
lpnet "github.com/livepeer/go-livepeer/net"
Expand Down Expand Up @@ -1703,7 +1704,11 @@ func TranscodingPrice(sender string, price *big.Rat) {
}

// RewardCallError records an error from reward calling
func RewardCallError(ctx context.Context, err string, round *big.Int, txHash string) {
func RewardCallError(ctx context.Context, err string, round *big.Int, tx *types.Transaction) {
var txHash string
if tx != nil && !strings.Contains(err, "context deadline exceeded") {
txHash = tx.Hash().Hex()
}

Check warning on line 1711 in monitor/census.go

View check run for this annotation

Codecov / codecov/patch

monitor/census.go#L1707-L1711

Added lines #L1707 - L1711 were not covered by tests

var errCode string
if strings.Contains(err, "current round is not initialized") {
Expand Down

0 comments on commit c4b6153

Please sign in to comment.