Merge pull request #353 from jl777/dev

Dev
This commit is contained in:
jl777
2017-03-23 06:54:04 +02:00
committed by GitHub
3 changed files with 29 additions and 31 deletions

View File

@@ -706,10 +706,10 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
return true;
}
int32_t komodo_validate_interest(const CTransaction& tx,uint32_t txblocktime)
int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint32_t txblocktime)
{
int32_t i,txheight=0; uint32_t cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0;
if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD && txblocktime >= 1490159171 - 24*3600*100 )//1473793441 )
if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 )
{
locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0);
if ( tiptime == 0 )
@@ -731,27 +731,26 @@ int32_t komodo_validate_interest(const CTransaction& tx,uint32_t txblocktime)
cmptime = txblocktime;
if ( tiptime != 0 && tiptime < cmptime )
cmptime = tiptime;
//validateinterest accept.246749 locktime 1490205024/1490205024 vs txheighttime.1490205794 tiptime.1490159171 txb.1490205794
//komodo_validate_interest reject.246749 locktime 1490201846/1490201846 vs nBlockTime 1490159171 txheighttime.1490205794 tiptime.1490159171 txb.1490205794
//CheckBlock(): komodo_validate_interest failure
if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 )
if ( cmptime >= 1490159171 - 24*3600 )
{
if ( txheighttime > 1490159171 || (locktime == 0 && txheighttime >= 1490159171) ) // 246748
if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 )
{
// komodo_validate_interest reject.0 locktime 1490193206/0 vs nBlockTime 1490202625 txheighttime.1490202625 tiptime.0
//static uint32_t counter;
//if ( counter++ < 100 )
if ( tx.nLockTime != 1477258935 )
fprintf(stderr,"komodo_validate_interest reject.%d locktime %u/%u vs nBlockTime %u txheighttime.%u tiptime.%u txb.%u cmp.%u\n",txheight,(uint32_t)tx.nLockTime,locktime,(uint32_t)chainActive.Tip()->nTime,txheighttime,tiptime,txblocktime,cmptime);
return(-1);
} else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime);
if ( txheighttime > 1490159171 || (locktime == 0 && txheighttime >= 1490159171) ) // 246748
{
if ( tx.nLockTime != 1477258935 )
fprintf(stderr,"komodo_validate_interest reject.%d locktime %u/%u vs nBlockTime %u txheighttime.%u tiptime.%u txb.%u cmp.%u\n",txheight,(uint32_t)tx.nLockTime,locktime,(uint32_t)chainActive.Tip()->nTime,txheighttime,tiptime,txblocktime,cmptime);
if ( expiredp != 0 )
*expiredp = cmptime-3600;
return(-1);
} else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime);
}
}
fprintf(stderr,"validateinterest accept.%d tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime);
//fprintf(stderr,"validateinterest accept.%d tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime);
}
return(0);
}
bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags)
bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags,int32_t interesttime)
{
int32_t i;
if ( expiredp != 0 )
@@ -760,14 +759,11 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6
return true;
if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600
{
if ( komodo_validate_interest(tx,nBlockTime) < 0 )
//if ( nBlockTime >= 1490159171 ) // 246748
if ( komodo_validate_interest(expiredp,tx,interesttime) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748
{
fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime);
if ( expiredp != 0 )
*expiredp = nBlockTime-3600;
return(false); // need to prevent pastdating tx
} else fprintf(stderr,"IsFinalTx grandfather.%d locktime %u vs nBlockTime %u\n",(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime);
} else fprintf(stderr,"IsFinalTx accept.%d locktime %u vs nBlockTime %u\n",(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime);
}
if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime))
return true;
@@ -814,7 +810,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags)
? chainActive.Tip()->GetMedianTimePast()
: GetAdjustedTime();
return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags);
return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags,chainActive.Tip()->nTime);
}
/**
@@ -1160,7 +1156,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
if (pfMissingInputs)
*pfMissingInputs = false;
auto verifier = libzcash::ProofVerifier::Strict();
/*if ( komodo_validate_interest(tx) < 0 ) // called from IsFinalTx() below
/*if ( komodo_validate_interest(tx) < 0 ) // called from CheckFinalTx() below
{
fprintf(stderr,"komodo_validate_interest failure\n");
return error("AcceptToMemoryPool: komodo_validate_interest failed");
@@ -3281,9 +3277,9 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
// Check transactions
BOOST_FOREACH(const CTransaction& tx, block.vtx)
{
if ( komodo_validate_interest(tx,block.nTime) < 0 )
if ( komodo_validate_interest(0,tx,block.nTime) < 0 )
{
fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size());
//fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size());
return error("CheckBlock: komodo_validate_interest failed");
}
if (!CheckTransaction(tx, state, verifier))
@@ -3365,7 +3361,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
int64_t nLockTimeCutoff = (nLockTimeFlags & LOCKTIME_MEDIAN_TIME_PAST)
? pindexPrev->GetMedianTimePast()
: block.GetBlockTime();
if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS)) {
if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS,pindexPrev->nTime)) {
return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal");
}
}

View File

@@ -351,7 +351,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason);
* Check if transaction is final and can be included in a block with the
* specified height and time. Consensus critical.
*/
bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags);
bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags,int32_t interesttime);
/**
* Check if transaction will be final in the next block to be created.

View File

@@ -202,14 +202,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
? nMedianTimePast
: pblock->GetBlockTime();
if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS))
if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS,chainActive.Tip()->nTime))
{
if ( expired != 0 )
{
fprintf(stderr,"expire from mempool tx.\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN);
list<CTransaction> removed;
mempool.remove(tx, removed, true);
}
continue;
}
} else fprintf(stderr,"coinbase or is finaltx (%d %u)\n",(int32_t)nHeight,(uint32_t)tx.nLockTime);
COrphan* porphan = NULL;
double dPriority = 0;
CAmount nTotalIn = 0;
@@ -436,8 +438,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
static uint32_t counter;
if ( counter++ < 100 )
fprintf(stderr,"warning: testblockvalidity failed\n");
return(0);
//throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed");
//return(0);
throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed");
}
}