Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
0xA001113 committed Jun 12, 2024
0 parents commit 5812a63
Show file tree
Hide file tree
Showing 29 changed files with 7,000 additions and 0 deletions.
167 changes: 167 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
name: Tests
on: [push, pull_request]

env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse # Should improve the speed of the build and the cache size.
ZSTD_CLEVEL: 10 # We want some tradeoff between speed and size.
ZSTD_NBTHREADS: 2 # We only got 2 cores.

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
id: rust-toolchain
uses: dtolnay/rust-toolchain@stable

- name: Set up cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}

- name: Install protoc
uses: taiki-e/install-action@v2
with:
tool: protoc

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --tests

test:
name: Test Suite
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
id: rust-toolchain
uses: dtolnay/rust-toolchain@stable

- name: Set up cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}

- name: Install protoc
uses: taiki-e/install-action@v2
with:
tool: protoc

- name: Run cargo test regular features
uses: actions-rs/cargo@v1
with:
command: test

- name: Run cargo test no asm
uses: actions-rs/cargo@v1
with:
command: test
args: --features=no-asm

- name: Run cargo test with parking_lot
uses: actions-rs/cargo@v1
with:
command: test
args: --features parking_lot

- name: Run cargo test shuttle
uses: actions-rs/cargo@v1
with:
command: test
args: --features=shuttle

test-release:
name: Test Suite Release
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
id: rust-toolchain
uses: dtolnay/rust-toolchain@stable

- name: Set up cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}

- name: Install protoc
uses: taiki-e/install-action@v2
with:
tool: protoc

- name: Run cargo test release regular features
uses: actions-rs/cargo@v1
with:
command: test
args: --release

- name: Run cargo test release no asm
uses: actions-rs/cargo@v1
with:
command: test
args: --features=no-asm --release

- name: Run cargo test release with parking_lot
uses: actions-rs/cargo@v1
with:
command: test
args: --features=parking_lot --release

- name: Run cargo test release shuttle
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features=shuttle --release

lints:
name: Lints
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
id: rust-toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Set up cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}

- name: Install protoc
uses: taiki-e/install-action@v2
with:
tool: protoc

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --tests -- -D warnings
101 changes: 101 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build and upload assets
on:
release:
types: [ published ]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:

# Build gnu-linux on ubuntu-18.04 and musl on ubuntu latest.
os: [ ubuntu-20.04, ubuntu-latest, windows-latest, macos-latest ]
name: Building, ${{ matrix.os }}
steps:

- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
id: rust-toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Install protoc
uses: taiki-e/install-action@v2
with:
tool: protoc

- name: Create bin directory
run: mkdir bin

- name: Build on Linux GNU
if: matrix.os == 'ubuntu-20.04'

# We're using musl to make the binaries statically linked and portable.
run: |
cargo build --target=x86_64-unknown-linux-gnu --release
archive="bin/spectre-miner-${{ github.event.release.tag_name }}-linux-gnu-amd64.zip"
asset_name="spectre-miner-${{ github.event.release.tag_name }}-linux-gnu-amd64"
strip ./target/x86_64-unknown-linux-gnu/release/spectre-miner
mv ./target/x86_64-unknown-linux-gnu/release/spectre-miner ./bin/${asset_name}
zip -r "${archive}" ./bin/${asset_name}
rm ./bin/${asset_name}
- name: Build on Linux musl
if: matrix.os == 'ubuntu-latest'

# We're using musl to make the binaries statically linked and portable.
run: |
sudo apt-get install -y musl-tools
rustup target add x86_64-unknown-linux-musl
cargo build --target=x86_64-unknown-linux-musl --release
archive="bin/spectre-miner-${{ github.event.release.tag_name }}-linux-musl-amd64.zip"
asset_name="spectre-miner-${{ github.event.release.tag_name }}-linux-musl-amd64"
strip ./target/x86_64-unknown-linux-musl/release/spectre-miner
mv ./target/x86_64-unknown-linux-musl/release/spectre-miner ./bin/${asset_name}
zip -r "${archive}" ./bin/${asset_name}
rm ./bin/${asset_name}
- name: Build on Windows
if: matrix.os == 'windows-latest'
shell: bash

# We're using 'bin/' instead of './bin/' as otherwise 7z won't add the directory.
run: |
cargo build --target=x86_64-pc-windows-msvc --release
archive="bin/spectre-miner-${{ github.event.release.tag_name }}-win64-amd64.zip"
asset_name="spectre-miner-${{ github.event.release.tag_name }}-win64-amd64.exe"
mv ./target/x86_64-pc-windows-msvc/release/spectre-miner.exe ./bin/${asset_name}
7z a -tzip -r "${archive}" bin/${asset_name}
rm ./bin/${asset_name}
- name: Build on MacOS for x86_64
if: matrix.os == 'macos-latest'
run: |
rustup target add x86_64-apple-darwin
cargo build --target=x86_64-apple-darwin --release
archive="bin/spectre-miner-${{ github.event.release.tag_name }}-osx-amd64.zip"
asset_name="spectre-miner-${{ github.event.release.tag_name }}-osx-amd64"
mv ./target/x86_64-apple-darwin/release/spectre-miner ./bin/${asset_name}
zip -r "${archive}" ./bin/${asset_name}
rm ./bin/${asset_name}
- name: Build on MacOS for M1/2
if: matrix.os == 'macos-latest'
run: |
cargo build --target=aarch64-apple-darwin --release
archive="bin/spectre-miner-${{ github.event.release.tag_name }}-osx-aarch64.zip"
asset_name="spectre-miner-${{ github.event.release.tag_name }}-osx-aarch64"
mv ./target/aarch64-apple-darwin/release/spectre-miner ./bin/${asset_name}
zip -r "${archive}" ./bin/${asset_name}
rm ./bin/${asset_name}
- name: Upload release asset
uses: softprops/action-gh-release@v1
with:
files: |
bin/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
6 changes: 6 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
max_width = 120
use_field_init_shorthand = true
use_try_shorthand = true
use_small_heuristics = "Max"
newline_style = "unix"
edition = "2021"
60 changes: 60 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[package]
name = "spectre-miner"
version = "0.3.14"
edition = "2021"
license = "MIT/Apache-2.0"
authors = ["Spectre developers"]
repository = "https://github.com/spectre-project/spectre-miner"
readme = "README.md"
description = "A Spectre high performance CPU miner"
categories = ["command-line-utilities"]
keywords = ["blockchain", "cli"]
include = [
"src/**",
"proto/**",
"Cargo.toml",
"Cargo.lock",
"build.rs",
"LICENSE-MIT",
"LICENSE-APACHE",
"README.md",
]

[dependencies]
tonic = "0.10"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
prost = "0.12"
tokio-stream = "0.1"
num_cpus = "1"
rand = "0.8"
blake2b_simd = "1.0.0"
clap = { version = "4", features = ["derive", "color"] }
log = "0.4"
env_logger = "0.10"
arc-swap = "1.6.0"
keccak = { version = "0.1", optional = true }
parking = { package = "parking_lot", version = "0.12", optional = true }
shuttle = { version = "0.6", optional = true }
chrono = "0.4"
spectrex = "0.3.15"

[features]
default = ["keccak?/asm"]
parking_lot = ["parking", "tokio/parking_lot"]
bench = []
no-asm = ["keccak"]

[target.'cfg(not(target_arch = "x86_64"))'.dependencies]
keccak = "0.1"

[profile.release]
lto = true
codegen-units = 1
strip = true

[build-dependencies]
tonic-build = { version = "0.10", default-features = false, features = ["prost", "transport"] }
cc = "1"

[dev-dependencies]
sha3 = "0.10"
Loading

0 comments on commit 5812a63

Please sign in to comment.