diff options
author | Suhas Daftuar <sdaftuar@chaincode.com> | 2023-06-27 12:11:34 -0400 |
---|---|---|
committer | Suhas Daftuar <sdaftuar@chaincode.com> | 2023-07-24 16:23:38 -0400 |
commit | d4a11abb1972b54f0babdccfbb2fde97ab885933 (patch) | |
tree | ae48398820384ca2a159c80887e378c11884f82c /src/validation.h | |
parent | 3556b850221bc0e597d7dd749d4d47ab58dc8083 (diff) |
Cache block index entry corresponding to assumeutxo snapshot base blockhash
This is to (a) avoid repeated lookups into the block index for an entry that
should never change and (b) emphasize that the snapshot base should always
exist when set and not change during the runtime of the program.
Thanks to Russ Yanofsky for suggesting this approach.
Diffstat (limited to 'src/validation.h')
-rw-r--r-- | src/validation.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/validation.h b/src/validation.h index 4fecc13071..b983876c66 100644 --- a/src/validation.h +++ b/src/validation.h @@ -500,6 +500,9 @@ protected: //! is set to true on the snapshot chainstate. bool m_disabled GUARDED_BY(::cs_main) {false}; + //! Cached result of LookupBlockIndex(*m_from_snapshot_blockhash) + const CBlockIndex* m_cached_snapshot_base GUARDED_BY(::cs_main) {nullptr}; + public: //! Reference to a BlockManager instance which itself is shared across all //! Chainstate instances. @@ -551,6 +554,13 @@ public: */ const std::optional<uint256> m_from_snapshot_blockhash; + /** + * The base of the snapshot this chainstate was created from. + * + * nullptr if this chainstate was not created from a snapshot. + */ + const CBlockIndex* SnapshotBase() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + //! Return true if this chainstate relies on blocks that are assumed-valid. In //! practice this means it was created based on a UTXO snapshot. bool reliesOnAssumedValid() { return m_from_snapshot_blockhash.has_value(); } |