evilspammer

package
v0.9.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2022 License: Apache-2.0, BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailPostTransaction = errors.New("failed to post transaction")
	ErrFailSendDataBlock   = errors.New("failed to send a data block")

	ErrTransactionIsNil    = errors.New("provided transaction is nil")
	ErrFailToPrepareBatch  = errors.New("custom conflict batch could not be prepared")
	ErrInsufficientClients = errors.New("insufficient clients to send conflicts")
	ErrInputsNotSolid      = errors.New("not all inputs are solid")
)
View Source
var DefaultSpamDetails = &SpamDetails{
	Rate:           10,
	TimeUnit:       time.Second,
	MaxDuration:    time.Minute,
	MaxBatchesSent: 601,
}

Functions

func BigWalletsNeeded

func BigWalletsNeeded(rate int, timeUnit, duration time.Duration) int

BigWalletsNeeded calculates how many big wallets needs to be prepared for a spam based on provided spam details.

func CustomConflictSpammingFunc

func CustomConflictSpammingFunc(s *Spammer)

func DataSpammingFunction

func DataSpammingFunction(s *Spammer)

Types

type ErrorCounter

type ErrorCounter struct {
	// contains filtered or unexported fields
}

ErrorCounter counts errors that appeared during the spam, as during the spam they are ignored and allows to print the summary (might be useful for debugging).

func NewErrorCount

func NewErrorCount() *ErrorCounter

func (*ErrorCounter) CountError

func (e *ErrorCounter) CountError(err error)

func (*ErrorCounter) GetErrorsSummary

func (e *ErrorCounter) GetErrorsSummary() string

func (*ErrorCounter) GetTotalErrorCount

func (e *ErrorCounter) GetTotalErrorCount() int64

type Logger

type Logger interface {
	Infof(template string, args ...interface{})
	Info(args ...interface{})
	Debugf(template string, args ...interface{})
	Debug(args ...interface{})
	Warn(args ...interface{})
	Warnf(template string, args ...interface{})
	Error(args ...interface{})
	Errorf(template string, args ...interface{})
}

type Options

type Options func(*Spammer)

func WithBatchesSent

func WithBatchesSent(maxBatchesSent int) Options

WithBatchesSent provides spammer with options regarding rate, time unit, and finishing spam criteria. Provide 0 to one of max parameters to skip it.

func WithErrorCounter

func WithErrorCounter(errCounter *ErrorCounter) Options

WithErrorCounter allows for setting an error counter object, if not provided a new instance will be created.

func WithEvilScenario

func WithEvilScenario(scenario *evilwallet.EvilScenario) Options

WithEvilScenario provides initWallet of spammer, if omitted spammer will prepare funds based on maxBlkSent parameter

func WithEvilWallet

func WithEvilWallet(initWallets *evilwallet.EvilWallet) Options

WithEvilWallet provides evil wallet instance, that will handle all spam logic according to provided EvilScenario

func WithLogTickerInterval

func WithLogTickerInterval(interval time.Duration) Options

WithLogTickerInterval allows for changing interval between progress spamming logs, default is 30s.

func WithNumberOfSpends

func WithNumberOfSpends(n int) Options

WithNumberOfSpends sets how many transactions should be created with the same input, e.g 3 for triple spend, 2 for double spend. For this to work user needs to make sure that there is enough number of clients.

func WithRateSetter added in v0.9.1

func WithRateSetter(enable bool) Options

WithRateSetter enables setting rate of spammer.

func WithSpamDuration

func WithSpamDuration(maxDuration time.Duration) Options

WithSpamDuration provides spammer with options regarding rate, time unit, and finishing spam criteria. Provide 0 to one of max parameters to skip it.

func WithSpamRate

func WithSpamRate(rate int, timeUnit time.Duration) Options

WithSpamRate provides spammer with options regarding rate, time unit, and finishing spam criteria. Provide 0 to one of max parameters to skip it.

func WithSpammingFunc

func WithSpammingFunc(spammerFunc func(s *Spammer)) Options

WithSpammingFunc sets core function of the spammer with spamming logic, needs to use done spammer's channel to communicate. end of spamming and errors. Default one is the CustomConflictSpammingFunc.

func WithTimeDelayForDoubleSpend

func WithTimeDelayForDoubleSpend(timeDelay time.Duration) Options

type SpamDetails

type SpamDetails struct {
	Rate           int
	TimeUnit       time.Duration
	MaxDuration    time.Duration
	MaxBatchesSent int
}

type Spammer

type Spammer struct {
	SpamDetails   *SpamDetails
	State         *State
	UseRateSetter bool
	Clients       evilwallet.Connector
	EvilWallet    *evilwallet.EvilWallet
	EvilScenario  *evilwallet.EvilScenario
	ErrCounter    *ErrorCounter

	TimeDelayBetweenConflicts time.Duration
	NumberOfSpends            int
	// contains filtered or unexported fields
}

Spammer is a utility object for new spammer creations, can be modified by passing options. Mandatory options: WithClients, WithSpammingFunc Not mandatory options, if not provided spammer will use default settings: WithSpamDetails, WithEvilWallet, WithErrorCounter, WithLogTickerInterval

func NewSpammer

func NewSpammer(options ...Options) *Spammer

NewSpammer is a constructor of Spammer.

func (*Spammer) BatchesPrepared

func (s *Spammer) BatchesPrepared() uint64

func (*Spammer) BlocksSent added in v0.9.2

func (s *Spammer) BlocksSent() uint64

func (*Spammer) CheckIfAllSent

func (s *Spammer) CheckIfAllSent()

func (*Spammer) PostTransaction

func (s *Spammer) PostTransaction(tx *devnetvm.Transaction, clt evilwallet.Client)

PostTransaction use provided client to issue a transaction. It chooses API method based on Spammer options. Counts errors, counts transactions and provides debug logs.

func (*Spammer) Spam

func (s *Spammer) Spam()

Spam runs the spammer. Function will stop after maxDuration time will pass or when maxBlkSent will be exceeded

func (*Spammer) StopSpamming

func (s *Spammer) StopSpamming()

StopSpamming finishes tasks before shutting down the spammer

type SpammerFunc

type SpammerFunc func(*Spammer)

type State

type State struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL