BootstrapState saves a new state, used e.g. by state sync when starting from non-zero height.
(state State)
| 205 | |
| 206 | // BootstrapState saves a new state, used e.g. by state sync when starting from non-zero height. |
| 207 | func (store dbStore) Bootstrap(state State) error { |
| 208 | height := state.LastBlockHeight + 1 |
| 209 | if height == 1 { |
| 210 | height = state.InitialHeight |
| 211 | } |
| 212 | |
| 213 | if height > 1 && !state.LastValidators.IsNilOrEmpty() { |
| 214 | if err := store.saveValidatorsInfo(height-1, height-1, state.LastValidators); err != nil { |
| 215 | return err |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | if err := store.saveValidatorsInfo(height, height, state.Validators); err != nil { |
| 220 | return err |
| 221 | } |
| 222 | |
| 223 | if err := store.saveValidatorsInfo(height+1, height+1, state.NextValidators); err != nil { |
| 224 | return err |
| 225 | } |
| 226 | |
| 227 | if err := store.saveConsensusParamsInfo(height, |
| 228 | state.LastHeightConsensusParamsChanged, state.ConsensusParams); err != nil { |
| 229 | return err |
| 230 | } |
| 231 | |
| 232 | return store.db.SetSync(stateKey, state.Bytes()) |
| 233 | } |
| 234 | |
| 235 | // PruneStates deletes states between the given heights (including from, excluding to). It is not |
| 236 | // guaranteed to delete all states, since the last checkpointed state and states being pointed to by |
nothing calls this directly
no test coverage detected