Merge pull request #355 from jl777/beta

Beta
This commit is contained in:
jl777
2017-03-23 07:28:42 +02:00
committed by GitHub
7 changed files with 111 additions and 47 deletions

View File

@@ -740,10 +740,12 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
return(0);
}
uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n)
uint32_t komodo_interest_args(uint32_t *txheighttimep,int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n)
{
LOCK(cs_main);
CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex;
*txheighttimep = *txheightp = *tiptimep = 0;
*valuep = 0;
if ( !GetTransaction(hash,tx,hashBlock,true) )
return(0);
uint32_t locktime = 0;
@@ -753,6 +755,7 @@ uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *va
{
*valuep = tx.vout[n].nValue;
*txheightp = pindex->nHeight;
*txheighttimep = pindex->nTime;
*tiptimep = tipindex->nTime;
locktime = tx.nLockTime;
//fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*tiptimep);
@@ -764,8 +767,8 @@ uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *va
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue)
{
uint64_t value; uint32_t tiptime;
if ( (*locktimep= komodo_interest_args(txheightp,&tiptime,&value,hash,n)) != 0 )
uint64_t value; uint32_t tiptime,txheighttimep;
if ( (*locktimep= komodo_interest_args(&txheighttimep,txheightp,&tiptime,&value,hash,n)) != 0 )
{
if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || *txheightp == checkheight) )
return(komodo_interest(*txheightp,value,*locktimep,tiptime));

View File

@@ -520,8 +520,8 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to
}
if ( ASSETCHAINS_SYMBOL[0] != 0 && (pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,symbol) != 0 || available < pax->fiatoshis) )
{
if ( pax->height > 214700 || strcmp(ASSETCHAINS_SYMBOL,symbol) == 0 )
printf("miner.[%s]: skip %s %.8f when avail %.8f deposited %.8f, issued %.8f withdrawn %.8f approved %.8f redeemed %.8f\n",ASSETCHAINS_SYMBOL,symbol,dstr(pax->fiatoshis),dstr(available),dstr(deposited),dstr(issued),dstr(withdrawn),dstr(approved),dstr(redeemed));
//if ( pax->height > 214700 || strcmp(ASSETCHAINS_SYMBOL,symbol) == 0 )
// printf("miner.[%s]: skip %s %.8f when avail %.8f deposited %.8f, issued %.8f withdrawn %.8f approved %.8f redeemed %.8f\n",ASSETCHAINS_SYMBOL,symbol,dstr(pax->fiatoshis),dstr(available),dstr(deposited),dstr(issued),dstr(withdrawn),dstr(approved),dstr(redeemed));
continue;
}
/*printf("pax.%s marked.%d %.8f -> %.8f ready.%d validated.%d\n",pax->symbol,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis),pax->ready!=0,pax->validated!=0);
@@ -717,8 +717,8 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
extern int32_t KOMODO_REWIND;
if ( KOMODO_REWIND < 0 )
{
fprintf(stderr,"rewind.%d\n",KOMODO_REWIND);
sleep(3);
fprintf(stderr,">>>>>>> rewind.%d will pause here for a minute. issue command and stop\n",KOMODO_REWIND);
sleep(60);
KOMODO_REWIND = 0;
}
// 6a35506c65617365206d616b6520796f75722047697420636f6d6d6974206d65737361676573206d6f726520696e74657265737469 height.241778 checkdeposit n.4 [6a] [P] 80 vs 88
@@ -1213,7 +1213,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
{
basesp->withdrawn += value;
didstats = 1;
if ( strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
if ( 0 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
printf("########### %p withdrawn %s += %.8f check %.8f\n",basesp,base,dstr(value),dstr(checktoshis));
}
if ( 0 && strcmp(base,"RUB") == 0 && (pax == 0 || pax->approved == 0) )

View File

@@ -706,47 +706,64 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
return true;
}
int32_t komodo_validate_interest(const CTransaction& tx)
int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint32_t txblocktime)
{
int32_t i,txheight=0; uint32_t prevblocktime=0,locktime; uint64_t value=0;
if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )
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 )//1473793441 )
{
locktime = komodo_interest_args(&txheight,&prevblocktime,&value,tx.GetHash(),0);
if ( prevblocktime == 0 )
locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0);
if ( tiptime == 0 )
tiptime = (int32_t)chainActive.Tip()->nTime;
if ( txheighttime == 0 )
{
static uint32_t counter0;
prevblocktime = chainActive.Tip()->nTime;
txheighttime = chainActive.Tip()->nTime;
if ( counter0++ < 3 )
fprintf(stderr,"error getting prevblocktime, set to tiptime.%u\n",prevblocktime);
fprintf(stderr,"error getting txheighttime, set to tiptime.%u\n",txheighttime);
}
if ( (int64_t)tx.nLockTime < prevblocktime-3600 )
if ( txheighttime != 0 && txblocktime != 0 )
{
if ( prevblocktime > 1490159171 || (txheight == 0 && prevblocktime >= 1490159171) ) // 246748
{
static uint32_t counter;
if ( counter++ < 100 )
fprintf(stderr,"komodo_validate_interest reject.%d locktime %u/%u vs nBlockTime %u prevblocktime.%u\n",txheight,(uint32_t)tx.nLockTime,locktime,(uint32_t)chainActive.Tip()->nTime,prevblocktime);
return(-1);
} else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs nBlockTime %u\n",(int32_t)txheight,tx.nLockTime,(uint32_t)prevblocktime);
cmptime = txheighttime;
if ( txblocktime < cmptime )
cmptime = txblocktime;
}
else if ( (cmptime= txheighttime) == 0 )
cmptime = txblocktime;
if ( tiptime != 0 && tiptime < cmptime )
cmptime = tiptime;
if ( cmptime >= 1490159171 - 24*3600 )
{
if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 )
{
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);
}
return(0);
}
bool IsFinalTx(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 )
*expiredp = 0;
if (tx.nLockTime == 0)
return true;
if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD && (int64_t)tx.nLockTime < nBlockTime-3600 )
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) < 0 )
// return(false);
if ( nBlockTime >= 1490159171 || nBlockHeight > 246748 ) // 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);
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;
@@ -793,7 +810,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags)
? chainActive.Tip()->GetMedianTimePast()
: GetAdjustedTime();
return IsFinalTx(tx, nBlockHeight, nBlockTime,flags);
return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags,chainActive.Tip()->nTime);
}
/**
@@ -898,8 +915,11 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state,libzcash::
static uint256 array[15]; int32_t j,k,n;
if ( *(int32_t *)&array[0] == 0 )
komodo_bannedset(array,(int32_t)(sizeof(array)/sizeof(*array)));
if ( komodo_validate_interest(tx) < 0 )
/*if ( komodo_validate_interest(tx) < 0 )
{
fprintf(stderr,"CheckTransaction komodo_validate_interest error\n");
return(false);
}*/
n = tx.vin.size();
for (j=0; j<n; j++)
{
@@ -1136,11 +1156,11 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
if (pfMissingInputs)
*pfMissingInputs = false;
auto verifier = libzcash::ProofVerifier::Strict();
if ( komodo_validate_interest(tx) < 0 )
/*if ( komodo_validate_interest(tx) < 0 ) // called from CheckFinalTx() below
{
fprintf(stderr,"komodo_validate_interest failure\n");
return error("AcceptToMemoryPool: komodo_validate_interest failed");
}
}*/
if (!CheckTransaction(tx, state, verifier))
{
fprintf(stderr,"accept failure.0\n");
@@ -1587,9 +1607,9 @@ bool IsInitialBlockDownload()
else if ( pindexBestHeader != 0 && pindexBestHeader->nHeight > ptr->nHeight )
ptr = pindexBestHeader;
if ( ASSETCHAINS_SYMBOL[0] == 0 )
state = ((chainActive.Height() < ptr->nHeight - 24*6) ||
state = ((chainActive.Height() < ptr->nHeight - 24*60) ||
ptr->GetBlockTime() < (GetTime() - chainParams.MaxTipAge()));
else state = (chainActive.Height() < ptr->nHeight - 100);
else state = (chainActive.Height() < ptr->nHeight - 3);
//fprintf(stderr,"state.%d ht.%d vs %d, t.%u %u\n",state,(int32_t)chainActive.Height(),(uint32_t)ptr->nHeight,(int32_t)ptr->GetBlockTime(),(uint32_t)(GetTime() - chainParams.MaxTipAge()));
if (!state)
{
@@ -2925,7 +2945,7 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) {
}
// Notify external listeners about the new tip.
uiInterface.NotifyBlockTip(hashNewTip);
}
} //else fprintf(stderr,"initial download skips propagation\n");
} while(pindexMostWork != chainActive.Tip());
CheckBlockIndex();
@@ -3176,6 +3196,21 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl
{
uint8_t pubkey33[33];
// Check timestamp
if ( 0 )
{
uint256 hash; int32_t i;
hash = blockhdr.GetHash();
for (i=31; i>=0; i--)
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
fprintf(stderr," <- CheckBlockHeader\n");
if ( chainActive.Tip() != 0 )
{
hash = chainActive.Tip()->GetBlockHash();
for (i=31; i>=0; i--)
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
fprintf(stderr," <- chainTip\n");
}
}
if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60)
return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new");
// Check block version
@@ -3241,9 +3276,15 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
// Check transactions
BOOST_FOREACH(const CTransaction& tx, block.vtx)
{
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());
return error("CheckBlock: komodo_validate_interest failed");
}
if (!CheckTransaction(tx, state, verifier))
return error("CheckBlock(): CheckTransaction failed");
}
unsigned int nSigOps = 0;
BOOST_FOREACH(const CTransaction& tx, block.vtx)
{
@@ -3320,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(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(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

@@ -183,7 +183,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
pblock->nTime = GetAdjustedTime();
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
CCoinsViewCache view(pcoinsTip);
uint32_t expired;
// Priority order to process transactions
list<COrphan> vOrphan; // list memory doesn't move
map<uint256, vector<COrphan*> > mapDependers;
@@ -201,9 +202,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
? nMedianTimePast
: pblock->GetBlockTime();
if (tx.IsCoinBase() || !IsFinalTx(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. need to verify this works\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;
@@ -430,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");
}
}
@@ -505,7 +513,19 @@ static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& rese
{
LOCK(cs_main);
if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash())
{
uint256 hash; int32_t i;
hash = pblock->hashPrevBlock;
for (i=31; i>=0; i--)
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
fprintf(stderr," <- prev (stale)\n");
hash = chainActive.Tip()->GetBlockHash();
for (i=31; i>=0; i--)
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
fprintf(stderr," <- chainTip (stale)\n");
return error("KomodoMiner: generated block is stale");
}
}
// Remove key from key pool
@@ -671,7 +691,7 @@ void static BitcoinMiner(CWallet *pwallet)
if ( externalflag == 0 && i != 66 )
printf("VIOLATION at %d\n",i);
for (i=0; i<66; i++)
{break;
{ break;
for (j=0; j<33; j++)
printf("%02x",pubkeys[i][j]);
printf(" p%d -> %d\n",i,komodo_minerid(pindexPrev->nHeight-i,pubkeys[i]));

View File

@@ -111,7 +111,7 @@ int8_t komodo_minerid(int32_t height,uint8_t *pubkey33);
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height);
extern int32_t KOMODO_CHOSEN_ONE;
#define KOMODO_ELECTION_GAP 2000
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height);
int32_t KOMODO_LOADINGBLOCKS;

View File

@@ -406,7 +406,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin
int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel);
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height);
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len);
uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n);
//uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n);
int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width);
int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);