-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
9e138d9
to
103fd76
Compare
103fd76
to
bc34f98
Compare
pkg/codec/config.go
Outdated
// 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"},
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good now
Requested changes made. Moving forward with Ilija's approval.
7a5b2dd
to
7374f74
Compare
No description provided.