Skip to content

Commit d712adb

Browse files
committed
CCIP - add ExtraDataCodecBundle protobuf and client/server support
1 parent b41d6a9 commit d712adb

File tree

16 files changed

+768
-106
lines changed

16 files changed

+768
-106
lines changed

pkg/loop/internal/pb/ccipocr3/codec.pb.go

Lines changed: 287 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/loop/internal/pb/ccipocr3/codec.proto

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ service SourceChainExtraDataCodec {
3232
rpc DecodeDestExecDataToMap(DecodeDestExecDataToMapRequest) returns (DecodeDestExecDataToMapResponse);
3333
}
3434

35+
// ExtraDataCodecBundle service for decoding extra args and dest exec data with chain selector
36+
service ExtraDataCodecBundle {
37+
rpc DecodeExtraArgs(DecodeExtraArgsWithChainSelectorRequest) returns (DecodeExtraArgsWithChainSelectorResponse);
38+
rpc DecodeTokenAmountDestExecData(DecodeTokenAmountDestExecDataRequest) returns (DecodeTokenAmountDestExecDataResponse);
39+
}
40+
3541
// ChainSpecificAddressCodec messages
3642
message AddressBytesToStringRequest {
3743
bytes address = 1;
@@ -109,6 +115,25 @@ message DecodeDestExecDataToMapResponse {
109115
values.v1.Map decoded_map = 1;
110116
}
111117

118+
// ExtraDataCodecBundle messages
119+
message DecodeExtraArgsWithChainSelectorRequest {
120+
bytes extra_args = 1;
121+
uint64 source_chain_selector = 2;
122+
}
123+
124+
message DecodeExtraArgsWithChainSelectorResponse {
125+
values.v1.Map decoded_map = 1;
126+
}
127+
128+
message DecodeTokenAmountDestExecDataRequest {
129+
bytes dest_exec_data = 1;
130+
uint64 source_chain_selector = 2;
131+
}
132+
133+
message DecodeTokenAmountDestExecDataResponse {
134+
values.v1.Map decoded_map = 1;
135+
}
136+
112137
// Supporting types
113138
message ExecutePluginReport {
114139
repeated ChainReport chain_reports = 1;

pkg/loop/internal/pb/ccipocr3/codec_grpc.pb.go

Lines changed: 144 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/loop/internal/pb/relayer.pb.go

Lines changed: 20 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/loop/internal/pb/relayer.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ message CCIPProviderArgs {
6363
string OffRampAddress = 4;
6464
uint32 pluginType = 5;
6565
map<string, bytes> synced_addresses = 6; // map[contract_name]contract_address
66+
uint32 extraDataCodecBundleID = 7; // LOOP service ID for ExtraDataCodecBundle served by core node
6667
}
6768

6869
// NewContractWriterRequest has request parameters for [github.com/smartcontractkit/chainlink-common/pkg/loop.Relayer.NewContractWriter].

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/codec.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,80 @@ func pbToExecutePluginReport(pb *ccipocr3pb.ExecutePluginReport) ccipocr3.Execut
589589
ChainReports: chainReports,
590590
}
591591
}
592+
593+
// ExtraDataCodecBundle client
594+
var _ ccipocr3.ExtraDataCodecBundle = (*extraDataCodecBundleClient)(nil)
595+
596+
type extraDataCodecBundleClient struct {
597+
*net.BrokerExt
598+
grpc ccipocr3pb.ExtraDataCodecBundleClient
599+
}
600+
601+
func NewExtraDataCodecBundleClient(broker *net.BrokerExt, cc grpc.ClientConnInterface) ccipocr3.ExtraDataCodecBundle {
602+
return &extraDataCodecBundleClient{
603+
BrokerExt: broker,
604+
grpc: ccipocr3pb.NewExtraDataCodecBundleClient(cc),
605+
}
606+
}
607+
608+
func (c *extraDataCodecBundleClient) DecodeExtraArgs(extraArgs ccipocr3.Bytes, sourceChainSelector ccipocr3.ChainSelector) (map[string]any, error) {
609+
resp, err := c.grpc.DecodeExtraArgs(context.Background(), &ccipocr3pb.DecodeExtraArgsWithChainSelectorRequest{
610+
ExtraArgs: extraArgs,
611+
SourceChainSelector: uint64(sourceChainSelector),
612+
})
613+
if err != nil {
614+
return nil, err
615+
}
616+
return pbMapToGoMap(resp.DecodedMap)
617+
}
618+
619+
func (c *extraDataCodecBundleClient) DecodeTokenAmountDestExecData(destExecData ccipocr3.Bytes, sourceChainSelector ccipocr3.ChainSelector) (map[string]any, error) {
620+
resp, err := c.grpc.DecodeTokenAmountDestExecData(context.Background(), &ccipocr3pb.DecodeTokenAmountDestExecDataRequest{
621+
DestExecData: destExecData,
622+
SourceChainSelector: uint64(sourceChainSelector),
623+
})
624+
if err != nil {
625+
return nil, err
626+
}
627+
return pbMapToGoMap(resp.DecodedMap)
628+
}
629+
630+
// ExtraDataCodecBundle server
631+
var _ ccipocr3pb.ExtraDataCodecBundleServer = (*extraDataCodecBundleServer)(nil)
632+
633+
type extraDataCodecBundleServer struct {
634+
ccipocr3pb.UnimplementedExtraDataCodecBundleServer
635+
impl ccipocr3.ExtraDataCodecBundle
636+
}
637+
638+
func NewExtraDataCodecBundleServer(impl ccipocr3.ExtraDataCodecBundle) ccipocr3pb.ExtraDataCodecBundleServer {
639+
return &extraDataCodecBundleServer{impl: impl}
640+
}
641+
642+
func (s *extraDataCodecBundleServer) DecodeExtraArgs(ctx context.Context, req *ccipocr3pb.DecodeExtraArgsWithChainSelectorRequest) (*ccipocr3pb.DecodeExtraArgsWithChainSelectorResponse, error) {
643+
decodedMap, err := s.impl.DecodeExtraArgs(req.ExtraArgs, ccipocr3.ChainSelector(req.SourceChainSelector))
644+
if err != nil {
645+
return nil, err
646+
}
647+
pbMap, err := goMapToPbMap(decodedMap)
648+
if err != nil {
649+
return nil, fmt.Errorf("failed to convert decoded map to protobuf: %w", err)
650+
}
651+
return &ccipocr3pb.DecodeExtraArgsWithChainSelectorResponse{
652+
DecodedMap: pbMap,
653+
}, nil
654+
}
655+
656+
func (s *extraDataCodecBundleServer) DecodeTokenAmountDestExecData(ctx context.Context, req *ccipocr3pb.DecodeTokenAmountDestExecDataRequest) (*ccipocr3pb.DecodeTokenAmountDestExecDataResponse, error) {
657+
decodedMap, err := s.impl.DecodeTokenAmountDestExecData(req.DestExecData, ccipocr3.ChainSelector(req.SourceChainSelector))
658+
if err != nil {
659+
return nil, err
660+
}
661+
pbMap, err := goMapToPbMap(decodedMap)
662+
if err != nil {
663+
return nil, fmt.Errorf("failed to convert decoded map to protobuf: %w", err)
664+
}
665+
return &ccipocr3pb.DecodeTokenAmountDestExecDataResponse{
666+
DecodedMap: pbMap,
667+
}, nil
668+
}

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/codec_test.go

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

77
"github.com/stretchr/testify/assert"
88
"github.com/stretchr/testify/require"
9-
9+
1010
ccipocr3pb "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb/ccipocr3"
1111
"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
1212
)

0 commit comments

Comments
 (0)