diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index eccd57f8..9e557df8 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -71,6 +71,7 @@ func NewSimulatedBackendWithDatabase(database etruedb.Database, alloc types.Gene genesis.Config.TIP10 = ¶ms.BlockConfig{FastNumber: big.NewInt(1000)} genesis.Config.TIP11 = ¶ms.BlockConfig{FastNumber: big.NewInt(0)} genesis.Config.TIP13 = ¶ms.BlockConfig{FastNumber: big.NewInt(0), SnailNumber: big.NewInt(0)} + genesis.Config.TIP14 = ¶ms.BlockConfig{FastNumber: big.NewInt(0)} genesis.MustFastCommit(database) blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{}) diff --git a/consensus/minerva/consensus.go b/consensus/minerva/consensus.go index a4dd1422..b15e8fae 100644 --- a/consensus/minerva/consensus.go +++ b/consensus/minerva/consensus.go @@ -882,7 +882,8 @@ func (m *Minerva) Finalize(chain consensus.ChainReader, header *types.Header, st if fastNumber.Uint64() == epoch.EndHeight && fastNumber.Cmp(chain.Config().TIP13.FastNumber) >= 0 { log.Info("*************accumulateRewardsFast3*******************") tip13Epoch := types.GetEpochFromHeight(chain.Config().TIP13.FastNumber.Uint64()) - infos, err = accumulateRewardsFast3(state, new(big.Int).Set(header.Number), big.NewInt(int64(tip13Epoch.EpochID))) + infos, err = accumulateRewardsFast3(state, new(big.Int).Set(header.Number), big.NewInt(int64(tip13Epoch.EpochID)), + new(big.Int).Set(chain.Config().TIP14.FastNumber)) if err != nil { log.Error("Finalize Error", "accumulateRewardsFast3", err.Error()) return nil, nil, err @@ -1155,8 +1156,8 @@ func accumulateRewardsFast2(stateDB *state.StateDB, sBlock *types.SnailBlock, fa // "FruitBase",rewardsInfos.FruitBase,"CommitteeBase",rewardsInfos.CommitteeBase) return rewardsInfos, nil } -func accumulateRewardsFast3(stateDB *state.StateDB, fast, origin *big.Int) (*types.ChainReward, error) { - committeeCoin, developerCoin := getBaseRewardCoinForPos(fast, origin) +func accumulateRewardsFast3(stateDB *state.StateDB, fast, origin, tip14 *big.Int) (*types.ChainReward, error) { + committeeCoin, developerCoin := getBaseRewardCoinForPos(fast, origin, tip14) epoch := types.GetEpochFromHeight(fast.Uint64()) impawn := vm.NewImpawnImpl() @@ -1203,8 +1204,8 @@ func posOfFruitsInFirstEpoch(fruits []*types.SnailBlock, min, max uint64) int { } return -1 } -func getBaseRewardCoinForPos(height, origin *big.Int) (committee, developercoin *big.Int) { - base := getRewardCoin2(height.Uint64(), origin.Uint64()) +func getBaseRewardCoinForPos(height, origin, tip14 *big.Int) (committee, developercoin *big.Int) { + base := getRewardCoin2(height.Uint64(), origin.Uint64(), tip14.Uint64()) // developercoin = base * 19% developercoin = new(big.Int).Div(new(big.Int).Mul(base, big.NewInt(19)), big.NewInt(100)) @@ -1406,13 +1407,16 @@ func getRewardCoin(height *big.Int) *big.Int { // decay 20% per years from the fork fast height. // 250 epochs in one year (365*86400/(5*25000)=252). // origin: the new epoch for the fork point -func getRewardCoin2(height, origin uint64) *big.Int { +func getRewardCoin2(height, origin, tip14 uint64) *big.Int { const count_epoch_in_one_year = 250 cur := types.GetEpochFromHeight(height) if cur.EpochID < origin { return big.NewInt(0) } base := new(big.Int).Set(NewRewardCoinForPos) + if height >= tip14 { + base = new(big.Int).Set(params.INITNewRewardCoinForPos2) + } margin := cur.EpochID - origin loops := new(big.Int).Div(big.NewInt(int64(margin)), big.NewInt(int64(count_epoch_in_one_year))).Int64() for i := 0; i < int(loops); i++ { diff --git a/consensus/minerva/consensus_test.go b/consensus/minerva/consensus_test.go index 0ac96e60..4f4791bd 100644 --- a/consensus/minerva/consensus_test.go +++ b/consensus/minerva/consensus_test.go @@ -276,12 +276,15 @@ func TestTime(t *testing.T) { fmt.Println("finish") } func Test03(t *testing.T) { + + cur2 := types.GetEpochFromHeight(23761197) + fmt.Println(cur2.EpochID, cur2.EndHeight) origin, height := uint64(0), uint64(0) year := new(big.Int).Mul(big.NewInt(250), big.NewInt(25000)) for i := 0; i < 100; i++ { - coin := getRewardCoin2(height, origin) + coin := getRewardCoin2(height, origin, 0) cur := types.GetEpochFromHeight(height) - fmt.Println(i, cur.EpochID, "yeas:", cur.EpochID/244, "coin", coin.String()) + fmt.Println(i, cur.EpochID, "yeas:", cur.EpochID/244, "coin", coin.String(), toTrueCoin(coin)) height = height + uint64(10*(i+1)) + year.Uint64() } } diff --git a/params/config.go b/params/config.go index bcae6ce7..baa30792 100644 --- a/params/config.go +++ b/params/config.go @@ -65,6 +65,7 @@ var ( TIP11: &BlockConfig{FastNumber: big.NewInt(8996000)}, TIP12: &BlockConfig{FastNumber: big.NewInt(14538000)}, TIP13: &BlockConfig{FastNumber: big.NewInt(23700000), SnailNumber: big.NewInt(198778)}, + TIP14: &BlockConfig{FastNumber: big.NewInt(23785000)}, } // MainnetTrustedCheckpoint contains the light client trusted checkpoint for the main network. @@ -105,6 +106,7 @@ var ( TIP11: &BlockConfig{FastNumber: big.NewInt(7552000)}, TIP12: &BlockConfig{FastNumber: big.NewInt(0)}, TIP13: &BlockConfig{FastNumber: big.NewInt(0), SnailNumber: big.NewInt(0)}, + TIP14: &BlockConfig{FastNumber: big.NewInt(0)}, } // TestnetTrustedCheckpoint contains the light client trusted checkpoint for the Ropsten test network. @@ -145,6 +147,7 @@ var ( TIP11: &BlockConfig{FastNumber: big.NewInt(0)}, TIP12: &BlockConfig{FastNumber: big.NewInt(0)}, TIP13: &BlockConfig{FastNumber: big.NewInt(0), SnailNumber: big.NewInt(0)}, + TIP14: &BlockConfig{FastNumber: big.NewInt(0)}, } SingleNodeChainConfig = &ChainConfig{ @@ -163,6 +166,7 @@ var ( TIP11: &BlockConfig{FastNumber: big.NewInt(0)}, TIP12: &BlockConfig{FastNumber: big.NewInt(0)}, TIP13: &BlockConfig{FastNumber: big.NewInt(0), SnailNumber: big.NewInt(0)}, + TIP14: &BlockConfig{FastNumber: big.NewInt(0)}, } // TestnetTrustedCheckpoint contains the light client trusted checkpoint for the Ropsten test network. @@ -180,14 +184,14 @@ var ( // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. AllMinervaProtocolChanges = &ChainConfig{ChainID: chainId, Minerva: new(MinervaConfig), TIP3: &BlockConfig{FastNumber: big.NewInt(0)}, - TIP5: nil, TIP7: nil, TIP8: nil, TIP9: nil, TIP10: nil, TIP11: &BlockConfig{FastNumber: big.NewInt(0)}, TIP13: nil, + TIP5: nil, TIP7: nil, TIP8: nil, TIP9: nil, TIP10: nil, TIP11: &BlockConfig{FastNumber: big.NewInt(0)}, TIP13: nil, TIP14: nil, } // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. TestChainConfig = &ChainConfig{ChainID: chainId, Minerva: &MinervaConfig{MinimumDifficulty, MinimumFruitDifficulty, DurationLimit}, TIP3: &BlockConfig{FastNumber: big.NewInt(0)}, - TIP5: nil, TIP7: nil, TIP8: nil, TIP9: nil, TIP10: nil, TIP11: &BlockConfig{FastNumber: big.NewInt(0)}, TIP13: nil, + TIP5: nil, TIP7: nil, TIP8: nil, TIP9: nil, TIP10: nil, TIP11: &BlockConfig{FastNumber: big.NewInt(0)}, TIP13: nil, TIP14: nil, } ) @@ -258,6 +262,7 @@ type ChainConfig struct { TIP11 *BlockConfig `json:"tip11"` TIP12 *BlockConfig `json:"tip12"` TIP13 *BlockConfig `json:"tip13"` + TIP14 *BlockConfig `json:"tip14"` TIPStake *BlockConfig `json:"tipstake"` } @@ -540,3 +545,9 @@ func (c *ChainConfig) IsTIP13(num *big.Int) bool { } return isForked(c.TIP13.FastNumber, num) } +func (c *ChainConfig) IsTIP14(num *big.Int) bool { + if c.TIP14 == nil { + return false + } + return isForked(c.TIP14.FastNumber, num) +} diff --git a/params/protocol_params.go b/params/protocol_params.go index 6d8d4e66..540e2751 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -194,5 +194,6 @@ var ( DposForkPoint uint64 = 0 ElectionMinLimitForStaking = new(big.Int).Mul(big.NewInt(20000), big.NewInt(1e18)) // calc from the TIP13 by manual - INITNewRewardCoinForPos = new(big.Int).Mul(big.NewInt(4096), big.NewInt(1e16)) + INITNewRewardCoinForPos = new(big.Int).Mul(big.NewInt(4096), big.NewInt(1e16)) + INITNewRewardCoinForPos2 = new(big.Int).Mul(big.NewInt(8192), big.NewInt(1e18)) ) diff --git a/send_transaction/test/pos_test.go b/send_transaction/test/pos_test.go index b27f47bc..10a56ad6 100644 --- a/send_transaction/test/pos_test.go +++ b/send_transaction/test/pos_test.go @@ -143,6 +143,7 @@ func TestSendTX(t *testing.T) { gspec.Config.TIP8 = ¶ms.BlockConfig{FastNumber: big.NewInt(0), CID: big.NewInt(-1)} gspec.Config.TIP9 = ¶ms.BlockConfig{SnailNumber: big.NewInt(20)} gspec.Config.TIP13 = ¶ms.BlockConfig{FastNumber: big.NewInt(0), SnailNumber: big.NewInt(0)} + gspec.Config.TIP14 = ¶ms.BlockConfig{FastNumber: big.NewInt(0)} genesis := gspec.MustFastCommit(db) blockchain, _ := core.NewBlockChain(db, nil, gspec.Config, engine, vm.Config{}) @@ -167,6 +168,7 @@ func TestRewardTime(t *testing.T) { gspec.Config.TIP8 = ¶ms.BlockConfig{FastNumber: big.NewInt(0), CID: big.NewInt(-1)} gspec.Config.TIP9 = ¶ms.BlockConfig{SnailNumber: big.NewInt(20)} gspec.Config.TIP13 = ¶ms.BlockConfig{FastNumber: big.NewInt(0), SnailNumber: big.NewInt(0)} + gspec.Config.TIP14 = ¶ms.BlockConfig{FastNumber: big.NewInt(0)} genesis := gspec.MustFastCommit(db) blockchain, _ := core.NewBlockChain(db, nil, gspec.Config, engine, vm.Config{})