mirror of
https://github.com/monero-project/monero.git
synced 2024-12-13 20:06:32 +02:00
Remove unnecessary m_check_txin_table, fix const correctness
This commit is contained in:
parent
633f14b976
commit
c164f9037e
@ -715,7 +715,6 @@ block Blockchain::pop_block_from_blockchain()
|
|||||||
m_blocks_longhash_table.clear();
|
m_blocks_longhash_table.clear();
|
||||||
m_scan_table.clear();
|
m_scan_table.clear();
|
||||||
m_blocks_txs_check.clear();
|
m_blocks_txs_check.clear();
|
||||||
m_check_txin_table.clear();
|
|
||||||
|
|
||||||
CHECK_AND_ASSERT_THROW_MES(update_next_cumulative_weight_limit(), "Error updating next cumulative weight limit");
|
CHECK_AND_ASSERT_THROW_MES(update_next_cumulative_weight_limit(), "Error updating next cumulative weight limit");
|
||||||
uint64_t top_block_height;
|
uint64_t top_block_height;
|
||||||
@ -2575,7 +2574,7 @@ void Blockchain::on_new_tx_from_block(const cryptonote::transaction &tx)
|
|||||||
// This function overloads its sister function with
|
// This function overloads its sister function with
|
||||||
// an extra value (hash of highest block that holds an output used as input)
|
// an extra value (hash of highest block that holds an output used as input)
|
||||||
// as a return-by-reference.
|
// as a return-by-reference.
|
||||||
bool Blockchain::check_tx_inputs(transaction& tx, uint64_t& max_used_block_height, crypto::hash& max_used_block_id, tx_verification_context &tvc, bool kept_by_block)
|
bool Blockchain::check_tx_inputs(transaction& tx, uint64_t& max_used_block_height, crypto::hash& max_used_block_id, tx_verification_context &tvc, bool kept_by_block) const
|
||||||
{
|
{
|
||||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||||
@ -2606,7 +2605,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, uint64_t& max_used_block_heigh
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
bool Blockchain::check_tx_outputs(const transaction& tx, tx_verification_context &tvc)
|
bool Blockchain::check_tx_outputs(const transaction& tx, tx_verification_context &tvc) const
|
||||||
{
|
{
|
||||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||||
@ -2715,7 +2714,7 @@ bool Blockchain::have_tx_keyimges_as_spent(const transaction &tx) const
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool Blockchain::expand_transaction_2(transaction &tx, const crypto::hash &tx_prefix_hash, const std::vector<std::vector<rct::ctkey>> &pubkeys)
|
bool Blockchain::expand_transaction_2(transaction &tx, const crypto::hash &tx_prefix_hash, const std::vector<std::vector<rct::ctkey>> &pubkeys) const
|
||||||
{
|
{
|
||||||
PERF_TIMER(expand_transaction_2);
|
PERF_TIMER(expand_transaction_2);
|
||||||
CHECK_AND_ASSERT_MES(tx.version == 2, false, "Transaction version is not 2");
|
CHECK_AND_ASSERT_MES(tx.version == 2, false, "Transaction version is not 2");
|
||||||
@ -2791,7 +2790,7 @@ bool Blockchain::expand_transaction_2(transaction &tx, const crypto::hash &tx_pr
|
|||||||
// check_tx_input() rather than here, and use this function simply
|
// check_tx_input() rather than here, and use this function simply
|
||||||
// to iterate the inputs as necessary (splitting the task
|
// to iterate the inputs as necessary (splitting the task
|
||||||
// using threads, etc.)
|
// using threads, etc.)
|
||||||
bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc, uint64_t* pmax_used_block_height)
|
bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc, uint64_t* pmax_used_block_height) const
|
||||||
{
|
{
|
||||||
PERF_TIMER(check_tx_inputs);
|
PERF_TIMER(check_tx_inputs);
|
||||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||||
@ -2897,13 +2896,6 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto it = m_check_txin_table.find(tx_prefix_hash);
|
|
||||||
if(it == m_check_txin_table.end())
|
|
||||||
{
|
|
||||||
m_check_txin_table.emplace(tx_prefix_hash, std::unordered_map<crypto::key_image, bool>());
|
|
||||||
it = m_check_txin_table.find(tx_prefix_hash);
|
|
||||||
assert(it != m_check_txin_table.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::vector<rct::ctkey>> pubkeys(tx.vin.size());
|
std::vector<std::vector<rct::ctkey>> pubkeys(tx.vin.size());
|
||||||
std::vector < uint64_t > results;
|
std::vector < uint64_t > results;
|
||||||
@ -2935,29 +2927,12 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||||||
{
|
{
|
||||||
// basically, make sure number of inputs == number of signatures
|
// basically, make sure number of inputs == number of signatures
|
||||||
CHECK_AND_ASSERT_MES(sig_index < tx.signatures.size(), false, "wrong transaction: not signature entry for input with index= " << sig_index);
|
CHECK_AND_ASSERT_MES(sig_index < tx.signatures.size(), false, "wrong transaction: not signature entry for input with index= " << sig_index);
|
||||||
|
|
||||||
#if defined(CACHE_VIN_RESULTS)
|
|
||||||
auto itk = it->second.find(in_to_key.k_image);
|
|
||||||
if(itk != it->second.end())
|
|
||||||
{
|
|
||||||
if(!itk->second)
|
|
||||||
{
|
|
||||||
MERROR_VER("Failed ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// txin has been verified already, skip
|
|
||||||
sig_index++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that output being spent matches up correctly with the
|
// make sure that output being spent matches up correctly with the
|
||||||
// signature spending it.
|
// signature spending it.
|
||||||
if (!check_tx_input(tx.version, in_to_key, tx_prefix_hash, tx.version == 1 ? tx.signatures[sig_index] : std::vector<crypto::signature>(), tx.rct_signatures, pubkeys[sig_index], pmax_used_block_height))
|
if (!check_tx_input(tx.version, in_to_key, tx_prefix_hash, tx.version == 1 ? tx.signatures[sig_index] : std::vector<crypto::signature>(), tx.rct_signatures, pubkeys[sig_index], pmax_used_block_height))
|
||||||
{
|
{
|
||||||
it->second[in_to_key.k_image] = false;
|
|
||||||
MERROR_VER("Failed to check ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
|
MERROR_VER("Failed to check ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
|
||||||
if (pmax_used_block_height) // a default value of NULL is used when called from Blockchain::handle_block_to_main_chain()
|
if (pmax_used_block_height) // a default value of NULL is used when called from Blockchain::handle_block_to_main_chain()
|
||||||
{
|
{
|
||||||
@ -2980,7 +2955,6 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||||||
check_ring_signature(tx_prefix_hash, in_to_key.k_image, pubkeys[sig_index], tx.signatures[sig_index], results[sig_index]);
|
check_ring_signature(tx_prefix_hash, in_to_key.k_image, pubkeys[sig_index], tx.signatures[sig_index], results[sig_index]);
|
||||||
if (!results[sig_index])
|
if (!results[sig_index])
|
||||||
{
|
{
|
||||||
it->second[in_to_key.k_image] = false;
|
|
||||||
MERROR_VER("Failed to check ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
|
MERROR_VER("Failed to check ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
|
||||||
|
|
||||||
if (pmax_used_block_height) // a default value of NULL is used when called from Blockchain::handle_block_to_main_chain()
|
if (pmax_used_block_height) // a default value of NULL is used when called from Blockchain::handle_block_to_main_chain()
|
||||||
@ -2990,7 +2964,6 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
it->second[in_to_key.k_image] = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3008,7 +2981,6 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||||||
for (size_t i = 0; i < tx.vin.size(); i++)
|
for (size_t i = 0; i < tx.vin.size(); i++)
|
||||||
{
|
{
|
||||||
const txin_to_key& in_to_key = boost::get<txin_to_key>(tx.vin[i]);
|
const txin_to_key& in_to_key = boost::get<txin_to_key>(tx.vin[i]);
|
||||||
it->second[in_to_key.k_image] = results[i];
|
|
||||||
if(!failed && !results[i])
|
if(!failed && !results[i])
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
@ -3182,7 +3154,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
void Blockchain::check_ring_signature(const crypto::hash &tx_prefix_hash, const crypto::key_image &key_image, const std::vector<rct::ctkey> &pubkeys, const std::vector<crypto::signature>& sig, uint64_t &result)
|
void Blockchain::check_ring_signature(const crypto::hash &tx_prefix_hash, const crypto::key_image &key_image, const std::vector<rct::ctkey> &pubkeys, const std::vector<crypto::signature>& sig, uint64_t &result) const
|
||||||
{
|
{
|
||||||
std::vector<const crypto::public_key *> p_output_keys;
|
std::vector<const crypto::public_key *> p_output_keys;
|
||||||
p_output_keys.reserve(pubkeys.size());
|
p_output_keys.reserve(pubkeys.size());
|
||||||
@ -3369,7 +3341,7 @@ bool Blockchain::is_tx_spendtime_unlocked(uint64_t unlock_time) const
|
|||||||
// This function locates all outputs associated with a given input (mixins)
|
// This function locates all outputs associated with a given input (mixins)
|
||||||
// and validates that they exist and are usable. It also checks the ring
|
// and validates that they exist and are usable. It also checks the ring
|
||||||
// signature for each input.
|
// signature for each input.
|
||||||
bool Blockchain::check_tx_input(size_t tx_version, const txin_to_key& txin, const crypto::hash& tx_prefix_hash, const std::vector<crypto::signature>& sig, const rct::rctSig &rct_signatures, std::vector<rct::ctkey> &output_keys, uint64_t* pmax_related_block_height)
|
bool Blockchain::check_tx_input(size_t tx_version, const txin_to_key& txin, const crypto::hash& tx_prefix_hash, const std::vector<crypto::signature>& sig, const rct::rctSig &rct_signatures, std::vector<rct::ctkey> &output_keys, uint64_t* pmax_related_block_height) const
|
||||||
{
|
{
|
||||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||||
|
|
||||||
@ -4208,7 +4180,6 @@ bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
|
|||||||
m_blocks_longhash_table.clear();
|
m_blocks_longhash_table.clear();
|
||||||
m_scan_table.clear();
|
m_scan_table.clear();
|
||||||
m_blocks_txs_check.clear();
|
m_blocks_txs_check.clear();
|
||||||
m_check_txin_table.clear();
|
|
||||||
|
|
||||||
// when we're well clear of the precomputed hashes, free the memory
|
// when we're well clear of the precomputed hashes, free the memory
|
||||||
if (!m_blocks_hash_check.empty() && m_db->height() > m_blocks_hash_check.size() + 4096)
|
if (!m_blocks_hash_check.empty() && m_db->height() > m_blocks_hash_check.size() + 4096)
|
||||||
@ -4497,7 +4468,6 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||||||
m_fake_pow_calc_time = 0;
|
m_fake_pow_calc_time = 0;
|
||||||
|
|
||||||
m_scan_table.clear();
|
m_scan_table.clear();
|
||||||
m_check_txin_table.clear();
|
|
||||||
|
|
||||||
TIME_MEASURE_FINISH(prepare);
|
TIME_MEASURE_FINISH(prepare);
|
||||||
m_fake_pow_calc_time = prepare / blocks_entry.size();
|
m_fake_pow_calc_time = prepare / blocks_entry.size();
|
||||||
|
@ -559,7 +559,7 @@ namespace cryptonote
|
|||||||
*
|
*
|
||||||
* @return false if any input is invalid, otherwise true
|
* @return false if any input is invalid, otherwise true
|
||||||
*/
|
*/
|
||||||
bool check_tx_inputs(transaction& tx, uint64_t& pmax_used_block_height, crypto::hash& max_used_block_id, tx_verification_context &tvc, bool kept_by_block = false);
|
bool check_tx_inputs(transaction& tx, uint64_t& pmax_used_block_height, crypto::hash& max_used_block_id, tx_verification_context &tvc, bool kept_by_block = false) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get fee quantization mask
|
* @brief get fee quantization mask
|
||||||
@ -626,7 +626,7 @@ namespace cryptonote
|
|||||||
*
|
*
|
||||||
* @return false if any outputs do not conform, otherwise true
|
* @return false if any outputs do not conform, otherwise true
|
||||||
*/
|
*/
|
||||||
bool check_tx_outputs(const transaction& tx, tx_verification_context &tvc);
|
bool check_tx_outputs(const transaction& tx, tx_verification_context &tvc) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief gets the block weight limit based on recent blocks
|
* @brief gets the block weight limit based on recent blocks
|
||||||
@ -1040,7 +1040,6 @@ namespace cryptonote
|
|||||||
// metadata containers
|
// metadata containers
|
||||||
std::unordered_map<crypto::hash, std::unordered_map<crypto::key_image, std::vector<output_data_t>>> m_scan_table;
|
std::unordered_map<crypto::hash, std::unordered_map<crypto::key_image, std::vector<output_data_t>>> m_scan_table;
|
||||||
std::unordered_map<crypto::hash, crypto::hash> m_blocks_longhash_table;
|
std::unordered_map<crypto::hash, crypto::hash> m_blocks_longhash_table;
|
||||||
std::unordered_map<crypto::hash, std::unordered_map<crypto::key_image, bool>> m_check_txin_table;
|
|
||||||
|
|
||||||
// SHA-3 hashes for each block and for fast pow checking
|
// SHA-3 hashes for each block and for fast pow checking
|
||||||
std::vector<crypto::hash> m_blocks_hash_of_hashes;
|
std::vector<crypto::hash> m_blocks_hash_of_hashes;
|
||||||
@ -1150,7 +1149,7 @@ namespace cryptonote
|
|||||||
*
|
*
|
||||||
* @return false if any output is not yet unlocked, or is missing, otherwise true
|
* @return false if any output is not yet unlocked, or is missing, otherwise true
|
||||||
*/
|
*/
|
||||||
bool check_tx_input(size_t tx_version,const txin_to_key& txin, const crypto::hash& tx_prefix_hash, const std::vector<crypto::signature>& sig, const rct::rctSig &rct_signatures, std::vector<rct::ctkey> &output_keys, uint64_t* pmax_related_block_height);
|
bool check_tx_input(size_t tx_version,const txin_to_key& txin, const crypto::hash& tx_prefix_hash, const std::vector<crypto::signature>& sig, const rct::rctSig &rct_signatures, std::vector<rct::ctkey> &output_keys, uint64_t* pmax_related_block_height) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief validate a transaction's inputs and their keys
|
* @brief validate a transaction's inputs and their keys
|
||||||
@ -1172,7 +1171,7 @@ namespace cryptonote
|
|||||||
*
|
*
|
||||||
* @return false if any validation step fails, otherwise true
|
* @return false if any validation step fails, otherwise true
|
||||||
*/
|
*/
|
||||||
bool check_tx_inputs(transaction& tx, tx_verification_context &tvc, uint64_t* pmax_used_block_height = NULL);
|
bool check_tx_inputs(transaction& tx, tx_verification_context &tvc, uint64_t* pmax_used_block_height = NULL) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief performs a blockchain reorganization according to the longest chain rule
|
* @brief performs a blockchain reorganization according to the longest chain rule
|
||||||
@ -1452,7 +1451,7 @@ namespace cryptonote
|
|||||||
* @param result false if the ring signature is invalid, otherwise true
|
* @param result false if the ring signature is invalid, otherwise true
|
||||||
*/
|
*/
|
||||||
void check_ring_signature(const crypto::hash &tx_prefix_hash, const crypto::key_image &key_image,
|
void check_ring_signature(const crypto::hash &tx_prefix_hash, const crypto::key_image &key_image,
|
||||||
const std::vector<rct::ctkey> &pubkeys, const std::vector<crypto::signature> &sig, uint64_t &result);
|
const std::vector<rct::ctkey> &pubkeys, const std::vector<crypto::signature> &sig, uint64_t &result) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief loads block hashes from compiled-in data set
|
* @brief loads block hashes from compiled-in data set
|
||||||
@ -1472,7 +1471,7 @@ namespace cryptonote
|
|||||||
* can be reconstituted by the receiver. This function expands
|
* can be reconstituted by the receiver. This function expands
|
||||||
* that implicit data.
|
* that implicit data.
|
||||||
*/
|
*/
|
||||||
bool expand_transaction_2(transaction &tx, const crypto::hash &tx_prefix_hash, const std::vector<std::vector<rct::ctkey>> &pubkeys);
|
bool expand_transaction_2(transaction &tx, const crypto::hash &tx_prefix_hash, const std::vector<std::vector<rct::ctkey>> &pubkeys) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief invalidates any cached block template
|
* @brief invalidates any cached block template
|
||||||
|
Loading…
Reference in New Issue
Block a user