Skip to content

Commit

Permalink
chore: x/genutil: cleanup CollectTxs
Browse files Browse the repository at this point in the history
This change moves []os.DirEntry close to where it is used
and also reuses the already created sdk.AccAddress.String()
[]byte->string (sure it is cached but unnecessary to re-invoke)
as a key to the balancesMap.

Fixes #17814
  • Loading branch information
odeke-em committed Sep 20, 2023
1 parent 86ab989 commit 4da52f3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions x/genutil/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx
return appGenTxs, persistentPeers, err
}

var fos []os.DirEntry
fos, err = os.ReadDir(genTxsDir)
if err != nil {
return appGenTxs, persistentPeers, err
}

balancesMap := make(map[string]bankexported.GenesisBalance)

genBalIterator.IterateGenesisBalances(
Expand All @@ -93,9 +87,17 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx
},
)

fos, err := os.ReadDir(genTxsDir)
if err != nil {
return appGenTxs, persistentPeers, err
}

// addresses and IPs (and port) validator server info
var addressesIPs []string

// TODO (https://github.com/cosmos/cosmos-sdk/issues/17815):
// Examine CPU and RAM profiles to see if we can parsing
// and ValidateAndGetGenTx concurrent.
for _, fo := range fos {
if fo.IsDir() {
continue
Expand Down Expand Up @@ -151,7 +153,7 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx
return appGenTxs, persistentPeers, fmt.Errorf("account %s balance not in genesis state: %+v", valAccAddr, balancesMap)
}

_, valOk := balancesMap[sdk.AccAddress(valAddr).String()]
_, valOk := balancesMap[valAccAddr]
if !valOk {
_, file, no, ok := runtime.Caller(1)
if ok {
Expand Down

0 comments on commit 4da52f3

Please sign in to comment.