From e541c256e2b70d113797b994fa3a8a46f70b7d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Wed, 17 Apr 2024 15:46:28 +0200 Subject: [PATCH] Do not spam too many gorutines for short spams --- programs/faucet.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/programs/faucet.go b/programs/faucet.go index da6a5f9..f96c231 100644 --- a/programs/faucet.go +++ b/programs/faucet.go @@ -8,6 +8,7 @@ import ( "github.com/iotaledger/evil-tools/pkg/evilwallet" "github.com/iotaledger/evil-tools/pkg/spammer" + "github.com/iotaledger/hive.go/lo" "github.com/iotaledger/hive.go/log" "github.com/iotaledger/hive.go/runtime/workerpool" ) @@ -15,7 +16,7 @@ import ( const ( MaxPendingRequestsRunning = 20 FaucetFundsAwaitTimeout = 3 * time.Minute - SelectCheckInterval = 2 * time.Second + SelectCheckInterval = 1 * time.Second ) func faucetFundsNeededForSpamType(spamType string) bool { @@ -44,7 +45,8 @@ func RequestFaucetFunds(ctx context.Context, logger log.Logger, paramsSpammer *s } canSubmit := func() bool { - return running.Load() < MaxPendingRequestsRunning && w.UnspentOutputsLeft(evilwallet.Fresh) <= 2*minFundsDeposit + maxRequests := int32(lo.Min(totalWalletsNeeded, MaxPendingRequestsRunning)) + return running.Load() < maxRequests && w.UnspentOutputsLeft(evilwallet.Fresh) <= 2*minFundsDeposit } if paramsSpammer.Duration == spammer.InfiniteDuration {