From feaa1ed17e00f10450f9263ed18c293cf6fa368a Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Wed, 12 Aug 2020 10:24:44 +0200 Subject: [PATCH] state: don't save genesis state in database when loaded (#5231) Fixes #5138. I don't have a strong opinion on this, but find it sort of odd that `Load` functions actually save as well. --- CHANGELOG_PENDING.md | 1 + node/node.go | 5 ++--- state/state_test.go | 1 + state/store.go | 8 ++------ 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index beab55b60..be7726b7b 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -17,6 +17,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi - [merkle] [\#5193](https://github.com/tendermint/tendermint/pull/5193) `HashFromByteSlices` and `ProofsFromByteSlices` now return a hash for empty inputs, following RFC6962 (@erikgrinaker) - [crypto] [\#5214] Change `GenPrivKeySecp256k1` to `GenPrivKeyFromSecret` to be consistent with other keys - [state] [\#5191](https://github.com/tendermint/tendermint/pull/5191/files) Add `State.InitialHeight` field to record initial block height, must be `1` (not `0`) to start from 1 (@erikgrinaker) + - [state] `LoadStateFromDBOrGenesisFile()` and `LoadStateFromDBOrGenesisDoc()` no longer saves the state in the database if not found, the genesis state is simply returned (@erikgrinaker) ### FEATURES: diff --git a/node/node.go b/node/node.go index c58435f4e..9b8d55906 100644 --- a/node/node.go +++ b/node/node.go @@ -1255,9 +1255,8 @@ var ( ) // LoadStateFromDBOrGenesisDocProvider attempts to load the state from the -// database, or creates one using the given genesisDocProvider and persists the -// result to the database. On success this also returns the genesis doc loaded -// through the given provider. +// database, or creates one using the given genesisDocProvider. On success this also +// returns the genesis doc loaded through the given provider. func LoadStateFromDBOrGenesisDocProvider( stateDB dbm.DB, genesisDocProvider GenesisDocProvider, diff --git a/state/state_test.go b/state/state_test.go index 1e1e49a50..b27020d4c 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -32,6 +32,7 @@ func setupTestCase(t *testing.T) (func(t *testing.T), dbm.DB, sm.State) { require.NoError(t, err) state, err := sm.LoadStateFromDBOrGenesisFile(stateDB, config.GenesisFile()) assert.NoError(t, err, "expected no error on LoadStateFromDBOrGenesisFile") + sm.SaveState(stateDB, state) tearDown := func(t *testing.T) { os.RemoveAll(config.RootDir) } diff --git a/state/store.go b/state/store.go index 986dff013..882562943 100644 --- a/state/store.go +++ b/state/store.go @@ -37,8 +37,7 @@ func calcABCIResponsesKey(height int64) []byte { } // LoadStateFromDBOrGenesisFile loads the most recent state from the database, -// or creates a new one from the given genesisFilePath and persists the result -// to the database. +// or creates a new one from the given genesisFilePath. func LoadStateFromDBOrGenesisFile(stateDB dbm.DB, genesisFilePath string) (State, error) { state := LoadState(stateDB) if state.IsEmpty() { @@ -47,15 +46,13 @@ func LoadStateFromDBOrGenesisFile(stateDB dbm.DB, genesisFilePath string) (State if err != nil { return state, err } - SaveState(stateDB, state) } return state, nil } // LoadStateFromDBOrGenesisDoc loads the most recent state from the database, -// or creates a new one from the given genesisDoc and persists the result -// to the database. +// or creates a new one from the given genesisDoc. func LoadStateFromDBOrGenesisDoc(stateDB dbm.DB, genesisDoc *types.GenesisDoc) (State, error) { state := LoadState(stateDB) @@ -65,7 +62,6 @@ func LoadStateFromDBOrGenesisDoc(stateDB dbm.DB, genesisDoc *types.GenesisDoc) ( if err != nil { return state, err } - SaveState(stateDB, state) } return state, nil