Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): in-place testnet creator #19280

Merged
merged 16 commits into from
Feb 12, 2024
Prev Previous commit
Next Next commit
remove leaking resource
  • Loading branch information
czarcas7ic committed Jan 29, 2024
commit 684ca39d085d4eef9d27db34a9cc87cb9db00cdb
10 changes: 2 additions & 8 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@
}

if isTestnet, ok := svrCtx.Viper.Get(KeyIsTestnet).(bool); ok && isTestnet {
Copy link
Contributor

@alexanderbez alexanderbez Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what is the relationship between the start command, which checks KeyIsTestnet, and the new testnet command?

Copy link
Contributor Author

@czarcas7ic czarcas7ic Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The testnet command and the start command are essentially identical except:

  1. The testnet command provides 2 inputs necessary for making the testnet
  2. The testnet command runs the testnetify logic before returning the app from the appCreator
  3. The pubkey and validator address retrieved from testnetify are stored to viper keys which are used at the application level

I am not sure if this answers your question, please lmk if you wanted clarification on something else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not sure this needs to exist. I may be missing something but this tool should only modify the underlying db.

app, err = testnetify(svrCtx, home, appCreator, db)
app, err = testnetify(svrCtx, home, appCreator, db, traceWriter)
if err != nil {
return app, traceCleanupFn, err
}
Expand Down Expand Up @@ -633,8 +633,8 @@

Additionally, the first block may take up to one minute to be committed, depending
on how old the block is. For instance, if a snapshot was taken weeks ago and we want
to turn this into a testnet, it is possible lots of pending state needs to be commited

Check failure on line 636 in server/start.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`commited` is a misspelling of `committed` (misspell)

Check failure on line 636 in server/start.go

View workflow job for this annotation

GitHub Actions / Analyze

`commited` is a misspelling of `committed` (misspell)
(expiring locks, etc.). It is recommended that you should wait for this block to be commited

Check failure on line 637 in server/start.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`commited` is a misspelling of `committed` (misspell)

Check failure on line 637 in server/start.go

View workflow job for this annotation

GitHub Actions / Analyze

`commited` is a misspelling of `committed` (misspell)
before stopping the daemon.
`,
Example: "in-place-testnet localosmosis osmo12smx2wdlyttvyzvzg54y2vnqwq2qjateuf7thj",
Expand Down Expand Up @@ -665,7 +665,7 @@
text, _ := reader.ReadString('\n')
response := strings.TrimSpace(strings.ToLower(text))
if response != "y" && response != "yes" {
fmt.Println("Operation cancelled.")

Check failure on line 668 in server/start.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`cancelled` is a misspelling of `canceled` (misspell)

Check failure on line 668 in server/start.go

View workflow job for this annotation

GitHub Actions / Analyze

`cancelled` is a misspelling of `canceled` (misspell)
return nil
}

Expand Down Expand Up @@ -697,20 +697,14 @@

// 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.
func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, db dbm.DB) (types.Application, error) {
func testnetify(ctx *Context, home string, testnetAppCreator types.AppCreator, db dbm.DB, traceWriter io.WriteCloser) (types.Application, error) {
config := ctx.Config

newChainID, ok := ctx.Viper.Get(KeyNewChainID).(string)
if !ok {
return nil, fmt.Errorf("expected string for key %s", KeyNewChainID)
}

traceWriterFile := ctx.Viper.GetString(flagTraceStore)
traceWriter, err := openTraceWriter(traceWriterFile)
if err != nil {
return nil, err
}

genDocProvider := node.DefaultGenesisDocProviderFunc(config)

// Initialize blockStore and stateDB.
Expand Down Expand Up @@ -758,7 +752,7 @@
}

// There are times when a user stops their node between commits, resulting in a mismatch between the
// blockStore and state. For convenience, we just discard the uncommited blockStore block and operate on

Check failure on line 755 in server/start.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`uncommited` is a misspelling of `uncommitted` (misspell)

Check failure on line 755 in server/start.go

View workflow job for this annotation

GitHub Actions / Analyze

`uncommited` is a misspelling of `uncommitted` (misspell)
// the lastBlockHeight in state.
if blockStore.Height() != state.LastBlockHeight {
err = blockStore.DeleteLatestBlock()
Expand All @@ -781,7 +775,7 @@
Height: state.LastBlockHeight,
Round: 0,
BlockID: state.LastBlockID,
Timestamp: time.Now(),

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, this is the only validator in the set, set setting the timestamp to local time is a non issue.

ValidatorAddress: validatorAddress,
ValidatorIndex: 0,
Signature: []byte{},
Expand Down
Loading