Merge pull request #895 from UdjinM6/ISKeepLock

Refactor InstantSend to use block count instead of local time
This commit is contained in:
Evan Duffield 2016-08-08 12:40:01 -07:00 committed by GitHub
commit 453c6628cd
4 changed files with 19 additions and 8 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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<uint256, CTransactionLock>::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)){

View File

@ -108,7 +108,7 @@ public:
int nBlockHeight;
uint256 txHash;
std::vector<CConsensusVote> vecConsensusVotes;
int nExpiration;
int nLockExpirationBlock;
int nTimeout;
bool VotesValid();