diff options
author | Jim Posen <jim.posen@gmail.com> | 2018-08-27 17:01:24 -0700 |
---|---|---|
committer | Jim Posen <jim.posen@gmail.com> | 2019-04-06 12:10:22 -0700 |
commit | 75a76e36199eba228856d59318cb54ca64ca6b57 (patch) | |
tree | dc0a24d1c8d9f9cc55fddc6f71cf43a09f4e9385 /src/index/blockfilterindex.h | |
parent | 2ad2338ef90bf661c19305afaf2fb648997b0c92 (diff) | |
download | bitcoin-75a76e36199eba228856d59318cb54ca64ca6b57.tar.xz |
index: Implement block filter index with write operations.
Diffstat (limited to 'src/index/blockfilterindex.h')
-rw-r--r-- | src/index/blockfilterindex.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/index/blockfilterindex.h b/src/index/blockfilterindex.h new file mode 100644 index 0000000000..d2dd3a27bc --- /dev/null +++ b/src/index/blockfilterindex.h @@ -0,0 +1,53 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_INDEX_BLOCKFILTERINDEX_H +#define BITCOIN_INDEX_BLOCKFILTERINDEX_H + +#include <blockfilter.h> +#include <chain.h> +#include <flatfile.h> +#include <index/base.h> + +/** + * BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of + * blocks by height. An index is constructed for each supported filter type with its own database + * (ie. filter data for different types are stored in separate databases). + * + * This index is used to serve BIP 157 net requests. + */ +class BlockFilterIndex final : public BaseIndex +{ +private: + BlockFilterType m_filter_type; + std::string m_name; + std::unique_ptr<BaseIndex::DB> m_db; + + FlatFilePos m_next_filter_pos; + std::unique_ptr<FlatFileSeq> m_filter_fileseq; + + size_t WriteFilterToDisk(FlatFilePos& pos, const BlockFilter& filter); + +protected: + bool Init() override; + + bool CommitInternal(CDBBatch& batch) override; + + bool WriteBlock(const CBlock& block, const CBlockIndex* pindex) override; + + bool Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip) override; + + BaseIndex::DB& GetDB() const override { return *m_db; } + + const char* GetName() const override { return m_name.c_str(); } + +public: + /** Constructs the index, which becomes available to be queried. */ + explicit BlockFilterIndex(BlockFilterType filter_type, + size_t n_cache_size, bool f_memory = false, bool f_wipe = false); + + BlockFilterType GetFilterType() const { return m_filter_type; } +}; + +#endif // BITCOIN_INDEX_BLOCKFILTERINDEX_H |