mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
added support for whitelisting contracts for sc deployment
This commit is contained in:
parent
f498b3c987
commit
ba8a5badef
4 changed files with 42 additions and 9 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -210,6 +213,8 @@ type TxPool struct {
|
|||
wg sync.WaitGroup // for shutdown sync
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue