Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Euler-5.1 #473

Merged
merged 6 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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