Documentation
¶
Index ¶
- type Daemon
- func (d *Daemon) DeleteSpammer(id int64) error
- func (d *Daemon) ExportSpammers(spammerIDs ...int64) (string, error)
- func (d *Daemon) GetAllSpammers() []*Spammer
- func (d *Daemon) GetClientPool() *spamoor.ClientPool
- func (d *Daemon) GetGlobalCfg() map[string]interface{}
- func (d *Daemon) GetRootWallet() *spamoor.RootWallet
- func (d *Daemon) GetSpammer(id int64) *Spammer
- func (d *Daemon) ImportSpammers(input string) (*ImportResult, error)
- func (d *Daemon) ImportSpammersOnStartup(source string, logger logrus.FieldLogger) error
- func (d *Daemon) InitializeMetrics() error
- func (d *Daemon) NewMetricsCollector() *MetricsCollector
- func (d *Daemon) NewSpammer(scenarioName string, config string, name string, description string, ...) (*Spammer, error)
- func (d *Daemon) ReclaimSpammer(id int64) error
- func (d *Daemon) Run() (bool, error)
- func (d *Daemon) SetGlobalCfg(name string, value interface{})
- func (d *Daemon) Shutdown()
- func (d *Daemon) TrackSpammerStatusChange(spammerID int64, running bool)
- func (d *Daemon) TrackTransactionFailure(spammerID int64)
- func (d *Daemon) TrackTransactionSent(spammerID int64)
- func (d *Daemon) UpdateSpammer(id int64, name string, description string, config string) error
- type ExportSpammerConfig
- type ImportItem
- type ImportResult
- type ImportValidationResult
- type ImportedSpammerInfo
- type MetricsCollector
- func (mc *MetricsCollector) IncrementTransactionFailures(spammerID int64, spammerName, scenario string)
- func (mc *MetricsCollector) IncrementTransactionsSent(spammerID int64, spammerName, scenario string)
- func (mc *MetricsCollector) SetSpammerRunning(spammerID int64, spammerName, scenario string, running bool)
- type Spammer
- func (s *Spammer) GetConfig() string
- func (s *Spammer) GetCreatedAt() int64
- func (s *Spammer) GetDescription() string
- func (s *Spammer) GetID() int64
- func (s *Spammer) GetLogScope() *logscope.LogScope
- func (s *Spammer) GetName() string
- func (s *Spammer) GetScenario() string
- func (s *Spammer) GetStatus() int
- func (s *Spammer) GetWalletPool() *spamoor.WalletPool
- func (s *Spammer) Pause() error
- func (s *Spammer) Start() error
- func (s *Spammer) TrackTransactionResult(err error)
- type SpammerConfig
- type SpammerStatus
- type SpammerValidationInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon manages multiple spammer instances with database persistence and graceful shutdown. It orchestrates the lifecycle of spammers including restoration from database, global configuration management, and coordinated shutdown with a 10-second timeout.
func NewDaemon ¶
func NewDaemon(parentCtx context.Context, logger logrus.FieldLogger, clientPool *spamoor.ClientPool, rootWallet *spamoor.RootWallet, txpool *spamoor.TxPool, db *db.Database) *Daemon
NewDaemon creates a new daemon instance with the provided components. It initializes a cancellable context, spammer map, and global configuration map. The daemon manages spammer instances and handles their lifecycle.
func (*Daemon) DeleteSpammer ¶
DeleteSpammer removes a spammer from both the daemon and database. If the spammer is running, it will be paused first before deletion. Returns an error if the spammer is not found or if database deletion fails.
func (*Daemon) ExportSpammers ¶ added in v1.1.5
ExportSpammers exports the specified spammer IDs to YAML format. If no IDs are provided, exports all spammers. Returns the YAML string representation of the spammers.
func (*Daemon) GetAllSpammers ¶
GetAllSpammers returns all spammer instances sorted by ID in descending order. This provides a snapshot of all active spammer instances managed by the daemon. The returned slice is safe to modify as it's a copy.
func (*Daemon) GetClientPool ¶
func (d *Daemon) GetClientPool() *spamoor.ClientPool
GetClientPool returns the RPC client pool used by all spammers. This provides access to the Ethereum client connections for transaction submission.
func (*Daemon) GetGlobalCfg ¶ added in v1.1.3
GetGlobalCfg returns the global configuration map that contains shared configuration values accessible to all spammer instances.
func (*Daemon) GetRootWallet ¶
func (d *Daemon) GetRootWallet() *spamoor.RootWallet
GetRootWallet returns the root wallet used for funding spammer wallets. This provides access to the main wallet that distributes funds to child wallets.
func (*Daemon) GetSpammer ¶
GetSpammer retrieves a spammer instance by ID from the internal map. Returns nil if the spammer with the given ID does not exist. This method is thread-safe using read locks.
func (*Daemon) ImportSpammers ¶ added in v1.1.5
func (d *Daemon) ImportSpammers(input string) (*ImportResult, error)
ImportSpammers imports spammers from YAML data, file path, or URL. Handles deduplication by checking name combinations and validates before importing. Returns validation results and the number of spammers imported.
func (*Daemon) ImportSpammersOnStartup ¶ added in v1.1.5
func (d *Daemon) ImportSpammersOnStartup(source string, logger logrus.FieldLogger) error
ImportSpammersOnStartup imports spammers from a file or URL on startup. This method reuses the import functionality but starts the spammers after importing them, which is the key difference from regular imports. Only imports on first startup for safety.
func (*Daemon) InitializeMetrics ¶ added in v1.1.5
func (*Daemon) NewMetricsCollector ¶ added in v1.1.5
func (d *Daemon) NewMetricsCollector() *MetricsCollector
NewMetricsCollector creates and registers all metrics
func (*Daemon) NewSpammer ¶
func (d *Daemon) NewSpammer(scenarioName string, config string, name string, description string, startImmediately bool) (*Spammer, error)
NewSpammer creates a new spammer instance with the specified configuration. It validates the config, generates a unique ID (starting from 100), persists to database, and optionally starts execution immediately. The ID counter is stored in database state.
func (*Daemon) ReclaimSpammer ¶ added in v1.1.4
ReclaimSpammer reclaims funds from all wallets in the spammer's wallet pool. This transfers remaining ETH back to the root wallet for reuse. Returns an error if the spammer is not found or if fund reclamation fails.
func (*Daemon) Run ¶
Run initializes the daemon by restoring spammers from the database. Returns true if this is the first launch, false if spammers were restored. Marks the first launch state in the database to track initialization status.
func (*Daemon) SetGlobalCfg ¶ added in v1.1.3
SetGlobalCfg sets a global configuration value that can be accessed by all spammers. This allows sharing configuration data across multiple spammer instances.
func (*Daemon) Shutdown ¶
func (d *Daemon) Shutdown()
Shutdown performs a graceful shutdown of the daemon and all running spammers. It cancels the context to stop all spammers, waits up to 10 seconds for them to finish, and closes the database connection. This ensures clean resource cleanup.
func (*Daemon) TrackSpammerStatusChange ¶ added in v1.1.5
TrackSpammerStatusChange updates the spammer running status metric
func (*Daemon) TrackTransactionFailure ¶ added in v1.1.5
TrackTransactionFailure records a failed transaction for metrics
func (*Daemon) TrackTransactionSent ¶ added in v1.1.5
TrackTransactionSent records a successful transaction send for metrics
func (*Daemon) UpdateSpammer ¶
UpdateSpammer modifies the name, description, and configuration of an existing spammer. The configuration is validated by attempting to unmarshal it into SpammerConfig. Returns an error if the spammer is not found, config is invalid, or database update fails.
type ExportSpammerConfig ¶ added in v1.1.5
type ExportSpammerConfig struct {
Scenario string `yaml:"scenario"`
Name string `yaml:"name"`
Description string `yaml:"description"`
Config map[string]interface{} `yaml:"config"`
}
ExportSpammerConfig represents a spammer configuration for export/import. This uses the same format as StartupSpammerConfig to maintain compatibility.
type ImportItem ¶ added in v1.1.5
type ImportItem struct {
// Spammer configuration fields
Scenario string `yaml:"scenario,omitempty"`
Name string `yaml:"name,omitempty"`
Description string `yaml:"description,omitempty"`
Config map[string]interface{} `yaml:"config,omitempty"`
// Include directive
Include string `yaml:"include,omitempty"`
}
ImportItem represents either a spammer config or an include directive
type ImportResult ¶ added in v1.1.5
type ImportResult struct {
ImportedCount int `json:"imported_count"`
Validation *ImportValidationResult `json:"validation"`
Imported []ImportedSpammerInfo `json:"imported"`
Errors []string `json:"errors"`
Warnings []string `json:"warnings"`
Message string `json:"message"`
}
ImportResult contains the results of an import operation
type ImportValidationResult ¶ added in v1.1.5
type ImportValidationResult struct {
TotalSpammers int `json:"total_spammers"`
ValidSpammers int `json:"valid_spammers"`
Duplicates []string `json:"duplicates"`
InvalidScenarios []string `json:"invalid_scenarios"`
Spammers []SpammerValidationInfo `json:"spammers"`
}
ImportValidationResult contains validation results for import data
type ImportedSpammerInfo ¶ added in v1.1.5
type MetricsCollector ¶ added in v1.1.5
type MetricsCollector struct {
// contains filtered or unexported fields
}
MetricsCollector holds all Prometheus metrics for the spamoor daemon
func (*MetricsCollector) IncrementTransactionFailures ¶ added in v1.1.5
func (mc *MetricsCollector) IncrementTransactionFailures(spammerID int64, spammerName, scenario string)
IncrementTransactionFailures increments the failed transaction counter
func (*MetricsCollector) IncrementTransactionsSent ¶ added in v1.1.5
func (mc *MetricsCollector) IncrementTransactionsSent(spammerID int64, spammerName, scenario string)
IncrementTransactionsSent increments the sent transaction counter
func (*MetricsCollector) SetSpammerRunning ¶ added in v1.1.5
func (mc *MetricsCollector) SetSpammerRunning(spammerID int64, spammerName, scenario string, running bool)
SetSpammerRunning sets the running status for a spammer
type Spammer ¶
type Spammer struct {
// contains filtered or unexported fields
}
Spammer represents a single scenario execution instance with database persistence. It manages the lifecycle of a scenario including wallet pool creation, configuration loading, and execution monitoring with panic recovery.
func (*Spammer) GetCreatedAt ¶
GetCreatedAt returns the Unix timestamp when this spammer was created.
func (*Spammer) GetDescription ¶
GetDescription returns the description text of the spammer instance.
func (*Spammer) GetLogScope ¶
GetLogScope returns the buffered log scope for this spammer. This provides access to captured log messages for debugging and monitoring.
func (*Spammer) GetScenario ¶
GetScenario returns the name of the scenario being executed by this spammer.
func (*Spammer) GetStatus ¶
GetStatus returns the current execution status of the spammer as an integer. Use SpammerStatus constants to interpret the returned value.
func (*Spammer) GetWalletPool ¶
func (s *Spammer) GetWalletPool() *spamoor.WalletPool
GetWalletPool returns the wallet pool used by this spammer for transaction submission. Returns nil if the spammer has not been started or the wallet pool is not initialized.
func (*Spammer) Pause ¶
Pause stops the running scenario by canceling its context. It waits up to 10 seconds for the scenario to stop gracefully. Returns an error if the scenario is not running or fails to stop within the timeout.
func (*Spammer) Start ¶
Start begins execution of the spammer's scenario in a separate goroutine. It updates the status to running in the database and launches the scenario runner. Returns an error if the database update fails.
func (*Spammer) TrackTransactionResult ¶ added in v1.1.5
TrackTransactionResult records transaction success or failure for metrics
type SpammerConfig ¶
type SpammerConfig struct {
Seed string `yaml:"seed"`
RefillAmount *uint256.Int `yaml:"refill_amount"`
RefillBalance *uint256.Int `yaml:"refill_balance"`
RefillInterval uint64 `yaml:"refill_interval"`
WalletCount int `yaml:"wallet_count"`
}
SpammerConfig defines the wallet configuration for a spammer instance. This includes the seed for deterministic wallet generation and funding parameters.
type SpammerStatus ¶
type SpammerStatus int
SpammerStatus represents the execution state of a spammer instance. It tracks whether the spammer is paused, running, finished, or failed.
const ( // SpammerStatusPaused indicates the spammer is stopped and can be resumed SpammerStatusPaused SpammerStatus = iota // SpammerStatusRunning indicates the spammer is actively executing its scenario SpammerStatusRunning // SpammerStatusFinished indicates the spammer completed its scenario successfully SpammerStatusFinished // SpammerStatusFailed indicates the spammer encountered an error and stopped SpammerStatusFailed )
type SpammerValidationInfo ¶ added in v1.1.5
type SpammerValidationInfo struct {
Name string `json:"name"`
Scenario string `json:"scenario"`
Description string `json:"description"`
Valid bool `json:"valid"`
Issues []string `json:"issues"`
}
SpammerValidationInfo contains validation info for a single spammer