Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
blockstatus.h
Go to the documentation of this file.
1// Copyright (c) 2018-2019 The Bitcoin 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#ifndef BITCOIN_BLOCKSTATUS_H
6#define BITCOIN_BLOCKSTATUS_H
7
8#include <blockvalidity.h>
9#include <serialize.h>
10
11#include <cstdint>
12
14private:
16
17 explicit constexpr BlockStatus(uint32_t nStatusIn) : status(nStatusIn) {}
18
19 static const uint32_t VALIDITY_MASK = 0x07;
20
21 // Full block available in blk*.dat
22 static const uint32_t HAS_DATA_FLAG = 0x08;
23 // Undo data available in rev*.dat
24 static const uint32_t HAS_UNDO_FLAG = 0x10;
25
26 // The block is invalid.
27 static const uint32_t FAILED_FLAG = 0x20;
28 // The block has an invalid parent.
29 static const uint32_t FAILED_PARENT_FLAG = 0x40;
30
31 // Mask used to check if the block failed.
33
34 // The block is being parked for some reason. It will be reconsidered if its
35 // chains grows.
36 static const uint32_t PARKED_FLAG = 0x80;
37 // One of the block's parent is parked.
38 static const uint32_t PARKED_PARENT_FLAG = 0x100;
39
40 // Mask used to check for parked blocks.
42
49 static const uint32_t ASSUMED_VALID_FLAG = 0x200;
50
51public:
52 explicit constexpr BlockStatus() : status(0) {}
53
57
61
62 bool hasData() const { return status & HAS_DATA_FLAG; }
63 BlockStatus withData(bool hasData = true) const {
64 return BlockStatus((status & ~HAS_DATA_FLAG) |
65 (hasData ? HAS_DATA_FLAG : 0));
66 }
67
68 bool hasUndo() const { return status & HAS_UNDO_FLAG; }
69 BlockStatus withUndo(bool hasUndo = true) const {
70 return BlockStatus((status & ~HAS_UNDO_FLAG) |
71 (hasUndo ? HAS_UNDO_FLAG : 0));
72 }
73
74 bool hasFailed() const { return status & FAILED_FLAG; }
75 BlockStatus withFailed(bool hasFailed = true) const {
76 return BlockStatus((status & ~FAILED_FLAG) |
77 (hasFailed ? FAILED_FLAG : 0));
78 }
79
80 bool hasFailedParent() const { return status & FAILED_PARENT_FLAG; }
85
86 bool isParked() const { return status & PARKED_FLAG; }
87 BlockStatus withParked(bool parked = true) const {
88 return BlockStatus((status & ~PARKED_FLAG) |
89 (parked ? PARKED_FLAG : 0));
90 }
91
92 bool hasParkedParent() const { return status & PARKED_PARENT_FLAG; }
97
103 if (isInvalid()) {
104 return false;
105 }
106
107 return getValidity() >= nUpTo;
108 }
109
110 bool isAssumedValid() const { return status & ASSUMED_VALID_FLAG; }
118
119 bool isInvalid() const { return status & INVALID_MASK; }
123
124 bool isOnParkedChain() const { return status & PARKED_MASK; }
128
130
131 friend constexpr bool operator==(const BlockStatus a, const BlockStatus b) {
132 return a.status == b.status;
133 }
134
135 friend constexpr bool operator!=(const BlockStatus a, const BlockStatus b) {
136 return !(a == b);
137 }
138};
139
140#endif // BITCOIN_BLOCKSTATUS_H
BlockValidity
@ TRANSACTIONS
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid,...
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
#define VARINT(obj)
Definition serialize.h:579
#define READWRITE(...)
Definition serialize.h:166
bool isOnParkedChain() const
bool isValid(enum BlockValidity nUpTo=BlockValidity::TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
static const uint32_t PARKED_FLAG
Definition blockstatus.h:36
bool hasParkedParent() const
Definition blockstatus.h:92
bool hasFailedParent() const
Definition blockstatus.h:80
BlockStatus withFailedParent(bool hasFailedParent=true) const
Definition blockstatus.h:81
BlockStatus withClearedFailureFlags() const
bool isAssumedValid() const
friend constexpr bool operator==(const BlockStatus a, const BlockStatus b)
static const uint32_t PARKED_MASK
Definition blockstatus.h:41
constexpr BlockStatus()
Definition blockstatus.h:52
BlockStatus withUndo(bool hasUndo=true) const
Definition blockstatus.h:69
static const uint32_t ASSUMED_VALID_FLAG
If set, this indicates that the block index entry is assumed-valid.
Definition blockstatus.h:49
bool isInvalid() const
BlockStatus withClearedAssumedValidFlags() const
static const uint32_t HAS_UNDO_FLAG
Definition blockstatus.h:24
static const uint32_t INVALID_MASK
Definition blockstatus.h:32
static const uint32_t FAILED_PARENT_FLAG
Definition blockstatus.h:29
static const uint32_t FAILED_FLAG
Definition blockstatus.h:27
BlockStatus withData(bool hasData=true) const
Definition blockstatus.h:63
bool hasUndo() const
Definition blockstatus.h:68
uint32_t status
Definition blockstatus.h:15
BlockStatus withParked(bool parked=true) const
Definition blockstatus.h:87
bool isParked() const
Definition blockstatus.h:86
BlockStatus withParkedParent(bool parkedParent=true) const
Definition blockstatus.h:93
SERIALIZE_METHODS(BlockStatus, obj)
static const uint32_t VALIDITY_MASK
Definition blockstatus.h:19
BlockStatus withClearedParkedFlags() const
BlockStatus withAssumedValid(bool assumed_valid=true) const
BlockStatus withFailed(bool hasFailed=true) const
Definition blockstatus.h:75
BlockStatus withValidity(BlockValidity validity) const
Definition blockstatus.h:58
friend constexpr bool operator!=(const BlockStatus a, const BlockStatus b)
constexpr BlockStatus(uint32_t nStatusIn)
Definition blockstatus.h:17
BlockValidity getValidity() const
Definition blockstatus.h:54
static const uint32_t HAS_DATA_FLAG
Definition blockstatus.h:22
static const uint32_t PARKED_PARENT_FLAG
Definition blockstatus.h:38
bool hasData() const
Definition blockstatus.h:62
bool hasFailed() const
Definition blockstatus.h:74