spammer

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RouteSpammerStatus is the route to get the status of the spammer.
	// GET the current status of the spammer.
	RouteSpammerStatus = "/status"

	// RouteSpammerStart is the route to start the spammer (with optional changing the settings).
	// POST the settings to change and start the spammer.
	RouteSpammerStart = "/start"

	// RouteSpammerStop is the route to stop the spammer.
	// POST to stop the spammer.
	RouteSpammerStop = "/stop"
)
View Source
const (
	AddressIndexSender   = 0
	AddressIndexReceiver = 1
)
View Source
const (
	IndexerQueryMaxResults = 1000
	IndexerQueryTimeout    = 15 * time.Second
)
View Source
const (
	APIRoute = "/api/spammer/v1"
)

Variables

View Source
var (
	// ErrCPUPercentageUnknown is returned if the CPU usage couldn't be determined.
	ErrCPUPercentageUnknown = errors.New("CPU percentage unknown")
)

Functions

func AliasIDFromFoundryID added in v1.0.0

func AliasIDFromFoundryID(foundryID iotago.FoundryID) (iotago.AliasID, error)

Types

type AddInputOption added in v1.0.0

type AddInputOption func(opts *AddInputOptions)

AddInputOption is a function setting an AddInput option.

func WithInputMaxInputsCount added in v1.0.0

func WithInputMaxInputsCount(maxInputsCount int) AddInputOption

WithInputMaxInputsCount sets the maximum allowed inputs.

func WithInputMaxTipsCount added in v1.0.0

func WithInputMaxTipsCount(maxTipsCount int) AddInputOption

WithInputMaxTipsCount sets the maximum allowed required tips.

type AddInputOptions added in v1.0.0

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

AddInputOptions define options for the AddInput function.

type AddOutputOption added in v1.0.0

type AddOutputOption func(opts *AddOutputOptions)

AddOutputOption is a function setting an AddOutput option.

func WithOutputMaxOutputsCount added in v1.0.0

func WithOutputMaxOutputsCount(maxOutputsCount int) AddOutputOption

WithInputMaxInputsCount sets the maximum allowed outputs.

type AddOutputOptions added in v1.0.0

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

AddOutputOptions define options for the AddOutput function.

type AliasUTXO added in v1.0.0

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

func NewAliasUTXO added in v1.0.0

func NewAliasUTXO(outputID iotago.OutputID, output iotago.Output, pendingBlockID iotago.BlockID, foundryOutputs []*UTXO) *AliasUTXO

func (*AliasUTXO) AppendFoundryOutput added in v1.0.0

func (u *AliasUTXO) AppendFoundryOutput(foundryOutput *UTXO)

func (*AliasUTXO) FoundryOutputs added in v1.0.0

func (u *AliasUTXO) FoundryOutputs() []*UTXO

func (*AliasUTXO) Output added in v1.0.0

func (u *AliasUTXO) Output() iotago.Output

func (*AliasUTXO) OutputID added in v1.0.0

func (u *AliasUTXO) OutputID() iotago.OutputID

func (*AliasUTXO) PendingBlockID added in v1.0.0

func (u *AliasUTXO) PendingBlockID() iotago.BlockID

func (*AliasUTXO) SetFoundryOutputs added in v1.0.0

func (u *AliasUTXO) SetFoundryOutputs(foundryOutputs []*UTXO)

type AvgSpamMetrics

type AvgSpamMetrics struct {
	NewBlocks              uint32  `json:"newBlocks"`
	AverageBlocksPerSecond float32 `json:"avgBlocks"`
}

AvgSpamMetrics are average metrics of the created spam.

type BlockMetadataFunc added in v1.0.0

type BlockMetadataFunc = func(blockID iotago.BlockID) (*Metadata, error)

BlockMetadataFunc is a function to fetch the required metadata for a given block ID. This should return nil if the block is not found.

type CPUUsageUpdater

type CPUUsageUpdater struct {
	syncutils.RWMutex
	// contains filtered or unexported fields
}

CPUUsageUpdater measures the CPU usage.

func NewCPUUsageUpdater

func NewCPUUsageUpdater(sampleTime time.Duration, sleepTime time.Duration) *CPUUsageUpdater

NewCPUUsageUpdater creates a new CPUUsageUpdater to measure the CPU usage.

func (*CPUUsageUpdater) CPUUsage

func (c *CPUUsageUpdater) CPUUsage() (float64, error)

CPUUsage returns latest cpu usage.

func (*CPUUsageUpdater) CPUUsageGuessWithAdditionalWorker

func (c *CPUUsageUpdater) CPUUsageGuessWithAdditionalWorker() (float64, error)

CPUUsageGuessWithAdditionalWorker returns guessed cpu usage with another core running at 100% load.

func (*CPUUsageUpdater) Run

func (c *CPUUsageUpdater) Run(ctx context.Context)

Run measures cpu usage until the context is canceled.

func (*CPUUsageUpdater) WaitForLowerCPUUsage

func (c *CPUUsageUpdater) WaitForLowerCPUUsage(ctx context.Context, cpuMaxUsage float64) error

WaitForLowerCPUUsage waits until the cpu usage drops below cpuMaxUsage.

type Events added in v1.0.0

type Events struct {
	// Fired when a single spam block is issued.
	SpamPerformed *event.Event1[*SpamStats]
	// Fired when average spam metrics were updated by the worker.
	AvgSpamMetricsUpdated *event.Event1[*AvgSpamMetrics]
}

Events are the events issued by the spammer.

type GetTipsPoolSizesFunc

type GetTipsPoolSizesFunc = func() (uint32, uint32)

GetTipsPoolSizesFunc returns the current tip pool sizes of the node.

type IsNodeHealthyFunc

type IsNodeHealthyFunc = func() bool

IsNodeHealthyFunc returns whether the node is synced, has active peers and its latest milestone is not too old.

type LedgerAccount added in v1.0.0

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

func NewLedgerAccount added in v1.0.0

func NewLedgerAccount(wallet *hdwallet.HDWallet, addressIndex uint64, protocolParametersFunc func() *iotago.ProtocolParameters) (*LedgerAccount, error)

func (*LedgerAccount) Address added in v1.0.0

func (la *LedgerAccount) Address() iotago.Address

func (*LedgerAccount) AddressBech32 added in v1.0.0

func (la *LedgerAccount) AddressBech32() string

func (*LedgerAccount) AliasOutputs added in v1.0.0

func (la *LedgerAccount) AliasOutputs() []*AliasUTXO

func (*LedgerAccount) AliasOutputsCount added in v1.0.0

func (la *LedgerAccount) AliasOutputsCount() int

func (*LedgerAccount) AppendAliasOutput added in v1.0.0

func (la *LedgerAccount) AppendAliasOutput(aliasOutput *AliasUTXO)

func (*LedgerAccount) AppendBasicOutput added in v1.0.0

func (la *LedgerAccount) AppendBasicOutput(basicOutput *UTXO)

func (*LedgerAccount) AppendFoundryOutput added in v1.0.0

func (la *LedgerAccount) AppendFoundryOutput(foundryOutput *UTXO) error

func (*LedgerAccount) AppendNFTOutput added in v1.0.0

func (la *LedgerAccount) AppendNFTOutput(nftOutput *UTXO)

func (*LedgerAccount) BasicOutputs added in v1.0.0

func (la *LedgerAccount) BasicOutputs() []*UTXO

func (*LedgerAccount) BasicOutputsCount added in v1.0.0

func (la *LedgerAccount) BasicOutputsCount() int

func (*LedgerAccount) CleanupOwnershipBasicOutputs added in v1.0.0

func (la *LedgerAccount) CleanupOwnershipBasicOutputs()

func (*LedgerAccount) ClearSpentOutputs added in v1.0.0

func (la *LedgerAccount) ClearSpentOutputs(spentsMap map[iotago.OutputID]struct{})

func (*LedgerAccount) Empty added in v1.0.0

func (la *LedgerAccount) Empty() bool

func (*LedgerAccount) FoundryOutputsCount added in v1.0.0

func (la *LedgerAccount) FoundryOutputsCount() int

func (*LedgerAccount) NFTOutputs added in v1.0.0

func (la *LedgerAccount) NFTOutputs() []*UTXO

func (*LedgerAccount) NFTOutputsCount added in v1.0.0

func (la *LedgerAccount) NFTOutputsCount() int

func (*LedgerAccount) QueryOutputsFromIndexer added in v1.0.0

func (la *LedgerAccount) QueryOutputsFromIndexer(ctx context.Context,
	indexer nodeclient.IndexerClient,
	allowNativeTokens bool,
	queryBasicOutputs bool,
	queryAliasOutputs bool,
	queryFoundryOutputs bool,
	queryNFTOutputs bool,
	maxResults ...int) error

func (*LedgerAccount) ResetAliasOutputs added in v1.0.0

func (la *LedgerAccount) ResetAliasOutputs()

func (*LedgerAccount) ResetBasicOutputs added in v1.0.0

func (la *LedgerAccount) ResetBasicOutputs()

func (*LedgerAccount) ResetFoundryOutputs added in v1.0.0

func (la *LedgerAccount) ResetFoundryOutputs()

func (*LedgerAccount) ResetNFTOutputs added in v1.0.0

func (la *LedgerAccount) ResetNFTOutputs()

func (*LedgerAccount) ResetOutputs added in v1.0.0

func (la *LedgerAccount) ResetOutputs()

func (*LedgerAccount) SetAliasOutputs added in v1.0.0

func (la *LedgerAccount) SetAliasOutputs(aliasOutputs []*AliasUTXO)

func (*LedgerAccount) SetBasicOutputs added in v1.0.0

func (la *LedgerAccount) SetBasicOutputs(basicOutputs []*UTXO)

func (*LedgerAccount) SetNFTOutputs added in v1.0.0

func (la *LedgerAccount) SetNFTOutputs(nftOutputs []*UTXO)

func (*LedgerAccount) Signer added in v1.0.0

func (la *LedgerAccount) Signer() iotago.AddressSigner

type Metadata added in v1.0.0

type Metadata struct {
	IsReferenced   bool
	IsConflicting  bool
	ShouldReattach bool
}

Metadata contains the basic block metadata required by the spammer.

type Metrics added in v1.0.0

type Metrics struct {
	// The number of sent spam blocks.
	SentSpamBlocks atomic.Uint32
}

Metrics defines metrics for the spammer.

type OutputWithOwnership added in v1.0.0

type OutputWithOwnership struct {
	Output       iotago.Output
	OwnedOutputs []*UTXO
}

type ProtocolParametersFunc added in v1.0.0

type ProtocolParametersFunc = func() *iotago.ProtocolParameters

ProtocolParametersFunc returns the latest protocol parameters from the node.

type RequestTipsFunc

type RequestTipsFunc = func(ctx context.Context, count uint32, allowSemiLazy bool) (iotago.BlockIDs, error)

RequestTipsFunc returns tips chosen by the node.

type SendBlockFunc

type SendBlockFunc = func(ctx context.Context, block *iotago.Block) (iotago.BlockID, error)

SendBlockFunc is a function which sends a block to the network.

type Server added in v1.0.0

type Server struct {
	Spammer *Spammer
}

func NewServer added in v1.0.0

func NewServer(spammer *Spammer, echo *echo.Echo) *Server

type SpamBuilder added in v1.0.0

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

func NewSpamBuilder added in v1.0.0

func NewSpamBuilder(accountSender *LedgerAccount, additionalTag ...string) *SpamBuilder

func (*SpamBuilder) AddInput added in v1.0.0

func (b *SpamBuilder) AddInput(input UTXOInterface, opts ...AddInputOption) bool

AddInput checks if the given input would fit in the transaction and it them if possible.

func (*SpamBuilder) AddOutput added in v1.0.0

func (b *SpamBuilder) AddOutput(output iotago.Output, opts ...AddOutputOption) bool

AddOutput adds the given output to the transaction.

func (*SpamBuilder) AddOutputWithOwnership added in v1.0.0

func (b *SpamBuilder) AddOutputWithOwnership(output iotago.Output, ownedOutputs []*UTXO, opts ...AddOutputOption) bool

AddOutput adds the given output to the transaction.

func (*SpamBuilder) Clone added in v1.0.0

func (b *SpamBuilder) Clone() *SpamBuilder

func (*SpamBuilder) ConsumedInputsEmpty added in v1.0.0

func (b *SpamBuilder) ConsumedInputsEmpty() bool

func (*SpamBuilder) InputConsumed added in v1.0.0

func (b *SpamBuilder) InputConsumed(outputID iotago.OutputID) bool

InputConsumed checks if the given input is already consumed.

type SpamStats

type SpamStats struct {
	Tipselection float32 `json:"tipselect"`
	ProofOfWork  float32 `json:"pow"`
}

SpamStats are stats for a single spam block.

type Spammer

type Spammer struct {
	// the logger used to log events.
	*logger.WrappedLogger
	syncutils.RWMutex

	Events *Events
	// contains filtered or unexported fields
}

Spammer is used to issue blocks to the IOTA network to create load on the tangle.

func New

func New(
	protocolParametersFunc ProtocolParametersFunc,
	indexer nodeclient.IndexerClient,
	wallet *hdwallet.HDWallet,
	bpsRateLimit float64,
	cpuMaxUsage float64,
	workersCount int,
	message string,
	tag string,
	tagSemiLazy string,
	valueSpamEnabled bool,
	valueSpamSendBasicOutput bool,
	valueSpamCollectBasicOutput bool,
	valueSpamCreateAlias bool,
	valueSpamDestroyAlias bool,
	valueSpamCreateFoundry bool,
	valueSpamDestroyFoundry bool,
	valueSpamMintNativeToken bool,
	valueSpamMeltNativeToken bool,
	valueSpamCreateNFT bool,
	valueSpamDestroyNFT bool,
	nonLazyTipsThreshold uint32,
	semiLazyTipsThreshold uint32,
	refreshTipsInterval time.Duration,
	getTipsPoolSizesFunc GetTipsPoolSizesFunc,
	requestTipsFunc RequestTipsFunc,
	isNodeHealthyFunc IsNodeHealthyFunc,
	sendBlockFunc SendBlockFunc,
	blockMetadataFunc BlockMetadataFunc,
	spammerMetrics *Metrics,
	cpuUsageUpdater *CPUUsageUpdater,
	daemon hivedaemon.Daemon,
	log *logger.Logger) (*Spammer, error)

New creates a new spammer instance.

func (*Spammer) ApplyNewLedgerUpdate added in v1.0.0

func (s *Spammer) ApplyNewLedgerUpdate(ctx context.Context, msIndex iotago.MilestoneIndex, createdOutputs iotago.OutputIDs, consumedOutputs iotago.OutputIDs) error

ApplyNewLedgerUpdate applies a new ledger update to the spammer. If a conflict is found, the spammer ledger state is rebuild by querying the indexer.

func (*Spammer) BPSRateLimitRunning

func (s *Spammer) BPSRateLimitRunning() float64

func (*Spammer) BuildTaggedDataBlockAndSend added in v1.0.0

func (s *Spammer) BuildTaggedDataBlockAndSend(ctx context.Context) error

func (*Spammer) BuildTransactionPayloadBlockAndSend added in v1.0.0

func (s *Spammer) BuildTransactionPayloadBlockAndSend(ctx context.Context, spamBuilder *SpamBuilder) ([]UTXOInterface, *UTXO, error)

func (*Spammer) CPUMaxUsageRunning

func (s *Spammer) CPUMaxUsageRunning() float64

func (*Spammer) IsRunning

func (s *Spammer) IsRunning() bool

func (*Spammer) IsValueSpamEnabled added in v1.0.0

func (s *Spammer) IsValueSpamEnabled() bool

func (*Spammer) MeasureSpammerMetrics

func (s *Spammer) MeasureSpammerMetrics()

measureSpammerMetrics measures the spammer metrics.

func (*Spammer) SpammerWorkersRunning

func (s *Spammer) SpammerWorkersRunning() int

func (*Spammer) Start

func (s *Spammer) Start(valueSpamEnabled *bool, bpsRateLimit *float64, cpuMaxUsage *float64, workersCount *int) error

Start starts the spammer to spam with the given settings, otherwise it uses the settings from the config.

func (*Spammer) Stop

func (s *Spammer) Stop() error

Stop stops the spammer.

type UTXO added in v1.0.0

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

unspent outputs.

func NewUTXO added in v1.0.0

func NewUTXO(outputID iotago.OutputID, output iotago.Output, pendingBlockID iotago.BlockID) *UTXO

func (*UTXO) Output added in v1.0.0

func (u *UTXO) Output() iotago.Output

func (*UTXO) OutputID added in v1.0.0

func (u *UTXO) OutputID() iotago.OutputID

func (*UTXO) PendingBlockID added in v1.0.0

func (u *UTXO) PendingBlockID() iotago.BlockID

type UTXOInterface added in v1.0.0

type UTXOInterface interface {
	OutputID() iotago.OutputID
	Output() iotago.Output
	PendingBlockID() iotago.BlockID
}

Jump to

Keyboard shortcuts

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