aboutsummaryrefslogtreecommitdiffstats
path: root/consensus
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-01-24 15:05:24 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:56 +0800
commit87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0 (patch)
tree7243672ff3235c5fc741b09e0cadf7c69a7c6ec8 /consensus
parent6f9f78e54ceb93db5495a3e15568efbfa9e5b25b (diff)
downloaddexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar.gz
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar.bz2
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar.lz
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar.xz
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar.zst
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.zip
consensus: dexcon: snapshot round height when finalizing block (#170)
Instead of having BP to send a tx to register the round height, just modify the state when finalizing block.
Diffstat (limited to 'consensus')
-rw-r--r--consensus/dexcon/dexcon.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go
index 33f05f599..2e406f0b0 100644
--- a/consensus/dexcon/dexcon.go
+++ b/consensus/dexcon/dexcon.go
@@ -143,13 +143,20 @@ 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) {
+ gs := vm.GovernanceStateHelper{state}
+
+ height := gs.RoundHeight(new(big.Int).SetUint64(header.Round))
+ if header.Round > 0 && height.Uint64() == 0 {
+ gs.PushRoundHeight(header.Number)
+ }
+
+ // Distribute block reward and halving condition.
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)
config := gs.Configuration()