Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the block number provided or derived to run basic checks #12086

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 52 additions & 33 deletions core/scripts/chaincli/handler/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,50 +98,27 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
failCheckArgs("invalid upkeep ID", nil)
}
}
// get upkeep info

// get trigger type, trigger type is immutable after its first setup
triggerType, err := keeperRegistry21.GetTriggerType(latestCallOpts, upkeepID)
if err != nil {
failUnknown("failed to get trigger type: ", err)
}
upkeepInfo, err := keeperRegistry21.GetUpkeep(latestCallOpts, upkeepID)
if err != nil {
failUnknown("failed to get trigger type: ", err)
}
minBalance, err := keeperRegistry21.GetMinBalance(latestCallOpts, upkeepID)
if err != nil {
failUnknown("failed to get min balance: ", err)
}
// do basic sanity checks
if (upkeepInfo.Target == gethcommon.Address{}) {
failCheckArgs("this upkeep does not exist on this registry", nil)
}
addLink("upkeep link", common.UpkeepLink(chainID, upkeepID))
addLink("upkeep contract address", common.ContractExplorerLink(chainID, upkeepInfo.Target))
if upkeepInfo.Paused {
resolveIneligible("upkeep is paused")
}
if upkeepInfo.MaxValidBlocknumber != math.MaxUint32 {
resolveIneligible("upkeep is cancelled")
}
message("upkeep is active (not paused or cancelled)")
if upkeepInfo.Balance.Cmp(minBalance) == -1 {
resolveIneligible("minBalance is < upkeep balance")
}
message("upkeep is funded above the min balance")
if bigmath.Div(bigmath.Mul(bigmath.Sub(upkeepInfo.Balance, minBalance), big.NewInt(100)), minBalance).Cmp(big.NewInt(5)) == -1 {
warning("upkeep balance is < 5% larger than minBalance")
}

// local state for pipeline results
var upkeepInfo iregistry21.KeeperRegistryBase21UpkeepInfo
var checkResult iregistry21.CheckUpkeep
var blockNum uint64
var performData []byte
var workID [32]byte
var trigger ocr2keepers.Trigger
upkeepNeeded := false
// check upkeep

// run basic checks and check upkeep by trigger type
if triggerType == ConditionTrigger {
message("upkeep identified as conditional trigger")

// validate inputs
if len(args) > 1 {
// if a block number is provided, use that block for both checkUpkeep and simulatePerformUpkeep
blockNum, err = strconv.ParseUint(args[1], 10, 64)
Expand All @@ -154,6 +131,9 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
triggerCallOpts = latestCallOpts
}

// do basic checks
upkeepInfo = getUpkeepInfoAndRunBasicChecks(keeperRegistry21, triggerCallOpts, upkeepID, chainID)

var tmpCheckResult iregistry21.CheckUpkeep0
tmpCheckResult, err = keeperRegistry21.CheckUpkeep0(triggerCallOpts, upkeepID)
if err != nil {
Expand Down Expand Up @@ -214,6 +194,7 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
trigger = mustAutomationTrigger(txHash, logIndex, blockNum, receipt.BlockHash)
workID = mustUpkeepWorkID(upkeepID, trigger)
message(fmt.Sprintf("workID computed: %s", hex.EncodeToString(workID[:])))

var hasKey bool
hasKey, err = keeperRegistry21.HasDedupKey(latestCallOpts, workID)
if err != nil {
Expand All @@ -223,6 +204,10 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
resolveIneligible("upkeep was already performed")
}
triggerCallOpts = &bind.CallOpts{Context: ctx, BlockNumber: big.NewInt(receipt.BlockNumber.Int64())}

// do basic checks
upkeepInfo = getUpkeepInfoAndRunBasicChecks(keeperRegistry21, triggerCallOpts, upkeepID, chainID)

var rawTriggerConfig []byte
rawTriggerConfig, err = keeperRegistry21.GetUpkeepTriggerConfig(triggerCallOpts, upkeepID)
if err != nil {
Expand Down Expand Up @@ -265,10 +250,10 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
} else {
resolveIneligible(fmt.Sprintf("invalid trigger type: %d", triggerType))
}
upkeepNeeded, performData = checkResult.UpkeepNeeded, checkResult.PerformData

upkeepNeeded, performData = checkResult.UpkeepNeeded, checkResult.PerformData
if checkResult.UpkeepFailureReason != 0 {
message(fmt.Sprintf("checkUpkeep failed with UpkeepFailureReason %s", getCheckUpkeepFailureReason(checkResult.UpkeepFailureReason)))
message(fmt.Sprintf("checkUpkeep reverted with UpkeepFailureReason %s", getCheckUpkeepFailureReason(checkResult.UpkeepFailureReason)))
}

// handle data streams lookup
Expand Down Expand Up @@ -316,7 +301,7 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
}

if k.cfg.DataStreamsLegacyURL == "" || k.cfg.DataStreamsURL == "" || k.cfg.DataStreamsID == "" || k.cfg.DataStreamsKey == "" {
failCheckConfig("Data streams configs not set properly, check your DATA_STREAMS_LEGACY_URL, DATA_STREAMS_URL, DATA_STREAMS_ID and DATA_STREAMS_KEY", nil)
failCheckConfig("Data streams configs not set properly for this network, check your DATA_STREAMS settings in .env", nil)
}

// do mercury request
Expand Down Expand Up @@ -394,6 +379,40 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
}
}

func getUpkeepInfoAndRunBasicChecks(keeperRegistry21 *iregistry21.IKeeperRegistryMaster, callOpts *bind.CallOpts, upkeepID *big.Int, chainID int64) iregistry21.KeeperRegistryBase21UpkeepInfo {
// get upkeep info
upkeepInfo, err := keeperRegistry21.GetUpkeep(callOpts, upkeepID)
if err != nil {
failUnknown("failed to get upkeep info: ", err)
}
// get min balance
minBalance, err := keeperRegistry21.GetMinBalance(callOpts, upkeepID)
if err != nil {
failUnknown("failed to get min balance: ", err)
}
// do basic sanity checks
if (upkeepInfo.Target == gethcommon.Address{}) {
failCheckArgs("this upkeep does not exist on this registry", nil)
}
addLink("upkeep link", common.UpkeepLink(chainID, upkeepID))
addLink("upkeep contract address", common.ContractExplorerLink(chainID, upkeepInfo.Target))
if upkeepInfo.Paused {
resolveIneligible("upkeep is paused")
}
if upkeepInfo.MaxValidBlocknumber != math.MaxUint32 {
resolveIneligible("upkeep is canceled")
}
message("upkeep is active (not paused or canceled)")
if upkeepInfo.Balance.Cmp(minBalance) == -1 {
resolveIneligible("minBalance is < upkeep balance")
}
message("upkeep is funded above the min balance")
if bigmath.Div(bigmath.Mul(bigmath.Sub(upkeepInfo.Balance, minBalance), big.NewInt(100)), minBalance).Cmp(big.NewInt(5)) == -1 {
warning("upkeep balance is < 5% larger than minBalance")
}
return upkeepInfo
}

func getCheckUpkeepFailureReason(reasonIndex uint8) string {
// Copied from KeeperRegistryBase2_1.sol
reasonStrings := []string{
Expand Down
Loading