Documentation
¶
Index ¶
- Constants
- type AuditLogger
- func (al *AuditLogger) LogClientUpdate(tx *sqlx.Tx, userEmail string, rpcURL string, clientName string, ...) error
- func (al *AuditLogger) LogPluginAction(userEmail string, action db.AuditActionType, pluginName string, ...) error
- func (al *AuditLogger) LogRootWalletTransaction(userEmail string, toAddress string, valueWei string, txHash string, ...) error
- func (al *AuditLogger) LogSpammerAction(userEmail string, action db.AuditActionType, spammerID int64, name string, ...) error
- func (al *AuditLogger) LogSpammerCreate(tx *sqlx.Tx, userEmail string, spammerID int64, name string, scenario string, ...) error
- func (al *AuditLogger) LogSpammerDelete(tx *sqlx.Tx, userEmail string, spammerID int64, name string) error
- func (al *AuditLogger) LogSpammerUpdate(tx *sqlx.Tx, userEmail string, spammerID int64, ...) error
- func (al *AuditLogger) LogSpammersExport(userEmail string, exportedIDs []int64) error
- func (al *AuditLogger) LogSpammersImport(userEmail string, importedCount int, skippedCount int, source string) error
- type BlockDataPoint
- type Daemon
- func (d *Daemon) AddSpammerToGroup(spammerID int64, groupID int64, member *configs.MemberConfig, userEmail string) error
- func (d *Daemon) DeleteGroup(id int64, cascade bool, userEmail string) error
- func (d *Daemon) DeleteSpammer(id int64, userEmail string) error
- func (d *Daemon) ExportSpammers(spammerIDs ...int64) (string, error)
- func (d *Daemon) GetAllSpammers() []*Spammer
- func (d *Daemon) GetAuditLogger() *AuditLogger
- func (d *Daemon) GetClientConfig(rpcUrl string) (*db.ClientConfig, error)
- func (d *Daemon) GetClientPool() *spamoor.ClientPool
- func (d *Daemon) GetDatabase() *db.Database
- func (d *Daemon) GetEffectiveConfig(id int64) (string, error)
- func (d *Daemon) GetGlobalCfg() map[string]interface{}
- func (d *Daemon) GetGroupMembers(groupID int64) []*Spammer
- func (d *Daemon) GetLongWindowMetrics() *MultiGranularityMetrics
- func (d *Daemon) GetMetricsCollector() *TxPoolMetricsCollector
- func (d *Daemon) GetPluginLoader() *plugin.PluginLoader
- func (d *Daemon) GetPluginPersistence() *PluginPersistence
- func (d *Daemon) GetRootWallet() *spamoor.RootWallet
- func (d *Daemon) GetShortWindowMetrics() *MultiGranularityMetrics
- func (d *Daemon) GetSpammer(id int64) *Spammer
- func (d *Daemon) GetSpammerName(spammerID uint64) string
- func (d *Daemon) GetStartupDelayRemaining() time.Duration
- func (d *Daemon) GetTxPool() *spamoor.TxPool
- func (d *Daemon) GetWalletInfos() []*spamoor.WalletInfo
- func (d *Daemon) ImportDefaultSpammers(autoStart []string, logger logrus.FieldLogger) error
- func (d *Daemon) ImportSpammers(input string, userEmail string) (*ImportResult, error)
- func (d *Daemon) ImportSpammersOnStartup(source string, logger logrus.FieldLogger) error
- func (d *Daemon) InitializeMetrics() error
- func (d *Daemon) InitializeTxPoolMetrics() error
- func (d *Daemon) IsInStartupDelay() bool
- func (d *Daemon) LoadAndApplyClientConfigs() error
- func (d *Daemon) NewGroup(name string, description string, overlayConfig string, ...) (*Spammer, error)
- func (d *Daemon) NewMetricsCollector() *MetricsCollector
- func (d *Daemon) NewSpammer(scenarioName string, config string, name string, description string, ...) (*Spammer, error)
- func (d *Daemon) NotifyPluginDereference(p *plugin.LoadedPlugin)
- func (d *Daemon) PauseSpammer(id int64, userEmail string) error
- func (d *Daemon) ReclaimSpammer(id int64, userEmail string) error
- func (d *Daemon) RemoveSpammerFromGroup(spammerID int64, userEmail string) error
- func (d *Daemon) ReorderGroupMembers(groupID int64, orderedIDs []int64, userEmail string) error
- func (d *Daemon) Run() (bool, error)
- func (d *Daemon) SetAuditLogger(logger *AuditLogger)
- func (d *Daemon) SetGlobalCfg(name string, value interface{})
- func (d *Daemon) SetPluginLoader(loader *plugin.PluginLoader)
- func (d *Daemon) SetPluginPersistence(persistence *PluginPersistence)
- func (d *Daemon) SetRootWallet(rootWallet *spamoor.RootWallet)
- func (d *Daemon) SetStartupDelay(delay time.Duration)
- func (d *Daemon) Shutdown()
- func (d *Daemon) StartSpammer(id int64, userEmail string) error
- func (d *Daemon) StartSpammersByName(names []string, logger logrus.FieldLogger)
- func (d *Daemon) SubscribeEvents() (uint64, <-chan *SpammerEvent)
- func (d *Daemon) TrackSpammerStatusChange(spammerID int64, running bool)
- func (d *Daemon) TrackTransactionFailure(spammerID int64)
- func (d *Daemon) TrackTransactionSent(spammerID int64)
- func (d *Daemon) UnsubscribeEvents(id uint64)
- func (d *Daemon) UpdateClientConfig(rpcUrl, name, tags, clientType string, enabled bool, userEmail string) error
- func (d *Daemon) UpdateGroup(id int64, name string, description string, overlayConfig string, ...) error
- func (d *Daemon) UpdateGroupMember(spammerID int64, member *configs.MemberConfig, userEmail string) error
- func (d *Daemon) UpdateSpammer(id int64, name string, description string, config string, userEmail string) error
- type DefaultSpammerConfig
- 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)
- func (mc *MetricsCollector) UpdateBlockGasUsage(spammerID int64, spammerName string, blockNumber uint64, gasUsed uint64)
- func (mc *MetricsCollector) UpdatePendingTransactions(spammerID int64, spammerName string, count uint64)
- func (mc *MetricsCollector) UpdateTotalBlockGas(category string, gasUsed uint64)
- type MetricsUpdate
- type MultiGranularityMetrics
- type PluginPersistence
- func (pp *PluginPersistence) DeletePlugin(name string) error
- func (pp *PluginPersistence) GetPluginStatus(name string) (*PluginStatus, error)
- func (pp *PluginPersistence) GetPluginStatuses() ([]*PluginStatus, error)
- func (pp *PluginPersistence) RegisterPluginFromFile(filePath string) (*plugin.LoadedPlugin, error)
- func (pp *PluginPersistence) RegisterPluginFromLocal(dirPath string) (*plugin.LoadedPlugin, error)
- func (pp *PluginPersistence) RegisterPluginFromURL(url string) (*plugin.LoadedPlugin, error)
- func (pp *PluginPersistence) RegisterPluginFromUpload(data []byte, filename string) (*plugin.LoadedPlugin, error)
- func (pp *PluginPersistence) ReloadPlugin(name string) (*plugin.LoadedPlugin, error)
- func (pp *PluginPersistence) RestorePlugins() (int, error)
- func (pp *PluginPersistence) SavePlugin(loaded *plugin.LoadedPlugin, archiveData []byte, sourcePath string) error
- type PluginStatus
- type Spammer
- func (s *Spammer) GetConfig() string
- func (s *Spammer) GetCreatedAt() int64
- func (s *Spammer) GetDescription() string
- func (s *Spammer) GetEffectiveStatus() int
- func (s *Spammer) GetGroupConfig() string
- func (s *Spammer) GetGroupID() int64
- 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) IsGroup() bool
- func (s *Spammer) Pause() error
- func (s *Spammer) Start() error
- func (s *Spammer) TrackTransactionResult(err error)
- type SpammerBlockData
- type SpammerConfig
- type SpammerEvent
- type SpammerEventInfo
- type SpammerSnapshot
- type SpammerStatus
- type SpammerValidationInfo
- type TxPoolMetricsCollector
- func (mc *TxPoolMetricsCollector) GetLongWindowMetrics() *MultiGranularityMetrics
- func (mc *TxPoolMetricsCollector) GetShortWindowMetrics() *MultiGranularityMetrics
- func (mc *TxPoolMetricsCollector) Shutdown()
- func (mc *TxPoolMetricsCollector) Subscribe() (uint64, <-chan *MetricsUpdate)
- func (mc *TxPoolMetricsCollector) Unsubscribe(id uint64)
Constants ¶
const ( // SpammerEventCreated is emitted when a spammer or group is created. SpammerEventCreated = "created" // SpammerEventUpdated is emitted when a spammer's or group's name/description/ // scenario or group settings change. SpammerEventUpdated = "updated" // SpammerEventStatus is emitted when a spammer's run state changes (and for the // parent group's derived status). SpammerEventStatus = "status" // SpammerEventMembership is emitted when a spammer's group membership changes // (added, detached, weight/enabled/order updated). SpammerEventMembership = "membership" // SpammerEventReorder is emitted when a group's members are reordered. SpammerEventReorder = "reorder" // SpammerEventDeleted is emitted when a spammer or group is deleted. SpammerEventDeleted = "deleted" )
Spammer event types emitted on the lifecycle event stream.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuditLogger ¶ added in v1.1.9
type AuditLogger struct {
// contains filtered or unexported fields
}
AuditLogger handles creating audit log entries with proper diff generation
func NewAuditLogger ¶ added in v1.1.9
func NewAuditLogger(daemon *Daemon) *AuditLogger
NewAuditLogger creates a new audit logger instance
func (*AuditLogger) LogClientUpdate ¶ added in v1.1.9
func (al *AuditLogger) LogClientUpdate(tx *sqlx.Tx, userEmail string, rpcURL string, clientName string, changes map[string]interface{}) error
LogClientUpdate logs a client configuration update with specific action types
func (*AuditLogger) LogPluginAction ¶ added in v1.2.0
func (al *AuditLogger) LogPluginAction(userEmail string, action db.AuditActionType, pluginName string, metadata db.AuditMetadata) error
LogPluginAction logs plugin actions (register, delete, reload)
func (*AuditLogger) LogRootWalletTransaction ¶ added in v1.1.10
func (al *AuditLogger) LogRootWalletTransaction(userEmail string, toAddress string, valueWei string, txHash string, gasLimit uint64, maxFee string, maxTip string, data string) error
LogRootWalletTransaction logs a transaction sent from the root wallet
func (*AuditLogger) LogSpammerAction ¶ added in v1.1.9
func (al *AuditLogger) LogSpammerAction(userEmail string, action db.AuditActionType, spammerID int64, name string, metadata db.AuditMetadata) error
LogSpammerAction logs simple spammer actions (start, pause, reclaim)
func (*AuditLogger) LogSpammerCreate ¶ added in v1.1.9
func (al *AuditLogger) LogSpammerCreate(tx *sqlx.Tx, userEmail string, spammerID int64, name string, scenario string, config string) error
LogSpammerCreate logs a spammer creation action
func (*AuditLogger) LogSpammerDelete ¶ added in v1.1.9
func (al *AuditLogger) LogSpammerDelete(tx *sqlx.Tx, userEmail string, spammerID int64, name string) error
LogSpammerDelete logs a spammer deletion action
func (*AuditLogger) LogSpammerUpdate ¶ added in v1.1.9
func (al *AuditLogger) LogSpammerUpdate(tx *sqlx.Tx, userEmail string, spammerID int64, oldName, newName, oldDesc, newDesc, oldConfig, newConfig string) error
LogSpammerUpdate logs a spammer update action
func (*AuditLogger) LogSpammersExport ¶ added in v1.1.9
func (al *AuditLogger) LogSpammersExport(userEmail string, exportedIDs []int64) error
LogSpammersExport logs a spammers export action
func (*AuditLogger) LogSpammersImport ¶ added in v1.1.9
func (al *AuditLogger) LogSpammersImport(userEmail string, importedCount int, skippedCount int, source string) error
LogSpammersImport logs a spammers import action
type BlockDataPoint ¶ added in v1.1.6
type BlockDataPoint struct {
Timestamp time.Time `json:"timestamp"`
StartBlockNumber uint64 `json:"startBlockNumber"`
EndBlockNumber uint64 `json:"endBlockNumber"`
BlockCount uint64 `json:"blockCount"`
TotalGasUsed uint64 `json:"totalGasUsed"`
SpammerGasData map[uint64]*SpammerBlockData `json:"spammerGasData"` // spammerID -> data
OthersGasUsed uint64 `json:"othersGasUsed"`
}
BlockDataPoint represents metrics for one or more blocks (based on granularity)
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, 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) AddSpammerToGroup ¶ added in v1.2.2
func (d *Daemon) AddSpammerToGroup(spammerID int64, groupID int64, member *configs.MemberConfig, userEmail string) error
AddSpammerToGroup assigns a spammer to a group with the given member metadata. It validates that the target is a real spammer (not a group), the group exists, and the scenario is compatible with a shared-mode group.
func (*Daemon) DeleteGroup ¶ added in v1.2.2
DeleteGroup deletes a group row. When cascade is true the members are paused and deleted as well; otherwise members are detached to standalone spammers first.
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) GetAuditLogger ¶ added in v1.1.9
func (d *Daemon) GetAuditLogger() *AuditLogger
GetAuditLogger returns the audit logger
func (*Daemon) GetClientConfig ¶ added in v1.1.9
func (d *Daemon) GetClientConfig(rpcUrl string) (*db.ClientConfig, error)
GetClientConfig retrieves the configuration for a specific client from the database.
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) GetDatabase ¶ added in v1.1.9
GetDatabase returns the database instance
func (*Daemon) GetEffectiveConfig ¶ added in v1.2.2
GetEffectiveConfig returns the resolved config a spammer would run with: the stored config for standalone spammers, or the group-resolved config for members.
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) GetGroupMembers ¶ added in v1.2.2
GetGroupMembers returns the members of a group ordered by their configured sort_order (then by id for stability). Safe to call concurrently.
func (*Daemon) GetLongWindowMetrics ¶ added in v1.1.6
func (d *Daemon) GetLongWindowMetrics() *MultiGranularityMetrics
GetLongWindowMetrics returns the 6-hour per-32-block metrics for the dashboard
func (*Daemon) GetMetricsCollector ¶ added in v1.1.6
func (d *Daemon) GetMetricsCollector() *TxPoolMetricsCollector
GetMetricsCollector returns the TxPool metrics collector for real-time subscriptions
func (*Daemon) GetPluginLoader ¶ added in v1.2.0
func (d *Daemon) GetPluginLoader() *plugin.PluginLoader
GetPluginLoader returns the plugin loader.
func (*Daemon) GetPluginPersistence ¶ added in v1.2.0
func (d *Daemon) GetPluginPersistence() *PluginPersistence
GetPluginPersistence returns the plugin persistence.
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) GetShortWindowMetrics ¶ added in v1.1.6
func (d *Daemon) GetShortWindowMetrics() *MultiGranularityMetrics
GetShortWindowMetrics returns the 30-minute per-block metrics for the dashboard
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) GetSpammerName ¶ added in v1.1.6
GetSpammerName returns the name of a spammer by ID for metrics dashboard
func (*Daemon) GetStartupDelayRemaining ¶ added in v1.1.10
GetStartupDelayRemaining returns the remaining time in the startup delay period. Returns 0 if the delay has expired or was not set.
func (*Daemon) GetTxPool ¶ added in v1.1.10
GetTxPool returns the transaction pool for sending transactions
func (*Daemon) GetWalletInfos ¶ added in v1.2.3
func (d *Daemon) GetWalletInfos() []*spamoor.WalletInfo
GetWalletInfos is the daemon's spamoor.WalletInfoProvider implementation: it enumerates the root wallet plus all wallets of all spammers' wallet pools, so cross-cutting scenarios (e.g. the ens-names wallet naming service) can discover every spamoor-managed wallet with its scenario/spammer context.
func (*Daemon) ImportDefaultSpammers ¶ added in v1.2.3
func (d *Daemon) ImportDefaultSpammers(autoStart []string, logger logrus.FieldLogger) error
ImportDefaultSpammers inserts the built-in default spammers and spammer groups into the database. All defaults are created paused; the ones listed in autoStart (matched by their technical key, falling back to their display name) are started afterwards. Intended to be called once on the daemon's first launch, after the spammer state has been restored. The insertion is a system bootstrap, not a user action, so it is excluded from the audit log (empty user).
func (*Daemon) ImportSpammers ¶ added in v1.1.5
func (d *Daemon) ImportSpammers(input string, userEmail 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) InitializeTxPoolMetrics ¶ added in v1.1.6
func (*Daemon) IsInStartupDelay ¶ added in v1.1.10
IsInStartupDelay checks if the daemon is still within the startup delay period. Returns true if we're still within the delay period, false otherwise.
func (*Daemon) LoadAndApplyClientConfigs ¶ added in v1.1.10
LoadAndApplyClientConfigs retrieves client configurations from the database and applies them to the corresponding clients in the client pool. This merges database settings with flag-provided settings according to the rules: - Name and enabled state from DB take precedence over flags - Tags are combined (flags + database tags)
func (*Daemon) NewGroup ¶ added in v1.2.2
func (d *Daemon) NewGroup(name string, description string, overlayConfig string, groupConfig *configs.GroupConfig, userEmail string) (*Spammer, error)
NewGroup creates a new spammer group. A group is stored as a regular spammers row with the reserved sentinel scenario name; overlayConfig holds the sparse YAML overlay applied to members and groupConfig holds the mode/totals metadata.
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, userEmail string, isImport 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) NotifyPluginDereference ¶ added in v1.2.0
func (d *Daemon) NotifyPluginDereference(p *plugin.LoadedPlugin)
NotifyPluginDereference is called when a spammer releases its reference to a plugin. It checks if the plugin can be cleaned up (no more scenarios registered AND no running spammers).
func (*Daemon) PauseSpammer ¶ added in v1.1.9
PauseSpammer pauses a spammer and logs the action
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) RemoveSpammerFromGroup ¶ added in v1.2.2
RemoveSpammerFromGroup detaches a spammer from its group, leaving it a fully working standalone spammer (its stored config is never touched).
func (*Daemon) ReorderGroupMembers ¶ added in v1.2.2
ReorderGroupMembers assigns sort_order values to members of a group according to the position of their ids in orderedIDs. Ids not in the group are ignored.
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) SetAuditLogger ¶ added in v1.1.9
func (d *Daemon) SetAuditLogger(logger *AuditLogger)
SetAuditLogger sets the audit logger for the daemon
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) SetPluginLoader ¶ added in v1.2.0
func (d *Daemon) SetPluginLoader(loader *plugin.PluginLoader)
SetPluginLoader sets the plugin loader for the daemon.
func (*Daemon) SetPluginPersistence ¶ added in v1.2.0
func (d *Daemon) SetPluginPersistence(persistence *PluginPersistence)
SetPluginPersistence sets the plugin persistence for the daemon.
func (*Daemon) SetRootWallet ¶ added in v1.1.10
func (d *Daemon) SetRootWallet(rootWallet *spamoor.RootWallet)
SetRootWallet sets the root wallet for the daemon. This is used to set the root wallet for the daemon.
func (*Daemon) SetStartupDelay ¶ added in v1.1.10
SetStartupDelay sets the startup delay duration for the daemon. This delay prevents spammers from running immediately on startup to allow cancellation.
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) StartSpammer ¶ added in v1.1.9
StartSpammer starts a spammer and logs the action
func (*Daemon) StartSpammersByName ¶ added in v1.2.3
func (d *Daemon) StartSpammersByName(names []string, logger logrus.FieldLogger)
StartSpammersByName starts all spammers or spammer groups whose configured name matches one of the given names. Starting a group starts all of its enabled members. Unknown names and failed starts are logged but do not abort the remaining names.
func (*Daemon) SubscribeEvents ¶ added in v1.2.2
func (d *Daemon) SubscribeEvents() (uint64, <-chan *SpammerEvent)
SubscribeEvents registers a new subscriber for spammer lifecycle events and returns a subscription id and a buffered receive channel. Mirrors the metrics collector pub/sub.
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) UnsubscribeEvents ¶ added in v1.2.2
UnsubscribeEvents removes a subscription and closes its channel.
func (*Daemon) UpdateClientConfig ¶ added in v1.1.9
func (d *Daemon) UpdateClientConfig(rpcUrl, name, tags, clientType string, enabled bool, userEmail string) error
UpdateClientConfig updates the configuration for a specific client and persists the changes to the database.
func (*Daemon) UpdateGroup ¶ added in v1.2.2
func (d *Daemon) UpdateGroup(id int64, name string, description string, overlayConfig string, groupConfig *configs.GroupConfig, userEmail string) error
UpdateGroup updates a group's name, description, overlay config and group config.
func (*Daemon) UpdateGroupMember ¶ added in v1.2.2
func (d *Daemon) UpdateGroupMember(spammerID int64, member *configs.MemberConfig, userEmail string) error
UpdateGroupMember updates the member metadata (weight/enabled/sort_order) for a spammer already in a group.
func (*Daemon) UpdateSpammer ¶
func (d *Daemon) UpdateSpammer(id int64, name string, description string, config string, userEmail string) error
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 DefaultSpammerConfig ¶ added in v1.2.3
type DefaultSpammerConfig struct {
Key string `yaml:"key"`
configs.SpammerConfig `yaml:",inline"`
}
DefaultSpammerConfig is a built-in default spammer definition: a regular import config plus a short technical key. The key is a stable machine identifier for the --startup-defaults flag; the display name/description may change over time, the key must not.
func LoadDefaultSpammerConfigs ¶ added in v1.2.3
func LoadDefaultSpammerConfigs() ([]DefaultSpammerConfig, error)
LoadDefaultSpammerConfigs parses the embedded default spammer definitions and returns them in import order (lexical filename order, entries in file order).
type ExportSpammerConfig ¶ added in v1.1.5
type ExportSpammerConfig = configs.SpammerConfig
ExportSpammerConfig is an alias for scenario.SpammerConfig to maintain API compatibility
type ImportItem ¶ added in v1.1.5
type ImportItem = configs.ConfigImportItem
ImportItem is an alias for scenario.ConfigImportItem to maintain API compatibility
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
func (*MetricsCollector) UpdateBlockGasUsage ¶ added in v1.1.6
func (mc *MetricsCollector) UpdateBlockGasUsage(spammerID int64, spammerName string, blockNumber uint64, gasUsed uint64)
UpdateBlockGasUsage updates the block gas usage gauge for a spammer
func (*MetricsCollector) UpdatePendingTransactions ¶ added in v1.1.6
func (mc *MetricsCollector) UpdatePendingTransactions(spammerID int64, spammerName string, count uint64)
UpdatePendingTransactions updates the pending transactions gauge for a spammer
func (*MetricsCollector) UpdateTotalBlockGas ¶ added in v1.1.6
func (mc *MetricsCollector) UpdateTotalBlockGas(category string, gasUsed uint64)
UpdateTotalBlockGas updates the total block gas gauge with category breakdown
type MetricsUpdate ¶ added in v1.1.6
type MetricsUpdate struct {
BlockNumber uint64
NewDataPoint *BlockDataPoint
UpdatedSpammers map[uint64]*SpammerSnapshot
Timestamp time.Time
}
MetricsUpdate represents a real-time update to metrics
type MultiGranularityMetrics ¶ added in v1.1.6
type MultiGranularityMetrics struct {
// contains filtered or unexported fields
}
MultiGranularityMetrics manages time-windowed metrics with configurable block granularity
func NewMultiGranularityMetrics ¶ added in v1.1.6
func NewMultiGranularityMetrics(windowDuration time.Duration, blockGranularity uint64) *MultiGranularityMetrics
NewMultiGranularityMetrics creates a new multi-granularity metrics collector
func (*MultiGranularityMetrics) GetDataPoints ¶ added in v1.1.6
func (mgm *MultiGranularityMetrics) GetDataPoints() []BlockDataPoint
GetDataPoints returns a deep copy of data points for a specific window. The nested maps are copied so the returned data is safe to read without holding the window lock.
func (*MultiGranularityMetrics) GetSpammerSnapshots ¶ added in v1.1.6
func (mgm *MultiGranularityMetrics) GetSpammerSnapshots() map[uint64]*SpammerSnapshot
GetSpammerSnapshots returns current spammer snapshots
func (*MultiGranularityMetrics) GetTimeRange ¶ added in v1.1.6
func (mgm *MultiGranularityMetrics) GetTimeRange() (time.Time, time.Time)
GetTimeRange returns the time range of data points
type PluginPersistence ¶ added in v1.2.0
type PluginPersistence struct {
// contains filtered or unexported fields
}
PluginPersistence handles saving and restoring plugins from the database.
func NewPluginPersistence ¶ added in v1.2.0
func NewPluginPersistence( logger logrus.FieldLogger, database *db.Database, pluginLoader *plugin.PluginLoader, ) *PluginPersistence
NewPluginPersistence creates a new PluginPersistence instance.
func (*PluginPersistence) DeletePlugin ¶ added in v1.2.0
func (pp *PluginPersistence) DeletePlugin(name string) error
DeletePlugin removes a plugin from the database. Returns an error if the plugin has running spammers.
func (*PluginPersistence) GetPluginStatus ¶ added in v1.2.0
func (pp *PluginPersistence) GetPluginStatus(name string) (*PluginStatus, error)
GetPluginStatus returns the status of a single plugin.
func (*PluginPersistence) GetPluginStatuses ¶ added in v1.2.0
func (pp *PluginPersistence) GetPluginStatuses() ([]*PluginStatus, error)
GetPluginStatuses returns the combined status of all plugins from DB and runtime. This includes deprecated plugins that have been replaced but still have running spammers.
func (*PluginPersistence) RegisterPluginFromFile ¶ added in v1.2.0
func (pp *PluginPersistence) RegisterPluginFromFile(filePath string) (*plugin.LoadedPlugin, error)
RegisterPluginFromFile loads and registers a plugin from a local file path.
func (*PluginPersistence) RegisterPluginFromLocal ¶ added in v1.2.0
func (pp *PluginPersistence) RegisterPluginFromLocal(dirPath string) (*plugin.LoadedPlugin, error)
RegisterPluginFromLocal loads and registers a plugin from a local directory path.
func (*PluginPersistence) RegisterPluginFromURL ¶ added in v1.2.0
func (pp *PluginPersistence) RegisterPluginFromURL(url string) (*plugin.LoadedPlugin, error)
RegisterPluginFromURL downloads and registers a plugin from a URL.
func (*PluginPersistence) RegisterPluginFromUpload ¶ added in v1.2.0
func (pp *PluginPersistence) RegisterPluginFromUpload(data []byte, filename string) (*plugin.LoadedPlugin, error)
RegisterPluginFromUpload loads and registers a plugin from uploaded bytes.
func (*PluginPersistence) ReloadPlugin ¶ added in v1.2.0
func (pp *PluginPersistence) ReloadPlugin(name string) (*plugin.LoadedPlugin, error)
ReloadPlugin re-loads a plugin from its original source (URL or local path). This allows users to manually trigger an update. Returns an error if the plugin has running spammers or the source type does not support reloading.
func (*PluginPersistence) RestorePlugins ¶ added in v1.2.0
func (pp *PluginPersistence) RestorePlugins() (int, error)
RestorePlugins restores all enabled plugins from the database on startup. Returns the number of successfully restored plugins.
func (*PluginPersistence) SavePlugin ¶ added in v1.2.0
func (pp *PluginPersistence) SavePlugin( loaded *plugin.LoadedPlugin, archiveData []byte, sourcePath string, ) error
SavePlugin persists a loaded plugin to the database. For non-local plugins, archiveData should be the original tar.gz bytes.
type PluginStatus ¶ added in v1.2.0
type PluginStatus struct {
Name string `json:"name"`
SourceType string `json:"source_type"`
SourcePath string `json:"source_path"`
MetadataName string `json:"metadata_name,omitempty"`
MetadataBuildTime string `json:"metadata_build_time,omitempty"`
MetadataGitVersion string `json:"metadata_git_version,omitempty"`
Scenarios []string `json:"scenarios"`
Enabled bool `json:"enabled"`
LoadError string `json:"load_error,omitempty"`
RunningCount int32 `json:"running_count"`
IsLoaded bool `json:"is_loaded"`
Deprecated bool `json:"deprecated"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
PluginStatus represents the combined status of a plugin from both DB and runtime.
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) GetEffectiveStatus ¶ added in v1.2.2
GetEffectiveStatus returns the display status for this spammer. For group rows the status is derived from members; for normal spammers it is the stored status.
func (*Spammer) GetGroupConfig ¶ added in v1.2.2
GetGroupConfig returns the role-dependent group_config JSON for this row.
func (*Spammer) GetGroupID ¶ added in v1.2.2
GetGroupID returns the parent group id for a member spammer, or 0 if the spammer is standalone or a group itself.
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) IsGroup ¶ added in v1.2.2
IsGroup reports whether this spammer row represents a spammer group rather than a runnable scenario. Group rows use the reserved sentinel scenario name and are guarded against execution throughout the daemon.
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.
For a group row, Start fans out to all effectively-enabled members instead of running a scenario itself.
func (*Spammer) TrackTransactionResult ¶ added in v1.1.5
TrackTransactionResult records transaction success or failure for metrics
type SpammerBlockData ¶ added in v1.1.6
type SpammerBlockData struct {
GasUsed uint64 `json:"gasUsed"`
ConfirmedTxCount uint64 `json:"confirmedTxCount"`
PendingTxCount uint64 `json:"pendingTxCount"` // snapshot at end of period
SubmittedTxCount uint64 `json:"submittedTxCount"` // total transactions submitted (lifetime)
}
SpammerBlockData represents a spammer's metrics within a data point
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 SpammerEvent ¶ added in v1.2.2
type SpammerEvent struct {
Type string `json:"type"`
ID int64 `json:"id"`
Spammer *SpammerEventInfo `json:"spammer,omitempty"`
Order []int64 `json:"order,omitempty"` // reorder events only
}
SpammerEvent is a single lifecycle event published to subscribers of the spammer event stream.
type SpammerEventInfo ¶ added in v1.2.2
type SpammerEventInfo struct {
ID int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Scenario string `json:"scenario"`
Status int `json:"status"`
IsGroup bool `json:"is_group"`
GroupID int64 `json:"group_id"`
// Group (parent) summary, set when IsGroup is true.
ThroughputMode string `json:"throughput_mode,omitempty"`
TotalThroughput uint64 `json:"total_throughput,omitempty"`
TotalCount uint64 `json:"total_count,omitempty"`
TotalMaxPending uint64 `json:"total_max_pending,omitempty"`
AutoRestartFailed bool `json:"auto_restart_failed,omitempty"`
AutoRestartCooldown uint64 `json:"auto_restart_cooldown,omitempty"`
// Member fields, set when GroupID != 0. Enabled is always serialized so the client
// can distinguish a disabled member (false) from a non-member (field absent).
Weight uint64 `json:"weight,omitempty"`
Enabled bool `json:"enabled"`
SortOrder int `json:"sort_order,omitempty"`
}
SpammerEventInfo is the safe, public snapshot of a spammer carried on the event stream. It deliberately contains NO config, seed or logs so the stream can be served unauthenticated. Its shape mirrors the spammer list API entry.
type SpammerSnapshot ¶ added in v1.1.6
type SpammerSnapshot struct {
SpammerID uint64
PendingTxCount uint64
TotalConfirmedTx uint64 // lifetime total
TotalSubmittedTx uint64 // lifetime total submitted
LastUpdate time.Time
}
SpammerSnapshot represents current state of a spammer (not aggregated)
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
type TxPoolMetricsCollector ¶ added in v1.1.6
type TxPoolMetricsCollector struct {
// contains filtered or unexported fields
}
TxPoolMetricsCollector subscribes to TxPool block updates for advanced metrics collection
func NewTxPoolMetricsCollector ¶ added in v1.1.6
func NewTxPoolMetricsCollector(txPool *spamoor.TxPool) *TxPoolMetricsCollector
NewTxPoolMetricsCollector creates and initializes the metrics collector
func (*TxPoolMetricsCollector) GetLongWindowMetrics ¶ added in v1.1.6
func (mc *TxPoolMetricsCollector) GetLongWindowMetrics() *MultiGranularityMetrics
GetLongWindowMetrics returns the 6-hour per-32-block metrics
func (*TxPoolMetricsCollector) GetShortWindowMetrics ¶ added in v1.1.6
func (mc *TxPoolMetricsCollector) GetShortWindowMetrics() *MultiGranularityMetrics
GetShortWindowMetrics returns the 30-minute per-block metrics
func (*TxPoolMetricsCollector) Shutdown ¶ added in v1.1.6
func (mc *TxPoolMetricsCollector) Shutdown()
Shutdown stops the metrics collector
func (*TxPoolMetricsCollector) Subscribe ¶ added in v1.1.6
func (mc *TxPoolMetricsCollector) Subscribe() (uint64, <-chan *MetricsUpdate)
Subscribe creates a new subscription for real-time metrics updates
func (*TxPoolMetricsCollector) Unsubscribe ¶ added in v1.1.6
func (mc *TxPoolMetricsCollector) Unsubscribe(id uint64)
Unsubscribe removes a subscription