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

Implement fee handler function in AnteHandler, add default BurnFeeHandler #852

Merged
merged 6 commits into from
Apr 16, 2018

Conversation

cwgoes
Copy link
Contributor

@cwgoes cwgoes commented Apr 12, 2018

Ref #583 - this just implements the AccountMapper part of that issue.

@cwgoes cwgoes requested a review from ebuchman as a code owner April 12, 2018 11:04
@codecov
Copy link

codecov bot commented Apr 12, 2018

Codecov Report

Merging #852 into develop will increase coverage by 0.02%.
The diff coverage is 100%.

@@             Coverage Diff             @@
##           develop     #852      +/-   ##
===========================================
+ Coverage    65.45%   65.48%   +0.02%     
===========================================
  Files           67       67              
  Lines         3543     3546       +3     
===========================================
+ Hits          2319     2322       +3     
  Misses        1034     1034              
  Partials       190      190

@cwgoes cwgoes requested review from sunnya97 and rigelrozanski and removed request for ebuchman April 12, 2018 11:15
x/auth/ante.go Outdated
@@ -74,6 +74,9 @@ func NewAnteHandler(accountMapper sdk.AccountMapper) sdk.AnteHandler {
// TODO: min fee
if !fee.Amount.IsZero() {
signerAcc, res = deductFees(signerAcc, fee)
pool := accountMapper.GetFeePool(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of extending accountMapper in this way - I reckon we should keep accountMapper as is and have AnteHandler take a new type of keeper (which can be defined in /types) which the stake module will define. The AnteHandler can have an additional function input say "FeeHandler" has a method HandleFees(ctx, fee coin.Coins) which actually performs the movement of the fees. HandleFees could be called right here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah then the reserve tax can be implemented as a part of HandleFees too

Copy link
Contributor Author

@cwgoes cwgoes Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nice part about this implementation is that it's cheap (one read, one write) and complex fee redistribution can be performed later in a batch at the end of the block - but I'll implement that option in another PR, then we can see which we like best.

Copy link
Contributor

@rigelrozanski rigelrozanski Apr 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I mean it's actually not cheap because now we need to handle the fees twice, first to write to this pool then a second time to digest. I'd like us to tackle both simultaneously - it's important to optimize here as it's every block that these operations are called

Copy link
Contributor Author

@cwgoes cwgoes Apr 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, according to https://cosmos.network/whitepaper fees are redistributed every ValidatorPayoutPeriod (default 1 hour), so it seems like we don't need to do that every block?

Even if we did redistribute every block instead, any implementation not writing to intermediary state (which could be in the AccountMapper, or not) would have to redistribute every transaction, which seems like it would be very inefficient (read/write all the bonded stakeholder bond values and accounts)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rigelrozanski what do you mean by "digest"?

Copy link
Contributor

@rigelrozanski rigelrozanski Apr 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sunnya97 apologies for the vague language - yeah digest = process the fee pool for the the proposer as outlined in the spec - https://github.com/cosmos/cosmos-sdk/blob/master/docs/spec/staking/old/spec2.md#fee-calculations

@cwgoes Also, due to technical reasons we must vear from the whitepaper proposed hourly distribution. Talked with Jae about this before - is OK. But yeah digest doesn't mean we're "distributing" to the validators we're calculating how the "feepool shares" ought to be modified for the proposer validator - this calculation is dependant on the fees collected in each block/digest. So yeah, the staking fee calculation actually needs access to what each incoming fee is - if it only has access to the pool in this current implementation, it would actually need to keep a second copy of the pool to calculate the difference, which is totally nuts when we could just do it all at once

@cwgoes cwgoes changed the title Implement fee pool pseudo-account in sdk.AccountMapper Add feeHandler function to AnteHandler Apr 16, 2018
@cwgoes cwgoes dismissed rigelrozanski’s stale review April 16, 2018 12:17

Refactored to feeHandler

@@ -60,6 +63,9 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp {
&types.AppAccount{}, // prototype
).Seal()

// Define the feeHandler.
app.feeHandler = func(ctx sdk.Context, fees sdk.Coins) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be defined below coinKeeper? Would be nice to have the Tx too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the function body would reference coinKeeper as a closure. Same with democoin.

@cwgoes
Copy link
Contributor Author

cwgoes commented Apr 16, 2018

Updated per comments

@@ -75,6 +72,9 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp {
AddRoute("ibc", ibc.NewHandler(ibcMapper, coinKeeper)).
AddRoute("simplestake", simplestake.NewHandler(stakeKeeper))

// Define the feeHandler.
app.feeHandler = func(ctx sdk.Context, tx sdk.Tx, fees sdk.Coins) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs implementation or a new Issue, same with democoin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will be implemented by the stake module, I guess this PR can just wait for that, no reason to merge beforehand

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't wait to merge this for staking implementation - let's add a basic "burn the fees" implementation of feeHandler as a part of this PR and merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what this does at the moment (the fees are burned and the total supply is decreased).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want the handler to do something else (log the burn somehow)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah I think that's fine - will review one last time and then merge soon unless something comes up

@cwgoes cwgoes changed the title Add feeHandler function to AnteHandler WIP: Staking fee implementation Apr 16, 2018
@@ -12,6 +12,9 @@ import (
wire "github.com/cosmos/cosmos-sdk/wire"
)

func nopFeeHandler(ctx sdk.Context, tx sdk.Tx, fee sdk.Coins) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does nop stand for? Why not call it BurnFeeHandler and have the apps and other examples import it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, renamed BurnFeeHandler, basecoin & democoin now import

@cwgoes cwgoes changed the title WIP: Staking fee implementation Implement fee handler function in AnteHandler, add default BurnFeeHandler Apr 16, 2018
@cwgoes cwgoes merged commit 0f2aa6b into develop Apr 16, 2018
@cwgoes cwgoes deleted the cwgoes/fee-account branch April 16, 2018 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants