-
Notifications
You must be signed in to change notification settings - Fork 451
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
Fix minor comments from Timeboost PR #2787
Changes from 4 commits
b7d1b06
436f831
b991d76
f5ca4bf
23869a2
066ff17
dc65eef
969dc1d
5a02894
cc75bf2
3b67813
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,10 +231,21 @@ func Test_expressLaneService_validateExpressLaneTx(t *testing.T) { | |
} | ||
} | ||
|
||
type stubPublisher struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not critical: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored it along those lines. |
||
publishFn func(parentCtx context.Context, tx *types.Transaction, options *arbitrum_types.ConditionalOptions, delay bool) error | ||
} | ||
|
||
func (s *stubPublisher) publishTransactionImpl(parentCtx context.Context, tx *types.Transaction, options *arbitrum_types.ConditionalOptions, isExpressLaneController bool) error { | ||
return s.publishFn(parentCtx, tx, options, isExpressLaneController) | ||
} | ||
|
||
func Test_expressLaneService_sequenceExpressLaneSubmission_nonceTooLow(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
els := &expressLaneService{ | ||
transactionPublisher: &stubPublisher{func(parentCtx context.Context, tx *types.Transaction, options *arbitrum_types.ConditionalOptions, delay bool) error { | ||
return nil | ||
}}, | ||
messagesBySequenceNumber: make(map[uint64]*timeboost.ExpressLaneSubmission), | ||
roundControl: lru.NewCache[uint64, *expressLaneControl](8), | ||
} | ||
|
@@ -244,17 +255,20 @@ func Test_expressLaneService_sequenceExpressLaneSubmission_nonceTooLow(t *testin | |
msg := &timeboost.ExpressLaneSubmission{ | ||
SequenceNumber: 0, | ||
} | ||
publishFn := func(parentCtx context.Context, tx *types.Transaction, options *arbitrum_types.ConditionalOptions, delay bool) error { | ||
return nil | ||
} | ||
err := els.sequenceExpressLaneSubmission(ctx, msg, publishFn) | ||
|
||
err := els.sequenceExpressLaneSubmission(ctx, msg) | ||
require.ErrorIs(t, err, timeboost.ErrSequenceNumberTooLow) | ||
} | ||
|
||
func Test_expressLaneService_sequenceExpressLaneSubmission_duplicateNonce(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
numPublished := 0 | ||
els := &expressLaneService{ | ||
transactionPublisher: &stubPublisher{func(parentCtx context.Context, tx *types.Transaction, options *arbitrum_types.ConditionalOptions, delay bool) error { | ||
numPublished += 1 | ||
return nil | ||
}}, | ||
roundControl: lru.NewCache[uint64, *expressLaneControl](8), | ||
messagesBySequenceNumber: make(map[uint64]*timeboost.ExpressLaneSubmission), | ||
} | ||
|
@@ -264,39 +278,36 @@ func Test_expressLaneService_sequenceExpressLaneSubmission_duplicateNonce(t *tes | |
msg := &timeboost.ExpressLaneSubmission{ | ||
SequenceNumber: 2, | ||
} | ||
numPublished := 0 | ||
publishFn := func(parentCtx context.Context, tx *types.Transaction, options *arbitrum_types.ConditionalOptions, delay bool) error { | ||
numPublished += 1 | ||
return nil | ||
} | ||
err := els.sequenceExpressLaneSubmission(ctx, msg, publishFn) | ||
err := els.sequenceExpressLaneSubmission(ctx, msg) | ||
require.NoError(t, err) | ||
// Because the message is for a future sequence number, it | ||
// should get queued, but not yet published. | ||
require.Equal(t, 0, numPublished) | ||
// Sending it again should give us an error. | ||
err = els.sequenceExpressLaneSubmission(ctx, msg, publishFn) | ||
err = els.sequenceExpressLaneSubmission(ctx, msg) | ||
require.ErrorIs(t, err, timeboost.ErrDuplicateSequenceNumber) | ||
} | ||
|
||
func Test_expressLaneService_sequenceExpressLaneSubmission_outOfOrder(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
numPublished := 0 | ||
publishedTxOrder := make([]uint64, 0) | ||
els := &expressLaneService{ | ||
roundControl: lru.NewCache[uint64, *expressLaneControl](8), | ||
messagesBySequenceNumber: make(map[uint64]*timeboost.ExpressLaneSubmission), | ||
} | ||
els.roundControl.Add(0, &expressLaneControl{ | ||
sequence: 1, | ||
}) | ||
numPublished := 0 | ||
publishedTxOrder := make([]uint64, 0) | ||
control, _ := els.roundControl.Get(0) | ||
publishFn := func(parentCtx context.Context, tx *types.Transaction, options *arbitrum_types.ConditionalOptions, delay bool) error { | ||
els.transactionPublisher = &stubPublisher{func(parentCtx context.Context, tx *types.Transaction, options *arbitrum_types.ConditionalOptions, delay bool) error { | ||
numPublished += 1 | ||
publishedTxOrder = append(publishedTxOrder, control.sequence) | ||
return nil | ||
} | ||
}} | ||
|
||
els.roundControl.Add(0, &expressLaneControl{ | ||
sequence: 1, | ||
}) | ||
|
||
messages := []*timeboost.ExpressLaneSubmission{ | ||
{ | ||
SequenceNumber: 10, | ||
|
@@ -315,14 +326,14 @@ func Test_expressLaneService_sequenceExpressLaneSubmission_outOfOrder(t *testing | |
}, | ||
} | ||
for _, msg := range messages { | ||
err := els.sequenceExpressLaneSubmission(ctx, msg, publishFn) | ||
err := els.sequenceExpressLaneSubmission(ctx, msg) | ||
require.NoError(t, err) | ||
} | ||
// We should have only published 2, as we are missing sequence number 3. | ||
require.Equal(t, 2, numPublished) | ||
require.Equal(t, len(messages), len(els.messagesBySequenceNumber)) | ||
|
||
err := els.sequenceExpressLaneSubmission(ctx, &timeboost.ExpressLaneSubmission{SequenceNumber: 3}, publishFn) | ||
err := els.sequenceExpressLaneSubmission(ctx, &timeboost.ExpressLaneSubmission{SequenceNumber: 3}) | ||
require.NoError(t, err) | ||
require.Equal(t, 5, numPublished) | ||
} | ||
|
@@ -340,14 +351,15 @@ func Test_expressLaneService_sequenceExpressLaneSubmission_erroredTx(t *testing. | |
numPublished := 0 | ||
publishedTxOrder := make([]uint64, 0) | ||
control, _ := els.roundControl.Get(0) | ||
publishFn := func(parentCtx context.Context, tx *types.Transaction, options *arbitrum_types.ConditionalOptions, delay bool) error { | ||
els.transactionPublisher = &stubPublisher{func(parentCtx context.Context, tx *types.Transaction, options *arbitrum_types.ConditionalOptions, delay bool) error { | ||
if tx == nil { | ||
return errors.New("oops, bad tx") | ||
} | ||
numPublished += 1 | ||
publishedTxOrder = append(publishedTxOrder, control.sequence) | ||
return nil | ||
} | ||
}} | ||
|
||
messages := []*timeboost.ExpressLaneSubmission{ | ||
{ | ||
SequenceNumber: 1, | ||
|
@@ -368,10 +380,10 @@ func Test_expressLaneService_sequenceExpressLaneSubmission_erroredTx(t *testing. | |
} | ||
for _, msg := range messages { | ||
if msg.Transaction == nil { | ||
err := els.sequenceExpressLaneSubmission(ctx, msg, publishFn) | ||
err := els.sequenceExpressLaneSubmission(ctx, msg) | ||
require.ErrorContains(t, err, "oops, bad tx") | ||
} else { | ||
err := els.sequenceExpressLaneSubmission(ctx, msg, publishFn) | ||
err := els.sequenceExpressLaneSubmission(ctx, msg) | ||
require.NoError(t, err) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mybe have something like "PublishFastLaneTransaction" or similar that doesn't accept the bool and is trivially implemented in the sequencer or a wrapper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored it along those lines.