Skip to content

Commit

Permalink
chore: block process after error reported
Browse files Browse the repository at this point in the history
  • Loading branch information
Candinya committed Jun 3, 2024
1 parent 0634abd commit fcd4cb7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
13 changes: 12 additions & 1 deletion internal/service/indexer/l2/report_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"net/http"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

type SlackMessageElement struct {
Expand All @@ -31,7 +32,12 @@ type SlackMessageStructure struct {
Blocks []SlackMessageBlock `json:"blocks"`
}

func (s *server) ReportFailedTransactionToSlack(txErr error, txHash string, txFunc string, users []common.Address, amount []*big.Int) {
func (s *server) ReportFailedTransactionToSlack(txErr error, receipt *types.Receipt, txFunc string, users []common.Address, amount []*big.Int) {
txHash := "Unknown"
if receipt != nil {
txHash = receipt.TxHash.Hex()
}

log.Println("===================== Transaction Error =====================")
log.Printf("%s transaction error! Please check information below:", txFunc)
log.Printf("Transaction Hash: %s", txHash)
Expand All @@ -49,6 +55,11 @@ func (s *server) ReportFailedTransactionToSlack(txErr error, txHash string, txFu

s.sendNotificationMessage(txErr, txHash, txFunc)
s.uploadUsersList(txHash, users, amount)

// select {} purposely block the process as it is a critical error and meaningless to continue
// if panic() is called, the process will be restarted by the supervisor
// we do not want that as it will be stuck in the same state
select {}
}

func (s *server) sendNotificationMessage(txErr error, txHash string, txFunc string) {
Expand Down
3 changes: 2 additions & 1 deletion internal/service/indexer/l2/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func (s *server) sendTransaction(ctx context.Context, input []byte) (*types.Rece
// select {} purposely block the process as it is a critical error and meaningless to continue
// if panic() is called, the process will be restarted by the supervisor
// we do not want that as it will be stuck in the same state
select {}
// select {} // Move this process blocker after message report to notification system
return receipt, fmt.Errorf("received an invalid transaction receipt")
}

// return the receipt if the transaction is successful
Expand Down
4 changes: 2 additions & 2 deletions internal/service/indexer/l2/trigger_billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (s *server) triggerBillingCollectTokens(ctx context.Context, epoch *big.Int
receipt, err := s.sendTransaction(ctx, input)

if err != nil {
s.ReportFailedTransactionToSlack(err, "", l2.MethodCollectTokens, users, amounts)
s.ReportFailedTransactionToSlack(err, receipt, l2.MethodCollectTokens, users, amounts)
return fmt.Errorf("send transaction receipt: %w", err)
}

Expand All @@ -275,7 +275,7 @@ func (s *server) triggerBillingWithdrawTokens(ctx context.Context, users []commo
receipt, err := s.sendTransaction(ctx, input)

if err != nil {
s.ReportFailedTransactionToSlack(err, "", l2.MethodWithdrawTokens, users, amounts)
s.ReportFailedTransactionToSlack(err, receipt, l2.MethodWithdrawTokens, users, amounts)
return fmt.Errorf("send transaction receipt: %w", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *server) triggerDistributeRequestRewards(ctx context.Context, nodeAddres

receipt, err := s.sendTransaction(ctx, input)
if err != nil {
s.ReportFailedTransactionToSlack(err, "", l2.MethodDistributeRewards, nodeAddress, amounts)
s.ReportFailedTransactionToSlack(err, receipt, l2.MethodDistributeRewards, nodeAddress, amounts)
return fmt.Errorf("send transaction receipt: %w", err)
}

Expand Down

0 comments on commit fcd4cb7

Please sign in to comment.