diff --git a/CHANGELOG.md b/CHANGELOG.md index c86ba3ed774a..00b8c70eb9d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,10 +37,17 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements + +* (client/tx) [#18852](https://github.com/cosmos/cosmos-sdk/pull/18852) Add `WithFromName` to tx factory. +* (types) [#18875](https://github.com/cosmos/cosmos-sdk/pull/18875) Speedup coins.Sort() if len(coins) <= 1 +* (testutil) [#18930](https://github.com/cosmos/cosmos-sdk/pull/18930) Add NodeURI for clientCtx. + ## [v0.47.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.7) - 2023-12-20 ### Improvements +* (types) [#18888](https://github.com/cosmos/cosmos-sdk/pull/18888) Speedup DecCoin.Sort() if len(coins) <= 1 * (x/gov) [#18707](https://github.com/cosmos/cosmos-sdk/pull/18707) Improve genesis validation. * (server) [#18478](https://github.com/cosmos/cosmos-sdk/pull/18478) Add command flag to disable colored logs. diff --git a/client/tx/factory.go b/client/tx/factory.go index 6eee79894117..d6ae20a0e11d 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -130,6 +130,7 @@ func (f Factory) Fees() sdk.Coins { return f.fees } func (f Factory) GasPrices() sdk.DecCoins { return f.gasPrices } func (f Factory) AccountRetriever() client.AccountRetriever { return f.accountRetriever } func (f Factory) TimeoutHeight() uint64 { return f.timeoutHeight } +func (f Factory) FromName() string { return f.fromName } // SimulateAndExecute returns the option to simulate and then execute the transaction // using the gas from the simulation results @@ -201,6 +202,13 @@ func (f Factory) WithKeybase(keybase keyring.Keyring) Factory { return f } +// WithFromName returns a copy of the Factory with updated fromName +// fromName will be use for building a simulation tx. +func (f Factory) WithFromName(fromName string) Factory { + f.fromName = fromName + return f +} + // WithSequence returns a copy of the Factory with an updated sequence number. func (f Factory) WithSequence(sequence uint64) Factory { f.sequence = sequence diff --git a/testutil/network/network.go b/testutil/network/network.go index ef065d9e68b8..d89c47655b2c 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -550,7 +550,8 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) { WithCodec(cfg.Codec). WithLegacyAmino(cfg.LegacyAmino). WithTxConfig(cfg.TxConfig). - WithAccountRetriever(cfg.AccountRetriever) + WithAccountRetriever(cfg.AccountRetriever). + WithNodeURI(tmCfg.RPC.ListenAddress) // Provide ChainID here since we can't modify it in the Comet config. ctx.Viper.Set(flags.FlagChainID, cfg.ChainID) diff --git a/types/coin.go b/types/coin.go index ec3c90f3527c..daf29a37ca0a 100644 --- a/types/coin.go +++ b/types/coin.go @@ -827,7 +827,12 @@ var _ sort.Interface = Coins{} // Sort is a helper function to sort the set of coins in-place func (coins Coins) Sort() Coins { - sort.Sort(coins) + // sort.Sort(coins) does a costly runtime copy as part of `runtime.convTSlice` + // So we avoid this heap allocation if len(coins) <= 1. In the future, we should hopefully find + // a strategy to always avoid this. + if len(coins) > 1 { + sort.Sort(coins) + } return coins } diff --git a/types/dec_coin.go b/types/dec_coin.go index 42ff885d58a6..1b515eac9c15 100644 --- a/types/dec_coin.go +++ b/types/dec_coin.go @@ -611,7 +611,12 @@ func (coins DecCoins) Swap(i, j int) { coins[i], coins[j] = coins[j], coins[i] } // Sort is a helper function to sort the set of decimal coins in-place. func (coins DecCoins) Sort() DecCoins { - sort.Sort(coins) + // sort.Sort(coins) does a costly runtime copy as part of `runtime.convTSlice` + // So we avoid this heap allocation if len(coins) <= 1. In the future, we should hopefully find + // a strategy to always avoid this. + if len(coins) > 1 { + sort.Sort(coins) + } return coins }