yet more debug

This commit is contained in:
Duke Leto
2022-07-01 13:10:30 -04:00
parent 4988ce6f2e
commit a45150eac4
3 changed files with 30 additions and 8 deletions

View File

@@ -1622,13 +1622,13 @@ uint64_t hush_block_subsidy(int height)
// wrapper for more general supply curves of Hush Smart Chains
uint64_t hush_sc_block_subsidy(int nHeight)
{
//fprintf(stderr,"%s: ht.%d\n", __func__, nHeight);
// Find current era, start from beginning reward, and determine current subsidy
int64_t numerator, denominator, subsidy = 0;
int64_t subsidyDifference;
int32_t numhalvings = 0, curEra = 0, sign = 1;
static uint64_t cached_subsidy; static int32_t cached_numhalvings; static int cached_era;
bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false;
fprintf(stderr,"%s: ht=%d ishush3=%d\n", __func__, nHeight, ishush3);
// check for backwards compat, older chains with no explicit rewards had 0.0001 block reward
if ( ASSETCHAINS_ENDSUBSIDY[0] == 0 && ASSETCHAINS_REWARD[0] == 0 ) {
@@ -1649,11 +1649,12 @@ uint64_t hush_sc_block_subsidy(int nHeight)
{
int64_t nStart = curEra ? ASSETCHAINS_ENDSUBSIDY[curEra - 1] : 0;
subsidy = (int64_t)ASSETCHAINS_REWARD[curEra];
if(fDebug)
//if(fDebug)
fprintf(stderr,"%s: nStart.%ld subsidy.%ld curEra.%d\n",__func__,nStart,subsidy,curEra);
if ( subsidy || (curEra != ASSETCHAINS_LASTERA && ASSETCHAINS_REWARD[curEra + 1] != 0) )
{
fprintf(stderr,"%s: subsidy=%ld at height=%d with ASSETCHAINS_HALVING[curEra]=%lu\n",__func__,subsidy,nHeight, ASSETCHAINS_HALVING[curEra]);
if ( ASSETCHAINS_HALVING[curEra] != 0 )
{
if (ishush3) {
@@ -1680,7 +1681,14 @@ uint64_t hush_sc_block_subsidy(int nHeight)
}
denominator = ASSETCHAINS_ENDSUBSIDY[curEra] - nStart;
numerator = denominator - ((ASSETCHAINS_ENDSUBSIDY[curEra] - nHeight) + ((nHeight - nStart) % ASSETCHAINS_HALVING[curEra]));
subsidy = subsidy - sign * ((subsidyDifference * numerator) / denominator);
fprintf(stderr,"%s: numerator=%ld , denominator=%ld at height=%d\n",__func__,numerator, denominator,nHeight);
if( denominator ) {
subsidy = subsidy - sign * ((subsidyDifference * numerator) / denominator);
} else {
fprintf(stderr,"%s: invalid denominator=%ld !\n", __func__, denominator);
fprintf(stderr,"%s: defaulting to 0.0001 subsidy\n",__func__);
subsidy = 10000;
}
} else {
if ( cached_subsidy > 0 && cached_era == curEra && cached_numhalvings == numhalvings ) {
subsidy = cached_subsidy;
@@ -1715,7 +1723,7 @@ uint64_t hush_sc_block_subsidy(int nHeight)
else
subsidy += ASSETCHAINS_SUPPLY * SATOSHIDEN + magicExtra;
}
if(fDebug)
//if(fDebug)
fprintf(stderr,"%s: ht.%d curEra.%d lastEra.%lu subsidy.%ld magicExtra.%u\n",__func__,nHeight,curEra,ASSETCHAINS_LASTERA,subsidy,magicExtra);
return(subsidy);
}