How to start a bare bones stratum server


#1

Please note this is extremely barebones and for people who want to write their own pool software entirely but not the stratum code. If you want a fully featured pool, use https://github.com/z-classic/z-nomp instead

To get started, do npm install z-classic/node-stratum-pool
This will install the stratum software.

After that, create a new file called index.js and put this code into it:

var Stratum = require('stratum-pool');

var zen = {
    "name": "zencash",
    "symbol": "zen",
    "algorithm": "equihash",
    "payFoundersReward": true,
    "percentFoundersReward": 8.5,
    "maxFoundersRewardBlockHeight": 839999,
    "foundersRewardAddressChangeInterval": 17500,
    "vFoundersRewardAddress": [
        "zssEdGnZCQ9G86LZFtbynMn1hYTVhn6eYCL",
       "zsrCsXXmUf8k59NLasEKfxA7us3iNvaPATz",
       "zsnLPsWMXW2s4w9EmFSwtSLRxL2LhPcfdby",
       "zshdovbcPfUAfkPeEE2qLbKnoue9RsbVokU",
       "zsqmq97JAKCCBFRGvxgv6FiJgQLCZBDp62S",
       "zskyFVFA7VRYX8EGdXmYN75WaBB25FmiL3g",
       "zsmncLmwEUdVmAGPUrUnNKmPGXyej7mbmdM",
       "zsfa9VVJCEdjfPbku4XrFcRR8kTDm2T64rz",
       "zsjdMnfWuFi46VeN2HSXVQWEGsnGHgVxayY",
       "zseb8wRQ8rZ722oLX5B8rx7qwZiBRb9mdig",
       "zsjxkovhqiMVggoW7jvSRi3NTSD3a6b6qfd",
       "zsokCCSU3wvZrS2G6mEDpJ5cH49E7sDyNr1",
       "zt12EsFgkABHLMRXA7JNnpMqLrxsgCLnVEV",
       "zt39mvuG9gDTHX8A8Qk45rbk3dSdQoJ8ZAv",
       "zssTQZs5YxDGijKC86dvcDxzWogWcK7n5AK",
       "zsywuMoQK7Bved2nrXs56AEtWBhpb88rMzS",
       "zsxVS2w7h1fHFX2nQtGm4372pd4DSHzq9ee",
       "zsupGi7ro3uC8CEVwm9r7vrdVUZaXQnHF6T",
       "zshVZvW47dA5AB3Sqk1h7ytwWJeUJUJxxaE",
       "zsubBCjvDx252MKFsL4Dcf5rJU9Z9Upqr1N",
       "zsweaST3NcU4hfgkVULfCsfEq41pjgMDgcW",
       "zswz6Rxb1S33fUpftETZwtGiVSeYxNKq2xc",
       "zswnpHtiBbrvYDzbhPQshkgvLSfYhDMRJ4S",
       "zsjSYAWaEYj35Ht7aXrRJUGY6Dc8qCmgYqu",
       "zsvMv8fGroWR8epbSiGDCJHmfe6ec2uFQrt",
       "zsujxCT56BExQDAwKwktBjtnopYnw8BiKbg",
       "zsxeXc2FTAzmUmeZmqVsKVdwTMSvzyns4rT",
       "zsuLqgABNudD8bVPbVGeUjGqapuoXp68i7F",
       "zsoc39J1dCFK1U8kckZznvQkv8As7sajYLz",
       "zt21NFdu1KRPJ7VRKtrWugM2Jqe5ePNmU4T",
       "zsp15qbVcbx9ifcjKe6XZEJTvzsFUZ2BHLT",
       "zso2KvqH6yxLQEYggHdmfL3Tcd5V6E9tqhp",
       "zsnFG2W5ZHRYh3QucNze4mp31tBkemtfxdj",
       "zsex2CGJtxHyHbpLXm7kESBmp3vWRqUkJMy",
       "zsvtFv96nrgrXKUbtNe2BpCt8aQEp5oJ7F8",
       "zsk5KitThmhK9KBa1KDybPgEmGSFTHzhMVA",
       "zsuy4n48c4NsJyaCZEzwdAKULM1FqbB6Y4z",
       "zsgtQVMpX2zNMLvHHG2NDwfqKoaebvVectJ",
       "zszQqXRSPGdqsWw4iaMTNN6aJz4JjEzSdCF",
       "zst6dBLrTtaMQBX7BLMNjKLTGcP11PBmgTV",
       "zshD9r6Eb6dZGdzYW2HCb9CzkMokCT1NGJR",
       "zswUaj1TboEGmvSfF7fdoxWyH3RMx7MBHHo",
       "zsv8s4Poi5GxCsbBrRJ97Vsvazp84nrz5AN",
       "zsmmxrKU6dqWFwUKow1iyovg3gxrgXpEivr",
       "zskh1221aRC9WEfb5a59WxffeW34McmZZsw",
       "zssAhuj57NnVm4yNFT6o8muRctABkUaBu3L",
       "zsi5Yr4Z8HwBvdBqQE8gk7ahExDu95J4oqZ",
       "zsy6ryEaxfk8emJ8bGVB7tmwRwBL8cfSqBW"
    ]
};  

var pool = Stratum.createPool({

    "coin": zen,

    "address": "mi4iBXbBsydtcc5yFmsff2zCFVX4XG7qJc", 

    "rewardRecipients": {
        "n37vuNFkXfk15uFnGoVyHZ6PYQxppD3QqK": 1.5, //1.5% goes to pool op
        "mirj3LtZxbSTharhtXvotqtJXUY7ki5qfx": 0.5, //0.5% goes to a pool co-owner
    },

    "blockRefreshInterval": 1000, //How often to poll RPC daemons for new blocks, in milliseconds

    "jobRebroadcastTimeout": 55,

    "connectionTimeout": 600, //Remove workers that haven't been in contact for this many seconds

    "emitInvalidBlockHashes": false,

    /* Enable for client IP addresses to be detected when using a load balancer with TCP proxy
       protocol enabled, such as HAProxy with 'send-proxy' param:
       http://haproxy.1wt.eu/download/1.5/doc/configuration.txt */
    "tcpProxyProtocol": false,

    /* If a worker is submitting a high threshold of invalid shares we can temporarily ban their IP
       to reduce system/network load. Also useful to fight against flooding attacks. If running
       behind something like HAProxy be sure to enable 'tcpProxyProtocol', otherwise you'll end up
       banning your own IP address (and therefore all workers). */
    "banning": {
        "enabled": true,
        "time": 600, //How many seconds to ban worker for
        "invalidPercent": 50, //What percent of invalid shares triggers ban
        "checkThreshold": 500, //Check invalid percent when this many shares have been submitted
        "purgeInterval": 300 //Every this many seconds clear out the list of old bans
    },

    /* Each pool can have as many ports for your miners to connect to as you wish. Each port can
       be configured to use its own pool difficulty and variable difficulty settings. varDiff is
       optional and will only be used for the ports you configure it for. */
       
       //1 Diff is 8192 network. IE: .5 diff is actually 4096. 2 diff is 16384
       
    "ports": {
        "3032": { //A port for your miners to connect to
            "diff": 0.125, //the pool difficulty for this port

            /* Variable difficulty is a feature that will automatically adjust difficulty for
               individual miners based on their hashrate in order to lower networking overhead */
            "varDiff": {
                "minDiff": 0.125, //Minimum difficulty
                "maxDiff": 512, //Network difficulty will be used if it is lower than this
                "targetTime": 15, //Try to get 1 share per this many seconds
                "retargetTime": 90, //Check to see if we should retarget every this many seconds
                "variancePercent": 30 //Allow time to very this % from target without retargeting
            }
        },
        "3256": { //Another port for your miners to connect to, this port does not use varDiff
            "diff": 256 //The pool difficulty
        }
    },

    "daemons": [
        {   //Main daemon instance
            "host": "127.0.0.1",
            "port": 19332,
            "user": "node1",
            "password": "testnet"
        },
        {   //Backup daemon instance
            "host": "127.0.0.1",
            "port": 19344,
            "user": "node2",
            "password": "testnet"
        }
    ],


    /* This allows the pool to connect to the daemon as a node peer to receive block updates.
       It may be the most efficient way to get block updates (faster than polling, less
       intensive than blocknotify script). It requires the additional field "peerMagic" in
       the coin config. */
    "p2p": {
        "enabled": false,

        /* Host for daemon */
        "host": "127.0.0.1",

        /* Port configured for daemon (this is the actual peer port not RPC port) */
        "port": 19333,

        /* If your coin daemon is new enough (i.e. not a shitcoin) then it will support a p2p
           feature that prevents the daemon from spamming our peer node with unnecessary
           transaction data. Assume its supported but if you have problems try disabling it. */
        "disableTransactions": true

    }

}, function(ip, port , workerName, password, callback){ //stratum authorization function
    console.log("Authorize " + workerName + ":" + password + "@" + ip);
    callback({
        error: null,
        authorized: true,
        disconnect: false
    });
});

pool.on('share', function(isValidShare, isValidBlock, data){

    if (isValidBlock)
        console.log('Block found');
    else if (isValidShare)
        console.log('Valid share submitted');
    else if (data.blockHash)
        console.log('We thought a block was found but it was rejected by the daemon');
    else
        console.log('Invalid share submitted')
});



/*
'severity': can be 'debug', 'warning', 'error'
'logKey':   can be 'system' or 'client' indicating if the error
            was caused by our system or a stratum client
*/
pool.on('log', function(severity, logKey, logText){
    console.log(severity + ': ' + '[' + logKey + '] ' + logText);
});

pool.start();

Start it with node index.js

This will start a stratum server that you can submit shares to and hopefully find blocks with, nothing else, nothing more.


How to build Private or Public pool for ZENCASH?
#2

Hello,
thank you for share this guide,