aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic/cryptonote_basic.h
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-09-16 12:18:34 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-09-27 00:10:37 +0000
commit8330e772f1ed680a54833d25c4d17d09a99ab8d6 (patch)
treed536126b06a00fabd56881363daaa9a1fd305c80 /src/cryptonote_basic/cryptonote_basic.h
parentMerge pull request #5876 (diff)
downloadmonero-8330e772f1ed680a54833d25c4d17d09a99ab8d6.tar.xz
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
Diffstat (limited to 'src/cryptonote_basic/cryptonote_basic.h')
-rw-r--r--src/cryptonote_basic/cryptonote_basic.h74
1 files changed, 70 insertions, 4 deletions
diff --git a/src/cryptonote_basic/cryptonote_basic.h b/src/cryptonote_basic/cryptonote_basic.h
index 055c4a22b..e2286ae8c 100644
--- a/src/cryptonote_basic/cryptonote_basic.h
+++ b/src/cryptonote_basic/cryptonote_basic.h
@@ -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;