Revert "core: update DAO soft-fork number, clean up the code"

This reverts commit ba784bdf36.
This commit is contained in:
Péter Szilágyi 2016-06-29 11:44:29 +03:00
parent 219859f8bb
commit 67e9d33486
10 changed files with 67 additions and 49 deletions

View File

@ -169,7 +169,6 @@ participating.
utils.MiningGPUFlag, utils.MiningGPUFlag,
utils.AutoDAGFlag, utils.AutoDAGFlag,
utils.TargetGasLimitFlag, utils.TargetGasLimitFlag,
utils.DAOSoftForkFlag,
utils.NATFlag, utils.NATFlag,
utils.NatspecEnabledFlag, utils.NatspecEnabledFlag,
utils.NoDiscoverFlag, utils.NoDiscoverFlag,

View File

@ -128,7 +128,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.TargetGasLimitFlag, utils.TargetGasLimitFlag,
utils.GasPriceFlag, utils.GasPriceFlag,
utils.ExtraDataFlag, utils.ExtraDataFlag,
utils.DAOSoftForkFlag,
}, },
}, },
{ {

View File

@ -163,6 +163,10 @@ var (
} }
// Miner settings // Miner settings
// TODO: refactor CPU vs GPU mining flags // TODO: refactor CPU vs GPU mining flags
BlockedCodeHashesFlag = cli.StringFlag{
Name: "blocked-code-hashes",
Usage: "Comma separated list of code-hashes to ignore any interaction from",
}
MiningEnabledFlag = cli.BoolFlag{ MiningEnabledFlag = cli.BoolFlag{
Name: "mine", Name: "mine",
Usage: "Enable mining", Usage: "Enable mining",
@ -181,10 +185,6 @@ var (
Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine", Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine",
Value: params.GenesisGasLimit.String(), Value: params.GenesisGasLimit.String(),
} }
DAOSoftForkFlag = cli.BoolFlag{
Name: "dao-soft-fork",
Usage: "Vote for the DAO soft-fork, temporarilly decreasing the gas limits",
}
AutoDAGFlag = cli.BoolFlag{ AutoDAGFlag = cli.BoolFlag{
Name: "autodag", Name: "autodag",
Usage: "Enable automatic DAG pregeneration", Usage: "Enable automatic DAG pregeneration",
@ -644,6 +644,16 @@ func MakePasswordList(ctx *cli.Context) []string {
return lines return lines
} }
// MakeBlockedCodeHashes parses a comma separated list of hashes.
func MakeBlockedCodeHashes(ctx *cli.Context) map[common.Hash]struct{} {
splittedHexHashes := strings.Split(ctx.GlobalString(BlockedCodeHashesFlag.Name), ",")
illegalCodeHashes := make(map[common.Hash]struct{})
for _, hexHash := range splittedHexHashes {
illegalCodeHashes[common.HexToHash(strings.TrimSpace(hexHash))] = struct{}{}
}
return illegalCodeHashes
}
// MakeSystemNode sets up a local node, configures the services to launch and // MakeSystemNode sets up a local node, configures the services to launch and
// assembles the P2P protocol stack. // assembles the P2P protocol stack.
func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node { func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node {
@ -680,9 +690,8 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
} }
// Configure the Ethereum service // Configure the Ethereum service
accman := MakeAccountManager(ctx) accman := MakeAccountManager(ctx)
// parse the blocked code hashes and set them to the core package.
// Handle some miner strategies arrising from the DAO fiasco core.BlockedCodeHashes = MakeBlockedCodeHashes(ctx)
core.DAOSoftFork = ctx.GlobalBool(DAOSoftForkFlag.Name)
// initialise new random number generator // initialise new random number generator
rand := rand.New(rand.NewSource(time.Now().UnixNano())) rand := rand.New(rand.NewSource(time.Now().UnixNano()))

View File

@ -371,10 +371,5 @@ func CalcGasLimit(parent *types.Block) *big.Int {
gl.Add(parent.GasLimit(), decay) gl.Add(parent.GasLimit(), decay)
gl.Set(common.BigMin(gl, params.TargetGasLimit)) gl.Set(common.BigMin(gl, params.TargetGasLimit))
} }
// Temporary special case: if DAO rupture is requested, cap the gas limit
if DAOSoftFork && parent.NumberU64() <= ruptureBlock && gl.Cmp(ruptureTarget) > 0 {
gl.Sub(parent.GasLimit(), decay)
gl.Set(common.BigMax(gl, ruptureTarget))
}
return gl return gl
} }

View File

@ -84,10 +84,12 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A
address = &addr address = &addr
createAccount = true createAccount = true
} }
// Mark all contracts doing outbound value transfers to allow DAO filtering.
// mark the code hash if the execution is a call, callcode or delegate.
if value.Cmp(common.Big0) > 0 { if value.Cmp(common.Big0) > 0 {
env.MarkCodeHash(env.Db().GetCodeHash(caller.Address())) env.MarkCodeHash(env.Db().GetCodeHash(caller.Address()))
} }
snapshotPreTransfer := env.MakeSnapshot() snapshotPreTransfer := env.MakeSnapshot()
var ( var (
from = env.Db().GetAccount(caller.Address()) from = env.Db().GetAccount(caller.Address())
@ -146,7 +148,7 @@ func execDelegateCall(env vm.Environment, caller vm.ContractRef, originAddr, toA
caller.ReturnGas(gas, gasPrice) caller.ReturnGas(gas, gasPrice)
return nil, common.Address{}, vm.DepthError return nil, common.Address{}, vm.DepthError
} }
// Mark all contracts doing outbound value transfers to allow DAO filtering.
if value.Cmp(common.Big0) > 0 { if value.Cmp(common.Big0) > 0 {
env.MarkCodeHash(env.Db().GetCodeHash(caller.Address())) env.MarkCodeHash(env.Db().GetCodeHash(caller.Address()))
} }

View File

@ -51,6 +51,8 @@ type StateDB struct {
txIndex int txIndex int
logs map[common.Hash]vm.Logs logs map[common.Hash]vm.Logs
logSize uint logSize uint
reducedDao bool
} }
// Create a new state from a given trie // Create a new state from a given trie

View File

@ -35,10 +35,7 @@ var (
blockedCodeHashErr = errors.New("core: blocked code-hash found during execution") blockedCodeHashErr = errors.New("core: blocked code-hash found during execution")
// DAO attack chain rupture mechanism // DAO attack chain rupture mechanism
DAOSoftFork bool // Flag whether to vote for DAO rupture ruptureBlock = uint64(1760000) // Block number of the voted soft fork
ruptureBlock = uint64(1775000) // Block number of the voted soft fork
ruptureTarget = big.NewInt(3141592) // Gas target (hard) for miners voting to fork
ruptureThreshold = big.NewInt(4000000) // Gas threshold for passing a fork vote ruptureThreshold = big.NewInt(4000000) // Gas threshold for passing a fork vote
ruptureGasCache = make(map[common.Hash]*big.Int) // Amount of gas in the point of rupture ruptureGasCache = make(map[common.Hash]*big.Int) // Amount of gas in the point of rupture
ruptureCodeHashes = map[common.Hash]struct{}{ ruptureCodeHashes = map[common.Hash]struct{}{
@ -144,13 +141,21 @@ func ApplyTransaction(config *ChainConfig, bc *BlockChain, gp *GasPool, statedb
} }
} }
} }
// Verify if the DAO soft fork kicks in // Iterate over the bullshit blacklist to keep waste some time while keeping random Joe's happy
if blockRuptureCodes { if len(BlockedCodeHashes) > 0 {
if recipient := tx.To(); recipient == nil || !ruptureWhitelist[*recipient] { for hash, _ := range env.GetMarkedCodeHashes() {
for hash, _ := range env.GetMarkedCodeHashes() { // Figure out whether this contract should in general be blocked
if _, blocked := ruptureCodeHashes[hash]; blocked { if _, blocked := BlockedCodeHashes[hash]; blocked {
return nil, nil, nil, blockedCodeHashErr return nil, nil, nil, blockedCodeHashErr
} }
}
}
// Actually verify the DAO soft fork
recipient := tx.To()
if blockRuptureCodes && (recipient == nil || !ruptureWhitelist[*recipient]) {
for hash, _ := range env.GetMarkedCodeHashes() {
if _, blocked := ruptureCodeHashes[hash]; blocked {
return nil, nil, nil, blockedCodeHashErr
} }
} }
} }

View File

@ -27,9 +27,10 @@ import (
// Env is a basic runtime environment required for running the EVM. // Env is a basic runtime environment required for running the EVM.
type Env struct { type Env struct {
ruleSet vm.RuleSet ruleSet vm.RuleSet
depth int depth int
state *state.StateDB state *state.StateDB
illegalHashes []common.Hash
origin common.Address origin common.Address
coinbase common.Address coinbase common.Address
@ -49,14 +50,15 @@ type Env struct {
// NewEnv returns a new vm.Environment // NewEnv returns a new vm.Environment
func NewEnv(cfg *Config, state *state.StateDB) vm.Environment { func NewEnv(cfg *Config, state *state.StateDB) vm.Environment {
env := &Env{ env := &Env{
ruleSet: cfg.RuleSet, ruleSet: cfg.RuleSet,
state: state, illegalHashes: cfg.illegalHashes,
origin: cfg.Origin, state: state,
coinbase: cfg.Coinbase, origin: cfg.Origin,
number: cfg.BlockNumber, coinbase: cfg.Coinbase,
time: cfg.Time, number: cfg.BlockNumber,
difficulty: cfg.Difficulty, time: cfg.Time,
gasLimit: cfg.GasLimit, difficulty: cfg.Difficulty,
gasLimit: cfg.GasLimit,
} }
env.evm = vm.New(env, vm.Config{ env.evm = vm.New(env, vm.Config{
Debug: cfg.Debug, Debug: cfg.Debug,

View File

@ -35,17 +35,18 @@ func (ruleSet) IsHomestead(*big.Int) bool { return true }
// Config is a basic type specifying certain configuration flags for running // Config is a basic type specifying certain configuration flags for running
// the EVM. // the EVM.
type Config struct { type Config struct {
RuleSet vm.RuleSet RuleSet vm.RuleSet
Difficulty *big.Int Difficulty *big.Int
Origin common.Address Origin common.Address
Coinbase common.Address Coinbase common.Address
BlockNumber *big.Int BlockNumber *big.Int
Time *big.Int Time *big.Int
GasLimit *big.Int GasLimit *big.Int
GasPrice *big.Int GasPrice *big.Int
Value *big.Int Value *big.Int
DisableJit bool // "disable" so it's enabled by default DisableJit bool // "disable" so it's enabled by default
Debug bool Debug bool
illegalHashes []common.Hash
State *state.StateDB State *state.StateDB
GetHashFn func(n uint64) common.Hash GetHashFn func(n uint64) common.Hash

View File

@ -25,6 +25,10 @@ import (
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
) )
// BlockedCodeHashes is a set of EVM code hashes that this node should block
// sending funds from.
var BlockedCodeHashes map[common.Hash]struct{}
// GetHashFn returns a function for which the VM env can query block hashes through // GetHashFn returns a function for which the VM env can query block hashes through
// up to the limit defined by the Yellow Paper and uses the given block chain // up to the limit defined by the Yellow Paper and uses the given block chain
// to query for information. // to query for information.