Skip to content

Commit

Permalink
address comments, add time in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shileiwill committed Nov 16, 2023
1 parent ec3b511 commit 0b3a28c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/patrickmn/go-cache"

ocr2keepers "github.com/smartcontractkit/ocr2keepers/pkg/v3/types"

"github.com/smartcontractkit/chainlink-relay/pkg/services"

iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evm21/core"
Expand Down Expand Up @@ -44,7 +47,7 @@ type contextCaller interface {
}

type streams struct {
utils.StartStopOnce
services.StateMachine
packer mercury.Packer
mercuryConfig mercury.MercuryConfigProvider
abi abi.ABI
Expand Down Expand Up @@ -184,7 +187,7 @@ func (s *streams) doLookup(ctx context.Context, wg *sync.WaitGroup, lookup *merc
}

if err != nil {
s.lggr.Errorf("upkeep %s retryable %v retryInterval %s doMercuryRequest: %s", lookup.UpkeepId, retryable, retryInterval, err.Error())
s.lggr.Errorf("at block %d upkeep %s requested time %s retryable %v retryInterval %s doMercuryRequest: %s", lookup.Block, lookup.UpkeepId, lookup.Time, retryable, retryInterval, err.Error())
checkResults[i].Retryable = retryable
checkResults[i].RetryInterval = retryInterval
checkResults[i].PipelineExecutionState = uint8(state)
Expand All @@ -193,7 +196,7 @@ func (s *streams) doLookup(ctx context.Context, wg *sync.WaitGroup, lookup *merc
}

for j, v := range values {
s.lggr.Infof("upkeep %s doMercuryRequest values[%d]: %s", lookup.UpkeepId, j, hexutil.Encode(v))
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)
Expand All @@ -203,31 +206,31 @@ func (s *streams) doLookup(ctx context.Context, wg *sync.WaitGroup, lookup *merc
checkResults[i].PipelineExecutionState = uint8(state)
return
}
s.lggr.Infof("checkCallback mercuryBytes=%s", hexutil.Encode(mercuryBytes))
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 UnpackCheckCallbackResult err: %s", lookup.Block, lookup.UpkeepId, err.Error())
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 mercury callback reverts", lookup.Block, lookup.UpkeepId)
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 callback reports upkeep not needed", lookup.Block, lookup.UpkeepId)
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 successful with perform data: %s", lookup.Block, lookup.UpkeepId, hexutil.Encode(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))
}

// allowedToUseMercury retrieves upkeep's administrative offchain config and decode a mercuryEnabled bool to indicate if
Expand Down
9 changes: 4 additions & 5 deletions core/services/ocr2/plugins/ocr2keeper/evm21/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewEvmRegistry(
finalityDepth uint32,
) *EvmRegistry {
mercuryConfig := &MercuryConfig{
Cred: mc,
cred: mc,
Abi: core.StreamsCompatibleABI,
AllowListCache: cache.New(defaultAllowListExpiration, cleanupInterval),
pluginRetryCache: cache.New(defaultPluginRetryExpiration, cleanupInterval),
Expand Down Expand Up @@ -129,7 +129,7 @@ var upkeepStateEvents = []common.Hash{
}

type MercuryConfig struct {
Cred *models.MercuryCredentials
cred *models.MercuryCredentials
Abi abi.ABI
// AllowListCache stores the upkeeps privileges. In 2.1, this only includes a JSON bytes for allowed to use mercury
AllowListCache *cache.Cache
Expand All @@ -138,16 +138,15 @@ type MercuryConfig struct {

func NewMercuryConfig(credentials *models.MercuryCredentials, abi abi.ABI) *MercuryConfig {
return &MercuryConfig{
Cred: credentials,
cred: credentials,
Abi: abi,
AllowListCache: cache.New(defaultPluginRetryExpiration, cleanupInterval),
pluginRetryCache: cache.New(defaultPluginRetryExpiration, cleanupInterval),
}
}

// TODO since Cred is now exposed, we should remove this method and use Cred directly
func (c *MercuryConfig) Credentials() *models.MercuryCredentials {
return c.Cred
return c.cred
}

func (c *MercuryConfig) IsUpkeepAllowed(k string) (interface{}, bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ func setupEVMRegistry(t *testing.T) *EvmRegistry {
headFunc: func(ocr2keepers.BlockKey) {},
chLog: make(chan logpoller.Log, 1000),
mercury: &MercuryConfig{
Cred: &models.MercuryCredentials{
cred: &models.MercuryCredentials{
LegacyURL: "https://google.old.com",
URL: "https://google.com",
Username: "FakeClientID",
Expand Down

0 comments on commit 0b3a28c

Please sign in to comment.