Skip to content

Commit c3a4d02

Browse files
authored
Merge pull request #903 from evoskuil/master
Allow unknown_state for block reset.
2 parents a020cdd + 496262a commit c3a4d02

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

console/executor_test_writer.cpp

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@
2525
namespace libbitcoin {
2626
namespace node {
2727

28-
////using boost::format;
28+
using boost::format;
2929
using namespace network;
3030
using namespace system;
3131

32+
#if defined(UNDEFINED)
33+
3234
// arbitrary testing (non-const).
3335
void executor::write_test(const hash_digest&)
3436
{
3537
logger("No write test implemented.");
3638
}
3739

38-
#if defined(UNDEFINED)
39-
4040
void executor::write_test(const system::hash_digest&)
4141
{
4242
for (database::header_link link{ 793'008_u32 }; link < 885'000_u32; ++link)
@@ -201,40 +201,25 @@ void executor::write_test(const system::hash_digest&)
201201
logger(format("block" BN_WRITE_ROW) % height % span.count());
202202
}
203203

204-
void executor::write_test(const system::hash_digest&)
205-
{
206-
constexpr auto hash251684 = base16_hash(
207-
"00000000000000720e4c59ad28a8b61f38015808e92465e53111e3463aed80de");
208-
const auto link = query_.to_header(hash251684);
204+
#endif // UNDEFINED
209205

206+
void executor::write_test(const system::hash_digest& hash)
207+
{
208+
const auto id = encode_hash(hash);
209+
const auto link = query_.to_header(hash);
210210
if (link.is_terminal())
211211
{
212-
logger("link.is_terminal()");
213-
return;
212+
logger(format("Block [%1%] not found.") % id);
214213
}
215-
216-
if (query_.confirmed_records() != 251684u)
217-
{
218-
logger("!query_.confirmed_records() != 251684u");
219-
return;
220-
}
221-
222-
if (!query_.push_confirmed(link, true))
214+
else if (query_.set_block_unknown(link))
223215
{
224-
logger("!query_.push_confirmed(link)");
225-
return;
216+
logger(format("Successfully reset block [%1%].") % id);
226217
}
227-
228-
if (query_.confirmed_records() != 251685u)
218+
else
229219
{
230-
logger("!query_.confirmed_records() != 251685u");
231-
return;
220+
logger(format("Failed to reset block [%1%].") % id);
232221
}
233-
234-
logger("Successfully confirmed block 251684.");
235222
}
236223

237-
#endif // UNDEFINED
238-
239224
} // namespace node
240225
} // namespace libbitcoin

src/chasers/chaser_validate.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ void chaser_validate::do_bump(height_t) NOEXCEPT
140140
const auto ec = query.get_block_state(link);
141141

142142
// First block state should be unvalidated, valid, or confirmable. This is
143-
// assured in do_checked by chasing block checks.
143+
// assured in do_checked by chasing block checks. unknown_state is a reset.
144144
const auto ready =
145145
(ec == database::error::unvalidated) ||
146146
(ec == database::error::block_valid) ||
147+
(ec == database::error::unknown_state) ||
147148
(ec == database::error::block_confirmable);
148149

149150
if (ready)
@@ -186,6 +187,7 @@ void chaser_validate::do_bumped(height_t height) NOEXCEPT
186187
else switch (ec.value())
187188
{
188189
case database::error::unvalidated:
190+
case database::error::unknown_state:
189191
{
190192
post_block(link, bypass);
191193
break;

0 commit comments

Comments
 (0)