Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add infinite spam and cleanup #15

Merged
merged 18 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ var (
customSpamParams = programs.CustomSpamParams{
ClientURLs: urls,
FaucetURL: "http://localhost:8088",
SpamTypes: []string{spammer.TypeBlock},
Rates: []int{1},
Durations: []time.Duration{time.Second * 20},
BlkToBeSent: []int{0},
SpamType: spammer.TypeBlock,
Rate: 1,
TimeUnit: time.Second,
DelayBetweenConflicts: 0,
NSpend: 2,
Scenario: evilwallet.Scenario1(),
ScenarioName: "guava",
DeepSpam: false,
EnableRateSetter: false,
AccountAlias: accountwallet.FaucetAccountAlias,
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func main() {
case ScriptInteractive:
interactive.Run()
case ScriptSpammer:
programs.CustomSpam(&customSpamParams, accWallet)
dispatcher := programs.NewDispatcher(accWallet)
dispatcher.RunSpam(&customSpamParams)
case ScriptAccounts:
accountsSubcommands(accWallet, accountsSubcommandsFlags)
default:
Expand Down
59 changes: 11 additions & 48 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"flag"
"fmt"
"os"
"strconv"
"strings"
"time"

"github.com/iotaledger/evil-tools/pkg/accountwallet"
"github.com/iotaledger/evil-tools/pkg/evilwallet"
"github.com/iotaledger/evil-tools/pkg/spammer"
"github.com/iotaledger/hive.go/ierrors"
)

Expand Down Expand Up @@ -56,12 +56,11 @@ func parseOptionFlagSet(flagSet *flag.FlagSet, args ...[]string) {

func parseBasicSpamFlags() {
urls := optionFlagSet.String("urls", "", "API urls for clients used in test separated with commas")
spamTypes := optionFlagSet.String("spammer", "", "Spammers used during test. Format: strings separated with comma, available options: 'blk' - block,"+
spamType := optionFlagSet.String("spammer", "", "Spammers used during test. Format: strings separated with comma, available options: 'blk' - block,"+
" 'tx' - transaction, 'ds' - double spends spammers, 'nds' - n-spends spammer, 'custom' - spams with provided scenario, 'bb' - blowball")
rate := optionFlagSet.String("rate", "", "Spamming rate for provided 'spammer'. Format: numbers separated with comma, e.g. 10,100,1 if three spammers were provided for 'spammer' parameter.")
duration := optionFlagSet.String("duration", "", "Spam duration. Cannot be combined with flag 'blkNum'. Format: separated by commas list of decimal numbers, each with optional fraction and a unit suffix, such as '300ms', '-1.5h' or '2h45m'.\n Valid time units are 'ns', 'us', 'ms', 's', 'm', 'h'.")
blkNum := optionFlagSet.String("blkNum", "", "Spam duration in seconds. Cannot be combined with flag 'duration'. Format: numbers separated with comma, e.g. 10,100,1 if three spammers were provided for 'spammer' parameter.")
timeunit := optionFlagSet.Duration("tu", customSpamParams.TimeUnit, "Time unit for the spamming rate. Format: decimal numbers, each with optional fraction and a unit suffix, such as '300ms', '-1.5h' or '2h45m'.\n Valid time units are 'ns', 'us', 'ms', 's', 'm', 'h'.")
rate := optionFlagSet.Int("rate", customSpamParams.Rate, "Spamming rate for provided 'spammer'. Format: numbers separated with comma, e.g. 10,100,1 if three spammers were provided for 'spammer' parameter.")
duration := optionFlagSet.String("duration", "", "Spam duration. If not provided spam will lats infinitely. Format: separated by commas list of decimal numbers, each with optional fraction and a unit suffix, such as '300ms', '-1.5h' or '2h45m'.\n Valid time units are 'ns', 'us', 'ms', 's', 'm', 'h'.")
timeunit := optionFlagSet.Duration("unit", customSpamParams.TimeUnit, "Time unit for the spamming rate. Format: decimal numbers, each with optional fraction and a unit suffix, such as '300ms', '-1.5h' or '2h45m'.\n Valid time units are 'ns', 'us', 'ms', 's', 'm', 'h'.")
delayBetweenConflicts := optionFlagSet.Duration("dbc", customSpamParams.DelayBetweenConflicts, "delayBetweenConflicts - Time delay between conflicts in double spend spamming")
scenario := optionFlagSet.String("scenario", "", "Name of the EvilBatch that should be used for the spam. By default uses Scenario1. Possible scenarios can be found in evilwallet/customscenarion.go.")
deepSpam := optionFlagSet.Bool("deep", customSpamParams.DeepSpam, "Enable the deep spam, by reusing outputs created during the spam.")
Expand All @@ -74,26 +73,18 @@ func parseBasicSpamFlags() {
parsedUrls := parseCommaSepString(*urls)
customSpamParams.ClientURLs = parsedUrls
}
if *spamTypes != "" {
parsedSpamTypes := parseCommaSepString(*spamTypes)
customSpamParams.SpamTypes = parsedSpamTypes
}
if *rate != "" {
parsedRates := parseCommaSepInt(*rate)
customSpamParams.Rates = parsedRates
}
customSpamParams.SpamType = *spamType
customSpamParams.Rate = *rate
if *duration != "" {
parsedDurations := parseDurations(*duration)
customSpamParams.Durations = parsedDurations
}
if *blkNum != "" {
parsedBlkNums := parseCommaSepInt(*blkNum)
customSpamParams.BlkToBeSent = parsedBlkNums
customSpamParams.Duration, _ = time.ParseDuration(*duration)
} else {
customSpamParams.Duration = spammer.InfiniteDuration
}
if *scenario != "" {
conflictBatch, ok := evilwallet.GetScenario(*scenario)
if ok {
customSpamParams.Scenario = conflictBatch
customSpamParams.ScenarioName = *scenario
}
}

Expand All @@ -104,14 +95,6 @@ func parseBasicSpamFlags() {
if *account != "" {
customSpamParams.AccountAlias = *account
}

// fill in unused parameter: blkNum or duration with zeros
if *duration == "" && *blkNum != "" {
customSpamParams.Durations = make([]time.Duration, len(customSpamParams.BlkToBeSent))
}
if *blkNum == "" && *duration != "" {
customSpamParams.BlkToBeSent = make([]int, len(customSpamParams.Durations))
}
}

// readSubcommandsAndFlagSets splits the subcommands on multiple flag sets.
Expand Down Expand Up @@ -436,23 +419,3 @@ func parseCommaSepString(urls string) []string {

return split
}

func parseCommaSepInt(nums string) []int {
split := strings.Split(nums, ",")
parsed := make([]int, len(split))
for i, num := range split {
parsed[i], _ = strconv.Atoi(num)
}

return parsed
}

func parseDurations(durations string) []time.Duration {
split := strings.Split(durations, ",")
parsed := make([]time.Duration, len(split))
for i, dur := range split {
parsed[i], _ = time.ParseDuration(dur)
}

return parsed
}
34 changes: 11 additions & 23 deletions pkg/evilwallet/evilwallet.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package evilwallet

import (
"fmt"
"sync"
"time"

Expand All @@ -22,8 +21,15 @@ import (

const (
// FaucetRequestSplitNumber defines the number of outputs to split from a faucet request.
FaucetRequestSplitNumber = 120
faucetTokensPerRequest iotago.BaseToken = 432_000_000
FaucetRequestSplitNumber = 50
// MaxBigWalletsCreatedAtOnce is maximum of evil wallets that can be created at once for non-infinite spam.
MaxBigWalletsCreatedAtOnce = 10
// BigFaucetWalletDeposit indicates the minimum outputs left number that triggers funds requesting in the background.
BigFaucetWalletDeposit = 4
// CheckFundsLeftInterval is the interval to check funds left in the background for requesting funds triggering.
CheckFundsLeftInterval = time.Second * 5
// BigFaucetWalletsAtOnce number of faucet wallets requested at once in the background.
BigFaucetWalletsAtOnce = 2
)

var (
Expand Down Expand Up @@ -213,7 +219,7 @@ func (e *EvilWallet) RequestFreshBigFaucetWallets(numberOfWallets int) bool {
}
wg.Wait()

e.log.Debugf("Finished requesting %d wallets from faucet", numberOfWallets)
e.log.Debugf("Finished requesting %d wallets from faucet, outputs available: %d", numberOfWallets, e.UnspentOutputsLeft(Fresh))

return success
}
Expand Down Expand Up @@ -464,28 +470,11 @@ func (e *EvilWallet) CreateTransaction(options ...Option) (*models.PayloadIssuan
e.addOutputsToOutputManager(signedTx, buildOptions.outputWallet, tempWallet, tempAddresses)
e.registerOutputAliases(signedTx, addrAliasMap)

e.log.Debugf("\n %s", printTransaction(signedTx))
//e.log.Debugf("\n %s", printTransaction(signedTx))

return txData, nil
}

func printTransaction(tx *iotago.SignedTransaction) string {
txDetails := ""
txDetails += fmt.Sprintf("Transaction ID; %s, slotCreation: %d\n", lo.PanicOnErr(tx.ID()).ToHex(), tx.Transaction.CreationSlot)
for index, out := range tx.Transaction.Outputs {
txDetails += fmt.Sprintf("Output index: %d, base token: %d, stored mana: %d\n", index, out.BaseTokenAmount(), out.StoredMana())
}
txDetails += fmt.Sprintln("Allotments:")
for _, allotment := range tx.Transaction.Allotments {
txDetails += fmt.Sprintf("AllotmentID: %s, value: %d\n", allotment.AccountID, allotment.Mana)
}
for _, allotment := range tx.Transaction.TransactionEssence.Allotments {
txDetails += fmt.Sprintf("al 2 AllotmentID: %s, value: %d\n", allotment.AccountID, allotment.Mana)
}

return txDetails
}

// addOutputsToOutputManager adds output to the OutputManager if.
func (e *EvilWallet) addOutputsToOutputManager(signedTx *iotago.SignedTransaction, outWallet, tmpWallet *Wallet, tempAddresses map[string]types.Empty) {
for idx, o := range signedTx.Transaction.Outputs {
Expand Down Expand Up @@ -762,7 +751,6 @@ func (e *EvilWallet) updateOutputBalances(buildOptions *Options) (err error) {
}

func (e *EvilWallet) makeTransaction(inputs []*models.Output, outputs iotago.Outputs[iotago.Output], w *Wallet, congestionResponse *apimodels.CongestionResponse, issuerAccountID iotago.AccountID) (tx *iotago.SignedTransaction, err error) {
e.log.Debugf("makeTransaction len(outputs): %d", len(outputs))
clt := e.Connector().GetClient()
currentTime := time.Now()
targetSlot := clt.LatestAPI().TimeProvider().SlotFromTime(currentTime)
Expand Down
Loading
Loading