Skip to content

Commit

Permalink
Merge branch 'main' into nina/fix-MajorUpgradeToV2
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze authored Apr 26, 2024
2 parents b76fc51 + 32e7015 commit 77875c3
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
**/**.go
go.mod
go.sum
- uses: golangci/golangci-lint-action@v4.0.0
- uses: golangci/golangci-lint-action@v5.0.0
with:
version: v1.57.0
args: --timeout 10m
Expand Down
50 changes: 40 additions & 10 deletions pkg/user/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
"sync"
"time"

"github.com/celestiaorg/celestia-app/v2/app/encoding"
apperrors "github.com/celestiaorg/celestia-app/v2/app/errors"
blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types"
"github.com/celestiaorg/go-square/blob"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand All @@ -23,9 +20,25 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
abci "github.com/tendermint/tendermint/abci/types"
"google.golang.org/grpc"

"github.com/celestiaorg/celestia-app/v2/app/encoding"
apperrors "github.com/celestiaorg/celestia-app/v2/app/errors"
blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types"
)

const DefaultPollTime = 3 * time.Second
const (
DefaultPollTime = 3 * time.Second
DefaultGasMultiplier float64 = 1.1
)

type Option func(s *Signer)

// WithGasMultiplier is a functional option allows to configure the gas multiplier.
func WithGasMultiplier(multiplier float64) Option {
return func(s *Signer) {
s.gasMultiplier = multiplier
}
}

// Signer is an abstraction for building, signing, and broadcasting Celestia transactions
type Signer struct {
Expand All @@ -48,6 +61,8 @@ type Signer struct {
localSequence uint64
// the chains last known sequence number
networkSequence uint64
// gasMultiplier is used to increase gas limit as it is sometimes underestimated
gasMultiplier float64
// lookup map of all pending and yet to be confirmed outbound transactions
outboundSequences map[uint64]struct{}
// a reverse map for confirming which sequence numbers have been committed
Expand All @@ -63,6 +78,7 @@ func NewSigner(
chainID string,
accountNumber, sequence,
appVersion uint64,
options ...Option,
) (*Signer, error) {
// check that the address exists
record, err := keys.KeyByAddress(address)
Expand All @@ -75,7 +91,7 @@ func NewSigner(
return nil, err
}

return &Signer{
signer := &Signer{
keys: keys,
address: address,
grpc: conn,
Expand All @@ -87,16 +103,28 @@ func NewSigner(
localSequence: sequence,
networkSequence: sequence,
pollTime: DefaultPollTime,
gasMultiplier: DefaultGasMultiplier,
outboundSequences: make(map[uint64]struct{}),
reverseTxHashSequenceMap: make(map[string]uint64),
}, nil
}

for _, opt := range options {
opt(signer)
}
return signer, nil
}

// SetupSingleSigner sets up a signer based on the provided keyring. The keyring
// must contain exactly one key. It extracts the address from the key and uses
// the grpc connection to populate the chainID, account number, and sequence
// number.
func SetupSingleSigner(ctx context.Context, keys keyring.Keyring, conn *grpc.ClientConn, encCfg encoding.Config) (*Signer, error) {
func SetupSingleSigner(
ctx context.Context,
keys keyring.Keyring,
conn *grpc.ClientConn,
encCfg encoding.Config,
options ...Option,
) (*Signer, error) {
records, err := keys.List()
if err != nil {
return nil, err
Expand All @@ -111,7 +139,7 @@ func SetupSingleSigner(ctx context.Context, keys keyring.Keyring, conn *grpc.Cli
return nil, err
}

return SetupSigner(ctx, keys, conn, address, encCfg)
return SetupSigner(ctx, keys, conn, address, encCfg, options...)
}

// SetupSigner uses the underlying grpc connection to populate the chainID, accountNumber and sequence number of the
Expand All @@ -122,6 +150,7 @@ func SetupSigner(
conn *grpc.ClientConn,
address sdktypes.AccAddress,
encCfg encoding.Config,
options ...Option,
) (*Signer, error) {
resp, err := tmservice.NewServiceClient(conn).GetLatestBlock(
ctx,
Expand All @@ -138,7 +167,7 @@ func SetupSigner(
return nil, err
}

return NewSigner(keys, conn, address, encCfg.TxConfig, chainID, accNum, seqNum, appVersion)
return NewSigner(keys, conn, address, encCfg.TxConfig, chainID, accNum, seqNum, appVersion, options...)
}

// SubmitTx forms a transaction from the provided messages, signs it, and submits it to the chain. TxOptions
Expand Down Expand Up @@ -416,7 +445,8 @@ func (s *Signer) EstimateGas(ctx context.Context, msgs []sdktypes.Msg, opts ...T
return 0, err
}

return resp.GasInfo.GasUsed, nil
gasLimit := uint64(float64(resp.GasInfo.GasUsed) * s.gasMultiplier)
return gasLimit, nil
}

// ChainID returns the chain ID of the signer.
Expand Down
13 changes: 7 additions & 6 deletions pkg/user/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import (
"testing"
"time"

"github.com/celestiaorg/celestia-app/v2/app"
"github.com/celestiaorg/celestia-app/v2/app/encoding"
"github.com/celestiaorg/celestia-app/v2/pkg/user"
"github.com/celestiaorg/celestia-app/v2/test/util/blobfactory"
"github.com/celestiaorg/celestia-app/v2/test/util/testnode"
sdk "github.com/cosmos/cosmos-sdk/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/rand"

"github.com/celestiaorg/celestia-app/v2/app"
"github.com/celestiaorg/celestia-app/v2/app/encoding"
"github.com/celestiaorg/celestia-app/v2/pkg/user"
"github.com/celestiaorg/celestia-app/v2/test/util/blobfactory"
"github.com/celestiaorg/celestia-app/v2/test/util/testnode"
)

func TestSignerTestSuite(t *testing.T) {
Expand All @@ -43,7 +44,7 @@ func (s *SignerTestSuite) SetupSuite() {
s.Require().NoError(err)
addr, err := rec.GetAddress()
s.Require().NoError(err)
s.signer, err = user.SetupSigner(s.ctx.GoContext(), s.ctx.Keyring, s.ctx.GRPCClient, addr, s.encCfg)
s.signer, err = user.SetupSigner(s.ctx.GoContext(), s.ctx.Keyring, s.ctx.GRPCClient, addr, s.encCfg, user.WithGasMultiplier(1.2))
s.Require().NoError(err)
}

Expand Down
32 changes: 16 additions & 16 deletions test/e2e/benchmark/throughput.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v2/test/e2e/testnets"
"github.com/celestiaorg/celestia-app/v2/test/e2e/testnet"
"github.com/celestiaorg/celestia-app/v2/test/util/testnode"
)

Expand All @@ -23,50 +23,50 @@ func main() {
}

func E2EThroughput() error {
latestVersion, err := testnets.GetLatestVersion()
testnets.NoError("failed to get latest version", err)
latestVersion, err := testnet.GetLatestVersion()
testnet.NoError("failed to get latest version", err)

log.Println("=== RUN E2EThroughput", "version:", latestVersion)

// create a new testnet
testnet, err := testnets.New("E2EThroughput", seed, testnets.GetGrafanaInfoFromEnvVar())
testnets.NoError("failed to create testnet", err)
testNet, err := testnet.New("E2EThroughput", seed, testnet.GetGrafanaInfoFromEnvVar())
testnet.NoError("failed to create testnet", err)

defer func() {
log.Print("Cleaning up testnet")
testnet.Cleanup()
testNet.Cleanup()
}()

// add 2 validators
testnets.NoError("failed to create genesis nodes", testnet.CreateGenesisNodes(2, latestVersion, 10000000, 0, testnets.DefaultResources))
testnet.NoError("failed to create genesis nodes", testNet.CreateGenesisNodes(2, latestVersion, 10000000, 0, testnet.DefaultResources))

// obtain the GRPC endpoints of the validators
gRPCEndpoints, err := testnet.RemoteGRPCEndpoints()
testnets.NoError("failed to get validators GRPC endpoints", err)
gRPCEndpoints, err := testNet.RemoteGRPCEndpoints()
testnet.NoError("failed to get validators GRPC endpoints", err)
log.Println("validators GRPC endpoints", gRPCEndpoints)

// create txsim nodes and point them to the validators
log.Println("Creating txsim nodes")

err = testnet.CreateTxClients(txsimVersion, 1, "10000-10000", testnets.DefaultResources, gRPCEndpoints)
testnets.NoError("failed to create tx clients", err)
err = testNet.CreateTxClients(txsimVersion, 1, "10000-10000", testnet.DefaultResources, gRPCEndpoints)
testnet.NoError("failed to create tx clients", err)

// start the testnet
log.Println("Setting up testnet")
testnets.NoError("failed to setup testnet", testnet.Setup())
testnet.NoError("failed to setup testnet", testNet.Setup())
log.Println("Starting testnet")
testnets.NoError("failed to start testnet", testnet.Start())
testnet.NoError("failed to start testnet", testNet.Start())

// once the testnet is up, start the txsim
log.Println("Starting txsim nodes")
testnets.NoError("failed to start tx clients", testnet.StartTxClients())
testnet.NoError("failed to start tx clients", testNet.StartTxClients())

// wait some time for the txsim to submit transactions
time.Sleep(1 * time.Minute)

log.Println("Reading blockchain")
blockchain, err := testnode.ReadBlockchain(context.Background(), testnet.Node(0).AddressRPC())
testnets.NoError("failed to read blockchain", err)
blockchain, err := testnode.ReadBlockchain(context.Background(), testNet.Node(0).AddressRPC())
testnet.NoError("failed to read blockchain", err)

totalTxs := 0
for _, block := range blockchain {
Expand Down
Loading

0 comments on commit 77875c3

Please sign in to comment.