Commit 89aa9601 authored by Benjamin Allred's avatar Benjamin Allred Committed by presstab
Browse files

BlockUndo to treat coinstake as if it were coinbase

parent ca94b528
Showing with 13 additions and 13 deletions
+13 -13
......@@ -87,7 +87,7 @@ public:
int nVersion;
void FromTx(const CTransaction &tx, int nHeightIn) {
fBlockReward = tx.IsCoinBase();
fBlockReward = tx.IsCoinBase() || tx.IsCoinStake();
vout = tx.vout;
nHeight = nHeightIn;
nVersion = tx.nVersion;
......
......@@ -1831,7 +1831,7 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
if (coins->vout.size() == 0) {
CTxInUndo& undo = txundo.vprevout.back();
undo.nHeight = coins->nHeight;
undo.fCoinBase = coins->fBlockReward; //todo - make sure undo is correct
undo.fBlockReward = coins->fBlockReward; //todo - make sure undo is correct
undo.nVersion = coins->nVersion;
}
}
......@@ -2018,7 +2018,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
if (!coins->IsPruned())
fClean = fClean && error("DisconnectBlock() : undo data overwriting existing transaction");
coins->Clear();
coins->fBlockReward = undo.fCoinBase;
coins->fBlockReward = undo.fBlockReward;
coins->nHeight = undo.nHeight;
coins->nVersion = undo.nVersion;
} else {
......@@ -2460,7 +2460,7 @@ bool static DisconnectTip(CValidationState &state) {
if (tx.IsCoinBase() || tx.IsCoinStake() || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL))
mempool.remove(tx, removed, true);
}
mempool.removeCoinbaseSpends(pcoinsTip, pindexDelete->nHeight);
mempool.removeBlockRewardSpends(pcoinsTip, pindexDelete->nHeight);
mempool.check(pcoinsTip);
// Update chainActive and related variables.
UpdateTip(pindexDelete->pprev);
......
......@@ -485,9 +485,9 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
}
}
void CTxMemPool::removeCoinbaseSpends(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight)
void CTxMemPool::removeBlockRewardSpends(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight)
{
// Remove transactions spending a coinbase which are now immature
// Remove transactions spending a coinbase/coinstake which are now immature
LOCK(cs);
list<CTransaction> transactionsToRemove;
for (std::map<uint256, CTxMemPoolEntry>::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
......
......@@ -118,7 +118,7 @@ public:
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry);
void remove(const CTransaction &tx, std::list<CTransaction>& removed, bool fRecursive = false);
void removeCoinbaseSpends(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight);
void removeBlockRewardSpends(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight);
void removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed);
void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
std::list<CTransaction>& conflicts);
......
......@@ -20,22 +20,22 @@ class CTxInUndo
{
public:
CTxOut txout; // the txout data before being spent
bool fCoinBase; // if the outpoint was the last unspent: whether it belonged to a coinbase
bool fBlockReward; // if the outpoint was the last unspent: whether it belonged to a coinbase/coinstake
unsigned int nHeight; // if the outpoint was the last unspent: its height
int nVersion; // if the outpoint was the last unspent: its version
CTxInUndo() : txout(), fCoinBase(false), nHeight(0), nVersion(0) {}
CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn = false, unsigned int nHeightIn = 0, int nVersionIn = 0) : txout(txoutIn), fCoinBase(fCoinBaseIn), nHeight(nHeightIn), nVersion(nVersionIn) { }
CTxInUndo() : txout(), fBlockReward(false), nHeight(0), nVersion(0) {}
CTxInUndo(const CTxOut &txoutIn, bool fBlockRewardIn = false, unsigned int nHeightIn = 0, int nVersionIn = 0) : txout(txoutIn), fBlockReward(fBlockRewardIn), nHeight(nHeightIn), nVersion(nVersionIn) { }
unsigned int GetSerializeSize(int nType, int nVersion) const {
return ::GetSerializeSize(VARINT(nHeight*2+(fCoinBase ? 1 : 0)), nType, nVersion) +
return ::GetSerializeSize(VARINT(nHeight*2+(fBlockReward ? 1 : 0)), nType, nVersion) +
(nHeight > 0 ? ::GetSerializeSize(VARINT(this->nVersion), nType, nVersion) : 0) +
::GetSerializeSize(CTxOutCompressor(REF(txout)), nType, nVersion);
}
template<typename Stream>
void Serialize(Stream &s, int nType, int nVersion) const {
::Serialize(s, VARINT(nHeight*2+(fCoinBase ? 1 : 0)), nType, nVersion);
::Serialize(s, VARINT(nHeight*2+(fBlockReward ? 1 : 0)), nType, nVersion);
if (nHeight > 0)
::Serialize(s, VARINT(this->nVersion), nType, nVersion);
::Serialize(s, CTxOutCompressor(REF(txout)), nType, nVersion);
......@@ -46,7 +46,7 @@ public:
unsigned int nCode = 0;
::Unserialize(s, VARINT(nCode), nType, nVersion);
nHeight = nCode / 2;
fCoinBase = nCode & 1;
fBlockReward = nCode & 1;
if (nHeight > 0)
::Unserialize(s, VARINT(this->nVersion), nType, nVersion);
::Unserialize(s, REF(CTxOutCompressor(REF(txout))), nType, nVersion);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment