From 7f89bba83e43df95c86a1218464aefaae3957dc8 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 29 Jun 2016 21:20:18 +0300 Subject: [PATCH] Refactor InstantSend to use block count instead of local time to set expiration limit - nInstantSendKeepLock. Also make it (and number of blocks to reprocess in case of a conflict) a part of Consensus params and set it to lower numbers for testnet/regtest to be able to break things easier there. Bump MIN_INSTANTX_PROTO_VERSION --- src/chainparams.cpp | 6 ++++++ src/consensus/params.h | 2 ++ src/instantx.cpp | 17 ++++++++++------- src/instantx.h | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 5ca40b779..9b382ebb1 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -76,6 +76,8 @@ public: consensus.nMasternodePaymentsStartBlock = 100000; // not true, but it's ok as long as it's less then nMasternodePaymentsIncreaseBlock consensus.nMasternodePaymentsIncreaseBlock = 158000; // actual historical value consensus.nMasternodePaymentsIncreasePeriod = 576*30; // 17280 - actual historical value + consensus.nInstantSendKeepLock = 24; + consensus.nInstantSendReprocessBlocks = 15; consensus.nBudgetPaymentsStartBlock = 328008; // actual historical value consensus.nBudgetPaymentsCycleBlocks = 16616; // ~(60*24*30)/2.6, actual number of blocks per month is 200700 / 12 = 16725 consensus.nBudgetPaymentsWindowBlocks = 100; @@ -191,6 +193,8 @@ public: consensus.nMasternodePaymentsStartBlock = 10000; // not true, but it's ok as long as it's less then nMasternodePaymentsIncreaseBlock consensus.nMasternodePaymentsIncreaseBlock = 46000; consensus.nMasternodePaymentsIncreasePeriod = 576; + consensus.nInstantSendKeepLock = 6; + consensus.nInstantSendReprocessBlocks = 4; consensus.nBudgetPaymentsStartBlock = 78476; consensus.nBudgetPaymentsCycleBlocks = 50; consensus.nBudgetPaymentsWindowBlocks = 10; @@ -288,6 +292,8 @@ public: consensus.nMasternodePaymentsStartBlock = 240; consensus.nMasternodePaymentsIncreaseBlock = 350; consensus.nMasternodePaymentsIncreasePeriod = 10; + consensus.nInstantSendKeepLock = 6; + consensus.nInstantSendReprocessBlocks = 4; consensus.nBudgetPaymentsStartBlock = 1000; consensus.nBudgetPaymentsCycleBlocks = 50; consensus.nBudgetPaymentsWindowBlocks = 100; diff --git a/src/consensus/params.h b/src/consensus/params.h index b860c58d7..5f0d44ae5 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -40,6 +40,8 @@ struct Params { int nMasternodePaymentsStartBlock; int nMasternodePaymentsIncreaseBlock; int nMasternodePaymentsIncreasePeriod; // in blocks + int nInstantSendKeepLock; // in blocks + int nInstantSendReprocessBlocks; int nBudgetPaymentsStartBlock; int nBudgetPaymentsCycleBlocks; int nBudgetPaymentsWindowBlocks; diff --git a/src/instantx.cpp b/src/instantx.cpp index 9e949f015..484d43dd8 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -247,7 +247,8 @@ int64_t CreateNewLock(CTransaction tx) CTransactionLock newLock; newLock.nBlockHeight = nBlockHeight; - newLock.nExpiration = GetTime()+(60*60); //locks expire after 60 minutes (24 confirmations) + //locks expire after nInstantSendKeepLock confirmations + newLock.nLockExpirationBlock = chainActive.Height() + Params().GetConsensus().nInstantSendKeepLock; newLock.nTimeout = GetTime()+(60*5); newLock.txHash = tx.GetHash(); mapTxLocks.insert(std::make_pair(tx.GetHash(), newLock)); @@ -338,7 +339,8 @@ bool ProcessConsensusVote(CNode* pnode, CConsensusVote& vote) CTransactionLock newLock; newLock.nBlockHeight = 0; - newLock.nExpiration = GetTime()+(60*60); + //locks expire after nInstantSendKeepLock confirmations + newLock.nLockExpirationBlock = chainActive.Height() + Params().GetConsensus().nInstantSendKeepLock; newLock.nTimeout = GetTime()+(60*5); newLock.txHash = vote.txHash; mapTxLocks.insert(std::make_pair(vote.txHash, newLock)); @@ -433,10 +435,10 @@ bool FindConflictingLocks(CTransaction& tx) LogPrintf("FindConflictingLocks -- found two complete conflicting locks, removing both: txid=%s, txin=%s", tx.GetHash().ToString(), mapLockedInputs[txin.prevout].ToString()); if(mapTxLocks.count(tx.GetHash())) - mapTxLocks[tx.GetHash()].nExpiration = GetTime(); + mapTxLocks[tx.GetHash()].nLockExpirationBlock = -1; if(mapTxLocks.count(mapLockedInputs[txin.prevout])) - mapTxLocks[mapLockedInputs[txin.prevout]].nExpiration = GetTime(); + mapTxLocks[mapLockedInputs[txin.prevout]].nLockExpirationBlock = -1; return true; } @@ -452,8 +454,8 @@ void ResolveConflicts(CTransaction& tx) if (IsLockedInstandSendTransaction(tx.GetHash()) && !FindConflictingLocks(tx)) { //????? LogPrintf("ResolveConflicts -- Found Existing Complete IX Lock, resolving...\n"); - //reprocess the last 15 blocks - ReprocessBlocks(15); + //reprocess the last nInstantSendReprocessBlocks blocks + ReprocessBlocks(Params().GetConsensus().nInstantSendReprocessBlocks); if(!mapTxLockReq.count(tx.GetHash())) mapTxLockReq.insert(std::make_pair(tx.GetHash(), tx)); //????? } @@ -480,9 +482,10 @@ void CleanTransactionLocksList() std::map::iterator it = mapTxLocks.begin(); + int nHeight = chainActive.Height(); while(it != mapTxLocks.end()) { CTransactionLock &txLock = it->second; - if(GetTime() > txLock.nExpiration){ + if(GetTime() > txLock.nLockExpirationBlock) { LogPrintf("Removing old transaction lock: txid=%s\n", txLock.txHash.ToString()); if(mapTxLockReq.count(txLock.txHash)){ diff --git a/src/instantx.h b/src/instantx.h index 7e132879e..2ff92446e 100644 --- a/src/instantx.h +++ b/src/instantx.h @@ -108,7 +108,7 @@ public: int nBlockHeight; uint256 txHash; std::vector vecConsensusVotes; - int nExpiration; + int nLockExpirationBlock; int nTimeout; bool VotesValid();