Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
0xA001113 committed May 6, 2024
0 parents commit 0f0c5f5
Show file tree
Hide file tree
Showing 39 changed files with 8,346 additions and 0 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/build-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Build and upload assets
on:
release:
types: [ published ]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
TARGET: linux/x86_64
- os: ubuntu-latest
TARGET: linux/aarch64
- os: ubuntu-latest
TARGET: windows/x64
- os: macos-latest
TARGET: macos/x64
name: Building, ${{ matrix.TARGET }}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.20.12

- name: Update sources
if: matrix.TARGET == 'linux/aarch64' || matrix.TARGET == 'windows/x64'
run: sudo apt-get update -y

- name: Install compilers
if: matrix.TARGET == 'linux/aarch64' || matrix.TARGET == 'windows/x64'
run: sudo apt-get install gcc-aarch64-linux-gnu gcc-mingw-w64-x86-64-win32 -y

- name: Build on Linux for ${{ matrix.TARGET }}
if: matrix.TARGET == 'linux/x86_64'
run: |
# `-extldflags=-static` - means static link everything,
# `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
# `-s -w` strips the binary to produce smaller size binaries
cd ./cmd/spectrebridge
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ .
mv ./bin/spectrebridge ./bin/spr_bridge
cp ./config.yaml ./bin/config.yaml
archive="bin/spr_bridge-${{ github.event.release.tag_name }}-linux-x86_64.zip"
asset_name="spr_bridge-${{ github.event.release.tag_name }}-linux-x86_64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
- name: Build on Linux for ${{ matrix.TARGET }}
if: matrix.TARGET == 'linux/aarch64'
env:
CGO_ENABLED: 1
CC: aarch64-linux-gnu-gcc
GOOS: linux
GOARCH: arm64
run: |
# `-extldflags=-static` - means static link everything,
# `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
# `-s -w` strips the binary to produce smaller size binaries
cd ./cmd/spectrebridge
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ .
mv ./bin/spectrebridge ./bin/spr_bridge
cp ./config.yaml ./bin/config.yaml
archive="bin/spr_bridge-${{ github.event.release.tag_name }}-linux-aarch64.zip"
asset_name="spr_bridge-${{ github.event.release.tag_name }}-linux-aarch64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
- name: Build on Linux for ${{ matrix.TARGET }}
if: matrix.TARGET == 'windows/x64'
env:
CGO_ENABLED: 1
CC: x86_64-w64-mingw32-gcc
GOOS: windows
GOARCH: amd64
run: |
# `-extldflags=-static` - means static link everything,
# `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
# `-s -w` strips the binary to produce smaller size binaries
cd ./cmd/spectrebridge
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ .
mv ./bin/spectrebridge.exe ./bin/spr_bridge.exe
cp ./config.yaml ./bin/config.yaml
archive="bin/spr_bridge-${{ github.event.release.tag_name }}-windows-x64.zip"
asset_name="spr_bridge-${{ github.event.release.tag_name }}-windows-x64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
- name: Build on Linux for ${{ matrix.TARGET }}
if: matrix.TARGET == 'macos/x64'
run: |
cd ./cmd/spectrebridge
go build -v -ldflags="-s -w" -o ./bin/ .
mv ./bin/spectrebridge ./bin/spr_bridge
cp ./config.yaml ./bin/config.yaml
archive="bin/spr_bridge-${{ github.event.release.tag_name }}-macos-x64.zip"
asset_name="spr_bridge-${{ github.event.release.tag_name }}-macos-x64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: "./cmd/spectrebridge/${{ env.archive }}"
asset_name: "${{ env.asset_name }}"
asset_content_type: application/zip
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Temp files
*~

# Databases
*-shm
*-wal

# Log files
*.log

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# IDE
.idea
.vscode
debug
debug.test
__debug_bin
.DS_Store

cmd/spectrebridge/spectrebridge
release/
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Many thanks to original author Brandon Smith (onemorebsmith).
FROM golang:1.19.1 as builder

LABEL org.opencontainers.image.description="Dockerized Spectre Stratum Bridge"
LABEL org.opencontainers.image.authors="Spectre"
LABEL org.opencontainers.image.source="https://github.com/spectre-project/spectre-stratum-bridge"

WORKDIR /go/src/app
ADD go.mod .
ADD go.sum .
RUN go mod download

ADD . .
RUN go build -o /go/bin/app ./cmd/spectrebridge


FROM gcr.io/distroless/base:nonroot
COPY --from=builder /go/bin/app /
COPY cmd/spectrebridge/config.yaml /

WORKDIR /
ENTRYPOINT ["/app"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Brandon Smith

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
139 changes: 139 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Spectre Stratum Adapter

This is a lightweight daemon that allows mining to a local (or remote)
spectre node using stratum-base miners. It is up to the community to
build a stratum based miner, the original built-in miner is using gRPC
interface.

## Features

Shares-based work allocation with miner-like periodic stat output:

```
===============================================================================
worker name | avg hashrate | acc/stl/inv | blocks | uptime
-------------------------------------------------------------------------------
ghostface | 4.17KH/s | 3/0/0 | 0 | 21m17s
-------------------------------------------------------------------------------
| 4.17KH/s | 3/0/0 | 0 | 22m31s
======================================================== spr_bridge_v0.3.14 ===
```

## Variable difficulty engine (vardiff)

Multiple miners with significantly different hashrates can be connected
to the same stratum bridge instance, and the appropriate difficulty
will automatically be decided for each one. Default settings target
15 shares/min, resulting in high confidence decisions regarding
difficulty adjustments, and stable measured hashrates (1hr avg
hashrates within +/- 10% of actual). The minimum share difficulty is 12
and optimized for CPUs mining SpectreX.

## Grafana UI

The grafana monitoring UI is an optional component but included for
convenience. It will help to visualize collected statistics.

[detailed instructions here](docs/monitoring-setup.md)

## Prometheus API

If the app is run with the `-prom={port}` flag the application will host
stats on the port specified by `{port}`, these stats are documented in
the file [prom.go](src/spectrestratum/prom.go). This is intended to be use
by prometheus but the stats can be fetched and used independently if
desired. `curl http://localhost:2114/metrics | grep spr_` will get a
listing of current stats. All published stats have a `spr_` prefix for
ease of use.

# Install

## Build from source (native executable)

Install go 1.19 or later using whatever package manager is approprate
for your system, or from [https://go.dev/doc/install](https://go.dev/doc/install).

```
cd cmd/spectrebridge
go build .
```

Modify the config file in `./cmd/spectrebridge/config.yaml` with your setup,
the file comments explain the various flags.

```
./spectrebridge
```

## Docker (all-in-one)

Best option for users who want access to reporting, and aren't already
using Grafana/Prometheus. Requires a local copy of this repository, and
docker installation.

[Install Docker](https://docs.docker.com/engine/install/) using the
appropriate method for your OS. The docker commands below are assuming a
server type installation - details may be different for a desktop
installation.

The following will run the bridge assuming a local spectred node with
default port settings, and listen on port 5555 for incoming stratum
connections.

```
git clone https://github.com/spectre-project/spectre-stratum-bridge.git
cd spectre-stratum-bridge
docker compose -f docker-compose-all-src.yml up -d --build
```

These settings can be updated in the [config.yaml](cmd/spectrebridge/config.yaml)
file, or overridden by modifying, adding or deleting the parameters in the
`command` section of the `docker-compose-all-src.yml` file. Additionally,
Prometheus (the stats database) and Grafana (the dashboard) will be
started and accessible on ports 9090 and 3000 respectively. Once all
services are running, the dashboard should be reachable at
`http://127.0.0.1:3000/d/z73gHk89e1/sprb-monitoring` with default
username and password `admin`.

These commands builds the bridge component from source, rather than
the previous behavior of pulling down a pre-built image. You may still
use the pre-built image by replacing `docker-compose-all-src.yml` with
`docker-compose-all.yml`, but it is not guaranteed to be up to date, so
compiling from source is the better alternative.

## Docker (bridge only)

Best option for users who want docker encapsulation, and don't need
reporting, or are already using Grafana/Prometheus. Requires a local
copy of this repository, and docker installation.

[Install Docker](https://docs.docker.com/engine/install/) using the
appropriate method for your OS. The docker commands below are assuming a
server type installation - details may be different for a desktop
installation.

The following will run the bridge assuming a local spectred node with
default port settings, and listen on port 5555 for incoming stratum
connections.

```
git clone https://github.com/spectre-project/spectre-stratum-bridge.git
cd spectre-stratum-bridge
docker compose -f docker-compose-bridge-src.yml up -d --build
```

These settings can be updated in the [config.yaml](cmd/spectrebridge/config.yaml)
file, or overridden by modifying, adding or deleting the parameters in the
`command` section of the `docker-compose-bridge-src.yml`

These commands builds the bridge component from source, rather than the
previous behavior of pulling down a pre-built image. You may still use
the pre-built image by issuing the command `docker run -p 5555:5555 spectrenetwork/spectre_bridge:latest`,
but it is not guaranteed to be up to date, so compiling from source is
the better alternative.

## Kudos

* https://github.com/KaffinPX/KStratum
* https://github.com/onemorebsmith/kaspa-stratum-bridge
* https://github.com/rdugan/kaspa-stratum-bridge
Loading

0 comments on commit 0f0c5f5

Please sign in to comment.