Skip to content

Commit

Permalink
Give supernova anabolic steroids
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Jun 14, 2024
1 parent c262693 commit 22c5fb9
Show file tree
Hide file tree
Showing 28 changed files with 428 additions and 448 deletions.
Binary file modified .github/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ USAGE
Starts the stress testing suite against a Gno TM2 cluster

FLAGS
-batch 20 the batch size of JSON-RPC transactions
-batch 100 the batch size of JSON-RPC transactions
-chain-id dev the chain ID of the Gno blockchain
-mnemonic ... the mnemonic used to generate sub-accounts
-mnemonic string the mnemonic used to generate sub-accounts
-mode REALM_DEPLOYMENT the mode for the stress test. Possible modes: [REALM_DEPLOYMENT, PACKAGE_DEPLOYMENT, REALM_CALL]
-output ... the output path for the results JSON
-output string the output path for the results JSON
-sub-accounts 10 the number of sub-accounts that will send out transactions
-transactions 100 the total number of transactions to be emitted
-url ... the JSON-RPC URL of the cluster
-url string the JSON-RPC URL of the cluster
```

## Modes
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func registerFlags(fs *flag.FlagSet, c *internal.Config) {
fs.Uint64Var(
&c.BatchSize,
"batch",
20,
100,
"the batch size of JSON-RPC transactions",
)
}
Expand Down
49 changes: 23 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/gnolang/supernova
go 1.21

require (
github.com/gnolang/gno v0.1.0-nightly.20240604
github.com/peterbourgon/ff/v3 v3.4.0
github.com/schollz/progressbar/v3 v3.14.4
github.com/stretchr/testify v1.9.0
Expand All @@ -11,57 +12,53 @@ require (
require (
dario.cat/mergo v1.0.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.opentelemetry.io/otel v1.25.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.25.0 // indirect
go.opentelemetry.io/otel/metric v1.25.0 // indirect
go.opentelemetry.io/otel/sdk v1.25.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.25.0 // indirect
go.opentelemetry.io/otel/trace v1.25.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.0 // indirect
)

require (
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gnolang/gno v0.0.0-20240509142750-711f4d03a167
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.7.15 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/onsi/gomega v1.31.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.9 // indirect
go.opentelemetry.io/otel v1.25.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.25.0 // indirect
go.opentelemetry.io/otel/metric v1.25.0 // indirect
go.opentelemetry.io/otel/sdk v1.25.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.25.0 // indirect
go.opentelemetry.io/otel/trace v1.25.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/gnolang/gno v0.0.0-20240509142750-711f4d03a167 h1:AW+W/XosfOZnhNZejtipmbPM9OzUwc4naEumnF7Tmzk=
github.com/gnolang/gno v0.0.0-20240509142750-711f4d03a167/go.mod h1:vbm5sS6KZj2rkwJ9C6AtdpPZB7aZDhfZ3lJUC+qa/to=
github.com/gnolang/gno v0.1.0-nightly.20240604 h1:1ennenQkBiXVbypporU1R1v3cWf1T6ol7Ava0rvIAKA=
github.com/gnolang/gno v0.1.0-nightly.20240604/go.mod h1:R9GL0bPvjrcZlWBmmQ5wMssKpBdJK/e5mZdUbkk5sV0=
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 h1:GKvsK3oLWG9B1GL7WP/VqwM6C92j5tIvB844oggL9Lk=
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216/go.mod h1:xJhtEL7ahjM1WJipt89gel8tHzfIl/LyMY+lCYh38d8=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -84,8 +84,6 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0/go.mod h1:qmOFXW2epJhM0qSnUUYp
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
Expand All @@ -97,8 +95,6 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
github.com/linxGnu/grocksdb v1.7.15 h1:AEhP28lkeAybv5UYNYviYISpR6bJejEnKuYbnWAnxx0=
github.com/linxGnu/grocksdb v1.7.15/go.mod h1:pY55D0o+r8yUYLq70QmhdudxYvoDb9F+9puf4m3/W+U=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
Expand Down Expand Up @@ -180,6 +176,8 @@ golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
24 changes: 24 additions & 0 deletions internal/client/batch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package client

import (
"context"
"fmt"

"github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
)

type Batch struct {
batch *client.RPCBatch
}

func (b *Batch) AddTxBroadcast(tx []byte) error {
if err := b.batch.BroadcastTxSync(tx); err != nil {
return fmt.Errorf("unable to prepare transaction, %w", err)
}

return nil
}

func (b *Batch) Execute() ([]interface{}, error) {
return b.batch.Send(context.Background())
}
49 changes: 22 additions & 27 deletions internal/client/http_client.go → internal/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"context"
"fmt"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
Expand All @@ -12,47 +11,43 @@ import (
"github.com/gnolang/supernova/internal/common"
)

type Batch struct {
batch *client.RPCBatch
type Client struct {
conn *client.RPCClient
}

func (b *Batch) AddTxBroadcast(tx []byte) error {
if err := b.batch.BroadcastTxSync(tx); err != nil {
return fmt.Errorf("unable to prepare transaction, %w", err)
// NewWSClient creates a new instance of the WS client
func NewWSClient(url string) (*Client, error) {
cli, err := client.NewWSClient(url)
if err != nil {
return nil, fmt.Errorf("unable to create ws client, %w", err)
}

return nil
}

func (b *Batch) Execute() ([]interface{}, error) {
return b.batch.Send(context.Background())
}

type HTTPClient struct {
conn *client.RPCClient
return &Client{
conn: cli,
}, nil
}

// NewHTTPClient creates a new instance of the HTTP client
func NewHTTPClient(url string) (*HTTPClient, error) {
func NewHTTPClient(url string) (*Client, error) {
cli, err := client.NewHTTPClient(url)
if err != nil {
return nil, fmt.Errorf("unable to create http client, %w", err)
}

return &HTTPClient{
return &Client{
conn: cli,
}, nil
}

func (h *HTTPClient) CreateBatch() common.Batch {
func (h *Client) CreateBatch() common.Batch {
return &Batch{batch: h.conn.NewBatch()}
}

func (h *HTTPClient) ExecuteABCIQuery(path string, data []byte) (*core_types.ResultABCIQuery, error) {
func (h *Client) ExecuteABCIQuery(path string, data []byte) (*core_types.ResultABCIQuery, error) {
return h.conn.ABCIQuery(path, data)
}

func (h *HTTPClient) GetLatestBlockHeight() (int64, error) {
func (h *Client) GetLatestBlockHeight() (int64, error) {
status, err := h.conn.Status()
if err != nil {
return 0, fmt.Errorf("unable to fetch status, %w", err)
Expand All @@ -61,19 +56,19 @@ func (h *HTTPClient) GetLatestBlockHeight() (int64, error) {
return status.SyncInfo.LatestBlockHeight, nil
}

func (h *HTTPClient) GetBlock(height *int64) (*core_types.ResultBlock, error) {
func (h *Client) GetBlock(height *int64) (*core_types.ResultBlock, error) {
return h.conn.Block(height)
}

func (h *HTTPClient) GetBlockResults(height *int64) (*core_types.ResultBlockResults, error) {
func (h *Client) GetBlockResults(height *int64) (*core_types.ResultBlockResults, error) {
return h.conn.BlockResults(height)
}

func (h *HTTPClient) GetConsensusParams(height *int64) (*core_types.ResultConsensusParams, error) {
func (h *Client) GetConsensusParams(height *int64) (*core_types.ResultConsensusParams, error) {
return h.conn.ConsensusParams(height)
}

func (h *HTTPClient) BroadcastTransaction(tx *std.Tx) error {
func (h *Client) BroadcastTransaction(tx *std.Tx) error {
marshalledTx, err := amino.Marshal(tx)
if err != nil {
return fmt.Errorf("unable to marshal transaction, %w", err)
Expand All @@ -95,7 +90,7 @@ func (h *HTTPClient) BroadcastTransaction(tx *std.Tx) error {
return nil
}

func (h *HTTPClient) GetAccount(address string) (*gnoland.GnoAccount, error) {
func (h *Client) GetAccount(address string) (*gnoland.GnoAccount, error) {
queryResult, err := h.conn.ABCIQuery(
fmt.Sprintf("auth/accounts/%s", address),
[]byte{},
Expand All @@ -117,7 +112,7 @@ func (h *HTTPClient) GetAccount(address string) (*gnoland.GnoAccount, error) {
return &acc, nil
}

func (h *HTTPClient) GetBlockGasUsed(height int64) (int64, error) {
func (h *Client) GetBlockGasUsed(height int64) (int64, error) {
blockRes, err := h.conn.BlockResults(&height)
if err != nil {
return 0, fmt.Errorf("unable to fetch block results, %w", err)
Expand All @@ -131,7 +126,7 @@ func (h *HTTPClient) GetBlockGasUsed(height int64) (int64, error) {
return gasUsed, nil
}

func (h *HTTPClient) GetBlockGasLimit(height int64) (int64, error) {
func (h *Client) GetBlockGasLimit(height int64) (int64, error) {
consensusParams, err := h.conn.ConsensusParams(&height)
if err != nil {
return 0, fmt.Errorf("unable to fetch block info, %w", err)
Expand Down
9 changes: 3 additions & 6 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package collector
import (
"errors"
"fmt"
"math"
"time"

"github.com/gnolang/gno/tm2/pkg/bft/types"
Expand Down Expand Up @@ -118,7 +117,6 @@ func (c *Collector) GetRunResult(
return &RunResult{
AverageTPS: calculateTPS(
startTime,
blockResults[len(blockResults)-1].Time,
len(txHashes),
),
Blocks: blockResults,
Expand Down Expand Up @@ -160,9 +158,8 @@ func (t *txLookup) anyBelong(txs types.Txs) int {
}

// calculateTPS calculates the TPS for the sequence
func calculateTPS(startBlock, endBlock time.Time, totalTx int) int {
diff := endBlock.Sub(startBlock).Seconds()
func calculateTPS(startTime time.Time, totalTx int) float64 {
diff := time.Now().Sub(startTime).Seconds()

// ceil(numTxs / commit time)
return int(math.Ceil(float64(totalTx) / diff))
return float64(totalTx) / diff
}
2 changes: 1 addition & 1 deletion internal/collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestCollector_GetRunResults(t *testing.T) {
t.Fatal("result should not be nil")
}

assert.Equal(t, 2, result.AverageTPS) // 1 tx per block; 100 blocks; 1s per block;
assert.NotZero(t, result.AverageTPS)
assert.Len(t, result.Blocks, numTxs)

for index, block := range result.Blocks {
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Client interface {

// RunResult is the complete test-run result
type RunResult struct {
AverageTPS int `json:"averageTPS"`
AverageTPS float64 `json:"averageTPS"`
Blocks []*BlockResult `json:"blocks"`
}

Expand Down
6 changes: 1 addition & 5 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ package common

import "github.com/gnolang/gno/tm2/pkg/std"

const (
Denomination = "ugnot"
EncryptPassword = "encrypt"
KeybasePrefix = "stress-account-"
)
const Denomination = "ugnot"

// TODO support estimating gas params
// These are constants for now,
Expand Down
10 changes: 7 additions & 3 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ var (
)

var (
// urlRegex is used for verifying the cluster's JSON-RPC endpoint
urlRegex = regexp.MustCompile(`(https?://.*)(:(\d*)\/?(.*))?`)
// httpRegex is used for verifying the cluster's JSON-RPC HTTP endpoint
httpRegex = regexp.MustCompile(`(https?://.*)(:(\d*)\/?(.*))?`)

// wsRegex is used for verifying the cluster's JSON-RPC WS endpoint
wsRegex = regexp.MustCompile(`(wss?://.*)(:(\d*)\/?(.*))?`)
)

// Config is the central pipeline configuration
Expand All @@ -38,7 +41,8 @@ type Config struct {
// Validate validates the stress-test configuration
func (cfg *Config) Validate() error {
// Make sure the URL is valid
if !urlRegex.MatchString(cfg.URL) {
if !httpRegex.MatchString(cfg.URL) &&
!wsRegex.MatchString(cfg.URL) {
return errInvalidURL
}

Expand Down
Loading

0 comments on commit 22c5fb9

Please sign in to comment.