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

Unhandled error when vesting locked amount > balance #13691

Closed
fedekunze opened this issue Oct 29, 2022 · 1 comment · Fixed by #13690
Closed

Unhandled error when vesting locked amount > balance #13691

fedekunze opened this issue Oct 29, 2022 · 1 comment · Fixed by #13690
Assignees
Labels

Comments

@fedekunze
Copy link
Collaborator

Summary of Bug

Bank's subUnlockedCoins panics when the vesting locked amount exceeds the available balance

spendable := balance.Sub(locked)

Version

main, latest

Steps to Reproduce

Error: rpc error: code = InvalidArgument desc = recovered: negative coin amount
stack:
goroutine 281243004 [running]:
runtime/debug.Stack(0x4111fb, 0xc00498fde8, 0x18)
	/opt/hostedtoolcache/go/1.16.15/x64/src/runtime/debug/stack.go:24 +0x9f
[github.com/cosmos/cosmos-sdk/baseapp.newDefaultRecoveryMiddleware.func1](http://github.com/cosmos/cosmos-sdk/baseapp.newDefaultRecoveryMiddleware.func1)(0x1d4c5a0, 0x24dada0, 0x0, 0xc0140d67e0)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/recovery.go:71 +0x26
[github.com/cosmos/cosmos-sdk/baseapp.newRecoveryMiddleware.func1](http://github.com/cosmos/cosmos-sdk/baseapp.newRecoveryMiddleware.func1)(0x1d4c5a0, 0x24dada0, 0x0, 0x0, 0xc00134cc60)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/recovery.go:39 +0x42
[github.com/cosmos/cosmos-sdk/baseapp.processRecovery](http://github.com/cosmos/cosmos-sdk/baseapp.processRecovery)(0x1d4c5a0, 0x24dada0, 0xc00134cc60, 0x0, 0x0)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/recovery.go:28 +0x43
[github.com/cosmos/cosmos-sdk/baseapp.processRecovery](http://github.com/cosmos/cosmos-sdk/baseapp.processRecovery)(0x1d4c5a0, 0x24dada0, 0xc00498fde8, 0x2568400, 0xc011e91740)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/recovery.go:33 +0x85
[github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp](http://github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp)).runTx.func1(0xc0140dba28, 0xc0140dbf00, 0xc000ec3d40, 0xc0140dd990, 0xc0140dd970, 0xc0140dd960)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/baseapp.go:634 +0x1b0
panic(0x1d4c5a0, 0x24dada0)
	/opt/hostedtoolcache/go/1.16.15/x64/src/runtime/panic.go:965 +0x1b9
[github.com/cosmos/cosmos-sdk/types.Coin.Sub](http://github.com/cosmos/cosmos-sdk/types.Coin.Sub)(0xc005e4da91, 0x5, 0xc00c987760, 0xc0152c59f8, 0x5, 0xc00c9876e0, 0x254dfc8, 0xc000052070, 0x2568400)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/types/coin.go:117 +0xf1
[github.com/cosmos/cosmos-sdk/x/bank/keeper.BaseSendKeeper.subUnlockedCoins](http://github.com/cosmos/cosmos-sdk/x/bank/keeper.BaseSendKeeper.subUnlockedCoins)(0x25657b8, 0xc0012c9ef0, 0x252e5f8, 0xc001331a80, 0x2567880, 0xc000034990, 0x25657b8, 0xc0012c9ef0, 0x2567880, 0xc000034990, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/x/bank/keeper/send.go:183 +0x2e5
[github.com/cosmos/cosmos-sdk/x/bank/keeper.BaseSendKeeper.SendCoins](http://github.com/cosmos/cosmos-sdk/x/bank/keeper.BaseSendKeeper.SendCoins)(0x25657b8, 0xc0012c9ef0, 0x252e5f8, 0xc001331a80, 0x2567880, 0xc000034990, 0x25657b8, 0xc0012c9ef0, 0x2567880, 0xc000034990, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/x/bank/keeper/send.go:134 +0x118
[github.com/cosmos/ibc-go/v2/modules/apps/transfer/keeper.Keeper.SendTransfer](http://github.com/cosmos/ibc-go/v2/modules/apps/transfer/keeper.Keeper.SendTransfer)(0x252e5f8, 0xc001331b50, 0x25657b8, 0xc0012c9ef0, 0x25657b8, 0xc0012c9ef0, 0xc000010568, 0x252e5f8, 0xc001331ae0, 0x252e648, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/ibc-go/v2@v2.0.0/modules/apps/transfer/keeper/relay.go:120 +0x110d
[github.com/cosmos/ibc-go/v2/modules/apps/transfer/keeper.Keeper.Transfer](http://github.com/cosmos/ibc-go/v2/modules/apps/transfer/keeper.Keeper.Transfer)(0x252e5f8, 0xc001331b50, 0x25657b8, 0xc0012c9ef0, 0x25657b8, 0xc0012c9ef0, 0xc000010568, 0x252e5f8, 0xc001331ae0, 0x252e648, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/ibc-go/v2@v2.0.0/modules/apps/transfer/keeper/msg_server.go:22 +0x2e8
[github.com/cosmos/ibc-go/v2/modules/apps/transfer/types._Msg_Transfer_Handler.func1](http://github.com/cosmos/ibc-go/v2/modules/apps/transfer/types._Msg_Transfer_Handler.func1)(0x254e038, 0xc0104371a0, 0x1fdc800, 0xc017cbe230, 0x20523c0, 0xc011ea9200, 0x254e038, 0xc0104371a0)
	/home/runner/go/pkg/mod/github.com/cosmos/ibc-go/v2@v2.0.0/modules/apps/transfer/types/tx.pb.go:233 +0x89
[github.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter](http://github.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter)).RegisterService.func2.1(0x254e038, 0xc010437170, 0x1fdc800, 0xc017cbe2a0, 0xc00c986ec0, 0xc00498f908, 0xc0140da2e0, 0x533e46, 0x1f22900, 0xc010437170)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/msg_service_router.go:113 +0x114
[github.com/cosmos/ibc-go/v2/modules/apps/transfer/types._Msg_Transfer_Handler](http://github.com/cosmos/ibc-go/v2/modules/apps/transfer/types._Msg_Transfer_Handler)(0x2047620, 0xc001457100, 0x254e038, 0xc010437170, 0x22e2d18, 0xc00c986e40, 0x254e038, 0xc010437170, 0x255ee48, 0xc0152c5a20)
	/home/runner/go/pkg/mod/github.com/cosmos/ibc-go/v2@v2.0.0/modules/apps/transfer/types/tx.pb.go:235 +0x150
[github.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter](http://github.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter)).RegisterService.func2(0x254dfc8, 0xc000052070, 0x2568400, 0xc011f14480, 0xb, 0x0, 0xc022f431b0, 0xb, 0x5c23f4, 0x39e69b7a, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/msg_service_router.go:126 +0x38d
[github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp](http://github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp)).runMsgs(0xc000ec3d40, 0x254dfc8, 0xc000052070, 0x2568400, 0xc011f14480, 0xb, 0x0, 0xc022f431b0, 0xb, 0x5c23f4, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/baseapp.go:755 +0x2fa
[github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp](http://github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp)).runTx(0xc000ec3d40, 0x7f6855b93b02, 0xc00fa63100, 0xf5, 0x100, 0x0, 0x0, 0x0, 0xc00efa9c00, 0x3, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/baseapp.go:715 +0x4f7
[github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp](http://github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp)).Simulate(...)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/test_helpers.go:23
[github.com/cosmos/cosmos-sdk/x/auth/tx.txServer.Simulate](http://github.com/cosmos/cosmos-sdk/x/auth/tx.txServer.Simulate)(0x0, 0x0, 0x0, 0x2573af0, 0xc0001b22e0, 0x0, 0x0, 0x2558848, 0xc0013303d0, 0x256bc58, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/x/auth/tx/service.go:117 +0xbf
[github.com/cosmos/cosmos-sdk/types/tx._Service_Simulate_Handler](http://github.com/cosmos/cosmos-sdk/types/tx._Service_Simulate_Handler)(0x1f39b40, 0xc00144a000, 0x254e038, 0xc0166ced50, 0xc02004bf90, 0x0, 0x254e038, 0xc0166ced50, 0xc015910080, 0x20)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/types/tx/service.pb.go:745 +0x214
[github.com/cosmos/cosmos-sdk/baseapp.(*GRPCQueryRouter](http://github.com/cosmos/cosmos-sdk/baseapp.(*GRPCQueryRouter)).RegisterService.func1(0x254dfc8, 0xc000052070, 0x2568400, 0xc011e91200, 0xb, 0x0, 0xc022f431b0, 0xb, 0x5c23f4, 0x39e69b7a, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/grpcrouter.go:85 +0x222
[github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp](http://github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp)).handleQueryGRPC(0xc000ec3d40, 0xc0019b0930, 0xc010dc0000, 0xf8, 0x200, 0xc014092e70, 0x23, 0x5c23f4, 0x0, 0x0, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/abci.go:559 +0x1d5
[github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp](http://github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp)).Query(0xc000ec3d40, 0xc010dc0000, 0xf8, 0x200, 0xc014092e70, 0x23, 0x5c23f4, 0x0, 0x0, 0x0, ...)
	/home/runner/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.44.5-patch/baseapp/abci.go:403 +0x96f
[github.com/tendermint/tendermint/abci/client.(*localClient](http://github.com/tendermint/tendermint/abci/client.(*localClient)).QuerySync(0xc0005316e0, 0xc010dc0000, 0xf8, 0x200, 0xc014092e70, 0x23, 0x0, 0x0, 0x0, 0x0, ...)
	/home/runner/go/pkg/mod/github.com/tendermint/tendermint@v0.34.14/abci/client/local_client.go:256 +0x10e
[github.com/tendermint/tendermint/proxy.(*appConnQuery](http://github.com/tendermint/tendermint/proxy.(*appConnQuery)).QuerySync(0xc004c2c880, 0xc010dc0000, 0xf8, 0x200, 0xc014092e70, 0x23, 0x0, 0x0, 0x203006, 0x203006, ...)
	/home/runner/go/pkg/mod/github.com/tendermint/tendermint@v0.34.14/proxy/app_conn.go:159 +0x68
[github.com/tendermint/tendermint/rpc/core.ABCIQuery](http://github.com/tendermint/tendermint/rpc/core.ABCIQuery)(0xc020195f40, 0xc014092e70, 0x23, 0xc010dc0000, 0xf8, 0x200, 0x0, 0x0, 0x0, 0x0, ...)
	/home/runner/go/pkg/mod/github.com/tendermint/tendermint@v0.34.14/rpc/core/abci.go:20 +0xfc
reflect.Value.call(0x1e0e4e0, 0x22e5570, 0x13, 0x206521a, 0x4, 0xc00efa9680, 0x5, 0x5, 0xc00efa9698, 0xc01ac60c60, ...)
	/opt/hostedtoolcache/go/1.16.15/x64/src/reflect/value.go:476 +0x8e7
reflect.Value.Call(0x1e0e4e0, 0x22e5570, 0x13, 0xc00efa9680, 0x5, 0x5, 0x1, 0x5, 0x0)
	/opt/hostedtoolcache/go/1.16.15/x64/src/reflect/value.go:337 +0xb9
[github.com/tendermint/tendermint/rpc/jsonrpc/server.makeJSONRPCHandler.func1](http://github.com/tendermint/tendermint/rpc/jsonrpc/server.makeJSONRPCHandler.func1)(0x2546680, 0xc011015320, 0xc010da8000)
	/home/runner/go/pkg/mod/github.com/tendermint/tendermint@v0.34.14/rpc/jsonrpc/server/http_json_handler.go:96 +0xc7e
[github.com/tendermint/tendermint/rpc/jsonrpc/server.handleInvalidJSONRPCPaths.func1](http://github.com/tendermint/tendermint/rpc/jsonrpc/server.handleInvalidJSONRPCPaths.func1)(0x2546680, 0xc011015320, 0xc010da8000)
	/home/runner/go/pkg/mod/github.com/tendermint/tendermint@v0.34.14/rpc/jsonrpc/server/http_json_handler.go:122 +0x9c
net/http.HandlerFunc.ServeHTTP(0xc004c2c090, 0x2546680, 0xc011015320, 0xc010da8000)
	/opt/hostedtoolcache/go/1.16.15/x64/src/net/http/server.go:2050 +0x44
net/http.(*ServeMux).ServeHTTP(0xc004a402c0, 0x2546680, 0xc011015320, 0xc010da8000)
	/opt/hostedtoolcache/go/1.16.15/x64/src/net/http/server.go:2429 +0x1ad
[github.com/tendermint/tendermint/rpc/jsonrpc/server.maxBytesHandler.ServeHTTP](http://github.com/tendermint/tendermint/rpc/jsonrpc/server.maxBytesHandler.ServeHTTP)(0x2509a80, 0xc004a402c0, 0xf4240, 0x2546680, 0xc011015320, 0xc010da8000)
	/home/runner/go/pkg/mod/github.com/tendermint/tendermint@v0.34.14/rpc/jsonrpc/server/http_server.go:236 +0xd9
[github.com/tendermint/tendermint/rpc/jsonrpc/server.RecoverAndLogHandler.func1](http://github.com/tendermint/tendermint/rpc/jsonrpc/server.RecoverAndLogHandler.func1)(0x2546ce0, 0xc010daa0e0, 0xc010da8000)
	/home/runner/go/pkg/mod/github.com/tendermint/tendermint@v0.34.14/rpc/jsonrpc/server/http_server.go:209 +0x36e
net/http.HandlerFunc.ServeHTTP(0xc004cbe300, 0x2546ce0, 0xc010daa0e0, 0xc010da8000)
	/opt/hostedtoolcache/go/1.16.15/x64/src/net/http/server.go:2050 +0x44
net/http.serverHandler.ServeHTTP(0xc00055a540, 0x2546ce0, 0xc010daa0e0, 0xc010da8000)
	/opt/hostedtoolcache/go/1.16.15/x64/src/net/http/server.go:2868 +0xa3
net/http.(*conn).serve(0xc017767680, 0x254e038, 0xc010ad98c0)
	/opt/hostedtoolcache/go/1.16.15/x64/src/net/http/server.go:1933 +0x8cd
created by net/http.(*Server).Serve
	/opt/hostedtoolcache/go/1.16.15/x64/src/net/http/server.go:2994 +0x39b
: panic: invalid request
@alexanderbez
Copy link
Contributor

This theoretically should not be possible, but it since you seem to somehow have discovered a path to it, might as well add defensive coding against it 👍

@mergify mergify bot closed this as completed in #13690 Nov 3, 2022
mergify bot pushed a commit that referenced this issue Nov 3, 2022
## Description

Closes: #13691 



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
mergify bot pushed a commit that referenced this issue Nov 3, 2022
## Description

Closes: #13691

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit 3034a9d)

# Conflicts:
#	CHANGELOG.md
#	x/bank/keeper/keeper_test.go
mergify bot pushed a commit that referenced this issue Nov 3, 2022
## Description

Closes: #13691

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit 3034a9d)

# Conflicts:
#	CHANGELOG.md
#	types/coin.go
#	x/bank/keeper/keeper_test.go
#	x/bank/keeper/send.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants