From c4b61538e4c452294fed4cfc21b14609a10b7e51 Mon Sep 17 00:00:00 2001 From: rickstaa Date: Tue, 19 Dec 2023 12:50:03 +0100 Subject: [PATCH] refactor: move reward error transaction hash parsing This commit moves the transaction hash parsing into the `rewardCallError` method to keep all code related to the reward call error in one place. --- eth/rewardservice.go | 7 +------ monitor/census.go | 7 ++++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/eth/rewardservice.go b/eth/rewardservice.go index 24be1c0bf5..7adb450021 100644 --- a/eth/rewardservice.go +++ b/eth/rewardservice.go @@ -3,7 +3,6 @@ package eth import ( "context" "fmt" - "strings" "sync" "github.com/ethereum/go-ethereum/core/types" @@ -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) } } }() diff --git a/monitor/census.go b/monitor/census.go index 4ee32a2164..97e827bc33 100644 --- a/monitor/census.go +++ b/monitor/census.go @@ -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" @@ -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() + } var errCode string if strings.Contains(err, "current round is not initialized") {