Commit bc9b6cd5 authored by Sebastian Stammler's avatar Sebastian Stammler Committed by GitHub

op-batcher: Enable throttling by default, shutdown on broken RPC (#12840)

parent dd3ec4c9
......@@ -10,6 +10,16 @@ import (
"sync"
"time"
"golang.org/x/sync/errgroup"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
altda "github.com/ethereum-optimism/optimism/op-alt-da"
"github.com/ethereum-optimism/optimism/op-batcher/metrics"
"github.com/ethereum-optimism/optimism/op-node/rollup"
......@@ -17,13 +27,6 @@ import (
"github.com/ethereum-optimism/optimism/op-service/dial"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"golang.org/x/sync/errgroup"
)
var (
......@@ -543,14 +546,26 @@ func (l *BatchSubmitter) throttlingLoop(throttlingLoopDone chan struct{}) {
maxBlockSize = l.Config.ThrottleBlockSize
}
}
var success bool
var (
success bool
rpcErr rpc.Error
)
if err := cl.Client().CallContext(
ctx, &success, SetMaxDASizeMethod, hexutil.Uint64(maxTxSize), hexutil.Uint64(maxBlockSize)); err != nil {
l.Log.Error("SetMaxDASize rpc failed", "err", err)
ctx, &success, SetMaxDASizeMethod, hexutil.Uint64(maxTxSize), hexutil.Uint64(maxBlockSize),
); errors.As(err, &rpcErr) && eth.ErrorCode(rpcErr.ErrorCode()).IsGenericRPCError() {
l.Log.Error("SetMaxDASize rpc unavailable or broken, shutting down. Either enable it or disable throttling.", "err", err)
// We'd probably hit this error right after startup, so a short shutdown duration should suffice.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Always returns nil. An error is only returned to expose this function as an RPC.
_ = l.StopBatchSubmitting(ctx)
return
} else if err != nil {
l.Log.Error("SetMaxDASize rpc failed, retrying.", "err", err)
return
}
if !success {
l.Log.Error("Result of SetMaxDASize was false")
l.Log.Error("Result of SetMaxDASize was false, retrying.")
}
}
......
......@@ -86,7 +86,6 @@ func TestBatchSubmitter_SafeL1Origin(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
if tt.failsToFetchSyncStatus {
ep.rollupClient.ExpectSyncStatus(&eth.SyncStatus{}, errors.New("failed to fetch sync status"))
} else {
ep.rollupClient.ExpectSyncStatus(&eth.SyncStatus{
SafeL2: eth.L2BlockRef{
......@@ -107,7 +106,6 @@ func TestBatchSubmitter_SafeL1Origin(t *testing.T) {
}
})
}
}
func TestBatchSubmitter_SafeL1Origin_FailsToResolveRollupClient(t *testing.T) {
......
......@@ -157,9 +157,9 @@ var (
EnvVars: prefixEnvVars("WAIT_NODE_SYNC"),
}
ThrottleIntervalFlag = &cli.DurationFlag{
Name: "throttle-interval",
Usage: "Interval between potential DA throttling actions. Zero (default) disables throttling. " +
"Recommended to be set to L2 block time if enabling.",
Name: "throttle-interval",
Usage: "Interval between potential DA throttling actions. Zero disables throttling.",
Value: 2 * time.Second,
EnvVars: prefixEnvVars("THROTTLE_INTERVAL"),
}
ThrottleThresholdFlag = &cli.IntFlag{
......
......@@ -25,9 +25,14 @@ func (c ErrorCode) IsEngineError() bool {
return -38100 < c && c <= -38000
}
func (c ErrorCode) IsGenericRPCError() bool {
return -32700 < c && c <= -32600
}
// Engine error codes used to be -3200x, but were rebased to -3800x:
// https://github.com/ethereum/execution-apis/pull/214
const (
MethodNotFound ErrorCode = -32601 // RPC method not found or not available.
InvalidParams ErrorCode = -32602
UnknownPayload ErrorCode = -38001 // Payload does not exist / is not available.
InvalidForkchoiceState ErrorCode = -38002 // Forkchoice state is invalid / inconsistent.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment