Skip to content

Commit

Permalink
log warning when node has insufficient balance to cover tx fees on fu…
Browse files Browse the repository at this point in the history
…nds return (#12437)
  • Loading branch information
Tofel authored Mar 15, 2024
1 parent caab80d commit ada42ef
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion integration-tests/actions/seth/refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,24 @@ func ReturnFunds(log zerolog.Logger, seth *seth.Client, chainlinkNodes []contrac
return err
}

totalGasCost := new(big.Int).Mul(big.NewInt(0).SetUint64(seth.Cfg.Network.GasLimit), big.NewInt(0).SetInt64(seth.Cfg.Network.GasPrice))
var totalGasCost *big.Int
if seth.Cfg.Network.EIP1559DynamicFees {
totalGasCost = new(big.Int).Mul(big.NewInt(0).SetUint64(seth.Cfg.Network.GasLimit), big.NewInt(0).SetInt64(seth.Cfg.Network.GasFeeCap))
} else {
totalGasCost = new(big.Int).Mul(big.NewInt(0).SetUint64(seth.Cfg.Network.GasLimit), big.NewInt(0).SetInt64(seth.Cfg.Network.GasPrice))
}

toSend := new(big.Int).Sub(balance, totalGasCost)

if toSend.Cmp(big.NewInt(0)) <= 0 {
log.Warn().
Str("Address", fromAddress.String()).
Str("Estimated total cost", totalGasCost.String()).
Str("Balance", balance.String()).
Str("To send", toSend.String()).
Msg("Not enough balance to cover gas cost. Skipping return.")
}

payload := FundsToSendPayload{ToAddress: seth.Addresses[0], Amount: toSend, PrivateKey: decryptedKey.PrivateKey}

_, err = SendFunds(log, seth, payload)
Expand Down

0 comments on commit ada42ef

Please sign in to comment.