diff --git a/.gitignore b/.gitignore index beb19d1..6612f8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ **seedphrase -**hardhat \ No newline at end of file +**meteorite \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md index a4ae98a..4045ea3 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,8 +1,8 @@ -# Hardhat is Somaitc Labs intellectual property. +# meteorite is Somaitc Labs intellectual property. The source code is here for reference and to encurage the rigorous testing of mainnets in the Cosmos ecosystem. No one will listen if you test testnets. -hardhat is licensed to Somatic Labs for its exclusive use. +meteorite is licensed to Somatic Labs for its exclusive use. Only Somatic is allowed to charge money for the use of this softweare. @@ -17,4 +17,4 @@ The Interchain Foundation, and the teams it funds are not allowed to use this so If you are not charging money for the use of this software, you can use it on production networks to ensure that they live up to the performance claims made by the Interchain Foundation, at no cost. -Somatic Labs will allow all uses of Hardhat by contributors, after a discussion. We encourage contribution to hardhat as we believe that performance claims need to be proven, and that false performance claims are dangerous. +Somatic Labs will allow all uses of meteorite by contributors, after a discussion. We encourage contribution to meteorite as we believe that performance claims need to be proven, and that false performance claims are dangerous. diff --git a/README.md b/README.md index 5df37ff..c462690 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Hardhat +# meteorite ## Overview -Hardhat is a powerful tool designed to empower users to test and validate the performance and security claims of Cosmos-based blockchains. By providing an easy-to-use testing suite, Hardhat enables advanced users to ensure that the blockchains they depend on are robust, secure, and capable of handling real-world conditions. +meteorite is a powerful tool designed to empower users to test and validate the performance and security claims of Cosmos-based blockchains. By providing an easy-to-use testing suite, meteorite enables advanced users to ensure that the blockchains they depend on are robust, secure, and capable of handling real-world conditions. ## Features @@ -14,11 +14,11 @@ Hardhat is a powerful tool designed to empower users to test and validate the pe ## Installation -To install Hardhat, run the following commands: +To install meteorite, run the following commands: ```bash -git clone https://github.com/somatic-labs/hardhat -cd hardhat +git clone https://github.com/somatic-labs/meteorite +cd meteorite go install ./... ``` @@ -26,24 +26,24 @@ go install ./... ## Usage -Hardhat comes with pre-configured mainnet settings available in the `configurations` folder. To get started: +meteorite comes with pre-configured mainnet settings available in the `configurations` folder. To get started: 1. Ensure you have a file named `seedphrase` containing your seed phrase. 2. *(Optional)* Set up your own node with a larger mempool (e.g., 10 GB) that accepts a higher number of transactions (e.g., 50,000). 3. Edit the `nodes.toml` file to include your RPC URLs and adjust any other necessary settings. -4. Run `hardhat` in the same directory as your `nodes.toml` and `seedphrase` files. +4. Run `meteorite` in the same directory as your `nodes.toml` and `seedphrase` files. This will initiate the testing suite with your specified configurations. ## Important Notes -- **Responsible Use**: Hardhat is designed for use on test networks and should be used responsibly. Ensure you have proper authorization before testing on any network you do not own or operate. +- **Responsible Use**: meteorite is designed for use on test networks and should be used responsibly. Ensure you have proper authorization before testing on any network you do not own or operate. - **Valid Transactions Only**: The tool operates within the bounds of valid transactions explicitly supported by the chains it tests. -- **Reporting Issues**: For questions about Hardhat's capabilities or to report potential security issues, please contact the project maintainers through the appropriate channels listed in this repository. +- **Reporting Issues**: For questions about meteorite's capabilities or to report potential security issues, please contact the project maintainers through the appropriate channels listed in this repository. ## Background -Hardhat was developed to enhance the testing capabilities for Cosmos-based blockchains after identifying areas where additional testing tools were needed. By simulating various scenarios, Hardhat helps developers and users alike to better understand the limits and robustness of their chains. +meteorite was developed to enhance the testing capabilities for Cosmos-based blockchains after identifying areas where additional testing tools were needed. By simulating various scenarios, meteorite helps developers and users alike to better understand the limits and robustness of their chains. ### Specific Tests Include: @@ -52,7 +52,7 @@ Hardhat was developed to enhance the testing capabilities for Cosmos-based block ## Outcomes -The release of Hardhat has contributed to: +The release of meteorite has contributed to: - **Improved Awareness**: Highlighting potential vulnerabilities and encouraging proactive improvements in network security. - **Enhanced Security Measures**: Prompting fixes for issues like P2P storms after thorough testing and community engagement. @@ -61,6 +61,6 @@ Additional information is available at [faddat/fasf-report](https://github.com/f ## Contributions and Feedback -We welcome contributions from the community to enhance Hardhat's features and capabilities. If you'd like to contribute or have feedback, please open an issue or submit a pull request on GitHub. +We welcome contributions from the community to enhance meteorite's features and capabilities. If you'd like to contribute or have feedback, please open an issue or submit a pull request on GitHub. --- diff --git a/broadcast/broadcast.go b/broadcast/broadcast.go index c28a39e..02a9b73 100644 --- a/broadcast/broadcast.go +++ b/broadcast/broadcast.go @@ -12,17 +12,16 @@ import ( "github.com/cosmos/ibc-go/v8/modules/apps/transfer" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v8/modules/core" - hardhatbank "github.com/somatic-labs/hardhat/modules/bank" - hardhatibc "github.com/somatic-labs/hardhat/modules/ibc" - wasm "github.com/somatic-labs/hardhat/modules/wasm" - types "github.com/somatic-labs/hardhat/types" + meteoritebank "github.com/somatic-labs/meteorite/modules/bank" + meteoriteibc "github.com/somatic-labs/meteorite/modules/ibc" + wasm "github.com/somatic-labs/meteorite/modules/wasm" + types "github.com/somatic-labs/meteorite/types" sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/std" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -41,10 +40,8 @@ func init() { banktypes.RegisterInterfaces(cdc.InterfaceRegistry()) } -func SendTransactionViaRPC(config types.Config, rpcEndpoint, chainID string, sequence, accnum uint64, - privKey cryptotypes.PrivKey, pubKey cryptotypes.PubKey, fromAddress, msgType string, - msgParams types.MsgParams, -) (response *coretypes.ResultBroadcastTx, txbody string, err error) { +// SendTransactionViaRPC sends a transaction using the provided TransactionParams and sequence number. +func SendTransactionViaRPC(txParams types.TransactionParams, sequence uint64) (response *coretypes.ResultBroadcastTx, txbody string, err error) { encodingConfig := params.MakeTestEncodingConfig() encodingConfig.Codec = cdc @@ -68,30 +65,29 @@ func SendTransactionViaRPC(config types.Config, rpcEndpoint, chainID string, seq var msg sdk.Msg var memo string // Declare a variable to hold the memo - switch msgType { + switch txParams.MsgType { case "ibc_transfer": - msg, memo, err = hardhatibc.CreateIBCTransferMsg(config, fromAddress, msgParams) + msg, memo, err = meteoriteibc.CreateIBCTransferMsg(txParams.Config, txParams.AcctAddress, txParams.MsgParams) if err != nil { return nil, "", err } case "bank_send": - msg, memo, err = hardhatbank.CreateBankSendMsg(config, fromAddress, msgParams) + msg, memo, err = meteoritebank.CreateBankSendMsg(txParams.Config, txParams.AcctAddress, txParams.MsgParams) if err != nil { return nil, "", err } case "store_code": - msg, memo, err = wasm.CreateStoreCodeMsg(config, fromAddress, msgParams) + msg, memo, err = wasm.CreateStoreCodeMsg(txParams.Config, txParams.AcctAddress, txParams.MsgParams) if err != nil { return nil, "", err } case "instantiate_contract": - msg, memo, err = wasm.CreateInstantiateContractMsg(config, fromAddress, msgParams) + msg, memo, err = wasm.CreateInstantiateContractMsg(txParams.Config, txParams.AcctAddress, txParams.MsgParams) if err != nil { return nil, "", err } - default: - return nil, "", fmt.Errorf("unsupported message type: %s", msgType) + return nil, "", fmt.Errorf("unsupported message type: %s", txParams.MsgType) } // Set messages @@ -102,22 +98,22 @@ func SendTransactionViaRPC(config types.Config, rpcEndpoint, chainID string, seq // Estimate gas limit based on transaction size txSize := len(msg.String()) - gasLimit := uint64((int64(txSize) * config.Bytes) + config.BaseGas) + gasLimit := uint64((int64(txSize) * txParams.Config.Bytes) + txParams.Config.BaseGas) txBuilder.SetGasLimit(gasLimit) // Calculate fee based on gas limit and a fixed gas price - gasPrice := sdk.NewDecCoinFromDec(config.Denom, sdkmath.LegacyNewDecWithPrec(config.Gas.Low, config.Gas.Precision)) + gasPrice := sdk.NewDecCoinFromDec(txParams.Config.Denom, sdkmath.LegacyNewDecWithPrec(txParams.Config.Gas.Low, txParams.Config.Gas.Precision)) feeAmount := gasPrice.Amount.MulInt64(int64(gasLimit)).RoundInt() - feecoin := sdk.NewCoin(config.Denom, feeAmount) + feecoin := sdk.NewCoin(txParams.Config.Denom, feeAmount) txBuilder.SetFeeAmount(sdk.NewCoins(feecoin)) // Set the memo (either random for bank_send or as per IBC transfer) txBuilder.SetMemo(memo) txBuilder.SetTimeoutHeight(0) - // First round: we gather all the signer infos. We use the "set empty signature" hack to do that. + // First round: gather all the signer infos using the "set empty signature" hack sigV2 := signing.SignatureV2{ - PubKey: pubKey, + PubKey: txParams.PubKey, Sequence: sequence, Data: &signing.SingleSignatureData{ SignMode: signing.SignMode(encodingConfig.TxConfig.SignModeHandler().DefaultMode()), @@ -126,23 +122,29 @@ func SendTransactionViaRPC(config types.Config, rpcEndpoint, chainID string, seq err = txBuilder.SetSignatures(sigV2) if err != nil { - fmt.Println("error setting signatures") + fmt.Println("Error setting signatures") return nil, "", err } signerData := authsigning.SignerData{ - ChainID: chainID, - AccountNumber: accnum, + ChainID: txParams.ChainID, + AccountNumber: txParams.AccNum, Sequence: sequence, } ctx := context.Background() - signed, err := tx.SignWithPrivKey(ctx, - signing.SignMode(encodingConfig.TxConfig.SignModeHandler().DefaultMode()), signerData, - txBuilder, privKey, encodingConfig.TxConfig, sequence) + signed, err := tx.SignWithPrivKey( + ctx, + signing.SignMode(encodingConfig.TxConfig.SignModeHandler().DefaultMode()), + signerData, + txBuilder, + txParams.PrivKey, + encodingConfig.TxConfig, + sequence, + ) if err != nil { - fmt.Println("couldn't sign") + fmt.Println("Couldn't sign") return nil, "", err } @@ -151,21 +153,22 @@ func SendTransactionViaRPC(config types.Config, rpcEndpoint, chainID string, seq return nil, "", err } - // Generate a JSON string. - txJSONBytes, err := encodingConfig.TxConfig.TxEncoder()(txBuilder.GetTx()) + // Generate the encoded transaction bytes + txBytes, err := encodingConfig.TxConfig.TxEncoder()(txBuilder.GetTx()) if err != nil { fmt.Println(err) return nil, "", err } - resp, err := Transaction(txJSONBytes, rpcEndpoint) + resp, err := Transaction(txBytes, txParams.NodeURL) if err != nil { - return resp, string(txJSONBytes), fmt.Errorf("failed to broadcast transaction: %w", err) + return resp, string(txBytes), fmt.Errorf("failed to broadcast transaction: %w", err) } - return resp, string(txJSONBytes), nil + return resp, string(txBytes), nil } +// Transaction broadcasts the transaction bytes to the given RPC endpoint. func Transaction(txBytes []byte, rpcEndpoint string) (*coretypes.ResultBroadcastTx, error) { cmtCli, err := cometrpc.New(rpcEndpoint, "/websocket") if err != nil { diff --git a/configurations/kujira/nodes.toml b/configurations/kujira/nodes.toml index f2d3f3f..96756b0 100644 --- a/configurations/kujira/nodes.toml +++ b/configurations/kujira/nodes.toml @@ -4,29 +4,22 @@ denom = "ukuji" prefix = "kujira" gas_per_byte = 10 base_gas = 110000 -ibc_memo = "I must politely and firmly question if anyone at Informal or Amulet ran the scripts I provided. To avoid interruptions to ibc, I am now sending transactions down a dead(ish) channel. It would be interesting to at this time observe chain B as well, if transactions are being relayed between them. I'm just one person, so I don't have the capacity to provide all of the instrumentation and such that I'd like give Cosmos teams. I think the issue goes deeper than the mempool, see Kujira. I worked extremely hard to provide information to the relevant teams, and the commentary from them was pretty startling. All of my emails with Amulet are at github.com/somatic-labs/hardhat. Might be good to be a great deal more restrictive abourt aspects of transactions. It is now my 11:52AM. I am doing this because I do not want anyone to be able to. The goal is NOT to distub people, or users, but instead to simply get this issue resolved. I think it is unreasonable that this is still possible. Also I mistakenly used the wrong channel on the first batch of transactions. Really, I don't think that Amulet or Informal ran my scripts. Really. I think that I did everything I reasonably could to report this, over the course of months, and have been retaliated against by many teams for doing so. I don't think that the patch for this belongs in the relayer, and when it comes to performance, I challenge anyone to identify a more meaningful series of events than p2p storms." +ibc_memo = "I must politely and firmly question if anyone at Informal or Amulet ran the scripts I provided. To avoid interruptions to ibc, I am now sending transactions down a dead(ish) channel. It would be interesting to at this time observe chain B as well, if transactions are being relayed between them. I'm just one person, so I don't have the capacity to provide all of the instrumentation and such that I'd like give Cosmos teams. I think the issue goes deeper than the mempool, see Kujira. I worked extremely hard to provide information to the relevant teams, and the commentary from them was pretty startling. All of my emails with Amulet are at github.com/somatic-labs/meteorite. Might be good to be a great deal more restrictive abourt aspects of transactions. It is now my 11:52AM. I am doing this because I do not want anyone to be able to. The goal is NOT to distub people, or users, but instead to simply get this issue resolved. I think it is unreasonable that this is still possible. Also I mistakenly used the wrong channel on the first batch of transactions. Really, I don't think that Amulet or Informal ran my scripts. Really. I think that I did everything I reasonably could to report this, over the course of months, and have been retaliated against by many teams for doing so. I don't think that the patch for this belongs in the relayer, and when it comes to performance, I challenge anyone to identify a more meaningful series of events than p2p storms." memo = "truly I believe there are some larger issues" ibc_memo_repeat = 10 rand_min = 450000 rand_max = 450000 revision_number = 4 -timeout_height = 21901107 +timeout_height = 21901107 slip44 = 118 - - [gas] low = 38 precision = 4 [nodes] -rpc = [ - "http://65.109.118.35:36009", -] +rpc = ["http://65.109.118.35:36009"] api = "https://a-kujira--a1f4bb74a50728120e4f8c8054a8bb4c.gw.notionalapi.net" - - - diff --git a/configurations/kujira2/nodes.toml b/configurations/kujira2/nodes.toml index 8b58d02..58d460d 100644 --- a/configurations/kujira2/nodes.toml +++ b/configurations/kujira2/nodes.toml @@ -4,25 +4,23 @@ denom = "uluna" prefix = "terra" gas_per_byte = 10 base_gas = 110000 -ibc_memo = "I must politely and firmly question if anyone at Informal or Amulet ran the scripts I provided. To avoid interruptions to ibc, I am now sending transactions down a dead(ish) channel. It would be interesting to at this time observe chain B as well, if transactions are being relayed between them. I'm just one person, so I don't have the capacity to provide all of the instrumentation and such that I'd like give Cosmos teams. I think the issue goes deeper than the mempool, see Kujira. I worked extremely hard to provide information to the relevant teams, and the commentary from them was pretty startling. All of my emails with Amulet are at github.com/somatic-labs/hardhat. Might be good to be a great deal more restrictive abourt aspects of transactions. It is now my 11:52AM. I am doing this because I do not want anyone to be able to. The goal is NOT to distub people, or users, but instead to simply get this issue resolved. I think it is unreasonable that this is still possible. Also I mistakenly used the wrong channel on the first batch of transactions. Really, I don't think that Amulet or Informal ran my scripts. Really. I think that I did everything I reasonably could to report this, over the course of months, and have been retaliated against by many teams for doing so. I don't think that the patch for this belongs in the relayer, and when it comes to performance, I challenge anyone to identify a more meaningful series of events than p2p storms." +ibc_memo = "I must politely and firmly question if anyone at Informal or Amulet ran the scripts I provided. To avoid interruptions to ibc, I am now sending transactions down a dead(ish) channel. It would be interesting to at this time observe chain B as well, if transactions are being relayed between them. I'm just one person, so I don't have the capacity to provide all of the instrumentation and such that I'd like give Cosmos teams. I think the issue goes deeper than the mempool, see Kujira. I worked extremely hard to provide information to the relevant teams, and the commentary from them was pretty startling. All of my emails with Amulet are at github.com/somatic-labs/meteorite. Might be good to be a great deal more restrictive abourt aspects of transactions. It is now my 11:52AM. I am doing this because I do not want anyone to be able to. The goal is NOT to distub people, or users, but instead to simply get this issue resolved. I think it is unreasonable that this is still possible. Also I mistakenly used the wrong channel on the first batch of transactions. Really, I don't think that Amulet or Informal ran my scripts. Really. I think that I did everything I reasonably could to report this, over the course of months, and have been retaliated against by many teams for doing so. I don't think that the patch for this belongs in the relayer, and when it comes to performance, I challenge anyone to identify a more meaningful series of events than p2p storms." memo = "I bet that as predicted, size doesn't matter. (thats not what she said)" ibc_memo_repeat = 1 rand_min = 100 rand_max = 300 revision_number = 4 -timeout_height = 21901107 +timeout_height = 21901107 slip44 = 330 - - [gas] low = 28325 precision = 3 [nodes] -rpc = [ +rpc = [ "http://164.132.200.52:26657", "http://136.243.82.69:26657", "http://81.183.230.170:26657", @@ -30,6 +28,3 @@ rpc = [ ] api = "https://a-kujira--a1f4bb74a50728120e4f8c8054a8bb4c.gw.notionalapi.net" - - - diff --git a/configurations/osmosis/nodes.toml b/configurations/osmosis/nodes.toml index 1de68e7..6c64267 100644 --- a/configurations/osmosis/nodes.toml +++ b/configurations/osmosis/nodes.toml @@ -4,29 +4,22 @@ denom = "uosmo" prefix = "osmo" gas_per_byte = 20 base_gas = 120000 -ibc_memo = "I must politely and firmly question if anyone at Informal or Amulet ran the scripts I provided. To avoid interruptions to ibc, I am now sending transactions down a dead(ish) channel. It would be interesting to at this time observe chain B as well, if transactions are being relayed between them. I'm just one person, so I don't have the capacity to provide all of the instrumentation and such that I'd like give Cosmos teams. I think the issue goes deeper than the mempool, see Kujira. I worked extremely hard to provide information to the relevant teams, and the commentary from them was pretty startling. All of my emails with Amulet are at github.com/somatic-labs/hardhat. Might be good to be a great deal more restrictive abourt aspects of transactions. It is now my 11:52AM. I am doing this because I do not want anyone to be able to. The goal is NOT to distub people, or users, but instead to simply get this issue resolved. I think it is unreasonable that this is still possible. Also I mistakenly used the wrong channel on the first batch of transactions. Really, I don't think that Amulet or Informal ran my scripts. Really. I think that I did everything I reasonably could to report this, over the course of months, and have been retaliated against by many teams for doing so. I don't think that the patch for this belongs in the relayer, and when it comes to performance, I challenge anyone to identify a more meaningful series of events than p2p storms." +ibc_memo = "I must politely and firmly question if anyone at Informal or Amulet ran the scripts I provided. To avoid interruptions to ibc, I am now sending transactions down a dead(ish) channel. It would be interesting to at this time observe chain B as well, if transactions are being relayed between them. I'm just one person, so I don't have the capacity to provide all of the instrumentation and such that I'd like give Cosmos teams. I think the issue goes deeper than the mempool, see Kujira. I worked extremely hard to provide information to the relevant teams, and the commentary from them was pretty startling. All of my emails with Amulet are at github.com/somatic-labs/meteorite. Might be good to be a great deal more restrictive abourt aspects of transactions. It is now my 11:52AM. I am doing this because I do not want anyone to be able to. The goal is NOT to distub people, or users, but instead to simply get this issue resolved. I think it is unreasonable that this is still possible. Also I mistakenly used the wrong channel on the first batch of transactions. Really, I don't think that Amulet or Informal ran my scripts. Really. I think that I did everything I reasonably could to report this, over the course of months, and have been retaliated against by many teams for doing so. I don't think that the patch for this belongs in the relayer, and when it comes to performance, I challenge anyone to identify a more meaningful series of events than p2p storms." memo = "I do genuinely think there are larger issues at play" ibc_memo_repeat = 10 rand_min = 50000 rand_max = 50000 revision_number = 4 -timeout_height = 21901107 +timeout_height = 21901107 slip44 = 118 - - [gas] low = 25 precision = 4 [nodes] -rpc = [ - "http://5.9.151.239:26657", -] +rpc = ["http://5.9.151.239:26657"] api = "https://a-osmosis--a1f4bb74a50728120e4f8c8054a8bb4c.gw.notionalapi.net" - - - diff --git a/go.mod b/go.mod index 913cc8f..f5e7c93 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/somatic-labs/hardhat +module github.com/somatic-labs/meteorite go 1.23.1 diff --git a/lib/lib.go b/lib/lib.go index a5e600a..886ad90 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -14,7 +14,7 @@ import ( "time" "github.com/BurntSushi/toml" - "github.com/somatic-labs/hardhat/types" + "github.com/somatic-labs/meteorite/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -29,7 +29,7 @@ var client = &http.Client{ }, } -func GetInitialSequence(address string, config types.Config) (int64, int64) { +func GetAccountInfo(address string, config types.Config) (uint64, uint64) { resp, err := HTTPGet(config.Nodes.API + "/cosmos/auth/v1beta1/accounts/" + address) if err != nil { log.Printf("Failed to get initial sequence: %v", err) @@ -55,7 +55,7 @@ func GetInitialSequence(address string, config types.Config) (int64, int64) { return 0, 0 } - return seqint, accnum + return uint64(seqint), uint64(accnum) } func GetChainID(nodeURL string) (string, error) { diff --git a/lib/privkey.go b/lib/privkey.go index cabed57..36cd0a3 100644 --- a/lib/privkey.go +++ b/lib/privkey.go @@ -3,7 +3,7 @@ package lib import ( "fmt" - types "github.com/somatic-labs/hardhat/types" + types "github.com/somatic-labs/meteorite/types" "github.com/cosmos/cosmos-sdk/crypto/hd" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" diff --git a/main.go b/main.go index 3deb719..0d502b8 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "context" "errors" "fmt" "log" @@ -11,18 +10,14 @@ import ( "time" "github.com/BurntSushi/toml" - coretypes "github.com/cometbft/cometbft/rpc/core/types" - "github.com/somatic-labs/hardhat/broadcast" - "github.com/somatic-labs/hardhat/lib" - "github.com/somatic-labs/hardhat/types" - - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/somatic-labs/meteorite/broadcast" + "github.com/somatic-labs/meteorite/lib" + "github.com/somatic-labs/meteorite/types" ) const ( BatchSize = 100000000 - MaxRetries = 1 - TimeoutDuration = 2 * time.Second + TimeoutDuration = 50 * time.Millisecond ) func main() { @@ -53,152 +48,144 @@ func main() { msgParams := config.MsgParams - successfulTxns, failedTxns := 0, 0 - responseCodes := make(map[uint32]int) + // Get the account info + _, accNum := lib.GetAccountInfo(acctAddress, config) + if err != nil { + log.Fatalf("Failed to get account info: %v", err) + } + + sequence := uint64(1) // Start from sequence number 1 + + // Create a TransactionParams struct + txParams := types.TransactionParams{ + Config: config, + NodeURL: nodeURL, + ChainID: chainID, + Sequence: sequence, + AccNum: accNum, + PrivKey: privKey, + PubKey: pubKey, + AcctAddress: acctAddress, + MsgType: config.MsgType, + MsgParams: msgParams, + } + + // Call the broadcast loop + successfulTxns, failedTxns, responseCodes, _ := broadcastLoop(txParams, BatchSize) - initialSequence, accNum := lib.GetInitialSequence(acctAddress, config) - sequence := initialSequence + // After the loop + fmt.Println("Successful transactions:", successfulTxns) + fmt.Println("Failed transactions:", failedTxns) + totalTxns := successfulTxns + failedTxns + fmt.Println("Response code breakdown:") + for code, count := range responseCodes { + percentage := float64(count) / float64(totalTxns) * 100 + fmt.Printf("Code %d: %d (%.2f%%)\n", code, count, percentage) + } +} - for i := 0; i < BatchSize; i++ { +// broadcastLoop handles the main transaction broadcasting logic +func broadcastLoop( + txParams types.TransactionParams, + batchSize int, +) (successfulTxns, failedTxns int, responseCodes map[uint32]int, updatedSequence uint64) { + successfulTxns = 0 + failedTxns = 0 + responseCodes = make(map[uint32]int) + sequence := txParams.Sequence + + for i := 0; i < batchSize; i++ { currentSequence := sequence - sequence++ + + fmt.Println("FROM LOOP, currentSequence", currentSequence) + fmt.Println("FROM LOOP, accNum", txParams.AccNum) + fmt.Println("FROM LOOP, chainID", txParams.ChainID) start := time.Now() - resp, err := sendTransaction(config, nodeURL, chainID, uint64(currentSequence), uint64(accNum), privKey, pubKey, acctAddress, msgParams) + resp, _, err := broadcast.SendTransactionViaRPC( + txParams, + currentSequence, + ) elapsed := time.Since(start) + fmt.Println("FROM MAIN, err", err) + fmt.Println("FROM MAIN, resp", resp.Code) + if err == nil { fmt.Printf("%s Transaction succeeded, sequence: %d, time: %v\n", time.Now().Format("15:04:05"), currentSequence, elapsed) successfulTxns++ responseCodes[resp.Code]++ + sequence++ // Increment sequence for next transaction continue } - fmt.Printf("%s Error: %v\n", time.Now().Format("15:04:05"), err) - - if !strings.Contains(err.Error(), "account sequence mismatch") { - failedTxns++ - continue - } - - parts := strings.Split(err.Error(), "expected ") - if len(parts) <= 1 { - failedTxns++ - continue - } + fmt.Printf("%s Error: %v\n", time.Now().Format("15:04:05.000"), err) + fmt.Println("FROM MAIN, resp.Code", resp.Code) - expectedSeqParts := strings.Split(parts[1], ",") - if len(expectedSeqParts) == 0 { - failedTxns++ - continue - } + if resp.Code == 32 { + // Extract the expected sequence number from the error message + expectedSeq, parseErr := extractExpectedSequence(err.Error()) + if parseErr != nil { + fmt.Printf("%s Failed to parse expected sequence: %v\n", time.Now().Format("15:04:05.000"), parseErr) + failedTxns++ + continue + } - expectedSeq, parseErr := strconv.ParseInt(expectedSeqParts[0], 10, 64) - if parseErr != nil { - failedTxns++ - continue - } + sequence = expectedSeq + fmt.Printf("%s Set sequence to expected value %d due to mismatch\n", + time.Now().Format("15:04:05"), sequence) - sequence = expectedSeq - fmt.Printf("%s Set sequence to expected value %d due to mismatch\n", - time.Now().Format("15:04:05"), sequence) + // Re-send the transaction with the correct sequence + start = time.Now() + resp, _, err = broadcast.SendTransactionViaRPC( + txParams, + sequence, + ) + elapsed = time.Since(start) - // Re-send the transaction with the correct sequence - start = time.Now() - resp, err = sendTransaction(config, nodeURL, chainID, uint64(sequence), uint64(accNum), privKey, pubKey, acctAddress, msgParams) - elapsed = time.Since(start) + if err != nil { + fmt.Printf("%s Error after adjusting sequence: %v\n", time.Now().Format("15:04:05.000"), err) + failedTxns++ + continue + } - if err != nil { - fmt.Printf("%s Error after adjusting sequence: %v\n", time.Now().Format("15:04:05"), err) - failedTxns++ + fmt.Printf("%s Transaction succeeded after adjusting sequence, sequence: %d, time: %v\n", + time.Now().Format("15:04:05"), sequence, elapsed) + successfulTxns++ + responseCodes[resp.Code]++ + sequence++ // Increment sequence for next transaction continue } + failedTxns++ - fmt.Printf("%s Transaction succeeded after adjusting sequence, sequence: %d, time: %v\n", - time.Now().Format("15:04:05"), currentSequence, elapsed) - successfulTxns++ - responseCodes[resp.Code]++ - } - - fmt.Println("Successful transactions:", successfulTxns) - fmt.Println("Failed transactions:", failedTxns) - totalTxns := successfulTxns + failedTxns - fmt.Println("Response code breakdown:") - for code, count := range responseCodes { - percentage := float64(count) / float64(totalTxns) * 100 - fmt.Printf("Code %d: %d (%.2f%%)\n", code, count, percentage) } + updatedSequence = sequence + return successfulTxns, failedTxns, responseCodes, updatedSequence } -// New helper function to send transaction -func sendTransaction(config types.Config, nodeURL, chainID string, currentSequence, accNum uint64, privKey cryptotypes.PrivKey, pubKey cryptotypes.PubKey, acctAddress string, msgParams types.MsgParams) (*coretypes.ResultBroadcastTx, error) { - return sendTransactionWithRetry( - config, - nodeURL, - chainID, - currentSequence, - accNum, - privKey, // Remove .(cryptotypes.PrivKey) - pubKey, // Remove .(cryptotypes.PubKey) - acctAddress, - config.MsgType, - msgParams, - ) -} - -func sendTransactionWithRetry(config types.Config, nodeURL, chainID string, sequence, accNum uint64, privKey cryptotypes.PrivKey, pubKey cryptotypes.PubKey, acctAddress, msgType string, msgParams types.MsgParams) (*coretypes.ResultBroadcastTx, error) { - var lastErr error - startTime := time.Now() - for retry := 0; retry < MaxRetries; retry++ { - attemptStart := time.Now() - - // Create a context with a timeout for each attempt - ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) - defer cancel() - - respChan := make(chan *coretypes.ResultBroadcastTx) - errChan := make(chan error) - - go func() { - resp, _, err := broadcast.SendTransactionViaRPC( - config, - nodeURL, - chainID, - sequence, - accNum, - privKey, - pubKey, - acctAddress, - msgType, - msgParams, - ) - if err != nil { - errChan <- err - } else { - respChan <- resp - } - }() - - select { - case resp := <-respChan: - return resp, nil - case err := <-errChan: - lastErr = err - case <-ctx.Done(): - lastErr = ctx.Err() - } - - attemptDuration := time.Since(attemptStart) - fmt.Printf("%s Retry %d failed after %v: %v\n", time.Now().Format("15:04:05"), retry, attemptDuration, lastErr) +// Function to extract the expected sequence number from the error message +func extractExpectedSequence(errMsg string) (uint64, error) { + // Parse the error message to extract the expected sequence number + // Example error message: + // "account sequence mismatch, expected 42, got 41: incorrect account sequence" + index := strings.Index(errMsg, "expected ") + if index == -1 { + return 0, errors.New("expected sequence not found in error message") + } - if time.Since(startTime) > 2*time.Second { - return nil, errors.New("total retry time exceeded 2 seconds") - } + start := index + len("expected ") + rest := errMsg[start:] + parts := strings.SplitN(rest, ",", 2) + if len(parts) < 1 { + return 0, errors.New("failed to split expected sequence from error message") + } - time.Sleep(TimeoutDuration) + expectedSeqStr := strings.TrimSpace(parts[0]) + expectedSeq, err := strconv.ParseUint(expectedSeqStr, 10, 64) + if err != nil { + return 0, fmt.Errorf("failed to parse expected sequence number: %v", err) } - totalDuration := time.Since(startTime) - return nil, fmt.Errorf("failed after %d retries in %v: %v", MaxRetries, totalDuration, lastErr) + return expectedSeq, nil } diff --git a/modules/bank/send.go b/modules/bank/send.go index f10d6a9..f7f856a 100644 --- a/modules/bank/send.go +++ b/modules/bank/send.go @@ -3,8 +3,8 @@ package bank import ( "fmt" - "github.com/somatic-labs/hardhat/lib" - types "github.com/somatic-labs/hardhat/types" + "github.com/somatic-labs/meteorite/lib" + types "github.com/somatic-labs/meteorite/types" sdkmath "cosmossdk.io/math" diff --git a/modules/ibc/transfer.go b/modules/ibc/transfer.go index d9125cb..778c352 100644 --- a/modules/ibc/transfer.go +++ b/modules/ibc/transfer.go @@ -7,8 +7,8 @@ import ( transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - lib "github.com/somatic-labs/hardhat/lib" - types "github.com/somatic-labs/hardhat/types" + lib "github.com/somatic-labs/meteorite/lib" + types "github.com/somatic-labs/meteorite/types" sdkmath "cosmossdk.io/math" diff --git a/modules/wasm/wasm.go b/modules/wasm/wasm.go index eb02cb9..59c5134 100644 --- a/modules/wasm/wasm.go +++ b/modules/wasm/wasm.go @@ -6,8 +6,8 @@ import ( "fmt" "os" - "github.com/somatic-labs/hardhat/lib" - types "github.com/somatic-labs/hardhat/types" + "github.com/somatic-labs/meteorite/lib" + types "github.com/somatic-labs/meteorite/types" sdkmath "cosmossdk.io/math" diff --git a/nodes.toml b/nodes.toml index 6bbb08a..2b7b84d 100644 --- a/nodes.toml +++ b/nodes.toml @@ -15,16 +15,16 @@ revision_number = 4 timeout_height = 21720608 slip44 = 118 -msg_type = "store_code" +msg_type = "bank_send" [msg_params] -# if this field is left blank as "", hardhat will send to random accounts endlessly +# if this field is left blank as "", meteorite will send to random accounts endlessly to_address = "" #[msg_params] -wasm_file = "/Users/faddat/hardhat/target/wasm32-unknown-unknown/release/statefilestore.wasm" +wasm_file = "/Users/faddat/meteorite/target/wasm32-unknown-unknown/release/statefilestore.wasm" label = "statefilestore" #msg_type = "instantiate_contract" diff --git a/types/txparams.go b/types/txparams.go index 980a62a..ca75da2 100644 --- a/types/txparams.go +++ b/types/txparams.go @@ -1,20 +1,18 @@ package types import ( - "go/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) type TransactionParams struct { - Config types.Config + Config Config NodeURL string ChainID string - Sequence uint64 + Sequence uint64 // Optional, can be managed separately AccNum uint64 PrivKey cryptotypes.PrivKey PubKey cryptotypes.PubKey AcctAddress string MsgType string - MsgParams map[string]interface{} + MsgParams MsgParams }