From 3f4a34b55be8b4bb1c8f864a777eed39e6e2e065 Mon Sep 17 00:00:00 2001 From: Will Winder Date: Fri, 9 Aug 2024 11:27:33 -0400 Subject: [PATCH] Move plugintypes.execute.go to exectypes package (#58) --- .mockery.yaml | 2 +- execute/exectypes/commit_data.go | 32 +++++ execute/exectypes/observation.go | 43 ++++++ execute/exectypes/outcome.go | 64 +++++++++ .../{types => exectypes}/token_data_reader.go | 2 +- execute/internal/validation/reports_test.go | 28 ++-- execute/plugin.go | 39 +++-- execute/plugin_e2e_test.go | 12 +- execute/plugin_functions.go | 41 +++--- execute/plugin_functions_test.go | 107 +++++++------- execute/plugin_test.go | 29 ++-- execute/report/builder.go | 13 +- execute/report/data.go | 6 +- execute/report/report.go | 26 ++-- execute/report/report_test.go | 89 ++++++------ execute/report/roots.go | 4 +- .../{types => exectypes}/token_data_reader.go | 2 +- plugintypes/execute.go | 134 ------------------ 18 files changed, 339 insertions(+), 334 deletions(-) create mode 100644 execute/exectypes/commit_data.go create mode 100644 execute/exectypes/observation.go create mode 100644 execute/exectypes/outcome.go rename execute/{types => exectypes}/token_data_reader.go (95%) rename mocks/execute/{types => exectypes}/token_data_reader.go (99%) delete mode 100644 plugintypes/execute.go diff --git a/.mockery.yaml b/.mockery.yaml index 0e7b60e53..102b9d1d4 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -2,7 +2,7 @@ with-expecter: true filename: "{{.InterfaceName | snakecase}}.go" dir: mocks/{{ replaceAll .InterfaceDirRelative "internal" "internal_" }} packages: - github.com/smartcontractkit/chainlink-ccip/execute/types: + github.com/smartcontractkit/chainlink-ccip/execute/exectypes: interfaces: TokenDataReader: github.com/smartcontractkit/chainlink-ccip/execute/internal/gen: diff --git a/execute/exectypes/commit_data.go b/execute/exectypes/commit_data.go new file mode 100644 index 000000000..51307a723 --- /dev/null +++ b/execute/exectypes/commit_data.go @@ -0,0 +1,32 @@ +package exectypes + +import ( + "time" + + cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" +) + +// CommitData is the data that is committed to the chain. +type CommitData struct { + // SourceChain of the chain that contains the commit report. + SourceChain cciptypes.ChainSelector `json:"chainSelector"` + // Timestamp of the block that contains the commit. + Timestamp time.Time `json:"timestamp"` + // BlockNum of the block that contains the commit. + BlockNum uint64 `json:"blockNum"` + // MerkleRoot of the messages that are in this commit report. + MerkleRoot cciptypes.Bytes32 `json:"merkleRoot"` + // SequenceNumberRange of the messages that are in this commit report. + SequenceNumberRange cciptypes.SeqNumRange `json:"sequenceNumberRange"` + + // Messages that are part of the commit report. + Messages []cciptypes.Message `json:"messages"` + + // ExecutedMessages are the messages in this report that have already been executed. + ExecutedMessages []cciptypes.SeqNum `json:"executedMessages"` + + // The following values are cached for validation algorithms, serialization is not required for consensus. + + // TokenData for each message. + TokenData [][][]byte `json:"-"` +} diff --git a/execute/exectypes/observation.go b/execute/exectypes/observation.go new file mode 100644 index 000000000..92dc9baa4 --- /dev/null +++ b/execute/exectypes/observation.go @@ -0,0 +1,43 @@ +package exectypes + +import ( + "encoding/json" + + cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" +) + +type CommitObservations map[cciptypes.ChainSelector][]CommitData +type MessageObservations map[cciptypes.ChainSelector]map[cciptypes.SeqNum]cciptypes.Message + +// Observation is the observation of the ExecutePlugin. +// TODO: revisit observation types. The maps used here are more space efficient and easier to work +// with but require more transformations compared to the on-chain representations. +type Observation struct { + // CommitReports are determined during the first phase of execute. + // It contains the commit reports we would like to execute in the following round. + CommitReports CommitObservations `json:"commitReports"` + // Messages are determined during the second phase of execute. + // Ideally, it contains all the messages identified by the previous outcome's + // NextCommits. With the previous outcome, and these messsages, we can build the + // execute report. + Messages MessageObservations `json:"messages"` + // TODO: some of the nodes configuration may need to be included here. +} + +func NewObservation( + commitReports CommitObservations, messages MessageObservations) Observation { + return Observation{ + CommitReports: commitReports, + Messages: messages, + } +} + +func (obs Observation) Encode() ([]byte, error) { + return json.Marshal(obs) +} + +func DecodeObservation(b []byte) (Observation, error) { + obs := Observation{} + err := json.Unmarshal(b, &obs) + return obs, err +} diff --git a/execute/exectypes/outcome.go b/execute/exectypes/outcome.go new file mode 100644 index 000000000..6c39ad107 --- /dev/null +++ b/execute/exectypes/outcome.go @@ -0,0 +1,64 @@ +package exectypes + +import ( + "encoding/json" + "sort" + + cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" +) + +// Outcome is the outcome of the ExecutePlugin. +type Outcome struct { + // PendingCommitReports are the oldest reports with pending commits. The slice is + // sorted from oldest to newest. + PendingCommitReports []CommitData `json:"commitReports"` + + // Report is built from the oldest pending commit reports. + Report cciptypes.ExecutePluginReport `json:"report"` +} + +func (o Outcome) IsEmpty() bool { + return len(o.PendingCommitReports) == 0 && len(o.Report.ChainReports) == 0 +} + +func NewOutcome( + pendingCommits []CommitData, + report cciptypes.ExecutePluginReport, +) Outcome { + return newSortedOutcome(pendingCommits, report) +} + +// Encode encodes the outcome by first sorting the pending commit reports and the chain reports +// and then JSON marshalling. +// The encoding MUST be deterministic. +func (o Outcome) Encode() ([]byte, error) { + // We sort again here in case construction is not via the constructor. + return json.Marshal(newSortedOutcome(o.PendingCommitReports, o.Report)) +} + +func newSortedOutcome( + pendingCommits []CommitData, + report cciptypes.ExecutePluginReport) Outcome { + pendingCommitsCP := append([]CommitData{}, pendingCommits...) + reportCP := append([]cciptypes.ExecutePluginReportSingleChain{}, report.ChainReports...) + sort.Slice( + pendingCommitsCP, + func(i, j int) bool { + return pendingCommitsCP[i].SourceChain < pendingCommitsCP[j].SourceChain + }) + sort.Slice( + reportCP, + func(i, j int) bool { + return reportCP[i].SourceChainSelector < reportCP[j].SourceChainSelector + }) + return Outcome{ + PendingCommitReports: pendingCommitsCP, + Report: cciptypes.ExecutePluginReport{ChainReports: reportCP}, + } +} + +func DecodeOutcome(b []byte) (Outcome, error) { + o := Outcome{} + err := json.Unmarshal(b, &o) + return o, err +} diff --git a/execute/types/token_data_reader.go b/execute/exectypes/token_data_reader.go similarity index 95% rename from execute/types/token_data_reader.go rename to execute/exectypes/token_data_reader.go index 59f3b0f20..a0500916c 100644 --- a/execute/types/token_data_reader.go +++ b/execute/exectypes/token_data_reader.go @@ -1,4 +1,4 @@ -package types +package exectypes import ( "context" diff --git a/execute/internal/validation/reports_test.go b/execute/internal/validation/reports_test.go index aeaf7c0e0..062794323 100644 --- a/execute/internal/validation/reports_test.go +++ b/execute/internal/validation/reports_test.go @@ -9,15 +9,15 @@ import ( cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" - "github.com/smartcontractkit/chainlink-ccip/plugintypes" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" ) func Test_CommitReportValidator_ExecutePluginCommitData(t *testing.T) { tests := []struct { name string min int - reports []plugintypes.ExecutePluginCommitData - valid []plugintypes.ExecutePluginCommitData + reports []exectypes.CommitData + valid []exectypes.CommitData }{ { name: "empty", @@ -26,17 +26,17 @@ func Test_CommitReportValidator_ExecutePluginCommitData(t *testing.T) { { name: "single report, enough observations", min: 1, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {MerkleRoot: [32]byte{1}}, }, - valid: []plugintypes.ExecutePluginCommitData{ + valid: []exectypes.CommitData{ {MerkleRoot: [32]byte{1}}, }, }, { name: "single report, not enough observations", min: 2, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {MerkleRoot: [32]byte{1}}, }, valid: nil, @@ -44,14 +44,14 @@ func Test_CommitReportValidator_ExecutePluginCommitData(t *testing.T) { { name: "multiple reports, partial observations", min: 2, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {MerkleRoot: [32]byte{3}}, {MerkleRoot: [32]byte{1}}, {MerkleRoot: [32]byte{2}}, {MerkleRoot: [32]byte{1}}, {MerkleRoot: [32]byte{2}}, }, - valid: []plugintypes.ExecutePluginCommitData{ + valid: []exectypes.CommitData{ {MerkleRoot: [32]byte{1}}, {MerkleRoot: [32]byte{2}}, }, @@ -59,21 +59,21 @@ func Test_CommitReportValidator_ExecutePluginCommitData(t *testing.T) { { name: "multiple reports for same root", min: 2, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {MerkleRoot: [32]byte{1}, BlockNum: 1}, {MerkleRoot: [32]byte{1}, BlockNum: 2}, {MerkleRoot: [32]byte{1}, BlockNum: 3}, {MerkleRoot: [32]byte{1}, BlockNum: 4}, {MerkleRoot: [32]byte{1}, BlockNum: 1}, }, - valid: []plugintypes.ExecutePluginCommitData{ + valid: []exectypes.CommitData{ {MerkleRoot: [32]byte{1}, BlockNum: 1}, }, }, { name: "different executed messages same root", min: 2, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {MerkleRoot: [32]byte{1}, ExecutedMessages: []cciptypes.SeqNum{1, 2}}, {MerkleRoot: [32]byte{1}, ExecutedMessages: []cciptypes.SeqNum{2, 3}}, {MerkleRoot: [32]byte{1}, ExecutedMessages: []cciptypes.SeqNum{3, 4}}, @@ -81,7 +81,7 @@ func Test_CommitReportValidator_ExecutePluginCommitData(t *testing.T) { {MerkleRoot: [32]byte{1}, ExecutedMessages: []cciptypes.SeqNum{5, 6}}, {MerkleRoot: [32]byte{1}, ExecutedMessages: []cciptypes.SeqNum{1, 2}}, }, - valid: []plugintypes.ExecutePluginCommitData{ + valid: []exectypes.CommitData{ {MerkleRoot: [32]byte{1}, ExecutedMessages: []cciptypes.SeqNum{1, 2}}, }, }, @@ -92,10 +92,10 @@ func Test_CommitReportValidator_ExecutePluginCommitData(t *testing.T) { t.Parallel() // Initialize the minObservationValidator - idFunc := func(data plugintypes.ExecutePluginCommitData) [32]byte { + idFunc := func(data exectypes.CommitData) [32]byte { return sha3.Sum256([]byte(fmt.Sprintf("%v", data))) } - validator := NewMinObservationValidator[plugintypes.ExecutePluginCommitData](tt.min, idFunc) + validator := NewMinObservationValidator[exectypes.CommitData](tt.min, idFunc) for _, report := range tt.reports { validator.Add(report) } diff --git a/execute/plugin.go b/execute/plugin.go index 755af7093..c4609f74a 100644 --- a/execute/plugin.go +++ b/execute/plugin.go @@ -16,13 +16,12 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" "github.com/smartcontractkit/chainlink-ccip/execute/internal/gas" "github.com/smartcontractkit/chainlink-ccip/execute/report" - types2 "github.com/smartcontractkit/chainlink-ccip/execute/types" "github.com/smartcontractkit/chainlink-ccip/internal/plugincommon" "github.com/smartcontractkit/chainlink-ccip/internal/reader" "github.com/smartcontractkit/chainlink-ccip/pluginconfig" - "github.com/smartcontractkit/chainlink-ccip/plugintypes" ) // maxReportSizeBytes that should be returned as an execution report payload. @@ -41,7 +40,7 @@ type Plugin struct { homeChain reader.HomeChain oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID - tokenDataReader types2.TokenDataReader + tokenDataReader exectypes.TokenDataReader estimateProvider gas.EstimateProvider lggr logger.Logger } @@ -54,7 +53,7 @@ func NewPlugin( reportCodec cciptypes.ExecutePluginCodec, msgHasher cciptypes.MessageHasher, homeChain reader.HomeChain, - tokenDataReader types2.TokenDataReader, + tokenDataReader exectypes.TokenDataReader, estimateProvider gas.EstimateProvider, lggr logger.Logger, ) *Plugin { @@ -93,7 +92,7 @@ func getPendingExecutedReports( dest cciptypes.ChainSelector, ts time.Time, lggr logger.Logger, -) (plugintypes.ExecutePluginCommitObservations, error) { +) (exectypes.CommitObservations, error) { latestReportTS := time.Time{} commitReports, err := ccipReader.CommitReportsGTETimestamp(ctx, dest, ts, 1000) if err != nil { @@ -158,10 +157,10 @@ func (p *Plugin) Observation( ctx context.Context, outctx ocr3types.OutcomeContext, _ types.Query, ) (types.Observation, error) { var err error - var previousOutcome plugintypes.ExecutePluginOutcome + var previousOutcome exectypes.Outcome if outctx.PreviousOutcome != nil { - previousOutcome, err = plugintypes.DecodeExecutePluginOutcome(outctx.PreviousOutcome) + previousOutcome, err = exectypes.DecodeOutcome(outctx.PreviousOutcome) if err != nil { return types.Observation{}, fmt.Errorf("unable to decode previous outcome: %w", err) } @@ -172,7 +171,7 @@ func (p *Plugin) Observation( // Phase 1: Gather commit reports from the destination chain and determine which messages are required to build a // valid execution report. - var groupedCommits plugintypes.ExecutePluginCommitObservations + var groupedCommits exectypes.CommitObservations supportsDest, err := p.supportsDestChain() if err != nil { return types.Observation{}, fmt.Errorf("unable to determine if the destination chain is supported: %w", err) @@ -188,13 +187,13 @@ func (p *Plugin) Observation( } // Phase 2: Gather messages from the source chains and build the execution report. - messages := make(plugintypes.ExecutePluginMessageObservations) + messages := make(exectypes.MessageObservations) if len(previousOutcome.PendingCommitReports) == 0 { p.lggr.Debug("TODO: No reports to execute. This is expected after a cold start.") // No reports to execute. // This is expected after a cold start. } else { - commitReportCache := make(map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData) + commitReportCache := make(map[cciptypes.ChainSelector][]exectypes.CommitData) for _, report := range previousOutcome.PendingCommitReports { commitReportCache[report.SourceChain] = append(commitReportCache[report.SourceChain], report) } @@ -227,13 +226,13 @@ func (p *Plugin) Observation( // TODO: Fire off messages for an attestation check service. - return plugintypes.NewExecutePluginObservation(groupedCommits, messages).Encode() + return exectypes.NewObservation(groupedCommits, messages).Encode() } func (p *Plugin) ValidateObservation( outctx ocr3types.OutcomeContext, query types.Query, ao types.AttributedObservation, ) error { - decodedObservation, err := plugintypes.DecodeExecutePluginObservation(ao.Observation) + decodedObservation, err := exectypes.DecodeObservation(ao.Observation) if err != nil { return fmt.Errorf("unable to decode observation: %w", err) } @@ -270,12 +269,12 @@ func selectReport( lggr logger.Logger, hasher cciptypes.MessageHasher, encoder cciptypes.ExecutePluginCodec, - tokenDataReader types2.TokenDataReader, + tokenDataReader exectypes.TokenDataReader, estimateProvider gas.EstimateProvider, - commitReports []plugintypes.ExecutePluginCommitData, + commitReports []exectypes.CommitData, maxReportSizeBytes int, maxGas uint64, -) ([]cciptypes.ExecutePluginReportSingleChain, []plugintypes.ExecutePluginCommitData, error) { +) ([]cciptypes.ExecutePluginReportSingleChain, []exectypes.CommitData, error) { // TODO: It may be desirable for this entire function to be an interface so that // different selection algorithms can be used. @@ -288,7 +287,7 @@ func selectReport( estimateProvider, uint64(maxReportSizeBytes), maxGas) - var stillPendingReports []plugintypes.ExecutePluginCommitData + var stillPendingReports []exectypes.CommitData for i, report := range commitReports { // Reports at the end may not have messages yet. if len(report.Messages) == 0 { @@ -356,12 +355,12 @@ func (p *Plugin) Outcome( fmt.Sprintf("[oracle %d] exec outcome: merged message observations", p.reportingCfg.OracleID), "mergedMessageObservations", mergedMessageObservations) - observation := plugintypes.NewExecutePluginObservation( + observation := exectypes.NewObservation( mergedCommitObservations, mergedMessageObservations) // flatten commit reports and sort by timestamp. - var commitReports []plugintypes.ExecutePluginCommitData + var commitReports []exectypes.CommitData for _, report := range observation.CommitReports { commitReports = append(commitReports, report...) } @@ -403,7 +402,7 @@ func (p *Plugin) Outcome( ChainReports: outcomeReports, } - outcome := plugintypes.NewExecutePluginOutcome(commitReports, execReport) + outcome := exectypes.NewOutcome(commitReports, execReport) if outcome.IsEmpty() { return nil, nil } @@ -421,7 +420,7 @@ func (p *Plugin) Reports(seqNr uint64, outcome ocr3types.Outcome) ([]ocr3types.R return nil, nil } - decodedOutcome, err := plugintypes.DecodeExecutePluginOutcome(outcome) + decodedOutcome, err := exectypes.DecodeOutcome(outcome) if err != nil { return nil, fmt.Errorf("unable to decode outcome: %w", err) } diff --git a/execute/plugin_e2e_test.go b/execute/plugin_e2e_test.go index d1d5dfc11..f7964d3a9 100644 --- a/execute/plugin_e2e_test.go +++ b/execute/plugin_e2e_test.go @@ -17,15 +17,15 @@ import ( cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" "github.com/smartcontractkit/chainlink-ccip/chainconfig" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" "github.com/smartcontractkit/chainlink-ccip/execute/internal/gas/evm" "github.com/smartcontractkit/chainlink-ccip/execute/report" - "github.com/smartcontractkit/chainlink-ccip/execute/types" "github.com/smartcontractkit/chainlink-ccip/internal/libs/slicelib" "github.com/smartcontractkit/chainlink-ccip/internal/libs/testhelpers" "github.com/smartcontractkit/chainlink-ccip/internal/mocks" "github.com/smartcontractkit/chainlink-ccip/internal/mocks/inmem" "github.com/smartcontractkit/chainlink-ccip/internal/reader" - mock_types "github.com/smartcontractkit/chainlink-ccip/mocks/execute/types" + mock_types "github.com/smartcontractkit/chainlink-ccip/mocks/execute/exectypes" "github.com/smartcontractkit/chainlink-ccip/pkg/consts" "github.com/smartcontractkit/chainlink-ccip/pluginconfig" "github.com/smartcontractkit/chainlink-ccip/plugintypes" @@ -53,7 +53,7 @@ func TestPlugin(t *testing.T) { // Two of the messages are executed which should be indicated in the Outcome. res, err := runner.RunRound(ctx) require.NoError(t, err) - outcome, err := plugintypes.DecodeExecutePluginOutcome(res.Outcome) + outcome, err := exectypes.DecodeOutcome(res.Outcome) require.NoError(t, err) require.Len(t, outcome.Report.ChainReports, 0) require.Len(t, outcome.PendingCommitReports, 1) @@ -63,7 +63,7 @@ func TestPlugin(t *testing.T) { // The exec report should indicate the following messages are executed: 102, 103, 104, 105. res, err = runner.RunRound(ctx) require.NoError(t, err) - outcome, err = plugintypes.DecodeExecutePluginOutcome(res.Outcome) + outcome, err = exectypes.DecodeOutcome(res.Outcome) require.NoError(t, err) require.Len(t, outcome.Report.ChainReports, 1) require.Len(t, outcome.PendingCommitReports, 0) @@ -135,7 +135,7 @@ func setupSimpleTest( } mapped := slicelib.Map(messages, func(m inmem.MessagesWithMetadata) cciptypes.Message { return m.Message }) - reportData := plugintypes.ExecutePluginCommitData{ + reportData := exectypes.CommitData{ SourceChain: srcSelector, SequenceNumberRange: cciptypes.NewSeqNumRange(100, 105), Messages: mapped, @@ -236,7 +236,7 @@ func newNode( msgHasher cciptypes.MessageHasher, ccipReader reader.CCIP, homeChain reader.HomeChain, - tokenDataReader types.TokenDataReader, + tokenDataReader exectypes.TokenDataReader, oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID, id int, N int, diff --git a/execute/plugin_functions.go b/execute/plugin_functions.go index 9b8b3cbc1..96419280b 100644 --- a/execute/plugin_functions.go +++ b/execute/plugin_functions.go @@ -13,6 +13,7 @@ import ( cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" "github.com/smartcontractkit/chainlink-ccip/execute/internal/validation" "github.com/smartcontractkit/chainlink-ccip/plugintypes" ) @@ -20,7 +21,7 @@ import ( // validateObserverReadingEligibility checks if the observer is eligible to observe the messages it observed. func validateObserverReadingEligibility( supportedChains mapset.Set[cciptypes.ChainSelector], - observedMsgs plugintypes.ExecutePluginMessageObservations, + observedMsgs exectypes.MessageObservations, ) error { for chainSel, msgs := range observedMsgs { if len(msgs) == 0 { @@ -38,7 +39,7 @@ func validateObserverReadingEligibility( // validateObservedSequenceNumbers checks if the sequence numbers of the provided messages are unique for each chain // and that they match the observed max sequence numbers. func validateObservedSequenceNumbers( - observedData map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData, + observedData map[cciptypes.ChainSelector][]exectypes.CommitData, ) error { for _, commitData := range observedData { // observed commitData must not contain duplicates @@ -77,7 +78,7 @@ var errOverlappingRanges = errors.New("overlapping sequence numbers in reports") // computeRanges takes a slice of reports and computes the smallest number of contiguous ranges // that cover all the sequence numbers in the reports. // Note: reports need all messages to create a proof even if some are already executed. -func computeRanges(reports []plugintypes.ExecutePluginCommitData) ([]cciptypes.SeqNumRange, error) { +func computeRanges(reports []exectypes.CommitData) ([]cciptypes.SeqNumRange, error) { var ranges []cciptypes.SeqNumRange if len(reports) == 0 { @@ -108,12 +109,12 @@ func computeRanges(reports []plugintypes.ExecutePluginCommitData) ([]cciptypes.S } func groupByChainSelector( - reports []plugintypes.CommitPluginReportWithMeta) plugintypes.ExecutePluginCommitObservations { - commitReportCache := make(map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData) + reports []plugintypes.CommitPluginReportWithMeta) exectypes.CommitObservations { + commitReportCache := make(map[cciptypes.ChainSelector][]exectypes.CommitData) for _, report := range reports { for _, singleReport := range report.Report.MerkleRoots { commitReportCache[singleReport.ChainSel] = append(commitReportCache[singleReport.ChainSel], - plugintypes.ExecutePluginCommitData{ + exectypes.CommitData{ SourceChain: singleReport.ChainSel, Timestamp: report.Timestamp, BlockNum: report.BlockNum, @@ -128,8 +129,8 @@ func groupByChainSelector( // filterOutExecutedMessages returns a new reports slice with fully executed messages removed. // Unordered inputs are supported. func filterOutExecutedMessages( - reports []plugintypes.ExecutePluginCommitData, executedMessages []cciptypes.SeqNumRange, -) ([]plugintypes.ExecutePluginCommitData, error) { + reports []exectypes.CommitData, executedMessages []cciptypes.SeqNumRange, +) ([]exectypes.CommitData, error) { sort.Slice(reports, func(i, j int) bool { return reports[i].SequenceNumberRange.Start() < reports[j].SequenceNumberRange.Start() }) @@ -152,7 +153,7 @@ func filterOutExecutedMessages( previousMax = seqRange.End() } - var filtered []plugintypes.ExecutePluginCommitData + var filtered []exectypes.CommitData reportIdx := 0 for _, executed := range executedMessages { @@ -201,14 +202,14 @@ func filterOutExecutedMessages( } type decodedAttributedObservation struct { - Observation plugintypes.ExecutePluginObservation + Observation exectypes.Observation Observer commontypes.OracleID } func decodeAttributedObservations(aos []types.AttributedObservation) ([]decodedAttributedObservation, error) { decoded := make([]decodedAttributedObservation, len(aos)) for i, ao := range aos { - observation, err := plugintypes.DecodeExecutePluginObservation(ao.Observation) + observation, err := exectypes.DecodeObservation(ao.Observation) if err != nil { return nil, err } @@ -222,7 +223,7 @@ func decodeAttributedObservations(aos []types.AttributedObservation) ([]decodedA func mergeMessageObservations( aos []decodedAttributedObservation, fChain map[cciptypes.ChainSelector]int, -) (plugintypes.ExecutePluginMessageObservations, error) { +) (exectypes.MessageObservations, error) { // Create a validator for each chain validators := make(map[cciptypes.ChainSelector]validation.MinObservationFilter[cciptypes.Message]) idFunc := func(data cciptypes.Message) [32]byte { @@ -237,7 +238,7 @@ func mergeMessageObservations( for selector, messages := range ao.Observation.Messages { validator, ok := validators[selector] if !ok { - return plugintypes.ExecutePluginMessageObservations{}, fmt.Errorf("no validator for chain %d", selector) + return exectypes.MessageObservations{}, fmt.Errorf("no validator for chain %d", selector) } // Add reports for _, msg := range messages { @@ -246,7 +247,7 @@ func mergeMessageObservations( } } - results := make(plugintypes.ExecutePluginMessageObservations) + results := make(exectypes.MessageObservations) for selector, validator := range validators { msgs := validator.GetValid() if _, ok := results[selector]; !ok { @@ -264,16 +265,16 @@ func mergeMessageObservations( // Any observations, or subsets of observations, which do not reach the threshold are ignored. func mergeCommitObservations( aos []decodedAttributedObservation, fChain map[cciptypes.ChainSelector]int, -) (plugintypes.ExecutePluginCommitObservations, error) { +) (exectypes.CommitObservations, error) { // Create a validator for each chain validators := - make(map[cciptypes.ChainSelector]validation.MinObservationFilter[plugintypes.ExecutePluginCommitData]) - idFunc := func(data plugintypes.ExecutePluginCommitData) [32]byte { + make(map[cciptypes.ChainSelector]validation.MinObservationFilter[exectypes.CommitData]) + idFunc := func(data exectypes.CommitData) [32]byte { return sha3.Sum256([]byte(fmt.Sprintf("%v", data))) } for selector, f := range fChain { validators[selector] = - validation.NewMinObservationValidator[plugintypes.ExecutePluginCommitData](f+1, idFunc) + validation.NewMinObservationValidator[exectypes.CommitData](f+1, idFunc) } // Add reports to the validator for each chain selector. @@ -281,7 +282,7 @@ func mergeCommitObservations( for selector, commitReports := range ao.Observation.CommitReports { validator, ok := validators[selector] if !ok { - return plugintypes.ExecutePluginCommitObservations{}, fmt.Errorf("no validator for chain %d", selector) + return exectypes.CommitObservations{}, fmt.Errorf("no validator for chain %d", selector) } // Add reports for _, commitReport := range commitReports { @@ -290,7 +291,7 @@ func mergeCommitObservations( } } - results := make(plugintypes.ExecutePluginCommitObservations) + results := make(exectypes.CommitObservations) for selector, validator := range validators { results[selector] = validator.GetValid() } diff --git a/execute/plugin_functions_test.go b/execute/plugin_functions_test.go index b544ecb50..271737928 100644 --- a/execute/plugin_functions_test.go +++ b/execute/plugin_functions_test.go @@ -12,6 +12,7 @@ import ( cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" "github.com/smartcontractkit/chainlink-ccip/plugintypes" ) @@ -19,13 +20,13 @@ func Test_validateObserverReadingEligibility(t *testing.T) { tests := []struct { name string observerCfg mapset.Set[cciptypes.ChainSelector] - observedMsgs plugintypes.ExecutePluginMessageObservations + observedMsgs exectypes.MessageObservations expErr string }{ { name: "ValidObserverAndMessages", observerCfg: mapset.NewSet(cciptypes.ChainSelector(1), cciptypes.ChainSelector(2)), - observedMsgs: plugintypes.ExecutePluginMessageObservations{ + observedMsgs: exectypes.MessageObservations{ 1: {1: {}, 2: {}}, 2: {}, }, @@ -33,7 +34,7 @@ func Test_validateObserverReadingEligibility(t *testing.T) { { name: "ObserverNotAllowedToReadChain", observerCfg: mapset.NewSet(cciptypes.ChainSelector(1)), - observedMsgs: plugintypes.ExecutePluginMessageObservations{ + observedMsgs: exectypes.MessageObservations{ 2: {1: {}}, }, expErr: "observer not allowed to read from chain 2", @@ -41,12 +42,12 @@ func Test_validateObserverReadingEligibility(t *testing.T) { { name: "NoMessagesObserved", observerCfg: mapset.NewSet(cciptypes.ChainSelector(1), cciptypes.ChainSelector(2)), - observedMsgs: plugintypes.ExecutePluginMessageObservations{}, + observedMsgs: exectypes.MessageObservations{}, }, { name: "EmptyMessagesInChain", observerCfg: mapset.NewSet(cciptypes.ChainSelector(1), cciptypes.ChainSelector(2)), - observedMsgs: plugintypes.ExecutePluginMessageObservations{ + observedMsgs: exectypes.MessageObservations{ 1: {}, 2: {1: {}, 2: {}}, }, @@ -54,7 +55,7 @@ func Test_validateObserverReadingEligibility(t *testing.T) { { name: "AllMessagesEmpty", observerCfg: mapset.NewSet(cciptypes.ChainSelector(1), cciptypes.ChainSelector(2)), - observedMsgs: plugintypes.ExecutePluginMessageObservations{ + observedMsgs: exectypes.MessageObservations{ 1: {}, 2: {}, }, @@ -77,12 +78,12 @@ func Test_validateObserverReadingEligibility(t *testing.T) { func Test_validateObservedSequenceNumbers(t *testing.T) { testCases := []struct { name string - observedData map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData + observedData map[cciptypes.ChainSelector][]exectypes.CommitData expErr bool }{ { name: "ValidData", - observedData: map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData{ + observedData: map[cciptypes.ChainSelector][]exectypes.CommitData{ 1: { { MerkleRoot: cciptypes.Bytes32{1}, @@ -101,7 +102,7 @@ func Test_validateObservedSequenceNumbers(t *testing.T) { }, { name: "DuplicateMerkleRoot", - observedData: map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData{ + observedData: map[cciptypes.ChainSelector][]exectypes.CommitData{ 1: { { MerkleRoot: cciptypes.Bytes32{1}, @@ -119,7 +120,7 @@ func Test_validateObservedSequenceNumbers(t *testing.T) { }, { name: "OverlappingSequenceNumberRange", - observedData: map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData{ + observedData: map[cciptypes.ChainSelector][]exectypes.CommitData{ 1: { { MerkleRoot: cciptypes.Bytes32{1}, @@ -137,7 +138,7 @@ func Test_validateObservedSequenceNumbers(t *testing.T) { }, { name: "ExecutedMessageOutsideObservedRange", - observedData: map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData{ + observedData: map[cciptypes.ChainSelector][]exectypes.CommitData{ 1: { { MerkleRoot: cciptypes.Bytes32{1}, @@ -150,13 +151,13 @@ func Test_validateObservedSequenceNumbers(t *testing.T) { }, { name: "NoCommitData", - observedData: map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData{ + observedData: map[cciptypes.ChainSelector][]exectypes.CommitData{ 1: {}, }, }, { name: "EmptyObservedData", - observedData: map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData{}, + observedData: map[cciptypes.ChainSelector][]exectypes.CommitData{}, }, } @@ -174,7 +175,7 @@ func Test_validateObservedSequenceNumbers(t *testing.T) { func Test_computeRanges(t *testing.T) { type args struct { - reports []plugintypes.ExecutePluginCommitData + reports []exectypes.CommitData } tests := []struct { @@ -185,12 +186,12 @@ func Test_computeRanges(t *testing.T) { }{ { name: "empty", - args: args{reports: []plugintypes.ExecutePluginCommitData{}}, + args: args{reports: []exectypes.CommitData{}}, want: nil, }, { name: "overlapping ranges", - args: args{reports: []plugintypes.ExecutePluginCommitData{ + args: args{reports: []exectypes.CommitData{ { SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20), }, @@ -202,7 +203,7 @@ func Test_computeRanges(t *testing.T) { }, { name: "simple ranges collapsed", - args: args{reports: []plugintypes.ExecutePluginCommitData{ + args: args{reports: []exectypes.CommitData{ { SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20), }, @@ -217,7 +218,7 @@ func Test_computeRanges(t *testing.T) { }, { name: "non-contiguous ranges", - args: args{reports: []plugintypes.ExecutePluginCommitData{ + args: args{reports: []exectypes.CommitData{ { SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20), }, @@ -231,7 +232,7 @@ func Test_computeRanges(t *testing.T) { }, { name: "contiguous and non-contiguous ranges", - args: args{reports: []plugintypes.ExecutePluginCommitData{ + args: args{reports: []exectypes.CommitData{ { SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20), }, @@ -267,12 +268,12 @@ func Test_groupByChainSelector(t *testing.T) { tests := []struct { name string args args - want plugintypes.ExecutePluginCommitObservations + want exectypes.CommitObservations }{ { name: "empty", args: args{reports: []plugintypes.CommitPluginReportWithMeta{}}, - want: plugintypes.ExecutePluginCommitObservations{}, + want: exectypes.CommitObservations{}, }, { name: "reports", @@ -282,7 +283,7 @@ func Test_groupByChainSelector(t *testing.T) { {ChainSel: 1, SeqNumsRange: cciptypes.NewSeqNumRange(10, 20), MerkleRoot: cciptypes.Bytes32{1}}, {ChainSel: 2, SeqNumsRange: cciptypes.NewSeqNumRange(30, 40), MerkleRoot: cciptypes.Bytes32{2}}, }}}}}, - want: plugintypes.ExecutePluginCommitObservations{ + want: exectypes.CommitObservations{ 1: { { SourceChain: 1, @@ -311,13 +312,13 @@ func Test_groupByChainSelector(t *testing.T) { func Test_filterOutFullyExecutedMessages(t *testing.T) { type args struct { - reports []plugintypes.ExecutePluginCommitData + reports []exectypes.CommitData executedMessages []cciptypes.SeqNumRange } tests := []struct { name string args args - want []plugintypes.ExecutePluginCommitData + want []exectypes.CommitData wantErr assert.ErrorAssertionFunc }{ { @@ -332,23 +333,23 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { { name: "empty2", args: args{ - reports: []plugintypes.ExecutePluginCommitData{}, + reports: []exectypes.CommitData{}, executedMessages: nil, }, - want: []plugintypes.ExecutePluginCommitData{}, + want: []exectypes.CommitData{}, wantErr: assert.NoError, }, { name: "no executed messages", args: args{ - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(30, 40)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(50, 60)}, }, executedMessages: nil, }, - want: []plugintypes.ExecutePluginCommitData{ + want: []exectypes.CommitData{ {SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(30, 40)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(50, 60)}, @@ -358,7 +359,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { { name: "executed messages", args: args{ - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(30, 40)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(50, 60)}, @@ -373,7 +374,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { { name: "2 partially executed", args: args{ - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(30, 40)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(50, 60)}, @@ -382,7 +383,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { cciptypes.NewSeqNumRange(15, 35), }, }, - want: []plugintypes.ExecutePluginCommitData{ + want: []exectypes.CommitData{ { SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20), ExecutedMessages: []cciptypes.SeqNum{15, 16, 17, 18, 19, 20}, @@ -400,7 +401,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { { name: "2 partially executed 1 fully executed", args: args{ - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(30, 40)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(50, 60)}, @@ -409,7 +410,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { cciptypes.NewSeqNumRange(15, 55), }, }, - want: []plugintypes.ExecutePluginCommitData{ + want: []exectypes.CommitData{ { SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20), ExecutedMessages: []cciptypes.SeqNum{15, 16, 17, 18, 19, 20}, @@ -424,7 +425,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { { name: "first report executed", args: args{ - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(30, 40)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(50, 60)}, @@ -433,7 +434,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { cciptypes.NewSeqNumRange(10, 20), }, }, - want: []plugintypes.ExecutePluginCommitData{ + want: []exectypes.CommitData{ {SequenceNumberRange: cciptypes.NewSeqNumRange(30, 40)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(50, 60)}, }, @@ -442,7 +443,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { { name: "last report executed", args: args{ - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ {SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(30, 40)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(50, 60)}, @@ -451,7 +452,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { cciptypes.NewSeqNumRange(50, 60), }, }, - want: []plugintypes.ExecutePluginCommitData{ + want: []exectypes.CommitData{ {SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20)}, {SequenceNumberRange: cciptypes.NewSeqNumRange(30, 40)}, }, @@ -460,7 +461,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { { name: "sort-report", args: args{ - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ { SequenceNumberRange: cciptypes.NewSeqNumRange(30, 40), }, @@ -473,7 +474,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { }, executedMessages: nil, }, - want: []plugintypes.ExecutePluginCommitData{ + want: []exectypes.CommitData{ { SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20), }, @@ -489,7 +490,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { { name: "sort-executed", args: args{ - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ { SequenceNumberRange: cciptypes.NewSeqNumRange(10, 20), }, @@ -523,7 +524,7 @@ func Test_filterOutFullyExecutedMessages(t *testing.T) { } func Test_decodeAttributedObservations(t *testing.T) { - mustEncode := func(obs plugintypes.ExecutePluginObservation) []byte { + mustEncode := func(obs exectypes.Observation) []byte { enc, err := obs.Encode() if err != nil { t.Fatal("Unable to encode") @@ -547,8 +548,8 @@ func Test_decodeAttributedObservations(t *testing.T) { args: []types.AttributedObservation{ { Observer: commontypes.OracleID(1), - Observation: mustEncode(plugintypes.ExecutePluginObservation{ - CommitReports: plugintypes.ExecutePluginCommitObservations{ + Observation: mustEncode(exectypes.Observation{ + CommitReports: exectypes.CommitObservations{ 1: {{MerkleRoot: cciptypes.Bytes32{1}}}, }, }), @@ -557,8 +558,8 @@ func Test_decodeAttributedObservations(t *testing.T) { want: []decodedAttributedObservation{ { Observer: commontypes.OracleID(1), - Observation: plugintypes.ExecutePluginObservation{ - CommitReports: plugintypes.ExecutePluginCommitObservations{ + Observation: exectypes.Observation{ + CommitReports: exectypes.CommitObservations{ 1: {{MerkleRoot: cciptypes.Bytes32{1}}}, }, }, @@ -571,16 +572,16 @@ func Test_decodeAttributedObservations(t *testing.T) { args: []types.AttributedObservation{ { Observer: commontypes.OracleID(1), - Observation: mustEncode(plugintypes.ExecutePluginObservation{ - CommitReports: plugintypes.ExecutePluginCommitObservations{ + Observation: mustEncode(exectypes.Observation{ + CommitReports: exectypes.CommitObservations{ 1: {{MerkleRoot: cciptypes.Bytes32{1}}}, }, }), }, { Observer: commontypes.OracleID(2), - Observation: mustEncode(plugintypes.ExecutePluginObservation{ - CommitReports: plugintypes.ExecutePluginCommitObservations{ + Observation: mustEncode(exectypes.Observation{ + CommitReports: exectypes.CommitObservations{ 2: {{MerkleRoot: cciptypes.Bytes32{2}}}, }, }), @@ -589,16 +590,16 @@ func Test_decodeAttributedObservations(t *testing.T) { want: []decodedAttributedObservation{ { Observer: commontypes.OracleID(1), - Observation: plugintypes.ExecutePluginObservation{ - CommitReports: plugintypes.ExecutePluginCommitObservations{ + Observation: exectypes.Observation{ + CommitReports: exectypes.CommitObservations{ 1: {{MerkleRoot: cciptypes.Bytes32{1}}}, }, }, }, { Observer: commontypes.OracleID(2), - Observation: plugintypes.ExecutePluginObservation{ - CommitReports: plugintypes.ExecutePluginCommitObservations{ + Observation: exectypes.Observation{ + CommitReports: exectypes.CommitObservations{ 2: {{MerkleRoot: cciptypes.Bytes32{2}}}, }, }, diff --git a/execute/plugin_test.go b/execute/plugin_test.go index 19c934d19..2b0fe365d 100644 --- a/execute/plugin_test.go +++ b/execute/plugin_test.go @@ -21,6 +21,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" "github.com/smartcontractkit/chainlink-ccip/internal/libs/slicelib" "github.com/smartcontractkit/chainlink-ccip/internal/mocks" "github.com/smartcontractkit/chainlink-ccip/internal/plugincommon" @@ -36,14 +37,14 @@ func Test_getPendingExecutedReports(t *testing.T) { name string reports []plugintypes.CommitPluginReportWithMeta ranges map[cciptypes.ChainSelector][]cciptypes.SeqNumRange - want plugintypes.ExecutePluginCommitObservations + want exectypes.CommitObservations wantErr assert.ErrorAssertionFunc }{ { name: "empty", reports: nil, ranges: nil, - want: plugintypes.ExecutePluginCommitObservations{}, + want: exectypes.CommitObservations{}, wantErr: assert.NoError, }, { @@ -65,8 +66,8 @@ func Test_getPendingExecutedReports(t *testing.T) { ranges: map[cciptypes.ChainSelector][]cciptypes.SeqNumRange{ 1: nil, }, - want: plugintypes.ExecutePluginCommitObservations{ - 1: []plugintypes.ExecutePluginCommitData{ + want: exectypes.CommitObservations{ + 1: []exectypes.CommitData{ { SourceChain: 1, SequenceNumberRange: cciptypes.NewSeqNumRange(1, 10), @@ -99,8 +100,8 @@ func Test_getPendingExecutedReports(t *testing.T) { cciptypes.NewSeqNumRange(7, 8), }, }, - want: plugintypes.ExecutePluginCommitObservations{ - 1: []plugintypes.ExecutePluginCommitData{ + want: exectypes.CommitObservations{ + 1: []exectypes.CommitData{ { SourceChain: 1, SequenceNumberRange: cciptypes.NewSeqNumRange(1, 10), @@ -127,7 +128,7 @@ func Test_getPendingExecutedReports(t *testing.T) { }, }, ranges: map[cciptypes.ChainSelector][]cciptypes.SeqNumRange{}, - want: plugintypes.ExecutePluginCommitObservations{}, + want: exectypes.CommitObservations{}, wantErr: assert.NoError, }, } @@ -221,7 +222,7 @@ func TestPlugin_ValidateObservation_IneligibleObserver(t *testing.T) { }, } - observation := plugintypes.NewExecutePluginObservation(nil, plugintypes.ExecutePluginMessageObservations{ + observation := exectypes.NewObservation(nil, exectypes.MessageObservations{ 0: map[cciptypes.SeqNum]cciptypes.Message{ 1: { Header: cciptypes.RampMessageHeader{ @@ -256,13 +257,13 @@ func TestPlugin_ValidateObservation_ValidateObservedSeqNum_Error(t *testing.T) { // Reports with duplicate roots. root := cciptypes.Bytes32{} - commitReports := map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData{ + commitReports := map[cciptypes.ChainSelector][]exectypes.CommitData{ 1: { {MerkleRoot: root}, {MerkleRoot: root}, }, } - observation := plugintypes.NewExecutePluginObservation(commitReports, nil) + observation := exectypes.NewObservation(commitReports, nil) encoded, err := observation.Encode() require.NoError(t, err) err = p.ValidateObservation(ocr3types.OutcomeContext{}, types.Query{}, types.AttributedObservation{ @@ -346,10 +347,10 @@ func TestPlugin_Outcome_CommitReportsMergeError(t *testing.T) { lggr: logger.Test(t), } - commitReports := map[cciptypes.ChainSelector][]plugintypes.ExecutePluginCommitData{ + commitReports := map[cciptypes.ChainSelector][]exectypes.CommitData{ 1: {}, } - observation, err := plugintypes.NewExecutePluginObservation(commitReports, nil).Encode() + observation, err := exectypes.NewObservation(commitReports, nil).Encode() require.NoError(t, err) _, err = p.Outcome(ocr3types.OutcomeContext{}, nil, []types.AttributedObservation{ { @@ -382,7 +383,7 @@ func TestPlugin_Outcome_MessagesMergeError(t *testing.T) { }, }, } - observation, err := plugintypes.NewExecutePluginObservation(nil, messages).Encode() + observation, err := exectypes.NewObservation(nil, messages).Encode() require.NoError(t, err) _, err = p.Outcome(ocr3types.OutcomeContext{}, nil, []types.AttributedObservation{ { @@ -405,7 +406,7 @@ func TestPlugin_Reports_UnableToEncode(t *testing.T) { codec.On("Encode", mock.Anything, mock.Anything). Return(nil, fmt.Errorf("test error")) p := &Plugin{reportCodec: codec} - report, err := plugintypes.NewExecutePluginOutcome(nil, cciptypes.ExecutePluginReport{}).Encode() + report, err := exectypes.NewOutcome(nil, cciptypes.ExecutePluginReport{}).Encode() require.NoError(t, err) _, err = p.Reports(0, report) diff --git a/execute/report/builder.go b/execute/report/builder.go index 4a10175ad..912d03166 100644 --- a/execute/report/builder.go +++ b/execute/report/builder.go @@ -8,15 +8,14 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" "github.com/smartcontractkit/chainlink-ccip/execute/internal/gas" - "github.com/smartcontractkit/chainlink-ccip/execute/types" - "github.com/smartcontractkit/chainlink-ccip/plugintypes" ) var _ ExecReportBuilder = &execReportBuilder{} type ExecReportBuilder interface { - Add(report plugintypes.ExecutePluginCommitData) (plugintypes.ExecutePluginCommitData, error) + Add(report exectypes.CommitData) (exectypes.CommitData, error) Build() ([]cciptypes.ExecutePluginReportSingleChain, error) } @@ -24,7 +23,7 @@ func NewBuilder( ctx context.Context, logger logger.Logger, hasher cciptypes.MessageHasher, - tokenDataReader types.TokenDataReader, + tokenDataReader exectypes.TokenDataReader, encoder cciptypes.ExecutePluginCodec, estimateProvider gas.EstimateProvider, maxReportSizeBytes uint64, @@ -62,7 +61,7 @@ type execReportBuilder struct { lggr logger.Logger // Providers - tokenDataReader types.TokenDataReader + tokenDataReader exectypes.TokenDataReader encoder cciptypes.ExecutePluginCodec hasher cciptypes.MessageHasher estimateProvider gas.EstimateProvider @@ -79,8 +78,8 @@ type execReportBuilder struct { } func (b *execReportBuilder) Add( - commitReport plugintypes.ExecutePluginCommitData, -) (plugintypes.ExecutePluginCommitData, error) { + commitReport exectypes.CommitData, +) (exectypes.CommitData, error) { execReport, updatedReport, err := b.buildSingleChainReport(b.ctx, commitReport) // No messages fit into the report, move to next report diff --git a/execute/report/data.go b/execute/report/data.go index 35d82187f..b09f06b93 100644 --- a/execute/report/data.go +++ b/execute/report/data.go @@ -5,14 +5,14 @@ import ( cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" - "github.com/smartcontractkit/chainlink-ccip/plugintypes" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" ) // markNewMessagesExecuted compares an execute plugin report with the commit report metadata and marks the new messages // as executed. func markNewMessagesExecuted( - execReport cciptypes.ExecutePluginReportSingleChain, report plugintypes.ExecutePluginCommitData, -) plugintypes.ExecutePluginCommitData { + execReport cciptypes.ExecutePluginReportSingleChain, report exectypes.CommitData, +) exectypes.CommitData { // Mark new messages executed. for i := 0; i < len(execReport.Messages); i++ { report.ExecutedMessages = diff --git a/execute/report/report.go b/execute/report/report.go index ec0e0d667..36e10bb47 100644 --- a/execute/report/report.go +++ b/execute/report/report.go @@ -11,8 +11,8 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" "github.com/smartcontractkit/chainlink-ccip/internal/libs/slicelib" - "github.com/smartcontractkit/chainlink-ccip/plugintypes" ) // buildSingleChainReportHelper converts the on-chain event data stored in cciptypes.ExecutePluginCommitData into the @@ -26,7 +26,7 @@ func buildSingleChainReportHelper( ctx context.Context, lggr logger.Logger, hasher cciptypes.MessageHasher, - report plugintypes.ExecutePluginCommitData, + report exectypes.CommitData, readyMessages map[int]struct{}, ) (cciptypes.ExecutePluginReportSingleChain, error) { if len(readyMessages) == 0 { @@ -147,9 +147,9 @@ func padSlice[T any](slice []T, padLen int, defaultValue T) []T { } func (b *execReportBuilder) checkMessage( - ctx context.Context, idx int, execReport plugintypes.ExecutePluginCommitData, + ctx context.Context, idx int, execReport exectypes.CommitData, // TODO: get rid of the nolint when the error is used -) (plugintypes.ExecutePluginCommitData, messageStatus, error) { // nolint this will use the error eventually +) (exectypes.CommitData, messageStatus, error) { // nolint this will use the error eventually if idx >= len(execReport.Messages) { b.lggr.Errorw("message index out of range", "index", idx, "numMessages", len(execReport.Messages)) return execReport, Unknown, fmt.Errorf("message index out of range") @@ -257,13 +257,13 @@ func (b *execReportBuilder) verifyReport( // See buildSingleChainReport for more details about how a report is built. func (b *execReportBuilder) buildSingleChainReport( ctx context.Context, - report plugintypes.ExecutePluginCommitData, -) (cciptypes.ExecutePluginReportSingleChain, plugintypes.ExecutePluginCommitData, error) { + report exectypes.CommitData, +) (cciptypes.ExecutePluginReportSingleChain, exectypes.CommitData, error) { finalize := func( execReport cciptypes.ExecutePluginReportSingleChain, - commitReport plugintypes.ExecutePluginCommitData, + commitReport exectypes.CommitData, meta validationMetadata, - ) (cciptypes.ExecutePluginReportSingleChain, plugintypes.ExecutePluginCommitData, error) { + ) (cciptypes.ExecutePluginReportSingleChain, exectypes.CommitData, error) { b.accumulated = b.accumulated.accumulate(meta) commitReport = markNewMessagesExecuted(execReport, commitReport) return execReport, commitReport, nil @@ -275,7 +275,7 @@ func (b *execReportBuilder) buildSingleChainReport( updatedReport, status, err := b.checkMessage(ctx, i, report) if err != nil { return cciptypes.ExecutePluginReportSingleChain{}, - plugintypes.ExecutePluginCommitData{}, + exectypes.CommitData{}, fmt.Errorf("unable to check message: %w", err) } report = updatedReport @@ -289,14 +289,14 @@ func (b *execReportBuilder) buildSingleChainReport( buildSingleChainReportHelper(b.ctx, b.lggr, b.hasher, report, readyMessages) if err != nil { return cciptypes.ExecutePluginReportSingleChain{}, - plugintypes.ExecutePluginCommitData{}, + exectypes.CommitData{}, fmt.Errorf("unable to build a single chain report (max): %w", err) } validReport, meta, err := b.verifyReport(ctx, finalReport) if err != nil { return cciptypes.ExecutePluginReportSingleChain{}, - plugintypes.ExecutePluginCommitData{}, + exectypes.CommitData{}, fmt.Errorf("unable to verify report: %w", err) } else if validReport { return finalize(finalReport, report, meta) @@ -314,14 +314,14 @@ func (b *execReportBuilder) buildSingleChainReport( finalReport2, err := buildSingleChainReportHelper(b.ctx, b.lggr, b.hasher, report, msgs) if err != nil { return cciptypes.ExecutePluginReportSingleChain{}, - plugintypes.ExecutePluginCommitData{}, + exectypes.CommitData{}, fmt.Errorf("unable to build a single chain report (messages %d): %w", len(msgs), err) } validReport, meta2, err := b.verifyReport(ctx, finalReport2) if err != nil { return cciptypes.ExecutePluginReportSingleChain{}, - plugintypes.ExecutePluginCommitData{}, + exectypes.CommitData{}, fmt.Errorf("unable to verify report: %w", err) } else if validReport { finalReport = finalReport2 diff --git a/execute/report/report_test.go b/execute/report/report_test.go index 6a150a6f6..2c1d59fee 100644 --- a/execute/report/report_test.go +++ b/execute/report/report_test.go @@ -18,12 +18,11 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/merklemulti" cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" "github.com/smartcontractkit/chainlink-ccip/execute/internal/gas" "github.com/smartcontractkit/chainlink-ccip/execute/internal/gas/evm" - "github.com/smartcontractkit/chainlink-ccip/execute/types" "github.com/smartcontractkit/chainlink-ccip/internal/libs/slicelib" "github.com/smartcontractkit/chainlink-ccip/internal/mocks" - "github.com/smartcontractkit/chainlink-ccip/plugintypes" ) // mustMakeBytes parses a given string into a byte array, any error causes a panic. Pass in an empty string for a @@ -114,7 +113,7 @@ func assertMerkleRoot( t *testing.T, hasher cciptypes.MessageHasher, execReport cciptypes.ExecutePluginReportSingleChain, - commitReport plugintypes.ExecutePluginCommitData, + commitReport exectypes.CommitData, ) { keccak := hashutil.NewKeccak() // Generate merkle root from commit report messages @@ -185,7 +184,7 @@ func makeTestCommitReport( timestamp int64, rootOverride cciptypes.Bytes32, executed []cciptypes.SeqNum, -) plugintypes.ExecutePluginCommitData { +) exectypes.CommitData { sequenceNumberRange := cciptypes.NewSeqNumRange(cciptypes.SeqNum(firstSeqNum), cciptypes.SeqNum(firstSeqNum+numMessages-1)) @@ -202,7 +201,7 @@ func makeTestCommitReport( uint64(i))) } - commitReport := plugintypes.ExecutePluginCommitData{ + commitReport := exectypes.CommitData{ //MerkleRoot: root, SourceChain: cciptypes.ChainSelector(srcChain), SequenceNumberRange: sequenceNumberRange, @@ -227,16 +226,16 @@ func makeTestCommitReport( // breakCommitReport by adding an extra message. This causes the report to have an unexpected number of messages. func breakCommitReport( - commitReport plugintypes.ExecutePluginCommitData, -) plugintypes.ExecutePluginCommitData { + commitReport exectypes.CommitData, +) exectypes.CommitData { commitReport.Messages = append(commitReport.Messages, cciptypes.Message{}) return commitReport } // setMessageData at the given index to the given size. This function will panic if the index is out of range. func setMessageData( - idx int, size uint64, commitReport plugintypes.ExecutePluginCommitData, -) plugintypes.ExecutePluginCommitData { + idx int, size uint64, commitReport exectypes.CommitData, +) exectypes.CommitData { if len(commitReport.Messages) < idx { panic("message index out of range") } @@ -254,7 +253,7 @@ func Test_buildSingleChainReport_Errors(t *testing.T) { lggr := logger.Test(t) type args struct { - report plugintypes.ExecutePluginCommitData + report exectypes.CommitData hasher cciptypes.MessageHasher } tests := []struct { @@ -266,7 +265,7 @@ func Test_buildSingleChainReport_Errors(t *testing.T) { name: "token data mismatch", wantErr: "token data length mismatch: got 2, expected 0", args: args{ - report: plugintypes.ExecutePluginCommitData{ + report: exectypes.CommitData{ TokenData: make([][][]byte, 2), }, }, @@ -275,7 +274,7 @@ func Test_buildSingleChainReport_Errors(t *testing.T) { name: "wrong number of messages", wantErr: "unexpected number of messages: expected 1, got 2", args: args{ - report: plugintypes.ExecutePluginCommitData{ + report: exectypes.CommitData{ TokenData: make([][][]byte, 2), SequenceNumberRange: cciptypes.NewSeqNumRange(cciptypes.SeqNum(100), cciptypes.SeqNum(100)), Messages: []cciptypes.Message{ @@ -289,7 +288,7 @@ func Test_buildSingleChainReport_Errors(t *testing.T) { name: "wrong sequence numbers", wantErr: "sequence number 102 outside of report range [100 -> 101]", args: args{ - report: plugintypes.ExecutePluginCommitData{ + report: exectypes.CommitData{ TokenData: make([][][]byte, 2), SequenceNumberRange: cciptypes.NewSeqNumRange(cciptypes.SeqNum(100), cciptypes.SeqNum(101)), Messages: []cciptypes.Message{ @@ -311,7 +310,7 @@ func Test_buildSingleChainReport_Errors(t *testing.T) { name: "source mismatch", wantErr: "unexpected source chain: expected 1111, got 2222", args: args{ - report: plugintypes.ExecutePluginCommitData{ + report: exectypes.CommitData{ TokenData: make([][][]byte, 1), SourceChain: 1111, SequenceNumberRange: cciptypes.NewSeqNumRange(cciptypes.SeqNum(100), cciptypes.SeqNum(100)), @@ -331,7 +330,7 @@ func Test_buildSingleChainReport_Errors(t *testing.T) { name: "bad hasher", wantErr: "unable to hash message (1234567, 100): bad hasher", args: args{ - report: plugintypes.ExecutePluginCommitData{ + report: exectypes.CommitData{ TokenData: make([][][]byte, 1), SourceChain: 1234567, SequenceNumberRange: cciptypes.NewSeqNumRange(cciptypes.SeqNum(100), cciptypes.SeqNum(100)), @@ -387,7 +386,7 @@ func Test_Builder_Build(t *testing.T) { tokenDataReader := tdr{mode: good} type args struct { - reports []plugintypes.ExecutePluginCommitData + reports []exectypes.CommitData maxReportSize uint64 maxGasLimit uint64 } @@ -403,7 +402,7 @@ func Test_Builder_Build(t *testing.T) { { name: "empty report", args: args{ - reports: []plugintypes.ExecutePluginCommitData{}, + reports: []exectypes.CommitData{}, }, expectedExecReports: 0, expectedCommitReports: 0, @@ -413,7 +412,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 2300, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, cciptypes.Bytes32{}, // generate a correct root. nil), @@ -429,7 +428,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 10000, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, cciptypes.Bytes32{}, // generate a correct root. nil), @@ -444,7 +443,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 15000, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, cciptypes.Bytes32{}, // generate a correct root. nil), @@ -462,7 +461,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 8500, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, cciptypes.Bytes32{}, // generate a correct root. nil), @@ -481,7 +480,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 4200, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, cciptypes.Bytes32{}, // generate a correct root. nil), @@ -500,7 +499,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 2500, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, cciptypes.Bytes32{}, // generate a correct root. []cciptypes.SeqNum{100, 101, 102, 103, 104}), @@ -515,7 +514,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 2050, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, cciptypes.Bytes32{}, // generate a correct root. []cciptypes.SeqNum{100, 101, 102, 103, 104}), @@ -531,7 +530,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 3500, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, cciptypes.Bytes32{}, // generate a correct root. []cciptypes.SeqNum{100, 102, 104, 106, 108}), @@ -546,7 +545,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 2050, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, cciptypes.Bytes32{}, // generate a correct root. []cciptypes.SeqNum{100, 102, 104, 106, 108}), @@ -562,7 +561,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 10000, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ breakCommitReport(makeTestCommitReport(hasher, 10, 1, 101, 1000, 10101010102, cciptypes.Bytes32{}, // generate a correct root. nil)), @@ -573,7 +572,7 @@ func Test_Builder_Build(t *testing.T) { { name: "invalid merkle root", args: args{ - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, mustMakeBytes(""), // random root nil), @@ -586,7 +585,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 10000, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ setMessageData(5, 20000, makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, cciptypes.Bytes32{}, // generate a correct root. @@ -603,7 +602,7 @@ func Test_Builder_Build(t *testing.T) { args: args{ maxReportSize: 10000, maxGasLimit: 10000000, - reports: []plugintypes.ExecutePluginCommitData{ + reports: []exectypes.CommitData{ setMessageData(8, 20000, setMessageData(5, 20000, makeTestCommitReport(hasher, 10, 1, 100, 999, 10101010101, @@ -634,7 +633,7 @@ func Test_Builder_Build(t *testing.T) { evm.EstimateProvider{}, tt.args.maxReportSize, tt.args.maxGasLimit) - var updatedMessages []plugintypes.ExecutePluginCommitData + var updatedMessages []exectypes.CommitData for _, report := range tt.args.reports { updatedMessage, err := builder.Add(report) if err != nil && tt.wantErr != "" { @@ -876,18 +875,18 @@ func (t tdr) ReadTokenData( func Test_execReportBuilder_checkMessage(t *testing.T) { type fields struct { - tokenDataReader types.TokenDataReader + tokenDataReader exectypes.TokenDataReader accumulated validationMetadata } type args struct { idx int - execReport plugintypes.ExecutePluginCommitData + execReport exectypes.CommitData } tests := []struct { name string fields fields args args - expectedData plugintypes.ExecutePluginCommitData + expectedData exectypes.CommitData expectedStatus messageStatus expectedMetadata validationMetadata expectedError string @@ -902,7 +901,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { name: "already executed", args: args{ idx: 0, - execReport: plugintypes.ExecutePluginCommitData{ + execReport: exectypes.CommitData{ Messages: []cciptypes.Message{ makeMessage(1, 100, 0), }, @@ -916,7 +915,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { name: "bad token data", args: args{ idx: 0, - execReport: plugintypes.ExecutePluginCommitData{ + execReport: exectypes.CommitData{ Messages: []cciptypes.Message{ makeMessage(1, 100, 0), }, @@ -932,7 +931,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { name: "token data not ready", args: args{ idx: 0, - execReport: plugintypes.ExecutePluginCommitData{ + execReport: exectypes.CommitData{ Messages: []cciptypes.Message{ makeMessage(1, 100, 0), }, @@ -948,7 +947,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { name: "good token data is cached", args: args{ idx: 0, - execReport: plugintypes.ExecutePluginCommitData{ + execReport: exectypes.CommitData{ Messages: []cciptypes.Message{ makeMessage(1, 100, 0), }, @@ -958,7 +957,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { tokenDataReader: tdr{mode: good}, }, expectedStatus: ReadyToExecute, - expectedData: plugintypes.ExecutePluginCommitData{ + expectedData: exectypes.CommitData{ Messages: []cciptypes.Message{ makeMessage(1, 100, 0), }, @@ -971,7 +970,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { name: "good - no token data - 1 msg", args: args{ idx: 0, - execReport: plugintypes.ExecutePluginCommitData{ + execReport: exectypes.CommitData{ Messages: []cciptypes.Message{ makeMessage(1, 100, 0), }, @@ -981,7 +980,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { tokenDataReader: tdr{mode: noop}, }, expectedStatus: ReadyToExecute, - expectedData: plugintypes.ExecutePluginCommitData{ + expectedData: exectypes.CommitData{ Messages: []cciptypes.Message{ makeMessage(1, 100, 0), }, @@ -992,7 +991,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { name: "good - no token data - 2nd msg pads slice", args: args{ idx: 1, - execReport: plugintypes.ExecutePluginCommitData{ + execReport: exectypes.CommitData{ Messages: []cciptypes.Message{ makeMessage(1, 100, 0), makeMessage(1, 101, 0), @@ -1003,7 +1002,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { tokenDataReader: tdr{mode: noop}, }, expectedStatus: ReadyToExecute, - expectedData: plugintypes.ExecutePluginCommitData{ + expectedData: exectypes.CommitData{ Messages: []cciptypes.Message{ makeMessage(1, 100, 0), makeMessage(1, 101, 0), @@ -1019,7 +1018,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { lggr, logs := logger.TestObserved(t, zapcore.DebugLevel) // Select token data reader mock. - var resolvedTokenDataReader types.TokenDataReader + var resolvedTokenDataReader exectypes.TokenDataReader if tt.fields.tokenDataReader != nil { resolvedTokenDataReader = tt.fields.tokenDataReader } else { @@ -1048,7 +1047,7 @@ func Test_execReportBuilder_checkMessage(t *testing.T) { } assert.Equalf(t, tt.expectedStatus, status, "checkMessage(...)") // If expected data not provided, we expect the result to be the same as the input. - if reflect.DeepEqual(tt.expectedData, plugintypes.ExecutePluginCommitData{}) { + if reflect.DeepEqual(tt.expectedData, exectypes.CommitData{}) { assert.Equalf(t, tt.args.execReport, data, "checkMessage(...)") } else { assert.Equalf(t, tt.expectedData, data, "checkMessage(...)") diff --git a/execute/report/roots.go b/execute/report/roots.go index 761b6509e..41023e548 100644 --- a/execute/report/roots.go +++ b/execute/report/roots.go @@ -9,14 +9,14 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/merklemulti" cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" - "github.com/smartcontractkit/chainlink-ccip/plugintypes" + "github.com/smartcontractkit/chainlink-ccip/execute/exectypes" ) // ConstructMerkleTree creates the merkle tree object from the messages in the report. func ConstructMerkleTree( ctx context.Context, hasher cciptypes.MessageHasher, - report plugintypes.ExecutePluginCommitData, + report exectypes.CommitData, lggr logger.Logger, ) (*merklemulti.Tree[[32]byte], error) { // Ensure we have the expected number of messages diff --git a/mocks/execute/types/token_data_reader.go b/mocks/execute/exectypes/token_data_reader.go similarity index 99% rename from mocks/execute/types/token_data_reader.go rename to mocks/execute/exectypes/token_data_reader.go index 76abb3786..ef8098be4 100644 --- a/mocks/execute/types/token_data_reader.go +++ b/mocks/execute/exectypes/token_data_reader.go @@ -1,6 +1,6 @@ // Code generated by mockery v2.43.0. DO NOT EDIT. -package types +package exectypes import ( context "context" diff --git a/plugintypes/execute.go b/plugintypes/execute.go deleted file mode 100644 index e6e86f7b5..000000000 --- a/plugintypes/execute.go +++ /dev/null @@ -1,134 +0,0 @@ -package plugintypes - -import ( - "encoding/json" - "sort" - "time" - - cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" -) - -// /////////////////////// -// Execute Observation // -// /////////////////////// - -// ExecutePluginCommitData is the data that is committed to the chain. -type ExecutePluginCommitData struct { - // SourceChain of the chain that contains the commit report. - SourceChain cciptypes.ChainSelector `json:"chainSelector"` - // Timestamp of the block that contains the commit. - Timestamp time.Time `json:"timestamp"` - // BlockNum of the block that contains the commit. - BlockNum uint64 `json:"blockNum"` - // MerkleRoot of the messages that are in this commit report. - MerkleRoot cciptypes.Bytes32 `json:"merkleRoot"` - // SequenceNumberRange of the messages that are in this commit report. - SequenceNumberRange cciptypes.SeqNumRange `json:"sequenceNumberRange"` - - // Messages that are part of the commit report. - Messages []cciptypes.Message `json:"messages"` - - // ExecutedMessages are the messages in this report that have already been executed. - ExecutedMessages []cciptypes.SeqNum `json:"executedMessages"` - - // The following values are cached for validation algorithms, serialization is not required for consensus. - - // TokenData for each message. - TokenData [][][]byte `json:"-"` -} - -type ExecutePluginCommitObservations map[cciptypes.ChainSelector][]ExecutePluginCommitData -type ExecutePluginMessageObservations map[cciptypes.ChainSelector]map[cciptypes.SeqNum]cciptypes.Message - -// ExecutePluginObservation is the observation of the ExecutePlugin. -// TODO: revisit observation types. The maps used here are more space efficient and easier to work -// with but require more transformations compared to the on-chain representations. -type ExecutePluginObservation struct { - // CommitReports are determined during the first phase of execute. - // It contains the commit reports we would like to execute in the following round. - CommitReports ExecutePluginCommitObservations `json:"commitReports"` - // Messages are determined during the second phase of execute. - // Ideally, it contains all the messages identified by the previous outcome's - // NextCommits. With the previous outcome, and these messsages, we can build the - // execute report. - Messages ExecutePluginMessageObservations `json:"messages"` - // TODO: some of the nodes configuration may need to be included here. -} - -func NewExecutePluginObservation( - commitReports ExecutePluginCommitObservations, messages ExecutePluginMessageObservations) ExecutePluginObservation { - return ExecutePluginObservation{ - CommitReports: commitReports, - Messages: messages, - } -} - -func (obs ExecutePluginObservation) Encode() ([]byte, error) { - return json.Marshal(obs) -} - -func DecodeExecutePluginObservation(b []byte) (ExecutePluginObservation, error) { - obs := ExecutePluginObservation{} - err := json.Unmarshal(b, &obs) - return obs, err -} - -// /////////////////// -// Execute Outcome // -// /////////////////// - -// ExecutePluginOutcome is the outcome of the ExecutePlugin. -type ExecutePluginOutcome struct { - // PendingCommitReports are the oldest reports with pending commits. The slice is - // sorted from oldest to newest. - PendingCommitReports []ExecutePluginCommitData `json:"commitReports"` - - // Report is built from the oldest pending commit reports. - Report cciptypes.ExecutePluginReport `json:"report"` -} - -func (o ExecutePluginOutcome) IsEmpty() bool { - return len(o.PendingCommitReports) == 0 && len(o.Report.ChainReports) == 0 -} - -func NewExecutePluginOutcome( - pendingCommits []ExecutePluginCommitData, - report cciptypes.ExecutePluginReport, -) ExecutePluginOutcome { - return newSortedExecuteOutcome(pendingCommits, report) -} - -// Encode encodes the outcome by first sorting the pending commit reports and the chain reports -// and then JSON marshalling. -// The encoding MUST be deterministic. -func (o ExecutePluginOutcome) Encode() ([]byte, error) { - // We sort again here in case construction is not via the constructor. - return json.Marshal(newSortedExecuteOutcome(o.PendingCommitReports, o.Report)) -} - -func newSortedExecuteOutcome( - pendingCommits []ExecutePluginCommitData, - report cciptypes.ExecutePluginReport) ExecutePluginOutcome { - pendingCommitsCP := append([]ExecutePluginCommitData{}, pendingCommits...) - reportCP := append([]cciptypes.ExecutePluginReportSingleChain{}, report.ChainReports...) - sort.Slice( - pendingCommitsCP, - func(i, j int) bool { - return pendingCommitsCP[i].SourceChain < pendingCommitsCP[j].SourceChain - }) - sort.Slice( - reportCP, - func(i, j int) bool { - return reportCP[i].SourceChainSelector < reportCP[j].SourceChainSelector - }) - return ExecutePluginOutcome{ - PendingCommitReports: pendingCommitsCP, - Report: cciptypes.ExecutePluginReport{ChainReports: reportCP}, - } -} - -func DecodeExecutePluginOutcome(b []byte) (ExecutePluginOutcome, error) { - o := ExecutePluginOutcome{} - err := json.Unmarshal(b, &o) - return o, err -}