diff --git a/.gitignore b/.gitignore index 033cc62..16ea7d9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ release/ .DS_Store go.work go.work.sum -go.work.backup \ No newline at end of file +go.work.backup +stress_test.log \ No newline at end of file diff --git a/app/app.go b/app/app.go index d0be61d..e7ea364 100644 --- a/app/app.go +++ b/app/app.go @@ -29,7 +29,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/auth/ante" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -115,7 +114,6 @@ import ( cosmosdaemonmoduletypes "cosmos-daemon/x/cosmosdaemon/types" ugdvestingmodule "github.com/unigrid-project/cosmos-sdk-unigrid-hedgehog-vesting/x/ugdvesting" - ugdvestingante "github.com/unigrid-project/cosmos-sdk-unigrid-hedgehog-vesting/x/ugdvesting/ante" ugdvestingmodulekeeper "github.com/unigrid-project/cosmos-sdk-unigrid-hedgehog-vesting/x/ugdvesting/keeper" ugdvestingmoduletypes "github.com/unigrid-project/cosmos-sdk-unigrid-hedgehog-vesting/x/ugdvesting/types" @@ -541,6 +539,7 @@ func New( keys[ugdvestingmoduletypes.StoreKey], memKeys[ugdvestingmoduletypes.MemStoreKey], app.GetSubspace(ugdvestingmoduletypes.ModuleName), + app.BankKeeper, // Assuming you have initialized the BankKeeper in your app ) app.CosmosdaemonKeeper = *cosmosdaemonmodulekeeper.NewKeeper( @@ -738,23 +737,6 @@ func New( app.MountKVStores(keys) app.MountTransientStores(tkeys) app.MountMemoryStores(memKeys) - - // initialize BaseApp - anteHandler, err := ugdvestingante.NewAnteHandler( - ante.HandlerOptions{ - AccountKeeper: app.AccountKeeper, - BankKeeper: app.BankKeeper, - SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), - FeegrantKeeper: app.FeeGrantKeeper, - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - }, - app.UgdvestingKeeper, - ) - if err != nil { - panic(fmt.Errorf("failed to create AnteHandler: %w", err)) - } - - app.SetAnteHandler(anteHandler) app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) app.SetEndBlocker(app.EndBlocker) diff --git a/go.mod b/go.mod index 9b09bcd..761b294 100644 --- a/go.mod +++ b/go.mod @@ -18,8 +18,8 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.16.0 github.com/stretchr/testify v1.8.3 - github.com/unigrid-project/cosmos-sdk-ugdmint v0.0.50 - github.com/unigrid-project/cosmos-sdk-unigrid-hedgehog-vesting v0.0.6 + github.com/unigrid-project/cosmos-sdk-ugdmint v0.0.56 + github.com/unigrid-project/cosmos-sdk-unigrid-hedgehog-vesting v0.0.10 google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 google.golang.org/grpc v1.55.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 4f6b391..198d1a3 100644 --- a/go.sum +++ b/go.sum @@ -941,10 +941,10 @@ github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0 github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8= github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= -github.com/unigrid-project/cosmos-sdk-ugdmint v0.0.50 h1:xNIpPsWkSUSKH/okPqAnCNphmodrmDw3S9VsqiP8xys= -github.com/unigrid-project/cosmos-sdk-ugdmint v0.0.50/go.mod h1:IQBurErJi44DZiaCMkG6sMXJNR9JRple25CBuurJf9M= -github.com/unigrid-project/cosmos-sdk-unigrid-hedgehog-vesting v0.0.6 h1:IJgSvvLwLfnA7tf+ZWIARvxR/uFgSBI+pbjq8a8gPAw= -github.com/unigrid-project/cosmos-sdk-unigrid-hedgehog-vesting v0.0.6/go.mod h1:0TR+spiiRNIybq8dk9jrP5DdkXQe311tr5e6Q/cqgvs= +github.com/unigrid-project/cosmos-sdk-ugdmint v0.0.56 h1:rtdgzyMAV7QJQMoKgDQsKBFPNFTfzST+Wow7VUpncX4= +github.com/unigrid-project/cosmos-sdk-ugdmint v0.0.56/go.mod h1:IQBurErJi44DZiaCMkG6sMXJNR9JRple25CBuurJf9M= +github.com/unigrid-project/cosmos-sdk-unigrid-hedgehog-vesting v0.0.10 h1:Q8N2MVmWY46FWPgSoPU3kouPanUc4++zPTEfXA+kB2I= +github.com/unigrid-project/cosmos-sdk-unigrid-hedgehog-vesting v0.0.10/go.mod h1:0TR+spiiRNIybq8dk9jrP5DdkXQe311tr5e6Q/cqgvs= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= diff --git a/stress_test.py b/stress_test.py new file mode 100644 index 0000000..cfe45fe --- /dev/null +++ b/stress_test.py @@ -0,0 +1,117 @@ +import json +import time +from colorama import Fore, init +import pexpect +import threading + +init(autoreset=True) + +DAEMON_PATH = "/home/evan/go/bin/cosmos-daemond" +LOG_FILE = "stress_test.log" +FROM_ADDRESS = "unigrid1attpyzmtq9k4r42gkglnx0edgukjh969jrsmn8" +TO_ADDRESS = "unigrid1xeq4qwyhxfukx0xyultta0r882ev86jjs4yvtc" + +# Define a global variable for the transaction count +tx_count = 0 +tx_count_lock = threading.Lock() + + +def send_tokens(password): + cmd = f"{DAEMON_PATH} tx bank send {FROM_ADDRESS} {TO_ADDRESS} 1ugd --home=/home/evan/.unigrid-testnet-1 --fees=0.025uugd" + child = pexpect.spawn(cmd) + + # Always expect the confirmation prompt and confirm + child.expect( + "confirm transaction before signing and broadcasting \[y/N\]:") + child.sendline("y") + + # Check if the password prompt appears + i = child.expect(["Password:", pexpect.EOF]) + if i == 0: # Password prompt appeared + child.sendline(password) + child.expect(pexpect.EOF) + + # Parse the output to check for transaction success + output = child.before.decode() + # print("Transaction Output:", output) # Debugging statement + if "txhash" in output: + return True + + return False + + +def stress_test(password, duration=10): + start_time = time.time() + tx_count = 0 + speeds = [] + + with open(LOG_FILE, "w") as log: + while time.time() - start_time < duration: + if send_tokens(password): + tx_count += 1 + current_speed = tx_count / (time.time() - start_time) + speeds.append(current_speed) + avg_speed = sum(speeds) / len(speeds) + slowdown = avg_speed - current_speed + + print(f"{Fore.GREEN}Speed: {current_speed:.2f} tx/s", end=" ") + print(f"{Fore.YELLOW}Average: {avg_speed:.2f} tx/s", end=" ") + print(f"{Fore.RED}Slowdown: {slowdown:.2f} tx/s") + + log.write( + f"{time.time() - start_time:.2f}s: Speed: {current_speed:.2f} tx/s, Average: {avg_speed:.2f} tx/s, Slowdown: {slowdown:.2f} tx/s\n") + + print(f"\nTest completed. Total transactions: {tx_count}") + + +def display_metrics(duration): + start_time = time.time() + speeds = [] + while time.time() - start_time < duration: + time.sleep(1) # Update metrics every second + current_speed = tx_count / (time.time() - start_time) + speeds.append(current_speed) + avg_speed = sum(speeds) / len(speeds) + slowdown = avg_speed - current_speed + + print(f"{Fore.GREEN}Speed: {current_speed:.2f} tx/s", end=" ") + print(f"{Fore.YELLOW}Average: {avg_speed:.2f} tx/s", end=" ") + print(f"{Fore.RED}Slowdown: {slowdown:.2f} tx/s") + + +def send_tokens_threaded(password, duration): + global tx_count + start_time = time.time() + while time.time() - start_time < duration: + if send_tokens(password): + with tx_count_lock: + tx_count += 1 + + +def stress_test_concurrent(password, duration=10, num_threads=30): + global tx_count + tx_count = 0 # Reset the transaction count + + # Start threads for sending transactions + threads = [] + for _ in range(num_threads): + t = threading.Thread(target=send_tokens_threaded, args=(password, duration)) + threads.append(t) + t.start() + + # Start a separate thread for displaying metrics + metrics_thread = threading.Thread(target=display_metrics, args=(duration,)) + metrics_thread.start() + + for t in threads: + t.join() + + metrics_thread.join() + + print(f"\nTest completed. Total transactions: {tx_count}") + + +if __name__ == "__main__": + password = input("Enter the password: ") + # stress_test(password) + stress_test_concurrent(password)