mirror of
https://github.com/monero-project/monero.git
synced 2025-06-07 16:22:41 -04: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:
parent
d0d76f771a
commit
8330e772f1
30 changed files with 731 additions and 195 deletions
|
@ -195,6 +195,7 @@ namespace cryptonote
|
|||
private:
|
||||
// hash cash
|
||||
mutable std::atomic<bool> hash_valid;
|
||||
mutable std::atomic<bool> prunable_hash_valid;
|
||||
mutable std::atomic<bool> blob_size_valid;
|
||||
|
||||
public:
|
||||
|
@ -203,6 +204,7 @@ namespace cryptonote
|
|||
|
||||
// hash cash
|
||||
mutable crypto::hash hash;
|
||||
mutable crypto::hash prunable_hash;
|
||||
mutable size_t blob_size;
|
||||
|
||||
bool pruned;
|
||||
|
@ -211,22 +213,26 @@ namespace cryptonote
|
|||
std::atomic<unsigned int> prefix_size;
|
||||
|
||||
transaction();
|
||||
transaction(const transaction &t): transaction_prefix(t), hash_valid(false), blob_size_valid(false), signatures(t.signatures), rct_signatures(t.rct_signatures), pruned(t.pruned), unprunable_size(t.unprunable_size.load()), prefix_size(t.prefix_size.load()) { if (t.is_hash_valid()) { hash = t.hash; set_hash_valid(true); } if (t.is_blob_size_valid()) { blob_size = t.blob_size; set_blob_size_valid(true); } }
|
||||
transaction &operator=(const transaction &t) { transaction_prefix::operator=(t); set_hash_valid(false); set_blob_size_valid(false); signatures = t.signatures; rct_signatures = t.rct_signatures; if (t.is_hash_valid()) { hash = t.hash; set_hash_valid(true); } if (t.is_blob_size_valid()) { blob_size = t.blob_size; set_blob_size_valid(true); } pruned = t.pruned; unprunable_size = t.unprunable_size.load(); prefix_size = t.prefix_size.load(); return *this; }
|
||||
transaction(const transaction &t);
|
||||
transaction &operator=(const transaction &t);
|
||||
virtual ~transaction();
|
||||
void set_null();
|
||||
void invalidate_hashes();
|
||||
bool is_hash_valid() const { return hash_valid.load(std::memory_order_acquire); }
|
||||
void set_hash_valid(bool v) const { hash_valid.store(v,std::memory_order_release); }
|
||||
bool is_prunable_hash_valid() const { return prunable_hash_valid.load(std::memory_order_acquire); }
|
||||
void set_prunable_hash_valid(bool v) const { prunable_hash_valid.store(v,std::memory_order_release); }
|
||||
bool is_blob_size_valid() const { return blob_size_valid.load(std::memory_order_acquire); }
|
||||
void set_blob_size_valid(bool v) const { blob_size_valid.store(v,std::memory_order_release); }
|
||||
void set_hash(const crypto::hash &h) { hash = h; set_hash_valid(true); }
|
||||
void set_blob_size(size_t sz) { blob_size = sz; set_blob_size_valid(true); }
|
||||
void set_hash(const crypto::hash &h) const { hash = h; set_hash_valid(true); }
|
||||
void set_prunable_hash(const crypto::hash &h) const { prunable_hash = h; set_prunable_hash_valid(true); }
|
||||
void set_blob_size(size_t sz) const { blob_size = sz; set_blob_size_valid(true); }
|
||||
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
if (!typename Archive<W>::is_saving())
|
||||
{
|
||||
set_hash_valid(false);
|
||||
set_prunable_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
}
|
||||
|
||||
|
@ -327,6 +333,63 @@ namespace cryptonote
|
|||
static size_t get_signature_size(const txin_v& tx_in);
|
||||
};
|
||||
|
||||
inline transaction::transaction(const transaction &t):
|
||||
transaction_prefix(t),
|
||||
hash_valid(false),
|
||||
prunable_hash_valid(false),
|
||||
blob_size_valid(false),
|
||||
signatures(t.signatures),
|
||||
rct_signatures(t.rct_signatures),
|
||||
pruned(t.pruned),
|
||||
unprunable_size(t.unprunable_size.load()),
|
||||
prefix_size(t.prefix_size.load())
|
||||
{
|
||||
if (t.is_hash_valid())
|
||||
{
|
||||
hash = t.hash;
|
||||
set_hash_valid(true);
|
||||
}
|
||||
if (t.is_blob_size_valid())
|
||||
{
|
||||
blob_size = t.blob_size;
|
||||
set_blob_size_valid(true);
|
||||
}
|
||||
if (t.is_prunable_hash_valid())
|
||||
{
|
||||
prunable_hash = t.prunable_hash;
|
||||
set_prunable_hash_valid(true);
|
||||
}
|
||||
}
|
||||
|
||||
inline transaction &transaction::operator=(const transaction &t)
|
||||
{
|
||||
transaction_prefix::operator=(t);
|
||||
|
||||
set_hash_valid(false);
|
||||
set_prunable_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
signatures = t.signatures;
|
||||
rct_signatures = t.rct_signatures;
|
||||
if (t.is_hash_valid())
|
||||
{
|
||||
hash = t.hash;
|
||||
set_hash_valid(true);
|
||||
}
|
||||
if (t.is_prunable_hash_valid())
|
||||
{
|
||||
prunable_hash = t.prunable_hash;
|
||||
set_prunable_hash_valid(true);
|
||||
}
|
||||
if (t.is_blob_size_valid())
|
||||
{
|
||||
blob_size = t.blob_size;
|
||||
set_blob_size_valid(true);
|
||||
}
|
||||
pruned = t.pruned;
|
||||
unprunable_size = t.unprunable_size.load();
|
||||
prefix_size = t.prefix_size.load();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
transaction::transaction()
|
||||
|
@ -346,6 +409,7 @@ namespace cryptonote
|
|||
signatures.clear();
|
||||
rct_signatures.type = rct::RCTTypeNull;
|
||||
set_hash_valid(false);
|
||||
set_prunable_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
pruned = false;
|
||||
unprunable_size = 0;
|
||||
|
@ -356,6 +420,7 @@ namespace cryptonote
|
|||
void transaction::invalidate_hashes()
|
||||
{
|
||||
set_hash_valid(false);
|
||||
set_prunable_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
}
|
||||
|
||||
|
@ -408,6 +473,7 @@ namespace cryptonote
|
|||
void invalidate_hashes() { set_hash_valid(false); }
|
||||
bool is_hash_valid() const { return hash_valid.load(std::memory_order_acquire); }
|
||||
void set_hash_valid(bool v) const { hash_valid.store(v,std::memory_order_release); }
|
||||
void set_hash(const crypto::hash &h) const { hash = h; set_hash_valid(true); }
|
||||
|
||||
transaction miner_tx;
|
||||
std::vector<crypto::hash> tx_hashes;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue