-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP Exploring x/distribution cleanup #2599
Changes from 5 commits
e23054f
93d5437
33521b0
1143c93
c17f425
b97a076
99efde2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,8 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, percentVotes sdk.Dec, proposer s | |
// apply commission | ||
commission := proposerReward.MulDec(proposerValidator.GetCommission()) | ||
remaining := proposerReward.Minus(commission) | ||
proposerDist.PoolCommission = proposerDist.PoolCommission.Plus(commission) | ||
proposerDist.Pool = proposerDist.Pool.Plus(remaining) | ||
proposerDist.ValCommission = proposerDist.ValCommission.Plus(commission) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm - maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
proposerDist.DelPool = proposerDist.DelPool.Plus(remaining) | ||
|
||
// allocate community funding | ||
communityTax := k.GetCommunityTax(ctx) | ||
|
@@ -38,7 +38,7 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, percentVotes sdk.Dec, proposer s | |
|
||
// set the global pool within the distribution module | ||
poolReceived := feesCollectedDec.Minus(proposerReward).Minus(communityFunding) | ||
feePool.Pool = feePool.Pool.Plus(poolReceived) | ||
feePool.ValPool = feePool.ValPool.Plus(poolReceived) | ||
|
||
k.SetValidatorDistInfo(ctx, proposerDist) | ||
k.SetFeePool(ctx, feePool) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,48 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
) | ||
|
||
// Create a new validator distribution record | ||
func (k Keeper) onValidatorCreated(ctx sdk.Context, addr sdk.ValAddress) { | ||
func (k Keeper) onValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) { | ||
|
||
height := ctx.BlockHeight() | ||
vdi := types.ValidatorDistInfo{ | ||
OperatorAddr: addr, | ||
OperatorAddr: valAddr, | ||
FeePoolWithdrawalHeight: height, | ||
Pool: types.DecCoins{}, | ||
PoolCommission: types.DecCoins{}, | ||
DelAccum: types.NewTotalAccum(height), | ||
DelPool: types.DecCoins{}, | ||
ValCommission: types.DecCoins{}, | ||
} | ||
k.SetValidatorDistInfo(ctx, vdi) | ||
} | ||
|
||
// Withdrawal all validator rewards | ||
func (k Keeper) onValidatorModified(ctx sdk.Context, addr sdk.ValAddress) { | ||
func (k Keeper) onValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) { | ||
// This doesn't need to be run at genesis | ||
if ctx.BlockHeight() > 0 { | ||
if err := k.WithdrawValidatorRewardsAll(ctx, addr); err != nil { | ||
if err := k.WithdrawValidatorRewardsAll(ctx, valAddr); err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
// XXX Consider removing this after debugging. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can leave it if you like, it's a very cheap sanity check |
||
func (k Keeper) onValidatorPowerDidChange(ctx sdk.Context, valAddr sdk.ValAddress) { | ||
vi := k.GetValidatorDistInfo(ctx, valAddr) | ||
if vi.FeePoolWithdrawalHeight != ctx.BlockHeight() { | ||
fmt.Println(vi.OperatorAddr.String(), vi.FeePoolWithdrawalHeight, ctx.BlockHeight()) | ||
panic("DID NOT UPDATE") | ||
} | ||
} | ||
|
||
// Withdrawal all validator distribution rewards and cleanup the distribution record | ||
func (k Keeper) onValidatorRemoved(ctx sdk.Context, addr sdk.ValAddress) { | ||
k.RemoveValidatorDistInfo(ctx, addr) | ||
func (k Keeper) onValidatorRemoved(ctx sdk.Context, valAddr sdk.ValAddress) { | ||
k.RemoveValidatorDistInfo(ctx, valAddr) | ||
} | ||
|
||
//_________________________________________________________________________________________ | ||
|
@@ -41,9 +52,9 @@ func (k Keeper) onDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, | |
valAddr sdk.ValAddress) { | ||
|
||
ddi := types.DelegationDistInfo{ | ||
DelegatorAddr: delAddr, | ||
ValOperatorAddr: valAddr, | ||
WithdrawalHeight: ctx.BlockHeight(), | ||
DelegatorAddr: delAddr, | ||
ValOperatorAddr: valAddr, | ||
DelPoolWithdrawalHeight: ctx.BlockHeight(), | ||
} | ||
k.SetDelegationDistInfo(ctx, ddi) | ||
} | ||
|
@@ -77,14 +88,14 @@ var _ sdk.StakingHooks = Hooks{} | |
func (k Keeper) Hooks() Hooks { return Hooks{k} } | ||
|
||
// nolint | ||
func (h Hooks) OnValidatorCreated(ctx sdk.Context, addr sdk.ValAddress) { | ||
h.k.onValidatorCreated(ctx, addr) | ||
func (h Hooks) OnValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) { | ||
h.k.onValidatorCreated(ctx, valAddr) | ||
} | ||
func (h Hooks) OnValidatorModified(ctx sdk.Context, addr sdk.ValAddress) { | ||
h.k.onValidatorModified(ctx, addr) | ||
func (h Hooks) OnValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) { | ||
h.k.onValidatorModified(ctx, valAddr) | ||
} | ||
func (h Hooks) OnValidatorRemoved(ctx sdk.Context, addr sdk.ValAddress) { | ||
h.k.onValidatorRemoved(ctx, addr) | ||
func (h Hooks) OnValidatorRemoved(ctx sdk.Context, valAddr sdk.ValAddress) { | ||
h.k.onValidatorRemoved(ctx, valAddr) | ||
} | ||
func (h Hooks) OnDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) { | ||
h.k.onValidatorModified(ctx, valAddr) | ||
|
@@ -97,9 +108,12 @@ func (h Hooks) OnDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddres | |
func (h Hooks) OnDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) { | ||
h.k.onDelegationRemoved(ctx, delAddr, valAddr) | ||
} | ||
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, addr sdk.ValAddress) { | ||
h.k.onValidatorModified(ctx, addr) | ||
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) { | ||
h.k.onValidatorModified(ctx, valAddr) | ||
} | ||
func (h Hooks) OnValidatorBonded(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) { | ||
h.k.onValidatorModified(ctx, valAddr) | ||
} | ||
func (h Hooks) OnValidatorBonded(ctx sdk.Context, _ sdk.ConsAddress, addr sdk.ValAddress) { | ||
h.k.onValidatorModified(ctx, addr) | ||
func (h Hooks) OnValidatorPowerDidChange(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name is confusing to me - this gets called after the validator's power has changed I guess? |
||
h.k.onValidatorPowerDidChange(ctx, valAddr) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably revert this