Skip to content

Commit

Permalink
Automation fixes. Override core/services/ocr2/plugins/ocr2keeper/evmr…
Browse files Browse the repository at this point in the history
…egistry/v21/mercury/streams to release/2.9.1 branch
  • Loading branch information
infiloop2 committed Mar 22, 2024
1 parent 1066e86 commit 41aa34b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (s *streams) buildResult(ctx context.Context, i int, checkResult ocr2keeper
if streamsLookupResponse.IsMercuryV02() {
// check permission on the registry for mercury v0.2
opts := s.buildCallOpts(ctx, block)
if state, reason, retryable, allowed, err := s.allowedToUseMercury(opts, upkeepId.BigInt()); err != nil {
if state, reason, retryable, allowed, err := s.AllowedToUseMercury(opts, upkeepId.BigInt()); err != nil {
lookupLggr.Warnf("at block %s upkeep %s failed to query mercury allow list: %s", block, upkeepId, err)
checkResults[i].PipelineExecutionState = uint8(state)
checkResults[i].IneligibilityReason = uint8(reason)
Expand Down Expand Up @@ -257,42 +257,10 @@ func (s *streams) DoMercuryRequest(ctx context.Context, lookup *mercury.StreamsL
for j, v := range values {
s.lggr.Infof("at block %d upkeep %s requested time %s doMercuryRequest values[%d]: %s", lookup.Block, lookup.UpkeepId, lookup.Time, j, hexutil.Encode(v))
}

state, retryable, mercuryBytes, err := s.checkCallback(ctx, values, lookup)
if err != nil {
s.lggr.Errorf("at block %d upkeep %s checkCallback err: %s", lookup.Block, lookup.UpkeepId, err.Error())
checkResults[i].Retryable = retryable
checkResults[i].PipelineExecutionState = uint8(state)
return
}
s.lggr.Infof("at block %d upkeep %s requested time %s checkCallback mercuryBytes: %s", lookup.Block, lookup.UpkeepId, lookup.Time, hexutil.Encode(mercuryBytes))

unpackCallBackState, needed, performData, failureReason, _, err := s.packer.UnpackCheckCallbackResult(mercuryBytes)
if err != nil {
s.lggr.Errorf("at block %d upkeep %s requested time %s UnpackCheckCallbackResult err: %s", lookup.Block, lookup.UpkeepId, lookup.Time, err.Error())
checkResults[i].PipelineExecutionState = unpackCallBackState
return
}

if failureReason == uint8(mercury.MercuryUpkeepFailureReasonMercuryCallbackReverted) {
checkResults[i].IneligibilityReason = uint8(mercury.MercuryUpkeepFailureReasonMercuryCallbackReverted)
s.lggr.Debugf("at block %d upkeep %s requested time %s mercury callback reverts", lookup.Block, lookup.UpkeepId, lookup.Time)
return
}

if !needed {
checkResults[i].IneligibilityReason = uint8(mercury.MercuryUpkeepFailureReasonUpkeepNotNeeded)
s.lggr.Debugf("at block %d upkeep %s requested time %s callback reports upkeep not needed", lookup.Block, lookup.UpkeepId, lookup.Time)
return
}

checkResults[i].IneligibilityReason = uint8(mercury.MercuryUpkeepFailureReasonNone)
checkResults[i].Eligible = true
checkResults[i].PerformData = performData
s.lggr.Infof("at block %d upkeep %s requested time %s successful with perform data: %s", lookup.Block, lookup.UpkeepId, lookup.Time, hexutil.Encode(performData))
return values, nil
}

// allowedToUseMercury retrieves upkeep's administrative offchain config and decode a mercuryEnabled bool to indicate if
// AllowedToUseMercury retrieves upkeep's administrative offchain config and decode a mercuryEnabled bool to indicate if
// this upkeep is allowed to use Mercury service.
func (s *streams) AllowedToUseMercury(opts *bind.CallOpts, upkeepId *big.Int) (state encoding.PipelineExecutionState, reason encoding.UpkeepFailureReason, retryable bool, allow bool, err error) {
allowed, ok := s.mercuryConfig.IsUpkeepAllowed(upkeepId.String())
Expand All @@ -314,7 +282,6 @@ func (s *streams) AllowedToUseMercury(opts *bind.CallOpts, upkeepId *big.Int) (s
"data": hexutil.Bytes(payload),
}

// call checkCallback function at the block which OCR3 has agreed upon
if err = s.client.CallContext(opts.Context, &resultBytes, "eth_call", args, hexutil.EncodeBig(opts.BlockNumber)); err != nil {
return encoding.RpcFlakyFailure, encoding.UpkeepFailureReasonNone, true, false, fmt.Errorf("failed to get upkeep privilege config: %v", err)
}
Expand All @@ -341,26 +308,6 @@ func (s *streams) AllowedToUseMercury(opts *bind.CallOpts, upkeepId *big.Int) (s
return encoding.NoPipelineError, encoding.UpkeepFailureReasonNone, false, privilegeConfig.MercuryEnabled, nil
}

func (s *streams) checkCallback(ctx context.Context, values [][]byte, lookup *mercury.StreamsLookup) (mercury.MercuryUpkeepState, bool, hexutil.Bytes, error) {
payload, err := s.abi.Pack("checkCallback", lookup.UpkeepId, values, lookup.ExtraData)
if err != nil {
return mercury.PackUnpackDecodeFailed, false, nil, err
}

var b hexutil.Bytes
args := map[string]interface{}{
"to": s.registry.Address().Hex(),
"data": hexutil.Bytes(payload),
}

// call checkCallback function at the block which OCR3 has agreed upon
if err := s.client.CallContext(ctx, &b, "eth_call", args, hexutil.EncodeUint64(lookup.Block)); err != nil {
return mercury.RpcFlakyFailure, true, nil, err
}

return mercury.NoPipelineError, false, b, nil
}

func (s *streams) buildCallOpts(ctx context.Context, block *big.Int) *bind.CallOpts {
opts := bind.CallOpts{
Context: ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func TestStreams_CheckCallback(t *testing.T) {
tests := []struct {
name string
lookup *mercury.StreamsLookup
input []ocr2keepers.CheckResult
values [][]byte
statusCode int

Expand Down Expand Up @@ -153,6 +154,9 @@ func TestStreams_CheckCallback(t *testing.T) {
UpkeepId: upkeepId,
Block: bn,
},
input: []ocr2keepers.CheckResult{
{},
},
values: values,
statusCode: http.StatusOK,
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, 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, 4, 48, 120, 48, 48, 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},
Expand Down Expand Up @@ -185,6 +189,9 @@ func TestStreams_CheckCallback(t *testing.T) {
UpkeepId: upkeepId,
Block: bn,
},
input: []ocr2keepers.CheckResult{
{},
},
values: values,
statusCode: http.StatusOK,
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, 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, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Expand Down Expand Up @@ -216,6 +223,9 @@ func TestStreams_CheckCallback(t *testing.T) {
UpkeepId: upkeepId,
Block: bn,
},
input: []ocr2keepers.CheckResult{
{},
},
values: values,
statusCode: http.StatusOK,
callbackResp: []byte{},
Expand Down Expand Up @@ -434,7 +444,7 @@ func TestStreams_AllowedToUseMercury(t *testing.T) {
BlockNumber: big.NewInt(10),
}

state, reason, retryable, allowed, err := s.allowedToUseMercury(opts, upkeepId)
state, reason, retryable, allowed, err := s.AllowedToUseMercury(opts, upkeepId)
assert.Equal(t, tt.err, err)
assert.Equal(t, tt.allowed, allowed)
assert.Equal(t, tt.state, state)
Expand Down

0 comments on commit 41aa34b

Please sign in to comment.