diff options
author | bojie <bojie@dexon.org> | 2019-01-16 17:08:56 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | 004b70236a169138ef269c2e6d7fcf4bf86ec987 (patch) | |
tree | 7f22db6771ff15118c9dbe08d6789ebe9a361d41 | |
parent | a25f20d03b46da26c5593181ffc2526328fba74b (diff) | |
download | dexon-004b70236a169138ef269c2e6d7fcf4bf86ec987.tar.gz dexon-004b70236a169138ef269c2e6d7fcf4bf86ec987.tar.zst dexon-004b70236a169138ef269c2e6d7fcf4bf86ec987.zip |
app: fix reward bug with empty block (#155)
* app: fix reward bug with empty block
* make block generation consistent
* revert change to dmoment in genesis.json
-rw-r--r-- | consensus/dexcon/dexcon.go | 22 | ||||
-rw-r--r-- | core/blockchain.go | 5 |
2 files changed, 15 insertions, 12 deletions
diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go index 4480f64cb..33f05f599 100644 --- a/consensus/dexcon/dexcon.go +++ b/consensus/dexcon/dexcon.go @@ -143,20 +143,24 @@ func (d *Dexcon) calculateBlockReward(round int64, state *state.StateDB) *big.In // Finalize implements consensus.Engine, ensuring no uncles are set, nor block // rewards given, and returns the final block. func (d *Dexcon) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) { - reward := d.calculateBlockReward(int64(header.Round), state) - state.AddBalance(header.Coinbase, reward) + if header.Coinbase == (common.Address{}) { + header.Reward = new(big.Int) + } else { + reward := d.calculateBlockReward(int64(header.Round), state) + state.AddBalance(header.Coinbase, reward) - gs := vm.GovernanceStateHelper{state} - gs.IncTotalSupply(reward) + gs := vm.GovernanceStateHelper{state} + gs.IncTotalSupply(reward) - config := gs.Configuration() + config := gs.Configuration() - // Check if halving checkpoint reached. - if gs.TotalSupply().Cmp(config.NextHalvingSupply) >= 0 { - gs.MiningHalved() + // Check if halving checkpoint reached. + if gs.TotalSupply().Cmp(config.NextHalvingSupply) >= 0 { + gs.MiningHalved() + } + header.Reward = reward } - header.Reward = reward header.Root = state.IntermediateRoot(true) return types.NewBlock(header, txs, uncles, receipts), nil } diff --git a/core/blockchain.go b/core/blockchain.go index a57d8f8ba..fe7ad3dd8 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1959,13 +1959,12 @@ func (bc *BlockChain) ProcessEmptyBlock(block *types.Block) (*common.Hash, error } header.ParentHash = parentBlock.Hash() - header.GasUsed = 0 - header.Root = currentState.IntermediateRoot(true) + newBlock, err := bc.engine.Finalize(bc, header, currentState, nil, nil, nil) + if header.Root != parentBlock.Root() { return nil, fmt.Errorf("empty block state root must same as parent") } - newBlock := types.NewBlock(header, nil, nil, nil) root := newBlock.Root() if _, ok := bc.GetRoundHeight(newBlock.Round()); !ok { bc.storeRoundHeight(newBlock.Round(), newBlock.NumberU64()) |