4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
+ "github.com/skip-mev/catalyst/pkg/types"
7
8
"sync"
8
9
"time"
9
10
@@ -22,132 +23,21 @@ import (
22
23
"gopkg.in/yaml.v3"
23
24
)
24
25
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
-
112
26
type PackagedState struct {
113
27
ProviderState []byte
114
28
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
141
30
}
142
31
143
32
type Activity struct {
144
33
DOToken string
145
34
TailscaleSettings digitalocean.TailscaleSettings
146
35
}
147
36
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 ) {
149
39
validators := chain .GetValidators ()
150
- var nodes []Node
40
+ var nodes []types. NodeAddress
151
41
for _ , v := range validators {
152
42
grpcAddr , err := v .GetIP (ctx )
153
43
grpcAddr = grpcAddr + ":9090"
@@ -161,7 +51,7 @@ func generateLoadTestConfig(ctx context.Context, logger *zap.Logger, chain *chai
161
51
return nil , err
162
52
}
163
53
164
- nodes = append (nodes , Node {
54
+ nodes = append (nodes , types. NodeAddress {
165
55
GRPC : grpcAddr ,
166
56
RPC : fmt .Sprintf ("http://%s" , rpcAddr ),
167
57
})
@@ -227,20 +117,20 @@ func generateLoadTestConfig(ctx context.Context, logger *zap.Logger, chain *chai
227
117
}
228
118
time .Sleep (5 * time .Second )
229
119
230
- config := LoadTestConfig {
120
+ config := types. LoadTestSpec {
231
121
ChainID : chainID ,
232
- NumOfBlocks : loadTestConfig .NumOfBlocks ,
122
+ NumOfBlocks : loadTestSpec .NumOfBlocks ,
233
123
NodesAddresses : nodes ,
234
124
Mnemonics : mnemonics ,
235
125
GasDenom : chain .GetConfig ().Denom ,
236
126
Bech32Prefix : chain .GetConfig ().Bech32Prefix ,
237
- Msgs : loadTestConfig .Msgs ,
127
+ Msgs : loadTestSpec .Msgs ,
238
128
}
239
129
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
244
134
} else {
245
135
return nil , fmt .Errorf ("failed to generate load test config, either BlockGasLimitTarget or NumOfTxs must be provided" )
246
136
}
@@ -250,7 +140,7 @@ func generateLoadTestConfig(ctx context.Context, logger *zap.Logger, chain *chai
250
140
}
251
141
252
142
func (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 ) {
254
144
logger , _ := zap .NewDevelopment ()
255
145
256
146
var p provider.ProviderI
@@ -280,7 +170,7 @@ func (a *Activity) RunLoadTest(ctx context.Context, chainState []byte,
280
170
return PackagedState {}, err
281
171
}
282
172
283
- configBytes , err := generateLoadTestConfig (ctx , logger , chain , chain .GetConfig ().ChainId , loadTestConfig )
173
+ configBytes , err := generateLoadTestSpec (ctx , logger , chain , chain .GetConfig ().ChainId , loadTestSpec )
284
174
if err != nil {
285
175
return PackagedState {}, err
286
176
}
@@ -289,7 +179,7 @@ func (a *Activity) RunLoadTest(ctx context.Context, chainState []byte,
289
179
Name : "catalyst" ,
290
180
ContainerName : "catalyst" ,
291
181
Image : provider.ImageDefinition {
292
- Image : "ghcr.io/skip-mev/catalyst:latest " ,
182
+ Image : "ghcr.io/skip-mev/catalyst:dev " ,
293
183
UID : "100" ,
294
184
GID : "100" ,
295
185
},
@@ -340,7 +230,7 @@ func (a *Activity) RunLoadTest(ctx context.Context, chainState []byte,
340
230
return PackagedState {}, fmt .Errorf ("failed to read result file: %w" , err )
341
231
}
342
232
343
- var result LoadTestResult
233
+ var result types. LoadTestResult
344
234
if err := json .Unmarshal (resultBytes , & result ); err != nil {
345
235
return PackagedState {}, fmt .Errorf ("failed to parse result file: %w" , err )
346
236
}
0 commit comments