MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BlockChecked

Method BlockChecked

src/test/kernel/test_kernel.cpp:139–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137 std::optional<std::vector<std::byte>> m_expected_valid_block = std::nullopt;
138
139 void BlockChecked(Block block, BlockValidationStateView state) override
140 {
141 if (m_expected_valid_block.has_value()) {
142 auto ser_block{block.ToBytes()};
143 check_equal(m_expected_valid_block.value(), ser_block);
144 }
145
146 auto mode{state.GetValidationMode()};
147 switch (mode) {
148 case ValidationMode::VALID: {
149 std::cout << "Valid block" << std::endl;
150 return;
151 }
152 case ValidationMode::INVALID: {
153 std::cout << "Invalid block: ";
154 auto result{state.GetBlockValidationResult()};
155 switch (result) {
156 case BlockValidationResult::UNSET:
157 std::cout << "initial value. Block has not yet been rejected" << std::endl;
158 break;
159 case BlockValidationResult::HEADER_LOW_WORK:
160 std::cout << "the block header may be on a too-little-work chain" << std::endl;
161 break;
162 case BlockValidationResult::CONSENSUS:
163 std::cout << "invalid by consensus rules (excluding any below reasons)" << std::endl;
164 break;
165 case BlockValidationResult::CACHED_INVALID:
166 std::cout << "this block was cached as being invalid and we didn't store the reason why" << std::endl;
167 break;
168 case BlockValidationResult::INVALID_HEADER:
169 std::cout << "invalid proof of work or time too old" << std::endl;
170 break;
171 case BlockValidationResult::MUTATED:
172 std::cout << "the block's data didn't match the data committed to by the PoW" << std::endl;
173 break;
174 case BlockValidationResult::MISSING_PREV:
175 std::cout << "We don't have the previous block the checked one is built on" << std::endl;
176 break;
177 case BlockValidationResult::INVALID_PREV:
178 std::cout << "A block this one builds on is invalid" << std::endl;
179 break;
180 case BlockValidationResult::TIME_FUTURE:
181 std::cout << "block timestamp was > 2 hours in the future (or our clock is bad)" << std::endl;
182 break;
183 }
184 return;
185 }
186 case ValidationMode::INTERNAL_ERROR: {
187 std::cout << "Internal error" << std::endl;
188 return;
189 }
190 }
191 }
192
193 void BlockConnected(Block block, BlockTreeEntry entry) override
194 {

Callers

nothing calls this directly

Calls 6

check_equalFunction · 0.85
has_valueMethod · 0.45
ToBytesMethod · 0.45
valueMethod · 0.45
GetValidationModeMethod · 0.45

Tested by

no test coverage detected