Skip to content

Commit a875ac0

Browse files
committed
feat: add evm stress test
1 parent 264d0fa commit a875ac0

File tree

9 files changed

+393
-158
lines changed

9 files changed

+393
-158
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ install:
77
go install ./cmd/...
88

99
gen-0:
10-
chain-stresser generate --validators 1 --sentries 0 --instances 1 --evm true
10+
chain-stresser generate --accounts-num 1000 --validators 1 --sentries 0 --instances 1 --evm true
1111

1212
val-0-start:
1313
injectived --home="./chain-stresser-deploy/validators/0" start
@@ -18,6 +18,9 @@ val-0-clean:
1818
run-bank-send:
1919
chain-stresser tx-bank-send --accounts ./chain-stresser-deploy/instances/0/accounts.json
2020

21+
run-eth-send:
22+
chain-stresser tx-eth-send --accounts ./chain-stresser-deploy/instances/0/accounts.json
23+
2124
cook:
2225
rsync -r ../chain-stresser cooking:~/go/src/
2326

chain/client.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type Client struct {
3939
clientCtx client.Context
4040
}
4141

42+
func (c Client) TxConfig() client.TxConfig {
43+
return c.clientCtx.TxConfig
44+
}
4245
func (c Client) GetNumberSequence(address string) (uint64, uint64, error) {
4346
addr, err := sdk.AccAddressFromBech32(address)
4447
orPanic(err)
@@ -72,6 +75,19 @@ func (c Client) BuildAndSignTx(
7275
)
7376
}
7477

78+
func (c Client) SignTx(
79+
signerAccount Account,
80+
txBuilder client.TxBuilder,
81+
) (signedTx authsigning.Tx, err error) {
82+
return signTx(
83+
c.clientCtx,
84+
signerAccount.Key,
85+
signerAccount.Number,
86+
signerAccount.Sequence,
87+
txBuilder,
88+
)
89+
}
90+
7591
func (c Client) Encode(signedTx authsigning.Tx) []byte {
7692
return bytesOrPanic(c.clientCtx.TxConfig.TxEncoder()(signedTx))
7793
}
@@ -181,10 +197,6 @@ func buildAndSignTx(
181197
gasLimit uint64,
182198
msgs ...sdk.Msg,
183199
) (signedTx authsigning.Tx, err error) {
184-
privKey := &ethsecp256k1.PrivKey{
185-
Key: signerKey,
186-
}
187-
188200
txBuilder := clientCtx.TxConfig.NewTxBuilder()
189201
txBuilder.SetGasLimit(gasLimit)
190202
txBuilder.SetFeeAmount(fee)
@@ -193,6 +205,22 @@ func buildAndSignTx(
193205
return nil, err
194206
}
195207

208+
return signTx(
209+
clientCtx,
210+
signerKey,
211+
accNum,
212+
accSeq,
213+
txBuilder,
214+
)
215+
}
216+
217+
func signTx(
218+
clientCtx client.Context,
219+
signerKey Secp256k1PrivateKey,
220+
accNum, accSeq uint64,
221+
txBuilder client.TxBuilder,
222+
) (signedTx authsigning.Tx, err error) {
223+
196224
signerData := authsigning.SignerData{
197225
ChainID: clientCtx.ChainID,
198226
AccountNumber: accNum,
@@ -204,6 +232,10 @@ func buildAndSignTx(
204232
Signature: nil,
205233
}
206234

235+
privKey := &ethsecp256k1.PrivKey{
236+
Key: signerKey,
237+
}
238+
207239
sig := signing.SignatureV2{
208240
PubKey: privKey.PubKey(),
209241
Data: sigData,

chain/templates/genesis.evm.json.tpl

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
{
2-
"app_name": "injectived",
3-
"app_version": "{{.AppVersion}}",
42
"genesis_time": "{{.GenesisTime}}",
53
"chain_id": "{{.ChainID}}",
64
"initial_height": "1",
7-
"app_hash": null,
5+
"consensus_params": {
6+
"block": {
7+
"max_bytes": "104857600",
8+
"max_gas": "1000000000"
9+
},
10+
"evidence": {
11+
"max_age_num_blocks": "100000",
12+
"max_age_duration": "172800000000000",
13+
"max_bytes": "1048576"
14+
},
15+
"validator": {
16+
"pub_key_types": [
17+
"ed25519"
18+
]
19+
},
20+
"version": {
21+
"app": "0"
22+
},
23+
"abci": {
24+
"vote_extensions_enable_height": "0"
25+
}
26+
},
27+
"app_hash": "",
828
"app_state": {
929
"07-tendermint": null,
1030
"auction": {
@@ -208,15 +228,15 @@
208228
},
209229
"feemarket": {
210230
"params": {
211-
"no_base_fee": false,
231+
"no_base_fee": true,
212232
"base_fee_change_denominator": 8,
213233
"elasticity_multiplier": 2,
214234
"enable_height": "0",
215235
"base_fee": "1000000000",
216236
"min_gas_price": "0.000000000000000000",
217237
"min_gas_multiplier": "0.500000000000000000"
218238
},
219-
"block_gas": "0"
239+
"block_gas": "1000000000"
220240
},
221241
"genutil": {
222242
"gen_txs": []
@@ -509,29 +529,5 @@
509529
},
510530
"registered_contracts": []
511531
}
512-
},
513-
"consensus": {
514-
"params": {
515-
"block": {
516-
"max_bytes": "22020096",
517-
"max_gas": "-1"
518-
},
519-
"evidence": {
520-
"max_age_num_blocks": "100000",
521-
"max_age_duration": "172800000000000",
522-
"max_bytes": "1048576"
523-
},
524-
"validator": {
525-
"pub_key_types": [
526-
"ed25519"
527-
]
528-
},
529-
"version": {
530-
"app": "0"
531-
},
532-
"abci": {
533-
"vote_extensions_enable_height": "0"
534-
}
535-
}
536532
}
537533
}

chain/templates/genesis.json.tpl

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
{
2-
"app_name": "injectived",
3-
"app_version": "{{.AppVersion}}",
42
"genesis_time": "{{.GenesisTime}}",
53
"chain_id": "{{.ChainID}}",
64
"initial_height": "1",
7-
"app_hash": null,
5+
"consensus_params": {
6+
"block": {
7+
"max_bytes": "104857600",
8+
"max_gas": "-1"
9+
},
10+
"evidence": {
11+
"max_age_num_blocks": "100000",
12+
"max_age_duration": "172800000000000",
13+
"max_bytes": "1048576"
14+
},
15+
"validator": {
16+
"pub_key_types": [
17+
"ed25519"
18+
]
19+
},
20+
"version": {
21+
"app": "0"
22+
},
23+
"abci": {
24+
"vote_extensions_enable_height": "0"
25+
}
26+
},
27+
"app_hash": "",
828
"app_state": {
929
"07-tendermint": null,
1030
"auction": {
@@ -440,7 +460,6 @@
440460
"total_escrowed": []
441461
},
442462
"upgrade": {},
443-
"vesting": {},
444463
"wasm": {
445464
"params": {
446465
"code_upload_access": {
@@ -466,29 +485,5 @@
466485
},
467486
"registered_contracts": []
468487
}
469-
},
470-
"consensus": {
471-
"params": {
472-
"block": {
473-
"max_bytes": "22020096",
474-
"max_gas": "-1"
475-
},
476-
"evidence": {
477-
"max_age_num_blocks": "100000",
478-
"max_age_duration": "172800000000000",
479-
"max_bytes": "1048576"
480-
},
481-
"validator": {
482-
"pub_key_types": [
483-
"ed25519"
484-
]
485-
},
486-
"version": {
487-
"app": "0"
488-
},
489-
"abci": {
490-
"vote_extensions_enable_height": "0"
491-
}
492-
}
493488
}
494489
}

cmd/chain-stresser/main.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
defaultNumOfAccounts = 1000
2222
defaultNumOfTx = 100
2323

24-
defaultNumOfValidators = 4
24+
defaultNumOfValidators = 1
2525
defaultNumOfSentries = 0
2626
defaultNumOfInstances = 1
2727
)
@@ -126,6 +126,41 @@ func main() {
126126
}
127127
rootCmd.AddCommand(txBankSendCmd)
128128

129+
txEthSendCmd := &cobra.Command{
130+
Use: "tx-eth-send",
131+
Short: "Run stresstest with eth value send transactions.",
132+
RunE: func(cmd *cobra.Command, args []string) error {
133+
if numOfAccounts <= 0 {
134+
return errors.New("number of accounts must be greater than 0")
135+
}
136+
137+
keysRaw, err := os.ReadFile(accountFile)
138+
if err != nil {
139+
return errors.Wrap(err, "reading account file failed")
140+
} else if err := json.Unmarshal(keysRaw, &stressCfg.Accounts); err != nil {
141+
return errors.Wrap(err, "parsing account file failed")
142+
} else if numOfAccounts > len(stressCfg.Accounts) {
143+
return errors.New("number of accounts is greater than the number of provided private keys")
144+
}
145+
146+
stressCfg.Accounts = stressCfg.Accounts[:numOfAccounts]
147+
148+
sendAmount := "1" + chain.DefaultBondDenom
149+
ethSendProvider, err := payload.NewEthSendProvider(stressCfg.ChainID, stressCfg.MinGasPrice, sendAmount)
150+
if err != nil {
151+
return errors.Wrap(err, "failed to initate eth value send stress provider")
152+
}
153+
154+
if err := stresser.Stress(rootCtx, stressCfg, ethSendProvider); err != nil {
155+
log.Errorf("❌ benchmark failed:\n\n%s", err)
156+
os.Exit(-1)
157+
}
158+
159+
return nil
160+
},
161+
}
162+
rootCmd.AddCommand(txEthSendCmd)
163+
129164
orPanic(rootCmd.Execute())
130165
}
131166

0 commit comments

Comments
 (0)