working compile errors
This commit is contained in:
parent
df9c8db5e7
commit
d9396ed732
|
@ -68,7 +68,7 @@ type ValidatorSet interface {
|
|||
func(index int64, validator Validator) (stop bool))
|
||||
|
||||
Validator(Context, ValAddress) Validator // get a particular validator by operator
|
||||
ValidatorByPubKey(Context, crypto.PubKey) Validator // get a particular validator by signing PubKey
|
||||
ValidatorByConsAddr(Context, ConsAddress) Validator // get a particular validator by consensus address
|
||||
TotalPower(Context) Dec // total power of the validator set
|
||||
|
||||
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
|
||||
|
|
|
@ -93,7 +93,7 @@ func (coins DecCoins) Plus(coinsB DecCoins) DecCoins {
|
|||
func (coins DecCoins) Mul(multiple sdk.Dec) DecCoins {
|
||||
products := make([]DecCoin, len(coins))
|
||||
for i, coin := range coins {
|
||||
product := DecCoins{
|
||||
product := DecCoin{
|
||||
Denom: coin.Denom,
|
||||
Amount: coin.Amount.Mul(multiple),
|
||||
}
|
||||
|
|
|
@ -15,15 +15,15 @@ func (di DelegatorDistInfo) WithdrawRewards(fp FeePool, vi ValidatorDistInfo,
|
|||
commissionRate sdk.Dec) (DelegatorDistInfo, FeePool, DecCoins) {
|
||||
|
||||
vi.UpdateTotalDelAccum(height, totalDelShares)
|
||||
fp = vi.TakeFeePoolRewards(fp, height, totalBonded, vdTokens, commissionRate)
|
||||
vi, fp = vi.TakeFeePoolRewards(fp, height, totalBonded, vdTokens, commissionRate)
|
||||
|
||||
blocks = height - di.WithdrawalHeight
|
||||
blocks := height - di.WithdrawalHeight
|
||||
di.WithdrawalHeight = height
|
||||
accum := delegatorShares.Mul(sdk.NewDec(blocks))
|
||||
withdrawalTokens := vi.Pool.Mul(accum.Quo(vi.TotalDelAccum))
|
||||
withdrawalTokens := vi.Pool.Mul(accum.Quo(vi.DelAccum.Accum))
|
||||
|
||||
vi.Pool = vi.Pool.Sub(withdrawalTokens)
|
||||
vi.TotalDelAccum = vi.TotalDelAccum.sub(accum)
|
||||
vi.DelAccum.Accum = vi.DelAccum.Accum.Sub(accum)
|
||||
|
||||
return di, fp, withdrawalTokens
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ func NewTotalAccum(height int64) TotalAccum {
|
|||
// update total validator accumulation factor
|
||||
func (ta TotalAccum) Update(height int64, accumCreatedPerBlock sdk.Dec) TotalAccum {
|
||||
blocks := height - ta.UpdateHeight
|
||||
f.Accum = f.Accum.Add(accumCreatedPerBlock.Mul(sdk.NewDec(blocks)))
|
||||
ta.Accum = ta.Accum.Add(accumCreatedPerBlock.Mul(sdk.NewDec(blocks)))
|
||||
ta.UpdateHeight = height
|
||||
return ta
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func (f FeePool) UpdateTotalValAccum(height int64, totalBondedTokens sdk.Dec) Fe
|
|||
// zero fee pool
|
||||
func InitialFeePool() FeePool {
|
||||
return FeePool{
|
||||
ValAccum: NewwTotalAccum(0),
|
||||
ValAccum: NewTotalAccum(0),
|
||||
Pool: DecCoins{},
|
||||
CommunityPool: DecCoins{},
|
||||
}
|
||||
|
|
|
@ -24,19 +24,20 @@ func (vi ValidatorDistInfo) UpdateTotalDelAccum(height int64, totalDelShares sdk
|
|||
func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBonded, vdTokens,
|
||||
commissionRate sdk.Dec) (ValidatorDistInfo, FeePool) {
|
||||
|
||||
fp.UpdateTotalValAccum(height, totalBondedShares)
|
||||
fp.UpdateTotalValAccum(height, totalBonded)
|
||||
|
||||
// update the validators pool
|
||||
blocks = height - vi.FeePoolWithdrawalHeight
|
||||
blocks := height - vi.FeePoolWithdrawalHeight
|
||||
vi.FeePoolWithdrawalHeight = height
|
||||
accum = sdk.NewDec(blocks).Mul(vdTokens)
|
||||
withdrawalTokens := fp.Pool.Mul(accum).Quo(fp.TotalValAccum)
|
||||
accum := sdk.NewDec(blocks).Mul(vdTokens)
|
||||
withdrawalTokens := fp.Pool.Mul(accum.Quo(fp.ValAccum.Accum))
|
||||
commission := withdrawalTokens.Mul(commissionRate)
|
||||
afterCommission := withdrawalTokens.Sub(commission)
|
||||
|
||||
fp.TotalValAccum = fp.TotalValAccum.Sub(accum)
|
||||
fp.ValAccum.Accum = fp.ValAccum.Accum.Sub(accum)
|
||||
fp.Pool = fp.Pool.Sub(withdrawalTokens)
|
||||
vi.PoolCommission = vi.PoolCommission.Add(commission)
|
||||
vi.PoolCommissionFree = vi.PoolCommissionFree.Add(withdrawalTokens.Sub(commission))
|
||||
vi.Pool = vi.Pool.Add(afterCommission)
|
||||
|
||||
return vi, fp
|
||||
}
|
||||
|
@ -45,10 +46,10 @@ func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBo
|
|||
func (vi ValidatorDistInfo) WithdrawCommission(fp FeePool, height int64,
|
||||
totalBonded, vdTokens, commissionRate sdk.Dec) (vio ValidatorDistInfo, fpo FeePool, withdrawn DecCoins) {
|
||||
|
||||
fp = vi.TakeFeePoolRewards(fp, height, totalBonded, vdTokens, commissionRate)
|
||||
vi, fp = vi.TakeFeePoolRewards(fp, height, totalBonded, vdTokens, commissionRate)
|
||||
|
||||
withdrawalTokens := vi.PoolCommission
|
||||
vi.PoolCommission = 0
|
||||
vi.PoolCommission = DecCoins{} // zero
|
||||
|
||||
return vi, fp, withdrawalTokens
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res [
|
|||
}
|
||||
|
||||
// Manually set indexes for the first time
|
||||
keeper.SetValidatorByPubKeyIndex(ctx, validator)
|
||||
keeper.SetValidatorByConsAddr(ctx, validator)
|
||||
keeper.SetValidatorByPowerIndex(ctx, validator, data.Pool)
|
||||
|
||||
if validator.Status == sdk.Bonded {
|
||||
|
|
|
@ -68,7 +68,7 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
|
|||
if found {
|
||||
return ErrValidatorOwnerExists(k.Codespace()).Result()
|
||||
}
|
||||
_, found = k.GetValidatorByPubKey(ctx, msg.PubKey)
|
||||
_, found = k.GetValidatorByConsAddr(ctx, sdk.ConsAddress(msg.PubKey.Address()))
|
||||
if found {
|
||||
return ErrValidatorPubKeyExists(k.Codespace()).Result()
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
|
|||
|
||||
validator := NewValidator(msg.ValidatorAddr, msg.PubKey, msg.Description)
|
||||
k.SetValidator(ctx, validator)
|
||||
k.SetValidatorByPubKeyIndex(ctx, validator)
|
||||
k.SetValidatorByConsAddr(ctx, validator)
|
||||
|
||||
// move coins from the msg.Address account to a (self-delegation) delegator account
|
||||
// the validator account and global shares are updated within here
|
||||
|
@ -88,10 +88,10 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
|
|||
}
|
||||
|
||||
// call the hook if present
|
||||
if k.validatorHooks != nil {
|
||||
k.validatorHooks.OnValidatorCreated(ctx, validator.OperatorAddr)
|
||||
accAddr := sdk.AccAddress{validator.OperatorAddr}
|
||||
k.validatorHooks.OnDelegationCreated(ctx, accAddr, validator.OperatorAddr)
|
||||
if k.hooks != nil {
|
||||
k.hooks.OnValidatorCreated(ctx, validator.OperatorAddr)
|
||||
accAddr := sdk.AccAddress(validator.OperatorAddr)
|
||||
k.hooks.OnDelegationCreated(ctx, accAddr, validator.OperatorAddr)
|
||||
}
|
||||
|
||||
tags := sdk.NewTags(
|
||||
|
@ -154,8 +154,8 @@ func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper)
|
|||
}
|
||||
|
||||
// call the hook if present
|
||||
if k.validatorHooks != nil {
|
||||
k.validatorHooks.OnDelegationCreated(ctx, msg.DelegatorAddr, validator.OperatorAddr)
|
||||
if k.hooks != nil {
|
||||
k.hooks.OnDelegationCreated(ctx, msg.DelegatorAddr, validator.OperatorAddr)
|
||||
}
|
||||
|
||||
tags := sdk.NewTags(
|
||||
|
|
|
@ -57,24 +57,6 @@ func (k Keeper) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddres
|
|||
return delegations[:i] // trim if the array length < maxRetrieve
|
||||
}
|
||||
|
||||
// iterate through all of the delegations from a delegator
|
||||
func (k Keeper) IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress,
|
||||
fn func(index int64, del types.Delegation) (stop bool)) {
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := GetDelegationsKey(delAddr)
|
||||
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) //smallest to largest
|
||||
for i := int64(0); iterator.Valid(); iterator.Next() {
|
||||
del := types.MustUnmarshalDelegation(k.cdc, iterator.Key(), iterator.Value())
|
||||
stop := fn(i, del)
|
||||
if stop {
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
iterator.Close()
|
||||
}
|
||||
|
||||
// set the delegation
|
||||
func (k Keeper) SetDelegation(ctx sdk.Context, delegation types.Delegation) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
|
|
|
@ -92,3 +92,21 @@ func (k Keeper) Delegation(ctx sdk.Context, addrDel sdk.AccAddress, addrVal sdk.
|
|||
|
||||
return bond
|
||||
}
|
||||
|
||||
// iterate through all of the delegations from a delegator
|
||||
func (k Keeper) IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress,
|
||||
fn func(index int64, del sdk.Delegation) (stop bool)) {
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := GetDelegationsKey(delAddr)
|
||||
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) //smallest to largest
|
||||
for i := int64(0); iterator.Valid(); iterator.Next() {
|
||||
del := types.MustUnmarshalDelegation(k.cdc, iterator.Key(), iterator.Value())
|
||||
stop := fn(i, del)
|
||||
if stop {
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
iterator.Close()
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in
|
|||
// ref https://github.com/cosmos/cosmos-sdk/issues/1348
|
||||
// ref https://github.com/cosmos/cosmos-sdk/issues/1471
|
||||
|
||||
validator, found := k.GetValidatorByPubKey(ctx, pubkey)
|
||||
validator, found := k.GetValidatorByConsAddr(ctx, sdk.ConsAddress(pubkey.Address()))
|
||||
if !found {
|
||||
// If not found, the validator must have been overslashed and removed - so we don't need to do anything
|
||||
// NOTE: Correctness dependent on invariant that unbonding delegations / redelegations must also have been completely
|
||||
|
@ -152,7 +152,7 @@ func (k Keeper) Unjail(ctx sdk.Context, pubkey crypto.PubKey) {
|
|||
|
||||
// set the jailed flag on a validator
|
||||
func (k Keeper) setJailed(ctx sdk.Context, pubkey crypto.PubKey, isJailed bool) {
|
||||
validator, found := k.GetValidatorByPubKey(ctx, pubkey)
|
||||
validator, found := k.GetValidatorByConsAddr(ctx, sdk.ConsAddress(pubkey.Address()))
|
||||
if !found {
|
||||
panic(fmt.Errorf("validator with pubkey %s not found, cannot set jailed to %v", pubkey, isJailed))
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ func (k Keeper) SetValidator(ctx sdk.Context, validator types.Validator) {
|
|||
// validator index
|
||||
func (k Keeper) SetValidatorByConsAddr(ctx sdk.Context, validator types.Validator) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
consAddr := sdk.ConsAddress{validator.OperatorAddr.Bytes()}
|
||||
consAddr := sdk.ConsAddress(validator.OperatorAddr.Bytes())
|
||||
store.Set(GetValidatorByConsAddrKey(consAddr), validator.OperatorAddr)
|
||||
}
|
||||
|
||||
|
@ -683,7 +683,7 @@ func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.ValAddress) {
|
|||
store := ctx.KVStore(k.storeKey)
|
||||
pool := k.GetPool(ctx)
|
||||
store.Delete(GetValidatorKey(address))
|
||||
store.Delete(GetValidatorByConsAddrKey(sdk.ConsAddr{validator.ConsPubKey.Address()}))
|
||||
store.Delete(GetValidatorByConsAddrKey(sdk.ConsAddress(validator.ConsPubKey.Address())))
|
||||
store.Delete(GetValidatorsByPowerIndexKey(validator, pool))
|
||||
|
||||
// delete from the current and power weighted validator groups if the validator
|
||||
|
@ -738,14 +738,13 @@ func ensureValidatorFound(found bool, ownerAddr []byte) {
|
|||
// XXX remove this code - this is should be superceded by commission work that bez is doing
|
||||
// get a single validator
|
||||
func (k Keeper) UpdateValidatorCommission(ctx sdk.Context, addr sdk.ValAddress, newCommission sdk.Dec) sdk.Error {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
|
||||
// call the hook if present
|
||||
if k.hooks != nil {
|
||||
k.hooks.OnValidatorCommissionChange(ctx, validator.OperatorAddr)
|
||||
k.hooks.OnValidatorCommissionChange(ctx, addr)
|
||||
}
|
||||
|
||||
validator, found := k.GetValidator(addr)
|
||||
validator, found := k.GetValidator(ctx, addr)
|
||||
|
||||
// check for errors
|
||||
switch {
|
||||
|
@ -763,6 +762,6 @@ func (k Keeper) UpdateValidatorCommission(ctx sdk.Context, addr sdk.ValAddress,
|
|||
|
||||
validator.Commission = newCommission
|
||||
|
||||
k.SetValidator(addr, validator)
|
||||
k.SetValidator(ctx, validator)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ var (
|
|||
NewKeeper = keeper.NewKeeper
|
||||
|
||||
GetValidatorKey = keeper.GetValidatorKey
|
||||
GetValidatorByPubKeyIndexKey = keeper.GetValidatorByPubKeyIndexKey
|
||||
GetValidatorByConsAddrKey = keeper.GetValidatorByConsAddrKey
|
||||
GetValidatorsBondedIndexKey = keeper.GetValidatorsBondedIndexKey
|
||||
GetValidatorsByPowerIndexKey = keeper.GetValidatorsByPowerIndexKey
|
||||
GetTendermintUpdatesTKey = keeper.GetTendermintUpdatesTKey
|
||||
|
@ -44,7 +44,7 @@ var (
|
|||
ParamKey = keeper.ParamKey
|
||||
PoolKey = keeper.PoolKey
|
||||
ValidatorsKey = keeper.ValidatorsKey
|
||||
ValidatorsByPubKeyIndexKey = keeper.ValidatorsByPubKeyIndexKey
|
||||
ValidatorsByConsAddrKey = keeper.ValidatorsByConsAddrKey
|
||||
ValidatorsBondedIndexKey = keeper.ValidatorsBondedIndexKey
|
||||
ValidatorsByPowerIndexKey = keeper.ValidatorsByPowerIndexKey
|
||||
ValidatorCliffIndexKey = keeper.ValidatorCliffIndexKey
|
||||
|
|
Loading…
Reference in New Issue