testnetify modifies both state and blockStore, allowing the provided operator address and local validator key to control the network that the state in the data folder represents. The chainID of the local genesis file is modified to match the provided chainID.
(sctx *sdksrv.Context, tcfg TestnetConfig, testnetAppCreator types.AppCreator, db dbm.DB, traceWriter io.WriteCloser)
| 277 | // testnetify modifies both state and blockStore, allowing the provided operator address and local validator key to control the network |
| 278 | // that the state in the data folder represents. The chainID of the local genesis file is modified to match the provided chainID. |
| 279 | func testnetify(sctx *sdksrv.Context, tcfg TestnetConfig, testnetAppCreator types.AppCreator, db dbm.DB, traceWriter io.WriteCloser) (types.Application, error) { |
| 280 | config := sctx.Config |
| 281 | |
| 282 | thisVal := config.PrivValidatorKeyFile() |
| 283 | sort.Slice(tcfg.Validators, func(i, _ int) bool { |
| 284 | return thisVal == tcfg.Validators[i].Home |
| 285 | }) |
| 286 | |
| 287 | // Modify app genesis chain ID and save to a genesis file. |
| 288 | genFilePath := config.GenesisFile() |
| 289 | appGen, err := genutiltypes.AppGenesisFromFile(genFilePath) |
| 290 | if err != nil { |
| 291 | return nil, err |
| 292 | } |
| 293 | |
| 294 | newChainID := tcfg.ChainID |
| 295 | |
| 296 | appGen.ChainID = newChainID |
| 297 | if err := appGen.ValidateAndComplete(); err != nil { |
| 298 | return nil, err |
| 299 | } |
| 300 | if err := appGen.SaveAs(genFilePath); err != nil { |
| 301 | return nil, err |
| 302 | } |
| 303 | |
| 304 | // Load the comet genesis doc provider. |
| 305 | genDocProvider := sdksrv.GetGenDocProvider(config) |
| 306 | |
| 307 | // Initialize blockStore and stateDB. |
| 308 | blockStoreDB, err := cmtcfg.DefaultDBProvider(&cmtcfg.DBContext{ID: "blockstore", Config: config}) |
| 309 | if err != nil { |
| 310 | return nil, err |
| 311 | } |
| 312 | blockStore := store.NewBlockStore(blockStoreDB) |
| 313 | |
| 314 | defer func() { |
| 315 | _ = blockStore.Close() |
| 316 | }() |
| 317 | |
| 318 | stateDB, err := cmtcfg.DefaultDBProvider(&cmtcfg.DBContext{ID: "state", Config: config}) |
| 319 | if err != nil { |
| 320 | return nil, err |
| 321 | } |
| 322 | |
| 323 | defer func() { |
| 324 | _ = stateDB.Close() |
| 325 | }() |
| 326 | |
| 327 | var updatedChecksum []byte |
| 328 | { |
| 329 | genDoc, err := genDocProvider() |
| 330 | if err != nil { |
| 331 | return nil, err |
| 332 | } |
| 333 | |
| 334 | updatedChecksum = genDoc.Sha256Checksum |
| 335 | } |
| 336 |