Skip to content

Commit 709b7ec

Browse files
ogtownsendamit-momin
authored andcommitted
Add extra data codec registry support
1 parent 4dc8682 commit 709b7ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+391
-230
lines changed

core/capabilities/ccip/ccipaptos/executecodec.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/aptos-labs/aptos-go-sdk"
99
"github.com/aptos-labs/aptos-go-sdk/bcs"
10+
1011
"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
1112

1213
cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
@@ -15,16 +16,16 @@ import (
1516
// ExecutePluginCodecV1 is a codec for encoding and decoding execute plugin reports.
1617
// Compatible with ccip_offramp::offramp version 1.6.0
1718
type ExecutePluginCodecV1 struct {
18-
extraDataCodec ccipocr3.ExtraDataCodec
19+
extraDataCodec ccipocr3.ExtraDataCodecBundle
1920
}
2021

21-
func NewExecutePluginCodecV1(extraDataCodec ccipocr3.ExtraDataCodec) *ExecutePluginCodecV1 {
22+
func NewExecutePluginCodecV1(extraDataCodec ccipocr3.ExtraDataCodecBundle) *ExecutePluginCodecV1 {
2223
return &ExecutePluginCodecV1{
2324
extraDataCodec: extraDataCodec,
2425
}
2526
}
2627

27-
func (e *ExecutePluginCodecV1) Encode(ctx context.Context, report cciptypes.ExecutePluginReport) ([]byte, error) {
28+
func (e *ExecutePluginCodecV1) Encode(ctx context.Context, report ccipocr3.ExecutePluginReport) ([]byte, error) {
2829
if len(report.ChainReports) == 0 {
2930
return nil, nil
3031
}

core/capabilities/ccip/ccipaptos/executecodec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func TestExecutePluginCodecV1(t *testing.T) {
163163

164164
for _, tc := range testCases {
165165
t.Run(tc.name, func(t *testing.T) {
166-
codec := NewExecutePluginCodecV1(registeredMockExtraDataCodecMap)
166+
codec := NewExecutePluginCodecV1(ccipocr3.ExtraDataCodecMap(registeredMockExtraDataCodecMap))
167167
// randomExecuteReport now uses the new encoding internally
168168
report := tc.report(randomExecuteReport(t, tc.chainSelector, tc.gasLimit, tc.destGasAmount))
169169
bytes, err := codec.Encode(ctx, report)

core/capabilities/ccip/ccipaptos/msghasher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var (
3131
// Compatible with ccip::offramp version 1.6.0
3232
type MessageHasherV1 struct {
3333
lggr logger.Logger
34-
extraDataCodec ccipocr3.ExtraDataCodec
34+
extraDataCodec ccipocr3.ExtraDataCodecBundle
3535
}
3636

3737
type any2AptosTokenTransfer struct {
@@ -42,7 +42,7 @@ type any2AptosTokenTransfer struct {
4242
Amount *big.Int
4343
}
4444

45-
func NewMessageHasherV1(lggr logger.Logger, extraDataCodec ccipocr3.ExtraDataCodec) *MessageHasherV1 {
45+
func NewMessageHasherV1(lggr logger.Logger, extraDataCodec ccipocr3.ExtraDataCodecBundle) *MessageHasherV1 {
4646
return &MessageHasherV1{
4747
lggr: lggr,
4848
extraDataCodec: extraDataCodec,

core/capabilities/ccip/ccipaptos/pluginconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// initializePluginConfig returns a PluginConfig for Aptos chains.
1616
func initializePluginConfigFunc(chainselFamily string) ccipcommon.InitFunction {
17-
return func(lggr logger.Logger, extraDataCodec ccipocr3.ExtraDataCodec) ccipcommon.PluginConfig {
17+
return func(lggr logger.Logger, extraDataCodec ccipocr3.ExtraDataCodecBundle) ccipcommon.PluginConfig {
1818
var cwProvider ccipcommon.ChainRWProvider
1919
var transmitterFactory types.ContractTransmitterFactory
2020
var msgHasher ccipocr3.MessageHasher

core/capabilities/ccip/ccipevm/executecodec.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/ethereum/go-ethereum/accounts/abi"
99
"github.com/ethereum/go-ethereum/common"
1010
chainsel "github.com/smartcontractkit/chain-selectors"
11+
1112
"github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_6_0/offramp"
1213
cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
1314
"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
@@ -19,10 +20,10 @@ import (
1920
// - "OffRamp 1.6.0"
2021
type ExecutePluginCodecV1 struct {
2122
executeReportMethodInputs abi.Arguments
22-
extraDataCodec ccipocr3.ExtraDataCodec
23+
extraDataCodec ccipocr3.ExtraDataCodecBundle
2324
}
2425

25-
func NewExecutePluginCodecV1(extraDataCodec ccipocr3.ExtraDataCodec) *ExecutePluginCodecV1 {
26+
func NewExecutePluginCodecV1(extraDataCodec ccipocr3.ExtraDataCodecBundle) *ExecutePluginCodecV1 {
2627
abiParsed, err := abi.JSON(strings.NewReader(offramp.OffRampABI))
2728
if err != nil {
2829
panic(fmt.Errorf("parse multi offramp abi: %s", err))
@@ -38,7 +39,7 @@ func NewExecutePluginCodecV1(extraDataCodec ccipocr3.ExtraDataCodec) *ExecutePlu
3839
}
3940
}
4041

41-
func (e *ExecutePluginCodecV1) Encode(ctx context.Context, report cciptypes.ExecutePluginReport) ([]byte, error) {
42+
func (e *ExecutePluginCodecV1) Encode(ctx context.Context, report ccipocr3.ExecutePluginReport) ([]byte, error) {
4243
evmReport := make([]offramp.InternalExecutionReport, 0, len(report.ChainReports))
4344

4445
for _, chainReport := range report.ChainReports {

core/capabilities/ccip/ccipevm/executecodec_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import (
1212
"github.com/ethereum/go-ethereum/common"
1313
"github.com/ethereum/go-ethereum/core"
1414
chainsel "github.com/smartcontractkit/chain-selectors"
15+
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/mock"
17+
"github.com/stretchr/testify/require"
18+
1519
"github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_6_0/message_hasher"
1620
"github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_6_0/offramp"
1721
"github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_6_0/report_codec"
@@ -22,9 +26,6 @@ import (
2226
"github.com/smartcontractkit/chainlink-evm/pkg/utils"
2327
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/common/mocks"
2428
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
25-
"github.com/stretchr/testify/assert"
26-
"github.com/stretchr/testify/mock"
27-
"github.com/stretchr/testify/require"
2829
)
2930

3031
var randomExecuteReport = func(t *testing.T, d *testSetupData, chainSelector uint64, gasLimit *big.Int, destGasAmount uint32) cciptypes.ExecutePluginReport {
@@ -187,7 +188,7 @@ func TestExecutePluginCodecV1(t *testing.T) {
187188

188189
for _, tc := range testCases {
189190
t.Run(tc.name, func(t *testing.T) {
190-
edc := ccipocr3.ExtraDataCodec(registeredMockExtraDataCodecMap)
191+
edc := ccipocr3.ExtraDataCodecMap(registeredMockExtraDataCodecMap)
191192
codec := NewExecutePluginCodecV1(edc)
192193
report := tc.report(randomExecuteReport(t, d, tc.chainSelector, tc.gasLimit, tc.destGasAmount))
193194
bytes, err := codec.Encode(ctx, report)

core/capabilities/ccip/ccipevm/gas_helpers.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math"
66

77
"github.com/pkg/errors"
8+
89
"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
910

1011
cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
@@ -34,14 +35,14 @@ const (
3435
DestGasOverhead = 300_000 // Commit and Exec costs
3536
)
3637

37-
func NewGasEstimateProvider(codec ccipocr3.ExtraDataCodec) EstimateProvider {
38+
func NewGasEstimateProvider(codec ccipocr3.ExtraDataCodecBundle) EstimateProvider {
3839
return EstimateProvider{
3940
extraDataCodec: codec,
4041
}
4142
}
4243

4344
type EstimateProvider struct {
44-
extraDataCodec ccipocr3.ExtraDataCodec
45+
extraDataCodec ccipocr3.ExtraDataCodecBundle
4546
}
4647

4748
// CalculateMerkleTreeGas estimates the merkle tree gas based on number of requests

core/capabilities/ccip/ccipevm/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func ABITypeOrPanic(t string) abi.Type {
3232

3333
// CCIPMsgToAny2EVMMessage converts a ccipocr3.Message object to an offramp.InternalAny2EVMRampMessage object.
3434
// These are typically used to create the execution report for EVM.
35-
func CCIPMsgToAny2EVMMessage(msg ccipocr3.Message, codec ccipocr3.ExtraDataCodec) (offramp.InternalAny2EVMRampMessage, error) {
35+
func CCIPMsgToAny2EVMMessage(msg ccipocr3.Message, codec ccipocr3.ExtraDataCodecBundle) (offramp.InternalAny2EVMRampMessage, error) {
3636
var tokenAmounts []offramp.InternalAny2EVMTokenTransfer
3737
for _, rta := range msg.TokenAmounts {
3838
decodedMap, err := codec.DecodeTokenAmountDestExecData(rta.DestExecData, msg.Header.SourceChainSelector)

core/capabilities/ccip/ccipevm/manualexeclib/exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func GetMessageHashes(
2222
lggr logger.Logger,
2323
onrampAddress common.Address,
2424
ccipMessageSentEvents []onramp.OnRampCCIPMessageSent,
25-
extraDataCodec ccipocr3.ExtraDataCodec,
25+
extraDataCodec ccipocr3.ExtraDataCodecBundle,
2626
) ([][32]byte, error) {
2727
msgHasher := ccipevm.NewMessageHasherV1(
2828
lggr,
@@ -107,7 +107,7 @@ func CreateExecutionReport(
107107
ccipMessageSentEvents []onramp.OnRampCCIPMessageSent,
108108
hashes [][32]byte,
109109
flags *big.Int,
110-
extraDataCodec ccipocr3.ExtraDataCodec,
110+
extraDataCodec ccipocr3.ExtraDataCodecBundle,
111111
) (offramp.InternalExecutionReport, error) {
112112
var any2EVMs []offramp.InternalAny2EVMRampMessage
113113
for _, event := range ccipMessageSentEvents {

core/capabilities/ccip/ccipevm/msghasher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ var (
4747
// - "OnRamp 1.6.0"
4848
type MessageHasherV1 struct {
4949
lggr logger.Logger
50-
extraDataCodec ccipocr3.ExtraDataCodec
50+
extraDataCodec ccipocr3.ExtraDataCodecBundle
5151
}
5252

53-
func NewMessageHasherV1(lggr logger.Logger, extraDataCodec ccipocr3.ExtraDataCodec) *MessageHasherV1 {
53+
func NewMessageHasherV1(lggr logger.Logger, extraDataCodec ccipocr3.ExtraDataCodecBundle) *MessageHasherV1 {
5454
return &MessageHasherV1{
5555
lggr: lggr,
5656
extraDataCodec: extraDataCodec,

0 commit comments

Comments
 (0)