Skip to content

Commit bc11462

Browse files
committed
1 sec feature
1 parent 72e90f7 commit bc11462

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

consensus/consensus_service.go

+3
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ func (consensus *Consensus) updateConsensusInformation(reason string) Mode {
364364
if consensus.Blockchain().Config().IsTwoSeconds(nextEpoch) {
365365
consensus.BlockPeriod = 2 * time.Second
366366
}
367+
if consensus.Blockchain().Config().IsOneSecond(nextEpoch) {
368+
consensus.BlockPeriod = 1 * time.Second
369+
}
367370

368371
isFirstTimeStaking := consensus.Blockchain().Config().IsStaking(nextEpoch) &&
369372
curHeader.IsLastBlockInEpoch() && !consensus.Blockchain().Config().IsStaking(curEpoch)

internal/chain/reward.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,14 @@ func getDefaultStakingReward(bc engine.ChainReader, epoch *big.Int, blockNum uin
220220
if bc.Config().IsTwoSeconds(epoch) {
221221
defaultReward = stakingReward.TwoSecStakedBlocks
222222
}
223+
if bc.Config().IsOneSecond(epoch) {
224+
defaultReward = stakingReward.OneSecStakedBlock
225+
}
223226
} else {
224227
// Mainnet (other nets):
225-
if bc.Config().IsHIP30(epoch) {
228+
if bc.Config().IsOneSecond(epoch) {
229+
defaultReward = stakingReward.OneSecStakedBlock
230+
} else if bc.Config().IsHIP30(epoch) {
226231
defaultReward = stakingReward.HIP30StakedBlocks
227232
} else if bc.Config().IsTwoSeconds(epoch) {
228233
defaultReward = stakingReward.TwoSecStakedBlocks

internal/configs/sharding/localnet.go

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const (
5151

5252
func (ls localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
5353
switch {
54+
case params.LocalnetChainConfig.IsOneSecond(epoch):
55+
return localnetV4
5456
case params.LocalnetChainConfig.IsHIP30(epoch):
5557
return localnetV4
5658
case params.LocalnetChainConfig.IsFeeCollectEpoch(epoch):

internal/params/config.go

+9
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ var (
323323
MaxRateEpoch: EpochTBD,
324324
DevnetExternalEpoch: EpochTBD,
325325
TestnetExternalEpoch: EpochTBD,
326+
IsOneSecondEpoch: big.NewInt(4),
326327
}
327328

328329
// AllProtocolChanges ...
@@ -374,6 +375,7 @@ var (
374375
big.NewInt(0),
375376
big.NewInt(0),
376377
big.NewInt(0),
378+
big.NewInt(0),
377379
}
378380

379381
// TestChainConfig ...
@@ -425,6 +427,7 @@ var (
425427
big.NewInt(0), // MaxRateEpoch
426428
big.NewInt(0),
427429
big.NewInt(0),
430+
big.NewInt(0),
428431
}
429432

430433
// TestRules ...
@@ -606,6 +609,8 @@ type ChainConfig struct {
606609
// vote power feature https://github.com/harmony-one/harmony/pull/4683
607610
// 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.
608611
HIP32Epoch *big.Int `json:"hip32-epoch,omitempty"`
612+
613+
IsOneSecondEpoch *big.Int `json:"is-one-second-epoch,omitempty"`
609614
}
610615

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

739+
func (c *ChainConfig) IsOneSecond(epoch *big.Int) bool {
740+
return isForked(c.IsOneSecondEpoch, epoch)
741+
}
742+
734743
// IsSixtyPercent determines whether it is the epoch to reduce internal voting power to 60%
735744
func (c *ChainConfig) IsSixtyPercent(epoch *big.Int) bool {
736745
return isForked(c.SixtyPercentEpoch, epoch)

node/harmony/node_syncing.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,29 @@ func (p *LocalSyncingPeerProvider) SyncingPeers(shardID uint32) (peers []p2p.Pee
206206
return nil, errors.Errorf(
207207
"shard ID %d out of range 0..%d", shardID, p.numShards-1)
208208
}
209-
shards := [][]string{
210-
{"6000", "6004", "6008", "6012", "6016", "6020", "6100", "6104", "6108", "6112", "6116", "6120"},
211-
{"6002", "6006", "6010", "6014", "6018", "6022", "6102", "6106", "6110", "6114", "6118", "6122"},
209+
shards := [][]string{}
210+
if true {
211+
shards = [][]string{
212+
{
213+
"6000",
214+
"6004",
215+
"6008",
216+
"6120",
217+
},
218+
{
219+
"6002",
220+
"6006",
221+
"6010",
222+
"6122",
223+
},
224+
}
225+
} else {
226+
shards = [][]string{
227+
{"6000", "6004", "6008", "6012", "6016", "6020", "6100", "6104", "6108", "6112", "6116", "6120"},
228+
{"6002", "6006", "6010", "6014", "6018", "6022", "6102", "6106", "6110", "6114", "6118", "6122"},
229+
}
212230
}
231+
213232
selfport := fmt.Sprint(p.selfPort)
214233
for _, port := range shards[shardID] {
215234
if port == selfport {
@@ -317,6 +336,9 @@ func (node *Node) doSync(syncInstance ISync, syncingPeerProvider SyncingPeerProv
317336
}
318337
// TODO: treat fake maximum height
319338
if isSynchronized, _, _ := syncInstance.GetParsedSyncStatusDoubleChecked(); !isSynchronized {
339+
if consensus.IsLeader() {
340+
return
341+
}
320342
node.IsSynchronized.UnSet()
321343
if willJoinConsensus {
322344
consensus.BlocksNotSynchronized("node.doSync")

staking/reward/values.go

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ var (
3939
big.NewInt(14*denominations.Nano), big.NewInt(denominations.Nano),
4040
))
4141

42+
// OneSecStakedBlock is half of HIP30
43+
OneSecStakedBlock = numeric.NewDecFromBigInt(new(big.Int).Mul(
44+
big.NewInt(7*denominations.Nano), big.NewInt(denominations.Nano),
45+
))
46+
4247
// TotalInitialTokens is the total amount of tokens (in ONE) at block 0 of the network.
4348
// This should be set/change on the node's init according to the core.GenesisSpec.
4449
TotalInitialTokens = numeric.Dec{Int: big.NewInt(0)}

0 commit comments

Comments
 (0)