diff options
author | MacroFake <falke.marco@gmail.com> | 2022-09-01 09:47:08 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-09-01 09:47:18 +0200 |
commit | f821fc98131476880fa191ba3236a57325232a2a (patch) | |
tree | dc6414fb028f8c49635e26b0d60023930f406973 | |
parent | 6ab84709fc1dca62a7db4693e2ff72f40a7eb650 (diff) | |
parent | 89576ccc572fcaf9fb7117ad6124482cc95fbd9f (diff) | |
download | bitcoin-f821fc98131476880fa191ba3236a57325232a2a.tar.xz |
Merge bitcoin/bitcoin#25967: refactor: add LIFETIMEBOUND to blockfilter where needed
89576ccc572fcaf9fb7117ad6124482cc95fbd9f refactor: add LIFETIMEBOUND to blockfilter where needed (stickies-v)
Pull request description:
Noticed from https://github.com/bitcoin/bitcoin/pull/25637#issuecomment-1231860822 that [`BlockFilter::GetFilter()`](https://github.com/bitcoin/bitcoin/blob/01e1627e25bc5477c40f51da03c3c31b609a85c9/src/blockfilter.h#L132) returns a reference to a member variable. Added LIFETIMEBOUND to all blockfilter-related code to ensure that the return values do not have a lifetime that exceeds the lifetime of what it is bound to. See https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#lifetimebound or https://github.com/bitcoin/bitcoin/pull/25060 for a similar example.
I used `grep -E '[a-zA-Z>0-9][&*] ([a-zA-Z]*)\((.*)\)' src/**/blockfilter*` to grep all possible occurrences (not all of them require LIFETIMEBOUND)
ACKs for top commit:
brunoerg:
crACK 89576ccc572fcaf9fb7117ad6124482cc95fbd9f
Tree-SHA512: 6fe61fc0c1ed9e446edce083d1b093e1a5e2ef8c39ff74125bb12a24e514d45711845809817fbd4a04d7a9c23c8b362203771c17b6d831d2560b1af268453019
-rw-r--r-- | src/blockfilter.h | 11 | ||||
-rw-r--r-- | src/index/blockfilterindex.h | 5 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/blockfilter.h b/src/blockfilter.h index d6a51e95c2..0cb627d9df 100644 --- a/src/blockfilter.h +++ b/src/blockfilter.h @@ -11,6 +11,7 @@ #include <unordered_set> #include <vector> +#include <attributes.h> #include <primitives/block.h> #include <serialize.h> #include <uint256.h> @@ -65,8 +66,8 @@ public: GCSFilter(const Params& params, const ElementSet& elements); uint32_t GetN() const { return m_N; } - const Params& GetParams() const { return m_params; } - const std::vector<unsigned char>& GetEncoded() const { return m_encoded; } + const Params& GetParams() const LIFETIMEBOUND { return m_params; } + const std::vector<unsigned char>& GetEncoded() const LIFETIMEBOUND { return m_encoded; } /** * Checks if the element may be in the set. False positives are possible @@ -128,10 +129,10 @@ public: BlockFilter(BlockFilterType filter_type, const CBlock& block, const CBlockUndo& block_undo); BlockFilterType GetFilterType() const { return m_filter_type; } - const uint256& GetBlockHash() const { return m_block_hash; } - const GCSFilter& GetFilter() const { return m_filter; } + const uint256& GetBlockHash() const LIFETIMEBOUND { return m_block_hash; } + const GCSFilter& GetFilter() const LIFETIMEBOUND { return m_filter; } - const std::vector<unsigned char>& GetEncodedFilter() const + const std::vector<unsigned char>& GetEncodedFilter() const LIFETIMEBOUND { return m_filter.GetEncoded(); } diff --git a/src/index/blockfilterindex.h b/src/index/blockfilterindex.h index 968eccb6b3..a31f7e460e 100644 --- a/src/index/blockfilterindex.h +++ b/src/index/blockfilterindex.h @@ -5,6 +5,7 @@ #ifndef BITCOIN_INDEX_BLOCKFILTERINDEX_H #define BITCOIN_INDEX_BLOCKFILTERINDEX_H +#include <attributes.h> #include <blockfilter.h> #include <chain.h> #include <flatfile.h> @@ -49,9 +50,9 @@ protected: bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override; - BaseIndex::DB& GetDB() const override { return *m_db; } + BaseIndex::DB& GetDB() const LIFETIMEBOUND override { return *m_db; } - const char* GetName() const override { return m_name.c_str(); } + const char* GetName() const LIFETIMEBOUND override { return m_name.c_str(); } public: /** Constructs the index, which becomes available to be queried. */ |