Skip to content

Commit

Permalink
Merge pull request #1990 from OffchainLabs/validate-config-params
Browse files Browse the repository at this point in the history
Validate that sequencer MaxTxDataSize and batch poster MaxSize are below sequencer inbox requirements
  • Loading branch information
ganeshvanahalli authored Dec 6, 2023
2 parents f5211ab + 467d7e0 commit d01eb16
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os/signal"
"path/filepath"
"reflect"
"regexp"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -50,6 +51,7 @@ import (
"github.com/offchainlabs/nitro/cmd/util/confighelpers"
"github.com/offchainlabs/nitro/execution/gethexec"
_ "github.com/offchainlabs/nitro/nodeInterface"
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/staker/validatorwallet"
Expand Down Expand Up @@ -488,6 +490,43 @@ func mainImpl() int {
log.Error("failed to create node", "err", err)
return 1
}

// Validate sequencer's MaxTxDataSize and batchPoster's MaxSize params.
config := liveNodeConfig.Get()
executionRevertedRegexp := regexp.MustCompile("(?i)execution reverted")
// SequencerInbox's maxDataSize is defaulted to 117964 which is 90% of Geth's 128KB tx size limit, leaving ~13KB for proving.
seqInboxMaxDataSize := 117964
if config.Node.ParentChainReader.Enable {
seqInbox, err := bridgegen.NewSequencerInbox(rollupAddrs.SequencerInbox, l1Client)
if err != nil {
log.Error("failed to create sequencer inbox for validating sequencer's MaxTxDataSize and batchposter's MaxSize", "err", err)
return 1
}
res, err := seqInbox.MaxDataSize(&bind.CallOpts{Context: ctx})
seqInboxMaxDataSize = int(res.Int64())
if err != nil && !executionRevertedRegexp.MatchString(err.Error()) {
log.Error("error fetching MaxDataSize from sequencer inbox", "err", err)
return 1
}
}
// If batchPoster is enabled, validate MaxSize to be at least 10kB below the sequencer inbox’s maxDataSize if the data availability service is not enabled.
// The 10kB gap is because its possible for the batch poster to exceed its MaxSize limit and produce batches of slightly larger size.
if config.Node.BatchPoster.Enable && !config.Node.DataAvailability.Enable {
if config.Node.BatchPoster.MaxSize > seqInboxMaxDataSize-10000 {
log.Error("batchPoster's MaxSize is too large")
return 1
}
}
// If sequencer is enabled, validate MaxTxDataSize to be at least 5kB below the batch poster's MaxSize to allow space for headers and such.
// And since batchposter's MaxSize is to be at least 10kB below the sequencer inbox’s maxDataSize, this leads to another condition of atlest 15kB below the sequencer inbox’s maxDataSize.
if config.Execution.Sequencer.Enable {
if config.Execution.Sequencer.MaxTxDataSize > config.Node.BatchPoster.MaxSize-5000 ||
config.Execution.Sequencer.MaxTxDataSize > seqInboxMaxDataSize-15000 {
log.Error("sequencer's MaxTxDataSize too large")
return 1
}
}

liveNodeConfig.SetOnReloadHook(func(oldCfg *NodeConfig, newCfg *NodeConfig) error {
if err := genericconf.InitLog(newCfg.LogType, log.Lvl(newCfg.LogLevel), &newCfg.FileLogging, pathResolver(nodeConfig.Persistent.LogDir)); err != nil {
return fmt.Errorf("failed to re-init logging: %w", err)
Expand Down

0 comments on commit d01eb16

Please sign in to comment.