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

(feat) Add PreCodec modifier #961

Merged
merged 1 commit into from
Dec 13, 2024
Merged

(feat) Add PreCodec modifier #961

merged 1 commit into from
Dec 13, 2024

Conversation

justinkaseman
Copy link
Contributor

@justinkaseman justinkaseman commented Dec 4, 2024

No description provided.

// A factory function that given an encoding scheme, returns a specific codec.
// This allows encoding and decoding implementations to be handled outside of the modifier.
// The map value given to "Fields" will be used to initialize the codec.
CodecFactory func(typeABI string) types.RemoteCodec
Copy link
Contributor

Choose a reason for hiding this comment

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

@ilija42 I think this is the first use case we have for passing a function as part of the config right?. I think we need to review the implications of allowing this since it would mean that the configuration cannot be serialized/deserialized and force the config to be a go binary.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have an address modifier which gets injected at runtime, but maintains the ability to serialize/deserialize because the CR injects the functionality automatically based on the config. I wonder if we can do something similar here.
CC @justinkaseman what are the different codec factories that would be injected here? Can we have a constant in the modifier config which injects different things inside of the chain Relayers in a switch case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is an example of what one would look like for the current Capability Encoder, which currently only supports EVM.

Usage through the OCR3 Capability looks like passing it config as so:

consensus := ocr3cap.ReduceConsensusConfig[computeOutput]{
		Encoder: ocr3cap.EncoderEVM,
		EncoderConfig: map[string]any{
		    "subabi": map[string]any{"Reports.Bundle": "uint256 Ask, uint256 Bid"},
		    "abi": "(bytes32 FeedID, bytes Bundle, uint32 Timestamp)[] Reports",
		},

--

I'm not sure that I see a use case for passing more than one factory at once into the modifier. The codec gets injected one level up in the Encoder. Imagining a different chain Relayer (e.g. a non-EVM chain), the switch case would live in the Encoder and pick which factory to use in the modifier based on the chain family.

One fringe use case may be mixed encodings, such as wanting part of the report encoded for EVM and one part for non-EVM. For this we could just use multiple chained modifiers, one per chain family. So the user would pass something more like:

		    "subabi": map[string]any{
                           "evm": map[string]any{"Reports.BundleEVM": "uint256 Ask, uint256 Bid"},
                           "nonevm": map[string]any{"Reports.BundleNonEVM": "uint256 Ask, uint256 Bid"},
                     }

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

If we can make this modifier more static then we wouldn't break the serialization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a change similar to AddressModifier!

// 'Off-chain' values will be overwritten with the encoded data as a byte array.
// 'On-chain' values will be typed using the optimistic types from the codec.
// This is useful when wanting to move the data as generic bytes.
type PreCodecModifierConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add more detailed documentation and probably examples in the doc?. Currently codec and codec modifiers are complex from an usability standpoint and it would be great to have more docs/examples for this new codec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an example! Let me know what else you think is missing and I can add more words

pkg/codec/precodec.go Outdated Show resolved Hide resolved
pkg/codec/config.go Outdated Show resolved Hide resolved
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.

Looks better now, just need the accompanying EVM PR, and maybe adding a function in other repos(at least Solana) that says that this modifier is not supported

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.

looks good now

@justinkaseman justinkaseman dismissed pablolagreca’s stale review December 13, 2024 17:36

Requested changes made. Moving forward with Ilija's approval.

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.

4 participants