From acb697a82add126f82bac68000cc4ad779d8af71 Mon Sep 17 00:00:00 2001 From: ReyisaRuby Date: Mon, 30 Jun 2025 15:22:50 +0800 Subject: [PATCH] revise Signed-off-by: ReyisaRuby --- .gitignore | 3 ++- Makefile | 8 ++++---- conf/config.toml | 2 +- test/cmd/uniswap_benchmark/main.go | 25 ++++++++----------------- test/uniswap/uniswapTPS_testcase.go | 14 +++++++++----- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 81dd20f2..cf6fe9d3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ data **/.env **/.*.env -bin/ \ No newline at end of file +bin/ +reddio \ No newline at end of file diff --git a/Makefile b/Makefile index 1afa6625..7341d331 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ PROJECT=reddio default: build build: - go build -v -o ./bin/$(PROJECT) ./cmd/node/main.go ./cmd/node/testrequest.go + go build -v -o ./$(PROJECT) ./cmd/node/main.go ./cmd/node/testrequest.go ## for local dev @@ -13,9 +13,6 @@ build_transfer_test_no_race: build_uniswap_test_no_race: go build -v -o ./bin/uniswap_test ./test/cmd/uniswap/main.go -build_uniswap_benchmark_test: - go build -v -o ./bin/uniswap_benchmark_test ./test/cmd/uniswap_benchmark/main.go - build_transfer_erc20_test_no_race: go build -v -o ./bin/transfer_erc20_test ./test/cmd/erc20/main.go @@ -62,6 +59,9 @@ ci_parallel_single_transfer_erc20_test: reset build_benchmark_test: go build -v -o ./bin/benchmark_test ./test/cmd/benchmark/main.go +build_uniswap_benchmark_test: + go build -v -o ./bin/uniswap_benchmark_test ./test/cmd/uniswap_benchmark/main.go + reset: @if [ -d "yu" ]; then \ echo "Deleting 'yu' directory..."; \ diff --git a/conf/config.toml b/conf/config.toml index e86db734..c14132f5 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -1,7 +1,7 @@ evmProcessorSelector = "serial" enableAsyncCommit = false maxConcurrency = 4 -isBenchmarkMode = false +isBenchmarkMode = true ignoreConflict = false [rateLimitConfig] diff --git a/test/cmd/uniswap_benchmark/main.go b/test/cmd/uniswap_benchmark/main.go index 3313c7e0..765b9811 100644 --- a/test/cmd/uniswap_benchmark/main.go +++ b/test/cmd/uniswap_benchmark/main.go @@ -6,7 +6,6 @@ import ( "time" "github.com/sirupsen/logrus" - "github.com/yu-org/yu/core/startup" "golang.org/x/time/rate" "github.com/reddio-com/reddio/evm" @@ -15,9 +14,8 @@ import ( ) var ( - configPath string + dataPath string evmConfigPath string - maxBlock int qps int action string duration time.Duration @@ -28,33 +26,26 @@ var ( ) func init() { - flag.StringVar(&configPath, "configPath", "", "") + flag.StringVar(&dataPath, "data-path", "./bin/prepared_test_data.json", "Path to uniswap data") flag.StringVar(&evmConfigPath, "evmConfigPath", "./conf/evm.toml", "") - flag.IntVar(&maxBlock, "maxBlock", 500, "") - flag.IntVar(&qps, "qps", 1500, "") - flag.StringVar(&action, "action", "run", "") - flag.DurationVar(&duration, "duration", time.Minute*5, "") - flag.IntVar(&deployUsers, "deployUsers", 10, "") - flag.IntVar(&testUsers, "testUsers", 100, "") + flag.IntVar(&qps, "qps", 5, "") + flag.StringVar(&action, "action", "prepare", "") + flag.DurationVar(&duration, "duration", time.Minute*3, "") + flag.IntVar(&deployUsers, "deployUsers", 1, "") + flag.IntVar(&testUsers, "testUsers", 2, "") flag.BoolVar(&nonConflict, "nonConflict", false, "") flag.IntVar(&maxUsers, "maxUsers", 0, "") } func main() { flag.Parse() - if err := conf.LoadConfig(configPath); err != nil { - panic(err) - } - yuCfg := startup.InitDefaultKernelConfig() - yuCfg.IsAdmin = true - yuCfg.Txpool.PoolSize = 10000000 evmConfig := evm.LoadEvmConfig(evmConfigPath) ethManager := &uniswap.EthManager{} cfg := conf.Config.EthCaseConf limiter := rate.NewLimiter(rate.Limit(qps), qps) ethManager.Configure(cfg, evmConfig) ethManager.AddTestCase( - uniswap.NewUniswapV2TPSStatisticsTestCase("UniswapV2 TPS StatisticsTestCase", deployUsers, testUsers, maxUsers, limiter, action == "run", nonConflict)) + uniswap.NewUniswapV2TPSStatisticsTestCase("UniswapV2 TPS StatisticsTestCase", deployUsers, testUsers, maxUsers, limiter, action == "run", nonConflict, dataPath)) switch action { case "prepare": prepareBenchmark(context.Background(), ethManager) diff --git a/test/uniswap/uniswapTPS_testcase.go b/test/uniswap/uniswapTPS_testcase.go index ec3b2bb7..38073063 100644 --- a/test/uniswap/uniswapTPS_testcase.go +++ b/test/uniswap/uniswapTPS_testcase.go @@ -6,6 +6,7 @@ import ( "fmt" "math/big" "math/rand" + "os" "time" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -33,6 +34,7 @@ const ( ) type UniswapV2TPSStatisticsTestCase struct { + dataPath string MaxUsers int NonConflict bool TestUsers int @@ -54,7 +56,7 @@ func (cd *UniswapV2TPSStatisticsTestCase) Name() string { return cd.CaseName } -func NewUniswapV2TPSStatisticsTestCase(name string, t, d, maxUser int, rm *rate.Limiter, needLoad, nonConflict bool) *UniswapV2TPSStatisticsTestCase { +func NewUniswapV2TPSStatisticsTestCase(name string, t, d, maxUser int, rm *rate.Limiter, needLoad, nonConflict bool, dataPath string) *UniswapV2TPSStatisticsTestCase { tc := &UniswapV2TPSStatisticsTestCase{ MaxUsers: maxUser, NonConflict: nonConflict, @@ -62,13 +64,15 @@ func NewUniswapV2TPSStatisticsTestCase(name string, t, d, maxUser int, rm *rate. TestUsers: d, CaseName: name, rm: rm, + dataPath: dataPath, } if needLoad { - loadedTestData, err := loadTestDataFromFile("test/tmp/prepared_test_data.json") + loadedTestData, err := loadTestDataFromFile(dataPath) if err != nil { logrus.Fatalf("Failed to load test data: %v", err) return nil } + logrus.Infof("loaded test data, testUsers:%v, testContracts:%v", len(loadedTestData.TestUsers), len(loadedTestData.TestContracts)) tc.loadTestData = loadedTestData } return tc @@ -201,6 +205,7 @@ func (cd *UniswapV2TPSStatisticsTestCase) prepareDeployerContract(deployerUser * } func (cd *UniswapV2TPSStatisticsTestCase) Prepare(ctx context.Context, m *pkg.WalletManager) error { + os.Remove(cd.dataPath) deployerUsers, err := m.GenerateRandomWallets(cd.DeployedUsers, accountInitialFunds) if err != nil { return fmt.Errorf("failed to generate deployer user: %v", err.Error()) @@ -223,7 +228,7 @@ func (cd *UniswapV2TPSStatisticsTestCase) Prepare(ctx context.Context, m *pkg.Wa TestContracts: make([]TestContract, 0), } for index, deployerUser := range deployerUsers { - logrus.Infof("start to deploy %v contract", index) + logrus.Infof("start to deploy %v contract", index+1) router, tokenPairs, err := cd.prepareDeployerContract(deployerUser, testUsers, gasPrice, client) if err != nil { return fmt.Errorf("prepare contract failed, err:%v", err) @@ -231,7 +236,7 @@ func (cd *UniswapV2TPSStatisticsTestCase) Prepare(ctx context.Context, m *pkg.Wa preparedTestData.TestContracts = append(preparedTestData.TestContracts, TestContract{router, tokenPairs}) logrus.Infof("create %v deploy contract done", index+1) } - saveTestDataToFile("test/tmp/prepared_test_data.json", preparedTestData) + saveTestDataToFile(cd.dataPath, preparedTestData) return err } @@ -253,7 +258,6 @@ func (cd *UniswapV2TPSStatisticsTestCase) executeTest(nodeUrl string, chainID in logrus.Infof("Failed to perform swap steps: %v", err) return err } - return nil }