2019-06-14 07:10:37 -07:00
|
|
|
package bank_test
|
2018-06-27 15:33:56 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-01-30 13:31:16 -08:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-06-05 16:26:17 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
2019-08-19 06:29:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
2020-07-14 10:33:31 -07:00
|
|
|
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
2018-06-27 15:33:56 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-05-20 12:21:00 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
2020-06-17 11:42:27 -07:00
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
2020-06-12 07:54:37 -07:00
|
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
2018-06-27 15:33:56 -07:00
|
|
|
)
|
|
|
|
|
2020-06-17 11:42:27 -07:00
|
|
|
var moduleAccAddr = authtypes.NewModuleAddress(stakingtypes.BondedPoolName)
|
2018-07-06 13:19:11 -07:00
|
|
|
|
2018-06-27 15:33:56 -07:00
|
|
|
func BenchmarkOneBankSendTxPerBlock(b *testing.B) {
|
|
|
|
// Add an account at genesis
|
2020-06-17 11:42:27 -07:00
|
|
|
acc := authtypes.BaseAccount{
|
2018-06-27 15:33:56 -07:00
|
|
|
Address: addr1,
|
|
|
|
}
|
|
|
|
|
2020-01-30 13:31:16 -08:00
|
|
|
// construct genesis state
|
2020-05-20 12:21:00 -07:00
|
|
|
genAccs := []types.GenesisAccount{&acc}
|
2019-08-19 06:29:17 -07:00
|
|
|
benchmarkApp := simapp.SetupWithGenesisAccounts(genAccs)
|
2020-01-30 13:31:16 -08:00
|
|
|
ctx := benchmarkApp.BaseApp.NewContext(false, abci.Header{})
|
|
|
|
|
|
|
|
// some value conceivably higher than the benchmarks would ever go
|
|
|
|
err := benchmarkApp.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000)))
|
|
|
|
require.NoError(b, err)
|
|
|
|
|
|
|
|
benchmarkApp.Commit()
|
2020-07-20 05:30:12 -07:00
|
|
|
txGen := simappparams.MakeEncodingConfig().TxConfig
|
2019-08-19 06:29:17 -07:00
|
|
|
|
2018-06-27 15:33:56 -07:00
|
|
|
// Precompute all txs
|
2020-07-14 10:33:31 -07:00
|
|
|
txs, err := simapp.GenSequenceOfTxs(txGen, []sdk.Msg{sendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1)
|
|
|
|
require.NoError(b, err)
|
2018-06-27 15:33:56 -07:00
|
|
|
b.ResetTimer()
|
2020-01-30 13:31:16 -08:00
|
|
|
|
|
|
|
height := int64(3)
|
|
|
|
|
2018-06-27 15:33:56 -07:00
|
|
|
// Run this with a profiler, so its easy to distinguish what time comes from
|
|
|
|
// Committing, and what time comes from Check/Deliver Tx.
|
|
|
|
for i := 0; i < b.N; i++ {
|
2020-01-30 13:31:16 -08:00
|
|
|
benchmarkApp.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: height}})
|
2019-12-27 09:57:54 -08:00
|
|
|
_, _, err := benchmarkApp.Check(txs[i])
|
|
|
|
if err != nil {
|
2018-06-27 15:33:56 -07:00
|
|
|
panic("something is broken in checking transaction")
|
|
|
|
}
|
2019-12-27 09:57:54 -08:00
|
|
|
|
2020-03-20 12:24:18 -07:00
|
|
|
_, _, err = benchmarkApp.Deliver(txs[i])
|
|
|
|
require.NoError(b, err)
|
2020-01-30 13:31:16 -08:00
|
|
|
benchmarkApp.EndBlock(abci.RequestEndBlock{Height: height})
|
2018-06-27 15:33:56 -07:00
|
|
|
benchmarkApp.Commit()
|
2020-01-30 13:31:16 -08:00
|
|
|
height++
|
2018-06-27 15:33:56 -07:00
|
|
|
}
|
|
|
|
}
|
2019-02-04 15:58:02 -08:00
|
|
|
|
|
|
|
func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) {
|
|
|
|
// Add an account at genesis
|
2020-06-17 11:42:27 -07:00
|
|
|
acc := authtypes.BaseAccount{
|
2019-02-04 15:58:02 -08:00
|
|
|
Address: addr1,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct genesis state
|
2020-06-17 11:42:27 -07:00
|
|
|
genAccs := []authtypes.GenesisAccount{&acc}
|
2019-08-19 06:29:17 -07:00
|
|
|
benchmarkApp := simapp.SetupWithGenesisAccounts(genAccs)
|
2020-01-30 13:31:16 -08:00
|
|
|
ctx := benchmarkApp.BaseApp.NewContext(false, abci.Header{})
|
|
|
|
|
|
|
|
// some value conceivably higher than the benchmarks would ever go
|
|
|
|
err := benchmarkApp.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000)))
|
|
|
|
require.NoError(b, err)
|
|
|
|
|
|
|
|
benchmarkApp.Commit()
|
2020-07-20 05:30:12 -07:00
|
|
|
txGen := simappparams.MakeEncodingConfig().TxConfig
|
2019-08-19 06:29:17 -07:00
|
|
|
|
2019-02-04 15:58:02 -08:00
|
|
|
// Precompute all txs
|
2020-07-14 10:33:31 -07:00
|
|
|
txs, err := simapp.GenSequenceOfTxs(txGen, []sdk.Msg{multiSendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1)
|
|
|
|
require.NoError(b, err)
|
2019-02-04 15:58:02 -08:00
|
|
|
b.ResetTimer()
|
2020-01-30 13:31:16 -08:00
|
|
|
|
|
|
|
height := int64(3)
|
|
|
|
|
2019-02-04 15:58:02 -08:00
|
|
|
// Run this with a profiler, so its easy to distinguish what time comes from
|
|
|
|
// Committing, and what time comes from Check/Deliver Tx.
|
|
|
|
for i := 0; i < b.N; i++ {
|
2020-01-30 13:31:16 -08:00
|
|
|
benchmarkApp.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: height}})
|
2019-12-27 09:57:54 -08:00
|
|
|
_, _, err := benchmarkApp.Check(txs[i])
|
|
|
|
if err != nil {
|
2019-02-04 15:58:02 -08:00
|
|
|
panic("something is broken in checking transaction")
|
|
|
|
}
|
2019-12-27 09:57:54 -08:00
|
|
|
|
2020-03-20 12:24:18 -07:00
|
|
|
_, _, err = benchmarkApp.Deliver(txs[i])
|
|
|
|
require.NoError(b, err)
|
2020-01-30 13:31:16 -08:00
|
|
|
benchmarkApp.EndBlock(abci.RequestEndBlock{Height: height})
|
2019-02-04 15:58:02 -08:00
|
|
|
benchmarkApp.Commit()
|
2020-01-30 13:31:16 -08:00
|
|
|
height++
|
2019-02-04 15:58:02 -08:00
|
|
|
}
|
|
|
|
}
|