Skip to content

Commit

Permalink
Keep track of when IS locks were mined
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Apr 5, 2019
1 parent 20ec1de commit d6e7758
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/llmq/quorums_instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ void CInstantSendDb::RemoveInstantSendLock(const uint256& hash, CInstantSendLock
}
}

void CInstantSendDb::WriteInstantSendLockMined(const uint256& hash, int nHeight)
{
db.Write(std::make_tuple(std::string("is_m"), std::numeric_limits<int>::max() - nHeight, hash), true);
}

void CInstantSendDb::RemoveInstantSendLockMined(const uint256& hash, int nHeight)
{
db.Erase(std::make_tuple(std::string("is_m"), std::numeric_limits<int>::max() - nHeight, hash));
}

CInstantSendLockPtr CInstantSendDb::GetInstantSendLockByHash(const uint256& hash)
{
CInstantSendLockPtr ret;
Expand Down Expand Up @@ -743,9 +753,23 @@ void CInstantSendManager::SyncTransaction(const CTransaction& tx, const CBlockIn
return;
}

bool locked = IsLocked(tx.GetHash());
uint256 islockHash;
{
LOCK(cs);
islockHash = db.GetInstantSendLockHashByTxid(tx.GetHash());

// update DB about when an IS lock was mined
if (!islockHash.IsNull() && pindex) {
if (posInBlock == CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK) {
db.RemoveInstantSendLockMined(islockHash, pindex->nHeight);
} else {
db.WriteInstantSendLockMined(islockHash, pindex->nHeight);
}
}
}

bool chainlocked = pindex && chainLocksHandler->HasChainLock(pindex->nHeight, pindex->GetBlockHash());
if (locked || chainlocked) {
if (!islockHash.IsNull() || chainlocked) {
RetryLockTxs(tx.GetHash());
} else {
ProcessTx(tx, Params().GetConsensus());
Expand Down
3 changes: 3 additions & 0 deletions src/llmq/quorums_instantsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class CInstantSendDb
void WriteNewInstantSendLock(const uint256& hash, const CInstantSendLock& islock);
void RemoveInstantSendLock(const uint256& hash, CInstantSendLockPtr islock);

void WriteInstantSendLockMined(const uint256& hash, int nHeight);
void RemoveInstantSendLockMined(const uint256& hash, int nHeight);

CInstantSendLockPtr GetInstantSendLockByHash(const uint256& hash);
uint256 GetInstantSendLockHashByTxid(const uint256& txid);
CInstantSendLockPtr GetInstantSendLockByTxid(const uint256& txid);
Expand Down

0 comments on commit d6e7758

Please sign in to comment.