Skip to content

Commit

Permalink
support customized block number for conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
shileiwill committed Jan 24, 2024
1 parent 2586bc4 commit 06463af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
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

0 comments on commit 06463af

Please sign in to comment.