Skip to content

Commit

Permalink
Merge branch '446-module-triggers' into 0.1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cyborgshead committed Feb 4, 2020
2 parents 5fb24d4 + 991a9f3 commit aa0f47d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion x/bank/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type IndexedKeeper interface {

Load(sdk.Context, sdk.Context)

FixUserStake() bool
FixUserStake(ctx sdk.Context) bool
UpdateStake(cbd.AccNumber, int64)
GetTotalStakes() map[cbd.AccNumber]uint64
EndBlocker(sdk.Context)
Expand Down
14 changes: 13 additions & 1 deletion x/bank/internal/keeper/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/tendermint/tendermint/crypto"

cbd "github.com/cybercongress/cyberd/types"
)

Expand Down Expand Up @@ -51,7 +53,17 @@ func (s *IndexedKeeper) getCollectFunc(ctx sdk.Context, userStake map[cbd.AccNum
}

// return true if some stake changed
func (s *IndexedKeeper) FixUserStake() bool {
func (s *IndexedKeeper) FixUserStake(ctx sdk.Context) bool {

// Standalone changes of modules balance should not trigger a rank recalculation
modulesNames := [6]string{"bonded_tokens_pool", "not_bonded_tokens_pool", "gov", "distribution", "mint", "fee_collector"}
for _, name := range modulesNames {
supplyModuleAddress := sdk.AccAddress(crypto.AddressHash([]byte(name)))
supplyModuleAccount := s.accountKeeper.GetAccount(ctx, supplyModuleAddress)
supplyModuleAccountNumber := cbd.AccNumber(supplyModuleAccount.GetAccountNumber())
s.userTotalStake[supplyModuleAccountNumber] = s.userNewTotalStake[supplyModuleAccountNumber]
}

stakeChanged := false
for k, v := range s.userNewTotalStake {
if s.userTotalStake[k] != v {
Expand Down
2 changes: 1 addition & 1 deletion x/rank/internal/keeper/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (s *StateKeeper) EndBlocker(ctx sdk.Context, log log.Logger) {
s.applyNextRank()

s.cidCount = int64(currentCidsCount)
stakeChanged := s.stakeKeeper.FixUserStake()
stakeChanged := s.stakeKeeper.FixUserStake(ctx)

// start new calculation
if s.hasNewLinksForPeriod || stakeChanged {
Expand Down
2 changes: 1 addition & 1 deletion x/rank/internal/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type StakeKeeper interface {
FixUserStake() bool
FixUserStake(ctx sdk.Context) bool
GetTotalStakes() map[cbd.AccNumber]uint64
}

Expand Down

0 comments on commit aa0f47d

Please sign in to comment.