Bitcoin Core  29.1.0
P2P Digital Currency
base.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017-present 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 <chainparams.h>
6 #include <common/args.h>
7 #include <index/base.h>
8 #include <interfaces/chain.h>
9 #include <kernel/chain.h>
10 #include <logging.h>
11 #include <node/abort.h>
12 #include <node/blockstorage.h>
13 #include <node/context.h>
14 #include <node/database_args.h>
15 #include <node/interface_ui.h>
16 #include <tinyformat.h>
17 #include <util/string.h>
18 #include <util/thread.h>
19 #include <util/translation.h>
20 #include <validation.h> // For g_chainman
21 
22 #include <string>
23 #include <utility>
24 
25 constexpr uint8_t DB_BEST_BLOCK{'B'};
26 
27 constexpr auto SYNC_LOG_INTERVAL{30s};
28 constexpr auto SYNC_LOCATOR_WRITE_INTERVAL{30s};
29 
30 template <typename... Args>
31 void BaseIndex::FatalErrorf(util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
32 {
33  auto message = tfm::format(fmt, args...);
34  node::AbortNode(m_chain->context()->shutdown_request, m_chain->context()->exit_status, Untranslated(message), m_chain->context()->warnings.get());
35 }
36 
38 {
39  CBlockLocator locator;
40  bool found = chain.findBlock(block_hash, interfaces::FoundBlock().locator(locator));
41  assert(found);
42  assert(!locator.IsNull());
43  return locator;
44 }
45 
46 BaseIndex::DB::DB(const fs::path& path, size_t n_cache_size, bool f_memory, bool f_wipe, bool f_obfuscate) :
48  .path = path,
49  .cache_bytes = n_cache_size,
50  .memory_only = f_memory,
51  .wipe_data = f_wipe,
52  .obfuscate = f_obfuscate,
53  .options = [] { DBOptions options; node::ReadDatabaseArgs(gArgs, options); return options; }()}}
54 {}
55 
57 {
58  bool success = Read(DB_BEST_BLOCK, locator);
59  if (!success) {
60  locator.SetNull();
61  }
62  return success;
63 }
64 
66 {
67  batch.Write(DB_BEST_BLOCK, locator);
68 }
69 
70 BaseIndex::BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name)
71  : m_chain{std::move(chain)}, m_name{std::move(name)} {}
72 
74 {
75  Interrupt();
76  Stop();
77 }
78 
80 {
82 
83  // May need reset if index is being restarted.
85 
86  // m_chainstate member gives indexing code access to node internals. It is
87  // removed in followup https://github.com/bitcoin/bitcoin/pull/24230
89  return &m_chain->context()->chainman->GetChainstateForIndexing());
90  // Register to validation interface before setting the 'm_synced' flag, so that
91  // callbacks are not missed once m_synced is true.
92  m_chain->context()->validation_signals->RegisterValidationInterface(this);
93 
94  CBlockLocator locator;
95  if (!GetDB().ReadBestBlock(locator)) {
96  locator.SetNull();
97  }
98 
99  LOCK(cs_main);
100  CChain& index_chain = m_chainstate->m_chain;
101 
102  if (locator.IsNull()) {
103  SetBestBlockIndex(nullptr);
104  } else {
105  // Setting the best block to the locator's top block. If it is not part of the
106  // best chain, we will rewind to the fork point during index sync
107  const CBlockIndex* locator_index{m_chainstate->m_blockman.LookupBlockIndex(locator.vHave.at(0))};
108  if (!locator_index) {
109  return InitError(Untranslated(strprintf("%s: best block of the index not found. Please rebuild the index.", GetName())));
110  }
111  SetBestBlockIndex(locator_index);
112  }
113 
114  // Child init
115  const CBlockIndex* start_block = m_best_block_index.load();
116  if (!CustomInit(start_block ? std::make_optional(interfaces::BlockRef{start_block->GetBlockHash(), start_block->nHeight}) : std::nullopt)) {
117  return false;
118  }
119 
120  // Note: this will latch to true immediately if the user starts up with an empty
121  // datadir and an index enabled. If this is the case, indexation will happen solely
122  // via `BlockConnected` signals until, possibly, the next restart.
123  m_synced = start_block == index_chain.Tip();
124  m_init = true;
125  return true;
126 }
127 
129 {
131 
132  if (!pindex_prev) {
133  return chain.Genesis();
134  }
135 
136  const CBlockIndex* pindex = chain.Next(pindex_prev);
137  if (pindex) {
138  return pindex;
139  }
140 
141  return chain.Next(chain.FindFork(pindex_prev));
142 }
143 
145 {
146  const CBlockIndex* pindex = m_best_block_index.load();
147  if (!m_synced) {
148  std::chrono::steady_clock::time_point last_log_time{0s};
149  std::chrono::steady_clock::time_point last_locator_write_time{0s};
150  while (true) {
151  if (m_interrupt) {
152  LogPrintf("%s: m_interrupt set; exiting ThreadSync\n", GetName());
153 
154  SetBestBlockIndex(pindex);
155  // No need to handle errors in Commit. If it fails, the error will be already be
156  // logged. The best way to recover is to continue, as index cannot be corrupted by
157  // a missed commit to disk for an advanced index state.
158  Commit();
159  return;
160  }
161 
162  const CBlockIndex* pindex_next = WITH_LOCK(cs_main, return NextSyncBlock(pindex, m_chainstate->m_chain));
163  // If pindex_next is null, it means pindex is the chain tip, so
164  // commit data indexed so far.
165  if (!pindex_next) {
166  SetBestBlockIndex(pindex);
167  // No need to handle errors in Commit. See rationale above.
168  Commit();
169 
170  // If pindex is still the chain tip after committing, exit the
171  // sync loop. It is important for cs_main to be locked while
172  // setting m_synced = true, otherwise a new block could be
173  // attached while m_synced is still false, and it would not be
174  // indexed.
175  LOCK(::cs_main);
176  pindex_next = NextSyncBlock(pindex, m_chainstate->m_chain);
177  if (!pindex_next) {
178  m_synced = true;
179  break;
180  }
181  }
182  if (pindex_next->pprev != pindex && !Rewind(pindex, pindex_next->pprev)) {
183  FatalErrorf("%s: Failed to rewind index %s to a previous chain tip", __func__, GetName());
184  return;
185  }
186  pindex = pindex_next;
187 
188 
189  CBlock block;
190  interfaces::BlockInfo block_info = kernel::MakeBlockInfo(pindex);
191  if (!m_chainstate->m_blockman.ReadBlock(block, *pindex)) {
192  FatalErrorf("%s: Failed to read block %s from disk",
193  __func__, pindex->GetBlockHash().ToString());
194  return;
195  } else {
196  block_info.data = &block;
197  }
198  if (!CustomAppend(block_info)) {
199  FatalErrorf("%s: Failed to write block %s to index database",
200  __func__, pindex->GetBlockHash().ToString());
201  return;
202  }
203 
204  auto current_time{std::chrono::steady_clock::now()};
205  if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
206  LogPrintf("Syncing %s with block chain from height %d\n",
207  GetName(), pindex->nHeight);
208  last_log_time = current_time;
209  }
210 
211  if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
212  SetBestBlockIndex(pindex);
213  last_locator_write_time = current_time;
214  // No need to handle errors in Commit. See rationale above.
215  Commit();
216  }
217  }
218  }
219 
220  if (pindex) {
221  LogPrintf("%s is enabled at height %d\n", GetName(), pindex->nHeight);
222  } else {
223  LogPrintf("%s is enabled\n", GetName());
224  }
225 }
226 
228 {
229  // Don't commit anything if we haven't indexed any block yet
230  // (this could happen if init is interrupted).
231  bool ok = m_best_block_index != nullptr;
232  if (ok) {
233  CDBBatch batch(GetDB());
234  ok = CustomCommit(batch);
235  if (ok) {
236  GetDB().WriteBestBlock(batch, GetLocator(*m_chain, m_best_block_index.load()->GetBlockHash()));
237  ok = GetDB().WriteBatch(batch);
238  }
239  }
240  if (!ok) {
241  LogError("%s: Failed to commit latest %s state\n", __func__, GetName());
242  return false;
243  }
244  return true;
245 }
246 
247 bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip)
248 {
249  assert(current_tip == m_best_block_index);
250  assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip);
251 
252  if (!CustomRewind({current_tip->GetBlockHash(), current_tip->nHeight}, {new_tip->GetBlockHash(), new_tip->nHeight})) {
253  return false;
254  }
255 
256  // Don't commit here - the committed index state must never be ahead of the
257  // flushed chainstate, otherwise unclean restarts would lead to index corruption.
258  // Pruning has a minimum of 288 blocks-to-keep and getting the index
259  // out of sync may be possible but a users fault.
260  // In case we reorg beyond the pruned depth, ReadBlock would
261  // throw and lead to a graceful shutdown
262  SetBestBlockIndex(new_tip);
263  return true;
264 }
265 
266 void BaseIndex::BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex)
267 {
268  // Ignore events from the assumed-valid chain; we will process its blocks
269  // (sequentially) after it is fully verified by the background chainstate. This
270  // is to avoid any out-of-order indexing.
271  //
272  // TODO at some point we could parameterize whether a particular index can be
273  // built out of order, but for now just do the conservative simple thing.
274  if (role == ChainstateRole::ASSUMEDVALID) {
275  return;
276  }
277 
278  // Ignore BlockConnected signals until we have fully indexed the chain.
279  if (!m_synced) {
280  return;
281  }
282 
283  const CBlockIndex* best_block_index = m_best_block_index.load();
284  if (!best_block_index) {
285  if (pindex->nHeight != 0) {
286  FatalErrorf("%s: First block connected is not the genesis block (height=%d)",
287  __func__, pindex->nHeight);
288  return;
289  }
290  } else {
291  // Ensure block connects to an ancestor of the current best block. This should be the case
292  // most of the time, but may not be immediately after the sync thread catches up and sets
293  // m_synced. Consider the case where there is a reorg and the blocks on the stale branch are
294  // in the ValidationInterface queue backlog even after the sync thread has caught up to the
295  // new chain tip. In this unlikely event, log a warning and let the queue clear.
296  if (best_block_index->GetAncestor(pindex->nHeight - 1) != pindex->pprev) {
297  LogPrintf("%s: WARNING: Block %s does not connect to an ancestor of "
298  "known best chain (tip=%s); not updating index\n",
299  __func__, pindex->GetBlockHash().ToString(),
300  best_block_index->GetBlockHash().ToString());
301  return;
302  }
303  if (best_block_index != pindex->pprev && !Rewind(best_block_index, pindex->pprev)) {
304  FatalErrorf("%s: Failed to rewind index %s to a previous chain tip",
305  __func__, GetName());
306  return;
307  }
308  }
309  interfaces::BlockInfo block_info = kernel::MakeBlockInfo(pindex, block.get());
310  if (CustomAppend(block_info)) {
311  // Setting the best block index is intentionally the last step of this
312  // function, so BlockUntilSyncedToCurrentChain callers waiting for the
313  // best block index to be updated can rely on the block being fully
314  // processed, and the index object being safe to delete.
315  SetBestBlockIndex(pindex);
316  } else {
317  FatalErrorf("%s: Failed to write block %s to index",
318  __func__, pindex->GetBlockHash().ToString());
319  return;
320  }
321 }
322 
324 {
325  // Ignore events from the assumed-valid chain; we will process its blocks
326  // (sequentially) after it is fully verified by the background chainstate.
327  if (role == ChainstateRole::ASSUMEDVALID) {
328  return;
329  }
330 
331  if (!m_synced) {
332  return;
333  }
334 
335  const uint256& locator_tip_hash = locator.vHave.front();
336  const CBlockIndex* locator_tip_index;
337  {
338  LOCK(cs_main);
339  locator_tip_index = m_chainstate->m_blockman.LookupBlockIndex(locator_tip_hash);
340  }
341 
342  if (!locator_tip_index) {
343  FatalErrorf("%s: First block (hash=%s) in locator was not found",
344  __func__, locator_tip_hash.ToString());
345  return;
346  }
347 
348  // This checks that ChainStateFlushed callbacks are received after BlockConnected. The check may fail
349  // immediately after the sync thread catches up and sets m_synced. Consider the case where
350  // there is a reorg and the blocks on the stale branch are in the ValidationInterface queue
351  // backlog even after the sync thread has caught up to the new chain tip. In this unlikely
352  // event, log a warning and let the queue clear.
353  const CBlockIndex* best_block_index = m_best_block_index.load();
354  if (best_block_index->GetAncestor(locator_tip_index->nHeight) != locator_tip_index) {
355  LogPrintf("%s: WARNING: Locator contains block (hash=%s) not on known best "
356  "chain (tip=%s); not writing index locator\n",
357  __func__, locator_tip_hash.ToString(),
358  best_block_index->GetBlockHash().ToString());
359  return;
360  }
361 
362  // No need to handle errors in Commit. If it fails, the error will be already be logged. The
363  // best way to recover is to continue, as index cannot be corrupted by a missed commit to disk
364  // for an advanced index state.
365  Commit();
366 }
367 
368 bool BaseIndex::BlockUntilSyncedToCurrentChain() const
369 {
371 
372  if (!m_synced) {
373  return false;
374  }
375 
376  {
377  // Skip the queue-draining stuff if we know we're caught up with
378  // m_chain.Tip().
379  LOCK(cs_main);
380  const CBlockIndex* chain_tip = m_chainstate->m_chain.Tip();
381  const CBlockIndex* best_block_index = m_best_block_index.load();
382  if (best_block_index->GetAncestor(chain_tip->nHeight) == chain_tip) {
383  return true;
384  }
385  }
386 
387  LogPrintf("%s: %s is catching up on block notifications\n", __func__, GetName());
388  m_chain->context()->validation_signals->SyncWithValidationInterfaceQueue();
389  return true;
390 }
391 
393 {
394  m_interrupt();
395 }
396 
398 {
399  if (!m_init) throw std::logic_error("Error: Cannot start a non-initialized index");
400 
401  m_thread_sync = std::thread(&util::TraceThread, GetName(), [this] { Sync(); });
402  return true;
403 }
404 
406 {
407  if (m_chain->context()->validation_signals) {
408  m_chain->context()->validation_signals->UnregisterValidationInterface(this);
409  }
410 
411  if (m_thread_sync.joinable()) {
412  m_thread_sync.join();
413  }
414 }
415 
417 {
418  IndexSummary summary{};
419  summary.name = GetName();
420  summary.synced = m_synced;
421  if (const auto& pindex = m_best_block_index.load()) {
422  summary.best_block_height = pindex->nHeight;
423  summary.best_block_hash = pindex->GetBlockHash();
424  } else {
425  summary.best_block_height = 0;
426  summary.best_block_hash = m_chain->getBlockHash(0);
427  }
428  return summary;
429 }
430 
432 {
434 
435  if (AllowPrune() && block) {
436  node::PruneLockInfo prune_lock;
437  prune_lock.height_first = block->nHeight;
438  WITH_LOCK(::cs_main, m_chainstate->m_blockman.UpdatePruneLock(GetName(), prune_lock));
439  }
440 
441  // Intentionally set m_best_block_index as the last step in this function,
442  // after updating prune locks above, and after making any other references
443  // to *this, so the BlockUntilSyncedToCurrentChain function (which checks
444  // m_best_block_index as an optimization) can be used to wait for the last
445  // BlockConnected notification and safely assume that prune locks are
446  // updated and that the index object is safe to delete.
447  m_best_block_index = block;
448 }
Helper for findBlock to selectively return pieces of block data.
Definition: chain.h:47
fs::path path
Location in the filesystem where leveldb data will be stored.
Definition: dbwrapper.h:36
bool Commit()
Write the current index state (eg.
Definition: base.cpp:227
AssertLockHeld(pool.cs)
bool IsPruneMode() const
Whether running in -prune mode.
Definition: blockstorage.h:349
bool Init()
Initializes the sync state and registers the instance to the validation interface so that it stays in...
Definition: base.cpp:79
CThreadInterrupt m_interrupt
Definition: base.h:81
assert(!tx.IsCoinBase())
BaseIndex(std::unique_ptr< interfaces::Chain > chain, std::string name)
Definition: base.cpp:70
Describes a place in the block chain to another node such that if the other node doesn&#39;t have the sam...
Definition: block.h:123
std::atomic< bool > m_synced
Whether the index is in sync with the main chain.
Definition: base.h:75
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:147
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:73
virtual bool CustomAppend(const interfaces::BlockInfo &block)
Write update index entries for a newly connected block.
Definition: base.h:114
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances...
Definition: validation.h:535
Definition: block.h:68
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172
void SetBestBlockIndex(const CBlockIndex *block)
Update the internal best block index as well as the prune lock.
Definition: base.cpp:431
An in-memory indexed chain of blocks.
Definition: chain.h:416
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:82
Hash/height pair to help track and identify blocks.
Definition: types.h:13
Interrupt(node)
bool ReadBlock(CBlock &block, const FlatFilePos &pos) const
Functions for disk access for blocks.
bool IsNull() const
Definition: block.h:152
bool Rewind(const CBlockIndex *current_tip, const CBlockIndex *new_tip)
Loop over disconnected blocks and call CustomRewind.
Definition: base.cpp:247
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:585
void format(std::ostream &out, FormatStringCheck< sizeof...(Args)> fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1079
User-controlled performance and debug options.
Definition: dbwrapper.h:28
void Stop()
Stops the instance from staying in sync with blockchain updates.
Definition: base.cpp:405
std::thread m_thread_sync
Definition: base.h:80
uint256 GetBlockHash() const
Definition: chain.h:243
Block data sent with blockConnected, blockDisconnected notifications.
Definition: chain.h:78
virtual ~BaseIndex()
Destructor interrupts sync thread if running and blocks until it exits.
Definition: base.cpp:73
void SetNull()
Definition: block.h:147
const CBlock * data
Definition: chain.h:84
void WriteBestBlock(CDBBatch &batch, const CBlockLocator &locator)
Write block locator of the chain that the index is in sync with.
Definition: base.cpp:65
void ChainStateFlushed(ChainstateRole role, const CBlockLocator &locator) override
Notifies listeners of the new active block chain on-disk.
Definition: base.cpp:323
ArgsManager & args
Definition: bitcoind.cpp:277
constexpr auto SYNC_LOG_INTERVAL
Definition: base.cpp:27
ChainstateRole
This enum describes the various roles a specific Chainstate instance can take.
Definition: chain.h:25
const std::string & GetName() const LIFETIMEBOUND
Get the name of the index for display in logs.
Definition: base.h:135
CBlockLocator GetLocator(interfaces::Chain &chain, const uint256 &block_hash)
Definition: base.cpp:37
#define LOCK(cs)
Definition: sync.h:257
const char * name
Definition: rest.cpp:49
bool InitError(const bilingual_str &str)
Show error message.
std::atomic< bool > m_init
Whether the index has been initialized or not.
Definition: base.h:67
void Sync()
Sync the index with the block index starting from the current best block.
Definition: base.cpp:144
virtual bool findBlock(const uint256 &hash, const FoundBlock &block={})=0
Return whether node has the block and optionally return block metadata or contents.
constexpr uint8_t DB_BEST_BLOCK
Definition: base.cpp:25
void Write(const K &key, const V &value)
Definition: dbwrapper.h:100
std::string ToString() const
Definition: uint256.cpp:47
void ReadDatabaseArgs(const ArgsManager &args, DBOptions &options)
constexpr auto SYNC_LOCATOR_WRITE_INTERVAL
Definition: base.cpp:28
std::vector< uint256 > vHave
Definition: block.h:134
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
A wrapper for a compile-time partially validated format string.
Definition: string.h:92
virtual bool CustomInit(const std::optional< interfaces::BlockRef > &block)
Initialize internal state from the database and block index.
Definition: base.h:111
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:301
ArgsManager gArgs
Definition: args.cpp:42
bool StartBackgroundSync()
Starts the initial sync process on a background thread.
Definition: base.cpp:397
256-bit opaque blob.
Definition: uint256.h:201
virtual bool CustomCommit(CDBBatch &batch)
Virtual method called internally by Commit that can be overridden to atomically commit more index sta...
Definition: base.h:118
std::string name
Definition: base.h:26
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
static const CBlockIndex * NextSyncBlock(const CBlockIndex *pindex_prev, CChain &chain) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: base.cpp:128
void AbortNode(const std::function< bool()> &shutdown_request, std::atomic< int > &exit_status, const bilingual_str &message, node::Warnings *warnings)
Definition: abort.cpp:18
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:128
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:140
#define LogError(...)
Definition: logging.h:358
Chainstate * m_chainstate
Definition: base.h:103
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:433
Application-specific storage settings.
Definition: dbwrapper.h:34
#define AssertLockNotHeld(cs)
Definition: sync.h:147
virtual bool CustomRewind(const interfaces::BlockRef &current_tip, const interfaces::BlockRef &new_tip)
Rewind index to an earlier chain tip during a chain reorg.
Definition: base.h:122
bool WriteBatch(CDBBatch &batch, bool fSync=false)
Definition: dbwrapper.cpp:292
void BlockConnected(ChainstateRole role, const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex) override
Notifies listeners of a block being connected.
Definition: base.cpp:266
interfaces::BlockInfo MakeBlockInfo(const CBlockIndex *index, const CBlock *data)
Return data from block index.
Definition: chain.cpp:14
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:153
DB(const fs::path &path, size_t n_cache_size, bool f_memory=false, bool f_wipe=false, bool f_obfuscate=false)
Definition: base.cpp:46
bool ReadBestBlock(CBlockLocator &locator) const
Read block locator of the chain that the index is in sync with.
Definition: base.cpp:56
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
Definition: chain.cpp:120
#define LogPrintf(...)
Definition: logging.h:361
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:32
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: cs_main.cpp:8
virtual DB & GetDB() const =0
std::atomic< const CBlockIndex * > m_best_block_index
The last block in the chain that the index is in sync with.
Definition: base.h:78
void FatalErrorf(util::ConstevalFormatString< sizeof...(Args)> fmt, const Args &... args)
Definition: base.cpp:31
virtual bool AllowPrune() const =0
std::unique_ptr< interfaces::Chain > m_chain
Definition: base.h:102
void TraceThread(std::string_view thread_name, std::function< void()> thread_func)
A wrapper for do-something-once thread functions.
Definition: thread.cpp:16
IndexSummary GetSummary() const
Get a summary of the index and its state.
Definition: base.cpp:416