Skip to content
Merged
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
8 changes: 7 additions & 1 deletion .github/workflows/dagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ jobs:
supernova:
name: supernova-ci
runs-on: ubuntu-latest
# runs-on: [ self-hosted, Linux, X64, dagger ]
strategy:
matrix:
env: [PACKAGE_DEPLOYMENT, REALM_DEPLOYMENT, REALM_CALL]
max-parallel: 1

steps:
- name: Checkout
uses: actions/checkout@v5
Expand All @@ -28,4 +34,4 @@ jobs:
version: ${{ steps.dagger_version.outputs.version }}
verb: call
module: ci/dagger/run-supernova/
args: run-stress-test --src-dir . --chain-id ${CHAIN_ID} --rpc-endpoint ${RPC_URL} --sub-accounts 2 --transactions 10
args: run-stress-test --src-dir . --chain-id ${CHAIN_ID} --rpc-endpoint ${RPC_URL} --mode ${{ matrix.env }} --sub-accounts 2 --transactions 100
31 changes: 30 additions & 1 deletion ci/dagger/run-supernova/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ const (
MNEMONIC = "source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast"
)

type supernovaMode string

const (
PACKAGE_DEPLOYMENT supernovaMode = "PACKAGE_DEPLOYMENT"
REALM_DEPLOYMENT supernovaMode = "REALM_DEPLOYMENT"
REALM_CALL supernovaMode = "REALM_CALL"
)

type Supernova struct{}

// Builds Supernova image from code passed into a *dagger.Directory item
Expand Down Expand Up @@ -51,7 +59,9 @@ func (s *Supernova) RunStressTest(
subAccounts int,
// +optional
transactions int,
// + optional
// +default="REALM_DEPLOYMENT"
mode string,
// +optional
srcDir *dagger.Directory,
) (int, error) {

Expand All @@ -65,10 +75,16 @@ func (s *Supernova) RunStressTest(
transactions = DEFAULT_TRANSACTIONS
}

runningMode, err := toSupernovaMode(mode)
if err != nil {
return -1, err
}

return s.buildOrPull(srcDir).
WithExec([]string{
"-sub-accounts", fmt.Sprintf("%d", subAccounts),
"-transactions", fmt.Sprintf("%d", transactions),
"-mode", string(runningMode),
"-chain-id", chainId,
"-url", rpcEndpoint,
"-mnemonic", MNEMONIC},
Expand All @@ -77,3 +93,16 @@ func (s *Supernova) RunStressTest(
}).
ExitCode(ctx)
}

func toSupernovaMode(s string) (supernovaMode, error) {
switch s {
case string(PACKAGE_DEPLOYMENT):
return PACKAGE_DEPLOYMENT, nil
case string(REALM_DEPLOYMENT):
return REALM_DEPLOYMENT, nil
case string(REALM_CALL):
return REALM_CALL, nil
default:
return "", fmt.Errorf("invalid supernova oode: %s", s)
}
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ func execMain(cfg *internal.Config) error {
return fmt.Errorf("unable to create pipeline, %w", err)
}

return pipeline.Execute()
return pipeline.Execute(context.Background())
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23.0
toolchain go1.24.1

require (
github.com/gnolang/gno v0.0.0-20250826105341-fba926958b6b
github.com/gnolang/gno v0.0.0-20250903154725-71e9ac3593a9
github.com/peterbourgon/ff/v3 v3.4.0
github.com/schollz/progressbar/v3 v3.18.0
github.com/stretchr/testify v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwV
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps=
github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
github.com/gnolang/gno v0.0.0-20250826105341-fba926958b6b h1:z0iw3ObgSnibeOpORPzRZjnx6v5eeSbQ35zgdoZndjE=
github.com/gnolang/gno v0.0.0-20250826105341-fba926958b6b/go.mod h1:j9wKq29meqwktEj2ReqPbSkeYUwoisfxHHVeV20lhtw=
github.com/gnolang/gno v0.0.0-20250903154725-71e9ac3593a9 h1:ijDZP1N5mHhedtGlIinq9IsNy3GpG3MTcw6V+s10WT8=
github.com/gnolang/gno v0.0.0-20250903154725-71e9ac3593a9/go.mod h1:j9wKq29meqwktEj2ReqPbSkeYUwoisfxHHVeV20lhtw=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down
7 changes: 5 additions & 2 deletions internal/batcher/batcher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package batcher

import (
"context"
"errors"
"fmt"
"math"
Expand All @@ -16,12 +17,14 @@ import (
// to the Gno Tendermint node
type Batcher struct {
cli Client
ctx context.Context
}

// NewBatcher creates a new Batcher instance
func NewBatcher(cli Client) *Batcher {
func NewBatcher(ctx context.Context, cli Client) *Batcher {
return &Batcher{
cli: cli,
ctx: ctx,
}
}

Expand All @@ -31,7 +34,7 @@ func (b *Batcher) BatchTransactions(txs []*std.Tx, batchSize int) (*TxBatchResul
fmt.Printf("\n📦 Batching Transactions 📦\n\n")

// Note the current latest block
latest, err := b.cli.GetLatestBlockHeight()
latest, err := b.cli.GetLatestBlockHeight(b.ctx)
if err != nil {
return nil, fmt.Errorf("unable to fetch latest block %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/batcher/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package batcher

import (
"bytes"
"context"
"crypto/rand"
"fmt"
"testing"
Expand Down Expand Up @@ -85,7 +86,7 @@ func TestBatcher_BatchTransactions(t *testing.T) {
)

// Create the batcher
b := NewBatcher(mockClient)
b := NewBatcher(context.Background(), mockClient)

// Batch the transactions
res, err := b.BatchTransactions(txs, batchSize)
Expand Down
8 changes: 5 additions & 3 deletions internal/batcher/mock_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package batcher

import (
"context"

"github.com/gnolang/supernova/internal/common"
)

type (
createBatchDelegate func() common.Batch
getLatestBlockHeightDelegate func() (int64, error)
getLatestBlockHeightDelegate func(context.Context) (int64, error)
)

type mockClient struct {
Expand All @@ -22,9 +24,9 @@ func (m *mockClient) CreateBatch() common.Batch {
return nil
}

func (m *mockClient) GetLatestBlockHeight() (int64, error) {
func (m *mockClient) GetLatestBlockHeight(ctx context.Context) (int64, error) {
if m.getLatestBlockHeightFn != nil {
return m.getLatestBlockHeightFn()
return m.getLatestBlockHeightFn(ctx)
}

return 0, nil
Expand Down
4 changes: 3 additions & 1 deletion internal/batcher/types.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package batcher

import (
"context"

"github.com/gnolang/supernova/internal/common"
)

type Client interface {
CreateBatch() common.Batch
GetLatestBlockHeight() (int64, error)
GetLatestBlockHeight(ctx context.Context) (int64, error)
}

// TxBatchResult contains batching results
Expand Down
44 changes: 23 additions & 21 deletions internal/client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"context"
"fmt"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
Expand Down Expand Up @@ -49,38 +50,38 @@ func (h *Client) CreateBatch() common.Batch {
return &Batch{batch: h.conn.NewBatch()}
}

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

func (h *Client) GetLatestBlockHeight() (int64, error) {
status, err := h.conn.Status()
func (h *Client) GetLatestBlockHeight(ctx context.Context) (int64, error) {
status, err := h.conn.Status(ctx, nil)
if err != nil {
return 0, fmt.Errorf("unable to fetch status, %w", err)
}

return status.SyncInfo.LatestBlockHeight, nil
}

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

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

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

func (h *Client) BroadcastTransaction(tx *std.Tx) error {
func (h *Client) BroadcastTransaction(ctx context.Context, tx *std.Tx) error {
marshalledTx, err := amino.Marshal(tx)
if err != nil {
return fmt.Errorf("unable to marshal transaction, %w", err)
}

res, err := h.conn.BroadcastTxCommit(marshalledTx)
res, err := h.conn.BroadcastTxCommit(ctx, marshalledTx)
if err != nil {
return fmt.Errorf("unable to broadcast transaction, %w", err)
}
Expand All @@ -96,8 +97,9 @@ func (h *Client) BroadcastTransaction(tx *std.Tx) error {
return nil
}

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

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

func (h *Client) GetBlockGasLimit(height int64) (int64, error) {
consensusParams, err := h.conn.ConsensusParams(&height)
func (h *Client) GetBlockGasLimit(ctx context.Context, height int64) (int64, error) {
consensusParams, err := h.conn.ConsensusParams(ctx, &height)
if err != nil {
return 0, fmt.Errorf("unable to fetch block info, %w", err)
}

return consensusParams.ConsensusParams.Block.MaxGas, nil
}

func (h *Client) EstimateGas(tx *std.Tx) (int64, error) {
func (h *Client) EstimateGas(ctx context.Context, tx *std.Tx) (int64, error) {
// Prepare the transaction.
// The transaction needs to be amino-binary encoded
// in order to be estimated
Expand All @@ -150,7 +152,7 @@ func (h *Client) EstimateGas(tx *std.Tx) (int64, error) {
}

// Perform the simulation query
resp, err := h.conn.ABCIQuery(simulatePath, encodedTx)
resp, err := h.conn.ABCIQuery(ctx, simulatePath, encodedTx)
if err != nil {
return 0, fmt.Errorf("unable to perform ABCI query: %w", err)
}
Expand All @@ -174,11 +176,11 @@ func (h *Client) EstimateGas(tx *std.Tx) (int64, error) {
return deliverTx.GasUsed, nil
}

func (h *Client) FetchGasPrice() (std.GasPrice, error) {
func (h *Client) FetchGasPrice(ctx context.Context) (std.GasPrice, error) {
// Perform auth/gasprice
gp := std.GasPrice{}

qres, err := h.conn.ABCIQuery(gaspricePath, []byte{})
qres, err := h.conn.ABCIQuery(ctx, gaspricePath, []byte{})
if err != nil {
return gp, err
}
Expand Down
13 changes: 8 additions & 5 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package collector

import (
"context"
"errors"
"fmt"
"time"
Expand All @@ -17,15 +18,17 @@ var errTimeout = errors.New("collector timed out")
// transaction indexing is introduced
type Collector struct {
cli Client
ctx context.Context

requestTimeout time.Duration
}

// NewCollector creates a new instance of the collector
func NewCollector(cli Client) *Collector {
func NewCollector(ctx context.Context, cli Client) *Collector {
return &Collector{
cli: cli,
requestTimeout: time.Second * 2,
ctx: ctx,
}
}

Expand Down Expand Up @@ -58,7 +61,7 @@ func (c *Collector) GetRunResult(
case <-timeout:
return nil, errTimeout
case <-time.After(c.requestTimeout):
latest, err := c.cli.GetLatestBlockHeight()
latest, err := c.cli.GetLatestBlockHeight(c.ctx)
if err != nil {
return nil, fmt.Errorf("unable to fetch latest block height, %w", err)
}
Expand All @@ -71,7 +74,7 @@ func (c *Collector) GetRunResult(
// Iterate over each block and find relevant transactions
for blockNum := start; blockNum <= latest; blockNum++ {
// Fetch the block
block, err := c.cli.GetBlock(&blockNum)
block, err := c.cli.GetBlock(c.ctx, &blockNum)
if err != nil {
return nil, fmt.Errorf("unable to fetch block, %w", err)
}
Expand All @@ -87,13 +90,13 @@ func (c *Collector) GetRunResult(
_ = bar.Add(belong) //nolint:errcheck // No need to check

// Fetch the total gas used by transactions
blockGasUsed, err := c.cli.GetBlockGasUsed(blockNum)
blockGasUsed, err := c.cli.GetBlockGasUsed(c.ctx, blockNum)
if err != nil {
return nil, fmt.Errorf("unable to fetch block gas used, %w", err)
}

// Fetch the block gas limit
blockGasLimit, err := c.cli.GetBlockGasLimit(blockNum)
blockGasLimit, err := c.cli.GetBlockGasLimit(c.ctx, blockNum)
if err != nil {
return nil, fmt.Errorf("unable to fetch block gas limit, %w", err)
}
Expand Down
Loading
Loading