Skip to content

Commit

Permalink
use a centralized place for failure reasons and states (#11523)
Browse files Browse the repository at this point in the history
  • Loading branch information
shileiwill authored Dec 18, 2023
1 parent cfbc0b0 commit f177b32
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 157 deletions.
4 changes: 2 additions & 2 deletions core/scripts/chaincli/handler/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ func (k *Keeper) Debug(ctx context.Context, args []string) {
var values [][]byte
values, err = streams.DoMercuryRequest(ctx, streamsLookup, checkResults, 0)

if checkResults[0].IneligibilityReason == uint8(mercury.MercuryUpkeepFailureReasonInvalidRevertDataInput) {
if checkResults[0].IneligibilityReason == uint8(encoding.UpkeepFailureReasonInvalidRevertDataInput) {
resolveIneligible("upkeep used invalid revert data")
}
if checkResults[0].PipelineExecutionState == uint8(mercury.InvalidMercuryRequest) {
if checkResults[0].PipelineExecutionState == uint8(encoding.InvalidMercuryRequest) {
resolveIneligible("the mercury request data is invalid")
}
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,47 @@ import (
iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1"
)

type UpkeepFailureReason uint8
type PipelineExecutionState uint8

const (
// NOTE: This enum should be kept in sync with evmregistry/v21/mercury/upkeep_failure_reasons.go
// TODO (AUTO-7928) Remove this duplication
// upkeep failure onchain reasons
UpkeepFailureReasonNone uint8 = 0
UpkeepFailureReasonUpkeepCancelled uint8 = 1
UpkeepFailureReasonUpkeepPaused uint8 = 2
UpkeepFailureReasonTargetCheckReverted uint8 = 3
UpkeepFailureReasonUpkeepNotNeeded uint8 = 4
UpkeepFailureReasonPerformDataExceedsLimit uint8 = 5
UpkeepFailureReasonInsufficientBalance uint8 = 6
UpkeepFailureReasonMercuryCallbackReverted uint8 = 7
UpkeepFailureReasonRevertDataExceedsLimit uint8 = 8
UpkeepFailureReasonRegistryPaused uint8 = 9
UpkeepFailureReasonNone UpkeepFailureReason = 0
UpkeepFailureReasonUpkeepCancelled UpkeepFailureReason = 1
UpkeepFailureReasonUpkeepPaused UpkeepFailureReason = 2
UpkeepFailureReasonTargetCheckReverted UpkeepFailureReason = 3
UpkeepFailureReasonUpkeepNotNeeded UpkeepFailureReason = 4
UpkeepFailureReasonPerformDataExceedsLimit UpkeepFailureReason = 5
UpkeepFailureReasonInsufficientBalance UpkeepFailureReason = 6
UpkeepFailureReasonMercuryCallbackReverted UpkeepFailureReason = 7
UpkeepFailureReasonRevertDataExceedsLimit UpkeepFailureReason = 8
UpkeepFailureReasonRegistryPaused UpkeepFailureReason = 9
// leaving a gap here for more onchain failure reasons in the future
// upkeep failure offchain reasons
UpkeepFailureReasonMercuryAccessNotAllowed uint8 = 32
UpkeepFailureReasonTxHashNoLongerExists uint8 = 33
UpkeepFailureReasonInvalidRevertDataInput uint8 = 34
UpkeepFailureReasonSimulationFailed uint8 = 35
UpkeepFailureReasonTxHashReorged uint8 = 36
UpkeepFailureReasonMercuryAccessNotAllowed UpkeepFailureReason = 32
UpkeepFailureReasonTxHashNoLongerExists UpkeepFailureReason = 33
UpkeepFailureReasonInvalidRevertDataInput UpkeepFailureReason = 34
UpkeepFailureReasonSimulationFailed UpkeepFailureReason = 35
UpkeepFailureReasonTxHashReorged UpkeepFailureReason = 36

// NOTE: This enum should be kept in sync with evmregistry/v21/mercury/upkeep_states.go
// TODO (AUTO-7928) Remove this duplication
// pipeline execution error
NoPipelineError uint8 = 0
CheckBlockTooOld uint8 = 1
CheckBlockInvalid uint8 = 2
RpcFlakyFailure uint8 = 3
MercuryFlakyFailure uint8 = 4
PackUnpackDecodeFailed uint8 = 5
MercuryUnmarshalError uint8 = 6
InvalidMercuryRequest uint8 = 7
InvalidMercuryResponse uint8 = 8 // this will only happen if Mercury server sends bad responses
UpkeepNotAuthorized uint8 = 9
NoPipelineError PipelineExecutionState = 0
CheckBlockTooOld PipelineExecutionState = 1
CheckBlockInvalid PipelineExecutionState = 2
RpcFlakyFailure PipelineExecutionState = 3
MercuryFlakyFailure PipelineExecutionState = 4
PackUnpackDecodeFailed PipelineExecutionState = 5
MercuryUnmarshalError PipelineExecutionState = 6
InvalidMercuryRequest PipelineExecutionState = 7
InvalidMercuryResponse PipelineExecutionState = 8 // this will only happen if Mercury server sends bad responses
UpkeepNotAuthorized PipelineExecutionState = 9
)

type UpkeepInfo = iregistry21.KeeperRegistryBase21UpkeepInfo

type Packer interface {
UnpackCheckResult(payload ocr2keepers.UpkeepPayload, raw string) (ocr2keepers.CheckResult, error)
UnpackPerformResult(raw string) (uint8, bool, error)
UnpackPerformResult(raw string) (PipelineExecutionState, bool, error)
UnpackLogTriggerConfig(raw []byte) (automation_utils_2_1.LogTriggerConfig, error)
PackReport(report automation_utils_2_1.KeeperRegistryBase21Report) ([]byte, error)
UnpackReport(raw []byte) (automation_utils_2_1.KeeperRegistryBase21Report, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (p *abiPacker) UnpackCheckResult(payload ocr2keepers.UpkeepPayload, raw str
return result, nil
}

func (p *abiPacker) UnpackPerformResult(raw string) (uint8, bool, error) {
func (p *abiPacker) UnpackPerformResult(raw string) (PipelineExecutionState, bool, error) {
b, err := hexutil.Decode(raw)
if err != nil {
return PackUnpackDecodeFailed, false, err
Expand Down Expand Up @@ -134,10 +134,10 @@ func (p *abiPacker) UnpackReport(raw []byte) (automation_utils_2_1.KeeperRegistr
}

// GetIneligibleCheckResultWithoutPerformData returns an ineligible check result with ineligibility reason and pipeline execution state but without perform data
func GetIneligibleCheckResultWithoutPerformData(p ocr2keepers.UpkeepPayload, reason uint8, state uint8, retryable bool) ocr2keepers.CheckResult {
func GetIneligibleCheckResultWithoutPerformData(p ocr2keepers.UpkeepPayload, reason UpkeepFailureReason, state PipelineExecutionState, retryable bool) ocr2keepers.CheckResult {
return ocr2keepers.CheckResult{
IneligibilityReason: reason,
PipelineExecutionState: state,
IneligibilityReason: uint8(reason),
PipelineExecutionState: uint8(state),
Retryable: retryable,
UpkeepID: p.UpkeepID,
Trigger: p.Trigger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestPacker_UnpackPerformResult(t *testing.T) {
tests := []struct {
Name string
RawData string
State uint8
State PipelineExecutionState
}{
{
Name: "unpack success",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type MercuryData struct {
Error error
Retryable bool
Bytes [][]byte
State MercuryUpkeepState
State encoding.PipelineExecutionState
}

type MercuryConfigProvider interface {
Expand All @@ -85,7 +85,7 @@ type HttpClient interface {
}

type MercuryClient interface {
DoRequest(ctx context.Context, streamsLookup *StreamsLookup, pluginRetryKey string) (MercuryUpkeepState, MercuryUpkeepFailureReason, [][]byte, bool, time.Duration, error)
DoRequest(ctx context.Context, streamsLookup *StreamsLookup, pluginRetryKey string) (encoding.PipelineExecutionState, encoding.UpkeepFailureReason, [][]byte, bool, time.Duration, error)
}

type StreamsLookupError struct {
Expand Down Expand Up @@ -116,7 +116,7 @@ func (l *StreamsLookup) IsMercuryV03UsingBlockNumber() bool {
}

type Packer interface {
UnpackCheckCallbackResult(callbackResp []byte) (uint8, bool, []byte, uint8, *big.Int, error)
UnpackCheckCallbackResult(callbackResp []byte) (encoding.PipelineExecutionState, bool, []byte, encoding.UpkeepFailureReason, *big.Int, error)
PackGetUpkeepPrivilegeConfig(upkeepId *big.Int) ([]byte, error)
UnpackGetUpkeepPrivilegeConfig(resp []byte) ([]byte, error)
DecodeStreamsLookupRequest(data []byte) (*StreamsLookupError, error)
Expand Down Expand Up @@ -149,15 +149,15 @@ func (p *abiPacker) DecodeStreamsLookupRequest(data []byte) (*StreamsLookupError
}, nil
}

func (p *abiPacker) UnpackCheckCallbackResult(callbackResp []byte) (uint8, bool, []byte, uint8, *big.Int, error) {
func (p *abiPacker) UnpackCheckCallbackResult(callbackResp []byte) (encoding.PipelineExecutionState, bool, []byte, encoding.UpkeepFailureReason, *big.Int, error) {
out, err := p.registryABI.Methods["checkCallback"].Outputs.UnpackValues(callbackResp)
if err != nil {
return encoding.PackUnpackDecodeFailed, false, nil, 0, nil, fmt.Errorf("%w: unpack checkUpkeep return: %s", err, hexutil.Encode(callbackResp))
}

upkeepNeeded := *abi.ConvertType(out[0], new(bool)).(*bool)
rawPerformData := *abi.ConvertType(out[1], new([]byte)).(*[]byte)
failureReason := *abi.ConvertType(out[2], new(uint8)).(*uint8)
failureReason := encoding.UpkeepFailureReason(*abi.ConvertType(out[2], new(uint8)).(*uint8))
gasUsed := *abi.ConvertType(out[3], new(*big.Int)).(**big.Int)

return encoding.NoPipelineError, upkeepNeeded, rawPerformData, failureReason, gasUsed, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,25 @@ func TestPacker_UnpackCheckCallbackResult(t *testing.T) {
CallbackResp []byte
UpkeepNeeded bool
PerformData []byte
FailureReason uint8
FailureReason encoding.UpkeepFailureReason
GasUsed *big.Int
ErrorString string
State uint8
State encoding.PipelineExecutionState
}{
{
Name: "unpack upkeep needed",
CallbackResp: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 8, 120, 111, 101, 122, 90, 54, 44, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
FailureReason: uint8(encoding.UpkeepFailureReasonNone),
FailureReason: encoding.UpkeepFailureReasonNone,
GasUsed: big.NewInt(11796),
},
{
Name: "unpack upkeep not needed",
CallbackResp: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 10, 11, 21, 31, 41, 15, 16, 17, 18, 19, 13, 14, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 120, 111, 101, 122, 90, 54, 44, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
FailureReason: uint8(encoding.UpkeepFailureReasonUpkeepNotNeeded),
FailureReason: encoding.UpkeepFailureReasonUpkeepNotNeeded,
GasUsed: big.NewInt(13008),
},
{
Expand Down
Loading

0 comments on commit f177b32

Please sign in to comment.