-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Interop load testing #15768
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
Merged
Merged
Interop load testing #15768
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
op-acceptance-tests/tests/interop/loadtest/interop_load_test.go
This file contains hidden or 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,116 @@ | ||
| package loadtest | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/rand" | ||
| "sync" | ||
| "testing" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/devnet-sdk/contracts/constants" | ||
| "github.com/ethereum-optimism/optimism/op-acceptance-tests/tests/interop" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/devtest" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/presets" | ||
| "github.com/ethereum-optimism/optimism/op-service/eth" | ||
| "github.com/ethereum-optimism/optimism/op-service/retry" | ||
| "github.com/ethereum-optimism/optimism/op-service/txintent" | ||
| "github.com/ethereum-optimism/optimism/op-service/txplan" | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| presets.DoMain(m, presets.WithSimpleInterop()) | ||
| } | ||
|
|
||
| // TestExecFromSameAddressInALoop spams transactions that each execute hundreds of initiating messages. | ||
| func TestExecFromSameAddressInALoop(gt *testing.T) { | ||
| if testing.Short() { | ||
| gt.Skip("skipping load test in short mode") | ||
| } | ||
| t := devtest.SerialT(gt) | ||
| sys := presets.NewSimpleInterop(t) | ||
| eoaA := sys.FunderA.NewFundedEOA(eth.MillionEther) | ||
| eoaB := sys.FunderB.NewFundedEOA(eth.MillionEther) | ||
|
|
||
| eventLoggerAddress := eoaA.DeployEventLogger() | ||
|
|
||
| // Create a transaction that emits numMsgs logs in a single transaction using multicall and the event logger. | ||
| const numMsgs = 275 // About the max number of msgs we can create before hitting tx size limits. | ||
| initMsgsTx := txintent.NewIntent[*txintent.MultiTrigger, *txintent.InteropOutput](eoaA.Plan()) | ||
| initCalls := make([]txintent.Call, 0, numMsgs) | ||
| rng := rand.New(rand.NewSource(1234)) | ||
| for range numMsgs { | ||
| initCalls = append(initCalls, interop.RandomInitTrigger(rng, eventLoggerAddress, rng.Intn(5), rng.Intn(10))) | ||
| } | ||
| initMsgsTx.Content.Set(&txintent.MultiTrigger{ | ||
| Emitter: constants.MultiCall3, | ||
| Calls: initCalls, | ||
| }) | ||
| initResult, err := initMsgsTx.Result.Eval(t.Ctx()) | ||
| t.Require().NoError(err) | ||
| t.Require().Len(initResult.Entries, numMsgs) | ||
| _, err = initMsgsTx.PlannedTx.Success.Eval(t.Ctx()) | ||
| t.Require().NoError(err) | ||
|
|
||
| // Wait to include the exec txs until we know it will be included at a higher timestamp than initMsgsTx, modulo reorgs. | ||
| // NOTE: this should be `<`, but the mempool filtering in op-geth currently uses the unsafe head's timestamp instead of | ||
| // the pending timestamp. See https://github.com/ethereum-optimism/op-geth/issues/603. | ||
| for sys.L2ChainB.UnsafeHeadRef().Time <= initMsgsTx.PlannedTx.IncludedBlock.Value().Time { | ||
| sys.L2ChainB.WaitForBlock() | ||
| } | ||
|
|
||
| execCalls := make([]txintent.Call, 0, numMsgs) | ||
| for i := range numMsgs { | ||
| execCalls = append(execCalls, &txintent.ExecTrigger{ | ||
| Executor: constants.CrossL2Inbox, | ||
| Msg: initResult.Entries[i], | ||
| }) | ||
| } | ||
| const numExecTxs = 1_000 | ||
| execMsgsTxs := make([]*txintent.IntentTx[*txintent.MultiTrigger, txintent.Result], 0, numExecTxs) | ||
| for i := range numExecTxs { | ||
| execMsgsTx := txintent.NewIntent[*txintent.MultiTrigger, txintent.Result](eoaB.Plan(), txplan.WithRetryInclusion(sys.L2ELB.Escape().EthClient(), 50, retry.Exponential())) | ||
| execMsgsTx.Content.Set(&txintent.MultiTrigger{ | ||
| Emitter: constants.MultiCall3, | ||
| Calls: execCalls, | ||
| }) | ||
| if i != 0 { | ||
| prevNonce := &execMsgsTxs[i-1].PlannedTx.Nonce | ||
| execMsgsTx.PlannedTx.Nonce.DependOn(prevNonce) | ||
| execMsgsTx.PlannedTx.Nonce.Fn(func(_ context.Context) (uint64, error) { | ||
| prevNonceU64, err := prevNonce.Get() | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| return prevNonceU64 + 1, nil | ||
| }) | ||
| } | ||
| execMsgsTxs = append(execMsgsTxs, execMsgsTx) | ||
| } | ||
| var wg sync.WaitGroup | ||
| wg.Add(len(execMsgsTxs)) | ||
| for _, execMsgsTx := range execMsgsTxs { | ||
| go func(tx *txplan.PlannedTx) { | ||
| defer wg.Done() | ||
| receipt, err := tx.Included.Eval(t.Ctx()) | ||
| t.Require().NoError(err) | ||
| t.Require().Len(receipt.Logs, numMsgs) | ||
| _, err = tx.Success.Eval(t.Ctx()) | ||
| t.Require().NoError(err) | ||
|
|
||
| // Wait for the transaction to be cross-safe. | ||
| includedBlock, err := tx.IncludedBlock.Eval(t.Ctx()) | ||
| t.Require().NoError(err) | ||
| for { | ||
| crossSafeID, err := sys.Supervisor.Escape().QueryAPI().CrossSafe(t.Ctx(), sys.L2ChainB.ChainID()) | ||
| t.Require().NoError(err) | ||
| if includedBlock.ID().Number <= crossSafeID.Derived.Number { | ||
| break | ||
| } | ||
| sys.L2ChainB.WaitForBlock() | ||
| } | ||
| // Sanity check that includedBlock is still in the canonical chain. | ||
| _, err = sys.L2ELB.Escape().EthClient().BlockRefByHash(t.Ctx(), includedBlock.Hash) | ||
| t.Require().NoError(err) | ||
| }(execMsgsTx.PlannedTx) | ||
| } | ||
| wg.Wait() | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.