@@ -325,7 +325,19 @@ void FinalizeNode(NodeId nodeid) {
325
325
326
326
mapNodeState.erase (nodeid);
327
327
}
328
-
328
+
329
+ void LimitMempoolSize (CTxMemPool& pool, size_t limit, unsigned long age)
330
+ {
331
+ /* int expired = pool.Expire(GetTime() - age);
332
+ if (expired != 0)
333
+ LogPrint("mempool", "Expired %i transactions from the memory pool\n", expired);
334
+
335
+ std::vector<uint256> vNoSpendsRemaining;
336
+ pool.TrimToSize(limit, &vNoSpendsRemaining);
337
+ BOOST_FOREACH(const uint256& removed, vNoSpendsRemaining)
338
+ pcoinsTip->Uncache(removed);*/
339
+ }
340
+
329
341
// Requires cs_main.
330
342
// Returns a bool indicating whether we requested this block.
331
343
bool MarkBlockAsReceived (const uint256& hash) {
@@ -708,132 +720,11 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
708
720
return true ;
709
721
}
710
722
711
- uint32_t komodo_heightstamp (int32_t height);
712
-
713
- int32_t komodo_validate_interest (uint32_t *expiredp,const CTransaction& tx,int32_t txheight,uint32_t prevblocktime,int32_t strictflag)
714
- {
715
- int32_t i; uint32_t cmptime=0 ,tiptime=0 ,locktime=0 ; uint64_t value=0 ; CBlockIndex *tip=0 ;
716
- if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0 ] == 0 && (int64_t )tx.nLockTime >= LOCKTIME_THRESHOLD )// 1473793441 )
717
- {
718
- // locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0);
719
- LOCK (cs_main);
720
- CTransaction gettx; uint256 hashBlock; CBlockIndex *pindex,*previndex;
721
- if ( GetTransaction (tx.GetHash (),gettx,hashBlock,true ) )
722
- {
723
- if ( (pindex= mapBlockIndex[hashBlock]) != 0 )
724
- {
725
- txheight = pindex->nHeight ;
726
- prevblocktime = pindex->nTime ;
727
- if ( (previndex= pindex->pprev ) != 0 )
728
- prevblocktime = previndex->nTime ;
729
- }
730
- }
731
- if ( prevblocktime == 0 )
732
- {
733
- if ( chainActive.Tip () != 0 )
734
- {
735
- if ( strictflag == 0 || txheight == 0 || txheight == chainActive.Tip ()->nHeight +1 )
736
- prevblocktime = chainActive.Tip ()->nTime ;
737
- else
738
- {
739
- fprintf (stderr," couldnt get prevblocktime for [%d] tiptime.%u\n " ,txheight,chainActive.Tip ()->nTime );
740
- return (-1 );
741
- }
742
- }
743
- }
744
- if ( prevblocktime == 0 )
745
- return (-1 );
746
- cmptime = prevblocktime + 600 ;
747
- /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0;
748
- prevblocktime = 0;
749
- locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0);
750
- if ( (txheight= txheightarg) == 0 )
751
- txheight = chainActive.Tip()->nHeight + 1;
752
- if ( (prev= komodo_chainactive(txheight-1)) != 0 )
753
- prevblocktime = prev->nTime;
754
- if ( tiptime == 0 )
755
- tiptime = (int32_t)chainActive.Tip()->nTime;
756
- if ( txheighttime == 0 )
757
- {
758
- static uint32_t counter0;
759
- txheighttime = chainActive.Tip()->nTime;
760
- if ( counter0++ < 3 )
761
- fprintf(stderr,"error getting txheighttime, set to tiptime.%u\n",txheighttime);
762
- }
763
- if ( txheighttime != 0 && txblocktime != 0 )
764
- {
765
- cmptime = txheighttime;
766
- if ( txblocktime < cmptime )
767
- cmptime = txblocktime;
768
- }
769
- else if ( (cmptime= txheighttime) == 0 )
770
- cmptime = txblocktime;
771
- if ( tiptime != 0 && tiptime < cmptime )
772
- cmptime = tiptime;
773
- if ( locktime != 0 && prevblocktime != 0 && prevblocktime < cmptime )
774
- cmptime = prevblocktime;
775
- if ( (prev= komodo_chainactive(txheight-1)) != 0 )
776
- cmptime = prev->nTime + 600;
777
- if ( cmptime >= 1490159171 - 24*3600 )
778
- {
779
- if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 )
780
- {
781
- if ( txheighttime > 1490159171 || (locktime == 0 && txheighttime >= 1490159171) ) // 246748
782
- {
783
- if ( tx.nLockTime != 1477258935 )
784
- {
785
- fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u/%u vs nBlockTime %u txheighttime.%u tiptime.%u txb.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,locktime,(uint32_t)chainActive.Tip()->nTime,txheighttime,tiptime,txblocktime,cmptime);
786
- }
787
- if ( expiredp != 0 )
788
- *expiredp = cmptime-3600;
789
- return(-1);
790
- } 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);
791
- }
792
- }
793
- if ( (cmptime= prevblocktime) == 0 )
794
- {
795
- if ( (cmptime= komodo_heightstamp(txheight-1)) == 0 )
796
- {
797
- fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheight-1,cmptime);
798
- return(-1);
799
- }
800
- }*/
801
- if ( cmptime > 0 && txheight > 246748 )
802
- {
803
- if ( txheight < 247205 )
804
- cmptime -= 600 ;
805
- if ( (int64_t )tx.nLockTime < cmptime-3600 )
806
- {
807
- if ( tx.nLockTime != 1477258935 )
808
- {
809
- // fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime);
810
- }
811
- if ( expiredp != 0 )
812
- *expiredp = cmptime-3600 ;
813
- return (-1 );
814
- }
815
- }
816
- if ( strictflag != 0 )
817
- fprintf (stderr," validateinterest strict.%d accept.%d [%d] tip.%d locktime %u cmp.%u\n " ,strictflag,(int32_t )txheight,(int32_t )(tx.nLockTime - (cmptime-3600 )),(int32_t )(tip != 0 ? tip->nHeight : 0 ),(int32_t )tx.nLockTime ,cmptime);
818
- }
819
- return (0 );
820
- }
821
-
822
- bool IsFinalTx (uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags,uint32_t prevblocktime)
723
+ bool IsFinalTx (const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
823
724
{
824
725
int32_t i;
825
- if ( expiredp != 0 )
826
- *expiredp = 0 ;
827
726
if (tx.nLockTime == 0 )
828
727
return true ;
829
- if ( ASSETCHAINS_SYMBOL[0 ] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t )tx.nLockTime >= LOCKTIME_THRESHOLD )// && nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600
830
- {
831
- if ( komodo_validate_interest (expiredp,tx,nBlockHeight,prevblocktime < nBlockTime ? nBlockTime : prevblocktime,1 ) < 0 ) // if ( nBlockTime >= 1490159171 ) // 246748
832
- {
833
- 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);
834
- return (false ); // need to prevent pastdating tx
835
- } // else fprintf(stderr,"IsFinalTx accept.%d locktime %u vs nBlockTime %u\n",(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime);
836
- }
837
728
if ((int64_t )tx.nLockTime < ((int64_t )tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t )nBlockHeight : nBlockTime))
838
729
return true ;
839
730
BOOST_FOREACH (const CTxIn& txin, tx.vin )
@@ -879,7 +770,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags)
879
770
? chainActive.Tip ()->GetMedianTimePast ()
880
771
: GetAdjustedTime ();
881
772
882
- return IsFinalTx (0 , tx, nBlockHeight, nBlockTime,flags,chainActive. Tip ()-> nTime );
773
+ return IsFinalTx (tx, nBlockHeight, nBlockTime);
883
774
}
884
775
885
776
/* *
@@ -984,11 +875,6 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state,libzcash::
984
875
static uint256 array[64 ]; static int32_t numbanned,indallvouts; int32_t j,k,n;
985
876
if ( *(int32_t *)&array[0 ] == 0 )
986
877
numbanned = komodo_bannedset (&indallvouts,array,(int32_t )(sizeof (array)/sizeof (*array)));
987
- /* if ( komodo_validate_interest(tx) < 0 )
988
- {
989
- fprintf(stderr,"CheckTransaction komodo_validate_interest error\n");
990
- return(false);
991
- }*/
992
878
n = tx.vin .size ();
993
879
for (j=0 ; j<n; j++)
994
880
{
@@ -1225,11 +1111,11 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
1225
1111
if (pfMissingInputs)
1226
1112
*pfMissingInputs = false ;
1227
1113
auto verifier = libzcash::ProofVerifier::Strict ();
1228
- /* if ( komodo_validate_interest(tx) < 0 ) // called from CheckFinalTx() below
1114
+ if ( komodo_validate_interest (tx,chainActive. Tip ()-> nHeight + 1 ,chainActive. Tip ()-> GetMedianTimePast () + 777 , 0 ) < 0 )
1229
1115
{
1230
- fprintf(stderr,"komodo_validate_interest failure\n");
1116
+ fprintf (stderr," AcceptToMemoryPool komodo_validate_interest failure\n " );
1231
1117
return error (" AcceptToMemoryPool: komodo_validate_interest failed" );
1232
- }*/
1118
+ }
1233
1119
if (!CheckTransaction (tx, state, verifier))
1234
1120
{
1235
1121
fprintf (stderr," accept failure.0\n " );
@@ -2407,27 +2293,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
2407
2293
for (unsigned int i = 0 ; i < block.vtx .size (); i++)
2408
2294
{
2409
2295
const CTransaction &tx = block.vtx [i];
2410
- uint32_t prevtime = 0 ; CBlockIndex *ptr;
2411
- if ( (ptr= pindex->pprev ) != 0 )
2412
- prevtime = ptr->nTime ;
2413
- /* if ( chainActive.Tip() != 0 && height == chainActive.Tip()->nHeight+1 )
2414
- prevtime = chainActive.Tip()->nTime;
2415
- else if ( pindex != 0 )
2416
- {
2417
- if ( (ptr= pindex->pprev) != 0 )
2418
- prevtime = ptr->nTime;
2419
- }
2420
- if ( prevtime == 0 )
2421
- {
2422
- if ( height > 0 && (ptr= chainActive[height-1]) != 0 )
2423
- prevtime = ptr->nTime;
2424
- }*/
2425
- if ( komodo_validate_interest (0 ,tx,pindex->nHeight ,prevtime,2 ) < 0 )
2426
- {
2427
- // fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\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(),chainActive.Tip()->nTime,prevtime);
2428
- return state.DoS (10 , error (" ConnectBlock(): validate interest failed" ),REJECT_INVALID, " bad-apr-calc" );
2429
- }
2430
-
2431
2296
nInputs += tx.vin .size ();
2432
2297
nSigOps += GetLegacySigOpCount (tx);
2433
2298
if (nSigOps > MAX_BLOCK_SIGOPS)
@@ -3060,6 +2925,7 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) {
3060
2925
return false ;
3061
2926
}
3062
2927
}
2928
+ // LimitMempoolSize(mempool, GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60);
3063
2929
3064
2930
// The resulting new best tip may not be in setBlockIndexCandidates anymore, so
3065
2931
// add it again.
@@ -3361,24 +3227,8 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
3361
3227
// Check transactions
3362
3228
BOOST_FOREACH (const CTransaction& tx, block.vtx )
3363
3229
{
3364
- uint32_t prevtime = 0 ; CBlockIndex *ptr;
3365
- if ( chainActive.Tip () != 0 && height == chainActive.Tip ()->nHeight +1 )
3366
- prevtime = chainActive.Tip ()->nTime ;
3367
- else if ( pindex != 0 )
3368
- {
3369
- if ( (ptr= pindex->pprev ) != 0 )
3370
- prevtime = ptr->nTime ;
3371
- }
3372
- if ( prevtime == 0 )
3373
- {
3374
- if ( height > 0 && (ptr= chainActive[height-1 ]) != 0 )
3375
- prevtime = ptr->nTime ;
3376
- }
3377
- if ( komodo_validate_interest (0 ,tx,height,prevtime,0 ) < 0 )
3378
- {
3379
- // fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\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(),chainActive.Tip()->nTime,prevtime);
3380
- return error (" CheckBlock: komodo_validate_interest failed" );
3381
- }
3230
+ if ( komodo_validate_interest (tx,komodo_block2height ((CBlock *)&block),block.nTime ,1 ) < 0 )
3231
+ return error (" CheckBlock: komodo_validate_interest failed" );
3382
3232
if (!CheckTransaction (tx, state, verifier))
3383
3233
return error (" CheckBlock(): CheckTransaction failed" );
3384
3234
}
@@ -3458,7 +3308,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
3458
3308
int64_t nLockTimeCutoff = (nLockTimeFlags & LOCKTIME_MEDIAN_TIME_PAST)
3459
3309
? pindexPrev->GetMedianTimePast ()
3460
3310
: block.GetBlockTime ();
3461
- if (!IsFinalTx (0 , tx, nHeight, nLockTimeCutoff, 0 *STANDARD_LOCKTIME_VERIFY_FLAGS,pindexPrev-> nTime )) {
3311
+ if (!IsFinalTx (tx, nHeight, nLockTimeCutoff)) {
3462
3312
return state.DoS (10 , error (" %s: contains a non-final transaction" , __func__), REJECT_INVALID, " bad-txns-nonfinal" );
3463
3313
}
3464
3314
}
0 commit comments