Skip to content

Commit

Permalink
config: flag for max acceptable calldata size (ethereum#181)
Browse files Browse the repository at this point in the history
* config: flag for max acceptable calldata size

* logging: better logline

* api: only have max calldata size when xfers disabled
  • Loading branch information
tynes authored Jan 13, 2021
1 parent f7326de commit c01384b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
4 changes: 1 addition & 3 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ var (
}

optimismFlags = []cli.Flag{
// Flags for the SyncService
utils.TxIngestionSignerKeyHexFlag,
utils.TxIngestionSignerKeyFileFlag,
utils.Eth1SyncServiceEnable,
utils.Eth1AddressResolverAddressFlag,
utils.Eth1CanonicalTransactionChainDeployHeightFlag,
Expand All @@ -169,6 +166,7 @@ var (
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
utils.RollupDisableTransfersFlag,
utils.RollupMaxCalldataSizeFlag,
}

rpcFlags = []cli.Flag{
Expand Down
3 changes: 1 addition & 2 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ var AppHelpFlagGroups = []flagGroup{
{
Name: "OPTIMISM",
Flags: []cli.Flag{
utils.TxIngestionSignerKeyHexFlag,
utils.TxIngestionSignerKeyFileFlag,
utils.Eth1SyncServiceEnable,
utils.Eth1AddressResolverAddressFlag,
utils.Eth1CanonicalTransactionChainDeployHeightFlag,
Expand All @@ -81,6 +79,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
utils.RollupDisableTransfersFlag,
utils.RollupMaxCalldataSizeFlag,
},
},
{
Expand Down
9 changes: 9 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,12 @@ var (
Usage: "Disable Transfers",
EnvVar: "ROLLUP_DISABLE_TRANSFERS",
}
RollupMaxCalldataSizeFlag = cli.IntFlag{
Name: "rollup.maxcalldatasize",
Usage: "Maximum allowed calldata size for Queue Origin Sequencer Txs",
Value: eth.DefaultConfig.Rollup.MaxCallDataSize,
EnvVar: "ROLLUP_MAX_CALLDATA_SIZE",
}
)

// MakeDataDir retrieves the currently requested data directory, terminating
Expand Down Expand Up @@ -1171,6 +1177,9 @@ func setRollup(ctx *cli.Context, cfg *rollup.Config) {
if ctx.GlobalIsSet(RollupDisableTransfersFlag.Name) {
cfg.DisableTransfers = true
}
if ctx.GlobalIsSet(RollupMaxCalldataSizeFlag.Name) {
cfg.MaxCallDataSize = ctx.GlobalInt(RollupMaxCalldataSizeFlag.Name)
}
}

// setLes configures the les server and ultra light client settings from the command line flags.
Expand Down
5 changes: 5 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type EthAPIBackend struct {
DisableTransfers bool
GasLimit uint64
UsingOVM bool
MaxCallDataSize int
}

func (b *EthAPIBackend) RollupTransactionSender() *common.Address {
Expand Down Expand Up @@ -329,6 +330,10 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
return errors.New("transferFrom(address,address,uint256) is disabled for now")
}
}

if len(signedTx.Data()) > b.MaxCallDataSize {
return fmt.Errorf("Calldata cannot be larger than %d, sent %d", b.MaxCallDataSize, len(signedTx.Data()))
}
}
}
return b.eth.syncService.ApplyTransaction(signedTx)
Expand Down
6 changes: 5 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, config.Rollup.IsVerifier, config.Rollup.DisableTransfers, config.Rollup.GasLimit, vm.UsingOVM}
log.Info("Backend Config", "disable-transfers", config.Rollup.DisableTransfers, "gas-limit", config.Rollup.GasLimit, "is-verifier", config.Rollup.IsVerifier, "using-ovm", vm.UsingOVM)
if config.Rollup.DisableTransfers {
log.Info("Transaction size restrictions", "max-calldata", config.Rollup.MaxCallDataSize)
}
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, config.Rollup.IsVerifier, config.Rollup.DisableTransfers, config.Rollup.GasLimit, vm.UsingOVM, config.Rollup.MaxCallDataSize}
gpoParams := config.GPO
if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice
Expand Down
1 change: 1 addition & 0 deletions eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var DefaultConfig = Config{
Rollup: rollup.Config{
TxIngestionEnable: false,
StateDumpPath: "https://raw.githubusercontent.com/ethereum-optimism/regenesis/master/master.json",
MaxCallDataSize: 512,
},
DiffDbCache: 256,
}
Expand Down
2 changes: 2 additions & 0 deletions rollup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
type Config struct {
// TODO(mark): deprecate these config options
TxIngestionEnable bool
// Maximum calldata size for a Queue Origin Sequencer Tx
MaxCallDataSize int
// Number of confs before applying a L1 to L2 tx
Eth1ConfirmationDepth uint64
// Verifier mode
Expand Down

0 comments on commit c01384b

Please sign in to comment.