Skip to content

Commit

Permalink
Merge pull request #473 from cybercongress/0.1.5.1
Browse files Browse the repository at this point in the history
Euler-5.1
  • Loading branch information
cyborgshead committed Feb 26, 2020
2 parents a9f3ff2 + 878a4d3 commit 6b6ef6b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ func (app *CyberdApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDel
}

app.bandwidthMeter.AddToBlockBandwidth(app.bandwidthMeter.GetTxCost(ctx, tx))
app.bandwidthMeter.AddToOverallKarma(linkingCost)

return abci.ResponseDeliverTx{
Code: resp.GetCode(),
Expand Down
2 changes: 2 additions & 0 deletions x/bandwidth/internal/types/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type BandwidthMeter interface {
Load(ctx sdk.Context)
// add value to consumed bandwidth for current block
AddToBlockBandwidth(value int64)
// add value to overall linked bandwidth
AddToOverallKarma(value int64)
// adjust price based on 24h loading
AdjustPrice(ctx sdk.Context)
// get current bandwidth price
Expand Down
5 changes: 4 additions & 1 deletion x/bandwidth/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (m *BaseBandwidthMeter) AddToBlockBandwidth(value int64) {
m.curBlockSpentBandwidth += uint64(value)
}

func (m *BaseBandwidthMeter) AddToOverallKarma(value int64) {
m.bandwidthSpentLinking += uint64(value)
}

// Here we move bandwidth window:
// Remove first block of window and add new block to window end
func (m *BaseBandwidthMeter) CommitBlockBandwidth(ctx sdk.Context) {
Expand All @@ -87,7 +91,6 @@ func (m *BaseBandwidthMeter) CommitBlockBandwidth(ctx sdk.Context) {
}
m.blockBandwidthKeeper.SetBlockSpentBandwidth(ctx, uint64(ctx.BlockHeight()), m.curBlockSpentBandwidth)
m.bandwidthSpent[uint64(newWindowEnd)] = m.curBlockSpentBandwidth
m.bandwidthSpentLinking += m.curBlockSpentBandwidth
m.curBlockSpentBandwidth = 0
}

Expand Down
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
1 change: 1 addition & 0 deletions x/rank/internal/types/rank.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewRank(values []float64, logger log.Logger, fullTree bool) Rank {

newSortedCIDs := make(sortableCidNumbers, 0, len(values))
for cid, rank := range values {
if math.IsNaN(rank) { continue } // TODO remove this after rank's NaN fix
newRankedCid := RankedCidNumber{link.CidNumber(cid), rank}
newSortedCIDs = append(newSortedCIDs, newRankedCid)
}
Expand Down

0 comments on commit 6b6ef6b

Please sign in to comment.