diff --git a/shard/committee/assignment.go b/shard/committee/assignment.go index a81169cac..3d13c83d4 100644 --- a/shard/committee/assignment.go +++ b/shard/committee/assignment.go @@ -149,6 +149,13 @@ func eposStakedCommittee( nil, }) } + + if stakedSlotsCount == 0 { + utils.Logger().Info().Int("slots-for-epos", stakedSlotsCount). + Msg("committe composed only of harmony node") + return superComm, nil + } + staked := effective.Apply(essentials, stakedSlotsCount) shardBig := big.NewInt(int64(shardCount)) diff --git a/staking/effective/calculate.go b/staking/effective/calculate.go index 1124e1acd..f2b7f593e 100644 --- a/staking/effective/calculate.go +++ b/staking/effective/calculate.go @@ -66,6 +66,12 @@ func (s Slots) JSON() string { } func median(stakes []SlotPurchase) numeric.Dec { + + if len(stakes) == 0 { + utils.Logger().Error().Int("non-zero", len(stakes)). + Msg("Input to median has len 0, check caller") + } + sort.SliceStable( stakes, func(i, j int) bool { return stakes[i].Dec.LTE(stakes[j].Dec) }, @@ -115,6 +121,11 @@ func Apply(shortHand map[common.Address]SlotOrder, pull int) Slots { pull = l } picks := eposedSlots[:pull] + + if len(picks) == 0 { + return Slots{} + } + median := median(picks) for i := range picks {