-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move plugintypes.execute.go to exectypes package (#58)
- Loading branch information
Showing
18 changed files
with
339 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:"-"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
2 changes: 1 addition & 1 deletion
2
execute/types/token_data_reader.go → execute/exectypes/token_data_reader.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package types | ||
package exectypes | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.