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

Broken TruncateDecimal #3870

Closed
4 tasks done
alexanderbez opened this issue Mar 13, 2019 · 0 comments · Fixed by #3913
Closed
4 tasks done

Broken TruncateDecimal #3870

alexanderbez opened this issue Mar 13, 2019 · 0 comments · Fixed by #3913
Assignees
Labels
Milestone

Comments

@alexanderbez
Copy link
Contributor

alexanderbez commented Mar 13, 2019

Summary of Bug

The following stracktrace shows how DecCoin/s#TruncateDecimal can lead to a panic:


Codespace: sdk
Code: 11
Message: \"102muon,0photino\"
stack:
goroutine 109833 [running]:
runtime/debug.Stack(0xc000aa9f28, 0xffa9a0, 0xc007db5230)
	/snap/go/3318/src/runtime/debug/stack.go:24 +0x9d
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx.func1(0xc000aabc50, 0xc000aabc78, 0xc000aabdb0)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/baseapp/baseapp.go:757 +0x90
panic(0xffa9a0, 0xc007db5230)
	/snap/go/3318/src/runtime/panic.go:522 +0x1b5
github.com/cosmos/cosmos-sdk/x/distribution/keeper.Hooks.BeforeDelegationSharesModified(0x135cce0, 0xc000bed230, 0xc000157b20, 0xc000157b20, 0x135cce0, 0xc000bed280, 0x135cd20, 0xc000bed290, 0xc000a6f5a0, 0x5, ...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/x/distribution/keeper/hooks.go:87 +0x233
github.com/cosmos/cosmos-sdk/cmd/gaia/app.StakingHooks.BeforeDelegationSharesModified(...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/cmd/gaia/app/app.go:374
github.com/cosmos/cosmos-sdk/x/staking/keeper.Keeper.BeforeDelegationSharesModified(...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/x/staking/keeper/hooks.go:52
github.com/cosmos/cosmos-sdk/x/staking/keeper.Keeper.Delegate(0x135cce0, 0xc000bed200, 0x135cd20, 0xc000bed210, 0xc000157b20, 0x7f32d83533e8, 0xc0000d2780, 0x137a380, 0xc000b73200, 0xc000157b20, ...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/x/staking/keeper/delegation.go:465 +0x9a1
github.com/cosmos/cosmos-sdk/x/staking.handleMsgDelegate(0x136ac60, 0xc004bc6000, 0xc00206b540, 0x14, 0xc003f10a00, 0x14, 0x14, 0xc003f10a20, 0x14, 0x14, ...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/x/staking/handler.go:216 +0x357
github.com/cosmos/cosmos-sdk/x/staking.NewHandler.func1(0x136ac60, 0xc004bc6000, 0xc00206b540, 0x14, 0x136e4a0, 0xc00431f220, 0x0, 0x0, 0x0, 0x0, ...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/x/staking/handler.go:25 +0x485
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runMsgs(0xc0000eb000, 0x136ac60, 0xc004bc6000, 0xc00206b540, 0x14, 0xc003c01f10, 0x1, 0x1, 0x136ac02, 0x0, ...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/baseapp/baseapp.go:653 +0xb4e
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx(0xc0000eb000, 0x2, 0xc003d3ab60, 0xc9, 0xc9, 0x135f020, 0xc0054fad20, 0x0, 0x0, 0x0, ...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/baseapp/baseapp.go:830 +0x375
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).DeliverTx(0xc0000eb000, 0xc003d3ab60, 0xc9, 0xc9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/baseapp/baseapp.go:587 +0x2a0
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/abci/client.(*localClient).DeliverTxAsync(0xc000bba600, 0xc003d3ab60, 0xc9, 0xc9, 0x0)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/abci/client/local_client.go:88 +0xc5
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/proxy.(*appConnConsensus).DeliverTxAsync(0xc0004fab90, 0xc003d3ab60, 0xc9, 0xc9, 0xa)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/proxy/app_conn.go:73 +0x51
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/state.execBlockOnProxyApp(0x136b760, 0xc000199ba0, 0x1374140, 0xc0004fab90, 0xc0034661e0, 0xc00507ed20, 0x137c200, 0xc000010a68, 0xc000035d60, 0xa, ...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/state/execution.go:281 +0x5e2
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/state.(*BlockExecutor).ApplyBlock(0xc00016b6c0, 0xa, 0x0, 0xc000035d50, 0x6, 0xc000035d60, 0xa, 0x13841, 0x26ac, 0xc0065078a0, ...)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/state/execution.go:119 +0x1b5
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).finalizeCommit(0xc000079880, 0x13842)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus/state.go:1327 +0x9be
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryFinalizeCommit(0xc000079880, 0x13842)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus/state.go:1258 +0x3e0
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit.func1(0xc000079880, 0x0, 0x13842)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus/state.go:1204 +0x91
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit(0xc000079880, 0x13842, 0x0)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus/state.go:1235 +0x61e
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote(0xc000079880, 0xc006c80fa0, 0xc005aecc90, 0x28, 0x109, 0x109, 0x109)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus/state.go:1660 +0xaec
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote(0xc000079880, 0xc006c80fa0, 0xc005aecc90, 0x28, 0x0, 0x109, 0x101)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus/state.go:1506 +0x5c
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg(0xc000079880, 0x134ea60, 0xc00371a360, 0xc005aecc90, 0x28)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus/state.go:694 +0x6cc
github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine(0xc000079880, 0x0)
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus/state.go:642 +0x695
created by github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).OnStart
	/home/nissa/go/src/github.com/cosmos/cosmos-sdk/vendor/github.com/tendermint/tendermint/consensus/state.go:334 +0x13a

This is similar to the fix in #3836 (I should've caught all cases...sigh). We need to groom through all the decimal coins methods and make sure there is no case where zero coins can be returned. In this case, DecCoins#TruncateDecimal cannot return any zero coins in out.

This does not affect mainnet because there will exist only one token and IsZero will return true in such a case as above.

credit: @fkbenjamin


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@alexanderbez alexanderbez added this to the Backlog milestone Mar 13, 2019
@alexanderbez alexanderbez self-assigned this Mar 13, 2019
@alexanderbez alexanderbez modified the milestones: Backlog, v0.34.0 Mar 13, 2019
This was referenced Mar 14, 2019
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.

1 participant