From 2ea974a402cdd80357145ccecaf1197faeba7825 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 18 Sep 2020 17:15:51 -0400 Subject: [PATCH 1/4] Update comments --- src/komodo_bitcoind.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e8eadbd09..69d4859af 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1261,10 +1261,10 @@ uint64_t hush_commission(int height) if( height > HALVING1) { // Block time going from 150s to 75s (half) means the interval between halvings // must be twice as often, i.e. 840000*2=1680000 - // 840000 is 4 years worth of 150s blocks + // 840000 is ~4 years worth of 150s blocks // With 150s blocks, we have 210,000 blocks per year // With 75s blocks, we have 420,000 blocks per year - INTERVAL = GetArg("-ac_halving2",1680000); // 4 years worth of 75s blocks + INTERVAL = GetArg("-ac_halving2",1680000); // ~4 years worth of 75s blocks fprintf(stderr,"%s: height=%d increasing interval to %d\n", __func__, height, INTERVAL); } @@ -1286,10 +1286,8 @@ uint64_t hush_commission(int height) } else if (height < HALVING1+6*INTERVAL) { // before 7th Halving @ Block 10420000 commission = commisions[6]; } else if (height < HALVING1+7*INTERVAL) { // before 8th Halving @ Block 12100000 - // TODO: Still true??? Block reward will go to zero between 7th+8th halvings, ac_end may need adjusting commission = commisions[7]; } else if (height < HALVING1+8*INTERVAL) { // before 9th Halving @ Block 13780000 - // BR should be zero before this halving happens commission = commisions[8]; } // Explicitly set the last block reward From 599c8420965f5f9e7f2fe2235baeddc16f714562 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 18 Sep 2020 17:50:04 -0400 Subject: [PATCH 2/4] WIP full supply curve --- src/komodo_bitcoind.h | 122 +++++++++++++++++++++++++++++++++--------- src/komodo_utils.h | 13 +++-- 2 files changed, 103 insertions(+), 32 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 69d4859af..c7aad1778 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1248,12 +1248,6 @@ uint64_t hush_commission(int height) // BR_END is the 31st halving int32_t starting_commission = 125000000, HALVING1 = GetArg("-z2zheight",340000), INTERVAL = GetArg("-ac_halving1",840000), TRANSITION = 129, BR_END = 50740000; - int32_t commisions[] = {starting_commission, 31250000, 15625000, 78125000, 39062500, 19531250, 9765625, // these are exact - 4882812, 2441406, 1220703, 610351 // these have deviation from ideal BR - // 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 - }; uint64_t commission = 0; //TODO: Likely a bug hiding here or at the next halving :) @@ -1267,29 +1261,107 @@ 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 +*/ + - // Transition period of 128 blocks has BR=FR=0 if (height < TRANSITION) { commission = 0; - } else if (height < HALVING1) { // before 1st Halving @ Block 340000 (Nov 2020) - commission = commisions[0]; - } else if (height < HALVING1+1*INTERVAL) { // before 2nd Halving @ Block 2020000 - commission = commisions[1]; - } else if (height < HALVING1+2*INTERVAL) { // before 3rd Halving @ Block 3700000 - commission = commisions[2]; - } else if (height < HALVING1+3*INTERVAL) { // before 4th Halving @ Block 5380000 - commission = commisions[3]; - } else if (height < HALVING1+4*INTERVAL) { // before 5th Halving @ Block 7060000 - commission = commisions[4]; - } else if (height < HALVING1+5*INTERVAL) { // before 6th Halving @ Block 8740000 - commission = commisions[5]; - } else if (height < HALVING1+6*INTERVAL) { // before 7th Halving @ Block 10420000 - commission = commisions[6]; - } else if (height < HALVING1+7*INTERVAL) { // before 8th Halving @ Block 12100000 - commission = commisions[7]; - } else if (height < HALVING1+8*INTERVAL) { // before 9th Halving @ Block 13780000 - commission = commisions[8]; + } 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 + if (height < HALVING1) { // before 1st Halving @ Block 340000 (Nov 2020) + commission = starting_commission; + } else if (height < 2020000 ) { + commission = 312500000; + } else if (height < 3700000 ) { + commission = 156250000; + } else if (height < 5380000 ) { + commission = 78125000; + } else if (height < 7060000 ) { + commission = 39062500; + } else if (height < 8740000 ) { + commission = 19531250; + } else if (height < 10420000) { + commission = 9765625; + } else if (height < 12100000) { + commission = 488281; + } else if (height < 15460000) { + commission = 244140; + } else if (height < 17140000) { + commission = 122070; + } else if (height < 18820000) { + commission = 61035; + } else if (height < 23860000) { + commission = 30517; + } else if (height < 23860000) { + commission = 15258; + } else if (height < 25540000) { + commission = 7629; + } else if (height < 27220000) { + commission = 3814; + } else if (height < 27220000) { + commission = 1907; + } else if (height < 28900000) { + commission = 953; + } else if (height < 30580000) { + commission = 476; + } else if (height < 32260000) { + commission = 238; + } else if (height < 33940000) { + commission = 119; + } else if (height < 35620000) { + commission = 59; + } else if (height < 37300000) { + commission = 29; + } else if (height < 38980000) { + commission = 14; + } else if (height < 40660000) { + commission = 7; + } else if (height < 42340000) { + commission = 3; + } else if (height < 44020000) { + commission = 1; + } else if (height < 45700000) { + commission = 0; + } else if (height < 47380000) { + commission = 0; + } else if (height < 49060000) { + commission = 0; + } else if (height < 50740000) { + commission = 0; + } else { + 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 diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e1449c170..392875dbc 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1543,18 +1543,17 @@ uint64_t komodo_max_money() // This implements the Hush Emission Curve -uint64_t hush_block_subsidy(int nHeight) +uint64_t hush_block_subsidy(int height) { uint64_t subsidy=0; //TODO: Cover all halvings until BR=0 - //if (nHeight >= 3700000) { - // subsidy = ASSETCHAINS_REWARD[4]; - //} else - if (nHeight >= 2020000) { + if (nHeight >= 3700000) { + subsidy = -1; + } else if (height >= 2020000) { subsidy = 140625000; - } else if (nHeight >= GetArg("-z2zheight",340000)) { + } else if (height >= GetArg("-z2zheight",340000)) { subsidy = 281250000; - } else if (nHeight >= 128) { + } else if (height >= 128) { subsidy = 1125000000; } return subsidy; From 65da80de5860ef56f18ba2a8b7e47e1357114e01 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 19 Sep 2020 11:03:35 -0400 Subject: [PATCH 3/4] Implement entire Hush block subsidy schedule We now have our halving schedule implemented until the BR goes to zero. The data was calculated via two new scripts which are in ./contrib : $ ./contrib/hush_halvings 1,12500000000,340000 2,312500000,2020000 3,156250000,3700000 4,78125000,5380000 5,39062500,7060000 6,19531250,8740000 7,9765625,10420000 8,4882812,12100000 9,2441406,13780000 10,1220703,15460000 11,610351,17140000 12,305175,18820000 13,152587,20500000 14,76293,22180000 15,38146,23860000 16,19073,25540000 17,9536,27220000 18,4768,28900000 19,2384,30580000 20,1192,32260000 21,596,33940000 22,298,35620000 23,149,37300000 24,74,38980000 25,37,40660000 26,18,42340000 27,9,44020000 28,4,45700000 29,2,47380000 30,1,49060000 31,0,50740000 32,0,52420000 33,0,54100000 $ ./contrib/hush_block_subsidy_per_halving 0,1250000000,1125000000,125000000 1,625000000,562500000,62500000 2,312500000,281250000,31250000 3,156250000,140625000,15625000 4,78125000,70312500,7812500 5,39062500,35156250,3906250 6,19531250,17578125,1953125 7,9765625,8789062,976562 8,4882812,4394531,488281 9,2441406,2197265,244140 10,1220703,1098632,122070 11,610351,549316,61035 12,305175,274658,30517 13,152587,137329,15258 14,76293,68664,7629 15,38146,34332,3814 16,19073,17166,1907 17,9536,8583,953 18,4768,4291,476 19,2384,2145,238 20,1192,1072,119 21,596,536,59 22,298,268,29 23,149,134,14 24,74,67,7 25,37,33,3 26,18,16,1 27,9,8,0 28,4,4,0 29,2,2,0 30,1,1,0 31,0,0,0 These show that the block subsidy for miners goes to 0 at the 31st halving and that the Founders Reward AKA Dev Tax goes to 0 at the 27th halving. There is also some current KMD internals code that we inherited that prevents the FR from being less than 10000, so that code would currently set our FR to 0 at the 14th halving and lead less HUSH being mined than the planned 21M and even a bit less than the amount under 21M that normally happens, such as in BTC. We have some time to deal with the bug, since halving 14 is in about 52 years. --- contrib/hush_block_subsidy_per_halving | 17 +++++ contrib/hush_halvings | 22 ++++++ src/komodo_bitcoind.h | 60 +++++----------- src/komodo_utils.h | 94 +++++++++++++++++++++++--- 4 files changed, 138 insertions(+), 55 deletions(-) create mode 100755 contrib/hush_block_subsidy_per_halving create mode 100755 contrib/hush_halvings 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; } From 9e288d185b069b3a0cac13c9850a4f9613772860 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 19 Sep 2020 12:17:26 -0400 Subject: [PATCH 4/4] Define the halving interval, initial transition period and fix format string bug --- src/komodo_utils.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f134e9957..9cf26d6ba 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1549,7 +1549,10 @@ uint64_t komodo_max_money() uint64_t hush_block_subsidy(int height) { uint64_t subsidy = 0; - int32_t HALVING1 = GetArg("-z2zheight",340000), + int32_t HALVING1 = GetArg("-z2zheight",340000); + //TODO: support INTERVAL :( + //int32_t INTERVAL = GetArg("-ac_halving1",840000); + int32_t TRANSITION = 129; if (height < TRANSITION) { if(fDebug) @@ -1627,7 +1630,7 @@ uint64_t hush_block_subsidy(int height) } } if(fDebug) - fprintf(stderr,"%s: subsidy=%ul at height=%d\n",__func__,subsidy,height); + fprintf(stderr,"%s: subsidy=%lu at height=%d\n",__func__,subsidy,height); return subsidy; }