Add 3s block time and change of block reward (#3469)

* Add 3s block time and change of block reward

* fixes
pull/3473/head
Rongjian Lan 4 years ago committed by GitHub
parent 2d8b316692
commit d8e509cbd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      consensus/consensus_service.go
  2. 15
      internal/chain/reward.go
  3. 17
      internal/params/config.go
  4. 5
      staking/network/reward.go
  5. 7
      staking/network/reward_test.go

@ -5,8 +5,6 @@ import (
"sync/atomic"
"time"
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/crypto/bls"
@ -309,9 +307,9 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode {
consensus.BlockPeriod = 5 * time.Second
// Disable aggregate sig at epoch TBD for mainnet (for other net, it's default to true)
if consensus.Blockchain.Config().ChainID == params.MainnetChainID && curEpoch.Cmp(big.NewInt(1000)) >= 0 {
consensus.AggregateSig = true
// Enable 3s block time at the threeSecondsEpoch
if consensus.Blockchain.Config().IsThreeSeconds(curEpoch) {
consensus.BlockPeriod = 3 * time.Second
}
isFirstTimeStaking := consensus.Blockchain.Config().IsStaking(nextEpoch) &&

@ -144,8 +144,9 @@ func AccumulateRewardsAndCountSigs(
bc.CurrentHeader().ShardID() == shard.BeaconChainShardID {
defaultReward := network.BaseStakedReward
// After block time is reduced to 5 seconds, the block reward is adjusted accordingly
// the block reward is adjusted accordingly based on 5s and 3s block time forks
if bc.Config().ChainID == params.TestnetChainID && bc.Config().FiveSecondsEpoch.Cmp(big.NewInt(16500)) == 0 {
// Testnet:
// This is testnet requiring the one-off forking logic
if blockNum > 634644 {
defaultReward = network.FiveSecondsBaseStakedReward
@ -156,8 +157,16 @@ func AccumulateRewardsAndCountSigs(
}
}
}
} else if bc.Config().IsFiveSeconds(header.Epoch()) {
defaultReward = network.FiveSecondsBaseStakedReward
if bc.Config().IsThreeSeconds(header.Epoch()) {
defaultReward = network.ThreeSecondsBaseStakedReward
}
} else {
// Mainnet (other nets):
if bc.Config().IsThreeSeconds(header.Epoch()) {
defaultReward = network.ThreeSecondsBaseStakedReward
} else if bc.Config().IsFiveSeconds(header.Epoch()) {
defaultReward = network.FiveSecondsBaseStakedReward
}
}
// Following is commented because the new econ-model has a flat-rate block reward

@ -32,6 +32,7 @@ var (
PreStakingEpoch: big.NewInt(185),
QuickUnlockEpoch: big.NewInt(191),
FiveSecondsEpoch: big.NewInt(230),
ThreeSecondsEpoch: big.NewInt(10000), // TBD
RedelegationEpoch: big.NewInt(290),
EIP155Epoch: big.NewInt(28),
S3Epoch: big.NewInt(28),
@ -48,6 +49,7 @@ var (
PreStakingEpoch: big.NewInt(1),
QuickUnlockEpoch: big.NewInt(0),
FiveSecondsEpoch: big.NewInt(16500),
ThreeSecondsEpoch: big.NewInt(70000),
RedelegationEpoch: big.NewInt(36500),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
@ -65,6 +67,7 @@ var (
PreStakingEpoch: big.NewInt(1),
QuickUnlockEpoch: big.NewInt(0),
FiveSecondsEpoch: big.NewInt(0),
ThreeSecondsEpoch: big.NewInt(0),
RedelegationEpoch: big.NewInt(0),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
@ -82,6 +85,7 @@ var (
PreStakingEpoch: big.NewInt(1),
QuickUnlockEpoch: big.NewInt(0),
FiveSecondsEpoch: big.NewInt(0),
ThreeSecondsEpoch: big.NewInt(0),
RedelegationEpoch: big.NewInt(0),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
@ -99,6 +103,7 @@ var (
PreStakingEpoch: big.NewInt(1),
QuickUnlockEpoch: big.NewInt(0),
FiveSecondsEpoch: big.NewInt(0),
ThreeSecondsEpoch: big.NewInt(0),
RedelegationEpoch: big.NewInt(0),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
@ -115,6 +120,7 @@ var (
PreStakingEpoch: big.NewInt(0),
QuickUnlockEpoch: big.NewInt(0),
FiveSecondsEpoch: big.NewInt(0),
ThreeSecondsEpoch: big.NewInt(0),
RedelegationEpoch: big.NewInt(0),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
@ -133,6 +139,7 @@ var (
big.NewInt(0), // PreStakingEpoch
big.NewInt(0), // QuickUnlockEpoch
big.NewInt(0), // FiveSecondsEpoch
big.NewInt(0), // ThreeSecondsEpoch
big.NewInt(0), // RedelegationEpoch
big.NewInt(0), // EIP155Epoch
big.NewInt(0), // S3Epoch
@ -151,6 +158,7 @@ var (
big.NewInt(0), // PreStakingEpoch
big.NewInt(0), // QuickUnlockEpoch
big.NewInt(0), // FiveSecondsEpoch
big.NewInt(0), // ThreeSecondsEpoch
big.NewInt(0), // RedelegationEpoch
big.NewInt(0), // EIP155Epoch
big.NewInt(0), // S3Epoch
@ -204,6 +212,10 @@ type ChainConfig struct {
// and block rewards adjusted to 17.5 ONE/block
FiveSecondsEpoch *big.Int `json:"five-seconds-epoch,omitempty"`
// ThreeSecondsEpoch is the epoch when block time is reduced to 3 seconds
// and block rewards adjusted to 10.5 ONE/block
ThreeSecondsEpoch *big.Int `json:"three-seconds-epoch,omitempty"`
// RedelegationEpoch is the epoch when redelegation is supported and undelegation locking time
// is restored to 7 epoch
RedelegationEpoch *big.Int `json:"redelegation-epoch,omitempty"`
@ -268,6 +280,11 @@ func (c *ChainConfig) IsFiveSeconds(epoch *big.Int) bool {
return isForked(c.FiveSecondsEpoch, epoch)
}
// IsThreeSeconds determines whether it is the epoch to change to 3 seconds block time
func (c *ChainConfig) IsThreeSeconds(epoch *big.Int) bool {
return isForked(c.ThreeSecondsEpoch, epoch)
}
// IsRedelegation determines whether it is the epoch to support redelegation
func (c *ChainConfig) IsRedelegation(epoch *big.Int) bool {
return isForked(c.RedelegationEpoch, epoch)

@ -25,6 +25,11 @@ var (
FiveSecondsBaseStakedReward = numeric.NewDecFromBigInt(new(big.Int).Mul(
big.NewInt(17.5*denominations.Nano), big.NewInt(denominations.Nano),
))
// ThreeSecondsBaseStakedReward is the flat-rate block reward after epoch 360.
// 10.5 ONE per block
ThreeSecondsBaseStakedReward = numeric.NewDecFromBigInt(new(big.Int).Mul(
big.NewInt(10.5*denominations.Nano), big.NewInt(denominations.Nano),
))
// BlockRewardStakedCase is the baseline block reward in staked case -
totalTokens = numeric.NewDecFromBigInt(
new(big.Int).Mul(big.NewInt(12600000000), big.NewInt(denominations.One)),

@ -14,4 +14,11 @@ func TestFiveSecondsBaseStakedReward(t *testing.T) {
"Expected: %s, Got: %s", FiveSecondsBaseStakedReward.String(), expectedNewReward.String(),
)
}
expectedNewReward = BaseStakedReward.Mul(numeric.MustNewDecFromStr("3")).Quo(numeric.MustNewDecFromStr("8"))
if !expectedNewReward.Equal(ThreeSecondsBaseStakedReward) {
t.Errorf(
"Expected: %s, Got: %s", ThreeSecondsBaseStakedReward.String(), expectedNewReward.String(),
)
}
}

Loading…
Cancel
Save