Skip to content

Commit

Permalink
Fix rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed Sep 11, 2024
1 parent bcaaa78 commit 5c682a9
Show file tree
Hide file tree
Showing 18 changed files with 410 additions and 930 deletions.
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/prometheus/client_golang v1.20.0
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910154010-ed9f50de7322
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240911125453-4678744e048c

Check failure on line 25 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): 4678744e048c Tree: https://github.com/smartcontractkit/chainlink-common/tree/4678744e048c Commit: https://github.com/smartcontractkit/chainlink-common/commit/4678744e048c
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240717100443-f6226e09bee7
github.com/spf13/cobra v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,8 @@ github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8um
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240910072312-810030689426 h1:siC6AoTs4889FwiqgEp0sC6S8nFlDzVTZAmUX7cV7aM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240910072312-810030689426/go.mod h1:v8hmGodMN1s1TQnvZepZ3Pbo+PyzWVdXag7JzJnvrkI=
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910154010-ed9f50de7322 h1:9SkeP9lpTMDqtqDd+BKPQhkPcylSoYi63L9YFdbzbEo=
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910154010-ed9f50de7322/go.mod h1:D/qaCoq0SxXzg5NRN5FtBRv98VBf+D2NOC++RbvvuOc=
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240911125453-4678744e048c h1:HxC3hiAl8x+2w3PJY9VGTRQJH3XoPs1UvGVGwnIfH2c=
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240911125453-4678744e048c/go.mod h1:D/qaCoq0SxXzg5NRN5FtBRv98VBf+D2NOC++RbvvuOc=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240910210931-638ba8a76227 h1:xow5cYrWxRmzTwhz2AjWOlnI9WRF4O5b84bXm1k292E=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240910210931-638ba8a76227/go.mod h1:DUFantPYoBGwBSkNVt2k4ZJi0jPKRRrZVVlAzcZwreA=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240904093355-e40169857652 h1:0aZ3HiEz2bMM5ywHAyKlFMN95qTzpNDn7uvnHLrFX6s=
Expand Down
75 changes: 37 additions & 38 deletions core/services/relay/evm/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var _ commontypes.ContractTypeProvider = &chainReader{}

// NewChainReaderService is a constructor for ChainReader, returns nil if there is any error
// Note that the ChainReaderService returned does not support anonymous events.
func NewChainReaderService(ctx context.Context, lggr logger.Logger, lp logpoller.LogPoller, ht logpoller.HeadTracker, client evmclient.Client, config types.ChainReaderConfig) (ChainReaderService, error) {
func NewChainReaderService(_ context.Context, lggr logger.Logger, lp logpoller.LogPoller, ht logpoller.HeadTracker, client evmclient.Client, config types.ChainReaderConfig) (ChainReaderService, error) {
cr := &chainReader{
lggr: logger.Named(lggr, "ChainReader"),
ht: ht,
Expand Down Expand Up @@ -131,7 +131,7 @@ func (cr *chainReader) init(chainContractReaders map[string]types.ChainContractR
return fmt.Errorf("%w: no read bindings added for contract: %s", commontypes.ErrInvalidConfig, contractName)
}

if err := cr.bindings.SetFilter(contractName, chainContractReader.PollingFilter.ToLPFilter(eventSigsForContractFilter)); err != nil {
if err = cr.bindings.SetFilter(contractName, chainContractReader.PollingFilter.ToLPFilter(eventSigsForContractFilter)); err != nil {
return err
}
}
Expand All @@ -152,7 +152,6 @@ func (cr *chainReader) Close() error {
return cr.StopOnce("ChainReader", func() error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

return cr.bindings.UnregisterAll(ctx, cr.lp)
})
}
Expand All @@ -163,6 +162,14 @@ func (cr *chainReader) HealthReport() map[string]error {
return map[string]error{cr.Name(): nil}
}

func (cr *chainReader) Bind(ctx context.Context, bindings []commontypes.BoundContract) error {
return cr.bindings.Bind(ctx, cr.lp, bindings)
}

func (cr *chainReader) Unbind(ctx context.Context, bindings []commontypes.BoundContract) error {
return cr.bindings.Unbind(ctx, cr.lp, bindings)
}

func (cr *chainReader) GetLatestValue(ctx context.Context, readName string, confidenceLevel primitives.ConfidenceLevel, params any, returnVal any) error {
binding, address, err := cr.bindings.GetReader(readName)
if err != nil {
Expand All @@ -176,14 +183,6 @@ func (cr *chainReader) BatchGetLatestValues(ctx context.Context, request commont
return cr.bindings.BatchGetLatestValues(ctx, request)
}

func (cr *chainReader) Bind(ctx context.Context, bindings []commontypes.BoundContract) error {
return cr.bindings.Bind(ctx, cr.lp, bindings)
}

func (cr *chainReader) Unbind(ctx context.Context, bindings []commontypes.BoundContract) error {
return cr.bindings.Unbind(ctx, cr.lp, bindings)
}

func (cr *chainReader) QueryKey(
ctx context.Context,
contract commontypes.BoundContract,
Expand Down Expand Up @@ -233,8 +232,8 @@ func (cr *chainReader) addEvent(contractName, eventName string, a abi.ABI, chain
return fmt.Errorf("%w: event %s doesn't exist", commontypes.ErrInvalidConfig, chainReaderDefinition.ChainSpecificName)
}

indexedAsUnIndexedABITypes, indexedTopicsCodecTypeInfo, eventDWs := getEventTypes(event)
if err := indexedTopicsCodecTypeInfo.Init(); err != nil {
indexedAsUnIndexedABITypes, indexedTopicsCodecTypes, eventDWs := getEventTypes(event)
if err := indexedTopicsCodecTypes.Init(); err != nil {
return err
}

Expand All @@ -244,8 +243,8 @@ func (cr *chainReader) addEvent(contractName, eventName string, a abi.ABI, chain
return err
}

codecTypes, codecModifiers := make(map[string]types.CodecEntry), make(map[string]codec.Modifier)
topicTypeID := read.WrapItemType(contractName, eventName, true)
codecTypes, codecModifiers := make(map[string]types.CodecEntry), make(map[string]commoncodec.Modifier)
topicTypeID := codec.WrapItemType(contractName, eventName, true)
codecTypes[topicTypeID], codecModifiers[topicTypeID], err = cr.getEventItemTypeAndModifier(topicTypeID, chainReaderDefinition.InputModifications)
if err != nil {
return err
Expand All @@ -256,7 +255,7 @@ func (cr *chainReader) addEvent(contractName, eventName string, a abi.ABI, chain
return err
}

eb := read.NewEventBinding(contractName, eventName, cr.lp, event.ID, indexedTopicsCodecTypeInfo, confirmations)
eb := read.NewEventBinding(contractName, eventName, cr.lp, event.ID, indexedTopicsCodecTypes, confirmations)
if eventDefinitions := chainReaderDefinition.EventDefinitions; eventDefinitions != nil {
if eventDefinitions.PollingFilter != nil {
eb.SetFilter(eventDefinitions.PollingFilter.ToLPFilter(evmtypes.HashArray{a.Events[event.Name].ID}))
Expand All @@ -277,22 +276,22 @@ func (cr *chainReader) addEvent(contractName, eventName string, a abi.ABI, chain
maps.Copy(codecTypes, dWSCodecTypeInfo)
// no modifier for now, but can be added if needed

eb.topics = topicsDetails
eb.dataWords = dataWordsDetails
eb.SetTopicDetails(topicsDetails)
eb.SetDataWordsDetails(dataWordsDetails)

}

eb.eventTypes = codecTypes
eb.eventModifiers = codecModifiers
eb.SetCodecTypesAndModifiers(codecTypes, codecModifiers)

cr.bindings.AddReader(contractName, eventName, eb)
return cr.addDecoderDef(contractName, eventName, event.Inputs, chainReaderDefinition.OutputModifications)
}

// initTopicQuerying registers codec types and modifiers for topics to be used for typing value comparator QueryKey filters.
func (cr *chainReader) initTopicQuerying(contractName, eventName string, eventInputs abi.Arguments, genericTopicNames map[string]string, inputModifications codec.ModifiersConfig) (map[string]topicDetail, map[string]types.CodecEntry, map[string]codec.Modifier, error) {
topicsDetails := make(map[string]topicDetail)
func (cr *chainReader) initTopicQuerying(contractName, eventName string, eventInputs abi.Arguments, genericTopicNames map[string]string, inputModifications commoncodec.ModifiersConfig) (map[string]read.TopicDetail, map[string]types.CodecEntry, map[string]commoncodec.Modifier, error) {
topicsDetails := make(map[string]read.TopicDetail)
topicsTypes := make(map[string]types.CodecEntry)
topicsModifiers := make(map[string]codec.Modifier)
topicsModifiers := make(map[string]commoncodec.Modifier)
for topicIndex, topic := range eventInputs {
genericTopicName, ok := genericTopicNames[topic.Name]
if ok {
Expand All @@ -303,30 +302,30 @@ func (cr *chainReader) initTopicQuerying(contractName, eventName string, eventIn
return nil, nil, nil, err
}

topicTypeID = read.WrapItemType(contractName, topicTypeID, true)
topicTypeID = codec.WrapItemType(contractName, topicTypeID, true)
topicsTypes[topicTypeID], topicsModifiers[topicTypeID], err = cr.getEventItemTypeAndModifier(topicTypeID, inputModifications)
if err != nil {
return nil, nil, nil, err
}

topicsDetails[genericTopicName] = topicDetail{Argument: topic, Index: uint64(topicIndex + 1)}
topicsDetails[genericTopicName] = read.TopicDetail{Argument: topic, Index: uint64(topicIndex + 1)}
}
}
return topicsDetails, topicsTypes, topicsModifiers, nil
}

// initDWQuerying registers codec types for evm data words to be used for typing value comparator QueryKey filters.
func (cr *chainReader) initDWQuerying(contractName, eventName string, eventDWs map[string]dataWordDetail, dWDefs map[string]types.DataWordDef) (map[string]dataWordDetail, map[string]types.CodecEntry, error) {
func (cr *chainReader) initDWQuerying(contractName, eventName string, eventDWs map[string]read.DataWordDetail, dWDefs map[string]types.DataWordDef) (map[string]read.DataWordDetail, map[string]types.CodecEntry, error) {
dwsCodecTypeInfo := make(map[string]types.CodecEntry)
dWsDetail := make(map[string]dataWordDetail)
dWsDetail := make(map[string]read.DataWordDetail)

for genericName, cfgDWInfo := range dWDefs {
foundDW := false
for _, dWDetail := range eventDWs {
// err if index is same but name is diff
if dWDetail.index != cfgDWInfo.Index {
if dWDetail.Index != cfgDWInfo.Index {
if dWDetail.Name == cfgDWInfo.OnChainName {
return nil, nil, fmt.Errorf("failed to find data word with index %d for event: %q data word: %q", dWDetail.index, eventName, genericName)
return nil, nil, fmt.Errorf("failed to find data word with index %d for event: %q data word: %q", dWDetail.Index, eventName, genericName)
}
continue
}
Expand All @@ -335,10 +334,10 @@ func (cr *chainReader) initDWQuerying(contractName, eventName string, eventDWs m

dwTypeID := eventName + "." + genericName
if err := cr.addEncoderDef(contractName, dwTypeID, abi.Arguments{abi.Argument{Type: dWDetail.Type}}, nil, nil); err != nil {
return nil, nil, fmt.Errorf("%w: failed to init codec for data word %s on index %d querying for event: %q", err, genericName, dWDetail.index, eventName)
return nil, nil, fmt.Errorf("%w: failed to init codec for data word %s on index %d querying for event: %q", err, genericName, dWDetail.Index, eventName)
}

dwCodecTypeID := read.WrapItemType(contractName, dwTypeID, true)
dwCodecTypeID := codec.WrapItemType(contractName, dwTypeID, true)
dwsCodecTypeInfo[dwCodecTypeID] = cr.parsed.EncoderDefs[dwCodecTypeID]

dWsDetail[genericName] = dWDetail
Expand All @@ -352,7 +351,7 @@ func (cr *chainReader) initDWQuerying(contractName, eventName string, eventDWs m
}

// getEventItemTypeAndModifier returns codec entry for expected incoming event item and the modifier.
func (cr *chainReader) getEventItemTypeAndModifier(itemType string, inputMod codec.ModifiersConfig) (types.CodecEntry, codec.Modifier, error) {
func (cr *chainReader) getEventItemTypeAndModifier(itemType string, inputMod commoncodec.ModifiersConfig) (types.CodecEntry, commoncodec.Modifier, error) {
inputTypeInfo := cr.parsed.EncoderDefs[itemType]
// TODO can this be simplified? Isn't this same as inputType.Modifier()? BCI-3909
inMod, err := inputMod.ToModifier(codec.DecoderHooks...)
Expand Down Expand Up @@ -380,7 +379,7 @@ func (cr *chainReader) addEncoderDef(contractName, itemType string, args abi.Arg
return err
}

cr.parsed.EncoderDefs[read.WrapItemType(contractName, itemType, true)] = input
cr.parsed.EncoderDefs[codec.WrapItemType(contractName, itemType, true)] = input
return nil
}

Expand All @@ -390,17 +389,17 @@ func (cr *chainReader) addDecoderDef(contractName, itemType string, outputs abi.
return err
}
output := types.NewCodecEntry(outputs, nil, mod)
cr.parsed.DecoderDefs[read.WrapItemType(contractName, itemType, false)] = output
cr.parsed.DecoderDefs[codec.WrapItemType(contractName, itemType, false)] = output
return output.Init()
}

// getEventTypes returns abi args where indexed flag is set to false because we expect caller to filter with params that aren't hashed,
// codecEntry where expected on chain types are set, for e.g. indexed topics of type string or uint8[32] array are expected as common.Hash onchain,
// and un-indexed data info in form of evm indexed 32 byte data words.
func getEventTypes(event abi.Event) ([]abi.Argument, types.CodecEntry, map[string]dataWordDetail) {
func getEventTypes(event abi.Event) ([]abi.Argument, types.CodecEntry, map[string]read.DataWordDetail) {
indexedAsUnIndexedTypes := make([]abi.Argument, 0, types.MaxTopicFields)
indexedTypes := make([]abi.Argument, 0, len(event.Inputs))
dataWords := make(map[string]dataWordDetail)
dataWords := make(map[string]read.DataWordDetail)
hadDynamicType := false
dwIndex := 0

Expand All @@ -414,8 +413,8 @@ func getEventTypes(event abi.Event) ([]abi.Argument, types.CodecEntry, map[strin
continue
}

dataWords[event.Name+"."+input.Name] = dataWordDetail{
index: uint8(dwIndex),
dataWords[event.Name+"."+input.Name] = read.DataWordDetail{
Index: uint8(dwIndex),

Check failure on line 417 in core/services/relay/evm/chain_reader.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion int -> uint8 (gosec)
Argument: input,
}
dwIndex++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/codec"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/read"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
)

Expand Down Expand Up @@ -69,8 +68,8 @@ func (cwh *ClientWithContractHistory) Init(_ context.Context, config types.Chain
return err
}

parsedTypes.EncoderDefs[read.WrapItemType(contractName, genericName, true)] = input
parsedTypes.DecoderDefs[read.WrapItemType(contractName, genericName, false)] = output
parsedTypes.EncoderDefs[codec.WrapItemType(contractName, genericName, true)] = input
parsedTypes.DecoderDefs[codec.WrapItemType(contractName, genericName, false)] = output
}
}

Expand Down Expand Up @@ -126,7 +125,7 @@ func (cwh *ClientWithContractHistory) CallContract(ctx context.Context, msg ethe
}

// encode the expected call to compare with the actual call
dataToCmp, err := cwh.codec.Encode(ctx, valAndCall.Params, read.WrapItemType(valAndCall.ContractName, valAndCall.ReadName, true))
dataToCmp, err := cwh.codec.Encode(ctx, valAndCall.Params, codec.WrapItemType(valAndCall.ContractName, valAndCall.ReadName, true))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions core/services/relay/evm/chain_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (w *chainWriter) SubmitTransaction(ctx context.Context, contract, method st
return fmt.Errorf("method config not found: %v", method)
}

calldata, err := w.encoder.Encode(ctx, args, WrapItemType(contract, method, true))
calldata, err := w.encoder.Encode(ctx, args, codec.WrapItemType(contract, method, true))
if err != nil {
return fmt.Errorf("%w: failed to encode args", err)
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func (w *chainWriter) parseContracts() error {
return fmt.Errorf("%w: failed to init codec entry for method %s", err, method)
}

w.parsedContracts.EncoderDefs[WrapItemType(contract, method, true)] = input
w.parsedContracts.EncoderDefs[codec.WrapItemType(contract, method, true)] = input
}
}

Expand Down
8 changes: 8 additions & 0 deletions core/services/relay/evm/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ func (c *evmCodec) CreateType(itemType string, forEncoding bool) (any, error) {
return reflect.New(def.CheckedType()).Interface(), nil
}

func WrapItemType(contractName, itemType string, isParams bool) string {
if isParams {
return fmt.Sprintf("params.%s.%s", contractName, itemType)
}

return fmt.Sprintf("return.%s.%s", contractName, itemType)
}

var bigIntType = reflect.TypeOf((*big.Int)(nil))

func sizeVerifyBigIntHook(from, to reflect.Type, data any) (any, error) {
Expand Down
Loading

0 comments on commit 5c682a9

Please sign in to comment.