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

support for decoding destexecdata #472

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

support for decoding destexecdata #472

wants to merge 19 commits into from

Conversation

huangzhen1997
Copy link
Collaborator

@huangzhen1997 huangzhen1997 commented Jan 17, 2025

core ref: 663859cd548ca40384ca02ac576961b5b5e53fc5

Add new function to the extradatacodec interface for parsing message destexecdata. The destExecData is used when Any2EVM or SVM2Any messages for storing uint32 dest chain gas prices in bytes. Because ABI uses big-endian encoding while Borsch uses little-endian encoding.

Corresponding change for chainlink repo: smartcontractkit/chainlink#15944

@@ -21,7 +21,8 @@ type MessageHasher interface {
}

type ExtraDataCodec interface {
DecodeExtraData(ExtraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
DecodeExtraArgs(extraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: add comment on which exact field on the Message struct does this work on.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need comments on this entire struct, please add doc comments so this is understandable to people who maintain this codebase

@@ -21,7 +21,8 @@ type MessageHasher interface {
}

type ExtraDataCodec interface {
DecodeExtraData(ExtraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
DecodeExtraArgs(extraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
DecodeDestExecData(destExecData Bytes, sourceChainSelector ChainSelector) (Bytes, error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

To what format should this function decode to?
The input is []byte, and output is []byte, so its confusing.

Also, since this is []byte, it means theoretically a family can encode even a struct here, even though today EVM and SVM just use uint32. So I think, to handle any generic struct, we likely need the format similar to the ExtraArgsDecoded.

All the fields here in the generic Any2Any Message ideally should be in a format that is chain agnostic. So we can't have these in either source/destination specific coding.

Lets confirm with CCIP team if they agree here, or have other suggestions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@winder @makramkd What's your guys thoughts about this ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you ask the onchain team? They confirmed the top level ExtraArgs is an object. Is this an object also?

At a minimum, I expect that this type should be any or map[string]any.

@@ -21,7 +21,8 @@ type MessageHasher interface {
}

type ExtraDataCodec interface {
DecodeExtraData(ExtraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
DecodeExtraArgs(extraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
DecodeDestExecData(destExecData Bytes, sourceChainSelector ChainSelector) (Bytes, error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: suggestion: function name rename to decodeTokenAmountDestExecData

@huangzhen1997 huangzhen1997 marked this pull request as ready for review January 21, 2025 04:10
@makramkd
Copy link
Collaborator

The destExecData is used when Any2EVM or SVM2Any messages for storing uint32 dest chain gas prices in bytes.

Hey @huangzhen1997 this doesn't make sense to me, why would we do this in ccip? I'm not aware of this as a feature or functionality.

@@ -21,7 +21,8 @@ type MessageHasher interface {
}

type ExtraDataCodec interface {
DecodeExtraData(ExtraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
DecodeExtraArgs(extraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need comments on this entire struct, please add doc comments so this is understandable to people who maintain this codebase

@@ -21,7 +21,8 @@ type MessageHasher interface {
}

type ExtraDataCodec interface {
DecodeExtraData(ExtraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
DecodeExtraArgs(extraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
DecodeTokenAmountDestExecData(destExecData Bytes, sourceChainSelector ChainSelector) (Bytes, error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a comment here on what this is

@@ -21,7 +21,8 @@ type MessageHasher interface {
}

type ExtraDataCodec interface {
DecodeExtraData(ExtraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
DecodeExtraArgs(extraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
DecodeTokenAmountDestExecData(destExecData Bytes, sourceChainSelector ChainSelector) (Bytes, error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see, I believe this is referring to : https://github.com/smartcontractkit/chainlink/blob/99860e4df73602187a926df4cc65c3919232d8f6/contracts/src/v0.8/ccip/libraries/Internal.sol#L230-L232

Lets make that very clear here that this is what this interface is doing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes

for i, token := range msg.Message.TokenAmounts {
token.DestExecData, err = r.extraDataCodec.DecodeTokenAmountDestExecData(token.DestExecData, sourceChainSelector)
if err != nil {
return nil, fmt.Errorf("failed to decode DestExecData: %w", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("failed to decode DestExecData: %w", err)
return nil, fmt.Errorf("failed to decode token amount destExecData (%v): %w", tokenAmount, err)

if err != nil {
return nil, fmt.Errorf("failed to decode ExtraArgs: %w", err)
}
msg.Message.Header.OnRamp = onRampAddress

for i, token := range msg.Message.TokenAmounts {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for i, token := range msg.Message.TokenAmounts {
for i, tokenAmount := range msg.Message.TokenAmounts {

@huangzhen1997
Copy link
Collaborator Author

Not sure how to fix the CI test, it's using a different Chainlink repo I provided in PR description.

DecodeExtraData(ExtraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
// DecodeExtraArgs reformat bytes into a chain agnostic map[string]any representation for extra args
DecodeExtraArgs(extraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
// DecodeTokenAmountDestExecData provide special treatment for DestExecData in token message depends on source chain
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment doesn't tell me much, can we improve it by saying:

  • what it does
  • why it does it
    ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm waiting for feedback here so I will have more details to provide in comment

Copy link
Collaborator

Choose a reason for hiding this comment

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

See the thread, posted a message

@@ -21,7 +21,10 @@ type MessageHasher interface {
}

type ExtraDataCodec interface {
DecodeExtraData(ExtraArgs Bytes, sourceChainSelector ChainSelector) (map[string]any, error)
// DecodeExtraArgs reformat bytes into a chain agnostic map[string]any representation for extra args
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto here

Copy link

Metric destExecData main
Coverage 76.6% 76.5%

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