port expired transaction notify from Zcash. Issue #110

This commit is contained in:
DenioD
2020-05-19 10:03:53 +02:00
parent 15b2e598c6
commit f3a4f77368
5 changed files with 24 additions and 3 deletions

View File

@@ -399,6 +399,7 @@ std::string HelpMessage(HelpMessageMode mode)
#ifndef _WIN32
strUsage += HelpMessageOpt("-pid=<file>", strprintf(_("Specify pid file (default: %s)"), "komodod.pid"));
#endif
strUsage += HelpMessageOpt("-txexpirynotify=<cmd>", _("Execute command when transaction expires (%s in cmd is replaced by transaction id)"));
strUsage += HelpMessageOpt("-prune=<n>", strprintf(_("Reduce storage requirements by pruning (deleting) old blocks. This mode disables wallet support and is incompatible with -txindex. "
"Warning: Reverting this setting requires re-downloading the entire blockchain. "
"(default: 0 = disable pruning blocks, >%u = target size in MiB to use for block files)"), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024));
@@ -618,6 +619,14 @@ static void BlockNotifyCallback(const uint256& hashNewTip)
boost::thread t(runCommand, strCmd); // thread runs free
}
static void TxExpiryNotifyCallback(const uint256& txid)
{
std::string strCmd = GetArg("-txexpirynotify", "");
boost::replace_all(strCmd, "%s", txid.GetHex());
boost::thread t(runCommand, strCmd); // thread runs free
}
struct CImportingNow
{
CImportingNow() {
@@ -2114,6 +2123,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if (mapArgs.count("-blocknotify"))
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
if (mapArgs.count("-txexpirynotify"))
uiInterface.NotifyTxExpiration.connect(TxExpiryNotifyCallback);
if ( KOMODO_REWIND >= 0 )
{
uiInterface.InitMessage(_("Activating best chain..."));

View File

@@ -4210,7 +4210,11 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
mempool.removeForBlock(pblock->vtx, pindexNew->GetHeight(), txConflicted, !IsInitialBlockDownload());
// Remove transactions that expire at new block height from mempool
mempool.removeExpired(pindexNew->GetHeight());
auto ids = mempool.removeExpired(pindexNew->GetHeight());
for (auto id : ids) {
uiInterface.NotifyTxExpiration(id);
}
// Update chainActive & related variables.
UpdateTip(pindexNew);

View File

@@ -513,7 +513,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag);
extern char ASSETCHAINS_SYMBOL[];
void CTxMemPool::removeExpired(unsigned int nBlockHeight)
std::vector<uint256> CTxMemPool::removeExpired(unsigned int nBlockHeight)
{
CBlockIndex *tipindex;
// Remove expired txs from the mempool
@@ -528,11 +528,14 @@ void CTxMemPool::removeExpired(unsigned int nBlockHeight)
transactionsToRemove.push_back(tx);
}
}
std::vector<uint256> ids;
for (const CTransaction& tx : transactionsToRemove) {
list<CTransaction> removed;
remove(tx, removed, true);
ids.push_back(tx.GetHash());
LogPrint("mempool", "Removing expired txid: %s\n", tx.GetHash().ToString());
}
return ids;
}
/**

View File

@@ -218,7 +218,7 @@ public:
void removeWithAnchor(const uint256 &invalidRoot, ShieldedType type);
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
void removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed);
void removeExpired(unsigned int nBlockHeight);
std::vector<uint256> removeExpired(unsigned int nBlockHeight);
void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
std::list<CTransaction>& conflicts, bool fCurrentEstimate = true);
void removeWithoutBranchId(uint32_t nMemPoolBranchId);

View File

@@ -98,6 +98,9 @@ public:
/** New block has been accepted */
boost::signals2::signal<void (const uint256& hash)> NotifyBlockTip;
/** Transaction expired */
boost::signals2::signal<void (const uint256& txid)> NotifyTxExpiration;
};
extern CClientUIInterface uiInterface;