Skip to content

Commit

Permalink
Add missing comments, delete dead code, linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Jan 9, 2025
1 parent e7bb048 commit 5c3ed89
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 70 deletions.
22 changes: 14 additions & 8 deletions execute/report/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@ type ExecReportBuilder interface {
Build() ([]cciptypes.ExecutePluginReportSingleChain, error)
}

// Option that can be passed to the builder.
type Option func(erb *execReportBuilder)

// WithMaxGas limits how much gas can be used during execution.
func WithMaxGas(maxGas uint64) func(*execReportBuilder) {
return func(erb *execReportBuilder) {
erb.maxGas = maxGas
}
}

// WithMaxReportSizeBytes configures the maximum report size.
func WithMaxReportSizeBytes(maxReportSizeBytes uint64) Option {
return func(erb *execReportBuilder) {
erb.maxReportSizeBytes = maxReportSizeBytes
}
}

func MaxMessages(maxMessages uint64) Option {
// WithMaxMessages configures the number of messages allowed to be in a report.
func WithMaxMessages(maxMessages uint64) Option {
return func(erb *execReportBuilder) {
erb.maxMessages = maxMessages
panic("not implemented")
Expand Down Expand Up @@ -62,13 +66,11 @@ func newBuilderInternal(
}

builder := &execReportBuilder{
lggr: logger,

checks: defaultChecks,
encoder: encoder,
hasher: hasher,
estimateProvider: estimateProvider,

lggr: logger,
checks: defaultChecks,
encoder: encoder,
hasher: hasher,
estimateProvider: estimateProvider,
destChainSelector: destChainSelector,
}

Expand All @@ -81,6 +83,7 @@ func newBuilderInternal(
return builder
}

// NewBuilder constructs the report builder.
func NewBuilder(
logger logger.Logger,
hasher cciptypes.MessageHasher,
Expand Down Expand Up @@ -127,6 +130,9 @@ type execReportBuilder struct {
execReports []cciptypes.ExecutePluginReportSingleChain
}

// Add an exec report for as many messages as possible in the given commit report.
// The commit report with updated metadata is returned, it reflects which messages
// were selected for the exec report.
func (b *execReportBuilder) Add(
ctx context.Context,
commitReport exectypes.CommitData,
Expand Down
61 changes: 3 additions & 58 deletions execute/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func CheckAlreadyExecuted() Check {
}
}

// CheckTokenData rejects messages which are missing their token data (attestations, i.e. CCTP).
func CheckTokenData() Check {
return func(lggr logger.Logger, msg ccipocr3.Message, idx int, report exectypes.CommitData) (messageStatus, error) {
if idx >= len(report.MessageTokenData) {
Expand Down Expand Up @@ -294,6 +295,7 @@ func CheckNonces(sendersNonce map[cciptypes.ChainSelector]map[string]uint64) Che
}
}

// checkMessage for execution readiness.
func (b *execReportBuilder) checkMessage(
_ context.Context, idx int, execReport exectypes.CommitData,
) (exectypes.CommitData, messageStatus, error) {
Expand Down Expand Up @@ -322,64 +324,7 @@ func (b *execReportBuilder) checkMessage(
return result, ReadyToExecute, nil
}

/*
func (b *execReportBuilder) checkMessageNonce(
msg cciptypes.Message,
execReport exectypes.CommitData,
) messageStatus {
if msg.Header.Nonce != 0 {
// Sequenced messages have non-zero nonces.
if _, ok := b.sendersNonce[execReport.SourceChain]; !ok {
b.lggr.Errorw("Skipping message - nonces not available for chain",
"messageID", msg.Header.MessageID,
"sourceChain", execReport.SourceChain,
"seqNum", msg.Header.SequenceNumber,
"messageState", MissingNoncesForChain)
return MissingNoncesForChain
}
chainNonces := b.sendersNonce[execReport.SourceChain]
sender := typeconv.AddressBytesToString(msg.Sender[:], uint64(msg.Header.SourceChainSelector))
if _, ok := chainNonces[sender]; !ok {
b.lggr.Errorw("Skipping message - missing nonce",
"messageID", msg.Header.MessageID,
"sourceChain", execReport.SourceChain,
"seqNum", msg.Header.SequenceNumber,
"messageState", MissingNonce)
return MissingNonce
}
if b.expectedNonce == nil {
// initialize expected nonce if needed.
b.expectedNonce = make(map[cciptypes.ChainSelector]map[string]uint64)
}
if _, ok := b.expectedNonce[execReport.SourceChain]; !ok {
// initialize expected nonce if needed.
b.expectedNonce[execReport.SourceChain] = make(map[string]uint64)
}
if _, ok := b.expectedNonce[execReport.SourceChain][sender]; !ok {
b.expectedNonce[execReport.SourceChain][sender] = chainNonces[sender] + 1
}
// Check expected nonce is valid for sequenced messages.
if msg.Header.Nonce != b.expectedNonce[execReport.SourceChain][sender] {
b.lggr.Warnw("Skipping message - invalid nonce",
"messageID", msg.Header.MessageID,
"sourceChain", execReport.SourceChain,
"seqNum", msg.Header.SequenceNumber,
"have", msg.Header.Nonce,
"want", b.expectedNonce[execReport.SourceChain][sender],
"messageState", InvalidNonce)
return InvalidNonce
}
b.expectedNonce[execReport.SourceChain][sender] = b.expectedNonce[execReport.SourceChain][sender] + 1
}
return ""
}
*/

// verifyReport is a final step to ensure the encoded message meets our exec criteria.
func (b *execReportBuilder) verifyReport(
ctx context.Context,
execReport cciptypes.ExecutePluginReportSingleChain,
Expand Down
4 changes: 0 additions & 4 deletions execute/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,17 +970,13 @@ func Test_execReportBuilder_verifyReport(t *testing.T) {
}

func Test_execReportBuilder_checkMessage(t *testing.T) {
type fields struct {
accumulated validationMetadata
}
type args struct {
idx int
nonces map[cciptypes.ChainSelector]map[string]uint64
execReport exectypes.CommitData
}
tests := []struct {
name string
fields fields
args args
expectedData exectypes.CommitData
expectedStatus messageStatus
Expand Down

0 comments on commit 5c3ed89

Please sign in to comment.