rename variable name and add comments

pull/4163/head
peekpi 3 years ago committed by Soph
parent ac4d4b02db
commit c1fd188df0
  1. 2
      cmd/harmony/default.go
  2. 2
      internal/configs/harmony/harmony.go
  3. 2
      internal/configs/sharding/instance.go
  4. 2
      internal/configs/sharding/shardingconfig.go
  5. 2
      internal/params/config.go
  6. 6
      staking/effective/calculate.go

@ -106,7 +106,7 @@ var defaultDevnetConfig = harmonyconfig.DevnetConfig{
NumShards: 2,
ShardSize: 10,
HmyNodeSize: 10,
SlotsLimit: 0,
SlotsLimit: 0, // 0 means no limit
}
var defaultRevertConfig = harmonyconfig.RevertConfig{

@ -174,7 +174,7 @@ type DevnetConfig struct {
NumShards int
ShardSize int
HmyNodeSize int
SlotsLimit int // HIP-16: The absolute number of maximum effective slots per shard limit for each validator.
SlotsLimit int // HIP-16: The absolute number of maximum effective slots per shard limit for each validator. 0 means no limit.
}
// TODO: make `revert` to a separate command

@ -32,7 +32,7 @@ type instance struct {
fnAccounts []genesis.DeployAccount
reshardingEpoch []*big.Int
blocksPerEpoch uint64
slotsLimit int // HIP-16: The absolute number of maximum effective slots per shard limit for each validator.
slotsLimit int // HIP-16: The absolute number of maximum effective slots per shard limit for each validator. 0 means no limit.
}
// NewInstance creates and validates a new sharding configuration based

@ -72,7 +72,7 @@ type Instance interface {
// Count of blocks per epoch
BlocksPerEpoch() uint64
// HIP-16: The absolute number of maximum effective slots per shard limit for each validator.
// HIP-16: The absolute number of maximum effective slots per shard limit for each validator. 0 means no limit.
SlotsLimit() int
}

@ -430,7 +430,7 @@ type ChainConfig struct {
StakingPrecompileEpoch *big.Int `json:"staking-precompile-epoch,omitempty"`
// SlotsLimitedEpoch is the first epoch to enable HIP-16.
SlotsLimitedEpoch *big.Int `json:"slots-limit,omitempty"`
SlotsLimitedEpoch *big.Int `json:"slots-limit-epoch,omitempty"`
}
// String implements the fmt.Stringer interface.

@ -127,13 +127,15 @@ func Compute(
}
shard := new(big.Int).Mod(slot.Key.Big(), big.NewInt(int64(shardCount))).Int64()
shardSlotsCount[int(shard)]++
// skip if count of slots in this shard exceeds the limit
if slotsLimit > 0 && shardSlotsCount[int(shard)] > slotsLimit {
continue
}
eposedSlots = append(eposedSlots, slot)
}
if effectiveSlotsCount := len(eposedSlots) - startIndex; effectiveSlotsCount != slotsCount {
effectiveSpread := numeric.NewDecFromBigInt(staker.slot.Stake).QuoInt64(int64(effectiveSlotsCount))
// recalculate the effectiveSpread if slots exceed the limit
if limitedSlotsCount := len(eposedSlots) - startIndex; limitedSlotsCount != slotsCount {
effectiveSpread := numeric.NewDecFromBigInt(staker.slot.Stake).QuoInt64(int64(limitedSlotsCount))
for _, slot := range eposedSlots[startIndex:] {
slot.RawStake = effectiveSpread
slot.EPoSStake = effectiveSpread

Loading…
Cancel
Save