Skip to content

Commit

Permalink
fix logIndex bug in debugging script (#10939)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanRHall authored Oct 24, 2023
1 parent 2dc0333 commit 621576c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions core/scripts/chaincli/handler/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,18 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
}
addLink("trigger", common.ExplorerLink(chainID, txHash))
blockNum = receipt.BlockNumber.Uint64()
if len(receipt.Logs) <= int(logIndex) {
failCheckArgs(fmt.Sprintf("the provided transaction has %d logs but index %d was requested", len(receipt.Logs), logIndex), err)
// find matching log event in tx
var triggeringEvent *types.Log
for i, log := range receipt.Logs {
if log.Index == uint(logIndex) {
triggeringEvent = receipt.Logs[i]
}
}
if triggeringEvent == nil {
failCheckArgs(fmt.Sprintf("unable to find log with index %d in transaction", logIndex), nil)
}
triggeringEvent := receipt.Logs[logIndex]
message(fmt.Sprintf("log #%d found in transaction", logIndex))
// check that tx for this upkeep / tx was not already performed
message(fmt.Sprintf("LogTrigger{blockNum: %d, blockHash: %s, txHash: %s, logIndex: %d}", blockNum, receipt.BlockHash.Hex(), txHash, logIndex))
workID := mustUpkeepWorkID(upkeepID, blockNum, receipt.BlockHash, txHash, logIndex)
message(fmt.Sprintf("workID computed: %s", hex.EncodeToString(workID[:])))
hasKey, err := keeperRegistry21.HasDedupKey(latestCallOpts, workID)
Expand Down Expand Up @@ -204,12 +210,14 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
if err != nil {
failUnknown("failed to check upkeep", err)
}
// do tenderly simulation
// do tenderly simulations
rawCall, err := core.RegistryABI.Pack("checkUpkeep", upkeepID, triggerData)
if err != nil {
failUnknown("failed to pack raw checkUpkeep call", err)
}
addLink("checkUpkeep simulation", tenderlySimLink(k.cfg, chainID, blockNum, rawCall, registryAddress))
rawCall = append(core.ILogAutomationABI.Methods["checkLog"].ID, triggerData...)
addLink("checkLog (direct) simulation", tenderlySimLink(k.cfg, chainID, blockNum, rawCall, upkeepInfo.Target))
} else {
resolveIneligible(fmt.Sprintf("invalid trigger type: %d", triggerType))
}
Expand All @@ -222,6 +230,7 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
streamsLookupErr, err := packer.DecodeStreamsLookupRequest(checkResult.PerformData)
if err == nil {
message("upkeep reverted with StreamsLookup")
message(fmt.Sprintf("StreamsLookup data: {FeedParamKey: %s, Feeds: %v, TimeParamKey: %s, Time: %d, ExtraData: %s}", streamsLookupErr.FeedParamKey, streamsLookupErr.Feeds, streamsLookupErr.TimeParamKey, streamsLookupErr.Time.Uint64(), hexutil.Encode(streamsLookupErr.ExtraData)))
if streamsLookupErr.FeedParamKey == feedIdHex && streamsLookupErr.TimeParamKey == blockNumber {
message("using mercury lookup v0.2")
// handle v0.2
Expand Down Expand Up @@ -269,6 +278,8 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
failUnknown("failed to pack raw checkUpkeep call", err)
}
addLink("checkCallback simulation", tenderlySimLink(k.cfg, chainID, blockNum, rawCall, registryAddress))
} else {
message("did not revert with StreamsLookup error")
}
}
if !upkeepNeeded {
Expand Down
2 changes: 2 additions & 0 deletions core/services/ocr2/plugins/ocr2keeper/evm21/core/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_utils_2_1"
iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_log_automation"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/streams_lookup_compatible_interface"
)

var UtilsABI = types.MustGetABI(automation_utils_2_1.AutomationUtilsABI)
var RegistryABI = types.MustGetABI(iregistry21.IKeeperRegistryMasterABI)
var StreamsCompatibleABI = types.MustGetABI(streams_lookup_compatible_interface.StreamsLookupCompatibleInterfaceABI)
var ILogAutomationABI = types.MustGetABI(i_log_automation.ILogAutomationABI)

0 comments on commit 621576c

Please sign in to comment.