-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
Codecov Report
@@ 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 |
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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
85c3a0b
to
7fafa9e
Compare
examples/basecoin/app/app.go
Outdated
@@ -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) {} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Updated per comments |
examples/basecoin/app/app.go
Outdated
@@ -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) {} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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
x/auth/ante_test.go
Outdated
@@ -12,6 +12,9 @@ import ( | |||
wire "github.com/cosmos/cosmos-sdk/wire" | |||
) | |||
|
|||
func nopFeeHandler(ctx sdk.Context, tx sdk.Tx, fee sdk.Coins) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Ref #583 - this just implements the AccountMapper part of that issue.