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 additional parameters for value spam #32

Merged
merged 9 commits into from
Aug 22, 2022
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
34 changes: 25 additions & 9 deletions config_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,33 @@
"address": "localhost:9029"
},
"spammer": {
"bindAddress": "localhost:9092",
"message": "We are all made of stardust.",
"tag": "HORNET Spammer",
"tagSemiLazy": "HORNET Spammer Semi-Lazy",
"valueSpamEnabled": false,
"autostart": false,
"bpsRateLimit": 0,
"cpuMaxUsage": 0.8,
"workers": 0,
"autostart": false,
"nonLazyTipsThreshold": 0,
"semiLazyTipsThreshold": 30,
"message": "We are all made of stardust.",
"tag": "HORNET Spammer",
"tagSemiLazy": "HORNET Spammer Semi-Lazy",
"valueSpam": {
"enabled": false,
"sendBasicOutput": true,
"collectBasicOutput": true,
"createAlias": true,
"destroyAlias": true,
"createFoundry": true,
"destroyFoundry": true,
"mintNativeToken": true,
"meltNativeToken": true,
"createNFT": true,
"destroyNFT": true
},
"tipselection": {
"nonLazyTipsThreshold": 0,
"semiLazyTipsThreshold": 30
}
},
"restAPI": {
"bindAddress": "localhost:9092",
"debugRequestLoggerEnabled": false
},
"pow": {
Expand All @@ -35,4 +51,4 @@
"processMetrics": false,
"promhttpMetrics": false
}
}
}
2 changes: 1 addition & 1 deletion core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
Name = "inx-spammer"

// Version of the app.
Version = "1.0.0-beta.5"
Version = "1.0.0-beta.6"
)

func App() *app.App {
Expand Down
26 changes: 18 additions & 8 deletions core/spammer/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func provide(c *dig.Container) error {

mnemonic, err := loadMnemonicFromEnvironment("SPAMMER_MNEMONIC")
if err != nil {
if ParamsSpammer.ValueSpamEnabled {
if ParamsSpammer.ValueSpam.Enabled {
CoreComponent.LogPanicf("value spam enabled but loading mnemonic seed failed, err: %s", err)
}
}
Expand All @@ -131,15 +131,25 @@ func provide(c *dig.Container) error {
deps.NodeBridge.ProtocolParameters,
deps.NodeBridge.INXNodeClient(),
wallet,
ParamsSpammer.ValueSpamEnabled,
ParamsSpammer.BPSRateLimit,
ParamsSpammer.CPUMaxUsage,
ParamsSpammer.Workers,
ParamsSpammer.Message,
ParamsSpammer.Tag,
ParamsSpammer.TagSemiLazy,
ParamsSpammer.NonLazyTipsThreshold,
ParamsSpammer.SemiLazyTipsThreshold,
ParamsSpammer.ValueSpam.Enabled,
ParamsSpammer.ValueSpam.SendBasicOutput,
ParamsSpammer.ValueSpam.CollectBasicOutput,
ParamsSpammer.ValueSpam.CreateAlias,
ParamsSpammer.ValueSpam.DestroyAlias,
ParamsSpammer.ValueSpam.CreateFoundry,
ParamsSpammer.ValueSpam.DestroyFoundry,
ParamsSpammer.ValueSpam.MintNativeToken,
ParamsSpammer.ValueSpam.MeltNativeToken,
ParamsSpammer.ValueSpam.CreateNFT,
ParamsSpammer.ValueSpam.DestroyNFT,
ParamsSpammer.Tipselection.NonLazyTipsThreshold,
ParamsSpammer.Tipselection.SemiLazyTipsThreshold,
ParamsPoW.RefreshTipsInterval,
deps.TipPoolListener.GetTipsPoolSizes,
deps.NodeBridge.RequestTips,
Expand Down Expand Up @@ -228,20 +238,20 @@ func run() error {
if err := CoreComponent.Daemon().BackgroundWorker("API", func(ctx context.Context) {
CoreComponent.LogInfo("Starting API ... done")

e := httpserver.NewEcho(CoreComponent.Logger(), nil, ParamsSpammer.DebugRequestLoggerEnabled)
e := httpserver.NewEcho(CoreComponent.Logger(), nil, ParamsRestAPI.DebugRequestLoggerEnabled)

CoreComponent.LogInfo("Starting API server...")

_ = spammer.NewServer(deps.Spammer, e.Group(""))

go func() {
CoreComponent.LogInfof("You can now access the API using: http://%s", ParamsSpammer.BindAddress)
if err := e.Start(ParamsSpammer.BindAddress); err != nil && !errors.Is(err, http.ErrServerClosed) {
CoreComponent.LogInfof("You can now access the API using: http://%s", ParamsRestAPI.BindAddress)
if err := e.Start(ParamsRestAPI.BindAddress); err != nil && !errors.Is(err, http.ErrServerClosed) {
CoreComponent.LogPanicf("Stopped REST-API server due to an error (%s)", err)
}
}()

if err := deps.NodeBridge.RegisterAPIRoute(APIRoute, ParamsSpammer.BindAddress); err != nil {
if err := deps.NodeBridge.RegisterAPIRoute(APIRoute, ParamsRestAPI.BindAddress); err != nil {
CoreComponent.LogPanicf("Registering INX api route failed, error: %s", err)
}

Expand Down
60 changes: 42 additions & 18 deletions core/spammer/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,52 @@ import (

// ParametersSpammer contains the definition of the parameters used by the Spammer.
type ParametersSpammer struct {
// BindAddress defines the bind address on which the Spammer HTTP server listens.
BindAddress string `default:"localhost:9092" usage:"the bind address on which the Spammer HTTP server listens"`
// the message to embed within the spam blocks
Message string `default:"We are all made of stardust." usage:"the message to embed within the spam blocks"`
// the tag of the block
Tag string `default:"HORNET Spammer" usage:"the tag of the block"`
// the tag of the block if the semi-lazy pool is used (uses "tag" if empty)
TagSemiLazy string `default:"HORNET Spammer Semi-Lazy" usage:"the tag of the block if the semi-lazy pool is used (uses \"tag\" if empty)"`
// whether to spam with transaction payloads instead of data payloads
ValueSpamEnabled bool `default:"false" usage:"whether to spam with transaction payloads instead of data payloads"`
// whether to automatically start the spammer on startup
Autostart bool `default:"false" usage:"automatically start the spammer on startup"`

// the blocks per second rate limit for the spammer (0 = no limit)
BPSRateLimit float64 `name:"bpsRateLimit" default:"0.0" usage:"the blocks per second rate limit for the spammer (0 = no limit)"`
// workers remains idle for a while when cpu usage gets over this limit (0 = disable)
CPUMaxUsage float64 `name:"cpuMaxUsage" default:"0.80" usage:"workers remains idle for a while when cpu usage gets over this limit (0 = disable)"`
// the amount of parallel running spammers
Workers int `default:"0" usage:"the amount of parallel running spammers"`
// whether to automatically start the spammer on startup
Autostart bool `default:"false" usage:"automatically start the spammer on startup"`
// NonLazyTipsThreshold is the maximum amount of tips in the non-lazy tip-pool before the spammer tries to reduce these (0 = always).
// This is used to support the network if someone attacks the tangle by spamming a lot of tips.
NonLazyTipsThreshold uint32 `default:"0" usage:"the maximum amount of tips in the non-lazy tip-pool before the spammer tries to reduce these (0 = always)"`
// SemiLazyTipsThreshold is the maximum amount of tips in the semi-lazy tip-pool before the spammer tries to reduce these (0 = disable).
// This is used to support the network if someone attacks the tangle by spamming a lot of tips.
SemiLazyTipsThreshold uint32 `default:"30" usage:"the maximum amount of tips in the semi-lazy tip-pool before the spammer tries to reduce these (0 = disable)"`

// the message to embed within the spam blocks
Message string `default:"We are all made of stardust." usage:"the message to embed within the spam blocks"`
// the tag of the block
Tag string `default:"HORNET Spammer" usage:"the tag of the block"`
// the tag of the block if the semi-lazy pool is used (uses "tag" if empty)
TagSemiLazy string `default:"HORNET Spammer Semi-Lazy" usage:"the tag of the block if the semi-lazy pool is used (uses \"tag\" if empty)"`

ValueSpam struct {
// whether to spam with transaction payloads instead of data payloads
Enabled bool `default:"false" usage:"whether to spam with transaction payloads instead of data payloads"`
SendBasicOutput bool `default:"true" usage:"whether to send basic outputs"`
CollectBasicOutput bool `default:"true" usage:"whether to collect basic outputs"`
CreateAlias bool `default:"true" usage:"whether to create aliases"`
DestroyAlias bool `default:"true" usage:"whether to destroy aliases"`
CreateFoundry bool `default:"true" usage:"whether to create foundries"`
DestroyFoundry bool `default:"true" usage:"whether to destroy foundries"`
MintNativeToken bool `default:"true" usage:"whether to mint native tokens"`
MeltNativeToken bool `default:"true" usage:"whether to melt native tokens"`
CreateNFT bool `default:"true" usage:"whether to create NFTs"`
DestroyNFT bool `default:"true" usage:"whether to destroy NFTs"`
}

Tipselection struct {
// NonLazyTipsThreshold is the maximum amount of tips in the non-lazy tip-pool before the spammer tries to reduce these (0 = always).
// This is used to support the network if someone attacks the tangle by spamming a lot of tips.
NonLazyTipsThreshold uint32 `default:"0" usage:"the maximum amount of tips in the non-lazy tip-pool before the spammer tries to reduce these (0 = always)"`
// SemiLazyTipsThreshold is the maximum amount of tips in the semi-lazy tip-pool before the spammer tries to reduce these (0 = disable).
// This is used to support the network if someone attacks the tangle by spamming a lot of tips.
SemiLazyTipsThreshold uint32 `default:"30" usage:"the maximum amount of tips in the semi-lazy tip-pool before the spammer tries to reduce these (0 = disable)"`
}
}

// ParametersRestAPI contains the definition of the parameters used by REST API.
type ParametersRestAPI struct {
// BindAddress defines the bind address on which the Spammer HTTP server listens.
BindAddress string `default:"localhost:9092" usage:"the bind address on which the Spammer HTTP server listens"`
// DebugRequestLoggerEnabled defines whether the debug logging for requests should be enabled
DebugRequestLoggerEnabled bool `default:"false" usage:"whether the debug logging for requests should be enabled"`
}
Expand All @@ -43,11 +65,13 @@ type ParametersPoW struct {
}

var ParamsSpammer = &ParametersSpammer{}
var ParamsRestAPI = &ParametersRestAPI{}
var ParamsPoW = &ParametersPoW{}

var params = &app.ComponentParams{
Params: map[string]any{
"spammer": ParamsSpammer,
"restAPI": ParamsRestAPI,
"pow": ParamsPoW,
},
Masked: nil,
Expand Down
100 changes: 75 additions & 25 deletions documentation/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,43 +64,93 @@ Example:

## <a id="spammer"></a> 3. Spammer

| Name | Description | Type | Default value |
| ------------------------- | ----------------------------------------------------------------------------------------------------------- | ------- | ------------------------------ |
| bindAddress | The bind address on which the Spammer HTTP server listens | string | "localhost:9092" |
| message | The message to embed within the spam blocks | string | "We are all made of stardust." |
| tag | The tag of the block | string | "HORNET Spammer" |
| tagSemiLazy | The tag of the block if the semi-lazy pool is used (uses "tag" if empty) | string | "HORNET Spammer Semi-Lazy" |
| valueSpamEnabled | Whether to spam with transaction payloads instead of data payloads | boolean | false |
| bpsRateLimit | The blocks per second rate limit for the spammer (0 = no limit) | float | 0.0 |
| cpuMaxUsage | Workers remains idle for a while when cpu usage gets over this limit (0 = disable) | float | 0.8 |
| workers | The amount of parallel running spammers | int | 0 |
| autostart | Automatically start the spammer on startup | boolean | false |
| nonLazyTipsThreshold | The maximum amount of tips in the non-lazy tip-pool before the spammer tries to reduce these (0 = always) | uint | 0 |
| semiLazyTipsThreshold | The maximum amount of tips in the semi-lazy tip-pool before the spammer tries to reduce these (0 = disable) | uint | 30 |
| debugRequestLoggerEnabled | Whether the debug logging for requests should be enabled | boolean | false |
| Name | Description | Type | Default value |
| ------------------------------------- | ---------------------------------------------------------------------------------- | ------- | ------------------------------ |
| autostart | Automatically start the spammer on startup | boolean | false |
| bpsRateLimit | The blocks per second rate limit for the spammer (0 = no limit) | float | 0.0 |
| cpuMaxUsage | Workers remains idle for a while when cpu usage gets over this limit (0 = disable) | float | 0.8 |
| workers | The amount of parallel running spammers | int | 0 |
| message | The message to embed within the spam blocks | string | "We are all made of stardust." |
| tag | The tag of the block | string | "HORNET Spammer" |
| tagSemiLazy | The tag of the block if the semi-lazy pool is used (uses "tag" if empty) | string | "HORNET Spammer Semi-Lazy" |
| [valueSpam](#spammer_valuespam) | Configuration for Value Spam | object | |
| [tipselection](#spammer_tipselection) | Configuration for tipselection | object | |

### <a id="spammer_valuespam"></a> Value Spam

| Name | Description | Type | Default value |
| ------------------ | ------------------------------------------------------------------ | ------- | ------------- |
| enabled | Whether to spam with transaction payloads instead of data payloads | boolean | false |
| sendBasicOutput | Whether to send basic outputs | boolean | true |
| collectBasicOutput | Whether to collect basic outputs | boolean | true |
| createAlias | Whether to create aliases | boolean | true |
| destroyAlias | Whether to destroy aliases | boolean | true |
| createFoundry | Whether to create foundries | boolean | true |
| destroyFoundry | Whether to destroy foundries | boolean | true |
| mintNativeToken | Whether to mint native tokens | boolean | true |
| meltNativeToken | Whether to melt native tokens | boolean | true |
| createNFT | Whether to create NFTs | boolean | true |
| destroyNFT | Whether to destroy NFTs | boolean | true |

### <a id="spammer_tipselection"></a> Tipselection

| Name | Description | Type | Default value |
| --------------------- | ----------------------------------------------------------------------------------------------------------- | ---- | ------------- |
| nonLazyTipsThreshold | The maximum amount of tips in the non-lazy tip-pool before the spammer tries to reduce these (0 = always) | uint | 0 |
| semiLazyTipsThreshold | The maximum amount of tips in the semi-lazy tip-pool before the spammer tries to reduce these (0 = disable) | uint | 30 |

Example:

```json
{
"spammer": {
"bindAddress": "localhost:9092",
"message": "We are all made of stardust.",
"tag": "HORNET Spammer",
"tagSemiLazy": "HORNET Spammer Semi-Lazy",
"valueSpamEnabled": false,
"autostart": false,
"bpsRateLimit": 0,
"cpuMaxUsage": 0.8,
"workers": 0,
"autostart": false,
"nonLazyTipsThreshold": 0,
"semiLazyTipsThreshold": 30,
"message": "We are all made of stardust.",
"tag": "HORNET Spammer",
"tagSemiLazy": "HORNET Spammer Semi-Lazy",
"valueSpam": {
"enabled": false,
"sendBasicOutput": true,
"collectBasicOutput": true,
"createAlias": true,
"destroyAlias": true,
"createFoundry": true,
"destroyFoundry": true,
"mintNativeToken": true,
"meltNativeToken": true,
"createNFT": true,
"destroyNFT": true
},
"tipselection": {
"nonLazyTipsThreshold": 0,
"semiLazyTipsThreshold": 30
}
}
}
```

## <a id="restapi"></a> 4. RestAPI

| Name | Description | Type | Default value |
| ------------------------- | --------------------------------------------------------- | ------- | ---------------- |
| bindAddress | The bind address on which the Spammer HTTP server listens | string | "localhost:9092" |
| debugRequestLoggerEnabled | Whether the debug logging for requests should be enabled | boolean | false |

Example:

```json
{
"restAPI": {
"bindAddress": "localhost:9092",
"debugRequestLoggerEnabled": false
}
}
```

## <a id="pow"></a> 4. Pow
## <a id="pow"></a> 5. Pow

| Name | Description | Type | Default value |
| ------------------- | --------------------------------------- | ------ | ------------- |
Expand All @@ -116,7 +166,7 @@ Example:
}
```

## <a id="profiling"></a> 5. Profiling
## <a id="profiling"></a> 6. Profiling

| Name | Description | Type | Default value |
| ----------- | ------------------------------------------------- | ------- | ---------------- |
Expand All @@ -134,7 +184,7 @@ Example:
}
```

## <a id="prometheus"></a> 6. Prometheus
## <a id="prometheus"></a> 7. Prometheus

| Name | Description | Type | Default value |
| --------------- | --------------------------------------------------------------- | ------- | ---------------- |
Expand Down
Loading