Skip to content

Commit

Permalink
devsvcs-675: update debugging script to check max gas price (#14582)
Browse files Browse the repository at this point in the history
* devsvcs-675: update debugging script to check max gas price

* update

* update
  • Loading branch information
FelixFan1992 authored Sep 27, 2024
1 parent fc1fefc commit 7291696
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/scripts/chaincli/DEBUGGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Use this script to debug and diagnose possible issues with registered upkeeps in

Before starting, you will need:

- An archival RPC URL (required) and Tenderly credential (optional)
In order to get an archive URL, it's recommended to go to your Infura or Alchemy account (free tier should do) and get
a RPC URL.
- A registered [upkeep](https://docs.chain.link/chainlink-automation/overview/getting-started)
- A working [Go](https://go.dev/doc/install) installation, please use this Go [version](https://github.com/smartcontractkit/chainlink/blob/develop/go.mod#L3)

Expand Down
44 changes: 44 additions & 0 deletions core/scripts/chaincli/handler/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (

ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation"

"github.com/smartcontractkit/chainlink/v2/core/cbor"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evm21 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21"

commonhex "github.com/smartcontractkit/chainlink-common/pkg/utils/hex"
Expand All @@ -47,6 +49,10 @@ const (
expectedVersion23 = "AutomationRegistry 2.3.0"
)

type UpkeepOffchainConfig struct {
MaxGasPrice *big.Int `json:"maxGasPrice" cbor:"maxGasPrice"`
}

var mercuryPacker = mercury.NewAbiPacker()
var packer = encoding.NewAbiPacker()

Expand Down Expand Up @@ -135,6 +141,10 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
// do basic checks
upkeepInfo = getUpkeepInfoAndRunBasicChecks(v2common, triggerCallOpts, upkeepID, chainID)

cgp, mgp := getGasPrice(ctx, k, upkeepInfo)
log.Printf("CURRENT gas price (you cannot call eth_gasPrice on any non latest block) is %s, this upkeep's MAX gas price is %s\n", cgp, mgp)
log.Printf("If upkeep's max gas price (if configured) is lower than the gas price when this upkeep was previously checked, the simulation will fail and this upkeep won't be performed.\n")

var tmpCheckResult autov2common.CheckUpkeep0
tmpCheckResult, err = v2common.CheckUpkeep0(triggerCallOpts, upkeepID)
if err != nil {
Expand Down Expand Up @@ -209,6 +219,10 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
// do basic checks
upkeepInfo = getUpkeepInfoAndRunBasicChecks(v2common, triggerCallOpts, upkeepID, chainID)

cgp, mgp := getGasPrice(ctx, k, upkeepInfo)
log.Printf("CURRENT gas price (you cannot call eth_gasPrice on any non latest block) is %s, this upkeep's MAX gas price is %s\n", cgp, mgp)
log.Printf("If upkeep's max gas price (if configured) is lower than the gas price when this upkeep was previously checked, the simulation will fail and this upkeep won't be performed.\n")

var rawTriggerConfig []byte
rawTriggerConfig, err = v2common.GetUpkeepTriggerConfig(triggerCallOpts, upkeepID)
if err != nil {
Expand Down Expand Up @@ -387,6 +401,36 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
}
}

func getGasPrice(ctx context.Context, k *Keeper, upkeepInfo autov2common.IAutomationV21PlusCommonUpkeepInfoLegacy) (*assets.Wei, *assets.Wei) {
var cgp *assets.Wei
var err error
var gp *big.Int
// get gas price, eth_gasPrice does not take arguments, so we cannot access gas price at an older block
gp, err = k.client.SuggestGasPrice(ctx)
if err != nil {
log.Printf("⚠️ failed to get current gas price due to %v", err)
} else {
cgp = assets.NewWei(gp)
log.Printf("current gas price is %s", cgp)
}

var mgp *assets.Wei
// check if max gas price is configured
if len(upkeepInfo.OffchainConfig) != 0 {
var offchainConfig UpkeepOffchainConfig
err := cbor.ParseDietCBORToStruct(upkeepInfo.OffchainConfig, &offchainConfig)
if err != nil {
log.Printf("failed to parse offchain config bytes to max gas price\n")
} else {
mgp = assets.NewWei(offchainConfig.MaxGasPrice)
}
} else {
log.Printf("offchain config is not configured for this upkeep\n")
}

return cgp, mgp
}

func getUpkeepInfoAndRunBasicChecks(keeperRegistry21 *autov2common.IAutomationV21PlusCommon, callOpts *bind.CallOpts, upkeepID *big.Int, chainID int64) autov2common.IAutomationV21PlusCommonUpkeepInfoLegacy {
// get upkeep info
upkeepInfo, err := keeperRegistry21.GetUpkeep(callOpts, upkeepID)
Expand Down

0 comments on commit 7291696

Please sign in to comment.