diff --git a/core/scripts/go.mod b/core/scripts/go.mod index 14e29a6740a..690a8d189cc 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -302,7 +302,7 @@ require ( github.com/sirupsen/logrus v1.9.3 // indirect github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231030134738-81a5a89699a0 // indirect - github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231030111206-48c9bf5d5436 // indirect + github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231031114820-e9826d481111 // indirect github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 // indirect github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb // indirect github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 // indirect diff --git a/core/scripts/go.sum b/core/scripts/go.sum index 08356fe0766..5cbdb37427d 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1458,8 +1458,8 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231030134738-81a5a89699a0 h1:YrJ3moRDu2kgdv4o3Hym/FWVF4MS5cIZ7o7wk+43pvk= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231030134738-81a5a89699a0/go.mod h1:fxtwgVZzTgoU1CpdSxNvFXecIY2r8DhH2JCzPO4e9G0= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231030111206-48c9bf5d5436 h1:XJuWThPInOZ9Bz0zM8xmACO+Ly/cY9+0JOILkHlN/2o= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231030111206-48c9bf5d5436/go.mod h1:M9U1JV7IQi8Sfj4JR1qSi1tIh6omgW78W/8SHN/8BUQ= +github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231031114820-e9826d481111 h1:CElKhWq0WIa9Rmg5Ssajs5Hp3m3u/nYIQdXtpj2gbcc= +github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231031114820-e9826d481111/go.mod h1:M9U1JV7IQi8Sfj4JR1qSi1tIh6omgW78W/8SHN/8BUQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 h1:DaPSVnxe7oz1QJ+AVIhQWs1W3ubQvwvGo9NbHpMs1OQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05/go.mod h1:o0Pn1pbaUluboaK6/yhf8xf7TiFCkyFl6WUOdwqamuU= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb h1:HiluOfEVGOQTM6BTDImOqYdMZZ7qq7fkZ3TJdmItNr8= diff --git a/core/services/ocr2/plugins/generic/telemetry_adapter.go b/core/services/ocr2/plugins/generic/telemetry_adapter.go new file mode 100644 index 00000000000..a81befa9854 --- /dev/null +++ b/core/services/ocr2/plugins/generic/telemetry_adapter.go @@ -0,0 +1,56 @@ +package generic + +import ( + "context" + "errors" + + "github.com/smartcontractkit/libocr/commontypes" + + "github.com/smartcontractkit/chainlink-relay/pkg/types" +) + +var _ types.TelemetryService = (*TelemetryAdapter)(nil) + +type TelemetryAdapter struct { + endpointGenerator types.MonitoringEndpointGenerator + endpoints map[[4]string]commontypes.MonitoringEndpoint +} + +func NewTelemetryAdapter(endpointGen types.MonitoringEndpointGenerator) *TelemetryAdapter { + return &TelemetryAdapter{ + endpoints: make(map[[4]string]commontypes.MonitoringEndpoint), + endpointGenerator: endpointGen, + } +} + +func (t *TelemetryAdapter) Send(ctx context.Context, network string, chainID string, contractID string, telemetryType string, payload []byte) error { + e, err := t.getOrCreateEndpoint(contractID, telemetryType, network, chainID) + if err != nil { + return err + } + e.SendLog(payload) + return nil +} + +func (t *TelemetryAdapter) getOrCreateEndpoint(contractID string, telemetryType string, network string, chainID string) (commontypes.MonitoringEndpoint, error) { + if contractID == "" { + return nil, errors.New("contractID cannot be empty") + } + if telemetryType == "" { + return nil, errors.New("telemetryType cannot be empty") + } + if network == "" { + return nil, errors.New("network cannot be empty") + } + if chainID == "" { + return nil, errors.New("chainID cannot be empty") + } + + key := [4]string{network, chainID, contractID, telemetryType} + e, ok := t.endpoints[key] + if !ok { + e = t.endpointGenerator.GenMonitoringEndpoint(network, chainID, contractID, telemetryType) + t.endpoints[key] = e + } + return e, nil +} diff --git a/core/services/ocr2/plugins/generic/telemetry_adapter_test.go b/core/services/ocr2/plugins/generic/telemetry_adapter_test.go new file mode 100644 index 00000000000..d430b889a4b --- /dev/null +++ b/core/services/ocr2/plugins/generic/telemetry_adapter_test.go @@ -0,0 +1,108 @@ +package generic + +import ( + "context" + "fmt" + "testing" + + "github.com/smartcontractkit/libocr/commontypes" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type mockEndpoint struct { + network string + chainID string + contractID string + telemetryType string + payload []byte +} + +func (m *mockEndpoint) SendLog(payload []byte) { m.payload = payload } + +type mockGenerator struct{} + +func (m *mockGenerator) GenMonitoringEndpoint(network, chainID, contractID, telemetryType string) commontypes.MonitoringEndpoint { + return &mockEndpoint{ + network: network, + chainID: chainID, + contractID: contractID, + telemetryType: telemetryType, + } +} + +func TestTelemetryAdapter(t *testing.T) { + ta := NewTelemetryAdapter(&mockGenerator{}) + + tests := []struct { + name string + contractID string + telemetryType string + networkID string + chainID string + payload []byte + errorMsg string + }{ + { + name: "valid request", + contractID: "contract", + telemetryType: "mercury", + networkID: "solana", + chainID: "1337", + payload: []byte("uh oh"), + }, + { + name: "no valid contractID", + telemetryType: "mercury", + networkID: "solana", + chainID: "1337", + payload: []byte("uh oh"), + errorMsg: "contractID cannot be empty", + }, + { + name: "no valid chainID", + contractID: "contract", + telemetryType: "mercury", + networkID: "solana", + payload: []byte("uh oh"), + errorMsg: "chainID cannot be empty", + }, + { + name: "no valid telemetryType", + contractID: "contract", + networkID: "solana", + chainID: "1337", + payload: []byte("uh oh"), + errorMsg: "telemetryType cannot be empty", + }, + { + name: "no valid network", + contractID: "contract", + telemetryType: "mercury", + chainID: "1337", + payload: []byte("uh oh"), + errorMsg: "network cannot be empty", + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + err := ta.Send(context.Background(), test.networkID, test.chainID, test.contractID, test.telemetryType, test.payload) + if test.errorMsg != "" { + assert.ErrorContains(t, err, test.errorMsg) + } else { + require.NoError(t, err) + key := [4]string{test.networkID, test.chainID, test.contractID, test.telemetryType} + fmt.Printf("%+v", ta.endpoints) + endpoint, ok := ta.endpoints[key] + require.True(t, ok) + + me := endpoint.(*mockEndpoint) + assert.Equal(t, test.networkID, me.network) + assert.Equal(t, test.chainID, me.chainID) + assert.Equal(t, test.contractID, me.contractID) + assert.Equal(t, test.telemetryType, me.telemetryType) + assert.Equal(t, test.payload, me.payload) + } + }) + } +} diff --git a/go.mod b/go.mod index 9c14fe8c144..ad3cb5f78ed 100644 --- a/go.mod +++ b/go.mod @@ -68,7 +68,7 @@ require ( github.com/shopspring/decimal v1.3.1 github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231030134738-81a5a89699a0 - github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231030111206-48c9bf5d5436 + github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231031114820-e9826d481111 github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb github.com/smartcontractkit/libocr v0.0.0-20231020123319-d255366a6545 diff --git a/go.sum b/go.sum index 372e705c71e..f879f16272b 100644 --- a/go.sum +++ b/go.sum @@ -1459,8 +1459,8 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231030134738-81a5a89699a0 h1:YrJ3moRDu2kgdv4o3Hym/FWVF4MS5cIZ7o7wk+43pvk= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231030134738-81a5a89699a0/go.mod h1:fxtwgVZzTgoU1CpdSxNvFXecIY2r8DhH2JCzPO4e9G0= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231030111206-48c9bf5d5436 h1:XJuWThPInOZ9Bz0zM8xmACO+Ly/cY9+0JOILkHlN/2o= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231030111206-48c9bf5d5436/go.mod h1:M9U1JV7IQi8Sfj4JR1qSi1tIh6omgW78W/8SHN/8BUQ= +github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231031114820-e9826d481111 h1:CElKhWq0WIa9Rmg5Ssajs5Hp3m3u/nYIQdXtpj2gbcc= +github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231031114820-e9826d481111/go.mod h1:M9U1JV7IQi8Sfj4JR1qSi1tIh6omgW78W/8SHN/8BUQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 h1:DaPSVnxe7oz1QJ+AVIhQWs1W3ubQvwvGo9NbHpMs1OQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05/go.mod h1:o0Pn1pbaUluboaK6/yhf8xf7TiFCkyFl6WUOdwqamuU= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb h1:HiluOfEVGOQTM6BTDImOqYdMZZ7qq7fkZ3TJdmItNr8= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 1263c406aaf..3affd799194 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -384,7 +384,7 @@ require ( github.com/sirupsen/logrus v1.9.3 // indirect github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231030134738-81a5a89699a0 // indirect - github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231030111206-48c9bf5d5436 // indirect + github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231031114820-e9826d481111 // indirect github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 // indirect github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb // indirect github.com/smartcontractkit/sqlx v1.3.5-0.20210805004948-4be295aacbeb // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 08c037dd0ce..98685fdf889 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -2362,8 +2362,8 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231030134738-81a5a89699a0 h1:YrJ3moRDu2kgdv4o3Hym/FWVF4MS5cIZ7o7wk+43pvk= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231030134738-81a5a89699a0/go.mod h1:fxtwgVZzTgoU1CpdSxNvFXecIY2r8DhH2JCzPO4e9G0= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231030111206-48c9bf5d5436 h1:XJuWThPInOZ9Bz0zM8xmACO+Ly/cY9+0JOILkHlN/2o= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231030111206-48c9bf5d5436/go.mod h1:M9U1JV7IQi8Sfj4JR1qSi1tIh6omgW78W/8SHN/8BUQ= +github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231031114820-e9826d481111 h1:CElKhWq0WIa9Rmg5Ssajs5Hp3m3u/nYIQdXtpj2gbcc= +github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231031114820-e9826d481111/go.mod h1:M9U1JV7IQi8Sfj4JR1qSi1tIh6omgW78W/8SHN/8BUQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 h1:DaPSVnxe7oz1QJ+AVIhQWs1W3ubQvwvGo9NbHpMs1OQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05/go.mod h1:o0Pn1pbaUluboaK6/yhf8xf7TiFCkyFl6WUOdwqamuU= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb h1:HiluOfEVGOQTM6BTDImOqYdMZZ7qq7fkZ3TJdmItNr8=