Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BCF-3392] - ContractReaderByIDs Wrapper #797

Merged
merged 14 commits into from
Sep 30, 2024

Conversation

ilija42
Copy link
Contributor

@ilija42 ilija42 commented Sep 24, 2024

Adding a wrapper for this feature instead of making interface changes since not all use cases might want this

  • Main concern is double versioning since ContractReader changes might break this interface so we would have to version both CR and this wrapper. Right now there are no further planned changes to the interface, so at least we should be safe until new chain family impl. starts.
  • Had to change the fakeChainReader tester to support multiple addresses for same contract

Comment on lines 30 to 33
type contractReaderByIDs struct {
bindings sync.Map
cr types.ContractReader
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to embed UnimplementedContractReader?

Copy link
Contributor Author

@ilija42 ilija42 Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, UnimplementedContractReader is mainly for relayer impl. to have a stub so that the build doesn't break. If there is an interface change to Contract Reader, chainlink-common won't be mergeable before contractReaderByIDs calls to ContractReader are updated.
There is a separate concern here though, if the interface changes are breaking then the wrapper methods will have to be modified too, which means that we would have to version both the ContractReader interface and this wrapper.

Copy link
Contributor Author

@ilija42 ilija42 Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no plans for making any changes to the interface so there is no chance of this happening for now, but this could theoretically happen when work on a new chain family starts

crByIds.bindings.Delete(customContractID)
toUnbind = append(toUnbind, boundContract)
}
return crByIds.cr.Unbind(ctx, toUnbind)
Copy link
Collaborator

@winder winder Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's an error, could crByIds.bindings be in a bad state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with the current EVM impl. even in the worst scenario (LP having a dangling filter tracking a contract for no reason) this would be fine. I changed it though to future proof a bit more, we should make Unbind completely transactional so that the behaviour is easier to predict and handle when we get to multiple chain impl.

@ilija42 ilija42 changed the title WIP [BCF-3392] - ContractReaderByIDs Wrapper Sep 27, 2024
…erByIDs-wrapper

# Conflicts:
#	pkg/loop/internal/relayer/pluginprovider/contractreader/contract_reader_test.go
@ilija42 ilija42 marked this pull request as ready for review September 27, 2024 13:54
@ilija42 ilija42 requested a review from a team as a code owner September 27, 2024 13:54
@ilija42 ilija42 requested review from patrickhuie19 and removed request for a team September 27, 2024 13:54
Copy link
Collaborator

@EasterTheBunny EasterTheBunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

// Test Unbind with error shouldn't remove bindings
require.Error(t, crByIDs.Unbind(ctx, map[string]types.BoundContract{bc1CustomID: bc1}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/nit is this slightly clearer for the reader if the map is empty?

Suggested change
require.Error(t, crByIDs.Unbind(ctx, map[string]types.BoundContract{bc1CustomID: bc1}))
require.Error(t, crByIDs.Unbind(ctx, map[string]types.BoundContract{}))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no, I think it's clearer as is given the Test successful Unbind case

@patrickhuie19
Copy link
Contributor

I don't know if I fully grok the reason for the feature request, but the change looks good 👍

@ilija42 ilija42 merged commit f10ba2b into main Sep 30, 2024
11 checks passed
@ilija42 ilija42 deleted the BCF-3392-ContractReaderByIDs-wrapper branch September 30, 2024 17:03
cedric-cordenier pushed a commit that referenced this pull request Oct 4, 2024
* WIP

* Update ContractReaderByIDs interface method names

* Unexpose types.ContractReader in contractReaderByIDs

* Add multiple contract address support to fakeContractReader for tests

* Add GetLatestValue unit test for contractReaderByIDs

* Add GetLatestValue unit test for QueryKey

* Add BatchGetLatestValues unit test for CR by custom IdDs wrapper

* Rm ContractReaderByIDs interface and export the struct

* Change ContractReaderByIDs wrapper Unbind handling

* Improve ContractReaderByIDs wrapper err handling

* Remove mockery usage from ContractReaderByIDs tests

* lint
cedric-cordenier added a commit that referenced this pull request Oct 10, 2024
* [CM-380] Identical Aggregator

* [CAPPL-60] Dynamic encoder selection in OCR consensus aggregator

* extract encoder name and config

* Add more tests

* add limit to seq num range (#781)

* [chore] Handle aliases in slices (#784)

* [chore] Handle aliases in slices

* More aliasing tests

* Lint fix

* Fix test

---------

Co-authored-by: Sri Kidambi <1702865+kidambisrinivas@users.noreply.github.com>

* feat(observability-lib): legendoptions + improvement on node general dashboard (#785)

* [CAPPL-58] Correctly stub out clock_time_get and poll_oneoff (#778)

* [CAPPL-58] Further cleanup

* [CAPPL-58] Add support for compression

* More alias handling in Unwrap functionality of Value  (#792)

* Generic case to handle both pointer type and raw type and simplify int unwrap

* Handling interface and default

* Small test fix

---------

Co-authored-by: Cedric Cordenier <cedric.cordenier@smartcontract.com>

* Fix alias typing and tests (#788)

* Fix alias typing and tests

* Fix ints

* errors.new instead of fmt

* Add array support to slice (#789)

* Replace fmt.Errorf with errors.New where possible (#795)

* chore(workflows): adds unit test to utils (#782)

* Have the mock runner register with capabilites (#783)

* Add binary + config to custom compute (#794)

* Add binary + config to custom compute

* Add binary + config to custom compute

* fix lint issues (#786)

* execution factory constructor updated to take two providers, chainIDs, and source token address (#641)

* execution factory constructor updated to take two providers and chain IDs

(cherry picked from commit 6ad1f08)

* Adding source token address to execution factory constructor

* Support passing in a values.Value to the chainreader GetLatestValue method (#779)

* add support for passing in a values.Value type to the contract readers GetLatestValue and QueryKey methods

---------

Co-authored-by: Sri Kidambi <1702865+kidambisrinivas@users.noreply.github.com>
Co-authored-by: Cedric Cordenier <cedric.cordenier@smartcontract.com>

* [CAPPL-31] feat(values): adds support for time.Time as value (#787)

* feat(values): adds support for time.Time as value

* chore(deps): updates .tool-versions

* refactor(values): uses primitive type in protos

* feat(values): support float64 values (#799)

* confidence level from string (#802)

* Float32/Float64 wrapping (#804)

* feat: implement sdk logger (#762)

* Add MustEmbed Constraint to Contract Reader (#801)

Reintroducing the must embed constraint to `ContractReader` implementations to
ensure that all implementations of `ContractReader` embed the `UnimplementedContractReader`.

If an implementation contains the unemplemented struct, changes to the interface
will flow down to all implementations without introducing breaking changes.

* Updated TestStruct to enable advanced querying (#798)

* Updated TestStruct to enable advanced querying

* linting fixes

* Update pkg/codec/encodings/type_codec_test.go

Co-authored-by: Clement <clement.erena78@gmail.com>

* Update pkg/codec/encodings/type_codec_test.go

Co-authored-by: Clement <clement.erena78@gmail.com>

* Fixed codec tests

---------

Co-authored-by: Clement <clement.erena78@gmail.com>

* Properly support the range of uint64 and allow big int to unwrap into smaller integer types (#810)

* Extract expirable cache abstraction for reuse (#807)

* expirable_cache

* remove cache (#812)

* CCIP-3555 Attestation encoder interfaces (#813)

* Attestation encoder interfaces

* Attestation encoder interfaces

* Attestation encoder interfaces

* Comment

* [BCF-3392]  - ContractReaderByIDs Wrapper (#797)

* WIP

* Update ContractReaderByIDs interface method names

* Unexpose types.ContractReader in contractReaderByIDs

* Add multiple contract address support to fakeContractReader for tests

* Add GetLatestValue unit test for contractReaderByIDs

* Add GetLatestValue unit test for QueryKey

* Add BatchGetLatestValues unit test for CR by custom IdDs wrapper

* Rm ContractReaderByIDs interface and export the struct

* Change ContractReaderByIDs wrapper Unbind handling

* Improve ContractReaderByIDs wrapper err handling

* Remove mockery usage from ContractReaderByIDs tests

* lint

* pkg/types/ccipocr3: add DestExecData to RampTokenAmount (#817)

* pkg/types/ccipocr3: add DestExecData to RampTokenAmount

* fix test

* Allow the creation of maps from string to capbility outputs. (#815)

* Add the FeeValueJuels field to ccipocr3.Message (#819)

* feat(observability-lib): improve alerts rule (#803)

* feat(observability-lib): improve alerts rule

* chore(observability-lib): README + folder structure (#806)

* chore(observability-lib): README + folder structure

* feat(observability-lib): variable add current + includeAll options (#808)

* chore(README): small corrections

* chore(README): example improved

* chore(README): add references to dashboards examples

* feat(observability-lib): refactor exportable func + link to godoc

* fix(observability-lib): cmd errors returns

* enable errorf check (#826)

* Make overridding the encoder first-class

* Update mocks

* Mock updates

* Adjust tests

* Fix mock

* Fix mock

* Update mock

* Linting

---------

Co-authored-by: Cedric Cordenier <cedric.cordenier@smartcontract.com>
Co-authored-by: dimitris <dimitrios.kouveris@smartcontract.com>
Co-authored-by: Sri Kidambi <1702865+kidambisrinivas@users.noreply.github.com>
Co-authored-by: Clement <clement.erena78@gmail.com>
Co-authored-by: Ryan Tinianov <tinianov@live.com>
Co-authored-by: Street <5597260+MStreet3@users.noreply.github.com>
Co-authored-by: Jordan Krage <jmank88@gmail.com>
Co-authored-by: Patrick <patrick.huie@smartcontract.com>
Co-authored-by: Matthew Pendrey <matthew.pendrey@gmail.com>
Co-authored-by: Gabriel Paradiso <gaboparadiso@gmail.com>
Co-authored-by: Awbrey Hughlett <athughlett@gmail.com>
Co-authored-by: Silas Lenihan <32529249+silaslenihan@users.noreply.github.com>
Co-authored-by: Mateusz Sekara <mateusz.sekara@gmail.com>
Co-authored-by: ilija42 <57732589+ilija42@users.noreply.github.com>
Co-authored-by: Makram <makramkd@users.noreply.github.com>
Co-authored-by: Ryan Stout <rstout610@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants