From 977bf12ecdc11c4745ad62da6cd7aed66a9d9e47 Mon Sep 17 00:00:00 2001 From: FelixFan1992 Date: Fri, 10 May 2024 11:29:09 -0400 Subject: [PATCH 1/8] AUTO-10539: improve offchain config length check --- .../ocr2keeper/evmregistry/v21/gasprice/gasprice.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go index 2c376443fa5..73cc32065f7 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go @@ -27,17 +27,18 @@ type UpkeepOffchainConfig struct { // CheckGasPrice retrieves the current gas price and compare against the max gas price configured in upkeep's offchain config // any errors in offchain config decoding will result in max gas price check disabled func CheckGasPrice(ctx context.Context, upkeepId *big.Int, offchainConfigBytes []byte, ge gas.EvmFeeEstimator, lggr logger.Logger) encoding.UpkeepFailureReason { - if len(offchainConfigBytes) == 0 { + // check for emptyh offchain config and 0x + if len(offchainConfigBytes) == 0 || len(offchainConfigBytes) == 2 && offchainConfigBytes[0] == 48 && offchainConfigBytes[1] == 120 { return encoding.UpkeepFailureReasonNone } var offchainConfig UpkeepOffchainConfig if err := cbor.ParseDietCBORToStruct(offchainConfigBytes, &offchainConfig); err != nil { - lggr.Errorw("failed to parse upkeep offchain config, gas price check is disabled", "upkeepId", upkeepId.String(), "err", err) + lggr.Debugw("failed to parse upkeep offchain config, gas price check is disabled", "upkeepId", upkeepId.String(), "err", err) return encoding.UpkeepFailureReasonNone } if offchainConfig.MaxGasPrice == nil || offchainConfig.MaxGasPrice.Int64() <= 0 { - lggr.Warnw("maxGasPrice is not configured or incorrectly configured in upkeep offchain config, gas price check is disabled", "upkeepId", upkeepId.String()) + lggr.Debugw("maxGasPrice is not configured or incorrectly configured in upkeep offchain config, gas price check is disabled", "upkeepId", upkeepId.String()) return encoding.UpkeepFailureReasonNone } lggr.Debugf("successfully decode offchain config for %s, max gas price is %s", upkeepId.String(), offchainConfig.MaxGasPrice.String()) From 2ad2bcf4351493e159d904c6aac98db87de56351 Mon Sep 17 00:00:00 2001 From: FelixFan1992 Date: Fri, 10 May 2024 13:35:03 -0400 Subject: [PATCH 2/8] add changeset --- .changeset/funny-monkeys-heal.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/funny-monkeys-heal.md diff --git a/.changeset/funny-monkeys-heal.md b/.changeset/funny-monkeys-heal.md new file mode 100644 index 00000000000..ccfada09a83 --- /dev/null +++ b/.changeset/funny-monkeys-heal.md @@ -0,0 +1,5 @@ +--- +"chainlink": patch +--- + +AUTO-10539: improve offchain config length check From f326f92badd42a7793081c4de97293f7ea583b78 Mon Sep 17 00:00:00 2001 From: FelixFan1992 Date: Fri, 10 May 2024 13:45:21 -0400 Subject: [PATCH 3/8] update changeset --- .changeset/funny-monkeys-heal.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/funny-monkeys-heal.md b/.changeset/funny-monkeys-heal.md index ccfada09a83..c58cb4ac60e 100644 --- a/.changeset/funny-monkeys-heal.md +++ b/.changeset/funny-monkeys-heal.md @@ -2,4 +2,5 @@ "chainlink": patch --- +#changed: AUTO-10539: improve offchain config length check From 461cfafd32d0a892aa894c4c45438060b0cf99ec Mon Sep 17 00:00:00 2001 From: FelixFan1992 Date: Mon, 13 May 2024 13:31:09 -0400 Subject: [PATCH 4/8] update --- .../ocr2keeper/evmregistry/v21/gasprice/gasprice.go | 8 ++++++-- .../ocr2keeper/evmregistry/v21/registry_check_pipeline.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go index 73cc32065f7..f3c7c3a2485 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go @@ -4,6 +4,8 @@ import ( "context" "math/big" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/smartcontractkit/chainlink/v2/core/cbor" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas" @@ -18,6 +20,8 @@ const ( // the estimator. it's set to a very high value because the gas price will be compared with user-defined gas price // later. maxFeePrice = 1_000_000_000_000_000 + // emptyOffchainConfig is the default upkeep offchain config + emptyOffchainConfig = "0x0000000000000000000000000000000000000000000000000000000000000000" ) type UpkeepOffchainConfig struct { @@ -27,8 +31,8 @@ type UpkeepOffchainConfig struct { // CheckGasPrice retrieves the current gas price and compare against the max gas price configured in upkeep's offchain config // any errors in offchain config decoding will result in max gas price check disabled func CheckGasPrice(ctx context.Context, upkeepId *big.Int, offchainConfigBytes []byte, ge gas.EvmFeeEstimator, lggr logger.Logger) encoding.UpkeepFailureReason { - // check for emptyh offchain config and 0x - if len(offchainConfigBytes) == 0 || len(offchainConfigBytes) == 2 && offchainConfigBytes[0] == 48 && offchainConfigBytes[1] == 120 { + // check for empty offchain config and 0x0000000000000000000000000000000000000000000000000000000000000000 + if len(offchainConfigBytes) == 0 || hexutil.Encode(offchainConfigBytes) == emptyOffchainConfig { return encoding.UpkeepFailureReasonNone } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go index e341730c794..d2d58b112da 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go @@ -311,6 +311,7 @@ func (r *EvmRegistry) simulatePerformUpkeeps(ctx context.Context, checkResults [ // this is mostly caused by RPC flakiness r.lggr.Errorw("failed get offchain config, gas price check will be disabled", "err", err, "upkeepId", upkeepId, "block", block) } + r.lggr.Debugf("upkeep %s's offchain config is %s", upkeepId, hexutil.Encode(oc)) fr := gasprice.CheckGasPrice(ctx, upkeepId, oc, r.ge, r.lggr) if uint8(fr) == uint8(encoding.UpkeepFailureReasonGasPriceTooHigh) { r.lggr.Infof("upkeep %s upkeep failure reason is %d", upkeepId, fr) From 5444aa15aba10e218ae32c29808c323f9c310b7b Mon Sep 17 00:00:00 2001 From: FelixFan1992 Date: Tue, 14 May 2024 12:34:26 -0400 Subject: [PATCH 5/8] update --- .../ocr2keeper/evmregistry/v21/gasprice/gasprice.go | 8 ++------ .../ocr2keeper/evmregistry/v21/registry_check_pipeline.go | 3 +-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go index f3c7c3a2485..aa47476b409 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go @@ -4,8 +4,6 @@ import ( "context" "math/big" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/smartcontractkit/chainlink/v2/core/cbor" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas" @@ -20,8 +18,6 @@ const ( // the estimator. it's set to a very high value because the gas price will be compared with user-defined gas price // later. maxFeePrice = 1_000_000_000_000_000 - // emptyOffchainConfig is the default upkeep offchain config - emptyOffchainConfig = "0x0000000000000000000000000000000000000000000000000000000000000000" ) type UpkeepOffchainConfig struct { @@ -31,8 +27,8 @@ type UpkeepOffchainConfig struct { // CheckGasPrice retrieves the current gas price and compare against the max gas price configured in upkeep's offchain config // any errors in offchain config decoding will result in max gas price check disabled func CheckGasPrice(ctx context.Context, upkeepId *big.Int, offchainConfigBytes []byte, ge gas.EvmFeeEstimator, lggr logger.Logger) encoding.UpkeepFailureReason { - // check for empty offchain config and 0x0000000000000000000000000000000000000000000000000000000000000000 - if len(offchainConfigBytes) == 0 || hexutil.Encode(offchainConfigBytes) == emptyOffchainConfig { + // check for empty offchain config + if len(offchainConfigBytes) == 0 { return encoding.UpkeepFailureReasonNone } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go index d2d58b112da..491099496cb 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go @@ -311,10 +311,9 @@ func (r *EvmRegistry) simulatePerformUpkeeps(ctx context.Context, checkResults [ // this is mostly caused by RPC flakiness r.lggr.Errorw("failed get offchain config, gas price check will be disabled", "err", err, "upkeepId", upkeepId, "block", block) } - r.lggr.Debugf("upkeep %s's offchain config is %s", upkeepId, hexutil.Encode(oc)) fr := gasprice.CheckGasPrice(ctx, upkeepId, oc, r.ge, r.lggr) if uint8(fr) == uint8(encoding.UpkeepFailureReasonGasPriceTooHigh) { - r.lggr.Infof("upkeep %s upkeep failure reason is %d", upkeepId, fr) + r.lggr.Debugf("upkeep %s upkeep failure reason is %d", upkeepId, fr) checkResults[i].Eligible = false checkResults[i].Retryable = false checkResults[i].IneligibilityReason = uint8(fr) From 023b323d575e8874366321ef3472fa459d449ee2 Mon Sep 17 00:00:00 2001 From: FelixFan1992 Date: Tue, 14 May 2024 12:39:30 -0400 Subject: [PATCH 6/8] add offchain config log field --- .../plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go index aa47476b409..f277b3179e1 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go @@ -4,6 +4,8 @@ import ( "context" "math/big" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/smartcontractkit/chainlink/v2/core/cbor" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas" @@ -34,11 +36,11 @@ func CheckGasPrice(ctx context.Context, upkeepId *big.Int, offchainConfigBytes [ var offchainConfig UpkeepOffchainConfig if err := cbor.ParseDietCBORToStruct(offchainConfigBytes, &offchainConfig); err != nil { - lggr.Debugw("failed to parse upkeep offchain config, gas price check is disabled", "upkeepId", upkeepId.String(), "err", err) + lggr.Debugw("failed to parse upkeep offchain config, gas price check is disabled", "offchainconfig", hexutil.Encode(offchainConfigBytes), "upkeepId", upkeepId.String(), "err", err) return encoding.UpkeepFailureReasonNone } if offchainConfig.MaxGasPrice == nil || offchainConfig.MaxGasPrice.Int64() <= 0 { - lggr.Debugw("maxGasPrice is not configured or incorrectly configured in upkeep offchain config, gas price check is disabled", "upkeepId", upkeepId.String()) + lggr.Debugw("maxGasPrice is not configured or incorrectly configured in upkeep offchain config, gas price check is disabled", "offchainconfig", hexutil.Encode(offchainConfigBytes), "upkeepId", upkeepId.String()) return encoding.UpkeepFailureReasonNone } lggr.Debugf("successfully decode offchain config for %s, max gas price is %s", upkeepId.String(), offchainConfig.MaxGasPrice.String()) From 314d9623ae17dd7fafa12555036c46b800e232cc Mon Sep 17 00:00:00 2001 From: FelixFan1992 Date: Tue, 14 May 2024 14:00:48 -0400 Subject: [PATCH 7/8] update --- .../plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go index f277b3179e1..f84a48c1ff8 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/gasprice/gasprice.go @@ -36,7 +36,7 @@ func CheckGasPrice(ctx context.Context, upkeepId *big.Int, offchainConfigBytes [ var offchainConfig UpkeepOffchainConfig if err := cbor.ParseDietCBORToStruct(offchainConfigBytes, &offchainConfig); err != nil { - lggr.Debugw("failed to parse upkeep offchain config, gas price check is disabled", "offchainconfig", hexutil.Encode(offchainConfigBytes), "upkeepId", upkeepId.String(), "err", err) + lggr.Warnw("failed to parse upkeep offchain config, gas price check is disabled", "offchainconfig", hexutil.Encode(offchainConfigBytes), "upkeepId", upkeepId.String(), "err", err) return encoding.UpkeepFailureReasonNone } if offchainConfig.MaxGasPrice == nil || offchainConfig.MaxGasPrice.Int64() <= 0 { From f1c1667614e6556cdfbe5805331ce84bde92c83a Mon Sep 17 00:00:00 2001 From: FelixFan1992 Date: Tue, 14 May 2024 14:01:29 -0400 Subject: [PATCH 8/8] update --- .changeset/funny-monkeys-heal.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/funny-monkeys-heal.md b/.changeset/funny-monkeys-heal.md index c58cb4ac60e..6267569432e 100644 --- a/.changeset/funny-monkeys-heal.md +++ b/.changeset/funny-monkeys-heal.md @@ -3,4 +3,4 @@ --- #changed: -AUTO-10539: improve offchain config length check +AUTO-10539: adjust logging for offchain config and gas control