diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-07-11 18:55:11 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-07-15 21:52:55 +0800 |
commit | 461cdb593b9e5bd9ae9ac35c68809a3a29290dcb (patch) | |
tree | 62a669dfab270dcfa1e334240083ba067569253f /core | |
parent | 7f00e8c0331bf13739e749bab88bf9006ca02f96 (diff) | |
download | dexon-461cdb593b9e5bd9ae9ac35c68809a3a29290dcb.tar.gz dexon-461cdb593b9e5bd9ae9ac35c68809a3a29290dcb.tar.zst dexon-461cdb593b9e5bd9ae9ac35c68809a3a29290dcb.zip |
core, params, tests: add DAO hard-fork balance moves
Diffstat (limited to 'core')
-rw-r--r-- | core/state_processor.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/core/state_processor.go b/core/state_processor.go index 95b3057bb..a9c2d1e18 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/params" ) var ( @@ -65,7 +66,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg allLogs vm.Logs gp = new(GasPool).AddGas(block.GasLimit()) ) - + // Mutate the statedb according to any hard-fork specs + if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 { + ApplyDAOHardFork(statedb) + } + // Iterate over and process the individual transactions for i, tx := range block.Transactions() { statedb.StartRecord(tx.Hash(), block.Hash(), i) 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 } statedb.AddBalance(header.Coinbase, reward) } + +// ApplyDAOHardFork modifies the state database according to the DAO hard-fork +// rules, transferring all balances of a set of DAO accounts to a single refund +// contract. +func ApplyDAOHardFork(statedb *state.StateDB) { + // Retrieve the contract to refund balances into + refund := statedb.GetOrNewStateObject(params.DAORefundContract) + + // Move every DAO account and extra-balance account funds into the refund contract + for _, addr := range params.DAODrainList { + if account := statedb.GetStateObject(addr); account != nil { + refund.AddBalance(account.Balance()) + account.SetBalance(new(big.Int)) + } + } +} |