Erase failed stake transaction from wallet to prevent slow return and loss of stake age

This commit is contained in:
Michael Toutonghi
2018-06-01 07:29:34 -07:00
parent 84d9a9b54a
commit ce379cf71a
3 changed files with 20 additions and 3 deletions

View File

@@ -3148,9 +3148,11 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
CTransaction &tx = block.vtx[i]; CTransaction &tx = block.vtx[i];
list<CTransaction> removed; list<CTransaction> removed;
CValidationState stateDummy; CValidationState stateDummy;
// don't keep staking transactions // don't keep staking or invalid transactions
if (tx.IsCoinBase() || (block.IsVerusPOSBlock() && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) if (tx.IsCoinBase() || (block.IsVerusPOSBlock() && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL))
{
mempool.remove(tx, removed, true); mempool.remove(tx, removed, true);
}
} }
if (anchorBeforeDisconnect != anchorAfterDisconnect) { if (anchorBeforeDisconnect != anchorAfterDisconnect) {
// The anchor may not change between block disconnects, // The anchor may not change between block disconnects,
@@ -3166,8 +3168,17 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
assert(pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), newTree)); assert(pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), newTree));
// Let wallets know transactions went from 1-confirmed to // Let wallets know transactions went from 1-confirmed to
// 0-confirmed or conflicted: // 0-confirmed or conflicted:
BOOST_FOREACH(const CTransaction &tx, block.vtx) { for (int i = 0; i < block.vtx.size(); i++)
SyncWithWallets(tx, NULL); {
CTransaction &tx = block.vtx[i];
if (block.IsVerusPOSBlock() && (i == (block.vtx.size() - 1)))
{
EraseFromWallets(tx.GetHash());
}
else
{
SyncWithWallets(tx, NULL);
}
} }
// Update cached incremental witnesses // Update cached incremental witnesses
//fprintf(stderr,"chaintip false\n"); //fprintf(stderr,"chaintip false\n");

View File

@@ -51,3 +51,7 @@ void UnregisterAllValidationInterfaces() {
void SyncWithWallets(const CTransaction &tx, const CBlock *pblock) { void SyncWithWallets(const CTransaction &tx, const CBlock *pblock) {
g_signals.SyncTransaction(tx, pblock); g_signals.SyncTransaction(tx, pblock);
} }
void EraseFromWallets(const uint256 &hash) {
g_signals.EraseTransaction(hash);
}

View File

@@ -28,6 +28,8 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn);
void UnregisterAllValidationInterfaces(); void UnregisterAllValidationInterfaces();
/** Push an updated transaction to all registered wallets */ /** Push an updated transaction to all registered wallets */
void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL); void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL);
/** Erase a transaction from all registered wallets */
void EraseFromWallets(const uint256 &hash);
class CValidationInterface { class CValidationInterface {
protected: protected: