mirror of
https://github.com/monero-project/monero.git
synced 2026-01-16 23:01:54 -08:00
monerod can now sync from pruned blocks
If the peer (whether pruned or not itself) supports sending pruned blocks to syncing nodes, the pruned version will be sent along with the hash of the pruned data and the block weight. The original tx hashes can be reconstructed from the pruned txes and theur prunable data hash. Those hashes and the block weights are hashes and checked against the set of precompiled hashes, ensuring the data we received is the original data. It is currently not possible to use this system when not using the set of precompiled hashes, since block weights can not otherwise be checked for validity. This is off by default for now, and is enabled by --sync-pruned-blocks
This commit is contained in:
@@ -247,6 +247,7 @@ namespace cryptonote
|
||||
meta.relayed = relayed;
|
||||
meta.do_not_relay = do_not_relay;
|
||||
meta.double_spend_seen = have_tx_keyimges_as_spent(tx);
|
||||
meta.pruned = tx.pruned;
|
||||
meta.bf_padding = 0;
|
||||
memset(meta.padding, 0, sizeof(meta.padding));
|
||||
try
|
||||
@@ -290,6 +291,7 @@ namespace cryptonote
|
||||
meta.relayed = relayed;
|
||||
meta.do_not_relay = do_not_relay;
|
||||
meta.double_spend_seen = false;
|
||||
meta.pruned = tx.pruned;
|
||||
meta.bf_padding = 0;
|
||||
memset(meta.padding, 0, sizeof(meta.padding));
|
||||
|
||||
@@ -460,7 +462,7 @@ namespace cryptonote
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::take_tx(const crypto::hash &id, transaction &tx, cryptonote::blobdata &txblob, size_t& tx_weight, uint64_t& fee, bool &relayed, bool &do_not_relay, bool &double_spend_seen)
|
||||
bool tx_memory_pool::take_tx(const crypto::hash &id, transaction &tx, cryptonote::blobdata &txblob, size_t& tx_weight, uint64_t& fee, bool &relayed, bool &do_not_relay, bool &double_spend_seen, bool &pruned)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||
CRITICAL_REGION_LOCAL1(m_blockchain);
|
||||
@@ -482,7 +484,7 @@ namespace cryptonote
|
||||
{
|
||||
tx = ci->second;
|
||||
}
|
||||
else if (!parse_and_validate_tx_from_blob(txblob, tx))
|
||||
else if (!(meta.pruned ? parse_and_validate_tx_base_from_blob(txblob, tx) : parse_and_validate_tx_from_blob(txblob, tx)))
|
||||
{
|
||||
MERROR("Failed to parse tx from txpool");
|
||||
return false;
|
||||
@@ -496,6 +498,7 @@ namespace cryptonote
|
||||
relayed = meta.relayed;
|
||||
do_not_relay = meta.do_not_relay;
|
||||
double_spend_seen = meta.double_spend_seen;
|
||||
pruned = meta.pruned;
|
||||
|
||||
// remove first, in case this throws, so key images aren't removed
|
||||
m_blockchain.remove_txpool_tx(id);
|
||||
@@ -601,7 +604,7 @@ namespace cryptonote
|
||||
txs.reserve(m_blockchain.get_txpool_tx_count());
|
||||
m_blockchain.for_all_txpool_txes([this, now, &txs](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata *){
|
||||
// 0 fee transactions are never relayed
|
||||
if(meta.fee > 0 && !meta.do_not_relay && now - meta.last_relayed_time > get_relay_delay(now, meta.receive_time))
|
||||
if(!meta.pruned && meta.fee > 0 && !meta.do_not_relay && now - meta.last_relayed_time > get_relay_delay(now, meta.receive_time))
|
||||
{
|
||||
// if the tx is older than half the max lifetime, we don't re-relay it, to avoid a problem
|
||||
// mentioned by smooth where nodes would flush txes at slightly different times, causing
|
||||
@@ -667,7 +670,7 @@ namespace cryptonote
|
||||
txs.reserve(m_blockchain.get_txpool_tx_count(include_unrelayed_txes));
|
||||
m_blockchain.for_all_txpool_txes([&txs](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata *bd){
|
||||
transaction tx;
|
||||
if (!parse_and_validate_tx_from_blob(*bd, tx))
|
||||
if (!(meta.pruned ? parse_and_validate_tx_base_from_blob(*bd, tx) : parse_and_validate_tx_from_blob(*bd, tx)))
|
||||
{
|
||||
MERROR("Failed to parse tx from txpool");
|
||||
// continue
|
||||
@@ -791,7 +794,7 @@ namespace cryptonote
|
||||
txi.id_hash = epee::string_tools::pod_to_hex(txid);
|
||||
txi.tx_blob = *bd;
|
||||
transaction tx;
|
||||
if (!parse_and_validate_tx_from_blob(*bd, tx))
|
||||
if (!(meta.pruned ? parse_and_validate_tx_base_from_blob(*bd, tx) : parse_and_validate_tx_from_blob(*bd, tx)))
|
||||
{
|
||||
MERROR("Failed to parse tx from txpool");
|
||||
// continue
|
||||
@@ -863,7 +866,7 @@ namespace cryptonote
|
||||
m_blockchain.for_all_txpool_txes([&tx_infos, key_image_infos](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata *bd){
|
||||
cryptonote::rpc::tx_in_pool txi;
|
||||
txi.tx_hash = txid;
|
||||
if (!parse_and_validate_tx_from_blob(*bd, txi.tx))
|
||||
if (!(meta.pruned ? parse_and_validate_tx_base_from_blob(*bd, txi.tx) : parse_and_validate_tx_from_blob(*bd, txi.tx)))
|
||||
{
|
||||
MERROR("Failed to parse tx from txpool");
|
||||
// continue
|
||||
@@ -1143,7 +1146,7 @@ namespace cryptonote
|
||||
ss << "id: " << txid << std::endl;
|
||||
if (!short_format) {
|
||||
cryptonote::transaction tx;
|
||||
if (!parse_and_validate_tx_from_blob(*txblob, tx))
|
||||
if (!(meta.pruned ? parse_and_validate_tx_base_from_blob(*txblob, tx) : parse_and_validate_tx_from_blob(*txblob, tx)))
|
||||
{
|
||||
MERROR("Failed to parse tx from txpool");
|
||||
return true; // continue
|
||||
@@ -1199,6 +1202,12 @@ namespace cryptonote
|
||||
}
|
||||
LOG_PRINT_L2("Considering " << sorted_it->second << ", weight " << meta.weight << ", current block weight " << total_weight << "/" << max_total_weight << ", current coinbase " << print_money(best_coinbase));
|
||||
|
||||
if (meta.pruned)
|
||||
{
|
||||
LOG_PRINT_L2(" tx is pruned");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Can not exceed maximum block weight
|
||||
if (max_total_weight < total_weight + meta.weight)
|
||||
{
|
||||
@@ -1322,7 +1331,7 @@ namespace cryptonote
|
||||
{
|
||||
cryptonote::blobdata txblob = m_blockchain.get_txpool_tx_blob(txid);
|
||||
cryptonote::transaction tx;
|
||||
if (!parse_and_validate_tx_from_blob(txblob, tx))
|
||||
if (!parse_and_validate_tx_from_blob(txblob, tx)) // remove pruned ones on startup, they're meant to be temporary
|
||||
{
|
||||
MERROR("Failed to parse tx from txpool");
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user