aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/blockchain_db.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/blockchain_db/blockchain_db.cpp')
-rw-r--r--src/blockchain_db/blockchain_db.cpp36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index be0ffeac3..d3eefef6e 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -170,7 +170,7 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
uint64_t tx_id = add_transaction_data(blk_hash, tx, tx_hash, tx_prunable_hash);
- std::vector<uint64_t> amount_output_indices;
+ std::vector<uint64_t> amount_output_indices(tx.vout.size());
// iterate tx.vout using indices instead of C++11 foreach syntax because
// we need the index
@@ -183,13 +183,13 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
cryptonote::tx_out vout = tx.vout[i];
rct::key commitment = rct::zeroCommit(vout.amount);
vout.amount = 0;
- amount_output_indices.push_back(add_output(tx_hash, vout, i, tx.unlock_time,
- &commitment));
+ amount_output_indices[i] = add_output(tx_hash, vout, i, tx.unlock_time,
+ &commitment);
}
else
{
- amount_output_indices.push_back(add_output(tx_hash, tx.vout[i], i, tx.unlock_time,
- tx.version > 1 ? &tx.rct_signatures.outPk[i].mask : NULL));
+ amount_output_indices[i] = add_output(tx_hash, tx.vout[i], i, tx.unlock_time,
+ tx.version > 1 ? &tx.rct_signatures.outPk[i].mask : NULL);
}
}
add_tx_amount_output_indices(tx_id, amount_output_indices);
@@ -267,7 +267,10 @@ void BlockchainDB::pop_block(block& blk, std::vector<transaction>& txs)
for (const auto& h : boost::adaptors::reverse(blk.tx_hashes))
{
- txs.push_back(get_tx(h));
+ cryptonote::transaction tx;
+ if (!get_tx(h, tx) && !get_pruned_tx(h, tx))
+ throw DB_ERROR("Failed to get pruned or unpruned transaction from the db");
+ txs.push_back(std::move(tx));
remove_transaction(h);
}
remove_transaction(get_transaction_hash(blk.miner_tx));
@@ -280,7 +283,7 @@ bool BlockchainDB::is_open() const
void BlockchainDB::remove_transaction(const crypto::hash& tx_hash)
{
- transaction tx = get_tx(tx_hash);
+ transaction tx = get_pruned_tx(tx_hash);
for (const txin_v& tx_input : tx.vin)
{
@@ -325,6 +328,17 @@ bool BlockchainDB::get_tx(const crypto::hash& h, cryptonote::transaction &tx) co
return true;
}
+bool BlockchainDB::get_pruned_tx(const crypto::hash& h, cryptonote::transaction &tx) const
+{
+ blobdata bd;
+ if (!get_pruned_tx_blob(h, bd))
+ return false;
+ if (!parse_and_validate_tx_base_from_blob(bd, tx))
+ throw DB_ERROR("Failed to parse transaction base from blob retrieved from the db");
+
+ return true;
+}
+
transaction BlockchainDB::get_tx(const crypto::hash& h) const
{
transaction tx;
@@ -333,6 +347,14 @@ transaction BlockchainDB::get_tx(const crypto::hash& h) const
return tx;
}
+transaction BlockchainDB::get_pruned_tx(const crypto::hash& h) const
+{
+ transaction tx;
+ if (!get_pruned_tx(h, tx))
+ throw TX_DNE(std::string("pruned tx with hash ").append(epee::string_tools::pod_to_hex(h)).append(" not found in db").c_str());
+ return tx;
+}
+
void BlockchainDB::reset_stats()
{
num_calls = 0;