A high-performance distributed Bitcoin mining pool server.

Related tags

Cryptography bitcoin
Overview

Viabtc Mining Server

ViaBTC Mining Server is a high-performance distributed Bitcoin mining pool server. We have made a lot of optimizations for Bitcoin blocks and transaction broadcasting, which can effectively reduce the orphaned block rate of the mining pool.

Overall Structure

Architecture

Code structure

Required systems

  • Redis: used to save the hashrate data of miners

Base library

  • network: An event base and high performance network programming library, easily supporting 1000K TCP connections. Include TCP/UDP/UNIX SOCKET server and client implementation, a simple timer, state machine, thread pool.

  • utils: Some basic library, including log, config parse, some data structure and http/websocket/rpc server implementation.

Modules

  1. Jobmaster, deployed on the mining pool server to connect to the Bitcoin node.
  • Jobmaster obtains mining task from the Bitcoin node and the Merged mining node, and sends it to Gateway.
  • To accept instructions from Bitpeer and Poolbench, so as to generate empty block task.
  • If a new block is successfully mined, it will be submitted to the node and broadcast by Blockmaster at the same time.
  1. Gateway, deployed on the mining pool server and can be scaled horizontally.
  • Implements the stratum protocol. When jobmaster sends the task, Gateway will forward it to miners, accept and verify the hashrate submitted by miners.
  • Implements a custom proxy protocol. When jobmaster sends the task, gateway will forward it to mineragent, accept and verify the hashrate of mineragent.
  • Aggregates hashrate and submits it to metawriter or metarelay.
  1. Mineragent, mainly used in mining farms with a huge number of mining machines and deployed in the mining farms, which can effectively save bandwidth and improve performance.
  • Implements the stratum protocol. It assigns task to miners, receives and verifies the hashrate submitted by miners.
  • Implements custom proxy protocol, receives mining task from gateway and submits hashrate to gateway.
  1. Blockmaster, connects the bitcoin node and bitpeer
  • Implements the thin block function and speeds up the synchronization of nodes and blocks.
  • After receiving the newly mined block, jobmaster will broadcast to multiple blockmaster and bitpeer to accelerate the block broadcasting.
  1. Bitpeer, can be considered as a special bitcoin node, with any number of deployments.
  • Implements the bitcoin p2p protocol and is connectable to multiple bitcoin nodes.
  • After accepting blockmaster’s block submission, Bitpeer will broadcast the block to the connected bitcoin node.
  • When Bitpeer noticed the block update of the connected node, it will prompt jobmaster to start mining empty blocks.
  1. Poolbench
  • Monitors the task update status of each mining pool.
  • If the height of the tasks of other mining pools is updated, it will prompt jobmaster to start mining empty blocks.
  1. Metawriter: Accpets the hashrate data submitted by Gateway or forwarded by Metarelay, and writes to redis after aggregating the data.
  2. Metarelay: Accpets the hashrate data submitted by Gateway and forwards it to Metawriter.
  3. Alertcenter: A simple server that writes FATAL level log to redis list so we can send alert emails.

Redis Data Format

There are 3 type of keys.

  1. event
  • list of keys:
newblock
newevent
newworker
  • example:
When new block found
newblock: {"name": "BTC", "hash": "0000000000000000032aee4bb112977ae8f4fb3614e0df196893285aa9c2adc0", "user": "haiyang", "worker": "example"}

list of event: connected, disconnected, When new connection connected or disconnected
newevent: {"user": "haiyang", "worker": "example", "coin": "BTC", "peer": "47.88.87.29", "event": "connected"}

When new worker connected
newworker: {"user": "haiyang", "worker": "example", "coin": "BTC"}
  • read example: (python code)
while True:
    try:
        r = redis_master.blpop('newblock', 60)
    except:
        time.sleep(1)
        continue
    if not r:
        continue
    try:
        data = json.loads(r[1])
    except:
        continue
  1. Mining data
  • key format:
<coin>:<t>:<user>(:<worker>(:reject))

coin: btc
t:
    s: share count ( count of submit shares)
    p: pow count (pow * 2^32 means how many hash have calculate)
    g: pow goal, counts the contribution of user’s hashrate in mining a block. 1 means that the hashrate that can mine a block has been submitted.

1) type: hash
2) key: unix timestamp, integer, multiple of 60, example: 1482252540 , represent the summary 3) of result in that minute.
4) value: integer or float(pow goal)
  • example:
btc:s:haiyang  means user haiyang valid submit share count every minute
btc:s:haiyang:reject means user haiyang invalid submit share count every minute
btc:p:haiyang means user haiyang valid work every minute

btc:s:haiyang:example  means user haiyang, worker example valid submit share count every minute
btc:s:haiyang:example:reject means user haiyang, worker example invalid submit share count every minute
btc:p:haiyang:example means user haiyang, worker example valid work every minute
  1. System data
  • key format:
<coin>:<type>:<key>

coin: btc
type:
    m: monitor data
    mh: monitor data of spec host

1) type: hash
2) key: unix timestamp, integer
3) value: integer
  • example:
btc:m:pow means the hole mining pool work every minute. use this calculate pool hashrate
btc:mh:47.89.182.198:pow means gateway 47.89.182.198 total work every minute.
  • important key:
btc:m:pow
btc:m:share
btc:m:reject
btc:m:block
btc:m:connections

set key: monitor:keys is a set of all keys
use redis command: SMEMBERS monitor:keys  to get all keys

set key: <coin>:mk:<key> is a set of all host of special key,
example: SMEMBERS btc:mk:pow
1) "192.168.2.17"
2) "192.168.2.18"

Compile and Install

Operating system

Ubuntu 16.04 or Ubuntu 18.04 or Ubuntu 20.04. Not yet tested on other systems.

Requirements

See requirements. Install the mentioned system or library.

You MUST use the depends/hiredis to install the hiredis library. Or it may not be compatible.

Compilation

Compile network and utils first. The rest all are independent.

Deployment

Please do not install every instance on the same machine.

Every process runs in deamon and starts with a watchdog process. It will automatically restart within 1s when crashed.

The best practice of deploying the instance is in the following directory structure:

gateway
|---bin
|   |---gateway.exe
|---log
|   |---gateway.log
|---conf
|   |---config.json
|---shell
|   |---restart.sh
|   |---check_alive.sh
Comments
  • Dynamically link libcurl

    Dynamically link libcurl

    Statically linking curl can be problematic on some platforms, as it may link against a bunch of other libraries that are not required for the mining pool software. This link illustrates more of the issue in general: https://stackoverflow.com/questions/7279764/static-linking-libcurl-using-c

    This patch moves libcurl to be dynamically linked so the associated binaries can be built on Debian 10 (Buster) without pulling in additional dependencies.

    opened by jasonbcox 1
  • requirements details cannot be opened in [Compile and Install]

    requirements details cannot be opened in [Compile and Install]

    Thanks open source for such a great project.

    Could you describe the installation more detail?

    I can not open the requirements link as the follow in README:

    See requirements. Install the mentioned system or library.
    
    opened by ruyichang 1
  • Empty job with out nbits

    Empty job with out nbits

    The bitpeer and poolbench modules, After finding a new block, do not update nbits when initializing empty job, could there be a problem here?

    https://github.com/viabtc/viabtc_mining_server/blob/4891c9ccbadc773919cbb3a53beca1b610fb6543/jobmaster/jm_job.c#L1272-L1276

    If the new block require a change in nbits.

    opened by vay007 0
  • Add support for p2sh coinbase outputs

    Add support for p2sh coinbase outputs

    This adds support for p2sh addresses as coinbase recipients.

    I tested this patch mining on ABC testnet so as to adhere to the 8% miner fund coinbase rule. In my testing, I configured the miner fund address as both main_coin_recipient and as a coin_recipient and they both work as expected. P2PKH was also tested for regressions.

    Although I'm unable to mine on mainnet, I also tested that jobmaster outputs valid coinbase outputs in its logs.

    Since there is no test coverage in the pool software, I highly recommend testing this on BTC and other coins before merging.

    opened by jasonbcox 0
  • Add a flag to optionally disable the segwit commitment

    Add a flag to optionally disable the segwit commitment

    Some nodes, like Bitcoin ABC do not provide default_witness_commitment in getblocktemplate since segwit is not supported. This patch provides an easy way to disable the assumption that a segwit commitment will always be provided. It remains enabled by default in order to be compatible with configurations in the wild.

    I tested this patch with segwit_commitment both enabled and disabled with Bitcoin ABC. Enabled fails as expected and disabled can be used to mine blocks on testnet as expected.

    Given that there is no test coverage for any of the pool software, I highly recommend testing this on BTC and other coins before merging.

    opened by jasonbcox 0
  • Missing http server

    Missing http server

    Hi,

    I am trying to setup this pool server for my home miner and I can't manage to get it working. I am missing "blockmaster_url": "http://127.0.0.1/blockmaster".

    Is it jsonrpc exposed from bitcoind?

    bitcoin-cli help
    == Blockchain ==
    

    Or maybe a service I did not find in this project?

    Thank you and I hope you can help with this.

    opened by bpsvpn 1
Distributed, Encrypted, Fractured File System - A custom distributed file system written in C with FUSE

A custom FUSE-based filesystem that distributes encrypted shards of data across machines on a local network, allowing those files to be accessible from any machine.

Charles Averill 14 Nov 2, 2022
Implementation of popular uncertain frequent subgraph mining algorithms

UFreS Algorithms for mining frequent subgraph patterns from Uncertain Graph Databases. The Datasets Folder contains the datasets used in our empirical

Riddho Ridwanul Haque 2 Nov 3, 2021
High-level build system for distributed, multi-platform C/C++ projects.

fips fips is a highlevel build system wrapper written in Python for C/C++ projects. (this project has nothing to do with the Federal Information Proce

Andre Weissflog 427 Dec 25, 2022
BTCU Wallet is the original Bitcoin Ultimatum client and it builds the backbone of the network.

The concept of BTCU is similar to the concept of the second cryptocurrency by capitalization - Ethereum.

Bitcoin Ultimatum (BTCU) 31 Jul 1, 2022
Bitcoin Core integration/staging tree

Bitcoin is an experimental digital currency that enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate with no central authority: managing transactions and issuing money are carried out collectively by the network. Bitcoin Core is the name of open source software which enables the use of this currency.

Bitcoin 67.6k Jan 4, 2023
Dogecoin is a cryptocurrency like Bitcoin

Dogecoin is a cryptocurrency like Bitcoin, although it does not use SHA256 as its proof of work (POW). Taking development cues from Tenebrix and Litecoin, Dogecoin currently employs a simplified variant of scrypt.

Dogecoin 14.2k Jan 3, 2023
Bitcoin Point of Sale

LNPoS Hardware https://shop.pimoroni.com/products/m5stack-faces-kit-pocket-computer-with-keyboard-game-calculator Installation Install Arduino IDE: ht

Arc 132 Dec 4, 2022
Bitcoin and Altcoins Publickey subtracter

keysubtracter Bitcoin and Altcoins Publickey subtracter Generate multiple but different "copies" of a publickey, Actually Added and substracted public

Luis Alberto 23 Dec 27, 2022
Bitcoin Core integration/staging tree

Bitcoin Core integration/staging tree https://bitcoincore.org For an immediately usable, binary version of the Bitcoin Core software, see https://bitc

Bitcoin Core 47 Dec 22, 2022
Brute Force Bitcoin Private keys, Public keys

Rotor-Cuda This is a modified version of KeyHunt v1.7 by kanhavishva. A lot of gratitude to all the developers whose codes has been used here. Feature

LostCoins 87 Sep 24, 2022
Onix is a decentralized blockchain project built on Bitcoin's UTXO model

What is Onix? Onix is a decentralized blockchain project built on Bitcoin's UTXO model, with support for Ethereum Virtual Machine based smart contract

Onix CryptoCurrency Development 4 Dec 16, 2021
mako - full bitcoin implementation in C

mako - full bitcoin implementation in C

Christopher Jeffrey (JJ) 540 Jan 5, 2023
Small collection of tools written in C for ECC and bitcoin

ecctools Small collection of tools written in C for ECC and bitcoin Why this programs are written in C language? Well i like C language because compil

Luis Alberto 26 Dec 7, 2022
Open-source, airgapped bitcoin hardware signer for the M5StickV.

Krux ✝ Krux is an open-source DIY hardware signer for Bitcoin that can sign for multisignature and single-key wallets. It is a low-cost airgapped devi

Jeff 50 Dec 28, 2022
XMRig is a high performance, open source, cross platform RandomX, KawPow, CryptoNight and AstroBWT unified CPU/GPU miner

XMRig is a high performance, open source, cross platform RandomX, KawPow, CryptoNight and AstroBWT unified CPU/GPU miner and RandomX benchmark. Official binaries are available for Windows, Linux, macOS and FreeBSD.

null 7.3k Jan 9, 2023
A stable nginx module for SSL/TLS ja3 fingerprint, with high performance.

nginx-ssl-fingerprint A stable nginx module for SSL/TLS ja3 fingerprint, with high performance. Description This module adds new nginx variables for t

phuslu 50 Dec 14, 2022
wtf is a distributed, code-coverage guided, customizable, cross-platform snapshot-based fuzzer designed for attacking user and / or kernel-mode targets running on Microsoft Windows.

wtf is a distributed, code-coverage guided, customizable, cross-platform snapshot-based fuzzer designed for attacking user and / or kernel-mode targets running on Microsoft Windows.

Axel Souchet 1.1k Dec 30, 2022
Thread-pool-cpp - High performance C++11 thread pool

thread-pool-cpp It is highly scalable and fast. It is header only. No external dependencies, only standard library needed. It implements both work-ste

Andrey Kubarkov 542 Dec 17, 2022
Decentralized pool for Monero mining

Monero P2Pool Decentralized pool for Monero mining. NOTE This is a highly experimental and untested software. I did some extensive testing locally, bu

null 644 Jan 1, 2023
BabyCoin: mining pool

BabyCoin Pool Based on cryptonote-nodejs-pool cryptonote-nodejs-pool High performance Node.js (with native C addons) mining pool for CryptoNote based

null 1 May 15, 2022