Skip to content

Commit

Permalink
feat: remove disable transfers (ethereum#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
tynes authored Mar 9, 2021
1 parent 9683d3f commit 50aa6fe
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 53 deletions.
1 change: 0 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ var (
utils.RollupPollIntervalFlag,
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
utils.RollupDisableTransfersFlag,
utils.RollupMaxCalldataSizeFlag,
}

Expand Down
1 change: 0 additions & 1 deletion cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.RollupPollIntervalFlag,
utils.RollupStateDumpPathFlag,
utils.RollupDiffDbFlag,
utils.RollupDisableTransfersFlag,
utils.RollupMaxCalldataSizeFlag,
},
},
Expand Down
8 changes: 0 additions & 8 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,11 +873,6 @@ var (
Value: eth.DefaultConfig.DiffDbCache,
EnvVar: "ROLLUP_DIFFDB_CACHE",
}
RollupDisableTransfersFlag = cli.BoolFlag{
Name: "rollup.disabletransfers",
Usage: "Disable Transfers",
EnvVar: "ROLLUP_DISABLE_TRANSFERS",
}
RollupMaxCalldataSizeFlag = cli.IntFlag{
Name: "rollup.maxcalldatasize",
Usage: "Maximum allowed calldata size for Queue Origin Sequencer Txs",
Expand Down Expand Up @@ -1145,9 +1140,6 @@ func setRollup(ctx *cli.Context, cfg *rollup.Config) {
} else {
cfg.StateDumpPath = eth.DefaultConfig.Rollup.StateDumpPath
}
if ctx.GlobalIsSet(RollupDisableTransfersFlag.Name) {
cfg.DisableTransfers = true
}
if ctx.GlobalIsSet(RollupMaxCalldataSizeFlag.Name) {
cfg.MaxCallDataSize = ctx.GlobalInt(RollupMaxCalldataSizeFlag.Name)
}
Expand Down
44 changes: 15 additions & 29 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package eth

import (
"bytes"
"context"
"errors"
"fmt"
Expand All @@ -44,14 +43,13 @@ import (

// EthAPIBackend implements ethapi.Backend for full nodes
type EthAPIBackend struct {
extRPCEnabled bool
eth *Ethereum
gpo *gasprice.Oracle
verifier bool
DisableTransfers bool
gasLimit uint64
UsingOVM bool
MaxCallDataSize int
extRPCEnabled bool
eth *Ethereum
gpo *gasprice.Oracle
verifier bool
gasLimit uint64
UsingOVM bool
MaxCallDataSize int
}

func (b *EthAPIBackend) IsVerifier() bool {
Expand Down Expand Up @@ -300,30 +298,18 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
if *to == (common.Address{}) {
return errors.New("Cannot send transaction to zero address")
}

// Prevent transactions from being submitted if the gas limit too high
if signedTx.Gas() >= b.gasLimit {
return fmt.Errorf("Transaction gasLimit (%d) is greater than max gasLimit (%d)", signedTx.Gas(), b.gasLimit)
}

if b.DisableTransfers {
data := signedTx.Data()
if len(data) >= 4 {
selector := data[:4]
// Initially prevent transfers
// `transfer(address,uint256)`
if bytes.Equal(selector, []byte{0xa9, 0x05, 0x9c, 0xbb}) {
return errors.New("transfer(address,uint256) is disabled for now")
}
// `transferFrom(address,address,uint256)`
if bytes.Equal(selector, []byte{0x23, 0xb8, 0x72, 0xdd}) {
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()))
}
// Prevent QueueOriginSequencer transactions that are too large to
// be included in a batch. The `MaxCallDataSize` should be set to
// the layer one consensus max transaction size in bytes minus the
// constant sized overhead of a batch. This will prevent
// a layer two transaction from not being able to be batch submitted
// to layer one.
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
13 changes: 6 additions & 7 deletions eth/api_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import (

func TestGasLimit(t *testing.T) {
backend := &EthAPIBackend{
extRPCEnabled: false,
eth: nil,
gpo: nil,
verifier: false,
DisableTransfers: false,
gasLimit: 0,
UsingOVM: true,
extRPCEnabled: false,
eth: nil,
gpo: nil,
verifier: false,
gasLimit: 0,
UsingOVM: true,
}

nonce := uint64(0)
Expand Down
7 changes: 2 additions & 5 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,8 @@ 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))

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}
log.Info("Backend Config", "max-calldata-size", config.Rollup.MaxCallDataSize, "gas-limit", config.Rollup.GasLimit, "is-verifier", config.Rollup.IsVerifier, "using-ovm", vm.UsingOVM)
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, config.Rollup.IsVerifier, config.Rollup.GasLimit, vm.UsingOVM, config.Rollup.MaxCallDataSize}
gpoParams := config.GPO
if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice
Expand Down
2 changes: 0 additions & 2 deletions rollup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ type Config struct {
CanonicalTransactionChainDeployHeight *big.Int
// Path to the state dump
StateDumpPath string
// Temporary setting to disable transfers
DisableTransfers bool
// Polling interval for rollup client
PollInterval time.Duration
// Interval for updating the timestamp
Expand Down

0 comments on commit 50aa6fe

Please sign in to comment.