Skip to content

Commit

Permalink
Merge pull request #438 from NAVCoin/synctx-fix
Browse files Browse the repository at this point in the history
Simplification of SyncTransaction
  • Loading branch information
proletesseract authored Apr 24, 2019
2 parents 4de0827 + 53d24ac commit 4041e3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 54 deletions.
4 changes: 4 additions & 0 deletions doc/release-notes/release-notes-4.6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ This PR adds a new RPC command to export the existing master private key encoded
`dumpmnemonic` It admits an argument specifying the language.
Support for two new wallet options (`-importmnemonic` and `-mnemoniclanguage`) have also been added to allow to create a new wallet from the specified mnemonic.

## Fix wrong balance after orphan stakes
<[Pull Request 438](https://github.com/NAVCoin/navcoin-core/pull/438)>
This PR fixes an historical issue which made the wallet show a wrong balance after orphan stakes.

## Other updates to the NavCoin client, docs and codebase

- Update FreeType depend file to 2.7.1 <[Pull Request 433](https://github.com/NAVCoin/navcoin-core/pull/433)> <[Commit 6025758](60257582df85c07b794ceb186e2289eada4d3832)>
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2033,8 +2033,14 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight,
log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S",
pindexNew->GetBlockTime()));
CBlock block;
CBlockIndex *tip = chainActive.Tip();
assert (tip);
if (ReadBlockFromDisk(block, pindexNew, Params().GetConsensus())) {
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
SyncWithWallets(tx, tip, NULL, false);
}
}
LogPrintf("%s: current best=%s height=%d log2_work=%.8g date=%s\n", __func__,
tip->GetBlockHash().ToString(), chainActive.Height(), log(tip->nChainWork.getdouble())/log(2.0),
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", tip->GetBlockTime()));
Expand Down
59 changes: 5 additions & 54 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ bool CWallet::IsSpent(const uint256& hash, unsigned int n) const
std::map<uint256, CWalletTx>::const_iterator mit = mapWallet.find(wtxid);
if (mit != mapWallet.end()) {
int depth = mit->second.GetDepthInMainChain();
if (depth > 0 || (depth == 0 && !mit->second.isAbandoned()))
if (depth > 0 || (depth == 0 && !mit->second.isAbandoned() && !mit->second.IsCoinStake()))
return true; // Spent
}
}
Expand Down Expand Up @@ -1542,68 +1542,19 @@ void CWallet::SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex,
{
LOCK2(cs_main, cs_wallet);

if (!fConnect)
{
// wallets need to refund inputs when disconnecting coinstake
if (tx.IsCoinStake())
{
if (IsFromMe(tx))
{
// Do not flush the wallet here for performance reasons
CWalletDB walletdb(strWalletFile, "r+", false);

if (mapWallet.count(tx.hash))
{
CWalletTx& wtx = mapWallet[tx.hash];
wtx.MarkDirty();
walletdb.WriteTx(wtx);
}
else
{
LogPrintf("SyncTransaction : Warning: Could not find %s in wallet. Trying to refund someone else's tx?", tx.hash.ToString());
}

LogPrintf("SyncTransaction : Refunding inputs of orphan tx %s\n",tx.hash.ToString());

BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
if (mapWallet.count(txin.prevout.hash))
mapWallet[txin.prevout.hash].MarkDirty();
}
}
}
}

bool isMine = true;

if (!AddToWalletIfInvolvingMe(tx, pblock, true))
isMine = false; // Not one of ours
return; // Not one of ours

// If a transaction changes 'conflicted' state, that changes the balance
// available of the outputs it spends. So force those to be
// recomputed, also:

if(isMine == true)
{
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
if (mapWallet.count(txin.prevout.hash))
mapWallet[txin.prevout.hash].MarkDirty();
}
}

if (!fConnect && tx.IsCoinStake() && IsFromMe(tx))
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
AbandonTransaction(tx.hash);
LogPrintf("SyncTransaction : Removing tx %s from mapTxSpends\n",tx.hash.ToString());
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
mapTxSpends.erase(txin.prevout);
}
if (mapWallet.count(txin.prevout.hash))
mapWallet[txin.prevout.hash].MarkDirty();
}
}


isminetype CWallet::IsMine(const CTxIn &txin) const
{
{
Expand Down

0 comments on commit 4041e3e

Please sign in to comment.