mirror of
https://github.com/monero-project/monero.git
synced 2024-12-13 11:56:31 +02:00
blockchain: fill in cumulative block weight for alt blocks
This commit is contained in:
parent
2c171a9b02
commit
01f660f60f
@ -1803,6 +1803,34 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
|
|||||||
}
|
}
|
||||||
bei.cumulative_difficulty += current_diff;
|
bei.cumulative_difficulty += current_diff;
|
||||||
|
|
||||||
|
bei.block_cumulative_weight = cryptonote::get_transaction_weight(b.miner_tx);
|
||||||
|
for (const crypto::hash &txid: b.tx_hashes)
|
||||||
|
{
|
||||||
|
cryptonote::tx_memory_pool::tx_details td;
|
||||||
|
cryptonote::blobdata blob;
|
||||||
|
if (m_tx_pool.get_transaction_info(txid, td))
|
||||||
|
{
|
||||||
|
bei.block_cumulative_weight += td.weight;
|
||||||
|
}
|
||||||
|
else if (m_db->get_pruned_tx_blob(txid, blob))
|
||||||
|
{
|
||||||
|
cryptonote::transaction tx;
|
||||||
|
if (!cryptonote::parse_and_validate_tx_base_from_blob(blob, tx))
|
||||||
|
{
|
||||||
|
MERROR_VER("Block with id: " << epee::string_tools::pod_to_hex(id) << " (as alternative) refers to unparsable transaction hash " << txid << ".");
|
||||||
|
bvc.m_verifivation_failed = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bei.block_cumulative_weight += cryptonote::get_pruned_transaction_weight(tx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we can't determine the block weight, set it to 0 and break out of the loop
|
||||||
|
bei.block_cumulative_weight = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add block to alternate blocks storage,
|
// add block to alternate blocks storage,
|
||||||
// as well as the current "alt chain" container
|
// as well as the current "alt chain" container
|
||||||
CHECK_AND_ASSERT_MES(!m_db->get_alt_block(id, NULL, NULL), false, "insertion of new alternative block returned as it already exists");
|
CHECK_AND_ASSERT_MES(!m_db->get_alt_block(id, NULL, NULL), false, "insertion of new alternative block returned as it already exists");
|
||||||
|
@ -515,6 +515,59 @@ namespace cryptonote
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
|
bool tx_memory_pool::get_transaction_info(const crypto::hash &txid, tx_details &td) const
|
||||||
|
{
|
||||||
|
PERF_TIMER(get_transaction_info);
|
||||||
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
|
CRITICAL_REGION_LOCAL1(m_blockchain);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LockedTXN lock(m_blockchain);
|
||||||
|
txpool_tx_meta_t meta;
|
||||||
|
if (!m_blockchain.get_txpool_tx_meta(txid, meta))
|
||||||
|
{
|
||||||
|
MERROR("Failed to find tx in txpool");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
cryptonote::blobdata txblob = m_blockchain.get_txpool_tx_blob(txid);
|
||||||
|
auto ci = m_parsed_tx_cache.find(txid);
|
||||||
|
if (ci != m_parsed_tx_cache.end())
|
||||||
|
{
|
||||||
|
td.tx = ci->second;
|
||||||
|
}
|
||||||
|
else if (!(meta.pruned ? parse_and_validate_tx_base_from_blob(txblob, td.tx) : parse_and_validate_tx_from_blob(txblob, td.tx)))
|
||||||
|
{
|
||||||
|
MERROR("Failed to parse tx from txpool");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
td.tx.set_hash(txid);
|
||||||
|
}
|
||||||
|
td.blob_size = txblob.size();
|
||||||
|
td.weight = meta.weight;
|
||||||
|
td.fee = meta.fee;
|
||||||
|
td.max_used_block_id = meta.max_used_block_id;
|
||||||
|
td.max_used_block_height = meta.max_used_block_height;
|
||||||
|
td.kept_by_block = meta.kept_by_block;
|
||||||
|
td.last_failed_height = meta.last_failed_height;
|
||||||
|
td.last_failed_id = meta.last_failed_id;
|
||||||
|
td.receive_time = meta.receive_time;
|
||||||
|
td.last_relayed_time = meta.last_relayed_time;
|
||||||
|
td.relayed = meta.relayed;
|
||||||
|
td.do_not_relay = meta.do_not_relay;
|
||||||
|
td.double_spend_seen = meta.double_spend_seen;
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
MERROR("Failed to get tx from txpool: " << e.what());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
void tx_memory_pool::on_idle()
|
void tx_memory_pool::on_idle()
|
||||||
{
|
{
|
||||||
m_remove_stuck_tx_interval.do_call([this](){return remove_stuck_transactions();});
|
m_remove_stuck_tx_interval.do_call([this](){return remove_stuck_transactions();});
|
||||||
|
@ -428,6 +428,11 @@ namespace cryptonote
|
|||||||
bool double_spend_seen; //!< true iff another tx was seen double spending this one
|
bool double_spend_seen; //!< true iff another tx was seen double spending this one
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief get infornation about a single transaction
|
||||||
|
*/
|
||||||
|
bool get_transaction_info(const crypto::hash &txid, tx_details &td) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user