Skip to content

Commit 4041e3e

Browse files
Merge pull request #438 from NAVCoin/synctx-fix
Simplification of SyncTransaction
2 parents 4de0827 + 53d24ac commit 4041e3e

3 files changed

Lines changed: 15 additions & 54 deletions

File tree

doc/release-notes/release-notes-4.6.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ This PR adds a new RPC command to export the existing master private key encoded
3030
`dumpmnemonic` It admits an argument specifying the language.
3131
Support for two new wallet options (`-importmnemonic` and `-mnemoniclanguage`) have also been added to allow to create a new wallet from the specified mnemonic.
3232

33+
## Fix wrong balance after orphan stakes
34+
<[Pull Request 438](https://github.com/NAVCoin/navcoin-core/pull/438)>
35+
This PR fixes an historical issue which made the wallet show a wrong balance after orphan stakes.
36+
3337
## Other updates to the NavCoin client, docs and codebase
3438

3539
- Update FreeType depend file to 2.7.1 <[Pull Request 433](https://github.com/NAVCoin/navcoin-core/pull/433)> <[Commit 6025758](60257582df85c07b794ceb186e2289eada4d3832)>

src/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,8 +2033,14 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
20332033
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight,
20342034
log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S",
20352035
pindexNew->GetBlockTime()));
2036+
CBlock block;
20362037
CBlockIndex *tip = chainActive.Tip();
20372038
assert (tip);
2039+
if (ReadBlockFromDisk(block, pindexNew, Params().GetConsensus())) {
2040+
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
2041+
SyncWithWallets(tx, tip, NULL, false);
2042+
}
2043+
}
20382044
LogPrintf("%s: current best=%s height=%d log2_work=%.8g date=%s\n", __func__,
20392045
tip->GetBlockHash().ToString(), chainActive.Height(), log(tip->nChainWork.getdouble())/log(2.0),
20402046
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", tip->GetBlockTime()));

src/wallet/wallet.cpp

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ bool CWallet::IsSpent(const uint256& hash, unsigned int n) const
10211021
std::map<uint256, CWalletTx>::const_iterator mit = mapWallet.find(wtxid);
10221022
if (mit != mapWallet.end()) {
10231023
int depth = mit->second.GetDepthInMainChain();
1024-
if (depth > 0 || (depth == 0 && !mit->second.isAbandoned()))
1024+
if (depth > 0 || (depth == 0 && !mit->second.isAbandoned() && !mit->second.IsCoinStake()))
10251025
return true; // Spent
10261026
}
10271027
}
@@ -1542,68 +1542,19 @@ void CWallet::SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex,
15421542
{
15431543
LOCK2(cs_main, cs_wallet);
15441544

1545-
if (!fConnect)
1546-
{
1547-
// wallets need to refund inputs when disconnecting coinstake
1548-
if (tx.IsCoinStake())
1549-
{
1550-
if (IsFromMe(tx))
1551-
{
1552-
// Do not flush the wallet here for performance reasons
1553-
CWalletDB walletdb(strWalletFile, "r+", false);
1554-
1555-
if (mapWallet.count(tx.hash))
1556-
{
1557-
CWalletTx& wtx = mapWallet[tx.hash];
1558-
wtx.MarkDirty();
1559-
walletdb.WriteTx(wtx);
1560-
}
1561-
else
1562-
{
1563-
LogPrintf("SyncTransaction : Warning: Could not find %s in wallet. Trying to refund someone else's tx?", tx.hash.ToString());
1564-
}
1565-
1566-
LogPrintf("SyncTransaction : Refunding inputs of orphan tx %s\n",tx.hash.ToString());
1567-
1568-
BOOST_FOREACH(const CTxIn& txin, tx.vin)
1569-
{
1570-
if (mapWallet.count(txin.prevout.hash))
1571-
mapWallet[txin.prevout.hash].MarkDirty();
1572-
}
1573-
}
1574-
}
1575-
}
1576-
1577-
bool isMine = true;
1578-
15791545
if (!AddToWalletIfInvolvingMe(tx, pblock, true))
1580-
isMine = false; // Not one of ours
1546+
return; // Not one of ours
15811547

15821548
// If a transaction changes 'conflicted' state, that changes the balance
15831549
// available of the outputs it spends. So force those to be
15841550
// recomputed, also:
1585-
1586-
if(isMine == true)
1587-
{
1588-
BOOST_FOREACH(const CTxIn& txin, tx.vin)
1589-
{
1590-
if (mapWallet.count(txin.prevout.hash))
1591-
mapWallet[txin.prevout.hash].MarkDirty();
1592-
}
1593-
}
1594-
1595-
if (!fConnect && tx.IsCoinStake() && IsFromMe(tx))
1551+
BOOST_FOREACH(const CTxIn& txin, tx.vin)
15961552
{
1597-
AbandonTransaction(tx.hash);
1598-
LogPrintf("SyncTransaction : Removing tx %s from mapTxSpends\n",tx.hash.ToString());
1599-
BOOST_FOREACH(const CTxIn& txin, tx.vin)
1600-
{
1601-
mapTxSpends.erase(txin.prevout);
1602-
}
1553+
if (mapWallet.count(txin.prevout.hash))
1554+
mapWallet[txin.prevout.hash].MarkDirty();
16031555
}
16041556
}
16051557

1606-
16071558
isminetype CWallet::IsMine(const CTxIn &txin) const
16081559
{
16091560
{

0 commit comments

Comments
 (0)