Bitcoin Core  24.99.0
P2P Digital Currency
blockfilterindex.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <map>
6 
7 #include <dbwrapper.h>
8 #include <hash.h>
10 #include <node/blockstorage.h>
11 #include <util/system.h>
12 #include <validation.h>
13 
15 
16 /* The index database stores three items for each block: the disk location of the encoded filter,
17  * its dSHA256 hash, and the header. Those belonging to blocks on the active chain are indexed by
18  * height, and those belonging to blocks that have been reorganized out of the active chain are
19  * indexed by block hash. This ensures that filter data for any block that becomes part of the
20  * active chain can always be retrieved, alleviating timing concerns.
21  *
22  * The filters themselves are stored in flat files and referenced by the LevelDB entries. This
23  * minimizes the amount of data written to LevelDB and keeps the database values constant size. The
24  * disk location of the next block filter to be written (represented as a FlatFilePos) is stored
25  * under the DB_FILTER_POS key.
26  *
27  * Keys for the height index have the type [DB_BLOCK_HEIGHT, uint32 (BE)]. The height is represented
28  * as big-endian so that sequential reads of filters by height are fast.
29  * Keys for the hash index have the type [DB_BLOCK_HASH, uint256].
30  */
31 constexpr uint8_t DB_BLOCK_HASH{'s'};
32 constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
33 constexpr uint8_t DB_FILTER_POS{'P'};
34 
35 constexpr unsigned int MAX_FLTR_FILE_SIZE = 0x1000000; // 16 MiB
37 constexpr unsigned int FLTR_FILE_CHUNK_SIZE = 0x100000; // 1 MiB
43 constexpr size_t CF_HEADERS_CACHE_MAX_SZ{2000};
44 
45 namespace {
46 
47 struct DBVal {
48  uint256 hash;
49  uint256 header;
50  FlatFilePos pos;
51 
52  SERIALIZE_METHODS(DBVal, obj) { READWRITE(obj.hash, obj.header, obj.pos); }
53 };
54 
55 struct DBHeightKey {
56  int height;
57 
58  explicit DBHeightKey(int height_in) : height(height_in) {}
59 
60  template<typename Stream>
61  void Serialize(Stream& s) const
62  {
64  ser_writedata32be(s, height);
65  }
66 
67  template<typename Stream>
68  void Unserialize(Stream& s)
69  {
70  const uint8_t prefix{ser_readdata8(s)};
71  if (prefix != DB_BLOCK_HEIGHT) {
72  throw std::ios_base::failure("Invalid format for block filter index DB height key");
73  }
74  height = ser_readdata32be(s);
75  }
76 };
77 
78 struct DBHashKey {
79  uint256 hash;
80 
81  explicit DBHashKey(const uint256& hash_in) : hash(hash_in) {}
82 
83  SERIALIZE_METHODS(DBHashKey, obj) {
84  uint8_t prefix{DB_BLOCK_HASH};
86  if (prefix != DB_BLOCK_HASH) {
87  throw std::ios_base::failure("Invalid format for block filter index DB hash key");
88  }
89 
90  READWRITE(obj.hash);
91  }
92 };
93 
94 }; // namespace
95 
96 static std::map<BlockFilterType, BlockFilterIndex> g_filter_indexes;
97 
98 BlockFilterIndex::BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain, BlockFilterType filter_type,
99  size_t n_cache_size, bool f_memory, bool f_wipe)
100  : BaseIndex(std::move(chain), BlockFilterTypeName(filter_type) + " block filter index")
101  , m_filter_type(filter_type)
102 {
103  const std::string& filter_name = BlockFilterTypeName(filter_type);
104  if (filter_name.empty()) throw std::invalid_argument("unknown filter_type");
105 
106  fs::path path = gArgs.GetDataDirNet() / "indexes" / "blockfilter" / fs::u8path(filter_name);
108 
109  m_db = std::make_unique<BaseIndex::DB>(path / "db", n_cache_size, f_memory, f_wipe);
110  m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
111 }
112 
113 bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockKey>& block)
114 {
115  if (!m_db->Read(DB_FILTER_POS, m_next_filter_pos)) {
116  // Check that the cause of the read failure is that the key does not exist. Any other errors
117  // indicate database corruption or a disk failure, and starting the index would cause
118  // further corruption.
119  if (m_db->Exists(DB_FILTER_POS)) {
120  return error("%s: Cannot read current %s state; index may be corrupted",
121  __func__, GetName());
122  }
123 
124  // If the DB_FILTER_POS is not set, then initialize to the first location.
127  }
128  return true;
129 }
130 
132 {
133  const FlatFilePos& pos = m_next_filter_pos;
134 
135  // Flush current filter file to disk.
136  AutoFile file{m_filter_fileseq->Open(pos)};
137  if (file.IsNull()) {
138  return error("%s: Failed to open filter file %d", __func__, pos.nFile);
139  }
140  if (!FileCommit(file.Get())) {
141  return error("%s: Failed to commit filter file %d", __func__, pos.nFile);
142  }
143 
144  batch.Write(DB_FILTER_POS, pos);
145  return true;
146 }
147 
148 bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, const uint256& hash, BlockFilter& filter) const
149 {
150  AutoFile filein{m_filter_fileseq->Open(pos, true)};
151  if (filein.IsNull()) {
152  return false;
153  }
154 
155  // Check that the hash of the encoded_filter matches the one stored in the db.
156  uint256 block_hash;
157  std::vector<uint8_t> encoded_filter;
158  try {
159  filein >> block_hash >> encoded_filter;
160  uint256 result;
161  CHash256().Write(encoded_filter).Finalize(result);
162  if (result != hash) return error("Checksum mismatch in filter decode.");
163  filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter), /*skip_decode_check=*/true);
164  }
165  catch (const std::exception& e) {
166  return error("%s: Failed to deserialize block filter from disk: %s", __func__, e.what());
167  }
168 
169  return true;
170 }
171 
173 {
174  assert(filter.GetFilterType() == GetFilterType());
175 
176  size_t data_size =
179 
180  // If writing the filter would overflow the file, flush and move to the next one.
181  if (pos.nPos + data_size > MAX_FLTR_FILE_SIZE) {
182  AutoFile last_file{m_filter_fileseq->Open(pos)};
183  if (last_file.IsNull()) {
184  LogPrintf("%s: Failed to open filter file %d\n", __func__, pos.nFile);
185  return 0;
186  }
187  if (!TruncateFile(last_file.Get(), pos.nPos)) {
188  LogPrintf("%s: Failed to truncate filter file %d\n", __func__, pos.nFile);
189  return 0;
190  }
191  if (!FileCommit(last_file.Get())) {
192  LogPrintf("%s: Failed to commit filter file %d\n", __func__, pos.nFile);
193  return 0;
194  }
195 
196  pos.nFile++;
197  pos.nPos = 0;
198  }
199 
200  // Pre-allocate sufficient space for filter data.
201  bool out_of_space;
202  m_filter_fileseq->Allocate(pos, data_size, out_of_space);
203  if (out_of_space) {
204  LogPrintf("%s: out of disk space\n", __func__);
205  return 0;
206  }
207 
208  AutoFile fileout{m_filter_fileseq->Open(pos)};
209  if (fileout.IsNull()) {
210  LogPrintf("%s: Failed to open filter file %d\n", __func__, pos.nFile);
211  return 0;
212  }
213 
214  fileout << filter.GetBlockHash() << filter.GetEncodedFilter();
215  return data_size;
216 }
217 
219 {
220  CBlockUndo block_undo;
221  uint256 prev_header;
222 
223  if (block.height > 0) {
224  // pindex variable gives indexing code access to node internals. It
225  // will be removed in upcoming commit
226  const CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate->m_blockman.LookupBlockIndex(block.hash));
227  if (!UndoReadFromDisk(block_undo, pindex)) {
228  return false;
229  }
230 
231  std::pair<uint256, DBVal> read_out;
232  if (!m_db->Read(DBHeightKey(block.height - 1), read_out)) {
233  return false;
234  }
235 
236  uint256 expected_block_hash = *Assert(block.prev_hash);
237  if (read_out.first != expected_block_hash) {
238  return error("%s: previous block header belongs to unexpected block %s; expected %s",
239  __func__, read_out.first.ToString(), expected_block_hash.ToString());
240  }
241 
242  prev_header = read_out.second.header;
243  }
244 
245  BlockFilter filter(m_filter_type, *Assert(block.data), block_undo);
246 
247  size_t bytes_written = WriteFilterToDisk(m_next_filter_pos, filter);
248  if (bytes_written == 0) return false;
249 
250  std::pair<uint256, DBVal> value;
251  value.first = block.hash;
252  value.second.hash = filter.GetHash();
253  value.second.header = filter.ComputeHeader(prev_header);
254  value.second.pos = m_next_filter_pos;
255 
256  if (!m_db->Write(DBHeightKey(block.height), value)) {
257  return false;
258  }
259 
260  m_next_filter_pos.nPos += bytes_written;
261  return true;
262 }
263 
265  const std::string& index_name,
266  int start_height, int stop_height)
267 {
268  DBHeightKey key(start_height);
269  db_it.Seek(key);
270 
271  for (int height = start_height; height <= stop_height; ++height) {
272  if (!db_it.GetKey(key) || key.height != height) {
273  return error("%s: unexpected key in %s: expected (%c, %d)",
274  __func__, index_name, DB_BLOCK_HEIGHT, height);
275  }
276 
277  std::pair<uint256, DBVal> value;
278  if (!db_it.GetValue(value)) {
279  return error("%s: unable to read value in %s at key (%c, %d)",
280  __func__, index_name, DB_BLOCK_HEIGHT, height);
281  }
282 
283  batch.Write(DBHashKey(value.first), std::move(value.second));
284 
285  db_it.Next();
286  }
287  return true;
288 }
289 
291 {
292  CDBBatch batch(*m_db);
293  std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
294 
295  // During a reorg, we need to copy all filters for blocks that are getting disconnected from the
296  // height index to the hash index so we can still find them when the height index entries are
297  // overwritten.
298  if (!CopyHeightIndexToHashIndex(*db_it, batch, m_name, new_tip.height, current_tip.height)) {
299  return false;
300  }
301 
302  // The latest filter position gets written in Commit by the call to the BaseIndex::Rewind.
303  // But since this creates new references to the filter, the position should get updated here
304  // atomically as well in case Commit fails.
306  if (!m_db->WriteBatch(batch)) return false;
307 
308  return true;
309 }
310 
311 static bool LookupOne(const CDBWrapper& db, const CBlockIndex* block_index, DBVal& result)
312 {
313  // First check if the result is stored under the height index and the value there matches the
314  // block hash. This should be the case if the block is on the active chain.
315  std::pair<uint256, DBVal> read_out;
316  if (!db.Read(DBHeightKey(block_index->nHeight), read_out)) {
317  return false;
318  }
319  if (read_out.first == block_index->GetBlockHash()) {
320  result = std::move(read_out.second);
321  return true;
322  }
323 
324  // If value at the height index corresponds to an different block, the result will be stored in
325  // the hash index.
326  return db.Read(DBHashKey(block_index->GetBlockHash()), result);
327 }
328 
329 static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start_height,
330  const CBlockIndex* stop_index, std::vector<DBVal>& results)
331 {
332  if (start_height < 0) {
333  return error("%s: start height (%d) is negative", __func__, start_height);
334  }
335  if (start_height > stop_index->nHeight) {
336  return error("%s: start height (%d) is greater than stop height (%d)",
337  __func__, start_height, stop_index->nHeight);
338  }
339 
340  size_t results_size = static_cast<size_t>(stop_index->nHeight - start_height + 1);
341  std::vector<std::pair<uint256, DBVal>> values(results_size);
342 
343  DBHeightKey key(start_height);
344  std::unique_ptr<CDBIterator> db_it(db.NewIterator());
345  db_it->Seek(DBHeightKey(start_height));
346  for (int height = start_height; height <= stop_index->nHeight; ++height) {
347  if (!db_it->Valid() || !db_it->GetKey(key) || key.height != height) {
348  return false;
349  }
350 
351  size_t i = static_cast<size_t>(height - start_height);
352  if (!db_it->GetValue(values[i])) {
353  return error("%s: unable to read value in %s at key (%c, %d)",
354  __func__, index_name, DB_BLOCK_HEIGHT, height);
355  }
356 
357  db_it->Next();
358  }
359 
360  results.resize(results_size);
361 
362  // Iterate backwards through block indexes collecting results in order to access the block hash
363  // of each entry in case we need to look it up in the hash index.
364  for (const CBlockIndex* block_index = stop_index;
365  block_index && block_index->nHeight >= start_height;
366  block_index = block_index->pprev) {
367  uint256 block_hash = block_index->GetBlockHash();
368 
369  size_t i = static_cast<size_t>(block_index->nHeight - start_height);
370  if (block_hash == values[i].first) {
371  results[i] = std::move(values[i].second);
372  continue;
373  }
374 
375  if (!db.Read(DBHashKey(block_hash), results[i])) {
376  return error("%s: unable to read value in %s at key (%c, %s)",
377  __func__, index_name, DB_BLOCK_HASH, block_hash.ToString());
378  }
379  }
380 
381  return true;
382 }
383 
384 bool BlockFilterIndex::LookupFilter(const CBlockIndex* block_index, BlockFilter& filter_out) const
385 {
386  DBVal entry;
387  if (!LookupOne(*m_db, block_index, entry)) {
388  return false;
389  }
390 
391  return ReadFilterFromDisk(entry.pos, entry.hash, filter_out);
392 }
393 
394 bool BlockFilterIndex::LookupFilterHeader(const CBlockIndex* block_index, uint256& header_out)
395 {
397 
398  bool is_checkpoint{block_index->nHeight % CFCHECKPT_INTERVAL == 0};
399 
400  if (is_checkpoint) {
401  // Try to find the block in the headers cache if this is a checkpoint height.
402  auto header = m_headers_cache.find(block_index->GetBlockHash());
403  if (header != m_headers_cache.end()) {
404  header_out = header->second;
405  return true;
406  }
407  }
408 
409  DBVal entry;
410  if (!LookupOne(*m_db, block_index, entry)) {
411  return false;
412  }
413 
414  if (is_checkpoint &&
415  m_headers_cache.size() < CF_HEADERS_CACHE_MAX_SZ) {
416  // Add to the headers cache if this is a checkpoint height.
417  m_headers_cache.emplace(block_index->GetBlockHash(), entry.header);
418  }
419 
420  header_out = entry.header;
421  return true;
422 }
423 
424 bool BlockFilterIndex::LookupFilterRange(int start_height, const CBlockIndex* stop_index,
425  std::vector<BlockFilter>& filters_out) const
426 {
427  std::vector<DBVal> entries;
428  if (!LookupRange(*m_db, m_name, start_height, stop_index, entries)) {
429  return false;
430  }
431 
432  filters_out.resize(entries.size());
433  auto filter_pos_it = filters_out.begin();
434  for (const auto& entry : entries) {
435  if (!ReadFilterFromDisk(entry.pos, entry.hash, *filter_pos_it)) {
436  return false;
437  }
438  ++filter_pos_it;
439  }
440 
441  return true;
442 }
443 
444 bool BlockFilterIndex::LookupFilterHashRange(int start_height, const CBlockIndex* stop_index,
445  std::vector<uint256>& hashes_out) const
446 
447 {
448  std::vector<DBVal> entries;
449  if (!LookupRange(*m_db, m_name, start_height, stop_index, entries)) {
450  return false;
451  }
452 
453  hashes_out.clear();
454  hashes_out.reserve(entries.size());
455  for (const auto& entry : entries) {
456  hashes_out.push_back(entry.hash);
457  }
458  return true;
459 }
460 
462 {
463  auto it = g_filter_indexes.find(filter_type);
464  return it != g_filter_indexes.end() ? &it->second : nullptr;
465 }
466 
467 void ForEachBlockFilterIndex(std::function<void (BlockFilterIndex&)> fn)
468 {
469  for (auto& entry : g_filter_indexes) fn(entry.second);
470 }
471 
472 bool InitBlockFilterIndex(std::function<std::unique_ptr<interfaces::Chain>()> make_chain, BlockFilterType filter_type,
473  size_t n_cache_size, bool f_memory, bool f_wipe)
474 {
475  auto result = g_filter_indexes.emplace(std::piecewise_construct,
476  std::forward_as_tuple(filter_type),
477  std::forward_as_tuple(make_chain(), filter_type,
478  n_cache_size, f_memory, f_wipe));
479  return result.second;
480 }
481 
483 {
484  return g_filter_indexes.erase(filter_type);
485 }
486 
488 {
489  g_filter_indexes.clear();
490 }
const std::string & BlockFilterTypeName(BlockFilterType filter_type)
Get the human-readable name for a filter type.
BlockFilterType
Definition: blockfilter.h:90
constexpr unsigned int FLTR_FILE_CHUNK_SIZE
The pre-allocation chunk size for fltr?????.dat files.
bool DestroyBlockFilterIndex(BlockFilterType filter_type)
Destroy the block filter index with the given type.
void DestroyAllBlockFilterIndexes()
Destroy all open block filter indexes.
static bool CopyHeightIndexToHashIndex(CDBIterator &db_it, CDBBatch &batch, const std::string &index_name, int start_height, int stop_height)
constexpr uint8_t DB_FILTER_POS
static bool LookupOne(const CDBWrapper &db, const CBlockIndex *block_index, DBVal &result)
BlockFilterIndex * GetBlockFilterIndex(BlockFilterType filter_type)
Get a block filter index by type.
constexpr unsigned int MAX_FLTR_FILE_SIZE
constexpr uint8_t DB_BLOCK_HASH
void ForEachBlockFilterIndex(std::function< void(BlockFilterIndex &)> fn)
Iterate over all running block filter indexes, invoking fn on each.
constexpr size_t CF_HEADERS_CACHE_MAX_SZ
Maximum size of the cfheaders cache We have a limit to prevent a bug in filling this cache potentiall...
bool InitBlockFilterIndex(std::function< std::unique_ptr< interfaces::Chain >()> make_chain, BlockFilterType filter_type, size_t n_cache_size, bool f_memory, bool f_wipe)
Initialize a block filter index for the given type if one does not already exist.
static bool LookupRange(CDBWrapper &db, const std::string &index_name, int start_height, const CBlockIndex *stop_index, std::vector< DBVal > &results)
constexpr uint8_t DB_BLOCK_HEIGHT
static std::map< BlockFilterType, BlockFilterIndex > g_filter_indexes
static constexpr int CFCHECKPT_INTERVAL
Interval between compact filter checkpoints.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: validation.cpp:121
#define Assert(val)
Identity function.
Definition: check.h:74
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: system.h:303
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:475
Base class for indices of blockchain data.
Definition: base.h:34
const std::string & GetName() const LIFETIMEBOUND
Get the name of the index for display in logs.
Definition: base.h:123
const std::string m_name
Definition: base.h:100
Chainstate * m_chainstate
Definition: base.h:99
Complete block filter struct as defined in BIP 157.
Definition: blockfilter.h:112
uint256 ComputeHeader(const uint256 &prev_header) const
Compute the filter header given the previous one.
BlockFilterType GetFilterType() const
Definition: blockfilter.h:131
uint256 GetHash() const
Compute the filter hash.
const uint256 & GetBlockHash() const LIFETIMEBOUND
Definition: blockfilter.h:132
const std::vector< unsigned char > & GetEncodedFilter() const LIFETIMEBOUND
Definition: blockfilter.h:135
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
std::unique_ptr< BaseIndex::DB > m_db
bool LookupFilterRange(int start_height, const CBlockIndex *stop_index, std::vector< BlockFilter > &filters_out) const
Get a range of filters between two heights on a chain.
bool CustomInit(const std::optional< interfaces::BlockKey > &block) override
Initialize internal state from the database and block index.
BlockFilterType GetFilterType() const
bool CustomCommit(CDBBatch &batch) override
Virtual method called internally by Commit that can be overridden to atomically commit more index sta...
BlockFilterType m_filter_type
BlockFilterIndex(std::unique_ptr< interfaces::Chain > chain, BlockFilterType filter_type, size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
Constructs the index, which becomes available to be queried.
std::unique_ptr< FlatFileSeq > m_filter_fileseq
bool LookupFilter(const CBlockIndex *block_index, BlockFilter &filter_out) const
Get a single filter by block.
bool ReadFilterFromDisk(const FlatFilePos &pos, const uint256 &hash, BlockFilter &filter) const
bool LookupFilterHashRange(int start_height, const CBlockIndex *stop_index, std::vector< uint256 > &hashes_out) const
Get a range of filter hashes between two heights on a chain.
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
bool CustomRewind(const interfaces::BlockKey &current_tip, const interfaces::BlockKey &new_tip) override
Rewind index to an earlier chain tip during a chain reorg.
size_t WriteFilterToDisk(FlatFilePos &pos, const BlockFilter &filter)
bool LookupFilterHeader(const CBlockIndex *block_index, uint256 &header_out) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_headers_cache)
Get a single filter header by block.
FlatFilePos m_next_filter_pos
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:152
uint256 GetBlockHash() const
Definition: chain.h:264
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:164
Undo information for a CBlock.
Definition: undo.h:64
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:60
void Write(const K &key, const V &value)
Definition: dbwrapper.h:85
bool GetValue(V &value)
Definition: dbwrapper.h:170
bool GetKey(K &key)
Definition: dbwrapper.h:159
void Seek(const K &key)
Definition: dbwrapper.h:149
void Next()
Definition: dbwrapper.cpp:257
CDBIterator * NewIterator()
Definition: dbwrapper.h:303
bool Read(const K &key, V &value) const
Definition: dbwrapper.h:238
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
Definition: hash.h:23
CHash256 & Write(Span< const unsigned char > input)
Definition: hash.h:36
void Finalize(Span< unsigned char > output)
Definition: hash.h:29
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
Definition: validation.h:476
std::string ToString() const
Definition: uint256.cpp:64
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:31
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
256-bit opaque blob.
Definition: uint256.h:119
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
Definition: clientversion.h:33
#define LogPrintf(...)
Definition: logging.h:234
static path u8path(const std::string &utf8_str)
Definition: fs.h:70
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
Definition: fs.h:188
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex)
const char * prefix
Definition: rest.cpp:930
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
uint8_t ser_readdata8(Stream &s)
Definition: serialize.h:82
void ser_writedata32be(Stream &s, uint32_t obj)
Definition: serialize.h:72
#define SERIALIZE_METHODS(cls, obj)
Implement the Serialize and Unserialize methods by delegating to a single templated static method tha...
Definition: serialize.h:176
void Unserialize(Stream &, char)=delete
void ser_writedata8(Stream &s, uint8_t obj)
Definition: serialize.h:53
size_t GetSerializeSize(const T &t, int nVersion=0)
Definition: serialize.h:1109
uint32_t ser_readdata32be(Stream &s)
Definition: serialize.h:106
#define READWRITE(...)
Definition: serialize.h:140
void Serialize(Stream &, char)=delete
int nFile
Definition: flatfile.h:16
unsigned int nPos
Definition: flatfile.h:17
Block data sent with blockConnected, blockDisconnected notifications.
Definition: chain.h:81
const uint256 * prev_hash
Definition: chain.h:83
const CBlock * data
Definition: chain.h:87
const uint256 & hash
Definition: chain.h:82
Hash/height pair to help track and identify blocks.
Definition: chain.h:42
#define LOCK(cs)
Definition: sync.h:261
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:305
bool error(const char *fmt, const Args &... args)
Definition: system.h:48
ArgsManager gArgs
Definition: system.cpp:86
bool TruncateFile(FILE *file, unsigned int length)
Definition: system.cpp:1215
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
Definition: system.cpp:1173
assert(!tx.IsCoinBase())