diff --git a/core/config/mercury_config.go b/core/config/mercury_config.go index 6a483c593e3..1210fd282ef 100644 --- a/core/config/mercury_config.go +++ b/core/config/mercury_config.go @@ -3,7 +3,7 @@ package config import ( "time" - ocr2models "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" + "github.com/smartcontractkit/chainlink-common/pkg/types" ) type MercuryCache interface { @@ -17,7 +17,7 @@ type MercuryTLS interface { } type Mercury interface { - Credentials(credName string) *ocr2models.MercuryCredentials + Credentials(credName string) *types.MercuryCredentials Cache() MercuryCache TLS() MercuryTLS } diff --git a/core/scripts/chaincli/handler/debug.go b/core/scripts/chaincli/handler/debug.go index 628aef0b434..c7b2ad7acbc 100644 --- a/core/scripts/chaincli/handler/debug.go +++ b/core/scripts/chaincli/handler/debug.go @@ -14,13 +14,15 @@ import ( "os" "strconv" + types2 "github.com/smartcontractkit/chainlink-common/pkg/types" + "github.com/ethereum/go-ethereum/accounts/abi/bind" gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" evm21 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21" @@ -31,7 +33,6 @@ import ( "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/logger" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury" @@ -256,7 +257,7 @@ func (k *Keeper) Debug(ctx context.Context, args []string) { } if checkResult.UpkeepFailureReason == uint8(encoding.UpkeepFailureReasonTargetCheckReverted) { - mc := &models.MercuryCredentials{LegacyURL: k.cfg.MercuryLegacyURL, URL: k.cfg.MercuryURL, Username: k.cfg.MercuryID, Password: k.cfg.MercuryKey} + mc := &types2.MercuryCredentials{LegacyURL: k.cfg.MercuryLegacyURL, URL: k.cfg.MercuryURL, Username: k.cfg.MercuryID, Password: k.cfg.MercuryKey} mercuryConfig := evm21.NewMercuryConfig(mc, core.StreamsCompatibleABI) lggr, _ := logger.NewLogger() blockSub := &blockSubscriber{k.client} diff --git a/core/scripts/go.mod b/core/scripts/go.mod index 2a60e0d4a14..1efcd5275d2 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -18,8 +18,8 @@ require ( github.com/olekukonko/tablewriter v0.0.5 github.com/pelletier/go-toml/v2 v2.1.1 github.com/shopspring/decimal v1.3.1 - github.com/smartcontractkit/chainlink-automation v1.0.1 - github.com/smartcontractkit/chainlink-common v0.1.7-0.20240108182329-237f56daad6b + github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20240118012339-4864e2306bb1 github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868 github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000 github.com/smartcontractkit/libocr v0.0.0-20231130143053-c5102a9c0fb7 diff --git a/core/scripts/go.sum b/core/scripts/go.sum index c2fc995d0df..cf504cf6047 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1162,10 +1162,10 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumvbfM1u/etVq42Afwq/jtNSBSOA8n5jntnNPo= github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= -github.com/smartcontractkit/chainlink-automation v1.0.1 h1:vVjBFq2Zsz21kPy1Pb0wpjF9zrbJX+zjXphDeeR4XZk= -github.com/smartcontractkit/chainlink-automation v1.0.1/go.mod h1:INSchkV3ntyDdlZKGWA030MPDpp6pbeuiRkRKYFCm2k= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240108182329-237f56daad6b h1:PRuvHgPka1gIGPKASuJHvqUvYWhZO7z5B/kKapjkZaM= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240108182329-237f56daad6b/go.mod h1:f+0ei9N4PlTJHu7pbGzEjTnBUr45syPdGFu5+31lS5Q= +github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429 h1:xkejUBZhcBpBrTSfxc91Iwzadrb6SXw8ks69bHIQ9Ww= +github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429/go.mod h1:wJmVvDf4XSjsahWtfUq3wvIAYEAuhr7oxmxYnEL/LGQ= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240118012339-4864e2306bb1 h1:3cWO2/lFVDul5SVTgl4/RX/GXcT8Zq5NGMPeNEz09tY= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240118012339-4864e2306bb1/go.mod h1:f+0ei9N4PlTJHu7pbGzEjTnBUr45syPdGFu5+31lS5Q= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5 h1:kBnmjv3fxU7krVIqZFvo1m4F6qBc4vPURQFX/mcChhI= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5/go.mod h1:EoM7wQ81mov7wsUzG4zEnnr0EH0POEo/I0hRDg433TU= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 h1:xYqRgZO0nMSO8CBCMR0r3WA+LZ4kNL8a6bnbyk/oBtQ= diff --git a/core/services/chainlink/config_mercury.go b/core/services/chainlink/config_mercury.go index 49f1cf0a5f4..27303a68899 100644 --- a/core/services/chainlink/config_mercury.go +++ b/core/services/chainlink/config_mercury.go @@ -3,9 +3,10 @@ package chainlink import ( "time" + "github.com/smartcontractkit/chainlink-common/pkg/types" + "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/config/toml" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" ) var _ config.MercuryCache = (*mercuryCacheConfig)(nil) @@ -37,9 +38,9 @@ type mercuryConfig struct { s toml.MercurySecrets } -func (m *mercuryConfig) Credentials(credName string) *models.MercuryCredentials { +func (m *mercuryConfig) Credentials(credName string) *types.MercuryCredentials { if mc, ok := m.s.Credentials[credName]; ok { - c := &models.MercuryCredentials{ + c := &types.MercuryCredentials{ URL: mc.URL.URL().String(), Password: string(*mc.Password), Username: string(*mc.Username), diff --git a/core/services/chainlink/config_mercury_test.go b/core/services/chainlink/config_mercury_test.go index 71dfb2a01ce..1ae8dc0ba2e 100644 --- a/core/services/chainlink/config_mercury_test.go +++ b/core/services/chainlink/config_mercury_test.go @@ -3,11 +3,11 @@ package chainlink import ( "testing" + "github.com/smartcontractkit/chainlink-common/pkg/types" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" - "github.com/smartcontractkit/chainlink/v2/core/config/toml" ) @@ -33,8 +33,8 @@ func TestMercuryConfig(t *testing.T) { require.NoError(t, err) m := cfg.Mercury() - assert.Equal(t, &models.MercuryCredentials{URL: "https://chain1.link", Username: "username1", Password: "password1"}, m.Credentials("cred1")) - assert.Equal(t, &models.MercuryCredentials{URL: "https://chain2.link", Username: "username2", Password: "password2"}, m.Credentials("cred2")) + assert.Equal(t, &types.MercuryCredentials{URL: "https://chain1.link", Username: "username1", Password: "password1"}, m.Credentials("cred1")) + assert.Equal(t, &types.MercuryCredentials{URL: "https://chain2.link", Username: "username2", Password: "password2"}, m.Credentials("cred2")) } func TestMercuryTLS(t *testing.T) { diff --git a/core/services/ocr2/delegate.go b/core/services/ocr2/delegate.go index 37235437de1..2ea99d65cfe 100644 --- a/core/services/ocr2/delegate.go +++ b/core/services/ocr2/delegate.go @@ -43,7 +43,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/services/keystore" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ocr2key" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/dkg" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/dkg/persistence" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/functions" @@ -188,7 +187,7 @@ type jobPipelineConfig interface { } type mercuryConfig interface { - Credentials(credName string) *models.MercuryCredentials + Credentials(credName string) *types.MercuryCredentials Cache() coreconfig.MercuryCache TLS() coreconfig.MercuryTLS } @@ -1089,12 +1088,13 @@ func (d *Delegate) newServicesOCR2Keepers21( provider, err := relayer.NewPluginProvider(ctx, types.RelayArgs{ - ExternalJobID: jb.ExternalJobID, - JobID: jb.ID, - ContractID: spec.ContractID, - New: d.isNewlyCreatedJob, - RelayConfig: spec.RelayConfig.Bytes(), - ProviderType: string(spec.PluginType), + ExternalJobID: jb.ExternalJobID, + JobID: jb.ID, + ContractID: spec.ContractID, + New: d.isNewlyCreatedJob, + RelayConfig: spec.RelayConfig.Bytes(), + ProviderType: string(spec.PluginType), + MercuryCredentials: mc, }, types.PluginArgs{ TransmitterID: transmitterID, PluginConfig: spec.PluginConfig.Bytes(), @@ -1108,12 +1108,7 @@ func (d *Delegate) newServicesOCR2Keepers21( return nil, errors.New("could not coerce PluginProvider to AutomationProvider") } - chain, err := d.legacyChains.Get(rid.ChainID) - if err != nil { - return nil, fmt.Errorf("keeper2 services: failed to get chain %s: %w", rid.ChainID, err) - } - - services, err := ocr2keeper.EVMDependencies21(jb, d.db, lggr, chain, mc, kb, d.cfg.Database()) + services, err := ocr2keeper.EVMDependencies21(kb) if err != nil { return nil, errors.Wrap(err, "could not build dependencies for ocr2 keepers") } @@ -1154,15 +1149,15 @@ func (d *Delegate) newServicesOCR2Keepers21( OffchainKeyring: kb, OnchainKeyring: services.Keyring(), LocalConfig: lc, - LogProvider: services.LogEventProvider(), - EventProvider: services.TransmitEventProvider(), - Runnable: services.Registry(), - Encoder: services.Encoder(), - BlockSubscriber: services.BlockSubscriber(), - RecoverableProvider: services.LogRecoverer(), - PayloadBuilder: services.PayloadBuilder(), - UpkeepProvider: services.UpkeepProvider(), - UpkeepStateUpdater: services.UpkeepStateStore(), + LogProvider: keeperProvider.LogEventProvider(), + EventProvider: keeperProvider.TransmitEventProvider(), + Runnable: keeperProvider.Registry(), + Encoder: keeperProvider.Encoder(), + BlockSubscriber: keeperProvider.BlockSubscriber(), + RecoverableProvider: keeperProvider.LogRecoverer(), + PayloadBuilder: keeperProvider.PayloadBuilder(), + UpkeepProvider: keeperProvider.UpkeepProvider(), + UpkeepStateUpdater: keeperProvider.UpkeepStateStore(), UpkeepTypeGetter: ocr2keeper21core.GetUpkeepType, WorkIDGenerator: ocr2keeper21core.UpkeepWorkID, // TODO: Clean up the config @@ -1179,12 +1174,12 @@ func (d *Delegate) newServicesOCR2Keepers21( automationServices := []job.ServiceCtx{ keeperProvider, - services.Registry(), - services.BlockSubscriber(), - services.LogEventProvider(), - services.LogRecoverer(), - services.UpkeepStateStore(), - services.TransmitEventProvider(), + keeperProvider.Registry(), + keeperProvider.BlockSubscriber(), + keeperProvider.LogEventProvider(), + keeperProvider.LogRecoverer(), + keeperProvider.UpkeepStateStore(), + keeperProvider.TransmitEventProvider(), pluginService, } @@ -1194,7 +1189,7 @@ func (d *Delegate) newServicesOCR2Keepers21( customTelemService, custErr := autotelemetry21.NewAutomationCustomTelemetryService( endpoint, lggr, - services.BlockSubscriber(), + keeperProvider.BlockSubscriber(), keeperProvider.ContractConfigTracker(), ) if custErr != nil { @@ -1230,7 +1225,7 @@ func (d *Delegate) newServicesOCR2Keepers20( return nil, fmt.Errorf("keepers2.0 services: failed to get chain (%s): %w", rid.ChainID, err2) } - keeperProvider, rgstry, encoder, logProvider, err2 := ocr2keeper.EVMDependencies20(jb, d.db, lggr, chain, d.ethKs) + keeperProvider, rgstry, encoder, logProvider, err2 := ocr2keeper.EVMDependencies20(jb, d.db, lggr, chain, d.ethKs, d.cfg.Database()) if err2 != nil { return nil, errors.Wrap(err2, "could not build dependencies for ocr2 keepers") } diff --git a/core/services/ocr2/models/models.go b/core/services/ocr2/models/models.go deleted file mode 100644 index 4d3b8bf532c..00000000000 --- a/core/services/ocr2/models/models.go +++ /dev/null @@ -1,8 +0,0 @@ -package models - -type MercuryCredentials struct { - LegacyURL string - URL string - Username string - Password string -} diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/active_list.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/active_list.go index 7ea476ee773..55c01939cb8 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/active_list.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/active_list.go @@ -4,7 +4,9 @@ import ( "math/big" "sync" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" ) @@ -18,7 +20,7 @@ type ActiveUpkeepList interface { // Remove removes entries from the list Remove(id ...*big.Int) int // View returns the list of IDs of the given type - View(...ocr2keepers.UpkeepType) []*big.Int + View(...types.UpkeepType) []*big.Int // IsActive returns true if the given ID is of an active upkeep IsActive(id *big.Int) bool Size() int @@ -81,7 +83,7 @@ func (al *activeList) Remove(ids ...*big.Int) int { } // View returns the list of IDs of the given type -func (al *activeList) View(upkeepTypes ...ocr2keepers.UpkeepType) []*big.Int { +func (al *activeList) View(upkeepTypes ...types.UpkeepType) []*big.Int { al.lock.RLock() defer al.lock.RUnlock() diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/active_list_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/active_list_test.go index 378589d1779..d9f9c45d749 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/active_list_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/active_list_test.go @@ -5,27 +5,29 @@ import ( "sort" "testing" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" ) func TestActiveUpkeepList(t *testing.T) { logIDs := []ocr2keepers.UpkeepIdentifier{ - core.GenUpkeepID(ocr2keepers.LogTrigger, "0"), - core.GenUpkeepID(ocr2keepers.LogTrigger, "1"), - core.GenUpkeepID(ocr2keepers.LogTrigger, "2"), - core.GenUpkeepID(ocr2keepers.LogTrigger, "3"), - core.GenUpkeepID(ocr2keepers.LogTrigger, "4"), + core.GenUpkeepID(types.LogTrigger, "0"), + core.GenUpkeepID(types.LogTrigger, "1"), + core.GenUpkeepID(types.LogTrigger, "2"), + core.GenUpkeepID(types.LogTrigger, "3"), + core.GenUpkeepID(types.LogTrigger, "4"), } conditionalIDs := []ocr2keepers.UpkeepIdentifier{ - core.GenUpkeepID(ocr2keepers.ConditionTrigger, "0"), - core.GenUpkeepID(ocr2keepers.ConditionTrigger, "1"), - core.GenUpkeepID(ocr2keepers.ConditionTrigger, "2"), - core.GenUpkeepID(ocr2keepers.ConditionTrigger, "3"), - core.GenUpkeepID(ocr2keepers.ConditionTrigger, "4"), + core.GenUpkeepID(types.ConditionTrigger, "0"), + core.GenUpkeepID(types.ConditionTrigger, "1"), + core.GenUpkeepID(types.ConditionTrigger, "2"), + core.GenUpkeepID(types.ConditionTrigger, "3"), + core.GenUpkeepID(types.ConditionTrigger, "4"), } tests := []struct { @@ -70,7 +72,7 @@ func TestActiveUpkeepList(t *testing.T) { for _, id := range tc.remove { require.False(t, al.IsActive(id)) } - logIds := al.View(ocr2keepers.LogTrigger) + logIds := al.View(types.LogTrigger) require.Equal(t, len(tc.expectedLogIds), len(logIds)) sort.Slice(logIds, func(i, j int) bool { return logIds[i].Cmp(logIds[j]) < 0 @@ -78,7 +80,7 @@ func TestActiveUpkeepList(t *testing.T) { for i := range logIds { require.Equal(t, tc.expectedLogIds[i], logIds[i]) } - conditionalIds := al.View(ocr2keepers.ConditionTrigger) + conditionalIds := al.View(types.ConditionTrigger) require.Equal(t, len(tc.expectedConditionalIds), len(conditionalIds)) sort.Slice(conditionalIds, func(i, j int) bool { return conditionalIds[i].Cmp(conditionalIds[j]) < 0 @@ -98,7 +100,7 @@ func TestActiveUpkeepList_error(t *testing.T) { al.items["-1"] = true al.items["100"] = true - keys := al.View(ocr2keepers.ConditionTrigger) + keys := al.View(types.ConditionTrigger) require.Equal(t, []*big.Int{big.NewInt(100)}, keys) }) } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/autotelemetry21/custom_telemetry.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/autotelemetry21/custom_telemetry.go index e7e9728c3a0..53303553db7 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/autotelemetry21/custom_telemetry.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/autotelemetry21/custom_telemetry.go @@ -10,12 +10,11 @@ import ( "github.com/smartcontractkit/libocr/commontypes" "github.com/smartcontractkit/libocr/offchainreporting2plus/types" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink-common/pkg/services" "github.com/smartcontractkit/chainlink/v2/core/logger" - evm21 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21" "github.com/smartcontractkit/chainlink/v2/core/services/synchronization/telem" "github.com/smartcontractkit/chainlink/v2/core/static" "github.com/smartcontractkit/chainlink/v2/core/utils" @@ -24,7 +23,7 @@ import ( type AutomationCustomTelemetryService struct { services.StateMachine monitoringEndpoint commontypes.MonitoringEndpoint - blockSubscriber *evm21.BlockSubscriber + blockSubscriber ocr2keepers.BlockSubscriber blockSubChanID int threadCtrl utils.ThreadControl lggr logger.Logger @@ -34,7 +33,7 @@ type AutomationCustomTelemetryService struct { // NewAutomationCustomTelemetryService creates a telemetry service for new blocks and node version func NewAutomationCustomTelemetryService(me commontypes.MonitoringEndpoint, - lggr logger.Logger, blocksub *evm21.BlockSubscriber, configTracker types.ContractConfigTracker) (*AutomationCustomTelemetryService, error) { + lggr logger.Logger, blocksub ocr2keepers.BlockSubscriber, configTracker types.ContractConfigTracker) (*AutomationCustomTelemetryService, error) { return &AutomationCustomTelemetryService{ monitoringEndpoint: me, threadCtrl: utils.NewThreadControl(), diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber.go index 134a75fc2c7..9ae17c08ee3 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink-common/pkg/services" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber_test.go index 41a43b951e7..2be6a6a874c 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/block_subscriber_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" commonmocks "github.com/smartcontractkit/chainlink/v2/common/mocks" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker/types" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/interfaces.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/interfaces.go index 49975855b54..4dd4d387a80 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/interfaces.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/interfaces.go @@ -3,7 +3,7 @@ package core import ( "context" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" ) // UpkeepStateReader is the interface for reading the current state of upkeeps. diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/mocks/upkeep_state_reader.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/mocks/upkeep_state_reader.go index 3167cf97aad..5a815987a83 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/mocks/upkeep_state_reader.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/mocks/upkeep_state_reader.go @@ -5,9 +5,9 @@ package mocks import ( context "context" - mock "github.com/stretchr/testify/mock" + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - types "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + mock "github.com/stretchr/testify/mock" ) // UpkeepStateReader is an autogenerated mock type for the UpkeepStateReader type @@ -16,7 +16,7 @@ type UpkeepStateReader struct { } // SelectByWorkIDs provides a mock function with given fields: ctx, workIDs -func (_m *UpkeepStateReader) SelectByWorkIDs(ctx context.Context, workIDs ...string) ([]types.UpkeepState, error) { +func (_m *UpkeepStateReader) SelectByWorkIDs(ctx context.Context, workIDs ...string) ([]automation.UpkeepState, error) { _va := make([]interface{}, len(workIDs)) for _i := range workIDs { _va[_i] = workIDs[_i] @@ -30,16 +30,16 @@ func (_m *UpkeepStateReader) SelectByWorkIDs(ctx context.Context, workIDs ...str panic("no return value specified for SelectByWorkIDs") } - var r0 []types.UpkeepState + var r0 []automation.UpkeepState var r1 error - if rf, ok := ret.Get(0).(func(context.Context, ...string) ([]types.UpkeepState, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, ...string) ([]automation.UpkeepState, error)); ok { return rf(ctx, workIDs...) } - if rf, ok := ret.Get(0).(func(context.Context, ...string) []types.UpkeepState); ok { + if rf, ok := ret.Get(0).(func(context.Context, ...string) []automation.UpkeepState); ok { r0 = rf(ctx, workIDs...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]types.UpkeepState) + r0 = ret.Get(0).([]automation.UpkeepState) } } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/payload.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/payload.go index ed5530ae7b5..5077e7b74d5 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/payload.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/payload.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" ) var ( diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/payload_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/payload_test.go index cb3a67dde0c..63de1f25ec4 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/payload_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/payload_test.go @@ -4,10 +4,12 @@ import ( "math/big" "testing" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" ) func TestWorkID(t *testing.T) { @@ -35,7 +37,7 @@ func TestWorkID(t *testing.T) { }, { name: "happy flow with extension", - upkeepID: GenUpkeepID(ocr2keepers.LogTrigger, "12345").String(), + upkeepID: GenUpkeepID(types.LogTrigger, "12345").String(), trigger: ocr2keepers.Trigger{ BlockNumber: 123, BlockHash: common.HexToHash("0xabcdef"), @@ -96,7 +98,7 @@ func TestNewUpkeepPayload(t *testing.T) { tests := []struct { name string upkeepID *big.Int - upkeepType ocr2keepers.UpkeepType + upkeepType types.UpkeepType trigger ocr2keepers.Trigger check []byte errored bool @@ -105,7 +107,7 @@ func TestNewUpkeepPayload(t *testing.T) { { name: "happy flow no extension", upkeepID: big.NewInt(111), - upkeepType: ocr2keepers.ConditionTrigger, + upkeepType: types.ConditionTrigger, trigger: ocr2keepers.Trigger{ BlockNumber: 11, BlockHash: common.HexToHash("0x11111"), @@ -116,7 +118,7 @@ func TestNewUpkeepPayload(t *testing.T) { { name: "happy flow with extension", upkeepID: big.NewInt(111), - upkeepType: ocr2keepers.LogTrigger, + upkeepType: types.LogTrigger, trigger: ocr2keepers.Trigger{ BlockNumber: 11, BlockHash: common.HexToHash("0x11111"), diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/testutil.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/testutil.go index 3c0eeb1c44e..18f4a73de05 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/testutil.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/testutil.go @@ -3,13 +3,15 @@ package core import ( "math/big" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" ) // GenUpkeepID generates an ocr2keepers.UpkeepIdentifier with a specific UpkeepType and some random string -func GenUpkeepID(uType ocr2keepers.UpkeepType, rand string) ocr2keepers.UpkeepIdentifier { +func GenUpkeepID(uType types.UpkeepType, rand string) ocr2keepers.UpkeepIdentifier { b := append([]byte{1}, common.LeftPadBytes([]byte{uint8(uType)}, 15)...) b = append(b, []byte(rand)...) b = common.RightPadBytes(b, 32-len(b)) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/trigger.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/trigger.go index 02e6946c8fb..b6ea7399736 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/trigger.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/trigger.go @@ -5,9 +5,9 @@ import ( "math/big" "strings" - "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_utils_2_1" ) @@ -33,13 +33,13 @@ func PackTrigger(id *big.Int, trig triggerWrapper) ([]byte, error) { return nil, ErrInvalidUpkeepID } switch upkeepType { - case ocr2keepers.ConditionTrigger: + case types.ConditionTrigger: trig := automation_utils_2_1.KeeperRegistryBase21ConditionalTrigger{ BlockNum: trig.BlockNum, BlockHash: trig.BlockHash, } trigger, err = utilsABI.Pack("_conditionalTrigger", &trig) - case ocr2keepers.LogTrigger: + case types.LogTrigger: logTrig := automation_utils_2_1.KeeperRegistryBase21LogTrigger{ BlockNum: trig.BlockNum, BlockHash: trig.BlockHash, @@ -70,7 +70,7 @@ func UnpackTrigger(id *big.Int, raw []byte) (triggerWrapper, error) { return triggerWrapper{}, ErrInvalidUpkeepID } switch upkeepType { - case ocr2keepers.ConditionTrigger: + case types.ConditionTrigger: unpacked, err := utilsABI.Methods["_conditionalTrigger"].Inputs.Unpack(raw) if err != nil { return triggerWrapper{}, fmt.Errorf("%w: failed to unpack conditional trigger", err) @@ -84,7 +84,7 @@ func UnpackTrigger(id *big.Int, raw []byte) (triggerWrapper, error) { } copy(triggerW.BlockHash[:], converted.BlockHash[:]) return triggerW, nil - case ocr2keepers.LogTrigger: + case types.LogTrigger: unpacked, err := utilsABI.Methods["_logTrigger"].Inputs.Unpack(raw) if err != nil { return triggerWrapper{}, fmt.Errorf("%w: failed to unpack log trigger", err) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/trigger_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/trigger_test.go index 366d59b6397..0a5d3fba4a0 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/trigger_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/trigger_test.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/stretchr/testify/assert" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" ) func TestPackUnpackTrigger(t *testing.T) { diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/type.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/type.go index 7820b47e6eb..b285db4d8aa 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/type.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/type.go @@ -3,7 +3,9 @@ package core import ( "math/big" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" ) const ( @@ -17,17 +19,17 @@ const ( // GetUpkeepType returns the upkeep type from the given ID. // it follows the same logic as the contract, but performs it locally. -func GetUpkeepType(id ocr2keepers.UpkeepIdentifier) ocr2keepers.UpkeepType { +func GetUpkeepType(id ocr2keepers.UpkeepIdentifier) types.UpkeepType { for i := upkeepTypeStartIndex; i < upkeepTypeByteIndex; i++ { if id[i] != 0 { // old id - return ocr2keepers.ConditionTrigger + return types.ConditionTrigger } } typeByte := id[upkeepTypeByteIndex] - return ocr2keepers.UpkeepType(typeByte) + return types.UpkeepType(typeByte) } -func getUpkeepTypeFromBigInt(id *big.Int) (ocr2keepers.UpkeepType, bool) { +func getUpkeepTypeFromBigInt(id *big.Int) (types.UpkeepType, bool) { uid := &ocr2keepers.UpkeepIdentifier{} ok := uid.FromBigInt(id) return GetUpkeepType(*uid), ok diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/type_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/type_test.go index 6f81ca7690e..1e4ec201b47 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/type_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core/type_test.go @@ -4,36 +4,38 @@ import ( "math/big" "testing" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/stretchr/testify/assert" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" ) func TestGetUpkeepType(t *testing.T) { tests := []struct { name string upkeepID []byte - upkeepType ocr2keepers.UpkeepType + upkeepType types.UpkeepType }{ { "zeroed id", big.NewInt(0).Bytes(), - ocr2keepers.ConditionTrigger, + types.ConditionTrigger, }, { "old id", []byte("5820911532554020907796191562093071158274499580927271776163559390280294438608"), - ocr2keepers.ConditionTrigger, + types.ConditionTrigger, }, { "condition trigger", - GenUpkeepID(ocr2keepers.ConditionTrigger, "").BigInt().Bytes(), - ocr2keepers.ConditionTrigger, + GenUpkeepID(types.ConditionTrigger, "").BigInt().Bytes(), + types.ConditionTrigger, }, { "log trigger", - GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt().Bytes(), - ocr2keepers.LogTrigger, + GenUpkeepID(types.LogTrigger, "111").BigInt().Bytes(), + types.LogTrigger, }, { "log trigger id", @@ -41,7 +43,7 @@ func TestGetUpkeepType(t *testing.T) { id, _ := big.NewInt(0).SetString("32329108151019397958065800113404894502874153543356521479058624064899121404671", 10) return id.Bytes() }(), - ocr2keepers.LogTrigger, + types.LogTrigger, }, } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/encoder.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/encoder.go index 89fcbb4a0ef..cdf2b0ea521 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/encoder.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/encoder.go @@ -4,7 +4,9 @@ import ( "fmt" "math/big" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_utils_2_1" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" @@ -65,7 +67,7 @@ func (e reportEncoder) Encode(results ...ocr2keepers.CheckResult) ([]byte, error BlockHash: result.Trigger.BlockHash, } switch core.GetUpkeepType(result.UpkeepID) { - case ocr2keepers.LogTrigger: + case types.LogTrigger: triggerW.TxHash = result.Trigger.LogTriggerExtension.TxHash triggerW.LogIndex = result.Trigger.LogTriggerExtension.Index triggerW.LogBlockHash = result.Trigger.LogTriggerExtension.BlockHash @@ -107,7 +109,7 @@ func (e reportEncoder) Extract(raw []byte) ([]ocr2keepers.ReportedUpkeep, error) triggerW.BlockHash, ) switch core.GetUpkeepType(*id) { - case ocr2keepers.LogTrigger: + case types.LogTrigger: trigger.LogTriggerExtension = &ocr2keepers.LogTriggerExtension{} trigger.LogTriggerExtension.TxHash = triggerW.TxHash trigger.LogTriggerExtension.Index = triggerW.LogIndex diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/encoder_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/encoder_test.go index aa549ab3ec8..600dc851728 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/encoder_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/encoder_test.go @@ -7,10 +7,12 @@ import ( "os" "testing" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" ) @@ -44,7 +46,7 @@ func TestReportEncoder_EncodeExtract(t *testing.T) { { "happy flow single", []ocr2keepers.CheckResult{ - newResult(1, 1, core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), 1, 1), + newResult(1, 1, core.GenUpkeepID(types.LogTrigger, "123"), 1, 1), }, 736, 1, @@ -54,9 +56,9 @@ func TestReportEncoder_EncodeExtract(t *testing.T) { { "happy flow multiple", []ocr2keepers.CheckResult{ - newResult(1, 1, core.GenUpkeepID(ocr2keepers.LogTrigger, "10"), 1, 1), - newResult(1, 1, core.GenUpkeepID(ocr2keepers.ConditionTrigger, "20"), 1, 1), - newResult(1, 1, core.GenUpkeepID(ocr2keepers.ConditionTrigger, "30"), 1, 1), + newResult(1, 1, core.GenUpkeepID(types.LogTrigger, "10"), 1, 1), + newResult(1, 1, core.GenUpkeepID(types.ConditionTrigger, "20"), 1, 1), + newResult(1, 1, core.GenUpkeepID(types.ConditionTrigger, "30"), 1, 1), }, 1312, 3, @@ -66,9 +68,9 @@ func TestReportEncoder_EncodeExtract(t *testing.T) { { "happy flow highest block number first", []ocr2keepers.CheckResult{ - newResult(1, 1, core.GenUpkeepID(ocr2keepers.ConditionTrigger, "30"), 1, 1), - newResult(1, 1, core.GenUpkeepID(ocr2keepers.ConditionTrigger, "20"), 1, 1), - newResult(1, 1, core.GenUpkeepID(ocr2keepers.LogTrigger, "10"), 1, 1), + newResult(1, 1, core.GenUpkeepID(types.ConditionTrigger, "30"), 1, 1), + newResult(1, 1, core.GenUpkeepID(types.ConditionTrigger, "20"), 1, 1), + newResult(1, 1, core.GenUpkeepID(types.LogTrigger, "10"), 1, 1), }, 1312, 1000, @@ -114,8 +116,8 @@ func TestReportEncoder_BackwardsCompatibility(t *testing.T) { packer: NewAbiPacker(), } results := []ocr2keepers.CheckResult{ - newResult(1, 2, core.GenUpkeepID(ocr2keepers.LogTrigger, "10"), 5, 6), - newResult(3, 4, core.GenUpkeepID(ocr2keepers.ConditionTrigger, "20"), 7, 8), + newResult(1, 2, core.GenUpkeepID(types.LogTrigger, "10"), 5, 6), + newResult(3, 4, core.GenUpkeepID(types.ConditionTrigger, "20"), 7, 8), } encoded, err := encoder.Encode(results...) assert.NoError(t, err) @@ -136,7 +138,7 @@ func newResult(block int64, checkBlock ocr2keepers.BlockNumber, id ocr2keepers.U BlockHash: [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}, } - if tp == ocr2keepers.LogTrigger { + if tp == types.LogTrigger { trig.LogTriggerExtension = &ocr2keepers.LogTriggerExtension{ Index: 1, TxHash: common.HexToHash("0x1234567890123456789012345678901234567890123456789012345678901234"), diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/interface.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/interface.go index 4555a5b0b9b..1f93fd3ee22 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/interface.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/interface.go @@ -1,7 +1,7 @@ package encoding import ( - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "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" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/packer.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/packer.go index 7db8b220a4d..81f4716a51b 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/packer.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/packer.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common/hexutil" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_utils_2_1" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/packer_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/packer_test.go index 3f08fcf0a2d..79221a620e1 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/packer_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding/packer_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_utils_2_1" automation21Utils "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_utils_2_1" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/buffer.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/buffer.go index f2c58fd30c1..afdb882cee5 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/buffer.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/buffer.go @@ -8,7 +8,7 @@ import ( "sync/atomic" "github.com/smartcontractkit/chainlink-automation/pkg/v3/random" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" "github.com/smartcontractkit/chainlink/v2/core/logger" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/buffer_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/buffer_test.go index 046c93a428a..c90a0f34a1b 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/buffer_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/buffer_test.go @@ -6,10 +6,12 @@ import ( "math/big" "testing" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -378,7 +380,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, maxBlockLogs: 10, maxUpkeepLogs: 2, @@ -392,7 +394,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, }, }, @@ -406,7 +408,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, }, visited: []fetchedLog{}, @@ -418,7 +420,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, maxBlockLogs: 10, maxUpkeepLogs: 2, @@ -432,7 +434,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, }, }, @@ -447,7 +449,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, }, toAdd: []appendArgs{ @@ -458,7 +460,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, maxBlockLogs: 10, maxUpkeepLogs: 2, @@ -480,7 +482,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, maxBlockLogs: 10, maxUpkeepLogs: 2, @@ -493,7 +495,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 1, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, maxBlockLogs: 10, maxUpkeepLogs: 2, @@ -506,7 +508,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 2, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, maxBlockLogs: 10, maxUpkeepLogs: 2, @@ -521,7 +523,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 1, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, { log: logpoller.Log{ @@ -529,7 +531,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 2, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, }, }, @@ -546,7 +548,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, maxBlockLogs: 2, maxUpkeepLogs: 4, @@ -559,7 +561,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 1, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, maxBlockLogs: 2, maxUpkeepLogs: 4, @@ -572,7 +574,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 2, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, maxBlockLogs: 2, maxUpkeepLogs: 4, @@ -587,7 +589,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 1, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, { log: logpoller.Log{ @@ -595,7 +597,7 @@ func TestLogEventBuffer_FetchedBlock_Append(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 2, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, }, }, @@ -676,7 +678,7 @@ func TestLogEventBuffer_FetchedBlock_Sort(t *testing.T) { TxHash: common.HexToHash("0xb711bd1103927611ee41152aa8ae27f3330"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, { log: logpoller.Log{ @@ -685,7 +687,7 @@ func TestLogEventBuffer_FetchedBlock_Sort(t *testing.T) { TxHash: common.HexToHash("0xa651bd1109922111ee411525ebae27f3fb6"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "222").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "222").BigInt(), }, { log: logpoller.Log{ @@ -694,7 +696,7 @@ func TestLogEventBuffer_FetchedBlock_Sort(t *testing.T) { TxHash: common.HexToHash("0xa651bd1109922111ee411525ebae27f3fb6"), LogIndex: 4, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, { log: logpoller.Log{ @@ -703,7 +705,7 @@ func TestLogEventBuffer_FetchedBlock_Sort(t *testing.T) { TxHash: common.HexToHash("0xa651bd1109922111ee411525ebae27f3fb6"), LogIndex: 3, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "222").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "222").BigInt(), }, { log: logpoller.Log{ @@ -712,7 +714,7 @@ func TestLogEventBuffer_FetchedBlock_Sort(t *testing.T) { TxHash: common.HexToHash("0xa651bd1109922111ee411525ebae27f3fb6"), LogIndex: 2, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, { log: logpoller.Log{ @@ -721,7 +723,7 @@ func TestLogEventBuffer_FetchedBlock_Sort(t *testing.T) { TxHash: common.HexToHash("0xa651bd1109922111ee411525ebae27f3fb6"), LogIndex: 5, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, { log: logpoller.Log{ @@ -730,7 +732,7 @@ func TestLogEventBuffer_FetchedBlock_Sort(t *testing.T) { TxHash: common.HexToHash("0xa651bd1109922111ee411525ebae27f3fb6"), LogIndex: 3, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, { log: logpoller.Log{ @@ -739,7 +741,7 @@ func TestLogEventBuffer_FetchedBlock_Sort(t *testing.T) { TxHash: common.HexToHash("0xa651bd1109922111ee411525ebae27f3fb6"), LogIndex: 1, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, }, beforeSort: []string{ @@ -801,7 +803,7 @@ func TestLogEventBuffer_FetchedBlock_Clone(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 0, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, { log: logpoller.Log{ @@ -809,7 +811,7 @@ func TestLogEventBuffer_FetchedBlock_Clone(t *testing.T) { TxHash: common.HexToHash("0x1"), LogIndex: 2, }, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt(), + upkeepID: core.GenUpkeepID(types.LogTrigger, "111").BigInt(), }, }, } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/integration_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/integration_test.go index caad1adc9ad..5ef06f1bd08 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/integration_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/integration_test.go @@ -7,6 +7,8 @@ import ( "testing" "time" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/common" @@ -18,7 +20,7 @@ import ( "go.uber.org/zap/zapcore" "golang.org/x/time/rate" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" @@ -150,7 +152,7 @@ func TestIntegration_LogEventProvider_UpdateConfig(t *testing.T) { require.Equal(t, 1, len(addrs)) t.Run("update filter config", func(t *testing.T) { - upkeepID := evmregistry21.GenUpkeepID(ocr2keepers.LogTrigger, "111") + upkeepID := evmregistry21.GenUpkeepID(types.LogTrigger, "111") id := upkeepID.BigInt() cfg := newPlainLogTriggerConfig(addrs[0]) b, err := ethClient.BlockByHash(ctx, backend.Commit()) @@ -182,7 +184,7 @@ func TestIntegration_LogEventProvider_UpdateConfig(t *testing.T) { }) t.Run("register same log filter", func(t *testing.T) { - upkeepID := evmregistry21.GenUpkeepID(ocr2keepers.LogTrigger, "222") + upkeepID := evmregistry21.GenUpkeepID(types.LogTrigger, "222") id := upkeepID.BigInt() cfg := newPlainLogTriggerConfig(addrs[0]) b, err := ethClient.BlockByHash(ctx, backend.Commit()) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider.go index 2dabcc82671..4840fa10fa1 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider.go @@ -16,7 +16,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink-common/pkg/services" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider_life_cycle_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider_life_cycle_test.go index 278c727a06a..d978940d297 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider_life_cycle_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider_life_cycle_test.go @@ -5,13 +5,13 @@ import ( "math/big" "testing" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" - "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller/mocks" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" @@ -155,7 +155,7 @@ func TestEventLogProvider_RefreshActiveUpkeeps(t *testing.T) { p := NewLogProvider(logger.TestLogger(t), mp, &mockedPacker{}, NewUpkeepFilterStore(), NewOptions(200)) require.NoError(t, p.RegisterFilter(ctx, FilterOptions{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1111").BigInt(), + UpkeepID: core.GenUpkeepID(types.LogTrigger, "1111").BigInt(), TriggerConfig: LogTriggerConfig{ ContractAddress: common.BytesToAddress(common.LeftPadBytes([]byte{1, 2, 3, 4}, 20)), Topic0: common.BytesToHash(common.LeftPadBytes([]byte{1, 2, 3, 4}, 32)), @@ -163,7 +163,7 @@ func TestEventLogProvider_RefreshActiveUpkeeps(t *testing.T) { UpdateBlock: uint64(0), })) require.NoError(t, p.RegisterFilter(ctx, FilterOptions{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "2222").BigInt(), + UpkeepID: core.GenUpkeepID(types.LogTrigger, "2222").BigInt(), TriggerConfig: LogTriggerConfig{ ContractAddress: common.BytesToAddress(common.LeftPadBytes([]byte{1, 2, 3, 4}, 20)), Topic0: common.BytesToHash(common.LeftPadBytes([]byte{1, 2, 3, 4}, 32)), @@ -175,11 +175,11 @@ func TestEventLogProvider_RefreshActiveUpkeeps(t *testing.T) { newIds, err := p.RefreshActiveUpkeeps() require.NoError(t, err) require.Len(t, newIds, 0) - mp.On("HasFilter", p.filterName(core.GenUpkeepID(ocr2keepers.LogTrigger, "2222").BigInt())).Return(true) + mp.On("HasFilter", p.filterName(core.GenUpkeepID(types.LogTrigger, "2222").BigInt())).Return(true) newIds, err = p.RefreshActiveUpkeeps( - core.GenUpkeepID(ocr2keepers.LogTrigger, "2222").BigInt(), - core.GenUpkeepID(ocr2keepers.LogTrigger, "1234").BigInt(), - core.GenUpkeepID(ocr2keepers.LogTrigger, "123").BigInt()) + core.GenUpkeepID(types.LogTrigger, "2222").BigInt(), + core.GenUpkeepID(types.LogTrigger, "1234").BigInt(), + core.GenUpkeepID(types.LogTrigger, "123").BigInt()) require.NoError(t, err) require.Len(t, newIds, 2) require.Equal(t, 1, p.filterStore.Size()) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider_test.go index 81774e26387..464b9aa3ba6 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/time/rate" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller/mocks" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/recoverer.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/recoverer.go index c7f6884426f..b28ece9843f 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/recoverer.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/recoverer.go @@ -14,10 +14,12 @@ import ( "sync/atomic" "time" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" "github.com/smartcontractkit/chainlink-automation/pkg/v3/random" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink-common/pkg/services" @@ -193,7 +195,7 @@ func (r *logRecoverer) HealthReport() map[string]error { func (r *logRecoverer) GetProposalData(ctx context.Context, proposal ocr2keepers.CoordinatedBlockProposal) ([]byte, error) { switch core.GetUpkeepType(proposal.UpkeepID) { - case ocr2keepers.LogTrigger: + case types.LogTrigger: return r.getLogTriggerCheckData(ctx, proposal) default: return []byte{}, errors.New("not a log trigger upkeep ID") diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/recoverer_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/recoverer_test.go index 65fe3c85fb8..eadd0446da8 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/recoverer_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/recoverer_test.go @@ -9,13 +9,15 @@ import ( "testing" "time" + types2 "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" @@ -50,33 +52,33 @@ func TestLogRecoverer_GetRecoverables(t *testing.T) { { "happy flow", []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "2")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "2")}, }, []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "2")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "2")}, }, false, }, { "rate limiting", []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "3", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "4", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "5", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "6", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "2")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "3", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "4", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "5", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "6", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "2")}, }, []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "3", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "4", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "5", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "2")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "3", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "4", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "5", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "2")}, }, false, }, @@ -121,9 +123,9 @@ func TestLogRecoverer_Clean(t *testing.T) { { "clean expired", []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "2")}, - {WorkID: "3", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "3")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "2")}, + {WorkID: "3", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "3")}, }, map[string]visitedRecord{ "1": visitedRecord{time.Now(), ocr2keepers.UpkeepPayload{ @@ -164,9 +166,9 @@ func TestLogRecoverer_Clean(t *testing.T) { ocr2keepers.UnknownState, }, []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "2")}, - {WorkID: "4", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "4")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "2")}, + {WorkID: "4", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "4")}, }, []string{"1", "2", "4"}, }, @@ -583,7 +585,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if a filter is not found for the upkeep ID, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), }, skipFilter: true, expectErr: true, @@ -592,7 +594,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if an error is encountered fetching the latest block, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 0, @@ -615,7 +617,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if an error is encountered fetching the tx receipt, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 0, @@ -643,7 +645,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if the tx block is nil, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 0, @@ -671,7 +673,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if a log trigger extension block number is 0, and the block number on the tx receipt is not recoverable, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 0, @@ -701,7 +703,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if a log block is not recoverable, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 200, @@ -731,7 +733,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if a log block has does not match, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 200, @@ -763,7 +765,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if a log block is recoverable, when the upkeep state reader errors, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 80, @@ -798,7 +800,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if a log block is recoverable, when the upkeep state reader returns a non recoverable state, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 80, @@ -835,7 +837,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if a log block is recoverable, when the filter address is empty, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 80, @@ -875,7 +877,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if a log block is recoverable, when the log poller returns an error fetching logs, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 80, @@ -910,7 +912,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "if a log block is recoverable, when logs cannot be found for an upkeep ID, an error is returned", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: ocr2keepers.Trigger{ LogTriggerExtension: &ocr2keepers.LogTriggerExtension{ BlockNumber: 80, @@ -949,7 +951,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "happy path with empty check data", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: func() ocr2keepers.Trigger { t := ocr2keepers.NewTrigger( ocr2keepers.BlockNumber(80), @@ -1000,7 +1002,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { { name: "happy path with check data", proposal: ocr2keepers.CoordinatedBlockProposal{ - UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "123"), Trigger: func() ocr2keepers.Trigger { t := ocr2keepers.NewTrigger( ocr2keepers.BlockNumber(80), @@ -1061,7 +1063,7 @@ func TestLogRecoverer_GetProposalData(t *testing.T) { filterStore.AddActiveUpkeeps(upkeepFilter{ addr: []byte("test"), topics: []common.Hash{common.HexToHash("0x1"), common.HexToHash("0x2"), common.HexToHash("0x3"), common.HexToHash("0x4")}, - upkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "123").BigInt(), + upkeepID: core.GenUpkeepID(types2.LogTrigger, "123").BigInt(), }) } @@ -1111,34 +1113,34 @@ func TestLogRecoverer_pending(t *testing.T) { name: "add new and existing", maxPerUpkeep: 10, exist: []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, }, new: []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "2")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "2")}, }, errored: []bool{false, false}, want: []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "2")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "2")}, }, }, { name: "exceed limits for upkeep", maxPerUpkeep: 3, exist: []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "3", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "3", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, }, new: []ocr2keepers.UpkeepPayload{ - {WorkID: "4", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, + {WorkID: "4", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, }, errored: []bool{true}, want: []ocr2keepers.UpkeepPayload{ - {WorkID: "1", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "2", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, - {WorkID: "3", UpkeepID: core.GenUpkeepID(ocr2keepers.LogTrigger, "1")}, + {WorkID: "1", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "2", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, + {WorkID: "3", UpkeepID: core.GenUpkeepID(types2.LogTrigger, "1")}, }, }, } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/mercury.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/mercury.go index d3a5167ef72..d24442b6ee9 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/mercury.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/mercury.go @@ -10,11 +10,12 @@ import ( "net/http" "time" + "github.com/smartcontractkit/chainlink-common/pkg/types" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/patrickmn/go-cache" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding" ) @@ -73,7 +74,7 @@ type MercuryData struct { } type MercuryConfigProvider interface { - Credentials() *models.MercuryCredentials + Credentials() *types.MercuryCredentials IsUpkeepAllowed(string) (interface{}, bool) SetUpkeepAllowed(string, interface{}, time.Duration) GetPluginRetry(string) (interface{}, bool) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/streams/streams.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/streams/streams.go index 27aafeca553..a0dba9c8ac3 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/streams/streams.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/streams/streams.go @@ -15,8 +15,8 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/patrickmn/go-cache" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" "github.com/smartcontractkit/chainlink-common/pkg/services" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1" "github.com/smartcontractkit/chainlink/v2/core/logger" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/streams/streams_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/streams/streams_test.go index 31b6597bb23..c7bff2eac7a 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/streams/streams_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/streams/streams_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/smartcontractkit/chainlink-common/pkg/types" + "github.com/pkg/errors" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -20,13 +22,12 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" evmClientMocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/logger" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury" v02 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/v02" @@ -37,8 +38,8 @@ type MockMercuryConfigProvider struct { mock.Mock } -func (m *MockMercuryConfigProvider) Credentials() *models.MercuryCredentials { - mc := &models.MercuryCredentials{ +func (m *MockMercuryConfigProvider) Credentials() *types.MercuryCredentials { + mc := &types.MercuryCredentials{ LegacyURL: "https://google.old.com", URL: "https://google.com", Username: "FakeClientID", diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/v02/v02_request_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/v02/v02_request_test.go index 686b2199ebc..6c07c383504 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/v02/v02_request_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/v02/v02_request_test.go @@ -11,13 +11,14 @@ import ( "testing" "time" + "github.com/smartcontractkit/chainlink-common/pkg/types" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/patrickmn/go-cache" "github.com/stretchr/testify/mock" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/logger" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury" "github.com/smartcontractkit/chainlink/v2/core/utils" @@ -41,8 +42,8 @@ func NewMockMercuryConfigProvider() *MockMercuryConfigProvider { } } -func (m *MockMercuryConfigProvider) Credentials() *models.MercuryCredentials { - mc := &models.MercuryCredentials{ +func (m *MockMercuryConfigProvider) Credentials() *types.MercuryCredentials { + mc := &types.MercuryCredentials{ LegacyURL: "https://google.old.com", URL: "https://google.com", Username: "FakeClientID", diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/v03/v03_request_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/v03/v03_request_test.go index 4a22ae477e6..a7742c04872 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/v03/v03_request_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury/v03/v03_request_test.go @@ -9,13 +9,14 @@ import ( "testing" "time" + "github.com/smartcontractkit/chainlink-common/pkg/types" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/patrickmn/go-cache" "github.com/stretchr/testify/mock" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/logger" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mercury" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mocks" @@ -40,8 +41,8 @@ func NewMockMercuryConfigProvider() *MockMercuryConfigProvider { } } -func (m *MockMercuryConfigProvider) Credentials() *models.MercuryCredentials { - mc := &models.MercuryCredentials{ +func (m *MockMercuryConfigProvider) Credentials() *types.MercuryCredentials { + mc := &types.MercuryCredentials{ LegacyURL: "https://google.old.com", URL: "https://google.com", Username: "FakeClientID", diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/payload_builder.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/payload_builder.go index 37c458ae6eb..4854f517c46 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/payload_builder.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/payload_builder.go @@ -3,7 +3,9 @@ package evm import ( "context" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" @@ -36,13 +38,13 @@ func (b *payloadBuilder) BuildPayloads(ctx context.Context, proposals ...ocr2kee var checkData []byte var err error switch core.GetUpkeepType(proposal.UpkeepID) { - case ocr2keepers.LogTrigger: + case types.LogTrigger: checkData, err = b.recoverer.GetProposalData(ctx, proposal) if err != nil { b.lggr.Warnw("failed to get log proposal data", "err", err, "upkeepID", proposal.UpkeepID, "trigger", proposal.Trigger) continue } - case ocr2keepers.ConditionTrigger: + case types.ConditionTrigger: // Empty checkData for conditionals } payload, err = core.NewUpkeepPayload(proposal.UpkeepID.BigInt(), proposal.Trigger, checkData) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/payload_builder_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/payload_builder_test.go index 7e55267f6d3..7cd63dd308a 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/payload_builder_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/payload_builder_test.go @@ -5,10 +5,12 @@ import ( "math/big" "testing" + types2 "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" - "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + types "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -33,7 +35,7 @@ func TestNewPayloadBuilder(t *testing.T) { }, proposals: []types.CoordinatedBlockProposal{ { - UpkeepID: core.GenUpkeepID(types.LogTrigger, "abc"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "abc"), WorkID: "workID1", Trigger: types.Trigger{ BlockNumber: 1, @@ -41,7 +43,7 @@ func TestNewPayloadBuilder(t *testing.T) { }, }, { - UpkeepID: core.GenUpkeepID(types.LogTrigger, "def"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "def"), WorkID: "workID2", Trigger: types.Trigger{ BlockNumber: 2, @@ -56,7 +58,7 @@ func TestNewPayloadBuilder(t *testing.T) { }, wantPayloads: []types.UpkeepPayload{ { - UpkeepID: core.GenUpkeepID(types.LogTrigger, "abc"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "abc"), WorkID: "714f83255c5b562823725748c4a75777c9b78ea8c5ba72ea819926a1fecd389e", Trigger: types.Trigger{ BlockNumber: 1, @@ -65,7 +67,7 @@ func TestNewPayloadBuilder(t *testing.T) { CheckData: []byte{1, 2, 3}, }, { - UpkeepID: core.GenUpkeepID(types.LogTrigger, "def"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "def"), WorkID: "3956daa0378d6a761fe972ee00fe98338f17fb6b7865c1d49a8a416cd85977b8", Trigger: types.Trigger{ BlockNumber: 2, @@ -79,12 +81,12 @@ func TestNewPayloadBuilder(t *testing.T) { name: "for an inactive log trigger upkeep, an empty payload is added to the list of payloads", activeList: &mockActiveUpkeepList{ IsActiveFn: func(id *big.Int) bool { - return core.GenUpkeepID(types.LogTrigger, "ghi").BigInt().Cmp(id) != 0 + return core.GenUpkeepID(types2.LogTrigger, "ghi").BigInt().Cmp(id) != 0 }, }, proposals: []types.CoordinatedBlockProposal{ { - UpkeepID: core.GenUpkeepID(types.LogTrigger, "abc"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "abc"), WorkID: "workID1", Trigger: types.Trigger{ BlockNumber: 1, @@ -92,7 +94,7 @@ func TestNewPayloadBuilder(t *testing.T) { }, }, { - UpkeepID: core.GenUpkeepID(types.LogTrigger, "def"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "def"), WorkID: "workID2", Trigger: types.Trigger{ BlockNumber: 2, @@ -100,7 +102,7 @@ func TestNewPayloadBuilder(t *testing.T) { }, }, { - UpkeepID: core.GenUpkeepID(types.LogTrigger, "ghi"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "ghi"), WorkID: "workID3", Trigger: types.Trigger{ BlockNumber: 3, @@ -115,7 +117,7 @@ func TestNewPayloadBuilder(t *testing.T) { }, wantPayloads: []types.UpkeepPayload{ { - UpkeepID: core.GenUpkeepID(types.LogTrigger, "abc"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "abc"), WorkID: "714f83255c5b562823725748c4a75777c9b78ea8c5ba72ea819926a1fecd389e", Trigger: types.Trigger{ BlockNumber: 1, @@ -124,7 +126,7 @@ func TestNewPayloadBuilder(t *testing.T) { CheckData: []byte{1, 2, 3}, }, { - UpkeepID: core.GenUpkeepID(types.LogTrigger, "def"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "def"), WorkID: "3956daa0378d6a761fe972ee00fe98338f17fb6b7865c1d49a8a416cd85977b8", Trigger: types.Trigger{ BlockNumber: 2, @@ -144,7 +146,7 @@ func TestNewPayloadBuilder(t *testing.T) { }, proposals: []types.CoordinatedBlockProposal{ { - UpkeepID: core.GenUpkeepID(types.LogTrigger, "abc"), + UpkeepID: core.GenUpkeepID(types2.LogTrigger, "abc"), WorkID: "workID1", Trigger: types.Trigger{ BlockNumber: 1, @@ -170,7 +172,7 @@ func TestNewPayloadBuilder(t *testing.T) { }, proposals: []types.CoordinatedBlockProposal{ { - UpkeepID: core.GenUpkeepID(types.ConditionTrigger, "def"), + UpkeepID: core.GenUpkeepID(types2.ConditionTrigger, "def"), WorkID: "workID1", Trigger: types.Trigger{ BlockNumber: 1, @@ -180,7 +182,7 @@ func TestNewPayloadBuilder(t *testing.T) { }, wantPayloads: []types.UpkeepPayload{ { - UpkeepID: core.GenUpkeepID(types.ConditionTrigger, "def"), + UpkeepID: core.GenUpkeepID(types2.ConditionTrigger, "def"), WorkID: "58f2f231792448679a75bac6efc2af4ba731901f0cb93a44a366525751cbabfb", Trigger: types.Trigger{ BlockNumber: 1, diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry.go index 39862bb7539..fd7bfa91d7f 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry.go @@ -9,6 +9,10 @@ import ( "sync" "time" + types2 "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + + "github.com/smartcontractkit/chainlink-common/pkg/types" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -19,7 +23,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/services" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" @@ -27,7 +31,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated" 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/models" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider" @@ -81,7 +84,7 @@ func NewEvmRegistry( addr common.Address, client legacyevm.Chain, registry *iregistry21.IKeeperRegistryMaster, - mc *models.MercuryCredentials, + mc *types.MercuryCredentials, al ActiveUpkeepList, logEventProvider logprovider.LogEventProvider, packer encoding.Packer, @@ -129,14 +132,14 @@ var upkeepStateEvents = []common.Hash{ } type MercuryConfig struct { - cred *models.MercuryCredentials + cred *types.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 pluginRetryCache *cache.Cache } -func NewMercuryConfig(credentials *models.MercuryCredentials, abi abi.ABI) *MercuryConfig { +func NewMercuryConfig(credentials *types.MercuryCredentials, abi abi.ABI) *MercuryConfig { return &MercuryConfig{ cred: credentials, Abi: abi, @@ -145,7 +148,7 @@ func NewMercuryConfig(credentials *models.MercuryCredentials, abi abi.ABI) *Merc } } -func (c *MercuryConfig) Credentials() *models.MercuryCredentials { +func (c *MercuryConfig) Credentials() *types.MercuryCredentials { return c.cred } @@ -295,7 +298,7 @@ func (r *EvmRegistry) refreshActiveUpkeeps() error { continue } switch core.GetUpkeepType(*uid) { - case ocr2keepers.LogTrigger: + case types2.LogTrigger: logTriggerIDs = append(logTriggerIDs, id) default: } @@ -517,7 +520,7 @@ func (r *EvmRegistry) removeFromActive(id *big.Int) { uid.FromBigInt(id) trigger := core.GetUpkeepType(*uid) switch trigger { - case ocr2keepers.LogTrigger: + case types2.LogTrigger: if err := r.logEventProvider.UnregisterFilter(id); err != nil { r.lggr.Warnw("failed to unregister log filter", "upkeepID", id.String()) } @@ -585,7 +588,7 @@ func (r *EvmRegistry) updateTriggerConfig(id *big.Int, cfg []byte, logBlock uint uid := &ocr2keepers.UpkeepIdentifier{} uid.FromBigInt(id) switch core.GetUpkeepType(*uid) { - case ocr2keepers.LogTrigger: + case types2.LogTrigger: if len(cfg) == 0 { fetched, err := r.fetchTriggerConfig(id) if err != nil { diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go index 33d4a7157be..6475b3ef7df 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline.go @@ -6,11 +6,13 @@ import ( "math/big" "strings" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/rpc" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding" @@ -197,7 +199,7 @@ func (r *EvmRegistry) checkUpkeeps(ctx context.Context, payloads []ocr2keepers.U uid := &ocr2keepers.UpkeepIdentifier{} uid.FromBigInt(upkeepId) switch core.GetUpkeepType(*uid) { - case ocr2keepers.LogTrigger: + case types.LogTrigger: reason, state, retryable := r.verifyLogExists(upkeepId, p) if reason != encoding.UpkeepFailureReasonNone || state != encoding.NoPipelineError { results[i] = encoding.GetIneligibleCheckResultWithoutPerformData(p, reason, state, retryable) diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline_test.go index 9867a58201b..e6b61be8d0a 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_check_pipeline_test.go @@ -8,6 +8,10 @@ import ( "sync/atomic" "testing" + types3 "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + + types2 "github.com/smartcontractkit/chainlink-common/pkg/types" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rpc" @@ -16,7 +20,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" evmClientMocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" @@ -25,7 +29,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/streams_lookup_compatible_interface" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/logger" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/mocks" @@ -376,9 +379,9 @@ func TestRegistry_VerifyLogExists(t *testing.T) { func TestRegistry_CheckUpkeeps(t *testing.T) { lggr := logger.TestLogger(t) - uid0 := core.GenUpkeepID(ocr2keepers.UpkeepType(0), "p0") - uid1 := core.GenUpkeepID(ocr2keepers.UpkeepType(1), "p1") - uid2 := core.GenUpkeepID(ocr2keepers.UpkeepType(1), "p2") + uid0 := core.GenUpkeepID(types3.UpkeepType(0), "p0") + uid1 := core.GenUpkeepID(types3.UpkeepType(1), "p1") + uid2 := core.GenUpkeepID(types3.UpkeepType(1), "p2") extension1 := &ocr2keepers.LogTriggerExtension{ TxHash: common.HexToHash("0xc8def8abdcf3a4eaaf6cc13bff3e4e2a7168d86ea41dbbf97451235aa76c3651"), @@ -536,9 +539,9 @@ func TestRegistry_CheckUpkeeps(t *testing.T) { } func TestRegistry_SimulatePerformUpkeeps(t *testing.T) { - uid0 := core.GenUpkeepID(ocr2keepers.UpkeepType(0), "p0") - uid1 := core.GenUpkeepID(ocr2keepers.UpkeepType(1), "p1") - uid2 := core.GenUpkeepID(ocr2keepers.UpkeepType(1), "p2") + uid0 := core.GenUpkeepID(types3.UpkeepType(0), "p0") + uid1 := core.GenUpkeepID(types3.UpkeepType(1), "p1") + uid2 := core.GenUpkeepID(types3.UpkeepType(1), "p2") extension1 := &ocr2keepers.LogTriggerExtension{ TxHash: common.HexToHash("0xc8def8abdcf3a4eaaf6cc13bff3e4e2a7168d86ea41dbbf97451235aa76c3651"), @@ -682,7 +685,7 @@ func setupEVMRegistry(t *testing.T) *EvmRegistry { headFunc: func(ocr2keepers.BlockKey) {}, chLog: make(chan logpoller.Log, 1000), mercury: &MercuryConfig{ - cred: &models.MercuryCredentials{ + cred: &types2.MercuryCredentials{ LegacyURL: "https://google.old.com", URL: "https://google.com", Username: "FakeClientID", diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_test.go index 0d097ceadb4..dc48c3d75f6 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/registry_test.go @@ -8,14 +8,14 @@ import ( "testing" "time" + types2 "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" coreTypes "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" - types3 "github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker/types" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller/mocks" @@ -211,7 +211,7 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { { name: "an error is returned when fetching indexed logs for IKeeperRegistryMasterUpkeepUnpaused errors", ids: []*big.Int{ - core.GenUpkeepID(types.LogTrigger, "abc").BigInt(), + core.GenUpkeepID(types2.LogTrigger, "abc").BigInt(), }, logEventProvider: &mockLogEventProvider{ RefreshActiveUpkeepsFn: func(ids ...*big.Int) ([]*big.Int, error) { @@ -234,8 +234,8 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { { name: "an error is returned when fetching indexed logs for IKeeperRegistryMasterUpkeepTriggerConfigSet errors", ids: []*big.Int{ - core.GenUpkeepID(types.LogTrigger, "abc").BigInt(), - core.GenUpkeepID(types.ConditionTrigger, "abc").BigInt(), + core.GenUpkeepID(types2.LogTrigger, "abc").BigInt(), + core.GenUpkeepID(types2.ConditionTrigger, "abc").BigInt(), big.NewInt(-1), }, logEventProvider: &mockLogEventProvider{ @@ -259,8 +259,8 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { { name: "an error is returned when parsing the logs using the registry errors", ids: []*big.Int{ - core.GenUpkeepID(types.LogTrigger, "abc").BigInt(), - core.GenUpkeepID(types.ConditionTrigger, "abc").BigInt(), + core.GenUpkeepID(types2.LogTrigger, "abc").BigInt(), + core.GenUpkeepID(types2.ConditionTrigger, "abc").BigInt(), big.NewInt(-1), }, logEventProvider: &mockLogEventProvider{ @@ -288,8 +288,8 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { { name: "an error is returned when registering the filter errors", ids: []*big.Int{ - core.GenUpkeepID(types.LogTrigger, "abc").BigInt(), - core.GenUpkeepID(types.ConditionTrigger, "abc").BigInt(), + core.GenUpkeepID(types2.LogTrigger, "abc").BigInt(), + core.GenUpkeepID(types2.ConditionTrigger, "abc").BigInt(), big.NewInt(-1), }, logEventProvider: &mockLogEventProvider{ @@ -319,11 +319,11 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { if log.BlockNumber == 1 { return &iregistry21.IKeeperRegistryMasterUpkeepTriggerConfigSet{ TriggerConfig: []byte{1, 2, 3}, - Id: core.GenUpkeepID(types.LogTrigger, "abc").BigInt(), + Id: core.GenUpkeepID(types2.LogTrigger, "abc").BigInt(), }, nil } return &iregistry21.IKeeperRegistryMasterUpkeepUnpaused{ - Id: core.GenUpkeepID(types.LogTrigger, "abc").BigInt(), + Id: core.GenUpkeepID(types2.LogTrigger, "abc").BigInt(), }, nil }, GetUpkeepTriggerConfigFn: func(opts *bind.CallOpts, upkeepId *big.Int) ([]byte, error) { @@ -341,9 +341,9 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { { name: "log trigger upkeeps are refreshed without error", ids: []*big.Int{ - core.GenUpkeepID(types.LogTrigger, "abc").BigInt(), - core.GenUpkeepID(types.LogTrigger, "def").BigInt(), - core.GenUpkeepID(types.ConditionTrigger, "abc").BigInt(), + core.GenUpkeepID(types2.LogTrigger, "abc").BigInt(), + core.GenUpkeepID(types2.LogTrigger, "def").BigInt(), + core.GenUpkeepID(types2.ConditionTrigger, "abc").BigInt(), big.NewInt(-1), }, logEventProvider: &mockLogEventProvider{ @@ -372,12 +372,12 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { ParseLogFn: func(log coreTypes.Log) (generated.AbigenLog, error) { if log.BlockNumber == 1 { return &iregistry21.IKeeperRegistryMasterUpkeepTriggerConfigSet{ - Id: core.GenUpkeepID(types.LogTrigger, "abc").BigInt(), + Id: core.GenUpkeepID(types2.LogTrigger, "abc").BigInt(), TriggerConfig: []byte{1, 2, 3}, }, nil } return &iregistry21.IKeeperRegistryMasterUpkeepUnpaused{ - Id: core.GenUpkeepID(types.LogTrigger, "def").BigInt(), + Id: core.GenUpkeepID(types2.LogTrigger, "def").BigInt(), }, nil }, GetUpkeepTriggerConfigFn: func(opts *bind.CallOpts, upkeepId *big.Int) ([]byte, error) { @@ -395,7 +395,7 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { ids: func() []*big.Int { res := []*big.Int{} for i := 0; i < logTriggerRefreshBatchSize*3; i++ { - res = append(res, core.GenUpkeepID(types.LogTrigger, fmt.Sprintf("%d", i)).BigInt()) + res = append(res, core.GenUpkeepID(types2.LogTrigger, fmt.Sprintf("%d", i)).BigInt()) } return res }(), @@ -424,12 +424,12 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { ParseLogFn: func(log coreTypes.Log) (generated.AbigenLog, error) { if log.BlockNumber == 1 { return &iregistry21.IKeeperRegistryMasterUpkeepTriggerConfigSet{ - Id: core.GenUpkeepID(types.LogTrigger, "abc").BigInt(), + Id: core.GenUpkeepID(types2.LogTrigger, "abc").BigInt(), TriggerConfig: []byte{1, 2, 3}, }, nil } return &iregistry21.IKeeperRegistryMasterUpkeepUnpaused{ - Id: core.GenUpkeepID(types.LogTrigger, "def").BigInt(), + Id: core.GenUpkeepID(types2.LogTrigger, "def").BigInt(), }, nil }, GetUpkeepTriggerConfigFn: func(opts *bind.CallOpts, upkeepId *big.Int) ([]byte, error) { @@ -447,7 +447,7 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { ids: func() []*big.Int { res := []*big.Int{} for i := 0; i < logTriggerRefreshBatchSize+3; i++ { - res = append(res, core.GenUpkeepID(types.LogTrigger, fmt.Sprintf("%d", i)).BigInt()) + res = append(res, core.GenUpkeepID(types2.LogTrigger, fmt.Sprintf("%d", i)).BigInt()) } return res }(), @@ -478,12 +478,12 @@ func TestRegistry_refreshLogTriggerUpkeeps(t *testing.T) { ParseLogFn: func(log coreTypes.Log) (generated.AbigenLog, error) { if log.BlockNumber == 1 { return &iregistry21.IKeeperRegistryMasterUpkeepTriggerConfigSet{ - Id: core.GenUpkeepID(types.LogTrigger, "abc").BigInt(), + Id: core.GenUpkeepID(types2.LogTrigger, "abc").BigInt(), TriggerConfig: []byte{1, 2, 3}, }, nil } return &iregistry21.IKeeperRegistryMasterUpkeepUnpaused{ - Id: core.GenUpkeepID(types.LogTrigger, "def").BigInt(), + Id: core.GenUpkeepID(types2.LogTrigger, "def").BigInt(), }, nil }, GetUpkeepTriggerConfigFn: func(opts *bind.CallOpts, upkeepId *big.Int) ([]byte, error) { diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/services.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/services.go index 71ccee872ff..5fe21b08724 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/services.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/services.go @@ -1,136 +1,31 @@ package evm import ( - "fmt" - - "github.com/ethereum/go-ethereum/common" - "github.com/jmoiron/sqlx" - "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" "github.com/smartcontractkit/chainlink-automation/pkg/v3/plugin" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" - - "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" - 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/models" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate" - "github.com/smartcontractkit/chainlink/v2/core/services/pg" ) type AutomationServices interface { - Registry() *EvmRegistry - Encoder() ocr2keepers.Encoder - TransmitEventProvider() *transmit.EventProvider - BlockSubscriber() *BlockSubscriber - PayloadBuilder() ocr2keepers.PayloadBuilder - UpkeepStateStore() upkeepstate.UpkeepStateStore - LogEventProvider() logprovider.LogEventProvider - LogRecoverer() logprovider.LogRecoverer - UpkeepProvider() ocr2keepers.ConditionalUpkeepProvider Keyring() ocr3types.OnchainKeyring[plugin.AutomationReportInfo] } -func New(addr common.Address, client legacyevm.Chain, mc *models.MercuryCredentials, keyring ocrtypes.OnchainKeyring, lggr logger.Logger, db *sqlx.DB, dbCfg pg.QConfig) (AutomationServices, error) { - registryContract, err := iregistry21.NewIKeeperRegistryMaster(addr, client.Client()) - if err != nil { - return nil, fmt.Errorf("%w: failed to create caller for address and backend", ErrInitializationFailure) - } - // lookback blocks for transmit event is hard coded and should provide ample time for logs - // to be detected in most cases - var transmitLookbackBlocks int64 = 250 - transmitEventProvider, err := transmit.NewTransmitEventProvider(lggr, client.LogPoller(), addr, client.Client(), transmitLookbackBlocks) - if err != nil { - return nil, err - } +func New(keyring ocrtypes.OnchainKeyring) (AutomationServices, error) { services := new(automationServices) - services.transmitEventProvider = transmitEventProvider - - packer := encoding.NewAbiPacker() - services.encoder = encoding.NewReportEncoder(packer) - - finalityDepth := client.Config().EVM().FinalityDepth() - - orm := upkeepstate.NewORM(client.ID(), db, lggr, dbCfg) - scanner := upkeepstate.NewPerformedEventsScanner(lggr, client.LogPoller(), addr, finalityDepth) - services.upkeepState = upkeepstate.NewUpkeepStateStore(orm, lggr, scanner) - - logProvider, logRecoverer := logprovider.New(lggr, client.LogPoller(), client.Client(), services.upkeepState, finalityDepth) - services.logProvider = logProvider - services.logRecoverer = logRecoverer - services.blockSub = NewBlockSubscriber(client.HeadBroadcaster(), client.LogPoller(), finalityDepth, lggr) services.keyring = NewOnchainKeyringV3Wrapper(keyring) - al := NewActiveUpkeepList() - services.payloadBuilder = NewPayloadBuilder(al, logRecoverer, lggr) - - services.reg = NewEvmRegistry(lggr, addr, client, - registryContract, mc, al, services.logProvider, - packer, services.blockSub, finalityDepth) - - services.upkeepProvider = NewUpkeepProvider(al, services.blockSub, client.LogPoller()) - return services, nil } type automationServices struct { - reg *EvmRegistry - encoder ocr2keepers.Encoder - transmitEventProvider *transmit.EventProvider - blockSub *BlockSubscriber - payloadBuilder ocr2keepers.PayloadBuilder - upkeepState upkeepstate.UpkeepStateStore - logProvider logprovider.LogEventProvider - logRecoverer logprovider.LogRecoverer - upkeepProvider *upkeepProvider - keyring *onchainKeyringV3Wrapper + keyring *onchainKeyringV3Wrapper } var _ AutomationServices = &automationServices{} -func (f *automationServices) Registry() *EvmRegistry { - return f.reg -} - -func (f *automationServices) Encoder() ocr2keepers.Encoder { - return f.encoder -} - -func (f *automationServices) TransmitEventProvider() *transmit.EventProvider { - return f.transmitEventProvider -} - -func (f *automationServices) BlockSubscriber() *BlockSubscriber { - return f.blockSub -} - -func (f *automationServices) PayloadBuilder() ocr2keepers.PayloadBuilder { - return f.payloadBuilder -} - -func (f *automationServices) UpkeepStateStore() upkeepstate.UpkeepStateStore { - return f.upkeepState -} - -func (f *automationServices) LogEventProvider() logprovider.LogEventProvider { - return f.logProvider -} - -func (f *automationServices) LogRecoverer() logprovider.LogRecoverer { - return f.logRecoverer -} - -func (f *automationServices) UpkeepProvider() ocr2keepers.ConditionalUpkeepProvider { - return f.upkeepProvider -} - func (f *automationServices) Keyring() ocr3types.OnchainKeyring[plugin.AutomationReportInfo] { return f.keyring } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/cache.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/cache.go index 2c0055482ed..814e86040b3 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/cache.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/cache.go @@ -3,7 +3,7 @@ package transmit import ( "sync" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" ) // transmitEventCache holds a ring buffer of the last visited blocks (transmit block), diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/cache_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/cache_test.go index 7f4a1296567..e7b7ca800ab 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/cache_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/cache_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" ) func TestTransmitEventCache_Sanity(t *testing.T) { diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/encoding.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/encoding.go index 17d3cd439f8..89dbb52c0e3 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/encoding.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/encoding.go @@ -4,7 +4,7 @@ import ( "fmt" "math/big" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/encoding_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/encoding_test.go index da32376aab6..97aed4706ec 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/encoding_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/encoding_test.go @@ -3,10 +3,12 @@ package transmit import ( "testing" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1" @@ -14,7 +16,7 @@ import ( ) func TestTransmitEventLog(t *testing.T) { - uid := core.GenUpkeepID(ocr2keepers.ConditionTrigger, "111") + uid := core.GenUpkeepID(types.ConditionTrigger, "111") tests := []struct { name string diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/event_provider.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/event_provider.go index f66711c2b71..eb8dc1793c1 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/event_provider.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/event_provider.go @@ -6,9 +6,11 @@ import ( "fmt" "sync" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink-common/pkg/services" @@ -20,7 +22,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/pg" ) -var _ ocr2keepers.TransmitEventProvider = &EventProvider{} +var _ types.TransmitEventProvider = &EventProvider{} type logParser func(registry *iregistry21.IKeeperRegistryMaster, log logpoller.Log) (transmitEventLog, error) @@ -189,7 +191,7 @@ func (c *EventProvider) processLogs(latestBlock int64, logs ...logpoller.Log) ([ triggerW.BlockHash, ) switch core.GetUpkeepType(*upkeepId) { - case ocr2keepers.LogTrigger: + case types.LogTrigger: trigger.LogTriggerExtension = &ocr2keepers.LogTriggerExtension{} trigger.LogTriggerExtension.TxHash = triggerW.TxHash trigger.LogTriggerExtension.Index = triggerW.LogIndex diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/event_provider_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/event_provider_test.go index 950ec810402..89a49f07807 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/event_provider_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit/event_provider_test.go @@ -5,12 +5,14 @@ import ( "runtime" "testing" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" evmClientMocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" @@ -107,7 +109,7 @@ func TestTransmitEventProvider_ProcessLogs(t *testing.T) { provider, err := NewTransmitEventProvider(logger.TestLogger(t), lp, common.HexToAddress("0x"), client, 250) require.NoError(t, err) - id := core.GenUpkeepID(ocr2keepers.LogTrigger, "1111111111111111") + id := core.GenUpkeepID(types.LogTrigger, "1111111111111111") tests := []struct { name string diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeep_provider.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeep_provider.go index b30215e4fbf..01f136aaa6b 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeep_provider.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeep_provider.go @@ -4,7 +4,8 @@ import ( "context" "fmt" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core" @@ -32,7 +33,7 @@ func (p *upkeepProvider) GetActiveUpkeeps(_ context.Context) ([]ocr2keepers.Upke return nil, fmt.Errorf("no latest block found when fetching active upkeeps") } var payloads []ocr2keepers.UpkeepPayload - for _, uid := range p.activeUpkeeps.View(ocr2keepers.ConditionTrigger) { + for _, uid := range p.activeUpkeeps.View(types.ConditionTrigger) { payload, err := core.NewUpkeepPayload( uid, ocr2keepers.NewTrigger(latestBlock.Number, latestBlock.Hash), diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeep_provider_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeep_provider_test.go index 81ea3913188..cad2d77411d 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeep_provider_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeep_provider_test.go @@ -5,9 +5,11 @@ import ( "sync/atomic" "testing" + "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + "github.com/stretchr/testify/require" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" @@ -29,7 +31,7 @@ func TestUpkeepProvider_GetActiveUpkeeps(t *testing.T) { { "empty", &mockActiveUpkeepList{ - ViewFn: func(upkeepType ...ocr2keepers.UpkeepType) []*big.Int { + ViewFn: func(upkeepType ...types.UpkeepType) []*big.Int { return []*big.Int{} }, }, @@ -40,7 +42,7 @@ func TestUpkeepProvider_GetActiveUpkeeps(t *testing.T) { { "happy flow", &mockActiveUpkeepList{ - ViewFn: func(upkeepType ...ocr2keepers.UpkeepType) []*big.Int { + ViewFn: func(upkeepType ...types.UpkeepType) []*big.Int { return []*big.Int{ big.NewInt(1), big.NewInt(2), @@ -65,7 +67,7 @@ func TestUpkeepProvider_GetActiveUpkeeps(t *testing.T) { { "latest block not found", &mockActiveUpkeepList{ - ViewFn: func(upkeepType ...ocr2keepers.UpkeepType) []*big.Int { + ViewFn: func(upkeepType ...types.UpkeepType) []*big.Int { return []*big.Int{ big.NewInt(1), big.NewInt(2), @@ -100,11 +102,11 @@ func TestUpkeepProvider_GetActiveUpkeeps(t *testing.T) { type mockActiveUpkeepList struct { ActiveUpkeepList - ViewFn func(...ocr2keepers.UpkeepType) []*big.Int + ViewFn func(...types.UpkeepType) []*big.Int IsActiveFn func(id *big.Int) bool } -func (l *mockActiveUpkeepList) View(u ...ocr2keepers.UpkeepType) []*big.Int { +func (l *mockActiveUpkeepList) View(u ...types.UpkeepType) []*big.Int { return l.ViewFn(u...) } diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate/store.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate/store.go index 19b3c46f502..9410374d7ca 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate/store.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate/store.go @@ -8,7 +8,7 @@ import ( "sync" "time" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink-common/pkg/services" diff --git a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate/store_test.go b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate/store_test.go index 7108e1b64c4..3912e2a99c6 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate/store_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate/store_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" diff --git a/core/services/ocr2/plugins/ocr2keeper/util.go b/core/services/ocr2/plugins/ocr2keeper/util.go index 199bbac0536..53fff8751c3 100644 --- a/core/services/ocr2/plugins/ocr2keeper/util.go +++ b/core/services/ocr2/plugins/ocr2keeper/util.go @@ -15,13 +15,12 @@ import ( ocr2keepers20coordinator "github.com/smartcontractkit/chainlink-automation/pkg/v2/coordinator" ocr2keepers20polling "github.com/smartcontractkit/chainlink-automation/pkg/v2/observer/polling" ocr2keepers20runner "github.com/smartcontractkit/chainlink-automation/pkg/v2/runner" - ocr2keepers21 "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" + ocr2keepers21 "github.com/smartcontractkit/chainlink-common/pkg/types/automation" "github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" evmregistry20 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v20" evmregistry21 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21" evmregistry21transmit "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit" @@ -44,9 +43,9 @@ var ( ErrNoChainFromSpec = fmt.Errorf("could not create chain from spec") ) -func EVMProvider(db *sqlx.DB, chain legacyevm.Chain, lggr logger.Logger, spec job.Job, ethKeystore keystore.Eth) (evmrelay.OCR2KeeperProvider, error) { +func EVMProvider(db *sqlx.DB, chain legacyevm.Chain, lggr logger.Logger, spec job.Job, ethKeystore keystore.Eth, dbCfg pg.QConfig) (evmrelay.OCR2KeeperProvider, error) { oSpec := spec.OCR2OracleSpec - ocr2keeperRelayer := evmrelay.NewOCR2KeeperRelayer(db, chain, lggr.Named("OCR2KeeperRelayer"), ethKeystore) + ocr2keeperRelayer := evmrelay.NewOCR2KeeperRelayer(db, chain, lggr.Named("OCR2KeeperRelayer"), ethKeystore, dbCfg) keeperProvider, err := ocr2keeperRelayer.NewOCR2KeeperProvider( types.RelayArgs{ @@ -73,6 +72,7 @@ func EVMDependencies20( lggr logger.Logger, chain legacyevm.Chain, ethKeystore keystore.Eth, + dbCfg pg.QConfig, ) (evmrelay.OCR2KeeperProvider, *evmregistry20.EvmRegistry, Encoder20, *evmregistry20.LogProvider, error) { var err error @@ -80,7 +80,7 @@ func EVMDependencies20( var registry *evmregistry20.EvmRegistry // the provider will be returned as a dependency - if keeperProvider, err = EVMProvider(db, chain, lggr, spec, ethKeystore); err != nil { + if keeperProvider, err = EVMProvider(db, chain, lggr, spec, ethKeystore, dbCfg); err != nil { return nil, nil, nil, nil, err } @@ -109,25 +109,9 @@ func FilterNamesFromSpec20(spec *job.OCR2OracleSpec) (names []string, err error) } func EVMDependencies21( - spec job.Job, - db *sqlx.DB, - lggr logger.Logger, - chain legacyevm.Chain, - mc *models.MercuryCredentials, keyring ocrtypes.OnchainKeyring, - dbCfg pg.QConfig, ) (evmregistry21.AutomationServices, error) { - var err error - - oSpec := spec.OCR2OracleSpec - - rAddr := ethkey.MustEIP55Address(oSpec.ContractID).Address() - services, err := evmregistry21.New(rAddr, chain, mc, keyring, lggr, db, dbCfg) - if err != nil { - return nil, err - } - - return services, err + return evmregistry21.New(keyring) } func FilterNamesFromSpec21(spec *job.OCR2OracleSpec) (names []string, err error) { diff --git a/core/services/relay/evm/evm.go b/core/services/relay/evm/evm.go index d6a8c584fab..633ca69ea67 100644 --- a/core/services/relay/evm/evm.go +++ b/core/services/relay/evm/evm.go @@ -498,7 +498,7 @@ func (r *Relayer) NewMedianProvider(rargs commontypes.RelayArgs, pargs commontyp func (r *Relayer) NewAutomationProvider(rargs commontypes.RelayArgs, pargs commontypes.PluginArgs) (commontypes.AutomationProvider, error) { lggr := r.lggr.Named("AutomationProvider").Named(rargs.ExternalJobID.String()) - ocr2keeperRelayer := NewOCR2KeeperRelayer(r.db, r.chain, lggr.Named("OCR2KeeperRelayer"), r.ks.Eth()) + ocr2keeperRelayer := NewOCR2KeeperRelayer(r.db, r.chain, lggr.Named("OCR2KeeperRelayer"), r.ks.Eth(), r.pgCfg) return ocr2keeperRelayer.NewOCR2KeeperProvider(rargs, pargs) } diff --git a/core/services/relay/evm/ocr2keeper.go b/core/services/relay/evm/ocr2keeper.go index 55c4d78e7b4..34daf55b835 100644 --- a/core/services/relay/evm/ocr2keeper.go +++ b/core/services/relay/evm/ocr2keeper.go @@ -6,6 +6,17 @@ import ( "fmt" "strings" + iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1" + "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey" + evm "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/encoding" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/upkeepstate" + "github.com/smartcontractkit/chainlink/v2/core/services/pg" + + "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/jmoiron/sqlx" @@ -27,8 +38,9 @@ import ( ) var ( - _ OCR2KeeperRelayer = (*ocr2keeperRelayer)(nil) - _ OCR2KeeperProvider = (*ocr2keeperProvider)(nil) + _ OCR2KeeperRelayer = (*ocr2keeperRelayer)(nil) + _ OCR2KeeperProvider = (*ocr2keeperProvider)(nil) + ErrInitializationFailure = fmt.Errorf("failed to initialize registry") ) // OCR2KeeperProviderOpts is the custom options to create a keeper provider @@ -41,6 +53,15 @@ type OCR2KeeperProviderOpts struct { // OCR2KeeperProvider provides all components needed for a OCR2Keeper plugin. type OCR2KeeperProvider interface { commontypes.Plugin + Registry() automation.Registry + Encoder() automation.Encoder + TransmitEventProvider() automation.EventProvider + BlockSubscriber() automation.BlockSubscriber + PayloadBuilder() automation.PayloadBuilder + UpkeepStateStore() automation.UpkeepStateStore + LogEventProvider() automation.LogEventProvider + LogRecoverer() automation.LogRecoverer + UpkeepProvider() automation.ConditionalUpkeepProvider } // OCR2KeeperRelayer contains the relayer and instantiating functions for OCR2Keeper providers. @@ -54,15 +75,17 @@ type ocr2keeperRelayer struct { chain legacyevm.Chain lggr logger.Logger ethKeystore keystore.Eth + dbCfg pg.QConfig } // NewOCR2KeeperRelayer is the constructor of ocr2keeperRelayer -func NewOCR2KeeperRelayer(db *sqlx.DB, chain legacyevm.Chain, lggr logger.Logger, ethKeystore keystore.Eth) OCR2KeeperRelayer { +func NewOCR2KeeperRelayer(db *sqlx.DB, chain legacyevm.Chain, lggr logger.Logger, ethKeystore keystore.Eth, dbCfg pg.QConfig) OCR2KeeperRelayer { return &ocr2keeperRelayer{ db: db, chain: chain, lggr: lggr, ethKeystore: ethKeystore, + dbCfg: dbCfg, } } @@ -78,10 +101,53 @@ func (r *ocr2keeperRelayer) NewOCR2KeeperProvider(rargs commontypes.RelayArgs, p return nil, err } - return &ocr2keeperProvider{ - configWatcher: cfgWatcher, - contractTransmitter: contractTransmitter, - }, nil + client := r.chain + + services := new(ocr2keeperProvider) + services.configWatcher = cfgWatcher + services.contractTransmitter = contractTransmitter + + addr := ethkey.MustEIP55Address(rargs.ContractID).Address() + + registryContract, err := iregistry21.NewIKeeperRegistryMaster(addr, client.Client()) + if err != nil { + return nil, fmt.Errorf("%w: failed to create caller for address and backend", ErrInitializationFailure) + } + // lookback blocks for transmit event is hard coded and should provide ample time for logs + // to be detected in most cases + var transmitLookbackBlocks int64 = 250 + transmitEventProvider, err := transmit.NewTransmitEventProvider(r.lggr, client.LogPoller(), addr, client.Client(), transmitLookbackBlocks) + if err != nil { + return nil, err + } + + services.transmitEventProvider = transmitEventProvider + + packer := encoding.NewAbiPacker() + services.encoder = encoding.NewReportEncoder(packer) + + finalityDepth := client.Config().EVM().FinalityDepth() + + orm := upkeepstate.NewORM(client.ID(), r.db, r.lggr, r.dbCfg) + scanner := upkeepstate.NewPerformedEventsScanner(r.lggr, client.LogPoller(), addr, finalityDepth) + services.upkeepStateStore = upkeepstate.NewUpkeepStateStore(orm, r.lggr, scanner) + + logProvider, logRecoverer := logprovider.New(r.lggr, client.LogPoller(), client.Client(), services.upkeepStateStore, finalityDepth) + services.logEventProvider = logProvider + services.logRecoverer = logRecoverer + blockSubscriber := evm.NewBlockSubscriber(client.HeadBroadcaster(), client.LogPoller(), finalityDepth, r.lggr) + services.blockSubscriber = blockSubscriber + + al := evm.NewActiveUpkeepList() + services.payloadBuilder = evm.NewPayloadBuilder(al, logRecoverer, r.lggr) + + services.registry = evm.NewEvmRegistry(r.lggr, addr, client, + registryContract, rargs.MercuryCredentials, al, logProvider, + packer, blockSubscriber, finalityDepth) + + services.conditionalUpkeepProvider = evm.NewUpkeepProvider(al, blockSubscriber, client.LogPoller()) + + return services, nil } type ocr3keeperProviderContractTransmitter struct { @@ -120,7 +186,16 @@ func (t *ocr3keeperProviderContractTransmitter) FromAccount() (ocrtypes.Account, type ocr2keeperProvider struct { *configWatcher - contractTransmitter ContractTransmitter + contractTransmitter ContractTransmitter + registry automation.Registry + encoder automation.Encoder + transmitEventProvider automation.EventProvider + blockSubscriber automation.BlockSubscriber + payloadBuilder automation.PayloadBuilder + upkeepStateStore automation.UpkeepStateStore + logEventProvider automation.LogEventProvider + logRecoverer automation.LogRecoverer + conditionalUpkeepProvider automation.ConditionalUpkeepProvider } func (c *ocr2keeperProvider) ContractTransmitter() ocrtypes.ContractTransmitter { @@ -175,3 +250,39 @@ func newOCR2KeeperConfigProvider(lggr logger.Logger, chain legacyevm.Chain, rarg rargs.New, ), nil } + +func (c *ocr2keeperProvider) Registry() automation.Registry { + return c.registry +} + +func (c *ocr2keeperProvider) Encoder() automation.Encoder { + return c.encoder +} + +func (c *ocr2keeperProvider) TransmitEventProvider() automation.EventProvider { + return c.transmitEventProvider +} + +func (c *ocr2keeperProvider) BlockSubscriber() automation.BlockSubscriber { + return c.blockSubscriber +} + +func (c *ocr2keeperProvider) PayloadBuilder() automation.PayloadBuilder { + return c.payloadBuilder +} + +func (c *ocr2keeperProvider) UpkeepStateStore() automation.UpkeepStateStore { + return c.upkeepStateStore +} + +func (c *ocr2keeperProvider) LogEventProvider() automation.LogEventProvider { + return c.logEventProvider +} + +func (c *ocr2keeperProvider) LogRecoverer() automation.LogRecoverer { + return c.logRecoverer +} + +func (c *ocr2keeperProvider) UpkeepProvider() automation.ConditionalUpkeepProvider { + return c.conditionalUpkeepProvider +} diff --git a/go.md b/go.md index 090221a89fd..2a893c2a55e 100644 --- a/go.md +++ b/go.md @@ -46,6 +46,7 @@ flowchart LR click tdh2/go/tdh2 href "https://github.com/smartcontractkit/tdh2" chainlink/v2 --> wsrpc click wsrpc href "https://github.com/smartcontractkit/wsrpc" + chainlink-automation --> chainlink-common chainlink-automation --> libocr chainlink-common --> libocr chainlink-cosmos --> chainlink-common diff --git a/go.mod b/go.mod index fd1ffe4760a..2d27bc575fb 100644 --- a/go.mod +++ b/go.mod @@ -64,8 +64,8 @@ require ( github.com/shirou/gopsutil/v3 v3.23.11 github.com/shopspring/decimal v1.3.1 github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 - github.com/smartcontractkit/chainlink-automation v1.0.1 - github.com/smartcontractkit/chainlink-common v0.1.7-0.20240108182329-237f56daad6b + github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20240118012339-4864e2306bb1 github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5 github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 github.com/smartcontractkit/chainlink-feeds v0.0.0-20231127231053-2232d3a6766d diff --git a/go.sum b/go.sum index 0e2b917f251..6db671e7dec 100644 --- a/go.sum +++ b/go.sum @@ -1148,10 +1148,10 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumvbfM1u/etVq42Afwq/jtNSBSOA8n5jntnNPo= github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= -github.com/smartcontractkit/chainlink-automation v1.0.1 h1:vVjBFq2Zsz21kPy1Pb0wpjF9zrbJX+zjXphDeeR4XZk= -github.com/smartcontractkit/chainlink-automation v1.0.1/go.mod h1:INSchkV3ntyDdlZKGWA030MPDpp6pbeuiRkRKYFCm2k= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240108182329-237f56daad6b h1:PRuvHgPka1gIGPKASuJHvqUvYWhZO7z5B/kKapjkZaM= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240108182329-237f56daad6b/go.mod h1:f+0ei9N4PlTJHu7pbGzEjTnBUr45syPdGFu5+31lS5Q= +github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429 h1:xkejUBZhcBpBrTSfxc91Iwzadrb6SXw8ks69bHIQ9Ww= +github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429/go.mod h1:wJmVvDf4XSjsahWtfUq3wvIAYEAuhr7oxmxYnEL/LGQ= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240118012339-4864e2306bb1 h1:3cWO2/lFVDul5SVTgl4/RX/GXcT8Zq5NGMPeNEz09tY= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240118012339-4864e2306bb1/go.mod h1:f+0ei9N4PlTJHu7pbGzEjTnBUr45syPdGFu5+31lS5Q= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5 h1:kBnmjv3fxU7krVIqZFvo1m4F6qBc4vPURQFX/mcChhI= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5/go.mod h1:EoM7wQ81mov7wsUzG4zEnnr0EH0POEo/I0hRDg433TU= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 h1:xYqRgZO0nMSO8CBCMR0r3WA+LZ4kNL8a6bnbyk/oBtQ= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index d6f1fa94c6d..9df6d54bd23 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -24,8 +24,8 @@ require ( github.com/scylladb/go-reflectx v1.0.1 github.com/segmentio/ksuid v1.0.4 github.com/slack-go/slack v0.12.2 - github.com/smartcontractkit/chainlink-automation v1.0.1 - github.com/smartcontractkit/chainlink-common v0.1.7-0.20240108182329-237f56daad6b + github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20240118012339-4864e2306bb1 github.com/smartcontractkit/chainlink-testing-framework v1.22.4 github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868 github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index f4129568536..98351519d13 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1481,10 +1481,10 @@ github.com/slack-go/slack v0.12.2 h1:x3OppyMyGIbbiyFhsBmpf9pwkUzMhthJMRNmNlA4LaQ github.com/slack-go/slack v0.12.2/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw= github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumvbfM1u/etVq42Afwq/jtNSBSOA8n5jntnNPo= github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= -github.com/smartcontractkit/chainlink-automation v1.0.1 h1:vVjBFq2Zsz21kPy1Pb0wpjF9zrbJX+zjXphDeeR4XZk= -github.com/smartcontractkit/chainlink-automation v1.0.1/go.mod h1:INSchkV3ntyDdlZKGWA030MPDpp6pbeuiRkRKYFCm2k= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240108182329-237f56daad6b h1:PRuvHgPka1gIGPKASuJHvqUvYWhZO7z5B/kKapjkZaM= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240108182329-237f56daad6b/go.mod h1:f+0ei9N4PlTJHu7pbGzEjTnBUr45syPdGFu5+31lS5Q= +github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429 h1:xkejUBZhcBpBrTSfxc91Iwzadrb6SXw8ks69bHIQ9Ww= +github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429/go.mod h1:wJmVvDf4XSjsahWtfUq3wvIAYEAuhr7oxmxYnEL/LGQ= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240118012339-4864e2306bb1 h1:3cWO2/lFVDul5SVTgl4/RX/GXcT8Zq5NGMPeNEz09tY= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240118012339-4864e2306bb1/go.mod h1:f+0ei9N4PlTJHu7pbGzEjTnBUr45syPdGFu5+31lS5Q= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5 h1:kBnmjv3fxU7krVIqZFvo1m4F6qBc4vPURQFX/mcChhI= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5/go.mod h1:EoM7wQ81mov7wsUzG4zEnnr0EH0POEo/I0hRDg433TU= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 h1:xYqRgZO0nMSO8CBCMR0r3WA+LZ4kNL8a6bnbyk/oBtQ=