Skip to content

Commit 14bad7e

Browse files
committed
[release/1.4.10] core, params, tests: add DAO hard-fork balance moves
(cherry picked from commit 461cdb5)
1 parent 8c20fe1 commit 14bad7e

File tree

10 files changed

+2011
-42
lines changed

10 files changed

+2011
-42
lines changed

cmd/ethtest/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ func runTestWithReader(test string, r io.Reader) error {
7474
var err error
7575
switch strings.ToLower(test) {
7676
case "bk", "block", "blocktest", "blockchaintest", "blocktests", "blockchaintests":
77-
err = tests.RunBlockTestWithReader(params.MainNetHomesteadBlock, r, skipTests)
77+
err = tests.RunBlockTestWithReader(params.MainNetHomesteadBlock, params.MainNetDAOForkBlock, r, skipTests)
7878
case "st", "state", "statetest", "statetests":
79-
rs := tests.RuleSet{HomesteadBlock: params.MainNetHomesteadBlock}
79+
rs := tests.RuleSet{HomesteadBlock: params.MainNetHomesteadBlock, DAOForkBlock: params.MainNetDAOForkBlock, DAOForkSupport: true}
8080
err = tests.RunStateTestWithReader(rs, r, skipTests)
8181
case "tx", "transactiontest", "transactiontests":
8282
err = tests.RunTransactionTestsWithReader(r, skipTests)

core/state_processor.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/ethereum/go-ethereum/crypto"
2626
"github.com/ethereum/go-ethereum/logger"
2727
"github.com/ethereum/go-ethereum/logger/glog"
28+
"github.com/ethereum/go-ethereum/params"
2829
)
2930

3031
var (
@@ -65,7 +66,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
6566
allLogs vm.Logs
6667
gp = new(GasPool).AddGas(block.GasLimit())
6768
)
68-
69+
// Mutate the statedb according to any hard-fork specs
70+
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
71+
ApplyDAOHardFork(statedb)
72+
}
73+
// Iterate over and process the individual transactions
6974
for i, tx := range block.Transactions() {
7075
statedb.StartRecord(tx.Hash(), block.Hash(), i)
7176
receipt, logs, _, err := ApplyTransaction(p.config, p.bc, gp, statedb, header, tx, totalUsedGas, cfg)
@@ -129,3 +134,19 @@ func AccumulateRewards(statedb *state.StateDB, header *types.Header, uncles []*t
129134
}
130135
statedb.AddBalance(header.Coinbase, reward)
131136
}
137+
138+
// ApplyDAOHardFork modifies the state database according to the DAO hard-fork
139+
// rules, transferring all balances of a set of DAO accounts to a single refund
140+
// contract.
141+
func ApplyDAOHardFork(statedb *state.StateDB) {
142+
// Retrieve the contract to refund balances into
143+
refund := statedb.GetOrNewStateObject(params.DAORefundContract)
144+
145+
// Move every DAO account and extra-balance account funds into the refund contract
146+
for _, addr := range params.DAODrainList {
147+
if account := statedb.GetStateObject(addr); account != nil {
148+
refund.AddBalance(account.Balance())
149+
account.SetBalance(new(big.Int))
150+
}
151+
}
152+
}

miner/worker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,11 @@ func (self *worker) commitNewWork() {
490490
glog.V(logger.Info).Infoln("Could not create new env for mining, retrying on next block.")
491491
return
492492
}
493+
// Create the current work task and check any fork transitions needed
493494
work := self.current
495+
if self.config.DAOForkSupport && self.config.DAOForkBlock != nil && self.config.DAOForkBlock.Cmp(header.Number) == 0 {
496+
core.ApplyDAOHardFork(work.state)
497+
}
494498

495499
/* //approach 1
496500
transactions := self.eth.TxPool().GetTransactions()

params/dao_list.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright 2016 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package params
18+
19+
import (
20+
"encoding/json"
21+
"fmt"
22+
23+
"github.com/ethereum/go-ethereum/common"
24+
)
25+
26+
// DAODrainList is the list of accounts whose full balances will be moved into a
27+
// refund contract at the beginning of the dao-fork block.
28+
var DAODrainList []common.Address
29+
30+
func init() {
31+
// Parse the list of DAO accounts to drain
32+
var list []map[string]string
33+
if err := json.Unmarshal([]byte(daoDrainListJSON), &list); err != nil {
34+
panic(fmt.Errorf("Failed to parse DAO drain list: %v", err))
35+
}
36+
// Collect all the accounts that need draining
37+
for _, dao := range list {
38+
DAODrainList = append(DAODrainList, common.HexToAddress(dao["address"]))
39+
DAODrainList = append(DAODrainList, common.HexToAddress(dao["extraBalanceAccount"]))
40+
}
41+
}
42+
43+
// daoDrainListJSON is the JSON encoded list of accounts whose full balances will
44+
// be moved into a refund contract at the beginning of the dao-fork block.
45+
const daoDrainListJSON = `
46+
[
47+
{
48+
"address":"0x304a554a310c7e546dfe434669c62820b7d83490",
49+
"balance":"30328a3f333ac2fb5f509",
50+
"extraBalance":"9184e72a000",
51+
"extraBalanceAccount":"0x914d1b8b43e92723e64fd0a06f5bdb8dd9b10c79"
52+
},
53+
{
54+
"address":"0xfe24cdd8648121a43a7c86d289be4dd2951ed49f",
55+
"balance":"ea0b1bdc78f500a43",
56+
"extraBalance":"0",
57+
"extraBalanceAccount":"0x17802f43a0137c506ba92291391a8a8f207f487d"
58+
},
59+
{
60+
"address":"0xb136707642a4ea12fb4bae820f03d2562ebff487",
61+
"balance":"6050bdeb3354b5c98adc3",
62+
"extraBalance":"0",
63+
"extraBalanceAccount":"0xdbe9b615a3ae8709af8b93336ce9b477e4ac0940"
64+
},
65+
{
66+
"address":"0xf14c14075d6c4ed84b86798af0956deef67365b5",
67+
"balance":"1d77844e94c25ba2",
68+
"extraBalance":"0",
69+
"extraBalanceAccount":"0xca544e5c4687d109611d0f8f928b53a25af72448"
70+
},
71+
{
72+
"address":"0xaeeb8ff27288bdabc0fa5ebb731b6f409507516c",
73+
"balance":"2e93a72de4fc5ec0ed",
74+
"extraBalance":"0",
75+
"extraBalanceAccount":"0xcbb9d3703e651b0d496cdefb8b92c25aeb2171f7"
76+
},
77+
{
78+
"address":"0xaccc230e8a6e5be9160b8cdf2864dd2a001c28b6",
79+
"balance":"14d0944eb3be947a8",
80+
"extraBalance":"0",
81+
"extraBalanceAccount":"0x2b3455ec7fedf16e646268bf88846bd7a2319bb2"
82+
},
83+
{
84+
"address":"0x4613f3bca5c44ea06337a9e439fbc6d42e501d0a",
85+
"balance":"275eaa8345ced6523a8",
86+
"extraBalance":"0",
87+
"extraBalanceAccount":"0xd343b217de44030afaa275f54d31a9317c7f441e"
88+
},
89+
{
90+
"address":"0x84ef4b2357079cd7a7c69fd7a37cd0609a679106",
91+
"balance":"4accfbf922fd046baa05",
92+
"extraBalance":"0",
93+
"extraBalanceAccount":"0xda2fef9e4a3230988ff17df2165440f37e8b1708"
94+
},
95+
{
96+
"address":"0xf4c64518ea10f995918a454158c6b61407ea345c",
97+
"balance":"38d275b0ed7862ba4f13",
98+
"extraBalance":"0",
99+
"extraBalanceAccount":"0x7602b46df5390e432ef1c307d4f2c9ff6d65cc97"
100+
},
101+
{
102+
"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
103+
"balance":"1",
104+
"extraBalance":"49097c66ae78c50e4d3c",
105+
"extraBalanceAccount":"0x807640a13483f8ac783c557fcdf27be11ea4ac7a"
106+
}
107+
]
108+
`

params/util.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ var (
2626
TestNetHomesteadBlock = big.NewInt(494000) // Testnet homestead block
2727
MainNetHomesteadBlock = big.NewInt(1150000) // Mainnet homestead block
2828

29-
TestNetDAOForkBlock = big.NewInt(8888888) // Testnet dao hard-fork block
30-
MainNetDAOForkBlock = big.NewInt(9999999) // Mainnet dao hard-fork block
31-
DAOForkBlockExtra = common.FromHex("0x64616f2d686172642d666f726b") // Block extradata to signel the fork with ("dao-hard-fork")
32-
DAOForkExtraRange = big.NewInt(10) // Number of blocks to override the extradata (prevent no-fork attacks)
29+
TestNetDAOForkBlock = big.NewInt(8888888) // Testnet dao hard-fork block
30+
MainNetDAOForkBlock = big.NewInt(9999999) // Mainnet dao hard-fork block
31+
DAOForkBlockExtra = common.FromHex("0x64616f2d686172642d666f726b") // Block extradata to signel the fork with ("dao-hard-fork")
32+
DAOForkExtraRange = big.NewInt(10) // Number of blocks to override the extradata (prevent no-fork attacks)
33+
DAORefundContract = common.HexToAddress("0x0000000000000000000000000000000000000000") // Address of the refund contract to send DAO balances to
3334
)

0 commit comments

Comments
 (0)