Skip to content

Commit f821fc9

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25967: refactor: add LIFETIMEBOUND to blockfilter where needed
89576cc refactor: add LIFETIMEBOUND to blockfilter where needed (stickies-v) Pull request description: Noticed from bitcoin/bitcoin#25637 (comment) 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 bitcoin/bitcoin#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 89576cc Tree-SHA512: 6fe61fc0c1ed9e446edce083d1b093e1a5e2ef8c39ff74125bb12a24e514d45711845809817fbd4a04d7a9c23c8b362203771c17b6d831d2560b1af268453019
2 parents 6ab8470 + 89576cc commit f821fc9

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/blockfilter.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <unordered_set>
1212
#include <vector>
1313

14+
#include <attributes.h>
1415
#include <primitives/block.h>
1516
#include <serialize.h>
1617
#include <uint256.h>
@@ -65,8 +66,8 @@ class GCSFilter
6566
GCSFilter(const Params& params, const ElementSet& elements);
6667

6768
uint32_t GetN() const { return m_N; }
68-
const Params& GetParams() const { return m_params; }
69-
const std::vector<unsigned char>& GetEncoded() const { return m_encoded; }
69+
const Params& GetParams() const LIFETIMEBOUND { return m_params; }
70+
const std::vector<unsigned char>& GetEncoded() const LIFETIMEBOUND { return m_encoded; }
7071

7172
/**
7273
* Checks if the element may be in the set. False positives are possible
@@ -128,10 +129,10 @@ class BlockFilter
128129
BlockFilter(BlockFilterType filter_type, const CBlock& block, const CBlockUndo& block_undo);
129130

130131
BlockFilterType GetFilterType() const { return m_filter_type; }
131-
const uint256& GetBlockHash() const { return m_block_hash; }
132-
const GCSFilter& GetFilter() const { return m_filter; }
132+
const uint256& GetBlockHash() const LIFETIMEBOUND { return m_block_hash; }
133+
const GCSFilter& GetFilter() const LIFETIMEBOUND { return m_filter; }
133134

134-
const std::vector<unsigned char>& GetEncodedFilter() const
135+
const std::vector<unsigned char>& GetEncodedFilter() const LIFETIMEBOUND
135136
{
136137
return m_filter.GetEncoded();
137138
}

src/index/blockfilterindex.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_INDEX_BLOCKFILTERINDEX_H
66
#define BITCOIN_INDEX_BLOCKFILTERINDEX_H
77

8+
#include <attributes.h>
89
#include <blockfilter.h>
910
#include <chain.h>
1011
#include <flatfile.h>
@@ -49,9 +50,9 @@ class BlockFilterIndex final : public BaseIndex
4950

5051
bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override;
5152

52-
BaseIndex::DB& GetDB() const override { return *m_db; }
53+
BaseIndex::DB& GetDB() const LIFETIMEBOUND override { return *m_db; }
5354

54-
const char* GetName() const override { return m_name.c_str(); }
55+
const char* GetName() const LIFETIMEBOUND override { return m_name.c_str(); }
5556

5657
public:
5758
/** Constructs the index, which becomes available to be queried. */

0 commit comments

Comments
 (0)