Skip to content

Commit

Permalink
Added another check for quantity overflow. Fixed removal of feedback_…
Browse files Browse the repository at this point in the history
…token
  • Loading branch information
VanGrx committed Jan 31, 2020
1 parent 70ef476 commit bfa2d45
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/blockchain_db/blockchain_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ void BlockchainDB::remove_transaction(const crypto::hash& tx_hash)
remove_transaction_data(tx_hash, tx);
}

void BlockchainDB::revert_transaction(const crypto::hash &tx_hash)
{
remove_transaction(tx_hash);
}

block BlockchainDB::get_block_from_height(const uint64_t& height) const
{
blobdata bd = get_block_blob_from_height(height);
Expand Down
11 changes: 11 additions & 0 deletions src/blockchain_db/blockchain_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,17 @@ namespace cryptonote
virtual uint64_t height() const = 0;


// helper function to remove transaction from blockchain
/**
* @brief helper function to remove transaction from the blockchain
*
* This function encapsulates aspects of removing a transaction.
*
* @param tx_hash the hash of the transaction to be removed
*/
void revert_transaction(const crypto::hash &tx_hash);


/**
* <!--
* TODO: Rewrite (if necessary) such that all calls to remove_* are
Expand Down
5 changes: 4 additions & 1 deletion src/blockchain_db/lmdb/db_lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ void BlockchainLMDB::remove_tx_outputs(const uint64_t tx_id, const transaction&
safex::create_purchase_data purchase_output_data;
parse_and_validate_object_from_blob(blobdata1, purchase_output_data);
remove_safex_purchase(purchase_output_data.offer_id,purchase_output_data.quantity);
} else if(output_type == tx_out_type::out_network_fee){
} else if(output_type == tx_out_type::out_network_fee || output_type == tx_out_type::out_safex_feedback_token){
remove_last_advanced_output();
}
else {
Expand Down Expand Up @@ -5196,6 +5196,9 @@ bool BlockchainLMDB::is_valid_transaction_output_type(const txout_target_v &txou
const cryptonote::blobdata accblob((uint8_t*)v.mv_data, (uint8_t*)v.mv_data+v.mv_size);
cryptonote::parse_and_validate_from_blob(accblob, sfx_offer);

if(sfx_offer.quantity - purchase.quantity > sfx_offer.quantity)
throw0(DB_ERROR("DB error attempting to create purchase: Not enough quantity of item"));

sfx_offer.quantity -= purchase.quantity;


Expand Down
7 changes: 7 additions & 0 deletions src/cryptonote_core/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4772,8 +4772,15 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
}
catch (const std::exception& e)
{

for(auto tx: txs){
cryptonote::transaction tmp;
if(m_db->get_tx(tx.hash,tmp))
m_db->revert_transaction(tx.hash);
}
//TODO: figure out the best way to deal with this failure
LOG_ERROR("Error adding block with hash: " << id << " to blockchain, what = " << e.what());
bvc.m_verifivation_failed = true;
return_tx_to_pool(txs);
return false;
}
Expand Down

0 comments on commit bfa2d45

Please sign in to comment.