diff --git a/contrib/hush_block_subsidy_per_halving b/contrib/hush_block_subsidy_per_halving new file mode 100755 index 000000000..7e7b05b4b --- /dev/null +++ b/contrib/hush_block_subsidy_per_halving @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +# Copyright 2019-2020 The Hush developers +# Released under the GPLv3 + +use strict; +use warnings; + +my $x = 12.5 * 100000000; +my $n = 0; +while ($n<=31) { + #printf "$n,%.16g,%.16g,%.16g\n", $x, $x*0.90, $x*0.1; + printf "$n,%d,%d,%d\n", $x, $x*0.90, $x*0.1; + $x = $x / 2; + $n++; + exit if ($x <= 0); +} + diff --git a/contrib/hush_halvings b/contrib/hush_halvings new file mode 100755 index 000000000..67246bb13 --- /dev/null +++ b/contrib/hush_halvings @@ -0,0 +1,22 @@ +#!/usr/bin/env perl +# Copyright 2019-2020 The Hush developers +# Released under the GPLv3 + +use strict; +use warnings; + +my $x = 340_000; +my $n = 0; +my $r = 12_500_000_000; +while ($n<=32) { + printf "%d,%d,%d\n", $n+1, $r, $x + 1680000*$n; + # blocktime halving at block 340000 + if ($n==0) { + $r = 3.125 * 100_000_000; + } else { + $r /= 2; + } + + $n++; +} + diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c7aad1778..76e075bd6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1241,7 +1241,8 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams); // You specify the BR, and the FR % gets added so 10% of 12.5 is 1.25 // but to tell the AC params, I need to say "11% of 11.25" is 1.25 // 11% ie. 1/9th cannot be exactly represented and so the FR has tiny amounts of error unless done manually -// Do not change this code unless you really know what you are doing. +// This must be kept in sync with hush_block_subsidy() in komoto_utils.h! +// Changing these functions are consensus changes! // Here Be Dragons! -- Duke Leto uint64_t hush_commission(int height) { @@ -1261,56 +1262,28 @@ uint64_t hush_commission(int height) INTERVAL = GetArg("-ac_halving2",1680000); // ~4 years worth of 75s blocks fprintf(stderr,"%s: height=%d increasing interval to %d\n", __func__, height, INTERVAL); } -/* -0,1250000000,1125000000,125000000 -1,312500000,281250000,31250000 -2,156250000,140625000,15625000 -3,78125000,70312500,7812500 -4,39062500,35156250,3906250 -5,19531250,17578125,1953125 -6,9765625,8789062,976562 -7,4882812,4394531,488281 -8,2441406,2197265,244140 -9,1220703,1098632,122070 -10,610351,549316,61035 -11,305175,274658,30517 -12,152587,137329,15258 -13,76293,68664,7629 -14,38146,34332,3814 -15,19073,17166,1907 -16,9536,8583,953 -17,4768,4291,476 -18,2384,2145,238 -19,1192,1072,119 -20,596,536,59 -21,298,268,29 -22,149,134,14 -23,74,67,7 -24,37,33,3 -25,18,16,1 -*/ - if (height < TRANSITION) { commission = 0; } else { // Just like BTC, BRs in the far future will be slightly less than // they should be because exact values are not integers, causing - // slightly less coins to be actually mined + // slightly less coins to be actually mined and small deviations + // to the ideal FR/devtax if (height < HALVING1) { // before 1st Halving @ Block 340000 (Nov 2020) commission = starting_commission; } else if (height < 2020000 ) { - commission = 312500000; + commission = 31250000; } else if (height < 3700000 ) { - commission = 156250000; + commission = 15625000; } else if (height < 5380000 ) { - commission = 78125000; + commission = 7812500; } else if (height < 7060000 ) { - commission = 39062500; + commission = 3906250; } else if (height < 8740000 ) { - commission = 19531250; + commission = 1953125; } else if (height < 10420000) { - commission = 9765625; + commission = 976562; // 0.5 puposhi deviation, all further BRs have deviation from ideal } else if (height < 12100000) { commission = 488281; } else if (height < 15460000) { @@ -1350,25 +1323,24 @@ uint64_t hush_commission(int height) } else if (height < 44020000) { commission = 1; } else if (height < 45700000) { + // FR goes to zero at Halving 26 commission = 0; } else if (height < 47380000) { + // FR still zero at Halving 27 commission = 0; } else if (height < 49060000) { + // FR still zero at Halving 28 commission = 0; } else if (height < 50740000) { + // FR still zero at Halving 29 commission = 0; } else { + // enforce FR=0 for all other heights + // This over-rides the -ac_end param via HUSH3 cli args commission = 0; } } - // Explicitly set the last block reward - // BR_END is the block with first zero block reward, which overrides - // the -ac_end param on HUSH3 - if(height >= BR_END) { - fprintf(stderr,"%s: HUSH block reward has gone to zero at height %d!!! It was a good run folks\n", __func__, height); - commission = 0; - } if(fDebug) fprintf(stderr,"%s: commission=%lu,interval=%d at height %d\n", __func__, commission, INTERVAL, height); return commission; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 392875dbc..f134e9957 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1542,20 +1542,92 @@ uint64_t komodo_max_money() } -// This implements the Hush Emission Curve +// This implements the Hush Emission Curve, the miner subsidy part, +// and must be kept in sync with hush_commision() in komoto_bitcoind.h! +// Changing these functions are consensus changes! +// Here Be Dragons! -- Duke Leto uint64_t hush_block_subsidy(int height) { - uint64_t subsidy=0; - //TODO: Cover all halvings until BR=0 - if (nHeight >= 3700000) { - subsidy = -1; - } else if (height >= 2020000) { - subsidy = 140625000; - } else if (height >= GetArg("-z2zheight",340000)) { - subsidy = 281250000; - } else if (height >= 128) { - subsidy = 1125000000; + uint64_t subsidy = 0; + int32_t HALVING1 = GetArg("-z2zheight",340000), + + if (height < TRANSITION) { + if(fDebug) + fprintf(stderr,"%s: setting subsidy=0 during transition at height=%d\n",__func__, height); + subsidy = 0; + } else { + // Just like BTC, BRs in the far future will be slightly less than + // they should be because exact values are not integers, causing + // slightly less coins to be actually mined and small deviations + // to the ideal FR/devtax + if (height < HALVING1) { // before 1st Halving @ Block 340000 (Nov 2020) + subsidy = 1125000000; + } else if (height < 2020000 ) { + subsidy = 281250000; + } else if (height < 3700000 ) { + subsidy = 140625000; + } else if (height < 5380000 ) { + subsidy = 70312500; + } else if (height < 7060000 ) { + subsidy = 35156250; + } else if (height < 8740000 ) { + subsidy = 17578125; + } else if (height < 10420000) { + subsidy = 8789062; + } else if (height < 12100000) { + subsidy = 4394531; + } else if (height < 15460000) { + subsidy = 2197265; + } else if (height < 17140000) { + subsidy = 1098632; + } else if (height < 18820000) { + subsidy = 549316; + } else if (height < 23860000) { + subsidy = 274658; + } else if (height < 23860000) { + subsidy = 137329; + } else if (height < 25540000) { + subsidy = 68664; + } else if (height < 27220000) { + subsidy = 34332; + } else if (height < 27220000) { + subsidy = 17166; + } else if (height < 28900000) { + subsidy = 8583; + } else if (height < 30580000) { + subsidy = 4291; + } else if (height < 32260000) { + subsidy = 2145; + } else if (height < 33940000) { + subsidy = 1072; + } else if (height < 35620000) { + subsidy = 536; + } else if (height < 37300000) { + subsidy = 268; + } else if (height < 38980000) { + subsidy = 134; + } else if (height < 40660000) { + subsidy = 67; + } else if (height < 42340000) { + subsidy = 33; + } else if (height < 44020000) { + subsidy = 16; + } else if (height < 45700000) { + subsidy = 8; + } else if (height < 47380000) { + subsidy = 4; + } else if (height < 49060000) { + subsidy = 2; + } else if (height < 50740000) { + subsidy = 1; + } else { + // HUSH Block Reward rounds down to 0 at Block 50740000 which is the 31st halving + // because Bitcoin/Zcash/Hush internals don't support 0.5 sat block reward yet ;) + subsidy = 0; + } } + if(fDebug) + fprintf(stderr,"%s: subsidy=%ul at height=%d\n",__func__,subsidy,height); return subsidy; }