|
|
@ -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,45 +2373,55 @@ 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") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := rawdb.WriteValidatorStats( |
|
|
|
snapshot, err := bc.ReadValidatorSnapshotAtEpoch( |
|
|
|
batch, key, stats, |
|
|
|
currentEpochSuperCommittee.Epoch, wrapper.Address, |
|
|
|
); err != nil { |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
existing, replacing := |
|
|
|
computed := availability.ComputeCurrentSigning(snapshot, wrapper) |
|
|
|
currentEpochSuperCommittee.StakedValidators(), |
|
|
|
|
|
|
|
newEpochSuperCommittee.StakedValidators() |
|
|
|
if _, wasBooted := bootedFromSuperCommittee[wrapper.Address]; wasBooted { |
|
|
|
for currentValidator := range existing.LookupSet { |
|
|
|
stats.BootedStatus = effective.LostEPoSAuction |
|
|
|
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 |
|
|
|
if computed.IsBelowThreshold { |
|
|
|
} |
|
|
|
stats.BootedStatus = effective.InsufficientUptimeDuringEpoch |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// deleteValidatorSnapshots deletes the snapshot staking information of given validator address
|
|
|
|
if slash.IsBanned(wrapper) { |
|
|
|
// TODO: delete validator snapshots from X epochs ago
|
|
|
|
stats.BootedStatus = effective.BannedForDoubleSigning |
|
|
|
func (bc *BlockChain) deleteValidatorSnapshots(addrs []common.Address) error { |
|
|
|
|
|
|
|
batch := bc.db.NewBatch() |
|
|
|
|
|
|
|
for i := range addrs { |
|
|
|
|
|
|
|
rawdb.DeleteValidatorSnapshot(batch, addrs[i], bc.CurrentBlock().Epoch()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if err := batch.Write(); err != nil { |
|
|
|
|
|
|
|
|
|
|
|
if err := rawdb.WriteValidatorStats( |
|
|
|
|
|
|
|
batch, key, stats, |
|
|
|
|
|
|
|
); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
for i := range addrs { |
|
|
|
|
|
|
|
bc.validatorCache.Remove("validator-snapshot-" + string(addrs[i].Bytes())) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// deleteValidatorSnapshots deletes the snapshot staking information of given validator address
|
|
|
|
|
|
|
|
// TODO: delete validator snapshots from X epochs ago
|
|
|
|
|
|
|
|
// NOTE Use when needed but don't compile at all until then
|
|
|
|
|
|
|
|
// func (bc *BlockChain) deleteValidatorSnapshots(addrs []common.Address) error {
|
|
|
|
|
|
|
|
// batch := bc.db.NewBatch()
|
|
|
|
|
|
|
|
// for i := range addrs {
|
|
|
|
|
|
|
|
// rawdb.DeleteValidatorSnapshot(batch, addrs[i], bc.CurrentBlock().Epoch())
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if err := batch.Write(); err != nil {
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// for i := range addrs {
|
|
|
|
|
|
|
|
// bc.validatorCache.Remove("validator-snapshot-" + string(addrs[i].Bytes()))
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
func (bc *BlockChain) UpdateValidatorSnapshots( |
|
|
|
func (bc *BlockChain) UpdateValidatorSnapshots( |
|
|
|