From 22ae19f7d09a30a6091ca9d935061b1edd281a0f Mon Sep 17 00:00:00 2001 From: ilija Date: Tue, 16 Apr 2024 13:18:45 +0200 Subject: [PATCH] Revert codec type key changes(belongs in a separate PR) --- core/scripts/go.mod | 2 +- core/scripts/go.sum | 4 +- core/services/relay/evm/bindings.go | 4 -- core/services/relay/evm/chain_reader.go | 39 +++++++++----------- core/services/relay/evm/chain_reader_test.go | 2 +- core/services/relay/evm/event_binding.go | 6 +-- core/services/relay/evm/method_binding.go | 5 +-- go.mod | 2 +- go.sum | 4 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 +- 13 files changed, 35 insertions(+), 45 deletions(-) diff --git a/core/scripts/go.mod b/core/scripts/go.mod index b2e390be2a1..21ad29f758a 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -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.20240415110553-dd497688eb25 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f 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-20240326191951-2bbe9382d052 diff --git a/core/scripts/go.sum b/core/scripts/go.sum index 60ae5153bc1..fc69f2a48f3 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1187,8 +1187,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.20240415110553-dd497688eb25 h1:9HiIIzQJ8jPJqkMBujqvXY53gi4srvDvk6cd/m7Z6p4= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415110553-dd497688eb25/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f h1:DMPgXryFDB5zwIh7KMoAJWKeoGZcuS7A++Yq8l5uL9Q= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8 h1:I326nw5GwHQHsLKHwtu5Sb9EBLylC8CfUd7BFAS0jtg= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8/go.mod h1:a65NtrK4xZb01mf0dDNghPkN2wXgcqFQ55ADthVBgMc= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo= diff --git a/core/services/relay/evm/bindings.go b/core/services/relay/evm/bindings.go index 3f683fd3073..e13fcbc02d5 100644 --- a/core/services/relay/evm/bindings.go +++ b/core/services/relay/evm/bindings.go @@ -60,7 +60,3 @@ func (b contractBindings) ForEach(ctx context.Context, fn func(readBinding, cont } return nil } - -func formatKey(contractName, readName string) string { - return contractName + "." + readName -} diff --git a/core/services/relay/evm/chain_reader.go b/core/services/relay/evm/chain_reader.go index 6f245c6b89a..e4ed1f88447 100644 --- a/core/services/relay/evm/chain_reader.go +++ b/core/services/relay/evm/chain_reader.go @@ -143,15 +143,15 @@ func (cr *chainReader) HealthReport() map[string]error { return map[string]error{cr.Name(): nil} } -func (cr *chainReader) CreateContractType(key string, forEncoding bool) (any, error) { - return cr.codec.CreateType(wrapItemType(key, forEncoding), forEncoding) +func (cr *chainReader) CreateContractType(contractName, itemType string, forEncoding bool) (any, error) { + return cr.codec.CreateType(wrapItemType(contractName, itemType, forEncoding), forEncoding) } -func wrapItemType(key string, isParams bool) string { +func wrapItemType(contractName, itemType string, isParams bool) string { if isParams { - return fmt.Sprintf("params.%s", key) + return fmt.Sprintf("params.%s.%s", contractName, itemType) } - return fmt.Sprintf("return.%s", key) + return fmt.Sprintf("return.%s.%s", contractName, itemType) } func (cr *chainReader) addMethod( @@ -177,12 +177,11 @@ func (cr *chainReader) addMethod( client: cr.client, }) - methodKey := formatKey(contractName, methodName) - if err := cr.addEncoderDef(methodKey, method.Inputs, method.ID, chainReaderDefinition); err != nil { + if err := cr.addEncoderDef(contractName, methodName, method.Inputs, method.ID, chainReaderDefinition); err != nil { return err } - return cr.addDecoderDef(methodKey, method.Outputs, chainReaderDefinition) + return cr.addDecoderDef(contractName, methodName, method.Outputs, chainReaderDefinition) } func (cr *chainReader) addEvent(contractName, eventName string, a abi.ABI, chainReaderDefinition types.ChainReaderDefinition) error { @@ -200,14 +199,12 @@ func (cr *chainReader) addEvent(contractName, eventName string, a abi.ABI, chain return err } - readKey := formatKey(contractName, eventName) - // Encoder def's codec won't be used to encode, only for its type as input for GetLatestValue - if err := cr.addEncoderDef(readKey, filterArgs, nil, chainReaderDefinition); err != nil { + if err := cr.addEncoderDef(contractName, eventName, filterArgs, nil, chainReaderDefinition); err != nil { return err } - inputInfo, inputModifier, err := cr.getEventInput(chainReaderDefinition, formatKey(contractName, eventName)) + inputInfo, inputModifier, err := cr.getEventInput(chainReaderDefinition, contractName, eventName) if err != nil { return err } @@ -222,7 +219,7 @@ func (cr *chainReader) addEvent(contractName, eventName string, a abi.ABI, chain codecTopicInfo: codecTopicInfo, topicsInfo: make(map[string]topicInfo), eventDataWords: chainReaderDefinition.GenericDataWordNames, - id: wrapItemType(readKey, false) + uuid.NewString(), + id: wrapItemType(contractName, eventName, false) + uuid.NewString(), } cr.contractBindings.AddReadBinding(contractName, eventName, eb) @@ -246,12 +243,12 @@ func (cr *chainReader) addEvent(contractName, eventName string, a abi.ABI, chain cr.contractBindings.AddReadBinding(contractName, genericDataWordName, eb) } - return cr.addDecoderDef(readKey, event.Inputs, chainReaderDefinition) + return cr.addDecoderDef(contractName, eventName, event.Inputs, chainReaderDefinition) } -func (cr *chainReader) getEventInput(def types.ChainReaderDefinition, key string) ( +func (cr *chainReader) getEventInput(def types.ChainReaderDefinition, contractName, eventName string) ( types.CodecEntry, codec.Modifier, error) { - inputInfo := cr.parsed.encoderDefs[wrapItemType(key, true)] + inputInfo := cr.parsed.encoderDefs[wrapItemType(contractName, eventName, true)] inMod, err := def.InputModifications.ToModifier(evmDecoderHooks...) if err != nil { return nil, nil, err @@ -274,7 +271,7 @@ func verifyEventInputsUsed(chainReaderDefinition types.ChainReaderDefinition, in return nil } -func (cr *chainReader) addEncoderDef(key string, args abi.Arguments, prefix []byte, chainReaderDefinition types.ChainReaderDefinition) error { +func (cr *chainReader) addEncoderDef(contractName, itemType string, args abi.Arguments, prefix []byte, chainReaderDefinition types.ChainReaderDefinition) error { // ABI.Pack prepends the method.ID to the encodings, we'll need the encoder to do the same. inputMod, err := chainReaderDefinition.InputModifications.ToModifier(evmDecoderHooks...) if err != nil { @@ -282,21 +279,21 @@ func (cr *chainReader) addEncoderDef(key string, args abi.Arguments, prefix []by } input := types.NewCodecEntry(args, prefix, inputMod) - if err := input.Init(); err != nil { + if err = input.Init(); err != nil { return err } - cr.parsed.encoderDefs[wrapItemType(key, true)] = input + cr.parsed.encoderDefs[wrapItemType(contractName, itemType, true)] = input return nil } -func (cr *chainReader) addDecoderDef(key string, outputs abi.Arguments, def types.ChainReaderDefinition) error { +func (cr *chainReader) addDecoderDef(contractName, itemType string, outputs abi.Arguments, def types.ChainReaderDefinition) error { mod, err := def.OutputModifications.ToModifier(evmDecoderHooks...) if err != nil { return err } output := types.NewCodecEntry(outputs, nil, mod) - cr.parsed.decoderDefs[wrapItemType(key, false)] = output + cr.parsed.decoderDefs[wrapItemType(contractName, itemType, false)] = output return output.Init() } diff --git a/core/services/relay/evm/chain_reader_test.go b/core/services/relay/evm/chain_reader_test.go index 33358523203..98e92966665 100644 --- a/core/services/relay/evm/chain_reader_test.go +++ b/core/services/relay/evm/chain_reader_test.go @@ -70,7 +70,7 @@ func TestChainReaderGetLatestValue(t *testing.T) { input := struct{ Field string }{Field: anyString} tp := cr.(clcommontypes.ContractTypeProvider) - output, err := tp.CreateContractType(AnyContractName+"."+triggerWithDynamicTopic, false) + output, err := tp.CreateContractType(AnyContractName, triggerWithDynamicTopic, false) require.NoError(t, err) rOutput := reflect.Indirect(reflect.ValueOf(output)) diff --git a/core/services/relay/evm/event_binding.go b/core/services/relay/evm/event_binding.go index 7b8557b35ed..f43576de4ff 100644 --- a/core/services/relay/evm/event_binding.go +++ b/core/services/relay/evm/event_binding.go @@ -217,8 +217,7 @@ func (e *eventBinding) getLatestValueWithFilters( } func (e *eventBinding) convertToOffChainType(params any) (any, error) { - dataType := wrapItemType(formatKey(e.contractName, e.eventName), true) - offChain, err := e.codec.CreateType(dataType, true) + offChain, err := e.codec.CreateType(wrapItemType(e.contractName, e.eventName, true), true) if err != nil { return nil, err } @@ -306,8 +305,7 @@ func (e *eventBinding) derefTopics(topics []any) error { } func (e *eventBinding) decodeLog(ctx context.Context, log *logpoller.Log, into any) error { - eventKey := formatKey(e.contractName, e.eventName) - if err := e.codec.Decode(ctx, log.Data, into, wrapItemType(eventKey, false)); err != nil { + if err := e.codec.Decode(ctx, log.Data, into, wrapItemType(e.contractName, e.eventName, false)); err != nil { return err } diff --git a/core/services/relay/evm/method_binding.go b/core/services/relay/evm/method_binding.go index 3b4b1307056..7484d17c3ef 100644 --- a/core/services/relay/evm/method_binding.go +++ b/core/services/relay/evm/method_binding.go @@ -45,8 +45,7 @@ func (m *methodBinding) GetLatestValue(ctx context.Context, params, returnValue return fmt.Errorf("%w: method not bound", commontypes.ErrInvalidType) } - methodKey := formatKey(m.contractName, m.method) - data, err := m.codec.Encode(ctx, params, wrapItemType(methodKey, true)) + data, err := m.codec.Encode(ctx, params, wrapItemType(m.contractName, m.method, true)) if err != nil { return err } @@ -62,7 +61,7 @@ func (m *methodBinding) GetLatestValue(ctx context.Context, params, returnValue return fmt.Errorf("%w: %w", commontypes.ErrInternal, err) } - return m.codec.Decode(ctx, bytes, returnValue, wrapItemType(methodKey, false)) + return m.codec.Decode(ctx, bytes, returnValue, wrapItemType(m.contractName, m.method, false)) } func (m *methodBinding) QueryKey(_ context.Context, _ query.KeyFilter, _ query.LimitAndSort, _ any) ([]commontypes.Sequence, error) { diff --git a/go.mod b/go.mod index 9363271a927..352d1d85e7d 100644 --- a/go.mod +++ b/go.mod @@ -72,7 +72,7 @@ require ( github.com/shopspring/decimal v1.3.1 github.com/smartcontractkit/chain-selectors v1.0.10 github.com/smartcontractkit/chainlink-automation v1.0.3 - github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415110553-dd497688eb25 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8 github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 github.com/smartcontractkit/chainlink-feeds v0.0.0-20240119021347-3c541a78cdb8 diff --git a/go.sum b/go.sum index b6dd4290f57..24075b2ff94 100644 --- a/go.sum +++ b/go.sum @@ -1182,8 +1182,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.20240415110553-dd497688eb25 h1:9HiIIzQJ8jPJqkMBujqvXY53gi4srvDvk6cd/m7Z6p4= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415110553-dd497688eb25/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f h1:DMPgXryFDB5zwIh7KMoAJWKeoGZcuS7A++Yq8l5uL9Q= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8 h1:I326nw5GwHQHsLKHwtu5Sb9EBLylC8CfUd7BFAS0jtg= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8/go.mod h1:a65NtrK4xZb01mf0dDNghPkN2wXgcqFQ55ADthVBgMc= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 404bd32f837..f875c42f5ea 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -24,7 +24,7 @@ require ( github.com/segmentio/ksuid v1.0.4 github.com/slack-go/slack v0.12.2 github.com/smartcontractkit/chainlink-automation v1.0.3 - github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415110553-dd497688eb25 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f github.com/smartcontractkit/chainlink-testing-framework v1.28.2 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 f45a3594e05..cbadcd206ae 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1521,8 +1521,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.20240415110553-dd497688eb25 h1:9HiIIzQJ8jPJqkMBujqvXY53gi4srvDvk6cd/m7Z6p4= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415110553-dd497688eb25/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f h1:DMPgXryFDB5zwIh7KMoAJWKeoGZcuS7A++Yq8l5uL9Q= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8 h1:I326nw5GwHQHsLKHwtu5Sb9EBLylC8CfUd7BFAS0jtg= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8/go.mod h1:a65NtrK4xZb01mf0dDNghPkN2wXgcqFQ55ADthVBgMc= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index b7acd6551f9..3d8597b927a 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -16,7 +16,7 @@ require ( github.com/rs/zerolog v1.30.0 github.com/slack-go/slack v0.12.2 github.com/smartcontractkit/chainlink-automation v1.0.3 - github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415110553-dd497688eb25 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f github.com/smartcontractkit/chainlink-testing-framework v1.28.2 github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240214231432-4ad5eb95178c github.com/smartcontractkit/chainlink/v2 v2.9.0-beta0.0.20240216210048-da02459ddad8 diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 4415b52124c..130ef967aa1 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1504,8 +1504,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.20240415110553-dd497688eb25 h1:9HiIIzQJ8jPJqkMBujqvXY53gi4srvDvk6cd/m7Z6p4= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415110553-dd497688eb25/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f h1:DMPgXryFDB5zwIh7KMoAJWKeoGZcuS7A++Yq8l5uL9Q= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240416104343-05c62ef54e2f/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8 h1:I326nw5GwHQHsLKHwtu5Sb9EBLylC8CfUd7BFAS0jtg= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8/go.mod h1:a65NtrK4xZb01mf0dDNghPkN2wXgcqFQ55ADthVBgMc= github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=