aboutsummaryrefslogtreecommitdiffstats
path: root/consensus
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-02-22 13:14:55 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:22 +0800
commit2354d4aa747616a8fd4fb9482ada8042fd362139 (patch)
tree46fe0953c0258591c2cd415c3760764ff613a5bb /consensus
parent81193a683d6328b627ee0e5f0f3689b3473e29ea (diff)
downloadgo-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar
go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.gz
go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.bz2
go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.lz
go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.xz
go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.zst
go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.zip
core: Remove K, Phi and NumChains from Governance (#198)
* change default sync_core.sh * vendor: sync to latest core * core: Remove K, Phi and NumChain
Diffstat (limited to 'consensus')
-rw-r--r--consensus/dexcon/dexcon.go23
-rw-r--r--consensus/dexcon/dexcon_test.go15
2 files changed, 11 insertions, 27 deletions
diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go
index 2e406f0b0..aff5c9c45 100644
--- a/consensus/dexcon/dexcon.go
+++ b/consensus/dexcon/dexcon.go
@@ -111,26 +111,17 @@ func (d *Dexcon) calculateBlockReward(round int64, state *state.StateDB) *big.In
gs := d.govStateFetcer.GetGovStateHelperAtRound(uint64(round))
config := gs.Configuration()
- gsCurrent := vm.GovernanceStateHelper{state}
- configCurrent := gsCurrent.Configuration()
- heightCurrent := gsCurrent.RoundHeight(big.NewInt(round)).Uint64()
+ blocksPerRound := config.RoundLength
+ roundInterval := new(big.Float).Mul(
+ big.NewFloat(float64(blocksPerRound)),
+ big.NewFloat(float64(config.MinBlockInterval)))
- blocksPerRound := uint64(0)
-
- // The initial round, calculate an approximate number of round base on config.
- if round == 0 || heightCurrent == 0 {
- blocksPerRound = uint64(config.NumChains) * config.RoundInterval / config.MinBlockInterval
- } else {
- heightPrev := gsCurrent.RoundHeight(big.NewInt(round - 1)).Uint64()
- blocksPerRound = heightCurrent - heightPrev
- }
-
- // blockReard = miningVelocity * totalStaked * roundInterval / aYear / numBlocksInPrevRound
+ // blockReard = miningVelocity * totalStaked * roundInterval / aYear / numBlocksInCurRound
numerator, _ := new(big.Float).Mul(
new(big.Float).Mul(
- big.NewFloat(float64(configCurrent.MiningVelocity)),
+ big.NewFloat(float64(config.MiningVelocity)),
new(big.Float).SetInt(gs.TotalStaked())),
- new(big.Float).SetInt(gs.RoundInterval())).Int(nil)
+ roundInterval).Int(nil)
reward := new(big.Int).Div(numerator,
new(big.Int).Mul(
diff --git a/consensus/dexcon/dexcon_test.go b/consensus/dexcon/dexcon_test.go
index 7ba1be876..65ed77cc8 100644
--- a/consensus/dexcon/dexcon_test.go
+++ b/consensus/dexcon/dexcon_test.go
@@ -63,8 +63,7 @@ func (d *DexconTestSuite) SetupTest() {
config.NextHalvingSupply = new(big.Int).Mul(big.NewInt(1e18), big.NewInt(2.5e9))
config.LastHalvedAmount = new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1.5e9))
config.MiningVelocity = 0.1875
- config.RoundInterval = 3600000
- config.NumChains = 6
+ config.RoundLength = 3600
config.MinBlockInterval = 1000
d.config = config
@@ -91,15 +90,9 @@ func (d *DexconTestSuite) TestBlockRewardCalculation() {
d.s.IncTotalStaked(big.NewInt(1e18))
- // blockReard = miningVelocity * totalStaked * roundInterval / aYear / numBlocksInPrevRound
- // 0.1875 * 1e18 * 3600 * 1000 / (86400 * 1000 * 365 * 6 * 3600) = 990930999.4926434
- d.Require().Equal(big.NewInt(990930999), consensus.calculateBlockReward(0, d.stateDB))
-
- // Round 1
- d.s.PushRoundHeight(big.NewInt(4000 * 6))
-
- // 0.1875 * 1e18 * 3600 * 1000 / (86400 * 1000 * 365 * 6 * 4000) = 891837899
- d.Require().Equal(big.NewInt(891837899), consensus.calculateBlockReward(1, d.stateDB))
+ // blockReard = miningVelocity * totalStaked * roundInterval / aYear / numBlocksInCurRound
+ // 0.1875 * 1e18 * 3600 * 1000 / (86400 * 1000 * 365 * 3600) = 5945585996.96
+ d.Require().Equal(big.NewInt(5945585996), consensus.calculateBlockReward(0, d.stateDB))
}
func TestDexcon(t *testing.T) {