-
Notifications
You must be signed in to change notification settings - Fork 411
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
Prune vesting accounts balances #1003
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1003 +/- ##
==========================================
- Coverage 60.33% 60.30% -0.03%
==========================================
Files 52 52
Lines 6436 6437 +1
==========================================
- Hits 3883 3882 -1
- Misses 2266 2268 +2
Partials 287 287
|
An alternative solution would be to burn only the |
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.
Logic seems correct.
Hard to follow, I would like PruneBalances to only take vesting account and make that check explicit in instantiate
} | ||
func (b VestingCoinBurner) PruneBalances(ctx sdk.Context, existingAcc authtypes.AccountI) error { | ||
v, ok := existingAcc.(vestingexported.VestingAccount) | ||
if !ok { |
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.
Ah, you check here... and only allow vesting accounts.
Either, "leave unchanged", "prune vesting" or reject.
You should definitely rename this function "EnforceVestingAndPruneBalances", or (my preference) do the vesting interface check in the instantiate method and accept vestingexported.VestingAccount
as an argument here, which makes it clearer and keeps the 3 cases very explicit in instantiate
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.
This was built with the assumption that also other than SDK account types can exists in a chain. The CoinPruner.PruneBalances
method is an extension point that can be used so that chains can handle their account types and/or vesting account types as they want. Another implementation could also be sending the tokens to the community pool or an escrow (not saying this makes sense).
The concrete struct type is VestingCoinBurner
. I thought this verbose enough and explicit addressing the SDK vesting account types only (or return error).
I can add some more code doc to this but switching to VestingAccount types only would not work due to the custom account types. Throwing types.ErrAccountExists
though would better fit one level where it was before. I will modify the method signature to return a handled
bool for this
WDYT?
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.
Ah, okay, so this PruneBalances is not on the Keeper, but can easily be set by an external app. Now I understand the design.
Throwing types.ErrAccountExists though would better fit one level where it was before. I will modify the method signature to return a handled bool for this
No need for handled
unless you prefer it as well, I think returning types.ErrAccountExists
is nice
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.
You convinced me that we need to keep the logic here. That does make sense.
However, the name is misleading. PruneBalances
is what you do when you encounter a vesting account.
Maybe CleanupExistingAccount
would be a better name (as is more general and fits what you want as an extension point). And if it is a vesting account, you PruneBalances
. Maybe other accounts have different cleanup methods? And if there is no cleanup possible (existing module account), returning some types.ErrCannotReuseAccount
error or such sounds good.
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.
👍 CleanupExistingAccount
makes sense as a more general term. I prefer the handled
result value, too as it brings back the control flow to the caller.
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.
Okay, I understand your motivation better.
Left comments for alternate cleanup. Basically just name changes now.
} | ||
func (b VestingCoinBurner) PruneBalances(ctx sdk.Context, existingAcc authtypes.AccountI) error { | ||
v, ok := existingAcc.(vestingexported.VestingAccount) | ||
if !ok { |
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.
Ah, okay, so this PruneBalances is not on the Keeper, but can easily be set by an external app. Now I understand the design.
Throwing types.ErrAccountExists though would better fit one level where it was before. I will modify the method signature to return a handled bool for this
No need for handled
unless you prefer it as well, I think returning types.ErrAccountExists
is nice
} | ||
func (b VestingCoinBurner) PruneBalances(ctx sdk.Context, existingAcc authtypes.AccountI) error { | ||
v, ok := existingAcc.(vestingexported.VestingAccount) | ||
if !ok { |
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.
You convinced me that we need to keep the logic here. That does make sense.
However, the name is misleading. PruneBalances
is what you do when you encounter a vesting account.
Maybe CleanupExistingAccount
would be a better name (as is more general and fits what you want as an extension point). And if it is a vesting account, you PruneBalances
. Maybe other accounts have different cleanup methods? And if there is no cleanup possible (existing module account), returning some types.ErrCannotReuseAccount
error or such sounds good.
I have pushed the renaming. Please approve the PR when they make sense now |
@@ -2274,3 +2274,66 @@ func TestAppendToContractHistory(t *testing.T) { | |||
gotHistory := keepers.WasmKeeper.GetContractHistory(ctx, contractAddr) | |||
assert.Equal(t, orderedEntries, gotHistory) | |||
} | |||
|
|||
func TestCoinBurnerPruneBalances(t *testing.T) { |
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.
nice test!
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.
LGTM 👍
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.
looks good now
* wasmd_v0.29.1: (94 commits) fix test. fix test. update cosmos-sdk to v45.9, add dragonberry. Changelog updates (CosmWasm#1024) Validate incoming messages Add dependencies for protobuf and remove third_party forlder (CosmWasm#1030) Bump bufbuild/buf-setup-action from 1.7.0 to 1.8.0 (CosmWasm#1006) Add check version wasm (CosmWasm#1029) Make SenderPrivKey field public Bump actions/checkout from 3.0.2 to 3.1.0 Revert module version to 1 as there is no migration Doc ante handler Fix: typos Changelog for v0.29.0-rc1 (CosmWasm#1018) Implement improvements to new address generation (CosmWasm#1014) Prune vesting accounts balances (CosmWasm#1003) Bump github.com/cosmos/ibc-go/v3 from 3.2.0 to 3.3.0 Fix path to proofs in protos Upgrade .a files to 1.1.1 Bump wasmvm to 1.1.1 ... # Conflicts: # .circleci/config.yml # .github/workflows/proto-buf-publisher.yml # CHANGELOG.md # Dockerfile # Makefile # README.md # app/app.go # app/app_test.go # app/export.go # app/sim_test.go # app/test_helpers.go # go.mod # go.sum # scripts/protocgen.sh # third_party/proto/cosmos/base/query/v1beta1/pagination.proto # third_party/proto/cosmos/base/v1beta1/coin.proto # third_party/proto/tendermint/blockchain/types.pb.go # third_party/proto/tendermint/consensus/types.pb.go # third_party/proto/tendermint/consensus/wal.pb.go # third_party/proto/tendermint/p2p/conn.pb.go # third_party/proto/tendermint/privval/types.pb.go # third_party/proto/tendermint/state/types.pb.go # third_party/proto/tendermint/types/types.pb.go # third_party/proto/tendermint/types/validator.pb.go # x/wasm/alias.go # x/wasm/client/cli/genesis_msg.go # x/wasm/client/cli/genesis_msg_test.go # x/wasm/client/cli/query.go # x/wasm/client/cli/tx.go # x/wasm/client/rest/gov.go # x/wasm/handler.go # x/wasm/ibctesting/chain.go # x/wasm/ibctesting/wasm.go # x/wasm/ioutils/ioutil_test.go # x/wasm/ioutils/utils_test.go # x/wasm/keeper/authz_policy.go # x/wasm/keeper/bench_test.go # x/wasm/keeper/contract_keeper.go # x/wasm/keeper/gas_register.go # x/wasm/keeper/gas_register_test.go # x/wasm/keeper/genesis_test.go # x/wasm/keeper/ibc_test.go # x/wasm/keeper/keeper.go # x/wasm/keeper/keeper_test.go # x/wasm/keeper/legacy_querier_test.go # x/wasm/keeper/msg_server.go # x/wasm/keeper/options.go # x/wasm/keeper/options_test.go # x/wasm/keeper/proposal_handler.go # x/wasm/keeper/proposal_integration_test.go # x/wasm/keeper/querier.go # x/wasm/keeper/querier_test.go # x/wasm/keeper/recurse_test.go # x/wasm/keeper/reflect_test.go # x/wasm/keeper/relay_test.go # x/wasm/keeper/staking_test.go # x/wasm/keeper/submsg_test.go # x/wasm/keeper/test_common.go # x/wasm/keeper/testdata/reflect.go # x/wasm/keeper/testdata/reflect.wasm # x/wasm/keeper/wasmtesting/coin_transferrer.go # x/wasm/keeper/wasmtesting/gas_register.go # x/wasm/module.go # x/wasm/module_test.go # x/wasm/simulation/genesis.go # x/wasm/simulation/operations.go # x/wasm/simulation/params.go # x/wasm/types/codec.go # x/wasm/types/events.go # x/wasm/types/exported_keepers.go # x/wasm/types/genesis.pb.go # x/wasm/types/iavl_range_test.go # x/wasm/types/ibc.pb.go # x/wasm/types/params.go # x/wasm/types/proposal.pb.go # x/wasm/types/query.pb.go # x/wasm/types/query.pb.gw.go # x/wasm/types/tx.pb.go # x/wasm/types/types.pb.go
* Prevent out of gas * Prune vesting account denoms only * Fix test state * Move account exists error up again * Review feedback: better naming
* Prevent out of gas * Prune vesting account denoms only * Fix test state * Move account exists error up again * Review feedback: better naming
Prevent an out of gas error when burning accounts balance
Update:
This PR also includes