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 19 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

aer_workflow , commit , Clean Go Tidy & Generate , Detect Changes , Scheduled Run Frequency , GolangCI Lint (core/scripts) , Core Tests (go_core_tests) , GolangCI Lint (.) , Core Tests (go_core_tests_integration) , GolangCI Lint (integration-tests/load) , Core Tests (go_core_ccip_deployment_tests) , GolangCI Lint (integration-tests) , Core Tests (go_core_fuzz) , GolangCI Lint (deployment) , test-scripts , Core Tests (go_core_race_tests) , lint , SonarQube Scan

1. Too Many Requests - 429:[Setup NodeJS]

Source of Error:
Setup NodeJS	2025-01-24T22:50:23.9668101Z  ERR_PNPM_FETCH_429  GET https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz: Too Many Requests - 429
Setup NodeJS	2025-01-24T22:50:24.0113606Z ##[error]Process completed with exit code 1.

Why: The error indicates that the npm registry is throttling requests due to too many requests being made in a short period, resulting in a 429 status code.

Suggested fix: Implement retry logic with exponential backoff or use a caching mechanism to reduce the number of requests made to the npm registry.

2. Improperly encoded boolean value:[Run tests]

Source of Error:
Run tests	2025-01-24T23:03:22.2848931Z --- FAIL: Test_decodeExtraArgs (0.01s)
Run tests	2025-01-24T23:03:22.2849443Z --- FAIL: Test_decodeExtraArgs/decode_extra_args_into_map_svm (0.00s)
Run tests	2025-01-24T23:03:22.2850067Z helpers_test.go:91: 
Run tests	2025-01-24T23:03:22.2851140Z 	Error Trace:	/home/runner/work/chainlink/chainlink/core/capabilities/ccip/ccipevm/helpers_test.go:91
Run tests	2025-01-24T23:03:22.2851842Z 	Error: 	Received unexpected error:
Run tests	2025-01-24T23:03:22.2853046Z 	 	abi decode extra args decodeSVMExtraArgsV1: abi: improperly encoded boolean value
Run tests	2025-01-24T23:03:22.2853801Z 	Test: 	Test_decodeExtraArgs/decode_extra_args_into_map_svm
Run tests	2025-01-24T23:03:22.2854484Z FAIL

Why: The test is failing because the ABI (Application Binary Interface) is not correctly encoding a boolean value, which is causing the decode function to throw an error.

Suggested fix: Ensure that the boolean values are correctly encoded in the ABI before decoding. Review the encoding logic and correct any discrepancies.

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 af29932 (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/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 0s @smartcontractkit/ccip-offchain
Test_decodeExtraArgs 0.00% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipsolana false 0s @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/ccipsolana false 0s @smartcontractkit/ccip-offchain

Artifacts

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

solana.SystemProgramID,
},
extraArgs := ccip_router.AnyExtraArgs{
// TODO wait for onchain team fix this AnyExtraArgs
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the source chain here is SVM, we won't need these SVM specific fields here, since you will not go from SVM -> SVM.
Atleast not until CCIP supports another SVM chain apart from Solana.

For testing right now, we should be good with just EVM specific fields in this struct.

Copy link
Contributor

Flakeguard Summary

Ran new or updated tests between solana-offchain-plugin and 2597b48 (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/ccipsolana false 0s @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/ccipsolana false 0s @smartcontractkit/ccip-offchain

Artifacts

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

t.Run("decode extra args into map svm", func(t *testing.T) {
key, err := solana.NewRandomPrivateKey()
require.NoError(t, err)
encoded, err := d.contract.EncodeSVMExtraArgsV1(nil, message_hasher.ClientSVMExtraArgsV1{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prashantkumar1982 This is the failing test I was talking about. By inspecting the encoded bytes, I suspect this EncodeSVMExtraArgsV1 is not working properly.

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 also use d.contract.DecodeSVMExtraArgsV1(), and see if that gives you back the same fields as what you encoded?

Copy link
Contributor Author

@huangzhen1997 huangzhen1997 Jan 24, 2025

Choose a reason for hiding this comment

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

Yep, just updated the test. Used the d.contract.DecodeSVMExtraArgsV1 constructor to create the payload, but it seems to be the same thing. When I try encoding, the encoded bytes cannot be unpacked correctly either.

Copy link
Contributor

Flakeguard Summary

Ran new or updated tests between solana-offchain-plugin and a99bdcc (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/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 0s @smartcontractkit/ccip-offchain

Artifacts

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

core/capabilities/ccip/oraclecreator/plugin.go Outdated Show resolved Hide resolved
integration-tests/smoke/ccip/ccip_reader_test.go Outdated Show resolved Hide resolved
require.NoError(t, err)
output, err := DecodeExtraArgsToMap(buf.Bytes())
require.NoError(t, err)
require.Len(t, output, 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add require.Equal checks on the contents of the output map?

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 decode extra data, %w", err)
Copy link
Contributor

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 extra data, %w", err)
return nil, fmt.Errorf("failed to get chain family for selector %d: %w", sourceChainSelector, err)

"github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_router"
)

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.

Good rule of thumb to add a docstring to exported methods


m, err := DecodeExtraArgsToMap(encoded)
require.NoError(t, err)
require.Len(t, m, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets add require.Equal checks on the contents of the map.

Copy link
Contributor

Choose a reason for hiding this comment

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

The check for contents is already in the below 3 lines (53-55).

Copy link
Contributor

Choose a reason for hiding this comment

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

the comparison is between a map, vs fields of a struct, so require.Equals will likely not work


m, err := DecodeExtraArgsToMap(encoded)
require.NoError(t, err)
require.Len(t, m, 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here re: equality checks.

Copy link
Contributor

Flakeguard Summary

Ran new or updated tests between solana-offchain-plugin and 5fe01d2 (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/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 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

Flakeguard Summary

Ran new or updated tests between solana-offchain-plugin and c49c04b (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/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 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

Flakeguard Summary

Ran new or updated tests between solana-offchain-plugin and afcd808 (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/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 0s @smartcontractkit/ccip-offchain

Artifacts

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

@huangzhen1997 huangzhen1997 requested a review from a team as a code owner January 24, 2025 16:52
Copy link
Contributor

Flakeguard Summary

Ran new or updated tests between solana-offchain-plugin and 6bc6b29 (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 3.333333ms @smartcontractkit/ccip-offchain

Artifacts

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


m, err := DecodeExtraArgsToMap(encoded)
require.NoError(t, err)
require.Len(t, m, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

The check for contents is already in the below 3 lines (53-55).


m, err := DecodeExtraArgsToMap(encoded)
require.NoError(t, err)
require.Len(t, m, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

the comparison is between a map, vs fields of a struct, so require.Equals will likely not work

require.NoError(t, err)

_, err = DecodeExtraArgsToMap(encoded)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

once the test passes, we should verify the decoded data is same as originally passed in data.

t.Run("decode extra args into map svm", func(t *testing.T) {
key, err := solana.NewRandomPrivateKey()
require.NoError(t, err)
encoded, err := d.contract.EncodeSVMExtraArgsV1(nil, message_hasher.ClientSVMExtraArgsV1{
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 also use d.contract.DecodeSVMExtraArgsV1(), and see if that gives you back the same fields as what you encoded?

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.

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