blockchain_db: match tx addition semantics to original code

The original code removed key images from a tx from the blockchain
when an non to-key nor gen input was found in that tx. Additionally,
the remainder of the tx data was added to the blockchain only after
the double spend check passed.
This commit is contained in:
moneromooo-monero 2015-08-11 11:09:09 +01:00
parent 83bbea4c7f
commit e63b854967
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3

View File

@ -56,6 +56,30 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
tx_hash = *tx_hash_ptr; tx_hash = *tx_hash_ptr;
} }
for (const txin_v& tx_input : tx.vin)
{
if (tx_input.type() == typeid(txin_to_key))
{
add_spent_key(boost::get<txin_to_key>(tx_input).k_image);
}
else if (tx_input.type() == typeid(txin_gen))
{
/* nothing to do here */
}
else
{
LOG_PRINT_L1("Unsupported input type, removing key images and aborting transaction addition");
for (const txin_v& tx_input : tx.vin)
{
if (tx_input.type() == typeid(txin_to_key))
{
remove_spent_key(boost::get<txin_to_key>(tx_input).k_image);
}
}
return;
}
}
add_transaction_data(blk_hash, tx, tx_hash); add_transaction_data(blk_hash, tx, tx_hash);
// iterate tx.vout using indices instead of C++11 foreach syntax because // iterate tx.vout using indices instead of C++11 foreach syntax because
@ -64,14 +88,6 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
{ {
add_output(tx_hash, tx.vout[i], i, tx.unlock_time); add_output(tx_hash, tx.vout[i], i, tx.unlock_time);
} }
for (const txin_v& tx_input : tx.vin)
{
if (tx_input.type() == typeid(txin_to_key))
{
add_spent_key(boost::get<txin_to_key>(tx_input).k_image);
}
}
} }
uint64_t BlockchainDB::add_block( const block& blk uint64_t BlockchainDB::add_block( const block& blk