zeta-chain / node

ZetaChain’s blockchain node and an observer validator client
https://zetachain.com
MIT License
167 stars 109 forks source link

Fix: Defaults for onChain Parameters to Prevent Halt on Not Set Values Expected to Exist #1866

Closed gzukel closed 1 week ago

gzukel commented 8 months ago

Describe the Bug A recent system upgrade encountered an issue where an emissions parameter was not set, leading to a halt of the binary. To prevent such occurrences, it is proposed that all parameters expected by the Chain should have default values unless explicitly set or overridden. This approach would ensure that the addition of new parameters does not cause a system panic due to missing state information, by instantiating a default value when the parameter is not present in the state. However, if the parameter is explicitly set, the system should utilize the specified value.

To Reproduce

Expected Behavior The system should automatically assign a default value to any new parameter that is not explicitly set in the state during an upgrade. This action would prevent the system from halting and ensure smooth operation, even when new parameters are introduced.

Screenshots/Logs

panic: UnmarshalJSON cannot decode empty bytes

goroutine 1 [running]:
github.com/cosmos/cosmos-sdk/x/params/types.Subspace.Get({{0x3dbd230, 0xc0014561d0}, 0xc000b81390, {0x3d8a470, 0xc001e42340}, {0x3d8a4c0, 0xc001e423f0}, {0xc00055c5a0, 0x9, 0x24}, ...}, ...)
    /root/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.13/x/params/types/subspace.go:110 +0x2c7
github.com/cosmos/cosmos-sdk/x/params/types.Subspace.GetParamSet({{0x3dbd230, 0xc0014561d0}, 0xc000b81390, {0x3d8a470, 0xc001e42340}, {0x3d8a4c0, 0xc001e423f0}, {0xc00055c5a0, 0x9, 0x24}, ...}, ...)
    /root/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.13/x/params/types/subspace.go:239 +0x106
github.com/zeta-chain/zetacore/x/emissions/keeper.Keeper.GetParams(...)
    /go/src/github.com/zeta-chain/node/x/emissions/keeper/params.go:10
github.com/zeta-chain/zetacore/x/emissions.BeginBlocker({{0x3da86b8, 0xc0000560b0}, {0x3dbdcb0, 0xc00364df00}, {{0xb, 0x0}, {0xc010d25e20, 0x10}, 0x1fa86a, {0x2b019d02, ...}, ...}, ...}, ...)
    /go/src/github.com/zeta-chain/node/x/emissions/abci.go:22 +0x2e8
github.com/zeta-chain/zetacore/x/emissions.AppModule.BeginBlock(...)
    /go/src/github.com/zeta-chain/node/x/emissions/module.go:172
github.com/cosmos/cosmos-sdk/types/module.(*Manager).BeginBlock(_, {{0x3da86b8, 0xc0000560b0}, {0x3dbdcb0, 0xc00364df00}, {{0xb, 0x0}, {0xc010d25e20, 0x10}, 0x1fa86a, ...}, ...}, ...)
    /root/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.13/types/module/module.go:484 +0x1bb
github.com/zeta-chain/zetacore/app.(*App).BeginBlocker(...)
    /go/src/github.com/zeta-chain/node/app/app.go:618
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).BeginBlock(_, {{0xc001e32fa0, 0x20, 0x20}, {{0xb, 0x0}, {0xc010d25e20, 0x10}, 0x1fa86a, {0x2b019d02, ...}, ...}, ...})
    /root/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.13/baseapp/abci.go:183 +0x843
github.com/tendermint/tendermint/abci/client.(*localClient).BeginBlockSync(_, {{0xc001e32fa0, 0x20, 0x20}, {{0xb, 0x0}, {0xc010d25e20, 0x10}, 0x1fa86a, {0x2b019d02, ...}, ...}, ...})
    /root/go/pkg/mod/github.com/cometbft/cometbft@v0.34.28/abci/client/local_client.go:280 +0x118
github.com/tendermint/tendermint/proxy.(*appConnConsensus).BeginBlockSync(_, {{0xc001e32fa0, 0x20, 0x20}, {{0xb, 0x0}, {0xc010d25e20, 0x10}, 0x1fa86a, {0x2b019d02, ...}, ...}, ...})
    /root/go/pkg/mod/github.com/cometbft/cometbft@v0.34.28/proxy/app_conn.go:81 +0x55
github.com/tendermint/tendermint/state.execBlockOnProxyApp({0x3daa130?, 0xc0058c0180}, {0x3db44c0, 0xc0018d4460}, 0xc001792000, {0x3dbf248, 0xc082724018}, 0x1fa869?)
    /root/go/pkg/mod/github.com/cometbft/cometbft@v0.34.28/state/execution.go:307 +0x51d
github.com/tendermint/tendermint/state.(*BlockExecutor).ApplyBlock(_, {{{0xb, 0x0}, {0xc0018d06b8, 0x7}}, {0xc0018d06f0, 0x10}, 0x1, 0x1fa869, {{0xc0446a20a0, ...}, ...}, ...}, ...)
    /root/go/pkg/mod/github.com/cometbft/cometbft@v0.34.28/state/execution.go:140 +0x171
github.com/tendermint/tendermint/consensus.(*Handshaker).replayBlock(_, {{{0xb, 0x0}, {0xc0018d06b8, 0x7}}, {0xc0018d06f0, 0x10}, 0x1, 0x1fa869, {{0xc0446a20a0, ...}, ...}, ...}, ...)
    /root/go/pkg/mod/github.com/cometbft/cometbft@v0.34.28/consensus/replay.go:503 +0x23c
github.com/tendermint/tendermint/consensus.(*Handshaker).ReplayBlocks(_, {{{0xb, 0x0}, {0xc0018d06b8, 0x7}}, {0xc0018d06f0, 0x10}, 0x1, 0x1fa869, {{0xc0446a20a0, ...}, ...}, ...}, ...)
    /root/go/pkg/mod/github.com/cometbft/cometbft@v0.34.28/consensus/replay.go:416 +0x7ae
github.com/tendermint/tendermint/consensus.(*Handshaker).Handshake(0xc01139cf90, {0x3dc1610, 0xc001b72ea0})
    /root/go/pkg/mod/github.com/cometbft/cometbft@v0.34.28/consensus/replay.go:268 +0x3d4
github.com/tendermint/tendermint/node.doHandshake({_, _}, {{{0xb, 0x0}, {0xc0018d06b8, 0x7}}, {0xc0018d06f0, 0x10}, 0x1, 0x1fa869, ...}, ...)
    /root/go/pkg/mod/github.com/cometbft/cometbft@v0.34.28/node/node.go:329 +0x1b8
github.com/tendermint/tendermint/node.NewNode(0xc000da32c0, {0x3da0600, 0xc001b63860}, 0xc001c68230, {0x3d80880, 0xc04296a480}, 0x1?, 0x5736700?, 0xc001c68470, {0x3daa130, ...}, ...)
    /root/go/pkg/mod/github.com/cometbft/cometbft@v0.34.28/node/node.go:779 +0x597
github.com/zeta-chain/zetacore/server.startInProcess(_, {{0x0, 0x0, 0x0}, {0x3dd4ac0, 0xc001b39b60}, 0x0, {0xc001b702c0, 0x10}, {0x3dc6458, ...}, ...}, ...)
    /go/src/github.com/zeta-chain/node/server/start.go:380 +0xf47
github.com/zeta-chain/zetacore/server.StartCmd.func2(0xc001a42f00?, {0xc001b394a0?, 0x0?, 0x3?})
    /go/src/github.com/zeta-chain/node/server/start.go:164 +0x2a5
github.com/spf13/cobra.(*Command).execute(0xc001a42f00, {0xc001b39410, 0x3, 0x3})
    /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc001782c00)
    /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
    /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
github.com/spf13/cobra.(*Command).ExecuteContext(...)
    /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:985
github.com/cosmos/cosmos-sdk/server/cmd.Execute(0x26bd600?, {0x0, 0x0}, {0xc001485460, 0x1a})
    /root/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.46.13/server/cmd/execute.go:36 +0x20f
main.main()
    /go/src/github.com/zeta-chain/node/cmd/zetacored/main.go:19 +0x35

Environment (please complete the following information): ALL

lumtis commented 8 months ago

FYI We already defined default parameters. The issue is the param module that panic when reading a key for a value that has not been previously set. Preventing the panic prevents the chain halt: https://github.com/zeta-chain/node/pull/1864