Skip to content

Commit 89576cc

Browse files
committed
refactor: add LIFETIMEBOUND to blockfilter where needed
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
1 parent 8343420 commit 89576cc

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)