Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix benchmark #596

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions benchmark/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@ var (
PrivE = tsstestutil.HexDecode("3ff4fb2beac0cee0ab230829a5ae0881310046282e79c978ca22f44897ea434a")
PubD = tss.Scalar(PrivD).Point()
PubE = tss.Scalar(PrivE).Point()

DELen = 30
)

func GetDEs() []tsstypes.DE {
func GetDEs(deLen int) []tsstypes.DE {
var delist []tsstypes.DE
for i := 0; i < DELen; i++ {
for i := 0; i < deLen; i++ {
delist = append(delist, tsstypes.DE{PubD: PubD, PubE: PubE})
}
return delist
Expand All @@ -76,19 +74,20 @@ func InitializeBenchmarkApp(tb testing.TB, maxGasPerBlock int64) *BenchmarkApp {
ba := &BenchmarkApp{
BandApp: app,
Sender: &Account{
Account: bandtesting.Owner,
Num: 0,
Account: bandtesting.Treasury,
Num: 1,
Seq: 0,
},
Validator: &Account{
Account: bandtesting.Validators[0],
Num: 6,
Num: 7,
Seq: 0,
},
}

ba.TB = tb
ba.Ctx = ba.NewUncachedContext(false, cmtproto.Header{ChainID: bandtesting.ChainID})
ba.Ctx = ba.NewUncachedContext(false, cmtproto.Header{ChainID: bandtesting.ChainID}).
WithBlockTime(time.Unix(1000000, 0))
ba.TSSMsgSrvr = tsskeeper.NewMsgServerImpl(ba.TSSKeeper)
ba.BandtssMsgSrvr = bandtsskeeper.NewMsgServerImpl(ba.BandtssKeeper)
ba.Querier = keeper.Querier{
Expand Down Expand Up @@ -125,19 +124,27 @@ func InitializeBenchmarkApp(tb testing.TB, maxGasPerBlock int64) *BenchmarkApp {
)

res, err := ba.FinalizeBlock(
&abci.RequestFinalizeBlock{Txs: txs, Height: ba.LastBlockHeight() + 1, Time: time.Now()},
&abci.RequestFinalizeBlock{Txs: txs, Height: ba.LastBlockHeight() + 1, Time: ba.Ctx.BlockTime()},
)
require.NoError(tb, err)

for _, tx := range res.TxResults {
require.Equal(tb, uint32(0), tx.Code)
}

// get gov address
ba.Authority = authtypes.NewModuleAddress(govtypes.ModuleName)
ba.PrivKeyStore = make(map[string]tss.Scalar)

_, err = ba.FinalizeBlock(
&abci.RequestFinalizeBlock{Height: ba.LastBlockHeight() + 1, Time: time.Now()},
&abci.RequestFinalizeBlock{Height: ba.LastBlockHeight() + 1, Time: ba.Ctx.BlockTime()},
)
require.NoError(tb, err)

for _, tx := range res.TxResults {
require.Equal(tb, uint32(0), tx.Code)
}

_, err = ba.Commit()
require.NoError(tb, err)

Expand Down Expand Up @@ -217,7 +224,7 @@ func (ba *BenchmarkApp) SetupTSSGroup() {
IsActive: true,
})
_, err := msgSrvr.SubmitDEs(ctx, &tsstypes.MsgSubmitDEs{
DEs: GetDEs(),
DEs: GetDEs(300),
Sender: ba.Sender.Address.String(),
})
require.NoError(ba.TB, err)
Expand Down Expand Up @@ -322,9 +329,9 @@ func (ba *BenchmarkApp) AddDEs(addr sdk.AccAddress) {

deQueue := k.GetDEQueue(ctx, addr)
count := deQueue.Tail - deQueue.Head
if count < uint64(DELen) {
if count < uint64(30) {
_, err := msgSrvr.SubmitDEs(ctx, &tsstypes.MsgSubmitDEs{
DEs: GetDEs(),
DEs: GetDEs(30),
Sender: addr.String(),
})
require.NoError(ba.TB, err)
Expand Down
54 changes: 36 additions & 18 deletions benchmark/feeds_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/rand"
"sort"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -66,12 +65,12 @@ func BenchmarkSubmitSignalPricesDeliver(b *testing.B) {
params, err := ba.StakingKeeper.GetParams(ba.Ctx)
require.NoError(b, err)

numVals := params.MaxValidators
numVals := params.MaxValidators - 5 // some validators are already activated

vals, err := generateValidators(ba, int(numVals))
require.NoError(b, err)

err = setupFeeds(ba)
err = setupFeeds(ba, 300)
require.NoError(b, err)

err = setupValidatorPriceList(ba, vals)
Expand Down Expand Up @@ -100,12 +99,16 @@ func BenchmarkSubmitSignalPricesDeliver(b *testing.B) {
&abci.RequestFinalizeBlock{
Txs: txs,
Height: ba.LastBlockHeight() + 1,
Time: time.Now(),
Time: ba.Ctx.BlockTime(),
},
)
b.StopTimer()

require.NoError(b, err)
for _, tx := range res.TxResults {
require.Equal(b, uint32(0), tx.Code)
}

b.StopTimer()
_, err = ba.Commit()
require.NoError(b, err)

Expand All @@ -131,7 +134,7 @@ func BenchmarkFeedsEndBlock(b *testing.B) {
vals, err := generateValidators(ba, int(numVals))
require.NoError(b, err)

err = setupFeeds(ba)
err = setupFeeds(ba, 300)
require.NoError(b, err)

err = setupValidatorPrices(ba, vals)
Expand All @@ -144,23 +147,25 @@ func BenchmarkFeedsEndBlock(b *testing.B) {
for i := 0; i < b.N; i++ {
// process endblock
b.StartTimer()
_, err := ba.FinalizeBlock(
res, err := ba.FinalizeBlock(
&abci.RequestFinalizeBlock{
Height: ba.LastBlockHeight() + 1,
Time: time.Now(),
Time: ba.Ctx.BlockTime(),
},
)
require.NoError(b, err)
b.StopTimer()

require.NoError(b, err)
for _, tx := range res.TxResults {
require.Equal(b, uint32(0), tx.Code)
}

_, err = ba.Commit()
require.NoError(b, err)
}
}

func setupFeeds(ba *BenchmarkApp) error {
numFeeds := ba.FeedsKeeper.GetParams(ba.Ctx).MaxCurrentFeeds

func setupFeeds(ba *BenchmarkApp, numFeeds uint64) error {
feeds := []types.Feed{}
for i := uint64(0); i < numFeeds; i++ {
feeds = append(feeds, types.Feed{
Expand Down Expand Up @@ -230,24 +235,31 @@ func generateValidators(ba *BenchmarkApp, num int) ([]*Account, error) {
tx := GenSequenceOfTxs(
ba.TxEncoder,
ba.TxConfig,
[]sdk.Msg{banktypes.NewMsgSend(ba.Sender.Address, acc.Address, sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(1))))},
[]sdk.Msg{banktypes.NewMsgSend(ba.Sender.Address, acc.Address, bandtesting.Coins100band)},
ba.Sender,
1,
)[0]

txs = append(txs, tx)
}

_, err := ba.FinalizeBlock(
res, err := ba.FinalizeBlock(
&abci.RequestFinalizeBlock{
Txs: txs,
Height: ba.LastBlockHeight() + 1,
Time: time.Now(),
Time: ba.Ctx.BlockTime(),
},
)
if err != nil {
return nil, err
}

for _, tx := range res.TxResults {
if tx.Code != 0 {
return nil, fmt.Errorf("transfer error: %s", tx.Log)
}
}

_, err = ba.Commit()
if err != nil {
return nil, err
Expand All @@ -268,7 +280,7 @@ func generateValidators(ba *BenchmarkApp, num int) ([]*Account, error) {
msgCreateVal, err := stakingtypes.NewMsgCreateValidator(
val.ValAddress.String(),
val.PubKey,
sdk.NewCoin("uband", sdkmath.NewInt(150000000)),
sdk.NewCoin("uband", sdkmath.NewInt(1000000)),
stakingtypes.NewDescription(val.Address.String(), val.Address.String(), "", "", ""),
stakingtypes.NewCommissionRates(sdkmath.LegacyNewDec(1), sdkmath.LegacyNewDec(1), sdkmath.LegacyNewDec(1)),
sdkmath.NewInt(1),
Expand All @@ -290,17 +302,23 @@ func generateValidators(ba *BenchmarkApp, num int) ([]*Account, error) {
txs = append(txs, tx)
}

_, err = ba.FinalizeBlock(
res, err = ba.FinalizeBlock(
&abci.RequestFinalizeBlock{
Txs: txs,
Height: ba.LastBlockHeight() + 1,
Time: time.Now(),
Time: ba.Ctx.BlockTime(),
},
)
if err != nil {
return nil, err
}

for _, tx := range res.TxResults {
if tx.Code != 0 {
return nil, fmt.Errorf("validator error: %s", tx.Log)
}
}

_, err = ba.Commit()
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions benchmark/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ func InitOwasmTestEnv(
Value: parameter,
Text: strings.Repeat("#", stringLength),
}), []sdk.ValAddress{[]byte{}}, 1,
1, time.Now(), "", nil, nil, ExecuteGasLimit, 0,
1, time.Unix(1000000, 0), "", nil, nil, ExecuteGasLimit, 0,
bandtesting.FeePayer.Address.String(),
bandtesting.Coins100000000uband,
bandtesting.Coins100band,
)

return owasmVM, compiledCode, req
Expand Down
14 changes: 7 additions & 7 deletions benchmark/bench_test.go → benchmark/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ func BenchmarkBlockOracleMsgRequestData(b *testing.B) {
&abci.RequestFinalizeBlock{
Txs: txs,
Height: ba.LastBlockHeight() + 1,
Time: time.Now(),
Time: ba.Ctx.BlockTime(),
},
)
require.NoError(b, err)

b.StopTimer()

require.NoError(b, err)

if i == 0 {
if res.TxResults[len(res.TxResults)-1].Code != 0 {
fmt.Println("\tDeliver Error:", res.TxResults[0].Log)
Expand Down Expand Up @@ -368,7 +368,7 @@ func BenchmarkBlockOracleMsgReportData(b *testing.B) {
&abci.RequestFinalizeBlock{
Txs: txs,
Height: ba.LastBlockHeight() + 1,
Time: time.Now(),
Time: ba.Ctx.BlockTime(),
},
)
require.NoError(b, err)
Expand All @@ -394,13 +394,13 @@ func BenchmarkBlockOracleMsgReportData(b *testing.B) {
&abci.RequestFinalizeBlock{
Txs: [][]byte{tx},
Height: ba.LastBlockHeight() + 1,
Time: time.Now(),
Time: ba.Ctx.BlockTime(),
},
)
require.NoError(b, err)

b.StopTimer()

require.NoError(b, err)

if i == 0 {
if res.TxResults[len(res.TxResults)-1].Code != 0 {
fmt.Println("\tDeliver Error:", res.TxResults[0].Log)
Expand Down
21 changes: 18 additions & 3 deletions benchmark/tss_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ func BenchmarkRequestSignatureDeliver(b *testing.B) {
b.N,
)

_, err := ba.FinalizeBlock(
res, err := ba.FinalizeBlock(
&abci.RequestFinalizeBlock{Height: ba.LastBlockHeight() + 1, Hash: ba.LastCommitID().Hash},
)
require.NoError(b, err)

for _, tx := range res.TxResults {
require.Equal(b, uint32(0), tx.Code)
}

b.ResetTimer()
b.StopTimer()

Expand Down Expand Up @@ -83,11 +87,15 @@ func BenchmarkSubmitSignatureDeliver(b *testing.B) {
ba := InitializeBenchmarkApp(b, -1)
ba.SetupTSSGroup()

_, err := ba.FinalizeBlock(
res, err := ba.FinalizeBlock(
&abci.RequestFinalizeBlock{Height: ba.LastBlockHeight() + 1, Hash: ba.LastCommitID().Hash},
)
require.NoError(b, err)

for _, tx := range res.TxResults {
require.Equal(b, uint32(0), tx.Code)
}

b.ResetTimer()
b.StopTimer()

Expand Down Expand Up @@ -136,14 +144,18 @@ func BenchmarkEndBlockHandleProcessSigning(b *testing.B) {

// deliver MsgSubmitSignature to the block
for i := 0; i < b.N; i++ {
_, err := ba.FinalizeBlock(
res, err := ba.FinalizeBlock(
&abci.RequestFinalizeBlock{
Height: ba.LastBlockHeight() + 1,
Hash: ba.LastCommitID().Hash,
},
)
require.NoError(b, err)

for _, tx := range res.TxResults {
require.Equal(b, uint32(0), tx.Code)
}

gid := ba.BandtssKeeper.GetCurrentGroup(ba.Ctx).GroupID
require.NotZero(b, gid)

Expand Down Expand Up @@ -172,6 +184,9 @@ func BenchmarkEndBlockHandleProcessSigning(b *testing.B) {
b.StopTimer()

require.NoError(b, err)
for _, tx := range res.TxResults {
require.Equal(b, uint32(0), tx.Code)
}

_, err = ba.Commit()
require.NoError(b, err)
Expand Down
Loading
Loading