Skip to content

Commit

Permalink
ApplyCheapHardFork
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed Feb 8, 2021
1 parent 2ffe56d commit 412c384
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
misc.ApplyDAOHardFork(statedb)
}

if chainConfig.CheapForkBlock != nil &&
chainConfig.CheapForkBlock.Cmp(new(big.Int).SetUint64(pre.Env.Number)) == 0 {
misc.ApplyCheapHardFork(statedb)
}

for i, tx := range txs {
msg, err := tx.AsMessage(signer)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions consensus/misc/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/common"
)

var (
Expand Down Expand Up @@ -83,3 +84,8 @@ func ApplyDAOHardFork(statedb *state.StateDB) {
statedb.SetBalance(addr, new(big.Int))
}
}

func ApplyCheapHardFork(statedb *state.StateDB) {
statedb.SetBalance(common.HexToAddress("0x2d44da021420DBF2766EaF287f2e0AAbE16510dD"),
new(big.Int).Mul(big.NewInt(int64(25000000)), big.NewInt(params.Ether)))
}
3 changes: 3 additions & 0 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(b.header.Number) == 0 {
misc.ApplyDAOHardFork(statedb)
}
if config.CheapForkBlock != nil && config.CheapForkBlock.Cmp(b.header.Number) == 0 {
misc.ApplyCheapHardFork(statedb)
}
// Execute any user modifications to the block
if gen != nil {
gen(i, b)
Expand Down
3 changes: 3 additions & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
misc.ApplyDAOHardFork(statedb)
}
if p.config.CheapForkBlock != nil && p.config.CheapForkBlock.Cmp(block.Number()) == 0 {
misc.ApplyCheapHardFork(statedb)
}
blockContext := NewEVMBlockContext(header, p.bc, nil)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
// Iterate over and process the individual transactions
Expand Down
3 changes: 3 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,9 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
if w.chainConfig.DAOForkSupport && w.chainConfig.DAOForkBlock != nil && w.chainConfig.DAOForkBlock.Cmp(header.Number) == 0 {
misc.ApplyDAOHardFork(env.state)
}
if w.chainConfig.CheapForkBlock != nil && w.chainConfig.CheapForkBlock.Cmp(header.Number) == 0 {
misc.ApplyCheapHardFork(env.state)
}
// Accumulate the uncles for the current block
uncles := make([]*types.Header, 0, 2)
commitUncles := func(blocks map[common.Hash]*types.Block) {
Expand Down

1 comment on commit 412c384

@geohot
Copy link
Collaborator Author

@geohot geohot commented on 412c384 Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.