Skip to content

Simple Example of CPPSRB payout for NodeJS/Mining Pools

Notifications You must be signed in to change notification settings

cbunting99/cppsrb-example-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPPSRB Mining Pool Payout System

Overview

This is a commercial-grade implementation of the Capped Pay-Per-Share with Recent Backpay (CPPSRB) algorithm for cryptocurrency mining pools. The system provides a robust and fair payout mechanism while maintaining pool financial stability.

Features

  • Capped Payouts: Limits the pool's liability per share
  • Recent Backpay: Rewards miners for recent shares even if they haven't found a block
  • Proportional Distribution: Pays miners based on their share contributions
  • Pool Protection: Prevents overpayment during high variance periods

Technology Stack

  • Runtime: Node.js
  • Web Framework: Express.js
  • Database: SQLite
  • Logging: Winston
  • Validation: Joi
  • Testing: Jest + Supertest
  • Linting: ESLint (Airbnb style)
  • Formatting: Prettier

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/cpprb-pool.git
    cd cpprb-pool
  2. Install dependencies:

    npm install
  3. Configure the application (see Configuration section)

  4. Start the server:

    npm start

Configuration

Configuration is managed through config/default.json:

{
  "server": {
    "port": 3000,
    "rateLimit": {
      "windowMs": 900000,
      "max": 100
    }
  },
  "logging": {
    "level": "info",
    "file": "logs/application.log"
  },
  "database": {
    "file": "data/cpprb.db"
  },
  "cpprb": {
    "capPerShare": 0.01,  // Maximum payout per share
    "backpayWindow": 3600 // Backpay window in seconds (1 hour)
  }
}

API Documentation

POST /api/v1/payouts/calculate

Calculate payouts using CPPSRB method

Request Body:

{
  "blockReward": 100,
  "shares": [
    { "miner": "Alice", "shares": 50 },
    { "miner": "Bob", "shares": 30 }
  ]
}

Response:

{
  "success": true,
  "data": {
    "totalShares": 80,
    "payouts": [
      {
        "miner": "Alice",
        "shares": 50,
        "cappedPayout": 0.5,
        "backpay": 0.2,
        "totalPayout": 0.7
      },
      {
        "miner": "Bob",
        "shares": 30,
        "cappedPayout": 0.3,
        "backpay": 0.1,
        "totalPayout": 0.4
      }
    ],
    "parameters": {
      "capPerShare": 0.01,
      "backpayWindow": 3600
    }
  }
}

Testing

Run unit tests:

npm test

Run linting:

npm run lint

Run formatting:

npm run format

Database Schema

Miners Table

Column Type Description
id TEXT Miner identifier (PK)
balance REAL Current balance
total_shares REAL Total shares submitted
total_payouts REAL Total payouts received

Shares Table

Column Type Description
id INTEGER Auto-incrementing ID (PK)
miner_id TEXT Miner identifier (FK)
shares REAL Number of shares submitted
timestamp DATETIME When shares were recorded

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Chris Bunting - [email protected]

Project Link: https://github.com/yourusername/cpprb-pool

About

Simple Example of CPPSRB payout for NodeJS/Mining Pools

Resources

Stars

Watchers

Forks