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);
}

View File

@@ -2359,6 +2359,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW)
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
fprintf(stderr,"%s: nHeight=%d\n", __func__, nHeight);
return hush_sc_block_subsidy(nHeight);
}

View File

@@ -178,6 +178,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
if ( gpucount < 0 )
gpucount = HUSH_MAXGPUCOUNT;
std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
fprintf(stderr,"%s: created new block template\n", __func__);
if(!pblocktemplate.get())
{
fprintf(stderr,"%s: pblocktemplate.get() failure\n", __func__);
@@ -193,6 +194,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
pblock->vtx.push_back(CTransaction());
pblocktemplate->vTxFees.push_back(-1); // updated at end
pblocktemplate->vTxSigOps.push_back(-1); // updated at end
fprintf(stderr,"%s: added dummy coinbase\n", __func__);
// Largest block you're willing to create:
unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1));
@@ -208,6 +210,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
// until there are no more or the block reaches this size:
unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
fprintf(stderr,"%s: nBlockMaxSize=%u, nBlockPrioritySize=%u, nBlockMinSize=%u\n", __func__, nBlockMaxSize, nBlockPrioritySize, nBlockMinSize);
// Collect memory pool transactions into the block
CAmount nFees = 0;
@@ -230,7 +234,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
uint32_t proposedTime = GetTime();
fprintf(stderr,"%s: nHeight=%d, consensusBranchId=%u, proposedTime=%u\n", __func__, nHeight, consensusBranchId, proposedTime);
voutsum = GetBlockSubsidy(nHeight,consensusParams) + 10000*COIN; // approx fees
fprintf(stderr,"%s: voutsum=%lu\n", __func__, voutsum);
if (proposedTime == nMedianTimePast)
{
@@ -267,6 +275,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
vector<TxPriority> vecPriority;
vecPriority.reserve(mempool.mapTx.size() + 1);
fprintf(stderr,"%s: going to add txs from mempool\n", __func__);
// now add transactions from the mem pool
int32_t Notarizations = 0; uint64_t txvalue;
for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin();
@@ -280,7 +289,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight))
{
//fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight));
fprintf(stderr,"%s: coinbase.%d finaltx.%d expired.%d\n",__func__, tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight));
continue;
}
txvalue = tx.GetValueOut();
@@ -449,6 +458,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
// Size limits
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
fprintf(stderr,"%s: nTxSize = %u\n", __func__, nTxSize);
// Opret spam limits
if (mapArgs.count("-opretmintxfee"))
@@ -485,7 +495,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx
{
//fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize);
fprintf(stderr,"%s: nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",__func__, (int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize);
continue;
}
@@ -496,6 +506,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
//fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS);
continue;
}
fprintf(stderr,"%s: looking to see if we need to skip any fee=0 txs\n", __func__);
// Skip free transactions if we're past the minimum block size:
const uint256& hash = tx.GetHash();
double dPriorityDelta = 0;
@@ -503,7 +516,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
{
//fprintf(stderr,"fee rate skip\n");
fprintf(stderr,"%s: fee rate skip\n", __func__);
continue;
}
// Prioritize by fee once past the priority size or we run out of high-priority transactions
@@ -535,7 +548,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
PrecomputedTransactionData txdata(tx);
if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId))
{
//fprintf(stderr,"context failure\n");
fprintf(stderr,"%s: ContextualCheckInputs failure\n",__func__);
continue;
}
UpdateCoins(tx, view, nHeight);