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
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

7. Start the worker:
```bash
go run ./cmd/worker
export TSNET_FORCE_LOGIN=1 && go run ./cmd/worker
```

## Start Backend and Frontend
Expand Down
9 changes: 6 additions & 3 deletions activities/loadtest/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ type PetriChain interface {
GetNodes() []types.NodeI
}

// TODO: this function is kind of confusing because we give it a half-baked loadtest spec, and then fill in the rest.
// I'm not sure if there is a better/more clearer way to go about this, but it seems confusing as is.
func generateLoadTestSpec(ctx context.Context, logger *zap.Logger, chain PetriChain, chainID string,
loadTestSpec ctltypes.LoadTestSpec, mnemonics []string,
loadTestSpec ctltypes.LoadTestSpec, baseMnemonic string, numWallets int,
) ([]byte, error) {
chainConfig := chain.GetConfig()

Expand Down Expand Up @@ -134,7 +136,8 @@ func generateLoadTestSpec(ctx context.Context, logger *zap.Logger, chain PetriCh
loadTestSpec.ChainCfg = catalystChainConfig
loadTestSpec.ChainID = chainID

loadTestSpec.Mnemonics = mnemonics
loadTestSpec.BaseMnemonic = baseMnemonic
loadTestSpec.NumWallets = numWallets

err := loadTestSpec.Validate()
if err != nil {
Expand Down Expand Up @@ -177,7 +180,7 @@ func (a *Activity) RunLoadTest(ctx context.Context, req messages.RunLoadTestRequ
return handleLoadTestError(ctx, logger, p, nil, err, "failed to restore chain")
}

configBytes, err := generateLoadTestSpec(ctx, logger, chain, chain.GetConfig().ChainId, req.LoadTestSpec, req.Mnemonics)
configBytes, err := generateLoadTestSpec(ctx, logger, chain, chain.GetConfig().ChainId, req.LoadTestSpec, req.BaseMnemonic, req.NumWallets)
if err != nil {
return handleLoadTestError(ctx, logger, p, chain, err, "failed to generate load test config")
}
Expand Down
18 changes: 7 additions & 11 deletions activities/loadtest/loadtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestGenerateSpec(t *testing.T) {
Kind: "eth",
SendInterval: 500 * time.Millisecond,
NumBatches: 20,
Mnemonics: nil,
Msgs: []types.LoadTestMsg{
{
Type: "MsgNativeTransferERC20",
Expand All @@ -41,12 +40,8 @@ func TestGenerateSpec(t *testing.T) {
},
}

mnemonics := []string{
"the coin is for everyone",
"blockchain liberate us all",
"all your base are belong to us",
"hello world i am here to save you",
}
baseMnemonic := "this is a mnemonic"
numWallets := 4
chain := mocks.NewMocktheChain(gomock.NewController(t))
chain.EXPECT().GetConfig().Times(1).Return(types2.ChainConfig{})

Expand All @@ -58,18 +53,19 @@ func TestGenerateSpec(t *testing.T) {
}
chain.EXPECT().GetNodes().Times(1).Return(nodes)

specBZ, err := generateLoadTestSpec(ctx, logger, chain, chainID, spec, mnemonics)
specBZ, err := generateLoadTestSpec(ctx, logger, chain, chainID, spec, baseMnemonic, numWallets)
require.NoError(t, err)

var gotLoadtestSpec types.LoadTestSpec
err = yaml.Unmarshal(specBZ, &gotLoadtestSpec)
require.NoError(t, err)

// the function will set mnemonics.
spec.Mnemonics = mnemonics
spec.ChainID = chainID
spec.ChainCfg.(*ethtypes.ChainConfig).NodesAddresses = gotLoadtestSpec.ChainCfg.(*ethtypes.ChainConfig).NodesAddresses
spec.BaseMnemonic = baseMnemonic
spec.NumWallets = numWallets
require.Equal(t, gotLoadtestSpec, spec)
require.Equal(t, len(nodes), len(gotLoadtestSpec.ChainCfg.(*ethtypes.ChainConfig).NodesAddresses))
require.True(t, len(gotLoadtestSpec.Mnemonics) > 0)
require.Equal(t, gotLoadtestSpec.BaseMnemonic, baseMnemonic)
require.Equal(t, gotLoadtestSpec.NumWallets, numWallets)
}
58 changes: 6 additions & 52 deletions activities/testnet/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,12 @@ func (a *Activity) LaunchTestnet(ctx context.Context, req messages.LaunchTestnet
resp.ChainID = chainConfig.ChainId

initErr := chain.Init(ctx, petritypes.ChainOptions{
ModifyGenesis: petrichain.ModifyGenesis(req.GenesisModifications),
NodeCreator: node.CreateNode,
WalletConfig: walletConfig,
NodeOptions: nodeOptions,
ModifyGenesis: petrichain.ModifyGenesis(req.GenesisModifications),
NodeCreator: node.CreateNode,
WalletConfig: walletConfig,
NodeOptions: nodeOptions,
BaseMnemonic: req.BaseMnemonic,
AdditionalAccounts: req.NumWallets,
})
if initErr != nil {
providerState, serializeErr := p.SerializeProvider(ctx)
Expand Down Expand Up @@ -310,54 +312,6 @@ func (a *Activity) LaunchTestnet(ctx context.Context, req messages.LaunchTestnet
return resp, nil
}

func emitHeartbeats(ctx context.Context, chain *petrichain.Chain, logger *zap.Logger) {
heartbeatCtx, cancel := context.WithCancel(ctx)
defer cancel()

ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()

for {
select {
case <-heartbeatCtx.Done():
return
case <-ticker.C:
validators := chain.GetValidators()

// attempts to get a heartbeat from up to 3 validators
success := false
maxValidators := 3
if len(validators) < maxValidators {
maxValidators = len(validators)
}

for i := 0; i < maxValidators; i++ {
tmClient, err := validators[i].GetTMClient(ctx)
if err != nil {
logger.Error("Failed to get TM client", zap.Error(err), zap.Int("validator", i))
continue
}

_, err = tmClient.Status(ctx)
if err != nil {
logger.Error("Chain status check failed", zap.Error(err), zap.Int("validator", i))
continue
}

success = true
break
}

if !success {
logger.Error("All validator checks failed", zap.Int("validators_attempted", maxValidators))
continue
}

activity.RecordHeartbeat(ctx, "Chain status: healthy")
}
}
}

func constructChainConfig(req messages.LaunchTestnetRequest,
chains types.Chains) (petritypes.ChainConfig, petritypes.WalletConfig) {
chainImage := chains[req.BaseImage]
Expand Down
117 changes: 0 additions & 117 deletions activities/walletcreator/chunk_fuzz_test.go

This file was deleted.

Loading
Loading