Skip to content

Commit c30b98d

Browse files
committed
[Core] Update money supply when disconnecting blocks too
1 parent 361e584 commit c30b98d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,8 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
20452045
bool fClean = true;
20462046

20472047
CBlockUndo blockUndo;
2048+
CAmount nValueOut = 0;
2049+
CAmount nValueIn = 0;
20482050
CDiskBlockPos pos = pindex->GetUndoPos();
20492051
if (pos.IsNull())
20502052
return error("DisconnectBlock() : no undo data available");
@@ -2081,9 +2083,11 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
20812083
return error("Failed to parse public spend");
20822084
}
20832085
serial = publicSpend.getCoinSerialNumber();
2086+
nValueIn += publicSpend.getDenomination() * COIN;
20842087
} else {
20852088
libzerocoin::CoinSpend spend = TxInToZerocoinSpend(txin);
20862089
serial = spend.getCoinSerialNumber();
2090+
nValueIn += spend.getDenomination() * COIN;
20872091
}
20882092

20892093
if (!zerocoinDB->EraseCoinSpend(serial))
@@ -2116,9 +2120,11 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
21162120
}
21172121
}
21182122
}
2123+
nValueOut += tx.GetValueOut();
21192124

21202125
uint256 hash = tx.GetHash();
21212126

2127+
21222128
// Check that all outputs are available and match the outputs in the block itself
21232129
// exactly. Note that transactions with only provably unspendable outputs won't
21242130
// have outputs available even in the block itself, so we handle that case
@@ -2169,8 +2175,14 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
21692175
coins->vout[out.n] = undo.txout;
21702176
}
21712177
}
2178+
2179+
if (!tx.HasZerocoinSpendInputs() && !tx.IsCoinBase() && view.HaveInputs(tx))
2180+
nValueIn += view.GetValueIn(tx);
21722181
}
21732182

2183+
// track money
2184+
nMoneySupply -= (nValueOut - nValueIn);
2185+
21742186
// move best block pointer to prevout block
21752187
view.SetBestBlock(pindex->pprev->GetBlockHash());
21762188

0 commit comments

Comments
 (0)