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

Prune vesting accounts balances #1003

Merged
merged 5 commits into from
Sep 21, 2022
Merged

Prune vesting accounts balances #1003

merged 5 commits into from
Sep 21, 2022

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Sep 14, 2022

Prevent an out of gas error when burning accounts balance

Update:
This PR also includes

  • pruning vesting accounts original denoms only
  • drop the prune account types list. It is easier to check for the vesting account interface. This should cover future vesting types as well. Chains can still overwrite this behaviour with a custom CoinPruner via Options

@alpe alpe requested a review from ethanfrey September 14, 2022 10:49
@codecov
Copy link

codecov bot commented Sep 14, 2022

Codecov Report

Merging #1003 (4c85b0d) into main (e55db8b) will decrease coverage by 0.02%.
The diff coverage is 76.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
x/wasm/keeper/keeper.go 87.67% <73.91%> (-0.20%) ⬇️
x/wasm/keeper/options.go 74.71% <100.00%> (-1.38%) ⬇️

@alpe
Copy link
Contributor Author

alpe commented Sep 14, 2022

An alternative solution would be to burn only the stakingKeeper.BondDenom() balance when pruning an account.

@alpe alpe changed the title Prevent out of gas Prune vesting accounts Sep 19, 2022
@alpe alpe changed the title Prune vesting accounts Prune vesting accounts balances Sep 19, 2022
Copy link
Member

@ethanfrey ethanfrey left a 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

x/wasm/keeper/keeper.go Show resolved Hide resolved
}
func (b VestingCoinBurner) PruneBalances(ctx sdk.Context, existingAcc authtypes.AccountI) error {
v, ok := existingAcc.(vestingexported.VestingAccount)
if !ok {
Copy link
Member

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

Copy link
Contributor Author

@alpe alpe Sep 20, 2022

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?

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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.

x/wasm/keeper/keeper.go Show resolved Hide resolved
x/wasm/keeper/keeper.go Outdated Show resolved Hide resolved
Copy link
Member

@ethanfrey ethanfrey left a 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 {
Copy link
Member

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 {
Copy link
Member

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.

@alpe alpe requested a review from ethanfrey September 21, 2022 11:39
@alpe
Copy link
Contributor Author

alpe commented Sep 21, 2022

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice test!

Copy link
Contributor

@pinosu pinosu left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

looks good now

@alpe alpe merged commit 54fec05 into main Sep 21, 2022
@alpe alpe deleted the 942_gas branch September 21, 2022 13:14
@faddat faddat mentioned this pull request Oct 2, 2022
zemyblue added a commit to zemyblue/wasmd that referenced this pull request Jan 13, 2023
* 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
Magicloud pushed a commit to fpco/wasmd that referenced this pull request Jan 13, 2023
* Prevent out of gas

* Prune vesting account denoms only

* Fix test state

* Move account exists error  up again

* Review feedback: better naming
conorpp pushed a commit to wormhole-foundation/wasmd that referenced this pull request Feb 1, 2023
* Prevent out of gas

* Prune vesting account denoms only

* Fix test state

* Move account exists error  up again

* Review feedback: better naming
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.

3 participants