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

Implement extra args codec #16016

Open
wants to merge 33 commits into
base: solana-offchain-plugin
Choose a base branch
from

Conversation

huangzhen1997
Copy link
Contributor

@huangzhen1997 huangzhen1997 commented Jan 21, 2025

Jira
extra args codec for OCR message. Convert []byte into map[string]any format depends on the source chain.

Copy link
Contributor

Flakeguard Summary

Ran new or updated tests between develop and a757a6e (NONEVM-1163/implement-extra-args-codec).

View Flaky Detector Details | Compare Changes

Found Flaky Tests ❌

Name Pass Ratio Panicked? Timed Out? Race? Runs Successes Failures Skips Package Package Panicked? Avg Duration Code Owners
Test_decodeExtraArgs 0.00% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipevm false 40ms @smartcontractkit/ccip-offchain
Test_decodeExtraArgs/SVMv1 0.00% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipevm false 0s @smartcontractkit/ccip-offchain

Artifacts

For detailed logs of the failed tests, please refer to the artifact failed-test-results-with-logs.json.

Copy link
Contributor

github-actions bot commented Jan 21, 2025

AER Report: CI Core ran successfully ✅

aer_workflow , commit

AER Report: Operator UI CI ran successfully ✅

aer_workflow , commit

@huangzhen1997 huangzhen1997 changed the base branch from develop to solana-offchain-plugin January 21, 2025 19:41
@huangzhen1997 huangzhen1997 changed the base branch from solana-offchain-plugin to develop January 21, 2025 19:42
@huangzhen1997 huangzhen1997 changed the title Use SVM ABI, needs to check test Implement extra args codec Jan 21, 2025
@@ -43,6 +50,61 @@ func decodeExtraArgsV1V2(extraArgs []byte) (gasLimit *big.Int, err error) {
return ifaces[0].(*big.Int), nil
}

func decodeExtraArgsSVMV1(extraArgs []byte) (*message_hasher.ClientSVMExtraArgsV1, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a method to decode from an EVM source chain right?

EVMExtraArgsKey: gas,
}, nil

case chainsel.FamilySolana:
Copy link
Contributor

Choose a reason for hiding this comment

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

The switch on family here is on the source chain selector, meaning this case applies when source was Solana chain.
Thus decoding this requires Solana decoder.
But the implementation is using EVM decoder.

Copy link
Contributor

Flakeguard Summary

Ran new or updated tests between develop and 7253bba (NONEVM-1163/implement-extra-args-codec).

View Flaky Detector Details | Compare Changes

Found Flaky Tests ❌

Name Pass Ratio Panicked? Timed Out? Race? Runs Successes Failures Skips Package Package Panicked? Avg Duration Code Owners
Test_decodeExtraArgs 0.00% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipevm false 43.333333ms @smartcontractkit/ccip-offchain
Test_decodeExtraArgs/SVMv1 0.00% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipevm false 3.333333ms @smartcontractkit/ccip-offchain

Artifacts

For detailed logs of the failed tests, please refer to the artifact failed-test-results-with-logs.json.

Comment on lines 33 to 41
case chainsel.FamilyEVM:
gas, err1 := decodeExtraArgsV1V2(extraArgs)
if err1 != nil {
return nil, fmt.Errorf("failed to decode EVM extra data, %w", err)
}

return map[string]any{
EVMExtraArgsKey: gas,
}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be tempted to do some minor refactoring here so you can write it like this:

Suggested change
case chainsel.FamilyEVM:
gas, err1 := decodeExtraArgsV1V2(extraArgs)
if err1 != nil {
return nil, fmt.Errorf("failed to decode EVM extra data, %w", err)
}
return map[string]any{
EVMExtraArgsKey: gas,
}, nil
case chainsel.FamilyEVM:
return decodeExtraArgsV1V2(extraArgs)

Maybe even some moderate refactoring to avoid having SVM code in the EVM package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

decodeExtraArgsV1V2 returns *big.int. The return type needs to be map[string]any

Copy link
Contributor

Choose a reason for hiding this comment

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

The way I understand, the SVMExtraArgsv1 is defined for EVM onchain, and requires abi decoding, which is all EVM

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I said there would be minor refactoring.

@huangzhen1997 huangzhen1997 changed the base branch from develop to solana-offchain-plugin January 21, 2025 21:20
@huangzhen1997 huangzhen1997 marked this pull request as ready for review January 21, 2025 22:25
@huangzhen1997 huangzhen1997 requested review from a team as code owners January 21, 2025 22:25
@huangzhen1997 huangzhen1997 requested review from pavel-raykov, asoliman92, makramkd, dimkouv and mateusz-sekara and removed request for a team January 21, 2025 22:25
Copy link
Contributor

Flakeguard Summary

Ran new or updated tests between solana-offchain-plugin and a5f84ac (NONEVM-1163/implement-extra-args-codec).

View Flaky Detector Details | Compare Changes

Found Flaky Tests ❌

Name Pass Ratio Panicked? Timed Out? Race? Runs Successes Failures Skips Package Package Panicked? Avg Duration Code Owners
Test_decodeExtraArgs 0.00% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipevm false 46.666666ms @smartcontractkit/ccip-offchain
Test_decodeExtraArgs/decode_extra_args_into_map_svm 0.00% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipevm false 10ms @smartcontractkit/ccip-offchain

Artifacts

For detailed logs of the failed tests, please refer to the artifact failed-test-results-with-logs.json.

@@ -55,20 +55,26 @@ func DecodeExtraArgsToMap(extraArgs []byte) (map[string]any, error) {
}

var method string
var extraByteOffset int
// for EVMExtraArgs, the first four bytes is the method name
// for SVMExtraArgs there's the four bytes plus another 32 bytes padding for the dynamic array
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move these comments to the actual case block where you set extraByteOffset

Comment on lines 20 to 36
func (ExtraArgsCodec) DecodeExtraData(extraArgs cciptypes.Bytes, sourceChainSelector cciptypes.ChainSelector) (map[string]any, error) {
family, err := chainsel.GetSelectorFamily(uint64(sourceChainSelector))
if err != nil {
return nil, fmt.Errorf("failed to get chain family for selector %d: %w", sourceChainSelector, err)
}

switch family {
case chainsel.FamilyEVM:
return ccipevm.DecodeExtraArgsToMap(extraArgs)

case chainsel.FamilySolana:
return ccipsolana.DecodeExtraArgsToMap(extraArgs)

default:
return nil, fmt.Errorf("unsupported family for extra args type %s", family)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍

Comment on lines 67 to 70
case string(svmExtraArgsV1Tag):
// for SVMExtraArgs there's the four bytes plus another 32 bytes padding for the dynamic array
method = svmV1DecodeName
extraByteOffset = 36
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is no longer needed because common would call the Solana version of this function directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for the case when source chain is EVM, and we need ABI decoding instead of Borsh

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 add some comments with pointers to the onchain code? i.e. something like we've done here.

Comment on lines 12 to 13
// DecodeExtraArgsToMap is a helper function for converting Borsh encoded extra args bytes into map[string]any, which will be saved in ocr report.message.ExtraArgsDecoded
func DecodeExtraArgsToMap(extraArgs []byte) (map[string]any, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously, the EVM version had this comment and a special offset. What happened to it?

	case string(svmExtraArgsV1Tag):
		// for SVMExtraArgs there's the four bytes plus another 32 bytes padding for the dynamic array
		method = svmV1DecodeName
		extraByteOffset = 36

@@ -20,6 +20,10 @@ import (

ccipcommon "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/common"

<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

Merge conflicts need resolving.

Comment on lines 81 to 84
// for SVMExtraArgs there's the four bytes plus another 32 bytes padding for the dynamic array
// https://github.com/smartcontractkit/chainlink/blob/33c0bda696b0ed97f587a46eacd5c65bed9fb2c1/contracts/src/v0.8/ccip/libraries/Client.sol#L57
method = svmV1DecodeName
extraByteOffset = 36
Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't see why this is 36 instead of 4. It looks like it's encoded the same way as EVM args are encoded: https://github.com/smartcontractkit/chainlink/blob/33c0bda696b0ed97f587a46eacd5c65bed9fb2c1/contracts/src/v0.8/ccip/libraries/Client.sol#L74C35-L74C62

Copy link
Contributor Author

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.

Could we rename or move these functions related to decoding to appropriately named files?
helpers.go seems like a bad place.
Maybe call them extradatadecoder.go

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