Skip to content

Commit

Permalink
add tip14
Browse files Browse the repository at this point in the history
  • Loading branch information
iceming123 committed Jan 10, 2023
1 parent 3ca36e9 commit 6500d9d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func NewSimulatedBackendWithDatabase(database etruedb.Database, alloc types.Gene
genesis.Config.TIP10 = &params.BlockConfig{FastNumber: big.NewInt(1000)}
genesis.Config.TIP11 = &params.BlockConfig{FastNumber: big.NewInt(0)}
genesis.Config.TIP13 = &params.BlockConfig{FastNumber: big.NewInt(0), SnailNumber: big.NewInt(0)}
genesis.Config.TIP14 = &params.BlockConfig{FastNumber: big.NewInt(0)}

genesis.MustFastCommit(database)
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{})
Expand Down
16 changes: 10 additions & 6 deletions consensus/minerva/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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++ {
Expand Down
7 changes: 5 additions & 2 deletions consensus/minerva/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
15 changes: 13 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand All @@ -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.
Expand All @@ -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,
}
)

Expand Down Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
2 changes: 2 additions & 0 deletions send_transaction/test/pos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func TestSendTX(t *testing.T) {
gspec.Config.TIP8 = &params.BlockConfig{FastNumber: big.NewInt(0), CID: big.NewInt(-1)}
gspec.Config.TIP9 = &params.BlockConfig{SnailNumber: big.NewInt(20)}
gspec.Config.TIP13 = &params.BlockConfig{FastNumber: big.NewInt(0), SnailNumber: big.NewInt(0)}
gspec.Config.TIP14 = &params.BlockConfig{FastNumber: big.NewInt(0)}

genesis := gspec.MustFastCommit(db)
blockchain, _ := core.NewBlockChain(db, nil, gspec.Config, engine, vm.Config{})
Expand All @@ -167,6 +168,7 @@ func TestRewardTime(t *testing.T) {
gspec.Config.TIP8 = &params.BlockConfig{FastNumber: big.NewInt(0), CID: big.NewInt(-1)}
gspec.Config.TIP9 = &params.BlockConfig{SnailNumber: big.NewInt(20)}
gspec.Config.TIP13 = &params.BlockConfig{FastNumber: big.NewInt(0), SnailNumber: big.NewInt(0)}
gspec.Config.TIP14 = &params.BlockConfig{FastNumber: big.NewInt(0)}

genesis := gspec.MustFastCommit(db)
blockchain, _ := core.NewBlockChain(db, nil, gspec.Config, engine, vm.Config{})
Expand Down

0 comments on commit 6500d9d

Please sign in to comment.