44 "context"
55 "encoding/json"
66 "fmt"
7+ "github.com/skip-mev/catalyst/pkg/types"
78 "sync"
89 "time"
910
@@ -22,132 +23,21 @@ import (
2223 "gopkg.in/yaml.v3"
2324)
2425
25- type MsgType string
26-
27- // LoadTestResult represents the results of a load test
28- type LoadTestResult struct {
29- Overall OverallStats
30- ByMessage map [MsgType ]MessageStats
31- ByNode map [string ]NodeStats
32- ByBlock []BlockStat
33- Error string `json:"error,omitempty"`
34- }
35-
36- // OverallStats represents the overall statistics of the load test
37- type OverallStats struct {
38- TotalTransactions int
39- SuccessfulTransactions int
40- FailedTransactions int
41- AvgGasPerTransaction int64
42- AvgBlockGasUtilization float64
43- Runtime time.Duration
44- StartTime time.Time
45- EndTime time.Time
46- BlocksProcessed int
47- }
48-
49- // MessageStats represents statistics for a specific message type
50- type MessageStats struct {
51- Transactions TransactionStats
52- Gas GasStats
53- Errors ErrorStats
54- }
55-
56- // TransactionStats represents transaction-related statistics
57- type TransactionStats struct {
58- Total int
59- Successful int
60- Failed int
61- }
62-
63- // GasStats represents gas-related statistics
64- type GasStats struct {
65- Average int64
66- Min int64
67- Max int64
68- Total int64
69- }
70-
71- // ErrorStats represents error-related statistics
72- type ErrorStats struct {
73- BroadcastErrors []BroadcastError
74- ErrorCounts map [string ]int // Error type to count
75- }
76-
77- // NodeStats represents statistics for a specific node
78- type NodeStats struct {
79- Address string
80- TransactionStats TransactionStats
81- MessageCounts map [MsgType ]int
82- GasStats GasStats
83- }
84-
85- // BlockStat represents statistics for a specific block
86- type BlockStat struct {
87- BlockHeight int64
88- Timestamp time.Time
89- GasLimit int
90- TotalGasUsed int64
91- MessageStats map [MsgType ]MessageBlockStats
92- GasUtilization float64
93- }
94-
95- // MessageBlockStats represents message-specific statistics within a block
96- type MessageBlockStats struct {
97- TransactionsSent int
98- SuccessfulTxs int
99- FailedTxs int
100- GasUsed int64
101- }
102-
103- // BroadcastError represents errors during broadcasting transactions
104- type BroadcastError struct {
105- BlockHeight int64 // Block height where the error occurred (0 indicates tx did not make it to a block)
106- TxHash string // Hash of the transaction that failed
107- Error string // Error message
108- MsgType MsgType // Type of message that failed
109- NodeAddress string // Address of the node that returned the error
110- }
111-
11226type PackagedState struct {
11327 ProviderState []byte
11428 ChainState []byte
115- Result LoadTestResult
116- }
117-
118- type LoadTestConfig struct {
119- ChainID string `yaml:"chain_id"`
120- BlockGasLimitTarget float64 `yaml:"block_gas_limit_target,omitempty"`
121- NumOfTxs int `yaml:"num_of_txs,omitempty"`
122- NumOfBlocks int `yaml:"num_of_blocks"`
123- NodesAddresses []Node `yaml:"nodes_addresses"`
124- Mnemonics []string `yaml:"mnemonics"`
125- GasDenom string `yaml:"gas_denom"`
126- Bech32Prefix string `yaml:"bech32_prefix"`
127- Msgs []Message `yaml:"msgs"`
128- }
129-
130- type Node struct {
131- GRPC string `yaml:"grpc"`
132- RPC string `yaml:"rpc"`
133- }
134-
135- type Message struct {
136- Type string `yaml:"type" json:"type"`
137- Weight float64 `yaml:"weight" json:"weight"`
138- NumMsgs int `yaml:"num_msgs,omitempty" json:"NumMsgs,omitempty"`
139- ContainedType MsgType `yaml:"contained_type,omitempty" json:"ContainedType,omitempty"`
140- NumOfRecipients int `yaml:"num_of_recipients,omitempty" json:"NumOfRecipients,omitempty"` // Number of recipients to include for MsgMultiSend
29+ Result types.LoadTestResult
14130}
14231
14332type Activity struct {
14433 DOToken string
14534 TailscaleSettings digitalocean.TailscaleSettings
14635}
14736
148- func generateLoadTestConfig (ctx context.Context , logger * zap.Logger , chain * chain.Chain , chainID string , loadTestConfig * LoadTestConfig ) ([]byte , error ) {
37+ func generateLoadTestSpec (ctx context.Context , logger * zap.Logger , chain * chain.Chain , chainID string ,
38+ loadTestSpec * types.LoadTestSpec ) ([]byte , error ) {
14939 validators := chain .GetValidators ()
150- var nodes []Node
40+ var nodes []types. NodeAddress
15141 for _ , v := range validators {
15242 grpcAddr , err := v .GetIP (ctx )
15343 grpcAddr = grpcAddr + ":9090"
@@ -161,7 +51,7 @@ func generateLoadTestConfig(ctx context.Context, logger *zap.Logger, chain *chai
16151 return nil , err
16252 }
16353
164- nodes = append (nodes , Node {
54+ nodes = append (nodes , types. NodeAddress {
16555 GRPC : grpcAddr ,
16656 RPC : fmt .Sprintf ("http://%s" , rpcAddr ),
16757 })
@@ -227,20 +117,20 @@ func generateLoadTestConfig(ctx context.Context, logger *zap.Logger, chain *chai
227117 }
228118 time .Sleep (5 * time .Second )
229119
230- config := LoadTestConfig {
120+ config := types. LoadTestSpec {
231121 ChainID : chainID ,
232- NumOfBlocks : loadTestConfig .NumOfBlocks ,
122+ NumOfBlocks : loadTestSpec .NumOfBlocks ,
233123 NodesAddresses : nodes ,
234124 Mnemonics : mnemonics ,
235125 GasDenom : chain .GetConfig ().Denom ,
236126 Bech32Prefix : chain .GetConfig ().Bech32Prefix ,
237- Msgs : loadTestConfig .Msgs ,
127+ Msgs : loadTestSpec .Msgs ,
238128 }
239129
240- if loadTestConfig .NumOfTxs > 0 {
241- config .NumOfTxs = loadTestConfig .NumOfTxs
242- } else if loadTestConfig .BlockGasLimitTarget > 0 {
243- config .BlockGasLimitTarget = loadTestConfig .BlockGasLimitTarget
130+ if loadTestSpec .NumOfTxs > 0 {
131+ config .NumOfTxs = loadTestSpec .NumOfTxs
132+ } else if loadTestSpec .BlockGasLimitTarget > 0 {
133+ config .BlockGasLimitTarget = loadTestSpec .BlockGasLimitTarget
244134 } else {
245135 return nil , fmt .Errorf ("failed to generate load test config, either BlockGasLimitTarget or NumOfTxs must be provided" )
246136 }
@@ -250,7 +140,7 @@ func generateLoadTestConfig(ctx context.Context, logger *zap.Logger, chain *chai
250140}
251141
252142func (a * Activity ) RunLoadTest (ctx context.Context , chainState []byte ,
253- loadTestConfig * LoadTestConfig , runnerType string , providerState []byte ) (PackagedState , error ) {
143+ loadTestSpec * types. LoadTestSpec , runnerType string , providerState []byte ) (PackagedState , error ) {
254144 logger , _ := zap .NewDevelopment ()
255145
256146 var p provider.ProviderI
@@ -280,7 +170,7 @@ func (a *Activity) RunLoadTest(ctx context.Context, chainState []byte,
280170 return PackagedState {}, err
281171 }
282172
283- configBytes , err := generateLoadTestConfig (ctx , logger , chain , chain .GetConfig ().ChainId , loadTestConfig )
173+ configBytes , err := generateLoadTestSpec (ctx , logger , chain , chain .GetConfig ().ChainId , loadTestSpec )
284174 if err != nil {
285175 return PackagedState {}, err
286176 }
@@ -289,7 +179,7 @@ func (a *Activity) RunLoadTest(ctx context.Context, chainState []byte,
289179 Name : "catalyst" ,
290180 ContainerName : "catalyst" ,
291181 Image : provider.ImageDefinition {
292- Image : "ghcr.io/skip-mev/catalyst:latest " ,
182+ Image : "ghcr.io/skip-mev/catalyst:dev " ,
293183 UID : "100" ,
294184 GID : "100" ,
295185 },
@@ -340,7 +230,7 @@ func (a *Activity) RunLoadTest(ctx context.Context, chainState []byte,
340230 return PackagedState {}, fmt .Errorf ("failed to read result file: %w" , err )
341231 }
342232
343- var result LoadTestResult
233+ var result types. LoadTestResult
344234 if err := json .Unmarshal (resultBytes , & result ); err != nil {
345235 return PackagedState {}, fmt .Errorf ("failed to parse result file: %w" , err )
346236 }
0 commit comments