aboutsummaryrefslogtreecommitdiff
path: root/src/chain.h
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@pm.me>2021-07-21 13:31:14 -0400
committerJames O'Beirne <james.obeirne@pm.me>2021-09-15 15:46:44 -0400
commit42b2520db93fd9feb3df4101654391fa7d3e2140 (patch)
tree4d5be14ead20a661b656b098b91393edd609522a /src/chain.h
parentb217020df78bc981d221fe04497c831120ef969f (diff)
downloadbitcoin-42b2520db93fd9feb3df4101654391fa7d3e2140.tar.xz
chain: add BLOCK_ASSUMED_VALID for use with assumeutxo
Instead of (ab)using the existing BLOCK_VALID_* flags to mark CBlockIndex entries which we haven't yet fully validated (but assume validity for use with UTXO snapshot loading), introduce a status flag that specifically marks an assumed-valid state. This state is then removed in RaiseValidity() when the block has actually been validated. This distinction will allow us to make the necessary changes to various parts of the system to facilitate assumeutxo/background chainstate validation but without leaking details like snapshot height, as we had done previously. Changes that actually make use of this flag follow in future commits.
Diffstat (limited to 'src/chain.h')
-rw-r--r--src/chain.h24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/chain.h b/src/chain.h
index 84a3a4e1e7..365a7f79b6 100644
--- a/src/chain.h
+++ b/src/chain.h
@@ -126,7 +126,15 @@ enum BlockStatus: uint32_t {
BLOCK_FAILED_CHILD = 64, //!< descends from failed block
BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD,
- BLOCK_OPT_WITNESS = 128, //!< block data in blk*.data was received with a witness-enforcing client
+ BLOCK_OPT_WITNESS = 128, //!< block data in blk*.dat was received with a witness-enforcing client
+
+ /**
+ * If set, this indicates that the block index entry is assumed-valid.
+ * Certain diagnostics will be skipped in e.g. CheckBlockIndex().
+ * It almost certainly means that the block's full validation is pending
+ * on a background chainstate. See `doc/assumeutxo.md`.
+ */
+ BLOCK_ASSUMED_VALID = 256,
};
/** The block chain is a tree shaped structure starting with the
@@ -300,14 +308,24 @@ public:
return ((nStatus & BLOCK_VALID_MASK) >= nUpTo);
}
+ //! @returns true if the block is assumed-valid; this means it is queued to be
+ //! validated by a background chainstate.
+ bool IsAssumedValid() const { return nStatus & BLOCK_ASSUMED_VALID; }
+
//! Raise the validity level of this block index entry.
//! Returns true if the validity was changed.
bool RaiseValidity(enum BlockStatus nUpTo)
{
assert(!(nUpTo & ~BLOCK_VALID_MASK)); // Only validity flags allowed.
- if (nStatus & BLOCK_FAILED_MASK)
- return false;
+ if (nStatus & BLOCK_FAILED_MASK) return false;
+
if ((nStatus & BLOCK_VALID_MASK) < nUpTo) {
+ // If this block had been marked assumed-valid and we're raising
+ // its validity to a certain point, there is no longer an assumption.
+ if (nStatus & BLOCK_ASSUMED_VALID && nUpTo >= BLOCK_VALID_SCRIPTS) {
+ nStatus &= ~BLOCK_ASSUMED_VALID;
+ }
+
nStatus = (nStatus & ~BLOCK_VALID_MASK) | nUpTo;
return true;
}