|
|
@ -51,6 +51,8 @@ import ( |
|
|
|
"github.com/harmony-one/harmony/shard" |
|
|
|
"github.com/harmony-one/harmony/shard" |
|
|
|
"github.com/harmony-one/harmony/shard/committee" |
|
|
|
"github.com/harmony-one/harmony/shard/committee" |
|
|
|
"github.com/harmony-one/harmony/staking/apr" |
|
|
|
"github.com/harmony-one/harmony/staking/apr" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/staking/availability" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/staking/effective" |
|
|
|
"github.com/harmony-one/harmony/staking/slash" |
|
|
|
"github.com/harmony-one/harmony/staking/slash" |
|
|
|
staking "github.com/harmony-one/harmony/staking/types" |
|
|
|
staking "github.com/harmony-one/harmony/staking/types" |
|
|
|
lru "github.com/hashicorp/golang-lru" |
|
|
|
lru "github.com/hashicorp/golang-lru" |
|
|
@ -2289,7 +2291,29 @@ func (bc *BlockChain) UpdateValidatorVotingPower( |
|
|
|
return shard.ErrSuperCommitteeNil |
|
|
|
return shard.ErrSuperCommitteeNil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rosters := make([]*votepower.Roster, len(newEpochSuperCommittee.Shards)) |
|
|
|
rosters, bootedFromSuperCommittee := |
|
|
|
|
|
|
|
make([]*votepower.Roster, len(newEpochSuperCommittee.Shards)), |
|
|
|
|
|
|
|
map[common.Address]struct{}{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
existing, replacing := |
|
|
|
|
|
|
|
currentEpochSuperCommittee.StakedValidators(), |
|
|
|
|
|
|
|
newEpochSuperCommittee.StakedValidators() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO could also keep track of the BLS keys which
|
|
|
|
|
|
|
|
// lost a slot because just losing slots doesn't mean that the
|
|
|
|
|
|
|
|
// validator was booted, just that some of their keys lost slots
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for currentValidator := range existing.LookupSet { |
|
|
|
|
|
|
|
if _, keptSlot := replacing.LookupSet[currentValidator]; !keptSlot { |
|
|
|
|
|
|
|
bootedFromSuperCommittee[currentValidator] = struct{}{} |
|
|
|
|
|
|
|
// NOTE Think carefully about when time comes to delete offchain things
|
|
|
|
|
|
|
|
// TODO Someone: collect and then delete every 30 epochs
|
|
|
|
|
|
|
|
// rawdb.DeleteValidatorSnapshot(
|
|
|
|
|
|
|
|
// bc.db, currentValidator, currentEpochSuperCommittee.Epoch,
|
|
|
|
|
|
|
|
// )
|
|
|
|
|
|
|
|
// rawdb.DeleteValidatorStats(bc.db, currentValidator)
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for i := range newEpochSuperCommittee.Shards { |
|
|
|
for i := range newEpochSuperCommittee.Shards { |
|
|
|
subCommittee := &newEpochSuperCommittee.Shards[i] |
|
|
|
subCommittee := &newEpochSuperCommittee.Shards[i] |
|
|
@ -2307,7 +2331,9 @@ func (bc *BlockChain) UpdateValidatorVotingPower( |
|
|
|
} |
|
|
|
} |
|
|
|
rosters[i] = roster |
|
|
|
rosters[i] = roster |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
networkWide := votepower.AggregateRosters(rosters) |
|
|
|
networkWide := votepower.AggregateRosters(rosters) |
|
|
|
|
|
|
|
|
|
|
|
for key, value := range networkWide { |
|
|
|
for key, value := range networkWide { |
|
|
|
stats, err := rawdb.ReadValidatorStats(bc.db, key) |
|
|
|
stats, err := rawdb.ReadValidatorStats(bc.db, key) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -2347,6 +2373,28 @@ func (bc *BlockChain) UpdateValidatorVotingPower( |
|
|
|
utils.Logger().Debug().Err(err).Msg("issue with compute of apr") |
|
|
|
utils.Logger().Debug().Err(err).Msg("issue with compute of apr") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
snapshot, err := bc.ReadValidatorSnapshotAtEpoch( |
|
|
|
|
|
|
|
currentEpochSuperCommittee.Epoch, wrapper.Address, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
computed := availability.ComputeCurrentSigning(snapshot, wrapper) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, wasBooted := bootedFromSuperCommittee[wrapper.Address]; wasBooted { |
|
|
|
|
|
|
|
stats.BootedStatus = effective.LostEPoSAuction |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if computed.IsBelowThreshold { |
|
|
|
|
|
|
|
stats.BootedStatus = effective.InsufficientUptimeDuringEpoch |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if slash.IsBanned(wrapper) { |
|
|
|
|
|
|
|
stats.BootedStatus = effective.BannedForDoubleSigning |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := rawdb.WriteValidatorStats( |
|
|
|
if err := rawdb.WriteValidatorStats( |
|
|
|
batch, key, stats, |
|
|
|
batch, key, stats, |
|
|
|
); err != nil { |
|
|
|
); err != nil { |
|
|
@ -2354,37 +2402,25 @@ func (bc *BlockChain) UpdateValidatorVotingPower( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
existing, replacing := |
|
|
|
|
|
|
|
currentEpochSuperCommittee.StakedValidators(), |
|
|
|
|
|
|
|
newEpochSuperCommittee.StakedValidators() |
|
|
|
|
|
|
|
for currentValidator := range existing.LookupSet { |
|
|
|
|
|
|
|
if _, keptSlot := replacing.LookupSet[currentValidator]; !keptSlot { |
|
|
|
|
|
|
|
// TODO Someone: collect and then delete every 30 epochs
|
|
|
|
|
|
|
|
// rawdb.DeleteValidatorSnapshot(
|
|
|
|
|
|
|
|
// bc.db, currentValidator, currentEpochSuperCommittee.Epoch,
|
|
|
|
|
|
|
|
// )
|
|
|
|
|
|
|
|
rawdb.DeleteValidatorStats(bc.db, currentValidator) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// deleteValidatorSnapshots deletes the snapshot staking information of given validator address
|
|
|
|
// deleteValidatorSnapshots deletes the snapshot staking information of given validator address
|
|
|
|
// TODO: delete validator snapshots from X epochs ago
|
|
|
|
// TODO: delete validator snapshots from X epochs ago
|
|
|
|
func (bc *BlockChain) deleteValidatorSnapshots(addrs []common.Address) error { |
|
|
|
// NOTE Use when needed but don't compile at all until then
|
|
|
|
batch := bc.db.NewBatch() |
|
|
|
// func (bc *BlockChain) deleteValidatorSnapshots(addrs []common.Address) error {
|
|
|
|
for i := range addrs { |
|
|
|
// batch := bc.db.NewBatch()
|
|
|
|
rawdb.DeleteValidatorSnapshot(batch, addrs[i], bc.CurrentBlock().Epoch()) |
|
|
|
// for i := range addrs {
|
|
|
|
} |
|
|
|
// rawdb.DeleteValidatorSnapshot(batch, addrs[i], bc.CurrentBlock().Epoch())
|
|
|
|
if err := batch.Write(); err != nil { |
|
|
|
// }
|
|
|
|
return err |
|
|
|
// if err := batch.Write(); err != nil {
|
|
|
|
} |
|
|
|
// return err
|
|
|
|
for i := range addrs { |
|
|
|
// }
|
|
|
|
bc.validatorCache.Remove("validator-snapshot-" + string(addrs[i].Bytes())) |
|
|
|
// for i := range addrs {
|
|
|
|
} |
|
|
|
// bc.validatorCache.Remove("validator-snapshot-" + string(addrs[i].Bytes()))
|
|
|
|
return nil |
|
|
|
// }
|
|
|
|
} |
|
|
|
// return nil
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// UpdateValidatorSnapshots updates the content snapshot of all validators
|
|
|
|
// UpdateValidatorSnapshots updates the content snapshot of all validators
|
|
|
|
// Note: this should only be called within the blockchain insert process.
|
|
|
|
// Note: this should only be called within the blockchain insert process.
|
|
|
|