Skip to content

Commit

Permalink
plugins/cmd/chainlink-example-relay: add example relay
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Dec 17, 2024
1 parent 8555745 commit db87711
Show file tree
Hide file tree
Showing 38 changed files with 158 additions and 456 deletions.
2 changes: 1 addition & 1 deletion core/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (n ChainlinkAppFactory) NewApplication(ctx context.Context, cfg chainlink.G

mailMon := mailbox.NewMonitor(cfg.AppID().String(), appLggr.Named("Mailbox"))

loopRegistry := plugins.NewLoopRegistry(appLggr, cfg.Tracing(), cfg.Telemetry(), beholderAuthHeaders, csaPubKeyHex)
loopRegistry := plugins.NewLoopRegistry(appLggr, cfg.Database(), cfg.Tracing(), cfg.Telemetry(), beholderAuthHeaders, csaPubKeyHex)

mercuryPool := wsrpc.NewPool(appLggr, cache.Config{
LatestReportTTL: cfg.Mercury().Cache().LatestReportTTL(),
Expand Down
10 changes: 5 additions & 5 deletions core/cmd/shell_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ func (s *Shell) PrepareTestDatabase(c *cli.Context) error {

// Creating pristine DB copy to speed up FullTestDB
dbUrl := cfg.Database().URL()
db, err := sqlx.Open(string(pgcommon.Postgres), dbUrl.String())
db, err := sqlx.Open(pgcommon.DriverPostgres, dbUrl.String())
if err != nil {
return s.errorOut(err)
}
Expand Down Expand Up @@ -1089,23 +1089,23 @@ type dbConfig interface {
MaxOpenConns() int
MaxIdleConns() int
URL() url.URL
Dialect() pgcommon.DialectName
DriverName() string
}

func newConnection(ctx context.Context, cfg dbConfig) (*sqlx.DB, error) {
parsed := cfg.URL()
if parsed.String() == "" {
return nil, errDBURLMissing
}
return pg.NewConnection(ctx, parsed.String(), cfg.Dialect(), cfg)
return pg.NewConnection(ctx, parsed.String(), cfg.DriverName(), cfg)
}

func dropAndCreateDB(parsed url.URL, force bool) (err error) {
// Cannot drop the database if we are connected to it, so we must connect
// to a different one. template1 should be present on all postgres installations
dbname := parsed.Path[1:]
parsed.Path = "/template1"
db, err := sql.Open(string(pgcommon.Postgres), parsed.String())
db, err := sql.Open(pgcommon.DriverPostgres, parsed.String())
if err != nil {
return fmt.Errorf("unable to open postgres database for creating test db: %+v", err)
}
Expand Down Expand Up @@ -1204,7 +1204,7 @@ func checkSchema(dbURL url.URL, prevSchema string) error {
}

func insertFixtures(dbURL url.URL, pathToFixtures string) (err error) {
db, err := sql.Open(string(pgcommon.Postgres), dbURL.String())
db, err := sql.Open(pgcommon.DriverPostgres, dbURL.String())
if err != nil {
return fmt.Errorf("unable to open postgres database for creating test db: %+v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions core/cmd/shell_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
func genTestEVMRelayers(t *testing.T, opts legacyevm.ChainRelayOpts, ks evmrelayer.CSAETHKeystore) *chainlink.CoreRelayerChainInteroperators {
f := chainlink.RelayerFactory{
Logger: opts.Logger,
LoopRegistry: plugins.NewLoopRegistry(opts.Logger, opts.AppConfig.Tracing(), opts.AppConfig.Telemetry(), nil, ""),
LoopRegistry: plugins.NewLoopRegistry(opts.Logger, opts.AppConfig.Database(), opts.AppConfig.Tracing(), opts.AppConfig.Telemetry(), nil, ""),
CapabilitiesRegistry: capabilities.NewRegistry(opts.Logger),
}

Expand Down Expand Up @@ -283,7 +283,7 @@ func TestShell_RebroadcastTransactions_Txm(t *testing.T) {
// test multiple connections to the database, and changes made within
// the transaction cannot be seen from another connection.
config, sqlxDB := heavyweight.FullTestDBV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Database.Dialect = pgcommon.Postgres
c.Database.DriverName = pgcommon.DriverPostgres
// evm config is used in this test. but if set, it must be pass config validation.
// simplest to make it nil
c.EVM = nil
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestShell_RebroadcastTransactions_OutsideRange_Txm(t *testing.T) {
// test multiple connections to the database, and changes made within
// the transaction cannot be seen from another connection.
config, sqlxDB := heavyweight.FullTestDBV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Database.Dialect = pgcommon.Postgres
c.Database.DriverName = pgcommon.DriverPostgres
// evm config is used in this test. but if set, it must be pass config validation.
// simplest to make it nil
c.EVM = nil
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestShell_RebroadcastTransactions_AddressCheck(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
config, sqlxDB := heavyweight.FullTestDBV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Database.Dialect = pgcommon.Postgres
c.Database.DriverName = pgcommon.DriverPostgres

c.EVM = nil
// seems to be needed for config validate
Expand Down Expand Up @@ -499,7 +499,7 @@ func TestShell_RebroadcastTransactions_AddressCheck(t *testing.T) {
func TestShell_CleanupChainTables(t *testing.T) {
// Just check if it doesn't error, command itself shouldn't be changed unless major schema changes were made.
// It would be really hard to write a test that accounts for schema changes, so this should be enough to alarm us that something broke.
config, _ := heavyweight.FullTestDBV2(t, func(c *chainlink.Config, s *chainlink.Secrets) { c.Database.Dialect = pgcommon.Postgres })
config, _ := heavyweight.FullTestDBV2(t, func(c *chainlink.Config, s *chainlink.Secrets) { c.Database.DriverName = pgcommon.DriverPostgres })
client := cmd.Shell{
Config: config,
Logger: logger.TestLogger(t),
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func TestNewUserCache(t *testing.T) {

func TestSetupSolanaRelayer(t *testing.T) {
lggr := logger.TestLogger(t)
reg := plugins.NewLoopRegistry(lggr, nil, nil, nil, "")
reg := plugins.NewTestLoopRegistry(lggr)
ks := mocks.NewSolana(t)
ds := sqltest.NewNoOpDataSource()

Expand Down Expand Up @@ -483,7 +483,7 @@ func TestSetupSolanaRelayer(t *testing.T) {

func TestSetupStarkNetRelayer(t *testing.T) {
lggr := logger.TestLogger(t)
reg := plugins.NewLoopRegistry(lggr, nil, nil, nil, "")
reg := plugins.NewTestLoopRegistry(lggr)
ks := mocks.NewStarkNet(t)
// config 3 chains but only enable 2 => should only be 2 relayer
nEnabledChains := 2
Expand Down
4 changes: 1 addition & 3 deletions core/config/database_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package config
import (
"net/url"
"time"

pgcommon "github.com/smartcontractkit/chainlink-common/pkg/sqlutil/pg"
)

type Backup interface {
Expand Down Expand Up @@ -35,7 +33,7 @@ type Database interface {
DefaultIdleInTxSessionTimeout() time.Duration
DefaultLockTimeout() time.Duration
DefaultQueryTimeout() time.Duration
Dialect() pgcommon.DialectName
DriverName() string
LogSQL() bool
MaxIdleConns() int
MaxOpenConns() int
Expand Down
2 changes: 1 addition & 1 deletion core/config/docs/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {

func CoreDefaults() (c toml.Core) {
c.SetFrom(&defaults)
c.Database.Dialect = pgcommon.Postgres // not user visible - overridden for tests only
c.Database.DriverName = pgcommon.DriverPostgres // not user visible - overridden for tests only
c.Tracing.Attributes = make(map[string]string)
return
}
4 changes: 1 addition & 3 deletions core/config/toml/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
ocrcommontypes "github.com/smartcontractkit/libocr/commontypes"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
pgcommon "github.com/smartcontractkit/chainlink-common/pkg/sqlutil/pg"

"github.com/smartcontractkit/chainlink/v2/core/build"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/config"
Expand Down Expand Up @@ -338,7 +336,7 @@ type Database struct {
DefaultIdleInTxSessionTimeout *commonconfig.Duration
DefaultLockTimeout *commonconfig.Duration
DefaultQueryTimeout *commonconfig.Duration
Dialect pgcommon.DialectName `toml:"-"`
DriverName string `toml:"-"`
LogQueries *bool
MaxIdleConns *int64
MaxOpenConns *int64
Expand Down
6 changes: 3 additions & 3 deletions core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func NewApplicationWithConfig(t testing.TB, cfg chainlink.GeneralConfig, flagsAn
}

url := cfg.Database().URL()
db, err := pg.NewConnection(ctx, url.String(), cfg.Database().Dialect(), cfg.Database())
db, err := pg.NewConnection(ctx, url.String(), cfg.Database().DriverName(), cfg.Database())
require.NoError(t, err)
t.Cleanup(func() { assert.NoError(t, db.Close()) })

Expand Down Expand Up @@ -394,7 +394,7 @@ func NewApplicationWithConfig(t testing.TB, cfg chainlink.GeneralConfig, flagsAn
keyStore := keystore.NewInMemory(ds, utils.FastScryptParams, lggr)

mailMon := mailbox.NewMonitor(cfg.AppID().String(), lggr.Named("Mailbox"))
loopRegistry := plugins.NewLoopRegistry(lggr, nil, nil, nil, "")
loopRegistry := plugins.NewTestLoopRegistry(lggr)

mercuryPool := wsrpc.NewPool(lggr, cache.Config{
LatestReportTTL: cfg.Mercury().Cache().LatestReportTTL(),
Expand Down Expand Up @@ -489,7 +489,7 @@ func NewApplicationWithConfig(t testing.TB, cfg chainlink.GeneralConfig, flagsAn
RestrictedHTTPClient: c,
UnrestrictedHTTPClient: c,
SecretGenerator: MockSecretGenerator{},
LoopRegistry: plugins.NewLoopRegistry(lggr, nil, nil, nil, ""),
LoopRegistry: plugins.NewTestLoopRegistry(lggr),
MercuryPool: mercuryPool,
CapabilitiesRegistry: capabilitiesRegistry,
CapabilitiesDispatcher: dispatcher,
Expand Down
2 changes: 1 addition & 1 deletion core/internal/testutils/configtest/general_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func overrides(c *chainlink.Config, s *chainlink.Secrets) {
c.InsecureFastScrypt = ptr(true)
c.ShutdownGracePeriod = commonconfig.MustNewDuration(testutils.DefaultWaitTimeout)

c.Database.Dialect = pgcommon.TransactionWrappedPostgres
c.Database.DriverName = pgcommon.DriverTxWrappedPostgres
c.Database.Lock.Enabled = ptr(false)
c.Database.MaxIdleConns = ptr[int64](20)
c.Database.MaxOpenConns = ptr[int64](20)
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/prometheus/client_golang v1.20.5
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chainlink-automation v0.8.1
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241214155818-b403079b2805
github.com/smartcontractkit/chainlink-common v0.4.1-0.20241217144508-28130f7e9584

Check failure on line 36 in core/scripts/go.mod

View workflow job for this annotation

GitHub Actions / Validate go.mod dependencies

[./core/scripts/go.mod] dependency github.com/smartcontractkit/[email protected] not on default branch (main). Version(commit): 28130f7e9584 Tree: https://github.com/smartcontractkit/chainlink-common/tree/28130f7e9584 Commit: https://github.com/smartcontractkit/chainlink-common/commit/28130f7e9584
github.com/smartcontractkit/libocr v0.0.0-20241007185508-adbe57025f12
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
Expand Down Expand Up @@ -68,7 +68,7 @@ require (
github.com/NethermindEth/juno v0.3.1 // indirect
github.com/NethermindEth/starknet.go v0.7.1-0.20240401080518-34a506f3cfdb // indirect
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/XSAM/otelsql v0.27.0 // indirect
github.com/XSAM/otelsql v0.29.0 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/atombender/go-jsonschema v0.16.1-0.20240916205339-a74cd4e2851c // indirect
Expand Down
8 changes: 4 additions & 4 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjC
github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI=
github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/XSAM/otelsql v0.27.0 h1:i9xtxtdcqXV768a5C6SoT/RkG+ue3JTOgkYInzlTOqs=
github.com/XSAM/otelsql v0.27.0/go.mod h1:0mFB3TvLa7NCuhm/2nU7/b2wEtsczkj8Rey8ygO7V+A=
github.com/XSAM/otelsql v0.29.0 h1:pEw9YXXs8ZrGRYfDc0cmArIz9lci5b42gmP5+tA1Huc=
github.com/XSAM/otelsql v0.29.0/go.mod h1:d3/0xGIGC5RVEE+Ld7KotwaLy6zDeaF3fLJHOPpdN2w=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -1150,8 +1150,8 @@ github.com/smartcontractkit/chainlink-automation v0.8.1 h1:sTc9LKpBvcKPc1JDYAmgB
github.com/smartcontractkit/chainlink-automation v0.8.1/go.mod h1:Iij36PvWZ6blrdC5A/nrQUBuf3MH3JvsBB9sSyc9W08=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241213122413-5e8f65dd6b1b h1:iSQJ6ng4FhEswf8SXunGkaJlVP3E3JlgLB8Oo2f3Ud4=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241213122413-5e8f65dd6b1b/go.mod h1:F8xQAIW0ymb2BZhqn89sWZLXreJhM5KDVF6Qb4y44N0=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241214155818-b403079b2805 h1:Pz8jB/6qe10xT10h2S3LFYJrnebNpG5rJ/w16HZGwPQ=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241214155818-b403079b2805/go.mod h1:yti7e1+G9hhkYhj+L5sVUULn9Bn3bBL5/AxaNqdJ5YQ=
github.com/smartcontractkit/chainlink-common v0.4.1-0.20241217144508-28130f7e9584 h1:tGINh0h0tqLRb20JhpruqHpJYSwHbKpcLetJN9HsnzM=
github.com/smartcontractkit/chainlink-common v0.4.1-0.20241217144508-28130f7e9584/go.mod h1:V3BHfvLnQNBUoZ4bGjD29ZPhyzPE++DkYkhvPb9tcRs=
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241202195413-82468150ac1e h1:PRoeby6ZlTuTkv2f+7tVU4+zboTfRzI+beECynF4JQ0=
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241202195413-82468150ac1e/go.mod h1:mUh5/woemsVaHgTorA080hrYmO3syBCmPdnWc/5dOqk=
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241216163550-fa030d178ba3 h1:aeiBdBHGY8QNftps+VqrIk6OnfeeOD5z4jrAabW4ZSc=
Expand Down
2 changes: 1 addition & 1 deletion core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
if err != nil {
return nil, fmt.Errorf("could not build Beholder auth: %w", err)
}
loopRegistry = plugins.NewLoopRegistry(globalLogger, opts.Config.Tracing(), opts.Config.Telemetry(), beholderAuthHeaders, csaPubKeyHex)
loopRegistry = plugins.NewLoopRegistry(globalLogger, opts.Config.Database(), opts.Config.Tracing(), opts.Config.Telemetry(), beholderAuthHeaders, csaPubKeyHex)
}

// If the audit logger is enabled
Expand Down
6 changes: 2 additions & 4 deletions core/services/chainlink/config_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"net/url"
"time"

pgcommon "github.com/smartcontractkit/chainlink-common/pkg/sqlutil/pg"

"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/config/toml"
)
Expand Down Expand Up @@ -110,8 +108,8 @@ func (d *databaseConfig) URL() url.URL {
return *d.s.URL.URL()
}

func (d *databaseConfig) Dialect() pgcommon.DialectName {
return d.c.Dialect
func (d *databaseConfig) DriverName() string {
return d.c.DriverName
}

func (d *databaseConfig) MigrateDatabase() bool {
Expand Down
2 changes: 1 addition & 1 deletion core/services/chainlink/config_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ URL = "postgresql://doesnotexist:justtopassvalidationtests@localhost:5432/chainl
assert.Equal(t, 7, db.MaxIdleConns())
assert.Equal(t, 13, db.MaxOpenConns())
assert.True(t, db.MigrateDatabase())
assert.Equal(t, pgcommon.Postgres, db.Dialect())
assert.Equal(t, pgcommon.DriverPostgres, db.DriverName())
url := db.URL()
assert.NotEqual(t, url.String(), "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {

factory := chainlink.RelayerFactory{
Logger: lggr,
LoopRegistry: plugins.NewLoopRegistry(lggr, nil, nil, nil, ""),
LoopRegistry: plugins.NewTestLoopRegistry(lggr),
GRPCOpts: loop.GRPCOpts{},
CapabilitiesRegistry: capabilities.NewRegistry(lggr),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func setupNodeCCIP(
beholderAuthHeaders, csaPubKeyHex, err := keystore.BuildBeholderAuth(keyStore)
require.NoError(t, err)

loopRegistry := plugins.NewLoopRegistry(lggr.Named("LoopRegistry"), config.Tracing(), config.Telemetry(), beholderAuthHeaders, csaPubKeyHex)
loopRegistry := plugins.NewLoopRegistry(lggr.Named("LoopRegistry"), config.Database(), config.Tracing(), config.Telemetry(), beholderAuthHeaders, csaPubKeyHex)
relayerFactory := chainlink.RelayerFactory{
Logger: lggr,
LoopRegistry: loopRegistry,
Expand Down Expand Up @@ -493,7 +493,7 @@ func setupNodeCCIP(
RestrictedHTTPClient: &http.Client{},
AuditLogger: audit.NoopLogger,
MailMon: mailMon,
LoopRegistry: plugins.NewLoopRegistry(lggr, config.Tracing(), config.Telemetry(), beholderAuthHeaders, csaPubKeyHex),
LoopRegistry: plugins.NewLoopRegistry(lggr, config.Database(), config.Tracing(), config.Telemetry(), beholderAuthHeaders, csaPubKeyHex),
})
require.NoError(t, err)
require.NoError(t, app.GetKeyStore().Unlock(ctx, "password"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestAdapter_Integration(t *testing.T) {
logger := logger.TestLogger(t)
cfg := configtest.NewTestGeneralConfig(t)
url := cfg.Database().URL()
db, err := pg.NewConnection(ctx, url.String(), cfg.Database().Dialect(), cfg.Database())
db, err := pg.NewConnection(ctx, url.String(), cfg.Database().DriverName(), cfg.Database())
require.NoError(t, err)

keystore := keystore.NewInMemory(db, utils.FastScryptParams, logger)
Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr2/plugins/mercury/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func TestNewServices(t *testing.T) {

t.Run("restartable loop", func(t *testing.T) {
// setup a real loop registry to test restartability
registry := plugins.NewLoopRegistry(logger.TestLogger(t), nil, nil, nil, "")
registry := plugins.NewTestLoopRegistry(logger.TestLogger(t))
loopRegistrarConfig := plugins.NewRegistrarConfig(loop.GRPCOpts{}, registry.Register, registry.Unregister)
prodCfg := mercuryocr2.NewMercuryConfig(1, 1, loopRegistrarConfig)
type args struct {
Expand Down
Loading

0 comments on commit db87711

Please sign in to comment.