Skip to content

Commit

Permalink
1 sec feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozen committed Dec 20, 2024
1 parent 89b0c63 commit 26ec9e6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
3 changes: 3 additions & 0 deletions consensus/consensus_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ func (consensus *Consensus) updateConsensusInformation(reason string) Mode {
if consensus.Blockchain().Config().IsTwoSeconds(nextEpoch) {
consensus.BlockPeriod = 2 * time.Second
}
if consensus.Blockchain().Config().IsOneSecond(nextEpoch) {
consensus.BlockPeriod = 1 * time.Second
}

isFirstTimeStaking := consensus.Blockchain().Config().IsStaking(nextEpoch) &&
curHeader.IsLastBlockInEpoch() && !consensus.Blockchain().Config().IsStaking(curEpoch)
Expand Down
7 changes: 6 additions & 1 deletion internal/chain/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,14 @@ func getDefaultStakingReward(bc engine.ChainReader, epoch *big.Int, blockNum uin
if bc.Config().IsTwoSeconds(epoch) {
defaultReward = stakingReward.TwoSecStakedBlocks
}
if bc.Config().IsOneSecond(epoch) {
defaultReward = stakingReward.OneSecStakedBlock
}
} else {
// Mainnet (other nets):
if bc.Config().IsHIP30(epoch) {
if bc.Config().IsOneSecond(epoch) {
defaultReward = stakingReward.OneSecStakedBlock
} else if bc.Config().IsHIP30(epoch) {
defaultReward = stakingReward.HIP30StakedBlocks
} else if bc.Config().IsTwoSeconds(epoch) {
defaultReward = stakingReward.TwoSecStakedBlocks
Expand Down
2 changes: 2 additions & 0 deletions internal/configs/sharding/localnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const (

func (ls localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
switch {
case params.LocalnetChainConfig.IsOneSecond(epoch):
return localnetV4
case params.LocalnetChainConfig.IsHIP30(epoch):
return localnetV4
case params.LocalnetChainConfig.IsFeeCollectEpoch(epoch):
Expand Down
13 changes: 11 additions & 2 deletions internal/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ var (
SlotsLimitedEpoch: EpochTBD, // epoch to enable HIP-16
CrossShardXferPrecompileEpoch: big.NewInt(1),
AllowlistEpoch: EpochTBD,
LeaderRotationInternalValidatorsEpoch: big.NewInt(5),
LeaderRotationExternalValidatorsEpoch: big.NewInt(6),
LeaderRotationInternalValidatorsEpoch: big.NewInt(3),
LeaderRotationExternalValidatorsEpoch: big.NewInt(3),
LeaderRotationV2Epoch: EpochTBD,
FeeCollectEpoch: big.NewInt(2),
ValidatorCodeFixEpoch: big.NewInt(2),
Expand All @@ -323,6 +323,7 @@ var (
MaxRateEpoch: EpochTBD,
DevnetExternalEpoch: EpochTBD,
TestnetExternalEpoch: EpochTBD,
IsOneSecondEpoch: big.NewInt(4),
}

// AllProtocolChanges ...
Expand Down Expand Up @@ -374,6 +375,7 @@ var (
big.NewInt(0),
big.NewInt(0),
big.NewInt(0),
big.NewInt(0),
}

// TestChainConfig ...
Expand Down Expand Up @@ -425,6 +427,7 @@ var (
big.NewInt(0), // MaxRateEpoch
big.NewInt(0),
big.NewInt(0),
big.NewInt(0),
}

// TestRules ...
Expand Down Expand Up @@ -606,6 +609,8 @@ type ChainConfig struct {
// vote power feature https://github.com/harmony-one/harmony/pull/4683
// if crosslink are not sent for an entire epoch signed and toSign will be 0 and 0. when that happen, next epoch there will no shard 1 validator elected in the committee.
HIP32Epoch *big.Int `json:"hip32-epoch,omitempty"`

IsOneSecondEpoch *big.Int `json:"is-one-second-epoch,omitempty"`
}

// String implements the fmt.Stringer interface.
Expand Down Expand Up @@ -731,6 +736,10 @@ func (c *ChainConfig) IsTwoSeconds(epoch *big.Int) bool {
return isForked(c.TwoSecondsEpoch, epoch)
}

func (c *ChainConfig) IsOneSecond(epoch *big.Int) bool {
return isForked(c.IsOneSecondEpoch, epoch)
}

// IsSixtyPercent determines whether it is the epoch to reduce internal voting power to 60%
func (c *ChainConfig) IsSixtyPercent(epoch *big.Int) bool {
return isForked(c.SixtyPercentEpoch, epoch)
Expand Down
28 changes: 25 additions & 3 deletions node/harmony/node_syncing.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,29 @@ func (p *LocalSyncingPeerProvider) SyncingPeers(shardID uint32) (peers []p2p.Pee
return nil, errors.Errorf(
"shard ID %d out of range 0..%d", shardID, p.numShards-1)
}
shards := [][]string{
{"6000", "6004", "6008", "6012", "6016", "6020", "6100", "6104", "6108", "6112", "6116", "6120"},
{"6002", "6006", "6010", "6014", "6018", "6022", "6102", "6106", "6110", "6114", "6118", "6122"},
shards := [][]string{}
if true {
shards = [][]string{
{
"6000",
"6004",
"6008",
"6120",
},
{
"6002",
"6006",
"6010",
"6122",
},
}
} else {
shards = [][]string{
{"6000", "6004", "6008", "6012", "6016", "6020", "6100", "6104", "6108", "6112", "6116", "6120"},
{"6002", "6006", "6010", "6014", "6018", "6022", "6102", "6106", "6110", "6114", "6118", "6122"},
}
}

selfport := fmt.Sprint(p.selfPort)
for _, port := range shards[shardID] {
if port == selfport {
Expand Down Expand Up @@ -317,6 +336,9 @@ func (node *Node) doSync(syncInstance ISync, syncingPeerProvider SyncingPeerProv
}
// TODO: treat fake maximum height
if isSynchronized, _, _ := syncInstance.GetParsedSyncStatusDoubleChecked(); !isSynchronized {
if consensus.IsLeader() {
return
}
node.IsSynchronized.UnSet()
if willJoinConsensus {
consensus.BlocksNotSynchronized("node.doSync")
Expand Down
5 changes: 5 additions & 0 deletions staking/reward/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ var (
big.NewInt(14*denominations.Nano), big.NewInt(denominations.Nano),
))

// OneSecStakedBlock is half of HIP30
OneSecStakedBlock = numeric.NewDecFromBigInt(new(big.Int).Mul(
big.NewInt(7*denominations.Nano), big.NewInt(denominations.Nano),
))

// TotalInitialTokens is the total amount of tokens (in ONE) at block 0 of the network.
// This should be set/change on the node's init according to the core.GenesisSpec.
TotalInitialTokens = numeric.Dec{Int: big.NewInt(0)}
Expand Down

0 comments on commit 26ec9e6

Please sign in to comment.