@ -1082,11 +1082,9 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund
// mark an outpoint spent, and construct undo information
// mark an outpoint spent, and construct undo information
txundo . vprevout . push_back ( CTxInUndo ( coins - > vout [ nPos ] ) ) ;
txundo . vprevout . push_back ( CTxInUndo ( coins - > vout [ nPos ] ) ) ;
coins - > Spend ( nPos ) ;
coins - > Spend ( nPos ) ;
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 - > fCoinBase ;
undo . fCoinBase = coins - > fCoinBase ;
}
}
}
}
}
// add outputs
// add outputs
@ -1266,11 +1264,16 @@ int ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, const COutPoint&
CCoinsModifier coins = view . ModifyCoins ( out . hash ) ;
CCoinsModifier coins = view . ModifyCoins ( out . hash ) ;
if ( undo . nHeight ! = 0 ) {
if ( undo . nHeight ! = 0 ) {
// undo data contains height: this is the last output of the prevout tx being spent
if ( ! coins - > IsPruned ( ) ) {
if ( ! coins - > IsPruned ( ) ) fClean = false ; // overwriting existing transaction
if ( coins - > fCoinBase ! = undo . fCoinBase | | ( uint32_t ) coins - > nHeight ! = undo . nHeight ) fClean = false ; // metadata mismatch
}
// restore height/coinbase tx metadata from undo data
coins - > fCoinBase = undo . fCoinBase ;
coins - > fCoinBase = undo . fCoinBase ;
coins - > nHeight = undo . nHeight ;
coins - > nHeight = undo . nHeight ;
} else {
} else {
// Undo data does not contain height/coinbase. This should never happen
// for newly created undo entries. Previously, this data was only saved
// for the last spend of a transaction's outputs, so check IsPruned().
if ( coins - > IsPruned ( ) ) fClean = false ; // adding output to missing transaction
if ( coins - > IsPruned ( ) ) fClean = false ; // adding output to missing transaction
}
}
if ( coins - > IsAvailable ( out . n ) ) fClean = false ; // overwriting existing output
if ( coins - > IsAvailable ( out . n ) ) fClean = false ; // overwriting existing output