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: ...@@ -87,7 +87,7 @@ public:
int nVersion; int nVersion;
void FromTx(const CTransaction &tx, int nHeightIn) { void FromTx(const CTransaction &tx, int nHeightIn) {
fBlockReward = tx.IsCoinBase(); fBlockReward = tx.IsCoinBase() || tx.IsCoinStake();
vout = tx.vout; vout = tx.vout;
nHeight = nHeightIn; nHeight = nHeightIn;
nVersion = tx.nVersion; nVersion = tx.nVersion;
......
...@@ -1831,7 +1831,7 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach ...@@ -1831,7 +1831,7 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
if (coins->vout.size() == 0) { if (coins->vout.size() == 0) {
CTxInUndo& undo = txundo.vprevout.back(); CTxInUndo& undo = txundo.vprevout.back();
undo.nHeight = coins->nHeight; 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; undo.nVersion = coins->nVersion;
} }
} }
...@@ -2018,7 +2018,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex ...@@ -2018,7 +2018,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
if (!coins->IsPruned()) if (!coins->IsPruned())
fClean = fClean && error("DisconnectBlock() : undo data overwriting existing transaction"); fClean = fClean && error("DisconnectBlock() : undo data overwriting existing transaction");
coins->Clear(); coins->Clear();
coins->fBlockReward = undo.fCoinBase; coins->fBlockReward = undo.fBlockReward;
coins->nHeight = undo.nHeight; coins->nHeight = undo.nHeight;
coins->nVersion = undo.nVersion; coins->nVersion = undo.nVersion;
} else { } else {
...@@ -2460,7 +2460,7 @@ bool static DisconnectTip(CValidationState &state) { ...@@ -2460,7 +2460,7 @@ bool static DisconnectTip(CValidationState &state) {
if (tx.IsCoinBase() || tx.IsCoinStake() || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) if (tx.IsCoinBase() || tx.IsCoinStake() || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL))
mempool.remove(tx, removed, true); mempool.remove(tx, removed, true);
} }
mempool.removeCoinbaseSpends(pcoinsTip, pindexDelete->nHeight); mempool.removeBlockRewardSpends(pcoinsTip, pindexDelete->nHeight);
mempool.check(pcoinsTip); mempool.check(pcoinsTip);
// Update chainActive and related variables. // Update chainActive and related variables.
UpdateTip(pindexDelete->pprev); UpdateTip(pindexDelete->pprev);
......
...@@ -485,9 +485,9 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem ...@@ -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); LOCK(cs);
list<CTransaction> transactionsToRemove; list<CTransaction> transactionsToRemove;
for (std::map<uint256, CTxMemPoolEntry>::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { for (std::map<uint256, CTxMemPoolEntry>::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
......
...@@ -118,7 +118,7 @@ public: ...@@ -118,7 +118,7 @@ public:
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry); bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry);
void remove(const CTransaction &tx, std::list<CTransaction>& removed, bool fRecursive = false); 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 removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed);
void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight, void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
std::list<CTransaction>& conflicts); std::list<CTransaction>& conflicts);
......
...@@ -20,22 +20,22 @@ class CTxInUndo ...@@ -20,22 +20,22 @@ class CTxInUndo
{ {
public: public:
CTxOut txout; // the txout data before being spent 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 unsigned int nHeight; // if the outpoint was the last unspent: its height
int nVersion; // if the outpoint was the last unspent: its version int nVersion; // if the outpoint was the last unspent: its version
CTxInUndo() : txout(), fCoinBase(false), nHeight(0), nVersion(0) {} CTxInUndo() : txout(), fBlockReward(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(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 { 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) + (nHeight > 0 ? ::GetSerializeSize(VARINT(this->nVersion), nType, nVersion) : 0) +
::GetSerializeSize(CTxOutCompressor(REF(txout)), nType, nVersion); ::GetSerializeSize(CTxOutCompressor(REF(txout)), nType, nVersion);
} }
template<typename Stream> template<typename Stream>
void Serialize(Stream &s, int nType, int nVersion) const { 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) if (nHeight > 0)
::Serialize(s, VARINT(this->nVersion), nType, nVersion); ::Serialize(s, VARINT(this->nVersion), nType, nVersion);
::Serialize(s, CTxOutCompressor(REF(txout)), nType, nVersion); ::Serialize(s, CTxOutCompressor(REF(txout)), nType, nVersion);
...@@ -46,7 +46,7 @@ public: ...@@ -46,7 +46,7 @@ public:
unsigned int nCode = 0; unsigned int nCode = 0;
::Unserialize(s, VARINT(nCode), nType, nVersion); ::Unserialize(s, VARINT(nCode), nType, nVersion);
nHeight = nCode / 2; nHeight = nCode / 2;
fCoinBase = nCode & 1; fBlockReward = nCode & 1;
if (nHeight > 0) if (nHeight > 0)
::Unserialize(s, VARINT(this->nVersion), nType, nVersion); ::Unserialize(s, VARINT(this->nVersion), nType, nVersion);
::Unserialize(s, REF(CTxOutCompressor(REF(txout))), 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