cosmos-sdk/simapp
Facundo Medica 6a03586074
fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)
## Description

### Issue
Some values (like chain ID) were being leaked from the previous block/initialization into PrepareProposal and ProcessProposal, these values are only available if:
1. The node has never been stopped since the genesis block (as these values are set on `InitChain`)
2. The node has already commited a block (as the previous header was being used for the new state of prepare and process proposal).

So if a node is restarted, during the first prepare and process proposal these values won't be populated, and that will cause issues if they are being used.

### Solution

Remove any previous header information from a previous block in the prepare and process proposal contexts, making things consistent at every height.

- Added ChainID to baseapp
- Use an empty header in Commit() with only the chain id set
- Fix context for prepare and process proposal

Closes: #15269



---

### 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/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)
2023-03-13 17:15:39 +00:00
..
params refactor!: extract AppStateFn out of simapp (#14977) 2023-02-09 14:16:07 +00:00
simd chore: revert panic in simapp (#15367) 2023-03-13 15:37:04 +00:00
app_config.go refactor: remove capability module (#15344) 2023-03-10 12:59:10 +00:00
app_test.go refactor: remove capability module (#15344) 2023-03-10 12:59:10 +00:00
app_v2.go refactor: remove capability module (#15344) 2023-03-10 12:59:10 +00:00
app.go refactor: remove capability module (#15344) 2023-03-10 12:59:10 +00:00
export.go refactor: rename commands to match consensus engine name (#14956) 2023-02-08 20:09:28 +00:00
genesis_account_test.go refactor!: migrate Cosmos SDK to CometBFT (#14897) 2023-02-05 14:51:33 +01:00
genesis_account.go x/auth: remove alias.go usage (#6440) 2020-06-17 14:42:27 -04:00
genesis.go fix: app config and simapp (v1,v2) fixes (#14209) 2022-12-08 23:08:40 +01:00
go.mod build(deps): Bump cosmossdk.io/log from 0.0.0-20230313123454-0fe816b71a62 to 0.1.0 (#15371) 2023-03-13 15:07:47 +00:00
go.sum build(deps): Bump cosmossdk.io/log from 0.0.0-20230313123454-0fe816b71a62 to 0.1.0 (#15371) 2023-03-13 15:07:47 +00:00
README.md refactor: rename commands to match consensus engine name (#14956) 2023-02-08 20:09:28 +00:00
sim_bench_test.go refactor!: extract AppStateFn out of simapp (#14977) 2023-02-09 14:16:07 +00:00
sim_test.go fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303) 2023-03-13 17:15:39 +00:00
sonar-project.properties ci: make sonarcloud more quiet (#14585) 2023-01-12 10:24:56 +00:00
test_helpers.go fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303) 2023-03-13 17:15:39 +00:00
testutil_network_test.go refactor: create go.mod for simapp (#13130) 2022-09-07 18:14:22 +00:00
upgrades.go refactor: fix lint issues + gofumpt (#15062) 2023-02-19 10:31:49 +00:00

sidebar_position
1

SimApp

SimApp is an application built using the Cosmos SDK for testing and educational purposes.

Running testnets with simd

If you want to spin up a quick testnet with your friends, you can follow these steps. Unless otherwise noted, every step must be done by everyone who wants to participate in this testnet.

  1. From the root directory of the Cosmos SDK repository, run $ make build. This will build the simd binary inside a new build directory. The following instructions are run from inside the build directory.

  2. If you've run simd before, you may need to reset your database before starting a new testnet. You can reset your database with the following command: $ ./simd comet unsafe-reset-all.

  3. $ ./simd init [moniker] --chain-id [chain-id]. This will initialize a new working directory at the default location ~/.simapp. You need to provide a "moniker" and a "chain id". These two names can be anything, but you will need to use the same "chain id" in the following steps.

  4. $ ./simd keys add [key_name]. This will create a new key, with a name of your choosing. Save the output of this command somewhere; you'll need the address generated here later.

  5. $ ./simd genesis add-genesis-account [key_name] [amount], where key_name is the same key name as before; and amount is something like 10000000000000000000000000stake.

  6. $ ./simd genesis gentx [key_name] [amount] --chain-id [chain-id]. This will create the genesis transaction for your new chain. Here amount should be at least 1000000000stake. If you provide too much or too little, you will encounter an error when starting your node.

  7. Now, one person needs to create the genesis file genesis.json using the genesis transactions from every participant, by gathering all the genesis transactions under config/gentx and then calling $ ./simd genesis collect-gentxs. This will create a new genesis.json file that includes data from all the validators (we sometimes call it the "super genesis file" to distinguish it from single-validator genesis files).

  8. Once you've received the super genesis file, overwrite your original genesis.json file with the new super genesis.json.

  9. Modify your config/config.toml (in the simapp working directory) to include the other participants as persistent peers:

    # Comma separated list of nodes to keep persistent connections to
    persistent_peers = "[validator_address]@[ip_address]:[port],[validator_address]@[ip_address]:[port]"
    

    You can find validator_address by running $ ./simd comet show-node-id. The output will be the hex-encoded validator_address. The default port is 26656.

  10. Now you can start your nodes: $ ./simd start.

Now you have a small testnet that you can use to try out changes to the Cosmos SDK or CometBFT!

NOTE: Sometimes creating the network through the collect-gentxs will fail, and validators will start in a funny state (and then panic). If this happens, you can try to create and start the network first with a single validator and then add additional validators using a create-validator transaction.