From a489420e16cb3470ceaa1ab96d031221d25d1e56 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 17 Aug 2020 12:47:05 +0200 Subject: [PATCH 1/2] Merge #19734: Move CDiskTxPos to its own file 7668db3b08531a590089d66cc5c91f1fb3afbfcc Move only: Move CDiskTxPos to its own file (Marcin Jachymiak) Pull request description: Moves `CDiskTxPos` it its own file so it can be used without the `txindex.h` include elsewhere. Originally part of #14053. ACKs for top commit: jnewbery: utACK 7668db3b08531a590089d66cc5c91f1fb3afbfcc promag: ACK 7668db3b08531a590089d66cc5c91f1fb3afbfcc. Tree-SHA512: b108e980ad04e43d1323410c3683a82bed70aee7795f5d8a2afbaf32a07ba598571f00b047bdde15048124b17178bcbd10654c48461beac988e9643cb2df664c --- src/Makefile.am | 1 + src/index/disktxpos.h | 37 +++++++++++++++++++++++++++++++++++++ src/index/txindex.cpp | 24 +----------------------- 3 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 src/index/disktxpos.h diff --git a/src/Makefile.am b/src/Makefile.am index ccb56cea57..4febdf3dc8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -178,6 +178,7 @@ BITCOIN_CORE_H = \ httpserver.h \ index/base.h \ index/blockfilterindex.h \ + index/disktxpos.h \ index/txindex.h \ indirectmap.h \ init.h \ diff --git a/src/index/disktxpos.h b/src/index/disktxpos.h new file mode 100644 index 0000000000..8cd2270028 --- /dev/null +++ b/src/index/disktxpos.h @@ -0,0 +1,37 @@ +// Copyright (c) 2019 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_DISKTXPOS_H +#define BITCOIN_INDEX_DISKTXPOS_H + +#include +#include +#include +#include + +struct CDiskTxPos : public FlatFilePos +{ + unsigned int nTxOffset; // after header + + SERIALIZE_METHODS(CDiskTxPos, obj) + { + READWRITEAS(FlatFilePos, obj); + READWRITE(VARINT(obj.nTxOffset)); + } + + CDiskTxPos(const FlatFilePos &blockIn, unsigned int nTxOffsetIn) : FlatFilePos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) { + } + + CDiskTxPos() { + SetNull(); + } + + void SetNull() { + FlatFilePos::SetNull(); + nTxOffset = 0; + } +}; + + +#endif // BITCOIN_INDEX_DISKTXPOS_H diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index d4c8ce8de7..a77d73a391 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include #include @@ -16,29 +17,6 @@ constexpr char DB_TXINDEX_BLOCK = 'T'; std::unique_ptr g_txindex; -struct CDiskTxPos : public FlatFilePos -{ - unsigned int nTxOffset; // after header - - SERIALIZE_METHODS(CDiskTxPos, obj) - { - READWRITEAS(FlatFilePos, obj); - READWRITE(VARINT(obj.nTxOffset)); - } - - CDiskTxPos(const FlatFilePos &blockIn, unsigned int nTxOffsetIn) : FlatFilePos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) { - } - - CDiskTxPos() { - SetNull(); - } - - void SetNull() { - FlatFilePos::SetNull(); - nTxOffset = 0; - } -}; - /** * Access to the txindex database (indexes/txindex/) * From 829aeff0f6d14b554b942a9afc2df3de177bcecc Mon Sep 17 00:00:00 2001 From: fanquake Date: Fri, 21 Aug 2020 12:08:38 +0800 Subject: [PATCH 2/2] Merge #19733: Move comment about BaseIndex::DB from TxIndex::DB 8ed2f1ed78937eff0bb8b5318a30da908e33af24 Remove unused includes (Marcin Jachymiak) cf095a53fcef8ad72e2f1177660ef50bc7e340ad Move comment about BaseIndex::DB from TxIndex::DB (Marcin Jachymiak) Pull request description: Moves a comment about the `BaseIndex::DB` from the `TxIndex::DB` into the correct place. Originally part of https://github.com/bitcoin/bitcoin/pull/14053. ACKs for top commit: fanquake: ACK 8ed2f1ed78937eff0bb8b5318a30da908e33af24 Tree-SHA512: cb4e2b916c7ab996961cc2e1d910bc4b8a1700eb32b70fc1657ca720117a7a84f7337fe5e4fb30e047aa92c31eaa976eaaa5cb8f861877f2ff6f4a59bb94f4e9 --- src/index/base.h | 7 +++++++ src/index/disktxpos.h | 4 +--- src/index/txindex.cpp | 12 +++--------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/index/base.h b/src/index/base.h index 31acbed0c1..84cb9c6919 100644 --- a/src/index/base.h +++ b/src/index/base.h @@ -22,6 +22,13 @@ class CBlockIndex; class BaseIndex : public CValidationInterface { protected: + /** + * The database stores a block locator of the chain the database is synced to + * so that the index can efficiently determine the point it last stopped at. + * A locator is used instead of a simple hash of the chain tip because blocks + * and block index entries may not be flushed to disk until after this database + * is updated. + */ class DB : public CDBWrapper { public: diff --git a/src/index/disktxpos.h b/src/index/disktxpos.h index 8cd2270028..69696b0ec5 100644 --- a/src/index/disktxpos.h +++ b/src/index/disktxpos.h @@ -5,10 +5,8 @@ #ifndef BITCOIN_INDEX_DISKTXPOS_H #define BITCOIN_INDEX_DISKTXPOS_H -#include #include -#include -#include +#include struct CDiskTxPos : public FlatFilePos { diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index a77d73a391..7a3df975f4 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -17,15 +17,9 @@ constexpr char DB_TXINDEX_BLOCK = 'T'; std::unique_ptr g_txindex; -/** - * Access to the txindex database (indexes/txindex/) - * - * The database stores a block locator of the chain the database is synced to - * so that the TxIndex can efficiently determine the point it last stopped at. - * A locator is used instead of a simple hash of the chain tip because blocks - * and block index entries may not be flushed to disk until after this database - * is updated. - */ + + +/** Access to the txindex database (indexes/txindex/) */ class TxIndex::DB : public BaseIndex::DB { public: