Skip to content

Commit

Permalink
go tendermint staking: adjust total supply in runtime transfer
Browse files Browse the repository at this point in the history
We previously left the total supply inconsistent when transferring
tokens to/from a runtime. Fix that to adjust the total supply
accordingly when transferring.

It was also proposed to move these transferred tokens to/from
per-runtime holding areas for bookkeeping. That remains a good
idea.

It's proposed in #2377 to dismantle this whole runtime transfer
system. So with any luck, none of this will be used after all.
  • Loading branch information
pro-wh committed Dec 12, 2019
1 parent f748904 commit f321f9b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions go/consensus/tendermint/apps/staking/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,20 +723,36 @@ func (s *MutableState) HandleRoothashMessage(runtimeID signature.PublicKey, mess
return errors.Errorf("staking general adjustment message received from unacceptable runtime %s", runtimeID), nil
}

totalSupply, err := s.TotalSupply()
if err != nil {
return nil, errors.Wrap(err, "TotalSupply")
}
account := s.Account(message.StakingGeneralAdjustmentRoothashMessage.Account)

switch message.StakingGeneralAdjustmentRoothashMessage.Op {
case block.Increase:
err = account.General.Balance.Add(message.StakingGeneralAdjustmentRoothashMessage.Amount)
if err != nil {
return errors.Wrapf(err, "couldn't apply adjustment in staking general adjustment message"), nil
}
err = totalSupply.Add(message.StakingGeneralAdjustmentRoothashMessage.Amount)
if err != nil {
return errors.Wrapf(err, "couldn't adjust total supply in staking general adjustment message"), nil
}
case block.Decrease:
err = account.General.Balance.Sub(message.StakingGeneralAdjustmentRoothashMessage.Amount)
if err != nil {
return errors.Wrapf(err, "couldn't apply adjustment in staking general adjustment message"), nil
}
err = totalSupply.Sub(message.StakingGeneralAdjustmentRoothashMessage.Amount)
if err != nil {
return errors.Wrapf(err, "couldn't adjust total supply in staking general adjustment message"), nil
}
default:
return errors.Errorf("staking general adjustment message has invalid op"), nil
}
if err != nil {
return errors.Wrapf(err, "couldn't apply adjustment in staking general adjustment message"), nil
}

s.SetTotalSupply(totalSupply)
s.SetAccount(message.StakingGeneralAdjustmentRoothashMessage.Account, account)
logger.Debug("handled StakingGeneralAdjustmentRoothashMessage",
logging.LogEvent, staking.LogEventGeneralAdjustment,
Expand Down

0 comments on commit f321f9b

Please sign in to comment.