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

Chain Reader config improvements #11679

Merged
merged 8 commits into from
Jan 16, 2024
Merged

Conversation

jmank88
Copy link
Contributor

@jmank88 jmank88 commented Jan 3, 2024

  • core/services/job: remove JSONConfig.Bytes hack
  • Shorten median chain reader smoke test abi
  • Improve ReadType UX by changing the enum to string

Copy link
Contributor

github-actions bot commented Jan 3, 2024

I see that you haven't updated any README files. Would it make sense to do so?

Copy link
Contributor

github-actions bot commented Jan 3, 2024

I see that you haven't updated any CHANGELOG files. Would it make sense to do so?

Copy link
Contributor

@ilija42 ilija42 left a comment

Choose a reason for hiding this comment

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

This doesn't work, it just ends up sending bytes representation of json in a string to get unmarshalled into RelayConfig.
for eg. codec looks like this
"codec\":\"[123 34 99 104 97 105 110 67 111 100 101 99 67 111 110 102 105 103 34 32 58 123 34 77 101 100 105 97 110 82 101 112 111 114 116 34 58 123 34 84 121 112 101 65 98 105 34 58 32 34 91 123 92 34 78 97 109 101 92 34 58 32 92 34 84 105 109 101 115 116 97 109 112 92 34 44 92 34 84 121 112 101 92 34 58 32 92 34 117 105 110 116 51 50 92 34 125 44 123 92 34 78 97 109 101 92 34 58 32 92 34 79 98 115 101 114 118 101 114 115 92 34 44 92 34 84 121 112 101 92 34 58 32 92 34 98 121 116 101 115 51 50 92 34 125 44 123 92 34 78 97 109 101 92 34 58 32 92 34 79 98 115 101 114 118 97 116 105 111 110 115 92 34 44 92 34 84 121 112 101 92 34 58 32 92 34 105 110 116 49 57 50 91 93 92 34 125 44 123 92 34 78 97 109 101 92 34 58 32 92 34 74 117 101 108 115 80 101 114 70 101 101 67 111 105 110 92 34 44 92 34 84 121 112 101 92 34 58 32 92 34 105 110 116 49 57 50 92 34 125 93 34 125 125 125]\"

fails here to be exact

@jmank88
Copy link
Contributor Author

jmank88 commented Jan 3, 2024

Debugging TestIntegration_OCR2/chain-reader reveals the real problem: we use type RelayConfig struct inside of (o *RelayOpts) RelayConfig(), which expects chainReader and codec to be JSON objects, but we are setting them as encoded JSON string in the TOML. The other fields don't have this problem because they are used as-is for both TOML and JSON. Why are we doing this usual approach? We already bridge TOML to JSON - why don't we continue to use that same pattern?

IMHO following the existing style leads to a much better user experience by producing more readable code and we can completely avoid escpaing JSON:

[relayConfig]
chainID = 1337
fromBlock = 42
[relayConfig.chainReader.chainContractReaders.median]
contractABI = '''
[
  {
    "inputs": [
      {
        "internalType": "contractLinkTokenInterface",
        "name": "link",
        "type": "address"
      }
    ]
  }
]
'''
[relayConfig.chainReader.chainContractReaders.median.chainReaderDefinitions.LatestTransmissionDetails]
chainSpecificName = "latestTransmissionDetails"
readType = 0
[[relayConfig.chainReader.chainContractReaders.median.chainReaderDefinitions.LatestTransmissionDetails.output_modifications]]
type = "rename"
fields = {
  LatestAnswer_ = "LatestAnswer",
  LatestTimestamp_ = "LatestTimestamp"
}
[relayConfig.chainReader.chainContractReaders.median.chainReaderDefinitions.LatestRoundRequested]
chainSpecificName = "RoundRequested"
"params": {
"requester": ""
},
"readType": 1
[relayConfig.codec.chainCodecConfig.MedianReport]
TypeAbi = '''
[
  {
    "Name": "Timestamp",
    "Type": "uint32"
  },
  {
    "Name": "Observers",
    "Type": "bytes32"
  },
  {
    "Name": "Observations",
    "Type": "int192[]"
  },
  {
    "Name": "JuelsPerFeeCoin",
    "Type": "int192"
  }
]
'''

@ilija42
Copy link
Contributor

ilija42 commented Jan 3, 2024

Debugging TestIntegration_OCR2/chain-reader reveals the real problem: we use type RelayConfig struct inside of (o *RelayOpts) RelayConfig(), which expects chainReader and codec to be JSON objects, but we are setting them as encoded JSON string in the TOML. The other fields don't have this problem because they are used as-is for both TOML and JSON. Why are we doing this usual approach? We already bridge TOML to JSON - why don't we continue to use that same pattern?

IMHO following the existing style leads to a much better user experience by producing more readable code and we can completely avoid escpaing JSON:

[relayConfig]
chainID = 1337
fromBlock = 42
[relayConfig.chainReader.chainContractReaders.median]
contractABI = '''
[
  {
    "inputs": [
      {
        "internalType": "contractLinkTokenInterface",
        "name": "link",
        "type": "address"
      }
    ]
  }
]
'''
[relayConfig.chainReader.chainContractReaders.median.chainReaderDefinitions.LatestTransmissionDetails]
chainSpecificName = "latestTransmissionDetails"
readType = 0
[[relayConfig.chainReader.chainContractReaders.median.chainReaderDefinitions.LatestTransmissionDetails.output_modifications]]
type = "rename"
fields = {
  LatestAnswer_ = "LatestAnswer",
  LatestTimestamp_ = "LatestTimestamp"
}
[relayConfig.chainReader.chainContractReaders.median.chainReaderDefinitions.LatestRoundRequested]
chainSpecificName = "RoundRequested"
"params": {
"requester": ""
},
"readType": 1
[relayConfig.codec.chainCodecConfig.MedianReport]
TypeAbi = '''
[
  {
    "Name": "Timestamp",
    "Type": "uint32"
  },
  {
    "Name": "Observers",
    "Type": "bytes32"
  },
  {
    "Name": "Observations",
    "Type": "int192[]"
  },
  {
    "Name": "JuelsPerFeeCoin",
    "Type": "int192"
  }
]
'''

still a bit of an eyesore, but looks way better than that string escaping hell, lgtm

@jmank88
Copy link
Contributor Author

jmank88 commented Jan 3, 2024

still a bit of an eyesore, but looks way better than that string escaping hell, lgtm

This was a bit hacky. Working on a cleaner version.

@jmank88 jmank88 force-pushed the rm-workaround branch 2 times, most recently from 96b9e12 to 7d81ca4 Compare January 3, 2024 23:58
@jmank88 jmank88 requested a review from ilija42 January 4, 2024 00:20
@ilija42 ilija42 changed the title core/services/job: remove JSONConfig.Bytes hack Chain Reader config improvements Jan 4, 2024
@jmank88 jmank88 force-pushed the rm-workaround branch 3 times, most recently from 2ca90fe to 5ccf80b Compare January 5, 2024 01:20
Copy link
Contributor

@nolag nolag left a comment

Choose a reason for hiding this comment

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

Please just verify that it's going through by putting invalid config in the field names or something to see it fail. Last time, it turned out to be ignoring the config. I wish there was an easy way to verify it's using the chain reader and codec...

@reductionista
Copy link
Contributor

Please just verify that it's going through by putting invalid config in the field names or something to see it fail. Last time, it turned out to be ignoring the config. I wish there was an easy way to verify it's using the chain reader and codec...

For ChainReader, could we fix that by adding an INFO log message to the OCR2 delegate that spawns the median plugin, or maybe the median plugin itself? At least one of those places, maybe both, should be able to check whether ChainReader got initialized or is nil. Although if its only available in the plugin itself, not sure where those logs will go to

@jmank88
Copy link
Contributor Author

jmank88 commented Jan 14, 2024

Please just verify that it's going through by putting invalid config in the field names or something to see it fail. Last time, it turned out to be ignoring the config. I wish there was an easy way to verify it's using the chain reader and codec...

For ChainReader, could we fix that by adding an INFO log message to the OCR2 delegate that spawns the median plugin, or maybe the median plugin itself? At least one of those places, maybe both, should be able to check whether ChainReader got initialized or is nil. Although if its only available in the plugin itself, not sure where those logs will go to

Does the chain reader report itself as a named service? If so, you could check the /health endpoint to see if it is running.
Edit: I might have to fix this first, but it should be unblocked this week and in by the end of the month 🤞 smartcontractkit/chainlink-common#206

@cl-sonarqube-production
Copy link

SonarQube Quality Gate

Quality Gate failed

Failed condition 73.1% 73.1% Coverage on New Code (is less than 75%)

See analysis details on SonarQube

@jmank88 jmank88 merged commit d5c1100 into BCF-2612-ChainReader-Next Jan 16, 2024
102 of 105 checks passed
@jmank88 jmank88 deleted the rm-workaround branch January 16, 2024 21:27
github-merge-queue bot pushed a commit that referenced this pull request Jan 22, 2024
* Implement skeleton interfaces, structs, & methods for ChainReader EVM POC

- Read ChainReader config in from RelayConfig
- Add some initialization and validation relay skeletons

- Use medianProviderWrapper instead of passing medianContract separately

This avoids us having to modify the signature of NewMedianFactory, which
would require further modifications to all non-evm repos and chainlink-relay

- Add chain_reader_test.go with some basic relay tests

Co-authored-by: Jordan Krage <jmank88@gmail.com>

- Add chain reader config validation
- Add chain reader config validation tests
- Add config for chain reader median contract to cr validation testcases
- Add unimplemented Encode(), Decode(), GetMaxEncodingSize(), GetMaxDecodingSize()
- Add ChainReader() method to mock provider for plugin test
- Rename relaymercury.ChainReader to MercuryChainReader, resolve name collisions
- Add tests for errors during ChainReader construction
- Propagate InvalidConfig & any other errors back to client

We should ignore Unsupported until node ops have been given ample time to migrate to the new job spec
(including a section for ChainReader config) so that we can remove the old product-specific
MedianContract component from MedianProvider. All other errors we can immediately start passing back
to the client, letting the core node decide how to handle them (eg. displaying an "invalid job spec"
message to the UI if the RelayConfig was invalid or the ContractID missing)

* Fix lint

* Fix go imports lint

* Fix go.mod require got split into two

Co-authored-by: Jordan Krage <jmank88@gmail.com>

* Run make gomodtidy

* Add tickets to chainreader TODOs

* Log when we're falling back to internal MedianContract

We had this before, at some point it accidentally got dropped

* Pass contractID, relayConfig instead of relayOpts

Also: move test for invalid contract ID to evm_test.go, & add mismatched ChainID
test while we're here since it's pretty similar

* Revert get solana sha workflow to ref develop

Co-authored-by: Jordan Krage <jmank88@gmail.com>

* Update err handling for when chain reader config is missing

* Update solana repo hash

* Improve chain reader config validation tests

* Run go mod tidy

* Update solana repo go mod reference and tidy

* fix logs dir for Solana tests

* fix solana logs path once more

* print absolue log folder location

* get abs folder in a correct way

* do it some other way

* update solana logs dir in github workflow

* Add chain Reader enabled log to NewMedianServices

* Update chainlink-solana ref and tidy

* Add logs and handle disabled chain reader when median loop is enabled

* Update go mod solana repo refs

* Improve error messages in evm chain reader and add test cases

* Update minor comment

* Run tidy

* Remove unneeded chain reader codec methods

* Remove chain reader return values as they are out of scope for this PR

* Add types for the evm

* Create a codec entry with from args, allowing us to do type checking and to have structs to use with abi.Arguments's Pack function

* Craetes a function to get the max size for abi.Argumetns, given any outermost slices have N elements

* Add codec and make chain reader use it.  Run the interface tests for both chain reader and codec.

* Add modifiers to evm chain reader and codec

* Add modifiers to evm chain reader and codec

* small fixes after merging

* Small cleanups and comments

* fix after merge

* add events

* Don't pass ctx around in tests

* Support multiple contract names and mapping them to multiple contracts.

* Upadte chain reader interface

* update go mod

* Fix address type and start the chain reader

* Update go mod references

* add epoch converting

* Simplify chain reader's bindings.

* Add smoke test and feature test for chain reader.

* lint again

* Update solana to point to newer other ones in its own integration tests...

* linter

* .

* newer solana again

* newer solana again...

* Fix bug with unnamed return params and invalid params containing the same name multiple times

* Add generated files to sonar exclude

* Update sonar again

* Methods per sonar suggestions

* Reanme function and type per PR feedback

* Generate abi, bin & wrapper for chainreader test with gethwrappers

* Update generated-wrapper-dependency-versions-do-not-edit.txt

Also: remove extra unused files

* prettier -w ChainReaderTestContract.sol

* Update to use the ErrSliceWrongLen

* Move test contract from contracts/tests to contrats/shared/test

* Fix SQ coverage exclusions

* Use modifier for time

* Update go.mod

* .github/workflows: dedupe log artifact name with tag_suffix

* [TT-792] Add Resources for New OCR2 Tests (#11702)

* Add Resources for New OCR2 Tests

* More power to the engines

* Log everything

* Chill on the power now

* Fix missing container env

* Update common

* Fix broken test

* Add encoder defs for events

* Revert "Add encoder defs for events"

This reverts commit dd99acc.

* revert the change to codec entry for event and simplify how it's done

* Add Marshal method for custom codec types.

* Updated common, still seeing not found, not sure why...

* Update feeds

* Update feeds and common to remove accidental debugging log line

* Update feeds to remove accidental log line and to add more logging to warning messages

* Fixup go mod

* Update feeds

* Remove json tag that had no business being where it was in codec entry

* Fix small lint error, likely detected from better linter in merge from dev

* Add fuzz test for codec

* Support indexed events

* PR feedback, fix typo, clear up comment, revert making a function public

* Refactored function for getting event input.

* --fix and add comments

* use maps instaed fo ToCamelCase to allow consistnacy, also safer if customers have foo and foo_ both as varibles.

* Scope native and checked type conversion to a single struct and add tests to verify that NewAt is safe and fuzz tests for sanity around it too

* Chain Reader config improvements (#11679)

* core/services/job: remove JSONConfig.Bytes hack

* Shorten chain reader cfg abi in median test, change readType string

* minimize abi; pretty formatting; use text marshaller

* integrations-tests/client: use TOML for relayconfig

* minimize chain reader median contract abi in features ocr2 test

* pretty ABI JSON

* add ModifiersConfig wrapper to include type field

* fix TestOCR2TaskJobSpec_String

---------

Co-authored-by: ilija <pavlovicilija42@gmail.com>

* Template must in types gen and small json rename for mods in chain reader def fields

* Update test contract for lint, fix toml test files after renaming the mod in prior commit

* Update common for a rename and fix tests that I broke a couple commits ago

* Move test contract

* Commit with fixed contract for codec test and add small check to if statement for arg len

* small fix to encoder, and fix config in feature test

* Remove debug line since smoke test is passing now and I need to be ready to merge

* Fix bad merge conflict

* small PR fixes

* Couple more error fixes

* update common

* update feeds to point to main

* Fix typo

* Update Solana repo refs

* Pretty chain reader test solitidty file

* Update solana

* Update solana in integation tests

* Needed to update more than just integation tests for solana.

* Update Solana ref to fix relayConfig

* Update Solana ref again

* Update solana and starknet to point to the develop branches.

* update relayer for starknet

---------

Co-authored-by: Domino Valdano <2644901+reductionista@users.noreply.github.com>
Co-authored-by: ilija <pavlovicilija42@gmail.com>
Co-authored-by: ilija42 <57732589+ilija42@users.noreply.github.com>
Co-authored-by: Jordan Krage <jmank88@gmail.com>
Co-authored-by: Bartek Tofel <bartek.tofel@smartcontract.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Adam Hamrick <adam.hamrick@smartcontract.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.

None yet

4 participants