mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
Merge pull request #5721
c164f90
Remove unnecessary m_check_txin_table, fix const correctness (omartijn)
This commit is contained in:
commit
1010a6503e
2 changed files with 12 additions and 43 deletions
|
@ -715,7 +715,6 @@ block Blockchain::pop_block_from_blockchain()
|
|||
m_blocks_longhash_table.clear();
|
||||
m_scan_table.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");
|
||||
uint64_t top_block_height;
|
||||
|
@ -2612,7 +2611,7 @@ void Blockchain::on_new_tx_from_block(const cryptonote::transaction &tx)
|
|||
// This function overloads its sister function with
|
||||
// an extra value (hash of highest block that holds an output used as input)
|
||||
// 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__);
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
|
@ -2643,7 +2642,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, uint64_t& max_used_block_heigh
|
|||
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__);
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
|
@ -2752,7 +2751,7 @@ bool Blockchain::have_tx_keyimges_as_spent(const transaction &tx) const
|
|||
}
|
||||
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);
|
||||
CHECK_AND_ASSERT_MES(tx.version == 2, false, "Transaction version is not 2");
|
||||
|
@ -2828,7 +2827,7 @@ bool Blockchain::expand_transaction_2(transaction &tx, const crypto::hash &tx_pr
|
|||
// check_tx_input() rather than here, and use this function simply
|
||||
// to iterate the inputs as necessary (splitting the task
|
||||
// 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);
|
||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||
|
@ -2947,13 +2946,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 < uint64_t > results;
|
||||
|
@ -2985,29 +2977,12 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||
{
|
||||
// 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);
|
||||
|
||||
#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
|
||||
// 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))
|
||||
{
|
||||
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);
|
||||
if (pmax_used_block_height) // a default value of NULL is used when called from Blockchain::handle_block_to_main_chain()
|
||||
{
|
||||
|
@ -3030,7 +3005,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]);
|
||||
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);
|
||||
|
||||
if (pmax_used_block_height) // a default value of NULL is used when called from Blockchain::handle_block_to_main_chain()
|
||||
|
@ -3040,7 +3014,6 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||
|
||||
return false;
|
||||
}
|
||||
it->second[in_to_key.k_image] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3058,7 +3031,6 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
|||
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]);
|
||||
it->second[in_to_key.k_image] = results[i];
|
||||
if(!failed && !results[i])
|
||||
failed = true;
|
||||
}
|
||||
|
@ -3232,7 +3204,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;
|
||||
p_output_keys.reserve(pubkeys.size());
|
||||
|
@ -3418,7 +3390,7 @@ bool Blockchain::is_tx_spendtime_unlocked(uint64_t unlock_time) const
|
|||
// This function locates all outputs associated with a given input (mixins)
|
||||
// and validates that they exist and are usable. It also checks the ring
|
||||
// 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__);
|
||||
|
||||
|
@ -4255,7 +4227,6 @@ bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
|
|||
m_blocks_longhash_table.clear();
|
||||
m_scan_table.clear();
|
||||
m_blocks_txs_check.clear();
|
||||
m_check_txin_table.clear();
|
||||
|
||||
// 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)
|
||||
|
@ -4544,7 +4515,6 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||
m_fake_pow_calc_time = 0;
|
||||
|
||||
m_scan_table.clear();
|
||||
m_check_txin_table.clear();
|
||||
|
||||
TIME_MEASURE_FINISH(prepare);
|
||||
m_fake_pow_calc_time = prepare / blocks_entry.size();
|
||||
|
|
|
@ -548,7 +548,7 @@ namespace cryptonote
|
|||
*
|
||||
* @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
|
||||
|
@ -615,7 +615,7 @@ namespace cryptonote
|
|||
*
|
||||
* @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
|
||||
|
@ -1020,7 +1020,6 @@ namespace cryptonote
|
|||
// 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, 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
|
||||
std::vector<crypto::hash> m_blocks_hash_of_hashes;
|
||||
|
@ -1127,7 +1126,7 @@ namespace cryptonote
|
|||
*
|
||||
* @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
|
||||
|
@ -1149,7 +1148,7 @@ namespace cryptonote
|
|||
*
|
||||
* @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
|
||||
|
@ -1429,7 +1428,7 @@ namespace cryptonote
|
|||
* @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,
|
||||
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
|
||||
|
@ -1449,7 +1448,7 @@ namespace cryptonote
|
|||
* can be reconstituted by the receiver. This function expands
|
||||
* 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
|
||||
|
|
Loading…
Reference in a new issue