Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2275 from bandprotocol/add-val-commission
Browse files Browse the repository at this point in the history
cdb: Add field accumulated_commission in validators table
  • Loading branch information
taobun committed Jul 22, 2020
1 parent c6adbe7 commit 6c38400
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion chain/emitter/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (app *App) BeginBlock(req abci.RequestBeginBlock) abci.ResponseBeginBlock {
"block_height": req.Header.GetHeight() - 1,
"voted": val.GetSignedLastBlock(),
})
app.emitUpdateValidatorReward(validator.GetOperator())
app.emitUpdateValidatorRewardAndAccumulatedCommission(validator.GetOperator())
}

for _, event := range res.Events {
Expand Down
12 changes: 11 additions & 1 deletion chain/emitter/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ func (app *App) getCurrentRewardAndCurrentRatio(addr sdk.ValAddress) (string, st
return currentReward, currentRatio
}

func (app *App) emitUpdateValidatorRewardAndAccumulatedCommission(addr sdk.ValAddress) {
currentReward, currentRatio := app.getCurrentRewardAndCurrentRatio(addr)
app.Write("UPDATE_VALIDATOR", JsDict{
"operator_address": addr.String(),
"current_reward": currentReward,
"current_ratio": currentRatio,
"accumulated_commission": app.DistrKeeper.GetValidatorAccumulatedCommission(app.DeliverContext, addr).String(),
})
}

func (app *App) emitUpdateValidatorReward(addr sdk.ValAddress) {
currentReward, currentRatio := app.getCurrentRewardAndCurrentRatio(addr)
app.Write("UPDATE_VALIDATOR", JsDict{
Expand Down Expand Up @@ -56,6 +66,6 @@ func (app *App) handleMsgWithdrawValidatorCommission(
) {
withdrawAddr := app.DistrKeeper.GetDelegatorWithdrawAddr(app.DeliverContext, sdk.AccAddress(msg.ValidatorAddress))
app.AddAccountsInTx(withdrawAddr)
app.emitUpdateValidatorReward(msg.ValidatorAddress)
app.emitUpdateValidatorRewardAndAccumulatedCommission(msg.ValidatorAddress)
extra["commission_amount"] = evMap[types.EventTypeWithdrawCommission+"."+sdk.AttributeKeyAmount][0]
}
35 changes: 18 additions & 17 deletions chain/emitter/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@ func (app *App) emitSetValidator(addr sdk.ValAddress) {
val, _ := app.StakingKeeper.GetValidator(app.DeliverContext, addr)
currentReward, currentRatio := app.getCurrentRewardAndCurrentRatio(addr)
app.Write("SET_VALIDATOR", JsDict{
"operator_address": addr.String(),
"delegator_address": sdk.AccAddress(addr).String(),
"consensus_address": sdk.ConsAddress(val.ConsPubKey.Address()).String(),
"consensus_pubkey": sdk.MustBech32ifyConsPub(val.ConsPubKey),
"moniker": val.Description.Moniker,
"identity": val.Description.Identity,
"website": val.Description.Website,
"details": val.Description.Details,
"commission_rate": val.Commission.Rate.String(),
"commission_max_rate": val.Commission.MaxRate.String(),
"commission_max_change": val.Commission.MaxChangeRate.String(),
"min_self_delegation": val.MinSelfDelegation.String(),
"tokens": val.Tokens.BigInt().Uint64(),
"jailed": val.Jailed,
"delegator_shares": val.DelegatorShares.String(),
"current_reward": currentReward,
"current_ratio": currentRatio,
"operator_address": addr.String(),
"delegator_address": sdk.AccAddress(addr).String(),
"consensus_address": sdk.ConsAddress(val.ConsPubKey.Address()).String(),
"consensus_pubkey": sdk.MustBech32ifyConsPub(val.ConsPubKey),
"moniker": val.Description.Moniker,
"identity": val.Description.Identity,
"website": val.Description.Website,
"details": val.Description.Details,
"commission_rate": val.Commission.Rate.String(),
"commission_max_rate": val.Commission.MaxRate.String(),
"commission_max_change": val.Commission.MaxChangeRate.String(),
"min_self_delegation": val.MinSelfDelegation.String(),
"tokens": val.Tokens.BigInt().Uint64(),
"jailed": val.Jailed,
"delegator_shares": val.DelegatorShares.String(),
"current_reward": currentReward,
"current_ratio": currentRatio,
"accumulated_commission": app.DistrKeeper.GetValidatorAccumulatedCommission(app.DeliverContext, addr).String(),
})
}

Expand Down
1 change: 1 addition & 0 deletions flusher/flusher/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def Column(*args, **kwargs):
Column("current_ratio", sa.DECIMAL),
Column("status", sa.Boolean, default=False),
Column("status_since", CustomDateTime, default=0),
Column("accumulated_commission", sa.String), # uband suffix
)

delegations = sa.Table(
Expand Down

0 comments on commit 6c38400

Please sign in to comment.