Skip to content

Commit

Permalink
Merge pull request #459 from cybercongress/447-overall-karma
Browse files Browse the repository at this point in the history
Fixed calculation of overall karma
  • Loading branch information
cyborgshead authored Feb 6, 2020
2 parents dd956f2 + 5fb24d4 commit 878a4d3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
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

0 comments on commit 878a4d3

Please sign in to comment.