Make donation percentage configurable and default to zero if not set.

This commit is contained in:
Con Kolivas 2023-05-23 16:40:16 +10:00
parent 7f06817e50
commit 5e4079e884
5 changed files with 19 additions and 3 deletions

4
README
View File

@ -224,6 +224,10 @@ new network blocks and is 100 by default. It is intended to be a backup only
for when the notifier is not set up and only polls if the "notify" field is
not set on a btcd.
"donation" : Optional percentage donation of block reward that goes to the
developer of ckpool to assist in further development and maintenance of the
code. Takes a floating point value and defaults to zero if not set.
"nodeserver" : This takes the same format as the serverurl array and specifies
additional IPs/ports to bind to that will accept incoming requests for mining
node communications. It is recommended to selectively isolate this address

View File

@ -19,6 +19,7 @@
"btcaddress" : "14BMjogz69qe8hk9thyzbmR5pg34mVKB1e",
"btcsig" : "/mined by ck/",
"blockpoll" : 100,
"donation" : 2.0,
"nonce1length" : 4,
"nonce2length" : 8,
"update_interval" : 30,

View File

@ -1461,6 +1461,12 @@ static void parse_config(ckpool_t *ckp)
json_get_int64(&ckp->maxdiff, json_conf, "maxdiff");
json_get_string(&ckp->logdir, json_conf, "logdir");
json_get_int(&ckp->maxclients, json_conf, "maxclients");
json_get_double(&ckp->donation, json_conf, "donation");
/* Avoid dust-sized donations */
if (ckp->donation < 0.1)
ckp->donation = 0;
else if (ckp->donation > 99.9)
ckp->donation = 99.9;
arr_val = json_object_get(json_conf, "proxy");
if (arr_val && json_is_array(arr_val)) {
arr_size = json_array_size(arr_val);

View File

@ -246,13 +246,16 @@ struct ckpool_instance {
bool script; // Address is a script address
bool segwit; // Address is a segwit address
char *btcsig; // Optional signature to add to coinbase
bool coinbase_valid; // Coinbase transaction confirmed valid
/* Donation data */
char *donaddress; // Donation address
char *tndonaddress; // Testnet donation address
char *rtdonaddress; // Regtest donation address
bool donscript; // Donation is a script
bool donsegwit; // Donation is segwit
bool donvalid; // Donation address works on this network
bool coinbase_valid; // Coinbase transaction confirmed valid
double donation; // Percentage donation to development
/* Stratum options */
server_instance_t **servers;

View File

@ -598,8 +598,10 @@ static void generate_coinbase(ckpool_t *ckp, workbase_t *wb)
// Generation value
g64 = wb->coinbasevalue;
if (ckp->donvalid) {
d64 = g64 / 50; // 2% donation
if (ckp->donvalid && ckp->donation > 0) {
double dbl64 = (double)g64 / 100 * ckp->donation;
d64 = dbl64;
g64 -= d64; // To guarantee integers add up to the original coinbasevalue
wb->coinb2bin[wb->coinb2len++] = 2 + wb->insert_witness;
} else