elesto-dao / elesto

The ElestoDAO node
Apache License 2.0
4 stars 1 forks source link

feat(mint): in-place store migrations #147

Closed gsora closed 2 years ago

gsora commented 2 years ago

This commit adds in-store migrations for the x/mint module, allowing us to leverage the SDK upgrade module to do migrations, rather than using the old export method.

A software upgrade gov proposal for version v1.1 must be created and pass before running this code.

I hardcoded version "v1.1" as Go constant here, but we can do pretty much whatever in terms of version naming, the important thing is it must match what's written in the gov proposal.

To test this change create a chain devnet using the latest released Elesto version, and use the following gov settings in genesis.json:

    "gov": {
      "starting_proposal_id": "1",
      "deposits": [],
      "votes": [],
      "proposals": [],
      "deposit_params": {
        "min_deposit": [
          {
            "denom": "stake",
            "amount": "1"
          }
        ],
        "max_deposit_period": "5s"
      },
      "voting_params": {
        "voting_period": "10s"
      },
      "tally_params": {
        "quorum": "0.000010000000000000",
        "threshold": "0.010000000000000000",
        "veto_threshold": "0.334000000000000000"
      }
    },

Create a software upgrade for version v1.1:

./elestod-premint tx gov submit-proposal software-upgrade v1.1 --upgrade-height 30 --deposit 100000stake --from validator -b block --title "v1.1 upgrade" --description "upgrade yay" --keyring-backend test --chain-id testing

Vote on the proposal:

./elestod-premint tx gov vote 1 yes --from validator --chain-id testing -b block -y --keyring-backend test

Then wait! At block 30 you'll see a consensus failure, this is normal:

1:02PM ERR UPGRADE "v1.1" NEEDED at height: 30: 
1:02PM ERR CONSENSUS FAILURE!!! err="UPGRADE \"v1.1\" NEEDED at height: 30: " module=consensus stack="goroutine 149 [running]:\nruntime/debug.Stack()\n\truntime/debug/stack.go:24 +0x68\ngithub.com/tendermint/tendermint/consensus.(*State).receiveRoutine.func2()\n\tgithub.com/tendermint/tendermint@v0.34.14/consensus/state.go:726 +0x48\npanic({0x101fbc940, 0x14000d52110})\n\truntime/panic.go:838 +0x204\ngithub.com/cosmos/cosmos-sdk/x/upgrade.BeginBlocker({{_, _}, _, {_, _}, {_, _}, _, {_, _}, ...}, ...)\n\tgithub.com/cosmos/cosmos-sdk@v0.45.1/x/upgrade/abci.go:71 +0xb0c\ngithub.com/cosmos/cosmos-sdk/x/upgrade.AppModule.BeginBlock(...)\n\tgithub.com/cosmos/cosmos-sdk@v0.45.1/x/upgrade/module.go:130\ngithub.com/cosmos/cosmos-sdk/types/module.(*Manager).BeginBlock(_, {{0x10227ba50, 0x14000128008}, {0x102287318, 0x140039ac340}, {{0xb, 0x0}, {0x14001165ed9, 0x7}, 0x1e, ...}, ...}, ...)\n\tgithub.com/cosmos/cosmos-sdk@v0.45.1/types/module/module.go:479 +0x2a4\ngithub.com/elesto-dao/elesto/app.(*App).BeginBlocker(_, {{0x10227ba50, 0x14000128008}, {0x102287318, 0x140039ac340}, {{0xb, 0x0}, {0x14001165ed9, 0x7}, 0x1e, ...}, ...}, ...)\n\tgithub.com/elesto-dao/elesto/app/app.go:551 +0x64\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).BeginBlock(_, {{0x1400339a160, 0x20, 0x20}, {{0xb, 0x0}, {0x14001165ed9, 0x7}, 0x1e, {0x3430dae8, ...}, ...}, ...})\n\tgithub.com/cosmos/cosmos-sdk@v0.45.1/baseapp/abci.go:194 +0x6f0\ngithub.com/tendermint/tendermint/abci/client.(*localClient).BeginBlockSync(_, {{0x1400339a160, 0x20, 0x20}, {{0xb, 0x0}, {0x14001165ed9, 0x7}, 0x1e, {0x3430dae8, ...}, ...}, ...})\n\tgithub.com/tendermint/tendermint@v0.34.14/abci/client/local_client.go:280 +0x110\ngithub.com/tendermint/tendermint/proxy.(*appConnConsensus).BeginBlockSync(_, {{0x1400339a160, 0x20, 0x20}, {{0xb, 0x0}, {0x14001165ed9, 0x7}, 0x1e, {0x3430dae8, ...}, ...}, ...})\n\tgithub.com/tendermint/tendermint@v0.34.14/proxy/app_conn.go:81 +0x50\ngithub.com/tendermint/tendermint/state.execBlockOnProxyApp({0x10227c8c0?, 0x140005d5b60}, {0x1022817b8, 0x14000ebb3e0}, 0x1400002e1e0, {0x102285d78, 0x14000eba760}, 0x1d?)\n\tgithub.com/tendermint/tendermint@v0.34.14/state/execution.go:307 +0x2bc\ngithub.com/tendermint/tendermint/state.(*BlockExecutor).ApplyBlock(_, {{{0xb, 0x0}, {0x14000128990, 0x8}}, {0x14000128998, 0x7}, 0x1, 0x1d, {{0x140032092e0, ...}, ...}, ...}, ...)\n\tgithub.com/tendermint/tendermint@v0.34.14/state/execution.go:140 +0xe8\ngithub.com/tendermint/tendermint/consensus.(*State).finalizeCommit(0x140005c6700, 0x1e)\n\tgithub.com/tendermint/tendermint@v0.34.14/consensus/state.go:1635 +0x7f8\ngithub.com/tendermint/tendermint/consensus.(*State).tryFinalizeCommit(0x140005c6700, 0x1e)\n\tgithub.com/tendermint/tendermint@v0.34.14/consensus/state.go:1546 +0x29c\ngithub.com/tendermint/tendermint/consensus.(*State).enterCommit.func1()\n\tgithub.com/tendermint/tendermint@v0.34.14/consensus/state.go:1481 +0x94\ngithub.com/tendermint/tendermint/consensus.(*State).enterCommit(0x140005c6700, 0x1e, 0x0)\n\tgithub.com/tendermint/tendermint@v0.34.14/consensus/state.go:1519 +0xa90\ngithub.com/tendermint/tendermint/consensus.(*State).addVote(0x140005c6700, 0x140001cea00, {0x0, 0x0})\n\tgithub.com/tendermint/tendermint@v0.34.14/consensus/state.go:2132 +0xaf8\ngithub.com/tendermint/tendermint/consensus.(*State).tryAddVote(0x140005c6700, 0x140001cea00, {0x0?, 0x1008c7c04?})\n\tgithub.com/tendermint/tendermint@v0.34.14/consensus/state.go:1930 +0x2c\ngithub.com/tendermint/tendermint/consensus.(*State).handleMsg(0x140005c6700, {{0x102264f18?, 0x140039b2df0?}, {0x0?, 0x0?}})\n\tgithub.com/tendermint/tendermint@v0.34.14/consensus/state.go:838 +0x37c\ngithub.com/tendermint/tendermint/consensus.(*State).receiveRoutine(0x140005c6700, 0x0)\n\tgithub.com/tendermint/tendermint@v0.34.14/consensus/state.go:782 +0x374\ncreated by github.com/tendermint/tendermint/consensus.(*State).OnStart\n\tgithub.com/tendermint/tendermint@v0.34.14/consensus/state.go:378 +0xe4\n"

After that, build this branch and run it, the chain should just work™️:

1:05PM INF starting node with ABCI Tendermint in-process
1:05PM INF Starting multiAppConn service impl=multiAppConn module=proxy
1:05PM INF Starting localClient service connection=query impl=localClient module=abci-client
1:05PM INF Starting localClient service connection=snapshot impl=localClient module=abci-client
1:05PM INF Starting localClient service connection=mempool impl=localClient module=abci-client
1:05PM INF Starting localClient service connection=consensus impl=localClient module=abci-client
1:05PM INF Starting EventBus service impl=EventBus module=events
1:05PM INF Starting PubSub service impl=PubSub module=pubsub
1:05PM INF Starting IndexerService service impl=IndexerService module=txindex
1:05PM INF ABCI Handshake App Info hash="��Ϻaw�\x1d��A��Z.\x17�Uop�h�\fC���\a�\nJ" height=29 module=consensus protocol-version=0 software-version=1.0.0-rc1-69-g403fc5a
1:05PM INF ABCI Replay Blocks appHeight=29 module=consensus stateHeight=29 storeHeight=30
1:05PM INF Replay last block using real app module=consensus
1:05PM INF applying upgrade "v1.1" at height: 30
1:05PM INF adding a new module: credential
1:05PM INF migrating module mint from version 1 to version 2
1:05PM INF minted coins from module account amount=31709792stake from=mint module=x/bank
1:05PM INF executed block height=30 module=consensus num_invalid_txs=0 num_valid_txs=0
1:05PM INF commit synced commit=436F6D6D697449447B5B313534203235342031373120373320383420313734203231372034352032313420373520323532203230302031373520313234203233392032203133352031363820313134203134203134342039352031353920323036203139392035332031393820323138203220313330203333203230345D3A31457D
1:05PM INF committed state app_hash=9AFEAB4954AED92DD64BFCC8AF7CEF0287A8720E905F9FCEC735C6DA028221CC height=30 module=consensus num_txs=0
1:05PM INF Completed ABCI Handshake - Tendermint and App are synced appHash="��Ϻaw�\x1d��A��Z.\x17�Uop�h�\fC���\a�\nJ" appHeight=29 module=consensus
1:05PM INF Version info block=11 p2p=8 tendermint_version=v0.34.19
1:05PM INF This node is a validator addr=693B78E5EA3C58C687C993F2F3D8D5A08AC56C8A module=consensus pubKey=MxF11+afWfQ0/uI8z6tQrvNb49DXp5l7lM0YYuC2TeM=
1:05PM INF indexed block height=30 module=txindex
1:05PM INF P2P Node ID ID=e2e26d80b2e226f142c44ef80789d0c5aae8806e file=/Users/gsora/.elesto/config/node_key.json module=p2p
1:05PM INF Adding persistent peers addrs=[] module=p2p
1:05PM INF Adding unconditional peer ids ids=[] module=p2p
1:05PM INF Add our address to book addr={"id":"e2e26d80b2e226f142c44ef80789d0c5aae8806e","ip":"0.0.0.0","port":26656} book=/Users/gsora/.elesto/config/addrbook.json module=p2p
1:05PM INF Starting Node service impl=Node
1:05PM INF Starting pprof server laddr=localhost:6060
1:05PM INF Starting RPC HTTP server on 127.0.0.1:26657 module=rpc-server
1:05PM INF Starting P2P Switch service impl="P2P Switch" module=p2p
1:05PM INF Starting Mempool service impl=Mempool module=mempool
1:05PM INF Starting BlockchainReactor service impl=BlockchainReactor module=blockchain
1:05PM INF Starting Consensus service impl=ConsensusReactor module=consensus
1:05PM INF Reactor  module=consensus waitSync=false
1:05PM INF Starting State service impl=ConsensusState module=consensus
1:05PM INF Starting baseWAL service impl=baseWAL module=consensus wal=/Users/gsora/.elesto/data/cs.wal/wal
1:05PM INF Starting Group service impl=Group module=consensus wal=/Users/gsora/.elesto/data/cs.wal/wal
1:05PM INF Starting TimeoutTicker service impl=TimeoutTicker module=consensus
1:05PM INF Searching for height height=31 max=0 min=0 module=consensus wal=/Users/gsora/.elesto/data/cs.wal/wal
1:05PM INF Searching for height height=30 max=0 min=0 module=consensus wal=/Users/gsora/.elesto/data/cs.wal/wal
1:05PM INF Found height=30 index=0 module=consensus wal=/Users/gsora/.elesto/data/cs.wal/wal
1:05PM INF Catchup by replaying consensus messages height=31 module=consensus
1:05PM INF Replay: Done module=consensus
1:05PM INF Starting Evidence service impl=Evidence module=evidence
1:05PM INF Starting StateSync service impl=StateSync module=statesync
1:05PM INF Starting PEX service impl=PEX module=pex
1:05PM INF Starting AddrBook service book=/Users/gsora/.elesto/config/addrbook.json impl=AddrBook module=p2p
1:05PM INF Saving AddrBook to file book=/Users/gsora/.elesto/config/addrbook.json module=p2p size=0
1:05PM INF Ensure peers module=pex numDialing=0 numInPeers=0 numOutPeers=0 numToDial=10
1:05PM INF No addresses to dial. Falling back to seeds module=pex
1:05PM INF Timed out dur=4997.268 height=31 module=consensus round=0 step=1
1:05PM INF received proposal module=consensus proposal={"Type":32,"block_id":{"hash":"D05B777C470F38275C3F36541A2AEA545960E78A14CB72E4494586BC2F6C9AAF","parts":{"hash":"AC74ECEAB62A6AC9FBDA38BF75C8C3D4A04DF271D871189B6B09131EB51DD2CD","total":1}},"height":31,"pol_round":-1,"round":0,"signature":"IAjQop+QNz2VyadSImbKxX4toy3bJOuK75ZHUzsilsWiGOYN2OLFfxVdKjDn5XCpHQFOQ/YuEYGkZfGQAMt0Aw==","timestamp":"2022-06-17T11:05:11.289846Z"}
1:05PM INF received complete proposal block hash=D05B777C470F38275C3F36541A2AEA545960E78A14CB72E4494586BC2F6C9AAF height=31 module=consensus
1:05PM INF finalizing commit of block hash=D05B777C470F38275C3F36541A2AEA545960E78A14CB72E4494586BC2F6C9AAF height=31 module=consensus num_txs=0 root=9AFEAB4954AED92DD64BFCC8AF7CEF0287A8720E905F9FCEC735C6DA028221CC
1:05PM INF minted coins from module account amount=31709792stake from=mint module=x/bank
1:05PM INF executed block height=31 module=state num_invalid_txs=0 num_valid_txs=0
1:05PM INF commit synced commit=436F6D6D697449447B5B32323020323436203135302031363920313535203337203336203132382035362031313320313339203233302031313820313434203330203132332034203135372033362033352031333520312030203534203633203133392038392032313020313330203133203234382035365D3A31467D
1:05PM INF committed state app_hash=DCF696A99B25248038718BE676901E7B049D2423870100363F8B59D2820DF838 height=31 module=state num_txs=0
1:05PM INF indexed block height=31 module=txindex