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 #2273 from bandprotocol/fix-bug-withdraw-reward
Browse files Browse the repository at this point in the history
cdb: Fix bug update delegators table after withdraw reward
  • Loading branch information
taobun authored Jul 20, 2020
2 parents 686b525 + 551bab6 commit 0361e84
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

### Emitter & Flusher

- (bugs) [\#2273](https://github.com/bandprotocol/bandchain/pull/2273) Fix bug update delegators table after withdraw reward.
- (bugs) [\#2255](https://github.com/bandprotocol/bandchain/pull/2255) Fix bug `reward_amount` and `commission_amount` in extra field.
- (bugs) [\#2252](https://github.com/bandprotocol/bandchain/pull/2252) `handle_set_validator` get wrong validator id.
- (impv) [\#2250](https://github.com/bandprotocol/bandchain/pull/2250) Add account id in `validators` table.
Expand Down
1 change: 1 addition & 0 deletions chain/emitter/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (app *App) handleMsgWithdrawDelegatorReward(
withdrawAddr := app.DistrKeeper.GetDelegatorWithdrawAddr(app.DeliverContext, msg.DelegatorAddress)
app.AddAccountsInTx(withdrawAddr)
app.emitUpdateValidatorReward(msg.ValidatorAddress)
app.emitDelegationAfterWithdrawReward(msg.ValidatorAddress, withdrawAddr)
extra["reward_amount"] = evMap[dist.EventTypeWithdrawRewards+"."+sdk.AttributeKeyAmount][0]
}

Expand Down
9 changes: 9 additions & 0 deletions chain/emitter/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func (app *App) emitUpdateValidatorStatus(addr sdk.ValAddress) {
})
}

func (app *App) emitDelegationAfterWithdrawReward(operatorAddress sdk.ValAddress, delegatorAddress sdk.AccAddress) {
_, ratio := app.getCurrentRewardAndCurrentRatio(operatorAddress)
app.Write("UPDATE_DELEGATION", JsDict{
"delegator_address": delegatorAddress,
"operator_address": operatorAddress,
"last_ratio": ratio,
})
}

func (app *App) emitDelegation(operatorAddress sdk.ValAddress, delegatorAddress sdk.AccAddress) {
delegation, found := app.StakingKeeper.GetDelegation(app.DeliverContext, delegatorAddress, operatorAddress)
if found {
Expand Down
10 changes: 10 additions & 0 deletions flusher/flusher/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ def handle_set_delegation(self, msg):
.on_conflict_do_update(constraint="delegations_pkey", set_=msg)
)

def handle_update_delegation(self, msg):
msg["delegator_id"] = self.get_account_id(msg["delegator_address"])
del msg["delegator_address"]
msg["validator_id"] = self.get_validator_id(msg["operator_address"])
del msg["operator_address"]
condition = True
for col in delegations.primary_key.columns.values():
condition = (col == msg[col.name]) & condition
self.conn.execute(delegations.update().where(condition).values(**msg))

def handle_remove_delegation(self, msg):
msg["delegator_id"] = self.get_account_id(msg["delegator_address"])
del msg["delegator_address"]
Expand Down

0 comments on commit 0361e84

Please sign in to comment.