aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic/cryptonote_basic.h
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-03-22 18:01:09 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-03-23 09:25:17 +0000
commitf065234b71f2e3d374d44435d47db4cd75ab1294 (patch)
tree9cd0f1fae6e0eaef9cfd677f085df88a9aa5250b /src/cryptonote_basic/cryptonote_basic.h
parentMerge pull request #1901 (diff)
downloadmonero-f065234b71f2e3d374d44435d47db4cd75ab1294.tar.xz
core: cache tx and block hashes in the respective classes
An idea from smooth
Diffstat (limited to 'src/cryptonote_basic/cryptonote_basic.h')
-rw-r--r--src/cryptonote_basic/cryptonote_basic.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/cryptonote_basic/cryptonote_basic.h b/src/cryptonote_basic/cryptonote_basic.h
index ed2787cf7..3492ace2b 100644
--- a/src/cryptonote_basic/cryptonote_basic.h
+++ b/src/cryptonote_basic/cryptonote_basic.h
@@ -190,11 +190,24 @@ namespace cryptonote
std::vector<std::vector<crypto::signature> > signatures; //count signatures always the same as inputs count
rct::rctSig rct_signatures;
+ // hash cash
+ mutable crypto::hash hash;
+ mutable size_t blob_size;
+ mutable bool hash_valid;
+ mutable bool blob_size_valid;
+
transaction();
virtual ~transaction();
void set_null();
+ void invalidate_hashes();
BEGIN_SERIALIZE_OBJECT()
+ if (!typename Archive<W>::is_saving())
+ {
+ hash_valid = false;
+ blob_size_valid = false;
+ }
+
FIELDS(*static_cast<transaction_prefix *>(this))
if (version == 1)
@@ -299,6 +312,15 @@ namespace cryptonote
extra.clear();
signatures.clear();
rct_signatures.type = rct::RCTTypeNull;
+ hash_valid = false;
+ blob_size_valid = false;
+ }
+
+ inline
+ void transaction::invalidate_hashes()
+ {
+ hash_valid = false;
+ blob_size_valid = false;
}
inline
@@ -339,10 +361,20 @@ namespace cryptonote
struct block: public block_header
{
+ block(): block_header(), hash_valid(false) {}
+ void invalidate_hashes() { hash_valid = false; }
+
transaction miner_tx;
std::vector<crypto::hash> tx_hashes;
+ // hash cash
+ mutable crypto::hash hash;
+ mutable bool hash_valid;
+
BEGIN_SERIALIZE_OBJECT()
+ if (!typename Archive<W>::is_saving())
+ hash_valid = false;
+
FIELDS(*static_cast<block_header *>(this))
FIELD(miner_tx)
FIELD(tx_hashes)