From 5db433b3f7a093d692d5a5ac5ea6974cf9400872 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 12 Oct 2017 13:27:20 +0100 Subject: [PATCH 1/2] blockchain: avoid exceptions in output verification This can happen if we get a bad tx, so let's not spam the log. --- src/cryptonote_core/blockchain.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 3e0ffc409..247387efe 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -188,7 +188,12 @@ bool Blockchain::scan_outputkeys_for_indexes(size_t tx_version, const txin_to_ke { try { - m_db->get_output_key(tx_in_to_key.amount, absolute_offsets, outputs); + m_db->get_output_key(tx_in_to_key.amount, absolute_offsets, outputs, true); + if (absolute_offsets.size() != outputs.size()) + { + MERROR_VER("Output does not exist! amount = " << tx_in_to_key.amount); + return false; + } } catch (...) { @@ -208,7 +213,12 @@ bool Blockchain::scan_outputkeys_for_indexes(size_t tx_version, const txin_to_ke add_offsets.push_back(absolute_offsets[i]); try { - m_db->get_output_key(tx_in_to_key.amount, add_offsets, add_outputs); + m_db->get_output_key(tx_in_to_key.amount, add_offsets, add_outputs, true); + if (add_offsets.size() != add_outputs.size()) + { + MERROR_VER("Output does not exist! amount = " << tx_in_to_key.amount); + return false; + } } catch (...) { From 22b51e06721addd078da2a786a7c7e59c7104af0 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 12 Oct 2017 13:28:28 +0100 Subject: [PATCH 2/2] db_lmdb: include chain height when failing to find an output key To help debugging logs. --- src/blockchain_db/lmdb/db_lmdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 985244f6b..c5e8da80c 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -2933,7 +2933,7 @@ void BlockchainLMDB::get_output_key(const uint64_t &amount, const std::vector(amount) + ", index " + boost::lexical_cast(index) + ", count " + boost::lexical_cast(get_num_outputs(amount)) + "), but key does not exist").c_str())); + throw1(OUTPUT_DNE((std::string("Attempting to get output pubkey by global index (amount ") + boost::lexical_cast(amount) + ", index " + boost::lexical_cast(index) + ", count " + boost::lexical_cast(get_num_outputs(amount)) + "), but key does not exist (current height " + boost::lexical_cast(height()) + ")").c_str())); } else if (get_result) throw0(DB_ERROR(lmdb_error("Error attempting to retrieve an output pubkey from the db", get_result).c_str()));