From 9138b107572458917538b22ef255fa330ad03e16 Mon Sep 17 00:00:00 2001 From: peekpi <894646171@qq.com> Date: Tue, 26 Apr 2022 13:15:10 +0800 Subject: [PATCH] rename RawStake() to RawStakePerSlot() and add commnet --- core/blockchain.go | 2 +- hmy/staking.go | 2 +- staking/types/validator.go | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 0ca10c815..40ab953ec 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2568,7 +2568,7 @@ func (bc *BlockChain) UpdateValidatorVotingPower( if snapshot, err := bc.ReadValidatorSnapshotAtEpoch( newEpochSuperCommittee.Epoch, key, ); err == nil { - spread := snapshot.RawStake() + spread := snapshot.RawStakePerSlot() for i := range stats.MetricsPerShard { stats.MetricsPerShard[i].Vote.RawStake = spread } diff --git a/hmy/staking.go b/hmy/staking.go index 3661f19d0..9d227c519 100644 --- a/hmy/staking.go +++ b/hmy/staking.go @@ -46,7 +46,7 @@ func (hmy *Harmony) readAndUpdateRawStakes( if err != nil { continue } - spread = snapshot.RawStake() + spread = snapshot.RawStakePerSlot() validatorSpreads[slotAddr] = spread } diff --git a/staking/types/validator.go b/staking/types/validator.go index 1374175cd..c1819f95b 100644 --- a/staking/types/validator.go +++ b/staking/types/validator.go @@ -387,10 +387,12 @@ func (w *ValidatorWrapper) SanityCheck() error { return nil } -func (snapshot *ValidatorSnapshot) RawStake() numeric.Dec { +// RawStakePerSlot return raw stake of each slot key. If HIP16 was activated at that apoch, it only calculate raw stake for keys not exceed the slotsLimit. +func (snapshot ValidatorSnapshot) RawStakePerSlot() numeric.Dec { wrapper := snapshot.Validator instance := shard.Schedule.InstanceForEpoch(snapshot.Epoch) slotsLimit := instance.SlotsLimit() + // HIP16 is acatived if slotsLimit > 0 { limitedSlotsCount := 0 // limited slots count for HIP16 shardCount := big.NewInt(int64(instance.NumShards()))