Merge pull request #1955 from fxfactorial/past-epoch-log

[committee] Log & error if try to Compute a past epoch relative to he…
pull/1957/head
Rongjian Lan 5 years ago committed by GitHub
commit 08dd2d2dd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      shard/committee/assignment.go

@ -13,6 +13,7 @@ import (
"github.com/harmony-one/harmony/shard"
"github.com/harmony-one/harmony/staking/effective"
staking "github.com/harmony-one/harmony/staking/types"
"github.com/pkg/errors"
)
// ValidatorListProvider ..
@ -46,6 +47,8 @@ type ChainReader interface {
GetHeaderByHash(common.Hash) *block.Header
// Config retrieves the blockchain's chain configuration.
Config() *params.ChainConfig
// CurrentHeader retrieves the current header from the local chain.
CurrentHeader() *block.Header
}
// DataProvider ..
@ -59,6 +62,8 @@ type partialStakingEnabled struct{}
var (
// WithStakingEnabled ..
WithStakingEnabled Reader = partialStakingEnabled{}
// ErrComputeForEpochInPast ..
ErrComputeForEpochInPast = errors.New("cannot compute for epoch in past")
)
func preStakingEnabledCommittee(s shardingconfig.Instance) *shard.State {
@ -226,6 +231,13 @@ func (def partialStakingEnabled) Compute(
// Pre-staking shard state doesn't need to set epoch (backward compatible)
return preStakingEnabledCommittee(instance), nil
}
// Sanity check, can't compute against epochs in past
if e := stakerReader.CurrentHeader().Epoch(); epoch.Cmp(e) == -1 {
utils.Logger().Error().Uint64("header-epoch", e.Uint64()).
Uint64("compute-epoch", epoch.Uint64()).
Msg("Tried to compute committee for epoch in past")
return nil, ErrComputeForEpochInPast
}
stakedSlots :=
(instance.NumNodesPerShard() - instance.NumHarmonyOperatedNodesPerShard()) *
int(instance.NumShards())

Loading…
Cancel
Save