Skip to content

Rk stratum2.0 fixed#877

Open
LiveLaughLove13 wants to merge 79 commits intokaspanet:masterfrom
LiveLaughLove13:RKStratum2.0-Fixed
Open

Rk stratum2.0 fixed#877
LiveLaughLove13 wants to merge 79 commits intokaspanet:masterfrom
LiveLaughLove13:RKStratum2.0-Fixed

Conversation

@LiveLaughLove13
Copy link
Contributor

@LiveLaughLove13 LiveLaughLove13 commented Feb 10, 2026

Bridge Configuration Options

RKStratum 2.0 — What’s New (vs CustomIdentifier)

This is a user-facing summary of the main upgrades that landed in the RKStratum2.0 branch compared to CustomIdentifier.

Web UI & API

  • Built-in web dashboard
    • Served directly by the bridge (no external UI service required).
    • Includes a main dashboard and a raw view.
  • New HTTP API endpoints for monitoring
    • /api/status for basic node/bridge status.
    • /api/stats for summarized worker/block/share stats.
    • /metrics for Prometheus scraping.

CLI & Configuration Quality-of-Life

  • Full CLI support for config values
    • Most config.yaml settings can now be overridden via CLI flags.
  • --config <path> support + smarter config discovery
    • The bridge can locate config relative to the executable in common deployment layouts.
  • More automation-friendly argument parsing
    • Boolean parsing supports common forms (true/false, 1/0, yes/no, on/off).
    • Port inputs accept :PORT or HOST:PORT.

Multi-Instance Improvements

  • Improved multi-instance configuration & overrides
    • Adds --instance syntax for defining multiple stratum listeners from the CLI.
    • Adds validation for duplicate ports and missing required instance fields.

Observability & Metrics

  • Expanded Prometheus metrics + better dashboard data
    • More complete worker/share/block instrumentation and better aggregation.
  • Optional global Web UI bind
    • A single port can expose aggregated stats across all instances.

Reliability / Operator Experience

  • Graceful shutdown
    • Coordinated shutdown with a drain window and forced-exit behavior on repeated interrupts.
  • Logging fixes and improvements
    • Log files are no longer created empty.
    • Log file naming standardized to RKStratum_*.log.
    • Improved console formatting (including better readability of periodic stats output).
  • Health check server
    • Optional lightweight health endpoint via health_check_port.

Optional / Advanced Features

  • Internal CPU miner (feature-gated)
    • Optional built-in CPU miner mode controlled via CLI flags when compiled with the rkstratum_cpu_miner feature.

Packaging & Deployment

  • Stratum bridge Docker support
    • dedicated Dockerfile.stratum-bridge.
  • Release packaging includes the bridge binary
    • Linux/Windows/macOS release assets build and ship stratum-bridge alongside other binaries.

Quick Start

  • Config file
    • Default: config.yaml (current directory).
    • Repository example: bridge/config.yaml.
  • Run (external node)
    • stratum-bridge --config bridge/config.yaml --node-mode external
  • Run (in-process node)
    • stratum-bridge --config bridge/config.yaml --node-mode inprocess -- <kaspad args...>
  • Dashboard (optional)
    • Set web_port (or use --web-port) and open: http://127.0.0.1:<PORT>/

Global Settings (shared by all instances)

Setting Type Default Description
kaspad_address String "localhost:16110" Kaspa node gRPC address. All instances use the same node. Format: "HOST:PORT" or "grpc://HOST:PORT".
block_wait_time Integer (milliseconds) 1000 How long to wait between checking for new block templates.
print_stats Boolean true Print mining statistics to the console.
log_to_file Boolean true Default log-to-file setting (can be overridden per-instance).
health_check_port String "" (disabled) Global health check server port. Leave empty to disable.
web_port String "" (disabled) Optional global Web UI / aggregated metrics port. Examples: ":3030", "0.0.0.0:3030".
var_diff Boolean true Enable variable difficulty (can be overridden per-instance).
shares_per_min Integer 20 Target shares per minute for variable difficulty (can be overridden per-instance).
var_diff_stats Boolean false Print variable difficulty statistics (can be overridden per-instance).
extranonce_size Integer 0 Extranonce size (auto-detected per client; this is for backward compatibility).
pow2_clamp Boolean false Enable power-of-2 difficulty clamping (can be overridden per-instance).
coinbase_tag_suffix String "" (empty) Optional suffix appended to the fixed base coinbase tag "RK-Stratum". Results in "RK-Stratum/<suffix>".

Instance Settings (each instance can have its own)

Setting Type Default Description
stratum_port String ":5555" Required. Stratum port for this instance. Must be unique across instances. Can be ":PORT" or "HOST:PORT".
min_share_diff Integer 8192 Required. Minimum share difficulty for this instance.
prom_port String None (disabled) Optional Prometheus port for this instance. Can be ":PORT" or "HOST:PORT".
log_to_file Boolean None (inherits global) Optional per-instance log-to-file setting. If not set, uses the global log_to_file.
block_wait_time Integer (milliseconds) None (inherits global) Optional per-instance block template polling interval.
extranonce_size Integer None (inherits global) Optional per-instance extranonce size override.
var_diff Boolean None (inherits global) Optional per-instance variable difficulty override.
shares_per_min Integer None (inherits global) Optional per-instance target shares per minute override.
var_diff_stats Boolean None (inherits global) Optional per-instance variable difficulty statistics override.
pow2_clamp Boolean None (inherits global) Optional per-instance power-of-2 difficulty clamping override.

Notes and Behavior

  • Multi-instance mode: If the instances array exists in config.yaml, the bridge runs in multi-instance mode. Otherwise, it runs in single-instance mode using the global settings.
  • Port formatting: stratum_port and prom_port can be specified as ":PORT" or "HOST:PORT". The bridge will prepend "0.0.0.0" if only a port is provided.
  • Coinbase tag: The base tag is always "RK-Stratum". You can only append a suffix via coinbase_tag_suffix. The suffix is sanitized to alphanumeric characters, ., _, and -, and is limited to 64 characters.
  • Variable difficulty: When enabled, the bridge adjusts the difficulty for miners based on their hashrate to target shares_per_min.
  • Logging: If log_to_file is enabled, logs are written under:
    • Windows: %LOCALAPPDATA%\kaspa-stratum-bridge\logs\RKStratum_<timestamp>.log
    • Linux/macOS: ~/.kaspa-stratum-bridge/logs/RKStratum_<timestamp>.log

CLI Notes

  • Booleans: Accept true/false, 1/0, yes/no, on/off.
  • Ports: Accept both :PORT and HOST:PORT formats.
  • Config override: CLI flags override values from config.yaml.
  • Multi-instance via CLI:
    • Use one or more --instance specs (example: --instance "port=:5555,diff=8192").
    • When using --instance, do not use the single-instance flags --stratum-port/--prom-port/--instance-*.

Notes

  • For the most up-to-date CLI reference, run stratum-bridge --help.

fix: bridge config persistence, logging, shutdown, and dashboard XSS
Difficulty- individual worker diff, Session Uptime
"Fixed block count mismatch in terminal stats TOTAL row. The TOTAL was using instance-level aggregate (overall.blocks_found) which included blocks from pruned workers, while individual rows only showed active workers. Changed to sum blocks from currently visible workers, ensuring TOTAL matches the sum of individual worker block counts."
The terminal stats now show:
Blocks: Current blocks from online workers (matches what's visible in individual rows)
Total: Historical total blocks from all workers, even if they've gone offline
This provides both current status and historical totals.
Refactor KaspaApi: Remove dead code and simplify API based on code review changes to be made from @IzioDev

- Remove unused `new()` function, rename `new_with_shutdown` to `new`
- Make `shutdown_rx` required (non-optional) - all callers provide it
- Remove unused `_block_wait_time` parameter from constructor
- Remove `verbose` parameters from `wait_for_sync` functions
- Simplify Option handling for shutdown receiver
Copy link
Collaborator

@coderofstuff coderofstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial comments

fail-fast: false
# matrix:
# os: [ ubuntu-latest, macos-latest, windows-latest ]
# strategy:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The matrix strategy was commented out due to CI resource constraints. The test suite builds the entire workspace and needs significant disk space; macOS and Windows runners have stricter limits than Ubuntu, and running on all three OS was causing disk space failures. It also triples CI execution time, delaying PR feedback. Multi-OS testing still happens in release builds (.github/workflows/deploy.yaml), which validates binaries on ubuntu-latest, windows-latest, and macos-latest, ensuring cross-platform compatibility. The code is commented out (not deleted) for easy re-enablement if needed. The current approach balances fast CI feedback during development with cross-platform validation during releases.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that should be included as part of this PR. please revert this part.

Comment on lines +357 to +359
# Append linker flag to handle mimalloc conflicts with libstdc++ in musl builds
# This allows multiple definitions to resolve the kaspa-alloc mimalloc override conflict
export RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,--allow-multiple-definition"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These RUSTFLAGS will apply to all the binaries build down below. But I think you only intended it to apply to kaspa-stratum-bridge.

What is it about the code of the bridge that's making this change necessary anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bridge needs this because it has both kaspa-alloc (which provides mimalloc) and a direct mimalloc dependency. In musl builds, mimalloc links against libstdc++ symbols, and static linking causes multiple definition errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"These RUSTFLAGS will apply to all the binaries build down below. But I think you only intended it to apply to kaspa-stratum-bridge." As a solution I have split the build into two steps.

Comment on lines +42 to +106
### Internal CPU miner (feature-gated)

The internal CPU miner is a **compile-time feature**.

Build:

```bash
cargo build -p kaspa-stratum-bridge --release --features rkstratum_cpu_miner
```

Run (external node mode + internal CPU miner enabled):

```bash
cargo run -p kaspa-stratum-bridge --release --features rkstratum_cpu_miner --bin stratum-bridge -- --config bridge/config.yaml --node-mode external --internal-cpu-miner --internal-cpu-miner-address kaspa:YOUR_WALLET_ADDRESS --internal-cpu-miner-threads 1
```

### Testing

Run all bridge tests (including CPU miner tests when feature is enabled):

```bash
cargo test -p kaspa-stratum-bridge --features rkstratum_cpu_miner --bin stratum-bridge
```

Run tests without the CPU miner feature:

```bash
cargo test -p kaspa-stratum-bridge --bin stratum-bridge
```

The test suite includes:
- Configuration parsing tests
- JSON-RPC event parsing tests
- Network utilities tests
- Hasher/difficulty calculation tests
- Mining state management tests
- Miner compatibility tests (IceRiver, Bitmain, BzMiner, Goldshell)
- Share validation and PoW checking tests
- VarDiff logic tests
- Wallet address cleaning tests
- CPU miner tests (when `rkstratum_cpu_miner` feature is enabled)

The test suite is comprehensive and educational, with 127+ unit tests designed to help developers understand the codebase.

### Running two bridges at once (two dashboards)

If you run **two `stratum-bridge` processes** simultaneously (e.g. one in-process and one external),
they **cannot share the same**:
- `web_dashboard_port` (dashboard)
- any Stratum ports
- any per-instance Prometheus ports

Recommended setup:
- **In-process bridge**: run normally with `--config config.yaml` (uses `web_dashboard_port: ":3030"` and the configured instance ports)
- **External bridge**: do **not** reuse the same instance ports; instead, run a single custom Stratum instance on a different port and set a different web dashboard port.

Example (external bridge on `:3031` + Stratum `:16120`):

```bash
cargo run -p kaspa-stratum-bridge --release --features rkstratum_cpu_miner --bin stratum-bridge -- --config config.yaml --web-dashboard-port :3031 --node-mode external --kaspad-address 127.0.0.1:16210 --instance "port=:16120,diff=1" --internal-cpu-miner --internal-cpu-miner-address "kaspatest:address" --internal-cpu-miner-threads 1
```

Open:
- `http://127.0.0.1:3030/` for the in-process bridge
- `http://127.0.0.1:3031/` for the external bridge
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these sections all the way down. Someone running the bridge will want the information on how to run it to come first.

Comment on lines +7 to +10
[target.x86_64-unknown-linux-musl]
rustflags = [
"-C", "link-arg=-Wl,--allow-multiple-definition",
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? Have you verified that this does not impact the kaspad binary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the flag exists:
kaspa-alloc uses mimalloc with "override" for non-macos targets (including musl)
The bridge also has a direct mimalloc dependency for musl builds (without override)
This creates a dual mimalloc dependency structure that requires the flag.

It does not impact kaspad binary.

The change was so that we did not have to make any changes directly to Util

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@biryukovmaxim do you have any recommendations here? I'm just concerned this applied at the top level like this affects all binaries

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@biryukovmaxim do you have any recommendations here? I'm just concerned this applied at the top level like this affects all binaries

Sry I have no expertise of what it could lead to. @saefstroem since you built musl step in ci, maybe you have any advices, considerations here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the flag exists: kaspa-alloc uses mimalloc with "override" for non-macos targets (including musl) The bridge also has a direct mimalloc dependency for musl builds (without override)

Doesn't it mean you can remove direct dependency

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@biryukovmaxim do you have any recommendations here? I'm just concerned this applied at the top level like this affects all binaries

// build.rs
fn main() {
    println!("cargo:rustc-link-arg=-Wl,--allow-multiple-definition");
}

Probably will do the same only for bridge crate

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into this more, this is probably fine to have.

@saefstroem would like to get your confirmation here too.

LiveLaughLove13 and others added 3 commits February 10, 2026 20:48
Summary of the Change

Problem: The RUSTFLAGS with --allow-multiple-definition was being applied to all binaries (kaspad, rothschild, kaspa-wallet, and stratum-bridge), but it's only needed for kaspa-stratum-bridge.
Solution: Split the build into two steps:
Copy link
Collaborator

@coderofstuff coderofstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuing review. still need to get to the rs parts but submitting feedback now

fail-fast: false
# matrix:
# os: [ ubuntu-latest, macos-latest, windows-latest ]
# strategy:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that should be included as part of this PR. please revert this part.

cargo --verbose build --bin kaspad --bin rothschild --bin kaspa-wallet --release --target x86_64-unknown-linux-musl
# Build bridge with allow-multiple-definition flag to handle mimalloc conflicts with libstdc++ in musl builds
# This flag is only needed for kaspa-stratum-bridge due to its dual mimalloc dependency structure
export RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,--allow-multiple-definition"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this rustflags is already in .cargo/cargo.toml, is it still needed here? This line can probably be removed.

Comment on lines 32 to 35
- `:5555`
- `:5556`
- `:5557`
- `:5558`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mentions the ports being open but not why. Reformat this into tabular form with columns: Port and Purpose

- `:5557`
- `:5558`

### CLI Help
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually the 2nd most important part, so it should come before Default configs / ports and right after a missing section: "Running from a release" (which describes how you would run this from the releases).

@@ -41,10 +46,12 @@

### Run (external node)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The in-process mode should come first.

It should show instructions using simply cargo (without any configs) to make it very clear that there are sane defaults in place:

cargo run --bin kaspa-stratum-bridge --release

Comment on lines +7 to +10
[target.x86_64-unknown-linux-musl]
rustflags = [
"-C", "link-arg=-Wl,--allow-multiple-definition",
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into this more, this is probably fine to have.

@saefstroem would like to get your confirmation here too.

Comment on lines +24 to +38
- stratum_port: ":5559"
min_share_diff: 4
prom_port: ":2118"
log_to_file: true

- stratum_port: ":5560"
min_share_diff: 512
prom_port: ":2119"
log_to_file: true

- stratum_port: ":5561"
min_share_diff: 1024
prom_port: ":2120"
log_to_file: true

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These extra ports aren't documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default config / ports (Port | Purpose table), including :5559, :5560, :5561 and prom ports.”

Readme updated

Reverted core/src/log/mod.rs as requested.
Changed back to:
let _handle = log4rs::init_config(config).unwrap();
shows inprocess mode first, then external
CI reflective of master

What was happening:
In bridge in-process mode, tracing_log::LogTracer::init() was setting the global log logger first.
Then embedded kaspad called kaspa_core::log::init_logger(...).unwrap(), which failed with SetLoggerError(()) and panicked.
What I changed:
Updated bridge/src/tracing_setup.rs to not initialize LogTracer in in-process mode.
It now only does LogTracer::init() in non-inprocess mode.
This removes the double-initialization conflict and keeps the required unwrap() line in core/src/log/mod.rs exactly as-is.
Ci revert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants