[quorum] Staked quorum member (#1819)
* [quorum] Factor out single vote & provide for staked quorum vote * [quorum] Pass ShardID to decider via cb * [quorum] Move ShardIDProvider higher, fix nil mistake * [quorum] ReadAllSignatures optimization * [quorum] Safer way to read over map, then to slice * [quorum] Address PR comments - naming changespull/1821/head
parent
e6a4fbea4f
commit
55c9386e4c
@ -0,0 +1,78 @@ |
||||
package quorum |
||||
|
||||
import ( |
||||
"math/big" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/harmony-one/bls/ffi/go/bls" |
||||
common2 "github.com/harmony-one/harmony/internal/common" |
||||
"github.com/harmony-one/harmony/internal/utils" |
||||
// "github.com/harmony-one/harmony/staking/effective"
|
||||
) |
||||
|
||||
type uniformVoteWeight struct { |
||||
SignatureReader |
||||
DependencyInjectionWriter |
||||
} |
||||
|
||||
// Policy ..
|
||||
func (v *uniformVoteWeight) Policy() Policy { |
||||
return SuperMajorityVote |
||||
} |
||||
|
||||
// func (v *uniformVoteWeight) SetShardIDProvider(p func() (uint32, error)) {
|
||||
// v.p = p
|
||||
// }
|
||||
|
||||
// IsQuorumAchieved ..
|
||||
func (v *uniformVoteWeight) IsQuorumAchieved(p Phase) bool { |
||||
r := v.SignersCount(p) >= v.QuorumThreshold().Int64() |
||||
utils.Logger().Info().Str("phase", p.String()). |
||||
Int64("signers-count", v.SignersCount(p)). |
||||
Int64("threshold", v.QuorumThreshold().Int64()). |
||||
Int64("participants", v.ParticipantsCount()). |
||||
Msg("Quorum details") |
||||
return r |
||||
} |
||||
|
||||
// QuorumThreshold ..
|
||||
func (v *uniformVoteWeight) QuorumThreshold() *big.Int { |
||||
return big.NewInt(v.ParticipantsCount()*2/3 + 1) |
||||
} |
||||
|
||||
// RewardThreshold ..
|
||||
func (v *uniformVoteWeight) IsRewardThresholdAchieved() bool { |
||||
return v.SignersCount(Commit) >= (v.ParticipantsCount() * 9 / 10) |
||||
} |
||||
|
||||
// func (v *uniformVoteWeight) UpdateVotingPower(effective.StakeKeeper) {
|
||||
// NO-OP do not add anything here
|
||||
// }
|
||||
|
||||
// ToggleActive for uniform vote is a no-op, always says that voter is active
|
||||
func (v *uniformVoteWeight) ToggleActive(*bls.PublicKey) bool { |
||||
// NO-OP do not add anything here
|
||||
return true |
||||
} |
||||
|
||||
// Award ..
|
||||
func (v *uniformVoteWeight) Award( |
||||
// Here hook is the callback which gets the amount the earner is due in just reward
|
||||
// up to the hook to do side-effects like write the statedb
|
||||
Pie *big.Int, earners []common2.Address, hook func(earner common.Address, due *big.Int), |
||||
) *big.Int { |
||||
payout := big.NewInt(0) |
||||
last := big.NewInt(0) |
||||
count := big.NewInt(int64(len(earners))) |
||||
|
||||
for i, account := range earners { |
||||
cur := big.NewInt(0) |
||||
cur.Mul(Pie, big.NewInt(int64(i+1))).Div(cur, count) |
||||
diff := big.NewInt(0).Sub(cur, last) |
||||
hook(common.Address(account), diff) |
||||
payout = big.NewInt(0).Add(payout, diff) |
||||
last = cur |
||||
} |
||||
|
||||
return payout |
||||
} |
@ -0,0 +1,75 @@ |
||||
package quorum |
||||
|
||||
import ( |
||||
"math/big" |
||||
|
||||
"github.com/harmony-one/bls/ffi/go/bls" |
||||
"github.com/harmony-one/harmony/internal/common" |
||||
"github.com/harmony-one/harmony/numeric" |
||||
"github.com/harmony-one/harmony/shard" |
||||
) |
||||
|
||||
var ( |
||||
twoThirds = numeric.NewDec(2).QuoInt64(3).Int |
||||
) |
||||
|
||||
type stakedVoter struct { |
||||
isActive, isHarmonyNode bool |
||||
effective numeric.Dec |
||||
} |
||||
|
||||
type stakedVoteWeight struct { |
||||
SignatureReader |
||||
DependencyInjectionWriter |
||||
// EPOS based staking
|
||||
validatorStakes map[[shard.PublicKeySizeInBytes]byte]stakedVoter |
||||
totalEffectiveStakedAmount *big.Int |
||||
} |
||||
|
||||
// Policy ..
|
||||
func (v *stakedVoteWeight) Policy() Policy { |
||||
return SuperMajorityStake |
||||
} |
||||
|
||||
// We must maintain 2/3 quoroum, so whatever is 2/3 staked amount,
|
||||
// we divide that out & you
|
||||
// IsQuorumAchieved ..
|
||||
func (v *stakedVoteWeight) IsQuorumAchieved(p Phase) bool { |
||||
// TODO Implement this logic
|
||||
return true |
||||
} |
||||
|
||||
// QuorumThreshold ..
|
||||
func (v *stakedVoteWeight) QuorumThreshold() *big.Int { |
||||
return new(big.Int).Mul(v.totalEffectiveStakedAmount, twoThirds) |
||||
} |
||||
|
||||
// RewardThreshold ..
|
||||
func (v *stakedVoteWeight) IsRewardThresholdAchieved() bool { |
||||
// TODO Implement
|
||||
return false |
||||
} |
||||
|
||||
// HACK
|
||||
var ( |
||||
hSentinel = big.NewInt(0) |
||||
hEffectiveSentinel = numeric.ZeroDec() |
||||
) |
||||
|
||||
// Award ..
|
||||
func (v *stakedVoteWeight) Award( |
||||
Pie *big.Int, earners []common.Address, hook func(earner common.Address, due *big.Int), |
||||
) *big.Int { |
||||
// TODO Implement
|
||||
return nil |
||||
} |
||||
|
||||
// UpdateVotingPower called only at epoch change, prob need to move to CalculateShardState
|
||||
// func (v *stakedVoteWeight) UpdateVotingPower(keeper effective.StakeKeeper) {
|
||||
// TODO Implement
|
||||
// }
|
||||
|
||||
func (v *stakedVoteWeight) ToggleActive(*bls.PublicKey) bool { |
||||
// TODO Implement
|
||||
return true |
||||
} |
Loading…
Reference in new issue