From c1f050ffd69288d4d684633e3e0c72299269300a Mon Sep 17 00:00:00 2001 From: Elias Naur <103319121+elias-orijtech@users.noreply.github.com> Date: Mon, 23 Oct 2023 14:46:25 -0500 Subject: [PATCH] fix(sim): make testutil/network genesis state deterministic (#18203) --- testutil/network/network.go | 13 +++++++------ testutil/network/util.go | 5 ++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/testutil/network/network.go b/testutil/network/network.go index 8fc1266045f8..58a35e1e9f5d 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -113,6 +113,7 @@ type Config struct { AccountRetriever client.AccountRetriever AppConstructor AppConstructor // the ABCI application constructor GenesisState map[string]json.RawMessage // custom genesis state to provide + GenesisTime time.Time // the genesis time TimeoutCommit time.Duration // the consensus commitment timeout ChainID string // the network chain-id NumValidators int // the total number of validators to create and bond @@ -477,7 +478,12 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) { cmtCfg.P2P.AddrBookStrict = false cmtCfg.P2P.AllowDuplicateIP = true - nodeID, pubKey, err := genutil.InitializeNodeValidatorFiles(cmtCfg) + var mnemonic string + if i < len(cfg.Mnemonics) { + mnemonic = cfg.Mnemonics[i] + } + + nodeID, pubKey, err := genutil.InitializeNodeValidatorFilesFromMnemonic(cmtCfg, mnemonic) if err != nil { return nil, err } @@ -496,11 +502,6 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) { return nil, err } - var mnemonic string - if i < len(cfg.Mnemonics) { - mnemonic = cfg.Mnemonics[i] - } - addr, secret, err := testutil.GenerateSaveCoinKey(kb, nodeDirName, mnemonic, true, algo) if err != nil { return nil, err diff --git a/testutil/network/util.go b/testutil/network/util.go index 6fda96924497..ecc5c54f73f5 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -122,7 +122,10 @@ func startInProcess(cfg Config, val *Validator) error { } func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { - genTime := cmttime.Now() + genTime := cfg.GenesisTime + if genTime.IsZero() { + genTime = cmttime.Now() + } for i := 0; i < cfg.NumValidators; i++ { cmtCfg := vals[i].Ctx.Config