Skip to content

Commit

Permalink
Disable nonce checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Aug 20, 2024
1 parent 1b75294 commit 4f6dda6
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 96 deletions.
102 changes: 52 additions & 50 deletions execute/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ const (
TokenDataNotReady messageStatus = "token_data_not_ready" //nolint:gosec // this is not a password
TokenDataFetchError messageStatus = "token_data_fetch_error"
InsufficientRemainingBatchGas messageStatus = "insufficient_remaining_batch_gas"
MissingNoncesForChain messageStatus = "missing_nonces_for_chain"
MissingNonce messageStatus = "missing_nonce"
InvalidNonce messageStatus = "invalid_nonce"
//MissingNoncesForChain messageStatus = "missing_nonces_for_chain"
//MissingNonce messageStatus = "missing_nonce"
//InvalidNonce messageStatus = "invalid_nonce"
/*
SenderAlreadySkipped messageStatus = "sender_already_skipped"
MessageMaxGasCalcError messageStatus = "message_max_gas_calc_error"
Expand Down Expand Up @@ -210,54 +210,56 @@ func (b *execReportBuilder) checkMessage(
"data", tokenData)

// 3. Check if the message has a valid nonce.
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,
)
return execReport, MissingNoncesForChain, nil
}

chainNonces := b.sendersNonce[execReport.SourceChain]
sender := msg.Sender.String()
if _, ok := chainNonces[sender]; !ok {
b.lggr.Errorw("Skipping message - missing nonce",
"messageID", msg.Header.MessageID,
"sourceChain", execReport.SourceChain,
"seqNum", msg.Header.SequenceNumber,
)
return execReport, MissingNonce, nil
}

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],
)
return execReport, InvalidNonce, nil
/*
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,
)
return execReport, MissingNoncesForChain, nil
}
chainNonces := b.sendersNonce[execReport.SourceChain]
sender := msg.Sender.String()
if _, ok := chainNonces[sender]; !ok {
b.lggr.Errorw("Skipping message - missing nonce",
"messageID", msg.Header.MessageID,
"sourceChain", execReport.SourceChain,
"seqNum", msg.Header.SequenceNumber,
)
return execReport, MissingNonce, nil
}
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],
)
return execReport, InvalidNonce, nil
}
b.expectedNonce[execReport.SourceChain][sender] = b.expectedNonce[execReport.SourceChain][sender] + 1
}
b.expectedNonce[execReport.SourceChain][sender] = b.expectedNonce[execReport.SourceChain][sender] + 1
}
*/

// TODO: Check for fee boost

Expand Down
94 changes: 48 additions & 46 deletions execute/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,62 +1122,64 @@ func Test_execReportBuilder_checkMessage(t *testing.T) {
TokenData: [][][]byte{nil, nil},
},
},
{
name: "missing chain nonce",
args: args{
idx: 0,
execReport: exectypes.CommitData{
SourceChain: 1,
Messages: []cciptypes.Message{
makeMessage(1, 100, 1),
/*
{
name: "missing chain nonce",
args: args{
idx: 0,
execReport: exectypes.CommitData{
SourceChain: 1,
Messages: []cciptypes.Message{
makeMessage(1, 100, 1),
},
},
},
},
fields: fields{
tokenDataReader: tdr{mode: noop},
},
expectedStatus: MissingNoncesForChain,
},
{
name: "missing sender nonce",
args: args{
idx: 0,
nonces: map[cciptypes.ChainSelector]map[string]uint64{
1: {},
fields: fields{
tokenDataReader: tdr{mode: noop},
},
execReport: exectypes.CommitData{
SourceChain: 1,
Messages: []cciptypes.Message{
makeMessage(1, 100, 1),
expectedStatus: MissingNoncesForChain,
},
{
name: "missing sender nonce",
args: args{
idx: 0,
nonces: map[cciptypes.ChainSelector]map[string]uint64{
1: {},
},
execReport: exectypes.CommitData{
SourceChain: 1,
Messages: []cciptypes.Message{
makeMessage(1, 100, 1),
},
},
},
fields: fields{
tokenDataReader: tdr{mode: noop},
},
expectedStatus: MissingNonce,
},
fields: fields{
tokenDataReader: tdr{mode: noop},
},
expectedStatus: MissingNonce,
},
{
name: "invalid sender nonce",
args: args{
idx: 0,
nonces: map[cciptypes.ChainSelector]map[string]uint64{
1: {
"0x": 99,
{
name: "invalid sender nonce",
args: args{
idx: 0,
nonces: map[cciptypes.ChainSelector]map[string]uint64{
1: {
"0x": 99,
},
},
},
execReport: exectypes.CommitData{
SourceChain: 1,
Messages: []cciptypes.Message{
makeMessage(1, 100, 1),
execReport: exectypes.CommitData{
SourceChain: 1,
Messages: []cciptypes.Message{
makeMessage(1, 100, 1),
},
},
},
fields: fields{
tokenDataReader: tdr{mode: noop},
},
expectedStatus: InvalidNonce,
},
fields: fields{
tokenDataReader: tdr{mode: noop},
},
expectedStatus: InvalidNonce,
},
*/
}
for _, tt := range tests {
tt := tt
Expand Down

0 comments on commit 4f6dda6

Please sign in to comment.