-
Notifications
You must be signed in to change notification settings - Fork 107
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
feat(wardend): burn 30% of the tx fee #85
base: main
Are you sure you want to change the base?
Conversation
This PR should be merged after warden-protocol/snapshots#1 |
SignModeHandler: in.TxConfig.SignModeHandler(), | ||
FeegrantKeeper: in.FeeGrantKeeper, | ||
SigGasConsumer: authante.DefaultSigVerificationGasConsumer, | ||
FeeBurnRatio: math.LegacyNewDecWithPrec(3, 1), // 30% |
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.
Do you know if we can get this number from the modules Params structure? This way it can get updated via governance proposals
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, we definitely can. Good point, I'll implement it.
Did you consider implementing this feature as a BeginBlocker instead of an AnteHandler? Do you know if there are limitations to one or the other possible implementations? |
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 consider implementing this feature as a BeginBlocker instead of an AnteHandler? Do you know if there are limitations to one or the other possible implementations?
(marking this PR as changes requested so it can be filtered)
WalkthroughThe changes introduce significant enhancements to the Warden protocol's transaction processing capabilities, focusing on account permissions, fee management, and the ante handler's structure. Notably, new features allow for fee burning and improved transaction handling logic, while unit tests and mock implementations bolster the testing framework. Overall, these modifications enhance security, efficiency, and flexibility within the application. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant AnteHandler
participant BankKeeper
participant FeeCollector
participant MockTest
User->>AnteHandler: Submit Transaction
AnteHandler->>BankKeeper: Validate and Deduct Fees
BankKeeper->>FeeCollector: Burn Portion of Fees
FeeCollector-->>BankKeeper: Confirm Burn
BankKeeper-->>AnteHandler: Fees Processed
AnteHandler-->>User: Transaction Complete
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 3
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- warden/app/app_config.go (2 hunks)
- warden/x/warden/ante/ante.go (1 hunks)
- warden/x/warden/ante/burn_fee.go (1 hunks)
- warden/x/warden/ante/burn_fee_test.go (1 hunks)
- warden/x/warden/ante/testutil_test.go (1 hunks)
- warden/x/warden/module/module.go (5 hunks)
- warden/x/warden/testutil/expected_keepers_mocks.go (1 hunks)
- warden/x/warden/types/expected_keepers.go (1 hunks)
Files skipped from review due to trivial changes (1)
- warden/x/warden/testutil/expected_keepers_mocks.go
Additional context used
golangci-lint
warden/x/warden/ante/testutil_test.go
120-120: Error return value of
acc.SetAccountNumber
is not checked(errcheck)
130-130: field
desc
is unused(unused)
131-131: field
malleate
is unused(unused)
Additional comments not posted (24)
warden/x/warden/ante/burn_fee.go (2)
16-19
: Struct definition is appropriate.The
BurnFeeDecorator
struct is well-defined with necessary fields for fee burning functionality.
21-26
: Constructor is correctly implemented.The
NewBurnFeeDecorator
function initializes theBurnFeeDecorator
with the necessary dependencies.warden/x/warden/ante/burn_fee_test.go (1)
19-46
: Test implementation is comprehensive.The
TestDeductFees
function effectively tests theBurnFeeDecorator
logic using mocks and assertions.warden/x/warden/types/expected_keepers.go (3)
16-20
: Interface enhancements are appropriate.The additions to the
AccountKeeper
interface provide necessary functionality for account and module management.
25-29
: Interface enhancements are appropriate.The additions to the
BankKeeper
interface support advanced financial operations, such as coin burning and transfers.
31-33
: New interface addition is valuable.The introduction of the
FeegrantKeeper
interface facilitates efficient fee management and transaction handling.warden/x/warden/ante/ante.go (3)
3-15
: Imports are well-organized and necessary.The imports are correctly organized and include all necessary packages for the functionality provided in this file.
17-26
:HandlerOptions
struct is well-defined.The
HandlerOptions
struct includes all necessary fields for configuring the AnteHandler, including the newFeeBurnRatio
.
28-61
:NewAnteHandler
function is well-structured.The function constructs an AnteHandler with appropriate decorators and error handling for missing dependencies. The inclusion of
BurnFeeDecorator
aligns with the PR's objective to burn transaction fees.warden/x/warden/module/module.go (6)
Line range hint
5-28
: Imports are necessary and well-organized.The new imports are necessary for the functionalities introduced, such as transaction handling and ante handler setup.
89-92
: Updated gRPC gateway handling mechanism.The change from
runtime.ServeMux
togwruntime.ServeMux
likely reflects an update for compatibility or improved functionality.
188-192
:ModuleInputs
struct enhancement withTxConfig
.The addition of
TxConfig
is essential for transaction configuration, aligning with the changes in transaction handling.
198-201
:ModuleOutputs
struct enhancement withBaseAppOption
.The inclusion of
BaseAppOption
allows for custom ante processing logic, enhancing module flexibility.
203-234
:newAnteHandler
function is robust and well-implemented.The function ensures essential dependencies are present before creating the ante handler, improving error handling and robustness.
Line range hint
234-267
:ProvideModule
function integrates custom ante processing logic.The inclusion of a base application option that sets the ante handler allows for a more integrated approach to handling transactions.
warden/x/warden/ante/testutil_test.go (7)
3-37
: Imports are appropriate for test utilities.The imports include necessary testing packages and mock utilities, which are appropriate for the test utilities provided in this file.
39-43
:TestAccount
struct is straightforward and useful.The
TestAccount
struct is useful for managing test accounts in a straightforward manner.
45-56
:AnteTestSuite
struct is well-structured for testing.The struct provides all necessary components for comprehensive ante handler testing.
58-112
:SetupTestSuite
function ensures proper test environment setup.The function is well-implemented, providing a proper test environment setup with mock controllers and context.
157-170
:DeliverMsgs
function is well-implemented for testing.The function provides a clear way to construct and deliver transactions through the ante handler for testing purposes.
172-206
:RunTestCase
function is comprehensive for executing tests.The function ensures that test cases are executed with appropriate checks for expected errors and outcomes.
208-259
:CreateTestTx
function is well-implemented for creating test transactions.The function provides necessary functionality for creating test transactions, handling signatures and encoding effectively.
warden/app/app_config.go (2)
260-262
: Flag potential implications of skipping the ante handler.Setting
SkipAnteHandler: true
allows transactions to bypass the ante handler, which may affect fee deduction, signature verification, and other pre-processing tasks. Ensure that this change does not compromise transaction security or integrity.
175-175
: Approve the addition of burner permission to the fee collector account.The addition of
Burner
permission to theFeeCollectorName
account aligns with the objective to burn transaction fees. Ensure that this change does not conflict with existing permissions or operations.Verification successful
Verify compatibility of Burner permission with existing operations.
The addition of the
Burner
permission to theFeeCollectorName
account appears consistent with its usage in burning operations. Ensure that no other permissions or operations are affected by this change.
- Usage in
burn_fee.go
: Confirms the intent to burn coins.- Tests in
burn_fee_test.go
: Validate the burning functionality.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the impact of the added Burner permission to the FeeCollectorName account. # Test: Search for usage of FeeCollectorName in the codebase to ensure compatibility with the new permission. rg --type go 'FeeCollectorName'Length of output: 554
func (bfd BurnFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { | ||
feeTx, ok := tx.(sdk.FeeTx) | ||
if !ok { | ||
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") | ||
} | ||
|
||
// Assume that default sdk FeeChecker is used. It follows that actual fee is always equal to feeTx.GetFee() | ||
fee := feeTx.GetFee() | ||
|
||
burnAmount, _ := sdk.NewDecCoinsFromCoins(fee...).MulDec(bfd.burnRatio).TruncateDecimal() | ||
|
||
if !burnAmount.IsZero() { | ||
err := bfd.bankKeeper.BurnCoins(ctx, authtypes.FeeCollectorName, burnAmount) | ||
if err != nil { | ||
return ctx, errorsmod.Wrap(sdkerrors.ErrLogic, "Failed to burn fee") | ||
} | ||
} | ||
|
||
return next(ctx, tx, simulate) |
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.
Enhance error message for BurnCoins
failure.
The error message when burning coins fails could be more descriptive to aid in debugging.
- return ctx, errorsmod.Wrap(sdkerrors.ErrLogic, "Failed to burn fee")
+ return ctx, errorsmod.Wrapf(sdkerrors.ErrLogic, "Failed to burn fee: %v", err)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func (bfd BurnFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { | |
feeTx, ok := tx.(sdk.FeeTx) | |
if !ok { | |
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") | |
} | |
// Assume that default sdk FeeChecker is used. It follows that actual fee is always equal to feeTx.GetFee() | |
fee := feeTx.GetFee() | |
burnAmount, _ := sdk.NewDecCoinsFromCoins(fee...).MulDec(bfd.burnRatio).TruncateDecimal() | |
if !burnAmount.IsZero() { | |
err := bfd.bankKeeper.BurnCoins(ctx, authtypes.FeeCollectorName, burnAmount) | |
if err != nil { | |
return ctx, errorsmod.Wrap(sdkerrors.ErrLogic, "Failed to burn fee") | |
} | |
} | |
return next(ctx, tx, simulate) | |
func (bfd BurnFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { | |
feeTx, ok := tx.(sdk.FeeTx) | |
if !ok { | |
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") | |
} | |
// Assume that default sdk FeeChecker is used. It follows that actual fee is always equal to feeTx.GetFee() | |
fee := feeTx.GetFee() | |
burnAmount, _ := sdk.NewDecCoinsFromCoins(fee...).MulDec(bfd.burnRatio).TruncateDecimal() | |
if !burnAmount.IsZero() { | |
err := bfd.bankKeeper.BurnCoins(ctx, authtypes.FeeCollectorName, burnAmount) | |
if err != nil { | |
return ctx, errorsmod.Wrapf(sdkerrors.ErrLogic, "Failed to burn fee: %v", err) | |
} | |
} | |
return next(ctx, tx, simulate) |
// TestCase represents a test case used in test tables. | ||
type TestCase struct { | ||
desc string | ||
malleate func(*AnteTestSuite) TestCaseArgs | ||
simulate bool | ||
expPass bool | ||
expErr error | ||
} |
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.
Address unused fields in TestCase
struct.
The fields desc
and malleate
are unused. Consider utilizing them or removing them if they are unnecessary.
Tools
golangci-lint
130-130: field
desc
is unused(unused)
131-131: field
malleate
is unused(unused)
func (suite *AnteTestSuite) CreateTestAccounts(numAccs int) []TestAccount { | ||
var accounts []TestAccount | ||
|
||
for i := 0; i < numAccs; i++ { | ||
priv, _, addr := testdata.KeyTestPubAddr() | ||
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr) | ||
acc.SetAccountNumber(uint64(i + 1000)) | ||
suite.accountKeeper.SetAccount(suite.ctx, acc) | ||
accounts = append(accounts, TestAccount{acc, priv}) | ||
} | ||
|
||
return 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.
Check the error return value of SetAccountNumber
.
The error return value of SetAccountNumber
should be checked to ensure that account setup is successful.
- acc.SetAccountNumber(uint64(i + 1000))
+ err := acc.SetAccountNumber(uint64(i + 1000))
+ require.NoError(t, err)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func (suite *AnteTestSuite) CreateTestAccounts(numAccs int) []TestAccount { | |
var accounts []TestAccount | |
for i := 0; i < numAccs; i++ { | |
priv, _, addr := testdata.KeyTestPubAddr() | |
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr) | |
acc.SetAccountNumber(uint64(i + 1000)) | |
suite.accountKeeper.SetAccount(suite.ctx, acc) | |
accounts = append(accounts, TestAccount{acc, priv}) | |
} | |
return accounts | |
} | |
func (suite *AnteTestSuite) CreateTestAccounts(numAccs int) []TestAccount { | |
var accounts []TestAccount | |
for i := 0; i < numAccs; i++ { | |
priv, _, addr := testdata.KeyTestPubAddr() | |
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr) | |
err := acc.SetAccountNumber(uint64(i + 1000)) | |
require.NoError(t, err) | |
suite.accountKeeper.SetAccount(suite.ctx, acc) | |
accounts = append(accounts, TestAccount{acc, priv}) | |
} | |
return accounts | |
} |
Tools
golangci-lint
120-120: Error return value of
acc.SetAccountNumber
is not checked(errcheck)
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores