Browse Source

Prevent relaying expired tx

pull/4/head
jl777 6 years ago
parent
commit
bd070d8bce
  1. 6
      src/komodo_bitcoind.h
  2. 1
      src/komodo_defs.h
  3. 4
      src/komodo_interest.h
  4. 13
      src/wallet/wallet.cpp

6
src/komodo_bitcoind.h

@ -1033,16 +1033,16 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_
{
if ( txheight < 247205 )
cmptime -= 16000;
if ( (int64_t)tx.nLockTime < cmptime-3600 )
if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME )
{
if ( tx.nLockTime != 1477258935 && dispflag != 0 )
{
fprintf(stderr,"komodo_validate_interest.%d reject.%d [%d] locktime %u cmp2.%u\n",dispflag,txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime);
fprintf(stderr,"komodo_validate_interest.%d reject.%d [%d] locktime %u cmp2.%u\n",dispflag,txheight,(int32_t)(tx.nLockTime - (cmptime-KOMODO_MAXMEMPOOLTIME)),(uint32_t)tx.nLockTime,cmptime);
}
return(-1);
}
if ( 0 && dispflag != 0 )
fprintf(stderr,"validateinterest.%d accept.%d [%d] locktime %u cmp2.%u\n",dispflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime);
fprintf(stderr,"validateinterest.%d accept.%d [%d] locktime %u cmp2.%u\n",dispflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-KOMODO_MAXMEMPOOLTIME)),(int32_t)tx.nLockTime,cmptime);
}
}
return(0);

1
src/komodo_defs.h

@ -6,5 +6,6 @@
#define ROUNDROBIN_DELAY 61
#define KOMODO_ASSETCHAIN_MAXLEN 65
#define KOMODO_LIMITED_NETWORKSIZE 4
#define KOMODO_MAXMEMPOOLTIME 3600 // affects consensus
#endif

4
src/komodo_interest.h

@ -83,13 +83,13 @@ uint64_t komodo_moneysupply(int32_t height)
uint64_t _komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
{
int32_t minutes; uint64_t interest = 0;
if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime > nLockTime && (minutes= (tiptime - nLockTime) / 60) >= 60 )
if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime > nLockTime && (minutes= (tiptime - nLockTime) / 60) >= (KOMODO_MAXMEMPOOLTIME/60) )
{
if ( minutes > 365 * 24 * 60 )
minutes = 365 * 24 * 60;
if ( txheight >= 1000000 && minutes > 31 * 24 * 60 )
minutes = 31 * 24 * 60;
minutes -= 59;
minutes -= ((KOMODO_MAXMEMPOOLTIME/60) - 1);
interest = ((nValue / 10512000) * minutes);
}
return(interest);

13
src/wallet/wallet.cpp

@ -1887,7 +1887,9 @@ bool CWalletTx::RelayWalletTransaction()
assert(pwallet->GetBroadcastTransactions());
if (!IsCoinBase())
{
if (GetDepthInMainChain() == 0) {
if (GetDepthInMainChain() == 0)
{
// if tx is expired, dont relay
LogPrintf("Relaying wtx %s\n", GetHash().ToString());
RelayTransaction((CTransaction)*this);
return true;
@ -2102,12 +2104,21 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime)
LOCK(cs_wallet);
// Sort them in chronological order
multimap<unsigned int, CWalletTx*> mapSorted;
uint32_t now = (uint32_t)time(NULL);
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
{
CWalletTx& wtx = item.second;
// Don't rebroadcast if newer than nTime:
if (wtx.nTimeReceived > nTime)
continue;
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
if ( wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-KOMODO_MAXMEMPOOLTIME )
{
LogPrintf("skip Relaying wtx %s nLockTime %u vs now.%u\n", GetHash().ToString(),(uint32_t)wtx.nLockTime,now);
continue;
}
}
mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx));
}
BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)

Loading…
Cancel
Save