-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
have batcher submit appropriate cancellation transactions when mempoo…
…l is blocked (#10941) * have batcher submit appropriate cancellation transactions when mempool is blocked * use a txRef type with a isCancel indicator instead of a magic channel id indicator
- Loading branch information
1 parent
4b80464
commit b7f8188
Showing
11 changed files
with
316 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,61 @@ | ||
package batcher | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/go-ethereum/core/txpool" | ||
|
||
"github.com/ethereum-optimism/optimism/op-service/txmgr" | ||
) | ||
|
||
type TestBatchSubmitter struct { | ||
*BatchSubmitter | ||
ttm *txmgr.TestTxManager | ||
} | ||
|
||
// JamTxPool is for testing ONLY. It sends a txpool-blocking transaction. This function must be | ||
// called *before* the batcher starts submitting batches to ensure successful jamming, and will | ||
// error out otherwise. | ||
func (l *TestBatchSubmitter) JamTxPool(ctx context.Context) error { | ||
l.mutex.Lock() | ||
defer l.mutex.Unlock() | ||
if l.running { | ||
return errors.New("tried to jam tx pool but batcher is already running") | ||
} | ||
var candidate *txmgr.TxCandidate | ||
var err error | ||
if l.Config.UseBlobs { | ||
candidate = l.calldataTxCandidate([]byte{}) | ||
} else if candidate, err = l.blobTxCandidate(emptyTxData); err != nil { | ||
return err | ||
} | ||
if candidate.GasLimit, err = core.IntrinsicGas(candidate.TxData, nil, false, true, true, false); err != nil { | ||
return err | ||
} | ||
|
||
l.ttm = &txmgr.TestTxManager{ | ||
SimpleTxManager: l.Txmgr, | ||
} | ||
l.Log.Info("sending txpool blocking test tx") | ||
if err := l.ttm.JamTxPool(ctx, *candidate); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// Wait on the jamming transaction, and return error if it completes successfully. (Tests should | ||
// expect the blocking transaction to result in error from the context being cancelled.) | ||
func (l *TestBatchSubmitter) WaitOnJammingTx(ctx context.Context) error { | ||
err := l.ttm.WaitOnJammingTx(ctx) | ||
if err == nil { | ||
return errors.New("txpool blocking tx didn't block!") | ||
} | ||
if strings.Contains(err.Error(), txpool.ErrAlreadyReserved.Error()) { | ||
return errors.New("txpool blocking tx failed because other tx in mempool is blocking it") | ||
} | ||
l.Log.Info("done waiting on jamming tx", "err", err) | ||
return nil | ||
} |
Oops, something went wrong.