fix(sim): make testutil/network genesis state deterministic (#18203)

This commit is contained in:
Elias Naur 2023-10-23 14:46:25 -05:00 committed by GitHub
parent 33183fe4c8
commit c1f050ffd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -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

View File

@ -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