Skip to content

Commit

Permalink
BCF-3168: changes required to integrate with the RelayerSet from chai… (
Browse files Browse the repository at this point in the history
#13000)

* BCF-3168: changes required to integrate with the RelayerSet from chainlink common

* lint

* lint

* goimports
  • Loading branch information
ettec committed Apr 29, 2024
1 parent c977815 commit 1b99404
Show file tree
Hide file tree
Showing 24 changed files with 318 additions and 356 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-socks-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#internal changes to core required by change BCF3168 in common to add relayer set
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/prometheus/client_golang v1.17.0
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/chainlink-automation v1.0.3
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240424132620-add4946c1c73
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240429120925-907b29311feb
github.com/smartcontractkit/chainlink-vrf v0.0.0-20240222010609-cd67d123c772
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.3 h1:h/ijT0NiyV06VxYVgcNfsE3+8OEzT3Q0Z9au0z1BPWs=
github.com/smartcontractkit/chainlink-automation v1.0.3/go.mod h1:RjboV0Qd7YP+To+OrzHGXaxUxoSONveCoAK2TQ1INLU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240424132620-add4946c1c73 h1:54hM3/SrOM166it2K35hGb5K7gQ49/Op0aHp9WkqpqU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240424132620-add4946c1c73/go.mod h1:GTDBbovHUSAUk+fuGIySF2A/whhdtHGaWmU61BoERks=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240429120925-907b29311feb h1:nJ9dkgvX5vdpFWhYufnRUAiNvNHsXkoBL6C0bDerq/k=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240429120925-907b29311feb/go.mod h1:GTDBbovHUSAUk+fuGIySF2A/whhdtHGaWmU61BoERks=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240419213354-ea34a948e2ee h1:eFuBKyEbL2b+eyfgV/Eu9+8HuCEev+IcBi+K9l1dG7g=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240419213354-ea34a948e2ee/go.mod h1:uATrrJ8IsuBkOBJ46USuf73gz9gZy5k5bzGE5/ji/rc=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand Down
4 changes: 4 additions & 0 deletions core/services/chainlink/mocks/relayer_chain_interoperators.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (f *FakeRelayerChainInteroperators) Get(id types.RelayID) (loop.Relayer, er
panic("unimplemented")
}

func (f *FakeRelayerChainInteroperators) GetIDToRelayerMap() (map[types.RelayID]loop.Relayer, error) {
panic("unimplemented")
}

func (f *FakeRelayerChainInteroperators) Slice() []loop.Relayer {
return f.Relayers
}
Expand Down
13 changes: 12 additions & 1 deletion core/services/chainlink/relayer_chain_interoperators.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"

"github.com/smartcontractkit/chainlink-common/pkg/loop"
relay "github.com/smartcontractkit/chainlink-common/pkg/loop/adapters/relay"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos"
"github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/adapters"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm"
"github.com/smartcontractkit/chainlink/v2/core/services"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
)

var ErrNoSuchRelayer = errors.New("relayer does not exist")
Expand Down Expand Up @@ -183,6 +183,17 @@ func (rs *CoreRelayerChainInteroperators) Get(id types.RelayID) (loop.Relayer, e
return lr, nil
}

func (rs *CoreRelayerChainInteroperators) GetIDToRelayerMap() (map[types.RelayID]loop.Relayer, error) {
rs.mu.Lock()
defer rs.mu.Unlock()
result := make(map[types.RelayID]loop.Relayer)
for id, relayer := range rs.loopRelayers {
result[id] = relayer
}

return result, nil
}

// LegacyEVMChains returns a container with all the evm chains
// TODO BCF-2511
func (rs *CoreRelayerChainInteroperators) LegacyEVMChains() legacyevm.LegacyChainContainer {
Expand Down
2 changes: 1 addition & 1 deletion core/services/chainlink/relayer_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/pelletier/go-toml/v2"

"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/loop/adapters/relay"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos"
Expand All @@ -23,7 +24,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/config/env"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/wsrpc"
"github.com/smartcontractkit/chainlink/v2/plugins"
Expand Down
4 changes: 4 additions & 0 deletions core/services/job/spawner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (g *relayGetter) Get(id types.RelayID) (loop.Relayer, error) {
return evmrelayer.NewLoopRelayServerAdapter(g.r, g.e), nil
}

func (g *relayGetter) GetIDToRelayerMap() (map[types.RelayID]loop.Relayer, error) {
return map[types.RelayID]loop.Relayer{}, nil
}

func TestSpawner_CreateJobDeleteJob(t *testing.T) {
t.Parallel()
ctx := testutils.Context(t)
Expand Down
29 changes: 15 additions & 14 deletions core/services/ocr2/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,22 @@ import (
ocr2keepers20runner "github.com/smartcontractkit/chainlink-automation/pkg/v2/runner"
ocr2keepers21config "github.com/smartcontractkit/chainlink-automation/pkg/v3/config"
ocr2keepers21 "github.com/smartcontractkit/chainlink-automation/pkg/v3/plugin"
"github.com/smartcontractkit/chainlink-common/pkg/loop/reportingplugins/ocr3"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"

"github.com/smartcontractkit/chainlink/v2/core/config/env"

"github.com/smartcontractkit/chainlink-vrf/altbn_128"
dkgpkg "github.com/smartcontractkit/chainlink-vrf/dkg"
"github.com/smartcontractkit/chainlink-vrf/ocr2vrf"

commonlogger "github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/loop/reportingplugins"
"github.com/smartcontractkit/chainlink-common/pkg/loop/reportingplugins/ocr3"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
llotypes "github.com/smartcontractkit/chainlink-common/pkg/types/llo"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox"

"github.com/smartcontractkit/chainlink-vrf/altbn_128"
dkgpkg "github.com/smartcontractkit/chainlink-vrf/dkg"
"github.com/smartcontractkit/chainlink-vrf/ocr2vrf"
"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm"
coreconfig "github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/config/env"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
Expand All @@ -71,7 +67,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/validate"
"github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
functionsRelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/functions"
evmmercury "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury"
Expand Down Expand Up @@ -108,6 +103,7 @@ func (e ErrRelayNotEnabled) Error() string {

type RelayGetter interface {
Get(id types.RelayID) (loop.Relayer, error)
GetIDToRelayerMap() (map[types.RelayID]loop.Relayer, error)
}
type Delegate struct {
ds sqlutil.DataSource
Expand Down Expand Up @@ -567,6 +563,11 @@ func (d *Delegate) newServicesGenericPlugin(
return nil, ErrJobSpecNoRelayer{PluginName: pCfg.PluginName, Err: err}
}

relayerSet, err := generic.NewRelayerSet(d.RelayGetter, jb.ExternalJobID, jb.ID, d.isNewlyCreatedJob)
if err != nil {
return nil, fmt.Errorf("failed to create relayer set: %w", err)
}

relayer, err := d.RelayGetter.Get(rid)
if err != nil {
return nil, ErrRelayNotEnabled{Err: err, Relay: spec.Relay, PluginName: pCfg.PluginName}
Expand Down Expand Up @@ -620,7 +621,7 @@ func (d *Delegate) newServicesGenericPlugin(
//TODO: remove this workaround when the EVM relayer is running inside of an LOOPP
d.lggr.Info("provider is not a LOOPP provider, switching to provider server")

ps, err2 := relay.NewProviderServer(provider, types.OCR2PluginType(pCfg.ProviderType), d.lggr)
ps, err2 := loop.NewProviderServer(provider, types.OCR2PluginType(pCfg.ProviderType), d.lggr)
if err2 != nil {
return nil, fmt.Errorf("cannot start EVM provider server: %s", err2)
}
Expand Down Expand Up @@ -657,7 +658,7 @@ func (d *Delegate) newServicesGenericPlugin(
switch pCfg.OCRVersion {
case 2:
plugin := reportingplugins.NewLOOPPService(pluginLggr, grpcOpts, cmdFn, pluginConfig, providerClientConn, pr, ta,
errorLog, keyValueStore)
errorLog, keyValueStore, relayerSet)
oracleArgs := libocr2.OCR2OracleArgs{
BinaryNetworkEndpointFactory: d.peerWrapper.Peer2,
V2Bootstrappers: bootstrapPeers,
Expand All @@ -683,7 +684,7 @@ func (d *Delegate) newServicesGenericPlugin(
case 3:
//OCR3 with OCR2 OnchainKeyring and ContractTransmitter
plugin := ocr3.NewLOOPPService(pluginLggr, grpcOpts, cmdFn, pluginConfig, providerClientConn, pr, ta, errorLog,
capabilitiesRegistry, keyValueStore)
capabilitiesRegistry, keyValueStore, relayerSet)
contractTransmitter := ocrcommon.NewOCR3ContractTransmitterAdapter(provider.ContractTransmitter())
oracleArgs := libocr2.OCR3OracleArgs[[]byte]{
BinaryNetworkEndpointFactory: d.peerWrapper.Peer2,
Expand Down
87 changes: 87 additions & 0 deletions core/services/ocr2/plugins/generic/relayerset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package generic

import (
"context"
"fmt"

"github.com/google/uuid"

"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
)

type RelayGetter interface {
GetIDToRelayerMap() (map[types.RelayID]loop.Relayer, error)
}

type RelayerSet struct {
wrappedRelayers map[types.RelayID]core.Relayer
}

func NewRelayerSet(relayGetter RelayGetter, externalJobID uuid.UUID, jobID int32, isNew bool) (*RelayerSet, error) {

wrappedRelayers := map[types.RelayID]core.Relayer{}

relayers, err := relayGetter.GetIDToRelayerMap()
if err != nil {
return nil, fmt.Errorf("failed to get relayers: %w", err)
}

for id, relayer := range relayers {
wrappedRelayers[id] = relayerWrapper{Relayer: relayer, ExternalJobID: externalJobID, JobID: jobID, New: isNew}
}

return &RelayerSet{wrappedRelayers: wrappedRelayers}, nil
}

func (r *RelayerSet) Get(_ context.Context, id types.RelayID) (core.Relayer, error) {
if relayer, ok := r.wrappedRelayers[id]; ok {
return relayer, nil
}

return nil, fmt.Errorf("relayer with id %s not found", id)
}

func (r *RelayerSet) List(_ context.Context, relayIDs ...types.RelayID) (map[types.RelayID]core.Relayer, error) {

if len(relayIDs) == 0 {
return r.wrappedRelayers, nil
}

filterer := map[types.RelayID]bool{}
for _, id := range relayIDs {
filterer[id] = true
}

result := map[types.RelayID]core.Relayer{}
for id, relayer := range r.wrappedRelayers {
if _, ok := filterer[id]; ok {
result[id] = relayer
}
}

return result, nil
}

type relayerWrapper struct {
loop.Relayer
ExternalJobID uuid.UUID
JobID int32
New bool // Whether this is a first time job add.
}

func (r relayerWrapper) NewPluginProvider(ctx context.Context, rargs core.RelayArgs, pargs core.PluginArgs) (types.PluginProvider, error) {

relayArgs := types.RelayArgs{
ExternalJobID: r.ExternalJobID,
JobID: r.JobID,
ContractID: rargs.ContractID,
New: r.New,
RelayConfig: rargs.RelayConfig,
ProviderType: rargs.ProviderType,
MercuryCredentials: rargs.MercuryCredentials,
}

return r.Relayer.NewPluginProvider(ctx, relayArgs, types.PluginArgs(pargs))
}
Loading

0 comments on commit 1b99404

Please sign in to comment.