aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic/cryptonote_basic.h
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-11-11 13:39:00 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-03-05 10:28:52 +0000
commite69477bf25630c94a5aff666433f3da9ab29298c (patch)
tree49ae5707c4ee4850e546fd7ae2da020489bc3795 /src/cryptonote_basic/cryptonote_basic.h
parentMerge pull request #5101 (diff)
downloadmonero-e69477bf25630c94a5aff666433f3da9ab29298c.tar.xz
db: speedup block addition
by avoiding repeated (de)serialization
Diffstat (limited to 'src/cryptonote_basic/cryptonote_basic.h')
-rw-r--r--src/cryptonote_basic/cryptonote_basic.h25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/cryptonote_basic/cryptonote_basic.h b/src/cryptonote_basic/cryptonote_basic.h
index c9c783a56..172a99e84 100644
--- a/src/cryptonote_basic/cryptonote_basic.h
+++ b/src/cryptonote_basic/cryptonote_basic.h
@@ -152,6 +152,10 @@ namespace cryptonote
};
+ template<typename T> static inline unsigned int getpos(T &ar) { return 0; }
+ template<> inline unsigned int getpos(binary_archive<true> &ar) { return ar.stream().tellp(); }
+ template<> inline unsigned int getpos(binary_archive<false> &ar) { return ar.stream().tellg(); }
+
class transaction_prefix
{
@@ -203,9 +207,12 @@ namespace cryptonote
bool pruned;
+ std::atomic<unsigned int> unprunable_size;
+ 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) { 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; return *this; }
+ 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; }
virtual ~transaction();
void set_null();
void invalidate_hashes();
@@ -223,10 +230,18 @@ namespace cryptonote
set_blob_size_valid(false);
}
+ const unsigned int start_pos = getpos(ar);
+
FIELDS(*static_cast<transaction_prefix *>(this))
+ if (std::is_same<Archive<W>, binary_archive<W>>())
+ prefix_size = getpos(ar) - start_pos;
+
if (version == 1)
{
+ if (std::is_same<Archive<W>, binary_archive<W>>())
+ unprunable_size = getpos(ar) - start_pos;
+
ar.tag("signatures");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(vin.size(), signatures);
@@ -265,6 +280,10 @@ namespace cryptonote
bool r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout.size());
if (!r || !ar.stream().good()) return false;
ar.end_object();
+
+ if (std::is_same<Archive<W>, binary_archive<W>>())
+ unprunable_size = getpos(ar) - start_pos;
+
if (!pruned && rct_signatures.type != rct::RCTTypeNull)
{
ar.tag("rctsig_prunable");
@@ -329,6 +348,8 @@ namespace cryptonote
set_hash_valid(false);
set_blob_size_valid(false);
pruned = false;
+ unprunable_size = 0;
+ prefix_size = 0;
}
inline