Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec: Skip messages that do not fit #40

Merged
merged 8 commits into from
Jul 29, 2024

Conversation

winder
Copy link
Contributor

@winder winder commented Jul 19, 2024

Three main changes:

  1. Rewrite selectReport test to use the report builder, move to report builder package.
  2. Update buildSingleChainReport to select reports by index rather than by a maximum number of messages to select.
  3. Introduce checkMesssage and verifyReport functions to contain business logic to determine whether messages are ready to be executed and if the final report is valid.

@winder winder marked this pull request as ready for review July 19, 2024 13:50
Comment on lines +656 to +668
builder := NewBuilder(ctx, lggr, hasher, tokenDataReader, codec, tt.args.maxReportSize, 0)
var updatedMessages []plugintypes.ExecutePluginCommitDataWithMessages
for _, report := range tt.args.reports {
updatedMessage, err := builder.Add(report)
if err != nil && tt.wantErr != "" {
if strings.Contains(err.Error(), tt.wantErr) {
foundError = true
break
}
}
require.NoError(t, err)
updatedMessages = append(updatedMessages, updatedMessage)
}
Copy link
Contributor Author

@winder winder Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost identical to the previous selectReports test. This part was swapped to use the builder directly, and there are 2 new test cases to cover the "skip over message that doesn't fit" logic.

Comment on lines -161 to -179
{
name: "bad codec",
wantErr: "unable to encode report: bad codec",
args: args{
report: plugintypes.ExecutePluginCommitDataWithMessages{
ExecutePluginCommitData: plugintypes.ExecutePluginCommitData{
SourceChain: 1234567,
SequenceNumberRange: cciptypes.NewSeqNumRange(cciptypes.SeqNum(100), cciptypes.SeqNum(100)),
},
Messages: []cciptypes.Message{
{Header: cciptypes.RampMessageHeader{
SourceChainSelector: 1234567,
SequenceNumber: cciptypes.SeqNum(100),
}},
},
},
codec: badCodec{},
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case will return when I test the new checkMessage and verifyReport methods.

return false
finalReport = cciptypes.ExecutePluginReportSingleChain{}
msgs := make(map[int]struct{})
for i := range report.Messages {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asoliman92 this is where sort.Search is replaced. The algorithm now adds messages in one at a time rather than attempting a binary search. I'm still not entirely happy with either approach.

return ReadyToExecute, nil
}

func (b *execReportBuilder) verifyReport(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice validationMetadata, this type holds the encoded size and will also hold the gas limit and perhaps the fee boost ratio. It is computed per report, and accumulated as part of the builder.

Comment on lines +127 to +149
type messageStatus string

const (
ReadyToExecute messageStatus = "ready_to_execute"
AlreadyExecuted messageStatus = "already_executed"
/*
SenderAlreadySkipped messageStatus = "sender_already_skipped"
MessageMaxGasCalcError messageStatus = "message_max_gas_calc_error"
InsufficientRemainingBatchDataLength messageStatus = "insufficient_remaining_batch_data_length"
InsufficientRemainingBatchGas messageStatus = "insufficient_remaining_batch_gas"
MissingNonce messageStatus = "missing_nonce"
InvalidNonce messageStatus = "invalid_nonce"
AggregateTokenValueComputeError messageStatus = "aggregate_token_value_compute_error"
AggregateTokenLimitExceeded messageStatus = "aggregate_token_limit_exceeded"
TokenDataNotReady messageStatus = "token_data_not_ready"
TokenDataFetchError messageStatus = "token_data_fetch_error"
TokenNotInDestTokenPrices messageStatus = "token_not_in_dest_token_prices"
TokenNotInSrcTokenPrices messageStatus = "token_not_in_src_token_prices"
InsufficientRemainingFee messageStatus = "insufficient_remaining_fee"
AddedToBatch messageStatus = "added_to_batch"
*/
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all the things in the ocr2 implementation. I guess that all of them need to be part of the new verify/check methods.

) (cciptypes.ExecutePluginReportSingleChain, int, error) {
if maxMessages == 0 {
maxMessages = len(report.Messages)
messages map[int]struct{},
Copy link
Contributor Author

@winder winder Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched from taking the first N messages, to taking specific messages. Manipulating the content of this map is how messages are skipped.

buildSingleChainReportMaxSize(b.ctx, b.lggr, b.hasher, b.tokenDataReader, b.encoder,
commitReport,
int(b.maxReportSizeBytes-b.reportSizeBytes))
execReport, updatedReport, err := b.buildSingleChainReport(b.ctx, commitReport)

Copy link
Contributor Author

@winder winder Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that the maximum size is gone, it's now part of the object along with the provider arguments.

execute/report/report.go Outdated Show resolved Hide resolved
execute/report/report.go Show resolved Hide resolved
@winder winder force-pushed the will/skip-messages-that-do-not-fit branch 2 times, most recently from f258998 to 23a10bf Compare July 29, 2024 13:13
@winder winder force-pushed the will/skip-messages-that-do-not-fit branch from 23a10bf to 4e7ed29 Compare July 29, 2024 17:49
Copy link

Test Coverage

Branch Coverage
will/skip-messages-that-do-not-fit 77.4%
ccip-develop 74.2%

@winder winder merged commit 742473d into ccip-develop Jul 29, 2024
1 check passed
@winder winder deleted the will/skip-messages-that-do-not-fit branch July 29, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants