Skip to content

Commit

Permalink
Revert codec type key changes(belongs in a separate PR)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed Apr 16, 2024
1 parent 9ff08d4 commit 22ae19f
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 45 deletions.
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.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
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 0 additions & 4 deletions core/services/relay/evm/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
39 changes: 18 additions & 21 deletions core/services/relay/evm/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -274,29 +271,29 @@ 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 {
return err
}
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()
}

Expand Down
2 changes: 1 addition & 1 deletion core/services/relay/evm/chain_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
6 changes: 2 additions & 4 deletions core/services/relay/evm/event_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions core/services/relay/evm/method_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/load/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/load/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 22ae19f

Please sign in to comment.