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 ( ...@@ -10,6 +10,16 @@ import (
"sync" "sync"
"time" "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" altda "github.com/ethereum-optimism/optimism/op-alt-da"
"github.com/ethereum-optimism/optimism/op-batcher/metrics" "github.com/ethereum-optimism/optimism/op-batcher/metrics"
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
...@@ -17,13 +27,6 @@ import ( ...@@ -17,13 +27,6 @@ import (
"github.com/ethereum-optimism/optimism/op-service/dial" "github.com/ethereum-optimism/optimism/op-service/dial"
"github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "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 ( var (
...@@ -543,14 +546,26 @@ func (l *BatchSubmitter) throttlingLoop(throttlingLoopDone chan struct{}) { ...@@ -543,14 +546,26 @@ func (l *BatchSubmitter) throttlingLoop(throttlingLoopDone chan struct{}) {
maxBlockSize = l.Config.ThrottleBlockSize maxBlockSize = l.Config.ThrottleBlockSize
} }
} }
var success bool var (
success bool
rpcErr rpc.Error
)
if err := cl.Client().CallContext( if err := cl.Client().CallContext(
ctx, &success, SetMaxDASizeMethod, hexutil.Uint64(maxTxSize), hexutil.Uint64(maxBlockSize)); err != nil { ctx, &success, SetMaxDASizeMethod, hexutil.Uint64(maxTxSize), hexutil.Uint64(maxBlockSize),
l.Log.Error("SetMaxDASize rpc failed", "err", err) ); 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 return
} }
if !success { 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) { ...@@ -86,7 +86,6 @@ func TestBatchSubmitter_SafeL1Origin(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if tt.failsToFetchSyncStatus { if tt.failsToFetchSyncStatus {
ep.rollupClient.ExpectSyncStatus(&eth.SyncStatus{}, errors.New("failed to fetch sync status")) ep.rollupClient.ExpectSyncStatus(&eth.SyncStatus{}, errors.New("failed to fetch sync status"))
} else { } else {
ep.rollupClient.ExpectSyncStatus(&eth.SyncStatus{ ep.rollupClient.ExpectSyncStatus(&eth.SyncStatus{
SafeL2: eth.L2BlockRef{ SafeL2: eth.L2BlockRef{
...@@ -107,7 +106,6 @@ func TestBatchSubmitter_SafeL1Origin(t *testing.T) { ...@@ -107,7 +106,6 @@ func TestBatchSubmitter_SafeL1Origin(t *testing.T) {
} }
}) })
} }
} }
func TestBatchSubmitter_SafeL1Origin_FailsToResolveRollupClient(t *testing.T) { func TestBatchSubmitter_SafeL1Origin_FailsToResolveRollupClient(t *testing.T) {
......
...@@ -157,9 +157,9 @@ var ( ...@@ -157,9 +157,9 @@ var (
EnvVars: prefixEnvVars("WAIT_NODE_SYNC"), EnvVars: prefixEnvVars("WAIT_NODE_SYNC"),
} }
ThrottleIntervalFlag = &cli.DurationFlag{ ThrottleIntervalFlag = &cli.DurationFlag{
Name: "throttle-interval", Name: "throttle-interval",
Usage: "Interval between potential DA throttling actions. Zero (default) disables throttling. " + Usage: "Interval between potential DA throttling actions. Zero disables throttling.",
"Recommended to be set to L2 block time if enabling.", Value: 2 * time.Second,
EnvVars: prefixEnvVars("THROTTLE_INTERVAL"), EnvVars: prefixEnvVars("THROTTLE_INTERVAL"),
} }
ThrottleThresholdFlag = &cli.IntFlag{ ThrottleThresholdFlag = &cli.IntFlag{
......
...@@ -25,9 +25,14 @@ func (c ErrorCode) IsEngineError() bool { ...@@ -25,9 +25,14 @@ func (c ErrorCode) IsEngineError() bool {
return -38100 < c && c <= -38000 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: // Engine error codes used to be -3200x, but were rebased to -3800x:
// https://github.com/ethereum/execution-apis/pull/214 // https://github.com/ethereum/execution-apis/pull/214
const ( const (
MethodNotFound ErrorCode = -32601 // RPC method not found or not available.
InvalidParams ErrorCode = -32602 InvalidParams ErrorCode = -32602
UnknownPayload ErrorCode = -38001 // Payload does not exist / is not available. UnknownPayload ErrorCode = -38001 // Payload does not exist / is not available.
InvalidForkchoiceState ErrorCode = -38002 // Forkchoice state is invalid / inconsistent. 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