diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 69802a48a7..e98b9049b5 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -38,7 +38,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/node" - "gopkg.in/urfave/cli.v1" + cli "gopkg.in/urfave/cli.v1" ) const ( @@ -52,6 +52,8 @@ var ( app = utils.NewApp(gitCommit, "the go-ethereum command line interface") // flags that configure the node nodeFlags = []cli.Flag{ + utils.SmartContractWhitelistAddressesFlag, //timo whitelist + utils.IdentityFlag, utils.UnlockedAccountFlag, utils.PasswordFileFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 82f17e0ee8..17b5e847ba 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -26,7 +26,7 @@ import ( "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/internal/debug" - "gopkg.in/urfave/cli.v1" + cli "gopkg.in/urfave/cli.v1" ) // AppHelpTemplate is the test template for the default, global app help topic. @@ -125,6 +125,8 @@ var AppHelpFlagGroups = []flagGroup{ utils.TxPoolAccountQueueFlag, utils.TxPoolGlobalQueueFlag, utils.TxPoolLifetimeFlag, + utils.SmartContractWhitelistAddressesFlag, //timo + }, }, { @@ -132,7 +134,6 @@ var AppHelpFlagGroups = []flagGroup{ Flags: []cli.Flag{ utils.CacheFlag, utils.CacheDatabaseFlag, - utils.CacheTrieFlag, utils.CacheGCFlag, utils.TrieCacheGenFlag, }, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index d0597c2f18..7d27cbed10 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -57,7 +57,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/netutil" "github.com/ethereum/go-ethereum/params" whisper "github.com/ethereum/go-ethereum/whisper/whisperv6" - "gopkg.in/urfave/cli.v1" + cli "gopkg.in/urfave/cli.v1" ) var ( @@ -626,6 +626,13 @@ var ( Usage: "External EVM configuration (default = built-in interpreter)", Value: "", } + + //timo whitelist + //white list for smart contract deployment + SmartContractWhitelistAddressesFlag = cli.StringFlag{ + Name: "txpool.scwhite", + Usage: "Comma separated accounts to white list for smart contract deploying.", + } ) // MakeDataDir retrieves the currently requested data directory, terminating @@ -1024,6 +1031,17 @@ func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) { } } } + //timo whitelist + if ctx.GlobalIsSet(SmartContractWhitelistAddressesFlag.Name) { + scwhitelist := strings.Split(ctx.GlobalString(SmartContractWhitelistAddressesFlag.Name), ",") + for _, account := range scwhitelist { + if trimmed := strings.TrimSpace(account); !common.IsHexAddress(trimmed) { + Fatalf("Invalid account in --txpool.scwhite: %s", trimmed) + } else { + cfg.SCWhitelist = append(cfg.SCWhitelist, common.HexToAddress(account)) + } + } + } if ctx.GlobalIsSet(TxPoolNoLocalsFlag.Name) { cfg.NoLocals = ctx.GlobalBool(TxPoolNoLocalsFlag.Name) } diff --git a/core/tx_pool.go b/core/tx_pool.go index c1fbf252a7..ba5b403c12 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -137,6 +137,9 @@ type TxPoolConfig struct { GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts Lifetime time.Duration // Maximum amount of time non-executable transaction are queued + //timo whitelist + SCWhitelist []common.Address // Addresses that should be treated by default as local + } // DefaultTxPoolConfig contains the default configurations for the transaction @@ -209,7 +212,9 @@ type TxPool struct { wg sync.WaitGroup // for shutdown sync - homestead bool + homestead bool + scwhitelist *accountSet //timo whitelist + } // NewTxPool creates a new transaction pool to gather, sort and filter inbound @@ -236,6 +241,13 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block log.Info("Setting new local account", "address", addr) pool.locals.add(addr) } + //timo whitelist + pool.scwhitelist = newAccountSet(pool.signer) + for _, addr := range config.SCWhitelist { + log.Info("Setting new whitelist account", "address", addr) + pool.scwhitelist.add(addr) + } + pool.priced = newTxPricedList(pool.all) pool.reset(nil, chain.CurrentBlock().Header()) @@ -586,12 +598,12 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { } //timo Discart contract create for non whitelisted address if to := tx.To(); to == nil { - whiteList := map[common.Address]bool{common.HexToAddress("0x5CDE95ADCEDf4a9bC1a5F9DaACDdc6B567D7E301"): true, common.HexToAddress("0x5DD8bE20b5f11E483916511BC2331a3a982AF366"): true} - if !whiteList[from] { - log.Info("################# IS NOT WHITELISTEDTHED FOR DEPLOYING SMART CONTRACTS", "address", from) + if !pool.scwhitelist.contains(from) { + log.Info("Account is NOT whitelisted for smart contract deployment", "address", from) + return ErrInvalidSender } - log.Info("################# IS WHITELISTEDTHED FOR DEPLOYING SMART CONTRACTS", "address", from) + log.Info("Account is whitelisted for smart contract deployment", "address", from) } // Drop non-local transactions under our own minimal accepted gas price