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: Several issues from dydx loadtest integ. [BLO-909] #109

Merged
merged 3 commits into from
Feb 21, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
**/*.pkr.hcl
go.work*
2 changes: 1 addition & 1 deletion core/provider/docker/docker_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Provider struct {
name string
dockerNetworkID string
dockerNetworkName string
networkMu sync.RWMutex
networkMu sync.Mutex
listeners map[string]Listeners
builderImageName string
}
Expand Down
9 changes: 6 additions & 3 deletions core/provider/docker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ func (p *Provider) CreateTask(ctx context.Context, logger *zap.Logger, definitio
listeners.CloseAll()
return "", err
}


// network map is volatile, so we need to mutex update it
p.networkMu.Lock()
p.listeners[createdContainer.ID] = listeners
p.networkMu.Unlock()

return createdContainer.ID, nil
}
Expand All @@ -118,8 +121,8 @@ func (p *Provider) pullImage(ctx context.Context, imageName string) error {

func (p *Provider) StartTask(ctx context.Context, id string) error {
p.logger.Info("starting task", zap.String("id", id))
p.networkMu.RLock()
defer p.networkMu.RUnlock()
p.networkMu.Lock()
defer p.networkMu.Unlock()

if _, ok := p.listeners[id]; !ok {
return fmt.Errorf("task port listeners %s not found", id)
Expand Down
26 changes: 21 additions & 5 deletions core/types/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package types
import (
"context"
"fmt"
"math/big"

rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -62,7 +64,6 @@ type ChainConfig struct {
SidecarArgs []string // SidecarArgs are the arguments to launch the chain sidecar

CoinType string // CoinType is the coin type of the chain (e.g. 118)
HDPath string // HDPath is the HD path of the chain (e.g. m/44'/118'/0'/0/0)
ChainId string // ChainId is the chain ID of the chain

ModifyGenesis GenesisModifier // ModifyGenesis is a function that modifies the genesis bytes of the chain
Expand All @@ -73,6 +74,25 @@ type ChainConfig struct {

NodeCreator NodeCreator // NodeCreator is a function that creates a node
NodeDefinitionModifier NodeDefinitionModifier // NodeDefinitionModifier is a function that modifies a node's definition
// number of tokens to allocate per account in the genesis state (unscaled). This value defaults to 10_000_000 if not set.
// if not set.
GenesisDelegation *big.Int
// number of tokens to allocate to the genesis account. This value defaults to 5_000_000 if not set.
GenesisBalance *big.Int
}

func (c ChainConfig) GetGenesisBalance() *big.Int {
if c.GenesisBalance == nil {
return big.NewInt(10_000_000)
}
return c.GenesisBalance
}

func (c ChainConfig) GetGenesisDelegation() *big.Int {
if c.GenesisDelegation == nil {
return big.NewInt(5_000_000)
}
return c.GenesisDelegation
}

func (c *ChainConfig) ValidateBasic() error {
Expand Down Expand Up @@ -118,10 +138,6 @@ func (c *ChainConfig) ValidateBasic() error {
return fmt.Errorf("coin type cannot be empty")
}

if c.HDPath == "" {
return fmt.Errorf("HD path cannot be empty")
}

if c.ChainId == "" {
return fmt.Errorf("chain ID cannot be empty")
}
Expand Down
27 changes: 11 additions & 16 deletions cosmos/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@ func (c *Chain) Init(ctx context.Context) error {
decimalPow := int64(math.Pow10(int(c.Config.Decimals)))

genesisCoin := types.Coin{
Amount: sdkmath.NewInt(10_000_000).MulRaw(decimalPow),
Amount: sdkmath.NewIntFromBigInt(c.GetConfig().GetGenesisBalance()).MulRaw(decimalPow),
Denom: c.Config.Denom,
}
c.logger.Info("creating genesis accounts", zap.String("coin", genesisCoin.String()))

genesisSelfDelegation := types.Coin{
Amount: sdkmath.NewInt(5_000_000).MulRaw(decimalPow),
Amount: sdkmath.NewIntFromBigInt(c.GetConfig().GetGenesisDelegation()).MulRaw(decimalPow),
Denom: c.Config.Denom,
}
c.logger.Info("creating genesis self-delegations", zap.String("coin", genesisSelfDelegation.String()))

genesisAmounts := []types.Coin{genesisCoin}

Expand Down Expand Up @@ -425,26 +427,19 @@ func (c *Chain) WaitForBlocks(ctx context.Context, delta uint64) error {
// WaitForHeight blocks until the chain reaches block height desiredHeight
func (c *Chain) WaitForHeight(ctx context.Context, desiredHeight uint64) error {
c.logger.Info("waiting for height", zap.Uint64("desired_height", desiredHeight))

height, err := c.Height(ctx)

if err != nil {
return err
}

for {
c.logger.Debug("waiting for height", zap.Uint64("desired_height", desiredHeight), zap.Uint64("current_height", height))

if height >= desiredHeight {
break
}

height, err = c.Height(ctx)
c.logger.Debug("waiting for height", zap.Uint64("desired_height", desiredHeight))

height, err := c.Height(ctx)
if err != nil {
time.Sleep(2 * time.Second)
continue
}

if height >= desiredHeight {
break
}

// We assume the chain will eventually return a non-zero height, otherwise
// this may block indefinitely.
if height == 0 {
Expand Down
6 changes: 3 additions & 3 deletions cosmos/cosmosutil/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package cosmosutil
import (
"context"
"fmt"
"strings"
"time"

"github.com/cosmos/cosmos-sdk/client"
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -15,8 +18,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
petritypes "github.com/skip-mev/petri/core/v2/types"
"github.com/skip-mev/petri/core/v2/util"
"strings"
"time"
)

// EncodingConfig is a struct that packs all the necessary encoding information
Expand Down Expand Up @@ -63,7 +64,6 @@ func (w *InteractingWallet) CreateSignedTx(ctx context.Context, gas int64, fees
}

acc, err := w.Account(ctx)

if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion cosmos/loadtest/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package loadtest

import (
"context"
"fmt"
"github.com/cometbft/cometbft/test/loadtime/payload"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -67,6 +68,9 @@ func (f *DefaultClientFactory) NewClient(cfg loadtest.Config) (loadtest.Client,
GasDenom: f.chain.GetConfig().Denom,
PricePerGas: 0, // todo(Zygimantass): get gas settings
}, true)
if err != nil {
return nil, fmt.Errorf("error seeding account %s from seeder %s: %v", interactingLoaderWallet.FormattedAddress(), f.seeder.FormattedAddress(), err)
}

msgs, gasSettings, err := f.msgGenerator(interactingLoaderWallet.Address())

Expand All @@ -77,7 +81,7 @@ func (f *DefaultClientFactory) NewClient(cfg loadtest.Config) (loadtest.Client,
acc, err := interactingLoaderWallet.Account(context.Background())

if err != nil {
return nil, err
return nil, fmt.Errorf("error in client initialization: sender account was not created %s", interactingLoaderWallet.FormattedAddress())
}

return NewDefaultClient(interactingLoaderWallet, f.chainClient, msgs, acc.GetSequence(), acc.GetAccountNumber(), gasSettings, &payload.Payload{
Expand Down
Loading