@ -134,7 +134,7 @@ namespace {
// First sort by most total work, ...
if ( pa - > chainPower > pb - > chainPower ) return false ;
if ( pa - > chainPower < pb - > chainPower ) return true ;
// ... then by earliest time received, ...
if ( pa - > nSequenceId < pb - > nSequenceId ) return false ;
if ( pa - > nSequenceId > pb - > nSequenceId ) return true ;
@ -469,7 +469,7 @@ namespace {
// Make sure pindexBestKnownBlock is up to date, we'll need it.
ProcessBlockAvailability ( nodeid ) ;
if ( state - > pindexBestKnownBlock = = NULL | | state - > pindexBestKnownBlock - > chainPower < chainActive . Tip ( ) - > chainPower ) {
// This peer has nothing interesting.
return ;
@ -961,13 +961,13 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
bool ContextualCheckCoinbaseTransaction ( const CTransaction & tx , const int nHeight )
{
// if time locks are on, ensure that this coin base is time locked exactly as it should be
if ( ( ( uint64_t ) ( tx . GetValueOut ( ) ) > = ASSETCHAINS_TIMELOCKGTE ) | |
if ( ( ( uint64_t ) ( tx . GetValueOut ( ) ) > = ASSETCHAINS_TIMELOCKGTE ) | |
( ( ( nHeight > = 31680 ) | | strcmp ( ASSETCHAINS_SYMBOL , " VRSC " ) ! = 0 ) & & komodo_ac_block_subsidy ( nHeight ) > = ASSETCHAINS_TIMELOCKGTE ) )
{
CScriptID scriptHash ;
// to be valid, it must be a P2SH transaction and have an op_return in vout[1] that
// holds the full output script, which may include multisig, etc., but starts with
// to be valid, it must be a P2SH transaction and have an op_return in vout[1] that
// holds the full output script, which may include multisig, etc., but starts with
// the time lock verify of the correct time lock for this block height
if ( tx . vout . size ( ) = = 2 & &
CScriptExt ( tx . vout [ 0 ] . scriptPubKey ) . IsPayToScriptHash ( & scriptHash ) & &
@ -1020,10 +1020,9 @@ bool ContextualCheckTransaction(
// If Sprout rules apply, reject transactions which are intended for Overwinter and beyond
if ( isSprout & & tx . fOverwintered ) {
return state . DoS ( isInitBlockDownload ( ) ? 0 : dosLevel ,
error ( " ContextualCheckTransaction(): ht.%d activates.%d dosLevel.%d overwinter is not active yet " ,
nHeight , Params ( ) . GetConsensus ( ) . vUpgrades [ Consensus : : UPGRADE_OVERWINTER ] . nActivationHeight , dosLevel ) ,
REJECT_INVALID , " tx-overwinter-not-active " ) ;
int32_t ht = Params ( ) . GetConsensus ( ) . vUpgrades [ Consensus : : UPGRADE_OVERWINTER ] . nActivationHeight ;
return state . DoS ( ( ht < 0 | | nHeight < ht ) ? 0 : dosLevel , error ( " ContextualCheckTransaction(): ht.%d activates.%d dosLevel.%d overwinter is not active yet " , nHeight , Params ( ) . GetConsensus ( ) . vUpgrades [ Consensus : : UPGRADE_OVERWINTER ] . nActivationHeight , dosLevel ) , REJECT_INVALID , " tx-overwinter-not-active " ) ;
//return state.DoS(isInitBlockDownload() ? 0 : dosLevel,error("ContextualCheckTransaction(): ht.%d activates.%d dosLevel.%d overwinter is not active yet",nHeight, Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight, dosLevel),REJECT_INVALID, "tx-overwinter-not-active");
}
if ( saplingActive ) {
@ -1077,11 +1076,14 @@ bool ContextualCheckTransaction(
}
// Rules that apply to Overwinter or later:
if ( overwinterActive ) {
if ( overwinterActive )
{
// Reject transactions intended for Sprout
if ( ! tx . fOverwintered ) {
return state . DoS ( dosLevel , error ( " ContextualCheckTransaction: overwinter is active " ) ,
REJECT_INVALID , " tx-overwinter-active " ) ;
if ( ! tx . fOverwintered )
{
int32_t ht = Params ( ) . GetConsensus ( ) . vUpgrades [ Consensus : : UPGRADE_OVERWINTER ] . nActivationHeight ;
fprintf ( stderr , " overwinter is active tx.%s not, ht.%d vs %d \n " , tx . GetHash ( ) . ToString ( ) . c_str ( ) , nHeight , ht ) ;
return state . DoS ( ( ASSETCHAINS_PRIVATE ! = 0 | | ht < 0 | | nHeight < ht ) ? 0 : dosLevel , error ( " ContextualCheckTransaction: overwinter is active " ) , REJECT_INVALID , " tx-overwinter-active " ) ;
}
// Check that all transactions are unexpired
@ -1117,7 +1119,7 @@ bool ContextualCheckTransaction(
return state . DoS ( 100 , error ( " CheckTransaction(): error computing signature hash " ) ,
REJECT_INVALID , " error-computing-signature-hash " ) ;
}
}
if ( ! ( tx . IsMint ( ) | | tx . vjoinsplit . empty ( ) ) )
@ -1447,7 +1449,7 @@ bool CheckTransactionWithoutProofVerification(uint32_t tiptime,const CTransactio
{
static uint32_t counter ;
if ( counter + + < 10 )
fprintf ( stderr , " found taddr in private chain: z_z.%d z_t.%d t_z.%d \n " , z_z , z_t , t_z ) ;
fprintf ( stderr , " found taddr in private chain: z_z.%d z_t.%d t_z.%d vinsize.%d \n " , z_z , z_t , t_z , ( int32_t ) tx . vin . size ( ) ) ;
if ( z_t = = 0 | | z_z ! = 0 | | t_z ! = 0 | | tx . vin . size ( ) ! = 0 )
return state . DoS ( 100 , error ( " CheckTransaction(): this is a private chain, only sprout -> taddr allowed until deadline " ) , REJECT_INVALID , " bad-txns-acprivacy-chain " ) ;
}
@ -1597,7 +1599,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
}
bool AcceptToMemoryPool ( CTxMemPool & pool , CValidationState & state , const CTransaction & tx , bool fLimitFree , bool * pfMissingInputs , bool fRejectAbsurdFee , int dosLevel )
bool AcceptToMemoryPool ( CTxMemPool & pool , CValidationState & state , const CTransaction & tx , bool fLimitFree , bool * pfMissingInputs , bool fRejectAbsurdFee , int dosLevel , bool fSkipExpiry )
{
AssertLockHeld ( cs_main ) ;
if ( pfMissingInputs )
@ -1634,7 +1636,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
}
// DoS level set to 10 to be more forgiving.
// Check transaction contextually against the set of consensus rules which apply in the next block to be mined.
if ( ! ContextualCheckTransaction ( tx , state , nextBlockHeight , ( dosLevel = = - 1 ) ? 10 : dosLevel ) )
if ( ! fSkipExpiry & & ! ContextualCheckTransaction ( tx , state , nextBlockHeight , ( dosLevel = = - 1 ) ? 10 : dosLevel ) )
{
return error ( " AcceptToMemoryPool: ContextualCheckTransaction failed " ) ;
}
@ -1731,8 +1733,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
if ( pfMissingInputs )
* pfMissingInputs = true ;
//fprintf(stderr,"missing inputs\n");
//return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing");
return ( false ) ;
if ( ! fSkipExpiry )
return state . DoS ( 0 , error ( " AcceptToMemoryPool: tx inputs not found " ) , REJECT_INVALID , " bad-txns-inputs-missing " ) ;
else
return ( false ) ;
}
}
@ -1740,7 +1744,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
if ( ! view . HaveInputs ( tx ) )
{
//fprintf(stderr,"accept failure.1\n");
return state . Invalid ( error ( " AcceptToMemoryPool: inputs already spent " ) , REJECT_DUPLICATE , " bad-txns-inputs-spent " ) ;
if ( ! fSkipExpiry )
return state . Invalid ( error ( " AcceptToMemoryPool: inputs already spent " ) , REJECT_DUPLICATE , " bad-txns-inputs-spent " ) ;
else
return ( false ) ;
}
}
// are the joinsplit's requirements met?
@ -1751,7 +1758,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
}
// Bring the best block into scope
view . GetBestBlock ( ) ;
nValueIn = view . GetValueIn ( chainActive . LastTip ( ) - > GetHeight ( ) , & interest , tx , chainActive . LastTip ( ) - > nTime ) ;
if ( 0 & & interest ! = 0 )
fprintf ( stderr , " add interest %.8f \n " , ( double ) interest / COIN ) ;
@ -1846,7 +1853,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
dFreeCount + = nSize ;
}
if ( fRejectAbsurdFee & & nFees > : : minRelayTxFee . GetFee ( nSize ) * 10000 & & nFees > nValueOut / 19 )
if ( fRejectAbsurdFee & & nFees > : : minRelayTxFee . GetFee ( nSize ) * 10000 & & nFees > nValueOut / 19 )
{
string errmsg = strprintf ( " absurdly high fees %s, %d > %d " ,
hash . ToString ( ) ,
@ -1973,14 +1980,14 @@ bool GetAddressUnspent(uint160 addressHash, int type,
else return ( coins . vout [ n ] . nValue ) ;
} */
bool myAddtomempool ( CTransaction & tx , CValidationState * pstate )
bool myAddtomempool ( CTransaction & tx , CValidationState * pstate , bool fSkipExpiry )
{
CValidationState state ;
if ( ! pstate )
pstate = & state ;
CTransaction Ltx ; bool fMissingInputs , fOverrideFees = false ;
if ( mempool . lookup ( tx . GetHash ( ) , Ltx ) = = 0 )
return ( AcceptToMemoryPool ( mempool , * pstate , tx , false , & fMissingInputs , ! fOverrideFees ) ) ;
return ( AcceptToMemoryPool ( mempool , * pstate , tx , false , & fMissingInputs , ! fOverrideFees , - 1 , fSkipExpiry ) ) ;
else return ( true ) ;
}
@ -2302,9 +2309,9 @@ int IsNotInSync()
CBlockIndex * pbi = chainActive . Tip ( ) ;
int longestchain = komodo_longestchain ( ) ;
if ( ! pbi | |
( pindexBestHeader = = 0 ) | |
( ( pindexBestHeader - > GetHeight ( ) - 1 ) > pbi - > GetHeight ( ) ) | |
if ( ! pbi | |
( pindexBestHeader = = 0 ) | |
( ( pindexBestHeader - > GetHeight ( ) - 1 ) > pbi - > GetHeight ( ) ) | |
( longestchain ! = 0 & & longestchain > pbi - > GetHeight ( ) ) )
{
return ( pbi & & pindexBestHeader & & ( pindexBestHeader - > GetHeight ( ) - 1 ) > pbi - > GetHeight ( ) ) ?
@ -2332,7 +2339,7 @@ void CheckForkWarningConditions()
// of our head, drop it
if ( pindexBestForkTip & & chainActive . Height ( ) - pindexBestForkTip - > GetHeight ( ) > = 288 )
pindexBestForkTip = NULL ;
if ( pindexBestForkTip | | ( pindexBestInvalid & & pindexBestInvalid - > chainPower > ( chainActive . LastTip ( ) - > chainPower + ( GetBlockProof ( * chainActive . LastTip ( ) ) * 6 ) ) ) )
{
if ( ! fLargeWorkForkFound & & pindexBestForkBase )
@ -2924,7 +2931,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
{
CCoinsModifier outs = view . ModifyCoins ( hash ) ;
outs - > ClearUnspendable ( ) ;
CCoins outsBlock ( tx , pindex - > GetHeight ( ) ) ;
// The CCoins serialization does not serialize negative numbers.
// No network rules currently depend on the version here, so an inconsistency is harmless
@ -3108,7 +3115,7 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const
// Aim for one false-positive about every fifty years of normal running:
const int FIFTY_YEARS = 50 * 365 * 24 * 60 * 60 ;
double alertThreshold = 1.0 / ( FIFTY_YEARS / SPAN_SECONDS ) ;
if ( bestHeader - > GetHeight ( ) > BLOCKS_EXPECTED )
{
if ( p < = alertThreshold & & nBlocks < BLOCKS_EXPECTED )
@ -3187,7 +3194,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
}
return true ;
}
bool fScriptChecks = ( ! fCheckpointsEnabled | | pindex - > GetHeight ( ) > = Checkpoints : : GetTotalBlocksEstimate ( chainparams . Checkpoints ( ) ) ) ;
//if ( KOMODO_TESTNET_EXPIRATION != 0 && pindex->GetHeight() > KOMODO_TESTNET_EXPIRATION ) // "testnet"
// return(false);
@ -3253,7 +3260,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
// Grab the consensus branch ID for the block's height
auto consensusBranchId = CurrentEpochBranchId ( pindex - > GetHeight ( ) , Params ( ) . GetConsensus ( ) ) ;
std : : vector < PrecomputedTransactionData > txdata ;
txdata . reserve ( block . vtx . size ( ) ) ; // Required so that pointers to individual PrecomputedTransactionData don't get invalidated
for ( unsigned int i = 0 ; i < block . vtx . size ( ) ; i + + )
@ -3393,7 +3400,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
blockundo . vtxundo . push_back ( CTxUndo ( ) ) ;
}
UpdateCoins ( tx , view , i = = 0 ? undoDummy : blockundo . vtxundo . back ( ) , pindex - > GetHeight ( ) ) ;
BOOST_FOREACH ( const JSDescription & joinsplit , tx . vjoinsplit ) {
BOOST_FOREACH ( const uint256 & note_commitment , joinsplit . commitments ) {
// Insert the note commitments into our temporary tree.
@ -3428,9 +3435,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
}
int64_t nTime1 = GetTimeMicros ( ) ; nTimeConnect + = nTime1 - nTimeStart ;
LogPrint ( " bench " , " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs] \n " , ( unsigned ) block . vtx . size ( ) , 0.001 * ( nTime1 - nTimeStart ) , 0.001 * ( nTime1 - nTimeStart ) / block . vtx . size ( ) , nInputs < = 1 ? 0 : 0.001 * ( nTime1 - nTimeStart ) / ( nInputs - 1 ) , nTimeConnect * 0.000001 ) ;
CAmount blockReward = nFees + GetBlockSubsidy ( pindex - > GetHeight ( ) , chainparams . GetConsensus ( ) ) + sum ;
if ( ASSETCHAINS_COMMISSION ! = 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 &&
if ( ASSETCHAINS_COMMISSION ! = 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 &&
{
uint64_t checktoshis ;
if ( ( checktoshis = komodo_commission ( ( CBlock * ) & block , ( int32_t ) pindex - > GetHeight ( ) ) ) ! = 0 )
@ -3495,7 +3502,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
}
ConnectNotarisations ( block , pindex - > GetHeight ( ) ) ;
if ( fTxIndex )
if ( ! pblocktree - > WriteTxIndex ( vPos ) )
return AbortNode ( state , " Failed to write transaction index " ) ;
@ -3767,7 +3774,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
// Write the chain state to disk, if necessary.
if ( ! FlushStateToDisk ( state , FLUSH_STATE_IF_NEEDED ) )
return false ;
if ( ! fBare ) {
// resurrect mempool transactions from the disconnected block.
for ( int i = 0 ; i < block . vtx . size ( ) ; i + + )
@ -3776,7 +3783,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
CTransaction & tx = block . vtx [ i ] ;
list < CTransaction > removed ;
CValidationState stateDummy ;
// don't keep staking or invalid transactions
if ( tx . IsCoinBase ( ) | | ( ( i = = ( block . vtx . size ( ) - 1 ) ) & & ( ASSETCHAINS_STAKED & & komodo_isPoS ( ( CBlock * ) & block ) ! = 0 ) ) | | ! AcceptToMemoryPool ( mempool , stateDummy , tx , false , NULL ) )
{
@ -3797,7 +3804,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
// Update chainActive and related variables.
UpdateTip ( pindexDelete - > pprev ) ;
// Get the current commitment tree
SproutMerkleTree newSproutTree ;
SaplingMerkleTree newSaplingTree ;
@ -3879,9 +3886,7 @@ int32_t komodo_activate_sapling(CBlockIndex *pindex)
}
if ( activation ! = 0 )
{
//#if KOMODO_SAPLING_ACTIVATION != 1544832000
komodo_setactivation ( activation ) ;
//#endif
fprintf ( stderr , " %s sapling activation at %d \n " , ASSETCHAINS_SYMBOL , activation ) ;
ASSETCHAINS_SAPLING = activation ;
}
@ -3945,10 +3950,10 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
// Remove conflicting transactions from the mempool.
list < CTransaction > txConflicted ;
mempool . removeForBlock ( pblock - > vtx , pindexNew - > GetHeight ( ) , txConflicted , ! IsInitialBlockDownload ( ) ) ;
// Remove transactions that expire at new block height from mempool
mempool . removeExpired ( pindexNew - > GetHeight ( ) ) ;
// Update chainActive & related variables.
UpdateTip ( pindexNew ) ;
// Tell wallet about transactions that went from mempool
@ -3964,7 +3969,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
GetMainSignals ( ) . ChainTip ( pindexNew , pblock , oldSproutTree , oldSaplingTree , true ) ;
EnforceNodeDeprecation ( pindexNew - > GetHeight ( ) ) ;
int64_t nTime6 = GetTimeMicros ( ) ; nTimePostConnect + = nTime6 - nTime5 ; nTimeTotal + = nTime6 - nTime1 ;
LogPrint ( " bench " , " - Connect postprocess: %.2fms [%.2fs] \n " , ( nTime6 - nTime5 ) * 0.001 , nTimePostConnect * 0.000001 ) ;
LogPrint ( " bench " , " - Connect block: %.2fms [%.2fs] \n " , ( nTime6 - nTime1 ) * 0.001 , nTimeTotal * 0.000001 ) ;
@ -3972,7 +3977,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
KOMODO_INSYNC = ( int32_t ) pindexNew - > GetHeight ( ) ;
else KOMODO_INSYNC = 0 ;
//fprintf(stderr,"connect.%d insync.%d ASSETCHAINS_SAPLING.%d\n",(int32_t)pindexNew->GetHeight(),KOMODO_INSYNC,ASSETCHAINS_SAPLING);
if ( KOMODO_INSYNC ! = 0 ) //ASSETCHAINS_SYMBOL[0] == 0 &&
if ( KOMODO_INSYNC ! = 0 ) //ASSETCHAINS_SYMBOL[0] == 0 &&
komodo_broadcast ( pblock , 8 ) ;
else if ( ASSETCHAINS_SYMBOL [ 0 ] ! = 0 )
komodo_broadcast ( pblock , 4 ) ;
@ -4003,7 +4008,7 @@ static CBlockIndex* FindMostWorkChain() {
bool fInvalidAncestor = false ;
while ( pindexTest & & ! chainActive . Contains ( pindexTest ) ) {
assert ( pindexTest - > nChainTx | | pindexTest - > GetHeight ( ) = = 0 ) ;
// Pruned nodes may have entries in setBlockIndexCandidates for
// which block files have been deleted. Remove those as candidates
// for the most work chain if we come across them; we can't switch
@ -4285,9 +4290,9 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) {
bool ReconsiderBlock ( CValidationState & state , CBlockIndex * pindex ) {
AssertLockHeld ( cs_main ) ;
int nHeight = pindex - > GetHeight ( ) ;
// Remove the invalidity flag from this block and all its descendants.
BlockMap : : iterator it = mapBlockIndex . begin ( ) ;
while ( it ! = mapBlockIndex . end ( ) ) {
@ -4680,12 +4685,13 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
int32_t i , j , rejects = 0 , lastrejects = 0 ;
//fprintf(stderr,"put block's tx into mempool\n");
// Copy all non Z-txs in mempool to temporary mempool because there can be tx in local mempool that make the block invalid.
LOCK ( mempool . cs ) ;
LOCK2 ( cs_main , mempool . cs ) ;
//fprintf(stderr, "starting... mempoolsize.%ld\n",mempool.size());
list < CTransaction > transactionsToRemove ;
BOOST_FOREACH ( const CTxMemPoolEntry & e , mempool . mapTx ) {
const CTransaction & tx = e . GetTx ( ) ;
const uint256 & hash = tx . GetHash ( ) ;
if ( tx . vjoinsplit . siz e( ) = = 0 ) {
if ( tx . vjoinsplit . empty ( ) & & tx . vShieldedSpend . empty ( ) ) {
transactionsToRemove . push_back ( tx ) ;
tmpmempool . addUnchecked ( hash , e , true ) ;
}
@ -4695,17 +4701,19 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
mempool . remove ( tx , removed , false ) ;
}
// add all the txs in the block to the empty mempool.
// CC validation shouldnt (cant) depend on the state of mempool!
while ( 1 )
{
list < CTransaction > removed ;
for ( i = 0 ; i < block . vtx . size ( ) ; i + + )
{
CValidationState state ;
CTransaction Tx ;
CTransaction Tx ;
const CTransaction & tx = ( CTransaction ) block . vtx [ i ] ;
if ( tx . IsCoinBase ( ) | | ( ( i = = ( block . vtx . size ( ) - 1 ) ) & & ( ASSETCHAINS_STAKED & & komodo_isPoS ( ( CBlock * ) & block ) ! = 0 ) ) )
if ( tx . IsCoinBase ( ) | | ( ! tx . vjoinsplit . empty ( ) & & ! tx . vShieldedSpend . empty ( ) ) | | ( ( i = = ( block . vtx . size ( ) - 1 ) ) & & ( ASSETCHAINS_STAKED & & komodo_isPoS ( ( CBlock * ) & block ) ! = 0 ) ) )
continue ;
Tx = tx ;
if ( myAddtomempool ( Tx , & state ) = = false ) // happens with out of order tx in block on resync
if ( myAddtomempool ( Tx , & state , true ) = = false ) // happens with out of order tx in block on resync
{
//LogPrintf("Rejected by mempool, reason: .%s.\n", state.GetRejectReason().c_str());
// take advantage of other checks, but if we were only rejected because it is a valid staking
@ -4716,7 +4724,10 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
ptx = & sTx ;
} else rejects + + ;
}
// here we remove any txs in the temp mempool that were included in the block.
tmpmempool . remove ( tx , removed , false ) ;
}
//fprintf(stderr, "removed.%ld\n",removed.size());
if ( rejects = = 0 | | rejects = = lastrejects )
{
if ( 0 & & lastrejects ! = 0 )
@ -4763,19 +4774,13 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
if ( ASSETCHAINS_CC ! = 0 )
{
// here we add back all txs from the temp mempool to the main mempool.
// which removes any tx locally that were invalid after the block arrives.
int invalidtxs = 0 ;
LOCK ( mempool . cs ) ;
BOOST_FOREACH ( const CTxMemPoolEntry & e , tmpmempool . mapTx ) {
CTransaction tx = e . GetTx ( ) ;
CValidationState state ; bool fMissingInputs , fOverrideFees = false ;
if ( AcceptToMemoryPool ( mempool , state , tx , false , & fMissingInputs , ! fOverrideFees ) = = false )
invalidtxs + + ;
//else fprintf(stderr, "added mempool tx back to mempool\n");
BOOST_FOREACH ( const CTxMemPoolEntry & e , tmpmempool . mapTx )
{
const CTransaction & tx = e . GetTx ( ) ;
const uint256 & hash = tx . GetHash ( ) ;
mempool . addUnchecked ( hash , e , true ) ;
}
if ( 0 & & invalidtxs > 0 )
fprintf ( stderr , " number of invalid txs: %d \n " , invalidtxs ) ;
//fprintf(stderr, "finished adding back. mempoolsize.%ld\n",mempool.size());
// empty the temp mempool for next time.
tmpmempool . clear ( ) ;
}
@ -4791,13 +4796,13 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
return true ;
assert ( pindexPrev ) ;
int nHeight = pindexPrev - > GetHeight ( ) + 1 ;
// Check proof of work
if ( ( ASSETCHAINS_SYMBOL [ 0 ] ! = 0 | | nHeight < 235300 | | nHeight > 236000 ) & & block . nBits ! = GetNextWorkRequired ( pindexPrev , & block , consensusParams ) )
{
cout < < block . nBits < < " block.nBits vs. calc " < < GetNextWorkRequired ( pindexPrev , & block , consensusParams ) < <
cout < < block . nBits < < " block.nBits vs. calc " < < GetNextWorkRequired ( pindexPrev , & block , consensusParams ) < <
" for block # " < < nHeight < < endl ;
return state . DoS ( 100 , error ( " %s: incorrect proof of work " , __func__ ) ,
REJECT_INVALID , " bad-diffbits " ) ;
@ -4872,7 +4877,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
// Check that all transactions are finalized
for ( uint32_t i = 0 ; i < block . vtx . size ( ) ; i + + ) {
const CTransaction & tx = block . vtx [ i ] ;
// Check transaction contextually against consensus rules at block height
if ( ! ContextualCheckTransaction ( tx , state , nHeight , 100 ) ) {
return false ; // Failure reason has been set in validation state object
@ -4921,7 +4926,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat
* ppindex = pindex ;
if ( pindex ! = 0 & & pindex - > nStatus & BLOCK_FAILED_MASK )
{
if ( ASSETCHAINS_CC = = 0 )
if ( ASSETCHAINS_CC = = 0 ) //&& (ASSETCHAINS_PRIVATE == 0 || KOMODO_INSYNC >= Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight) )
return state . Invalid ( error ( " %s: block is marked invalid " , __func__ ) , 0 , " duplicate " ) ;
else
{
@ -5028,7 +5033,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C
// regardless of whether pruning is enabled; it should generally be safe to
// not process unrequested blocks.
bool fTooFarAhead = ( pindex - > GetHeight ( ) > int ( chainActive . Height ( ) + BLOCK_DOWNLOAD_WINDOW ) ) ; //MIN_BLOCKS_TO_KEEP));
// TODO: deal better with return value and error conditions for duplicate
// and unrequested blocks.
//fprintf(stderr,"Accept %s flags already.%d requested.%d morework.%d farahead.%d\n",pindex->GetBlockHash().ToString().c_str(),fAlreadyHave,fRequested,fHasMoreWork,fTooFarAhead);
@ -5066,7 +5071,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C
return false ;
}
}
int nHeight = pindex - > GetHeight ( ) ;
// Write block to history file
try {
@ -5469,7 +5474,7 @@ bool static LoadBlockIndexDB()
return false ;
LogPrintf ( " %s: loaded guts \n " , __func__ ) ;
boost : : this_thread : : interruption_point ( ) ;
// Calculate chainPower
vector < pair < int , CBlockIndex * > > vSortedByHeight ;
vSortedByHeight . reserve ( mapBlockIndex . size ( ) ) ;
@ -5727,7 +5732,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
//fprintf(stderr,"end VerifyDB %u\n",(uint32_t)time(NULL));
if ( pindexFailure )
return error ( " VerifyDB() : * * * coin database inconsistencies found ( last % i blocks , % i good transactions before that ) \ n " , chainActive.Height() - pindexFailure->GetHeight() + 1, nGoodTransactions) ;
// check level 4: try reconnecting blocks
if ( nCheckLevel > = 4 ) {
CBlockIndex * pindex = pindexState ;
@ -5742,9 +5747,9 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
return error ( " VerifyDB() : * * * found unconnectable block at % d , hash = % s " , pindex->GetHeight(), pindex->GetBlockHash().ToString()) ;
}
}
LogPrintf ( " No coin database inconsistencies in last %i blocks (%i transactions) \n " , chainActive . Height ( ) - pindexState - > GetHeight ( ) , nGoodTransactions ) ;
return true ;
}
@ -6586,7 +6591,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
pfrom - > fDisconnect = true ;
return false ;
}
if ( ! vRecv . empty ( ) )
vRecv > > addrFrom > > nNonce ;
if ( ! vRecv . empty ( ) ) {
@ -6609,7 +6614,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}
pfrom - > nVersion = nVersion ;
pfrom - > addrLocal = addrMe ;
if ( pfrom - > fInbound & & addrMe . IsRoutable ( ) )
{