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

support customized block number for conditional #11804

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions core/scripts/chaincli/DEBUGGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ For detailed transaction simulation logs, set up Tenderly credentials. Refer to

Execute the following command based on your upkeep type:

- For conditional upkeep:
- For conditional upkeep, if a block number is given we use that block, otherwise we use the latest block:

```bash
go run main.go keeper debug UPKEEP_ID
go run main.go keeper debug UPKEEP_ID [OPTIONAL BLOCK_NUMBER]
```

- For log trigger upkeep:
Expand Down
24 changes: 20 additions & 4 deletions core/scripts/chaincli/handler/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
}
chainID := chainIDBig.Int64()

var triggerCallOpts *bind.CallOpts // use latest block for conditionals, but use block from tx for log triggers
latestCallOpts := &bind.CallOpts{Context: ctx} // always use latest block
// Log triggers: always use block from tx
// Conditional: use latest block if no block number is provided, otherwise use block from user input
var triggerCallOpts *bind.CallOpts // use a certain block
latestCallOpts := &bind.CallOpts{Context: ctx} // use the latest block

// connect to registry contract
registryAddress := gethcommon.HexToAddress(k.cfg.RegistryAddress)
Expand Down Expand Up @@ -139,8 +141,21 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
// check upkeep
if triggerType == ConditionTrigger {
message("upkeep identified as conditional trigger")

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)
if err != nil {
failCheckArgs("unable to parse block number", err)
}
triggerCallOpts = &bind.CallOpts{Context: ctx, BlockNumber: new(big.Int).SetUint64(blockNum)}
} else {
// if no block number is provided, use latest block for both checkUpkeep and simulatePerformUpkeep
triggerCallOpts = latestCallOpts
}

var tmpCheckResult iregistry21.CheckUpkeep0
tmpCheckResult, err = keeperRegistry21.CheckUpkeep0(latestCallOpts, upkeepID)
tmpCheckResult, err = keeperRegistry21.CheckUpkeep0(triggerCallOpts, upkeepID)
if err != nil {
failUnknown("failed to check upkeep: ", err)
}
Expand Down Expand Up @@ -251,11 +266,12 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
resolveIneligible(fmt.Sprintf("invalid trigger type: %d", triggerType))
}
upkeepNeeded, performData = checkResult.UpkeepNeeded, checkResult.PerformData
// handle streams lookup

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

// handle data streams lookup
if checkResult.UpkeepFailureReason == uint8(encoding.UpkeepFailureReasonTargetCheckReverted) {
mc := &types2.MercuryCredentials{LegacyURL: k.cfg.DataStreamsLegacyURL, URL: k.cfg.DataStreamsURL, Username: k.cfg.DataStreamsID, Password: k.cfg.DataStreamsKey}
mercuryConfig := evm21.NewMercuryConfig(mc, core.StreamsCompatibleABI)
Expand Down
Loading