Skip to content

Commit aefffc9

Browse files
committed
[release/1.4.8] core: update DAO soft-fork number, clean up the code
(cherry picked from commit ba784bd)
1 parent f31a3a2 commit aefffc9

File tree

10 files changed

+49
-67
lines changed

10 files changed

+49
-67
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ participating.
169169
utils.MiningGPUFlag,
170170
utils.AutoDAGFlag,
171171
utils.TargetGasLimitFlag,
172+
utils.DAOSoftForkFlag,
172173
utils.NATFlag,
173174
utils.NatspecEnabledFlag,
174175
utils.NoDiscoverFlag,

cmd/geth/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ var AppHelpFlagGroups = []flagGroup{
128128
utils.TargetGasLimitFlag,
129129
utils.GasPriceFlag,
130130
utils.ExtraDataFlag,
131+
utils.DAOSoftForkFlag,
131132
},
132133
},
133134
{

cmd/utils/flags.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ var (
163163
}
164164
// Miner settings
165165
// TODO: refactor CPU vs GPU mining flags
166-
BlockedCodeHashesFlag = cli.StringFlag{
167-
Name: "blocked-code-hashes",
168-
Usage: "Comma separated list of code-hashes to ignore any interaction from",
169-
}
170166
MiningEnabledFlag = cli.BoolFlag{
171167
Name: "mine",
172168
Usage: "Enable mining",
@@ -185,6 +181,10 @@ var (
185181
Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine",
186182
Value: params.GenesisGasLimit.String(),
187183
}
184+
DAOSoftForkFlag = cli.BoolFlag{
185+
Name: "dao-soft-fork",
186+
Usage: "Vote for the DAO soft-fork, temporarilly decreasing the gas limits",
187+
}
188188
AutoDAGFlag = cli.BoolFlag{
189189
Name: "autodag",
190190
Usage: "Enable automatic DAG pregeneration",
@@ -644,16 +644,6 @@ func MakePasswordList(ctx *cli.Context) []string {
644644
return lines
645645
}
646646

647-
// MakeBlockedCodeHashes parses a comma separated list of hashes.
648-
func MakeBlockedCodeHashes(ctx *cli.Context) map[common.Hash]struct{} {
649-
splittedHexHashes := strings.Split(ctx.GlobalString(BlockedCodeHashesFlag.Name), ",")
650-
illegalCodeHashes := make(map[common.Hash]struct{})
651-
for _, hexHash := range splittedHexHashes {
652-
illegalCodeHashes[common.HexToHash(strings.TrimSpace(hexHash))] = struct{}{}
653-
}
654-
return illegalCodeHashes
655-
}
656-
657647
// MakeSystemNode sets up a local node, configures the services to launch and
658648
// assembles the P2P protocol stack.
659649
func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node {
@@ -690,8 +680,9 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
690680
}
691681
// Configure the Ethereum service
692682
accman := MakeAccountManager(ctx)
693-
// parse the blocked code hashes and set them to the core package.
694-
core.BlockedCodeHashes = MakeBlockedCodeHashes(ctx)
683+
684+
// Handle some miner strategies arrising from the DAO fiasco
685+
core.DAOSoftFork = ctx.GlobalBool(DAOSoftForkFlag.Name)
695686

696687
// initialise new random number generator
697688
rand := rand.New(rand.NewSource(time.Now().UnixNano()))

core/block_validator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,5 +371,10 @@ func CalcGasLimit(parent *types.Block) *big.Int {
371371
gl.Add(parent.GasLimit(), decay)
372372
gl.Set(common.BigMin(gl, params.TargetGasLimit))
373373
}
374+
// Temporary special case: if DAO rupture is requested, cap the gas limit
375+
if DAOSoftFork && parent.NumberU64() <= ruptureBlock && gl.Cmp(ruptureTarget) > 0 {
376+
gl.Sub(parent.GasLimit(), decay)
377+
gl.Set(common.BigMax(gl, ruptureTarget))
378+
}
374379
return gl
375380
}

core/execution.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A
8484
address = &addr
8585
createAccount = true
8686
}
87-
88-
// mark the code hash if the execution is a call, callcode or delegate.
87+
// Mark all contracts doing outbound value transfers to allow DAO filtering.
8988
if value.Cmp(common.Big0) > 0 {
9089
env.MarkCodeHash(env.Db().GetCodeHash(caller.Address()))
9190
}
92-
9391
snapshotPreTransfer := env.MakeSnapshot()
9492
var (
9593
from = env.Db().GetAccount(caller.Address())
@@ -148,7 +146,7 @@ func execDelegateCall(env vm.Environment, caller vm.ContractRef, originAddr, toA
148146
caller.ReturnGas(gas, gasPrice)
149147
return nil, common.Address{}, vm.DepthError
150148
}
151-
149+
// Mark all contracts doing outbound value transfers to allow DAO filtering.
152150
if value.Cmp(common.Big0) > 0 {
153151
env.MarkCodeHash(env.Db().GetCodeHash(caller.Address()))
154152
}

core/state/statedb.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ type StateDB struct {
5151
txIndex int
5252
logs map[common.Hash]vm.Logs
5353
logSize uint
54-
55-
reducedDao bool
5654
}
5755

5856
// Create a new state from a given trie

core/state_processor.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ var (
3535
blockedCodeHashErr = errors.New("core: blocked code-hash found during execution")
3636

3737
// DAO attack chain rupture mechanism
38-
ruptureBlock = uint64(1760000) // Block number of the voted soft fork
38+
DAOSoftFork bool // Flag whether to vote for DAO rupture
39+
40+
ruptureBlock = uint64(1775000) // Block number of the voted soft fork
41+
ruptureTarget = big.NewInt(3141592) // Gas target (hard) for miners voting to fork
3942
ruptureThreshold = big.NewInt(4000000) // Gas threshold for passing a fork vote
4043
ruptureGasCache = make(map[common.Hash]*big.Int) // Amount of gas in the point of rupture
4144
ruptureCodeHashes = map[common.Hash]struct{}{
@@ -141,21 +144,13 @@ func ApplyTransaction(config *ChainConfig, bc *BlockChain, gp *GasPool, statedb
141144
}
142145
}
143146
}
144-
// Iterate over the bullshit blacklist to keep waste some time while keeping random Joe's happy
145-
if len(BlockedCodeHashes) > 0 {
146-
for hash, _ := range env.GetMarkedCodeHashes() {
147-
// Figure out whether this contract should in general be blocked
148-
if _, blocked := BlockedCodeHashes[hash]; blocked {
149-
return nil, nil, nil, blockedCodeHashErr
150-
}
151-
}
152-
}
153-
// Actually verify the DAO soft fork
154-
recipient := tx.To()
155-
if blockRuptureCodes && (recipient == nil || !ruptureWhitelist[*recipient]) {
156-
for hash, _ := range env.GetMarkedCodeHashes() {
157-
if _, blocked := ruptureCodeHashes[hash]; blocked {
158-
return nil, nil, nil, blockedCodeHashErr
147+
// Verify if the DAO soft fork kicks in
148+
if blockRuptureCodes {
149+
if recipient := tx.To(); recipient == nil || !ruptureWhitelist[*recipient] {
150+
for hash, _ := range env.GetMarkedCodeHashes() {
151+
if _, blocked := ruptureCodeHashes[hash]; blocked {
152+
return nil, nil, nil, blockedCodeHashErr
153+
}
159154
}
160155
}
161156
}

core/vm/runtime/env.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ import (
2727

2828
// Env is a basic runtime environment required for running the EVM.
2929
type Env struct {
30-
ruleSet vm.RuleSet
31-
depth int
32-
state *state.StateDB
33-
illegalHashes []common.Hash
30+
ruleSet vm.RuleSet
31+
depth int
32+
state *state.StateDB
3433

3534
origin common.Address
3635
coinbase common.Address
@@ -50,15 +49,14 @@ type Env struct {
5049
// NewEnv returns a new vm.Environment
5150
func NewEnv(cfg *Config, state *state.StateDB) vm.Environment {
5251
env := &Env{
53-
ruleSet: cfg.RuleSet,
54-
illegalHashes: cfg.illegalHashes,
55-
state: state,
56-
origin: cfg.Origin,
57-
coinbase: cfg.Coinbase,
58-
number: cfg.BlockNumber,
59-
time: cfg.Time,
60-
difficulty: cfg.Difficulty,
61-
gasLimit: cfg.GasLimit,
52+
ruleSet: cfg.RuleSet,
53+
state: state,
54+
origin: cfg.Origin,
55+
coinbase: cfg.Coinbase,
56+
number: cfg.BlockNumber,
57+
time: cfg.Time,
58+
difficulty: cfg.Difficulty,
59+
gasLimit: cfg.GasLimit,
6260
}
6361
env.evm = vm.New(env, vm.Config{
6462
Debug: cfg.Debug,

core/vm/runtime/runtime.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,17 @@ func (ruleSet) IsHomestead(*big.Int) bool { return true }
3535
// Config is a basic type specifying certain configuration flags for running
3636
// the EVM.
3737
type Config struct {
38-
RuleSet vm.RuleSet
39-
Difficulty *big.Int
40-
Origin common.Address
41-
Coinbase common.Address
42-
BlockNumber *big.Int
43-
Time *big.Int
44-
GasLimit *big.Int
45-
GasPrice *big.Int
46-
Value *big.Int
47-
DisableJit bool // "disable" so it's enabled by default
48-
Debug bool
49-
illegalHashes []common.Hash
38+
RuleSet vm.RuleSet
39+
Difficulty *big.Int
40+
Origin common.Address
41+
Coinbase common.Address
42+
BlockNumber *big.Int
43+
Time *big.Int
44+
GasLimit *big.Int
45+
GasPrice *big.Int
46+
Value *big.Int
47+
DisableJit bool // "disable" so it's enabled by default
48+
Debug bool
5049

5150
State *state.StateDB
5251
GetHashFn func(n uint64) common.Hash

core/vm_env.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import (
2525
"github.com/ethereum/go-ethereum/core/vm"
2626
)
2727

28-
// BlockedCodeHashes is a set of EVM code hashes that this node should block
29-
// sending funds from.
30-
var BlockedCodeHashes map[common.Hash]struct{}
31-
3228
// GetHashFn returns a function for which the VM env can query block hashes through
3329
// up to the limit defined by the Yellow Paper and uses the given block chain
3430
// to query for information.

0 commit comments

Comments
 (0)