added support for whitelisting contracts for sc deployment

This commit is contained in:
Timo Hedke 2018-12-28 11:19:23 -03:00
parent f498b3c987
commit ba8a5badef
4 changed files with 42 additions and 9 deletions

View file

@ -38,7 +38,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"gopkg.in/urfave/cli.v1" cli "gopkg.in/urfave/cli.v1"
) )
const ( const (
@ -52,6 +52,8 @@ var (
app = utils.NewApp(gitCommit, "the go-ethereum command line interface") app = utils.NewApp(gitCommit, "the go-ethereum command line interface")
// flags that configure the node // flags that configure the node
nodeFlags = []cli.Flag{ nodeFlags = []cli.Flag{
utils.SmartContractWhitelistAddressesFlag, //timo whitelist
utils.IdentityFlag, utils.IdentityFlag,
utils.UnlockedAccountFlag, utils.UnlockedAccountFlag,
utils.PasswordFileFlag, utils.PasswordFileFlag,

View file

@ -26,7 +26,7 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/internal/debug" "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. // AppHelpTemplate is the test template for the default, global app help topic.
@ -125,6 +125,8 @@ var AppHelpFlagGroups = []flagGroup{
utils.TxPoolAccountQueueFlag, utils.TxPoolAccountQueueFlag,
utils.TxPoolGlobalQueueFlag, utils.TxPoolGlobalQueueFlag,
utils.TxPoolLifetimeFlag, utils.TxPoolLifetimeFlag,
utils.SmartContractWhitelistAddressesFlag, //timo
}, },
}, },
{ {
@ -132,7 +134,6 @@ var AppHelpFlagGroups = []flagGroup{
Flags: []cli.Flag{ Flags: []cli.Flag{
utils.CacheFlag, utils.CacheFlag,
utils.CacheDatabaseFlag, utils.CacheDatabaseFlag,
utils.CacheTrieFlag,
utils.CacheGCFlag, utils.CacheGCFlag,
utils.TrieCacheGenFlag, utils.TrieCacheGenFlag,
}, },

View file

@ -57,7 +57,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/netutil" "github.com/ethereum/go-ethereum/p2p/netutil"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6" whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
"gopkg.in/urfave/cli.v1" cli "gopkg.in/urfave/cli.v1"
) )
var ( var (
@ -626,6 +626,13 @@ var (
Usage: "External EVM configuration (default = built-in interpreter)", Usage: "External EVM configuration (default = built-in interpreter)",
Value: "", 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 // 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) { if ctx.GlobalIsSet(TxPoolNoLocalsFlag.Name) {
cfg.NoLocals = ctx.GlobalBool(TxPoolNoLocalsFlag.Name) cfg.NoLocals = ctx.GlobalBool(TxPoolNoLocalsFlag.Name)
} }

View file

@ -137,6 +137,9 @@ type TxPoolConfig struct {
GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts
Lifetime time.Duration // Maximum amount of time non-executable transaction are queued 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 // DefaultTxPoolConfig contains the default configurations for the transaction
@ -210,6 +213,8 @@ type TxPool struct {
wg sync.WaitGroup // for shutdown sync 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 // 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) log.Info("Setting new local account", "address", addr)
pool.locals.add(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.priced = newTxPricedList(pool.all)
pool.reset(nil, chain.CurrentBlock().Header()) 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 //timo Discart contract create for non whitelisted address
if to := tx.To(); to == nil { if to := tx.To(); to == nil {
whiteList := map[common.Address]bool{common.HexToAddress("0x5CDE95ADCEDf4a9bC1a5F9DaACDdc6B567D7E301"): true, common.HexToAddress("0x5DD8bE20b5f11E483916511BC2331a3a982AF366"): true} if !pool.scwhitelist.contains(from) {
if !whiteList[from] { log.Info("Account is NOT whitelisted for smart contract deployment", "address", from)
log.Info("################# IS NOT WHITELISTEDTHED FOR DEPLOYING SMART CONTRACTS", "address", from)
return ErrInvalidSender 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 // Drop non-local transactions under our own minimal accepted gas price