Skip to content

Commit 98b9148

Browse files
committed
Simplify non-critical block setters by generating height.
1 parent f9596ca commit 98b9148

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

include/bitcoin/database/impl/query/archive_write.ipp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ bool CLASS::set(const transaction& tx) NOEXCEPT
6565
}
6666

6767
TEMPLATE
68-
bool CLASS::set(const block& block, bool strong, bool bypass,
69-
size_t height) NOEXCEPT
68+
bool CLASS::set(const block& block, bool strong, bool bypass) NOEXCEPT
7069
{
7170
// This sets only the txs of a block with header/context already archived.
72-
return !set_code(block, strong, bypass, height);
71+
return !set_code(block, strong, bypass);
7372
}
7473

7574
// set transaction
@@ -350,27 +349,30 @@ code CLASS::set_code(header_link& out_fk, const block& block,
350349
// releases all memory for parts of itself, due to the custom allocator.
351350

352351
TEMPLATE
353-
code CLASS::set_code(const block& block, bool strong, bool bypass,
354-
size_t height) NOEXCEPT
352+
code CLASS::set_code(const block& block, bool strong, bool bypass) NOEXCEPT
355353
{
356354
header_link unused{};
357-
return set_code(unused, block, strong, bypass, height);
355+
return set_code(unused, block, strong, bypass);
358356
}
359357

360358
TEMPLATE
361359
code CLASS::set_code(header_link& out_fk, const block& block, bool strong,
362-
bool bypass, size_t height) NOEXCEPT
360+
bool bypass) NOEXCEPT
363361
{
364362
out_fk = to_header(block.get_hash());
365363
if (out_fk.is_terminal())
366364
return error::txs_header;
367365

366+
size_t height{};
367+
if (!get_height(height, out_fk))
368+
return error::txs_height;
369+
368370
return set_code(block, out_fk, strong, bypass, height);
369371
}
370372

371373
TEMPLATE
372374
code CLASS::set_code(const block& block, const header_link& key,
373-
bool strong, bool bypass, size_t /* height */) NOEXCEPT
375+
bool strong, bool bypass, size_t height) NOEXCEPT
374376
{
375377
using namespace system;
376378
if (key.is_terminal())

include/bitcoin/database/query.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ class query
413413
bool set(const block& block, const context& ctx,
414414
bool milestone, bool strong) NOEXCEPT;
415415
bool set(const transaction& tx) NOEXCEPT;
416-
bool set(const block& block, bool strong, bool bypass,
417-
size_t height) NOEXCEPT;
416+
bool set(const block& block, bool strong, bool bypass) NOEXCEPT;
418417

419418
/// Set transaction.
420419
code set_code(const transaction& tx) NOEXCEPT;
@@ -440,10 +439,9 @@ class query
440439
const chain_context& ctx, bool milestone, bool strong) NOEXCEPT;
441440

442441
/// Set block.txs (headers-first).
443-
code set_code(const block& block, bool strong, bool bypass,
444-
size_t height) NOEXCEPT;
442+
code set_code(const block& block, bool strong, bool bypass) NOEXCEPT;
445443
code set_code(header_link& out_fk, const block& block, bool strong,
446-
bool bypass, size_t height) NOEXCEPT;
444+
bool bypass) NOEXCEPT;
447445
code set_code(const block& block, const header_link& key, bool strong,
448446
bool bypass, size_t height) NOEXCEPT;
449447

test/query/archive_write.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ BOOST_AUTO_TEST_CASE(query_archive_write__set_block_txs__get_block__expected)
705705
BOOST_REQUIRE(!query.is_block(test::genesis.hash()));
706706
BOOST_REQUIRE(query.set(test::genesis.header(), test::context, milestone));
707707
BOOST_REQUIRE(!query.is_associated(0));
708-
BOOST_REQUIRE(query.set(test::genesis, false, false, zero));
708+
BOOST_REQUIRE(query.set(test::genesis, false, false));
709709
BOOST_REQUIRE(query.is_block(test::genesis.hash()));
710710
BOOST_REQUIRE(query.is_associated(0));
711711

test/query/initialize.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,17 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_unassociated_above__gapped_candidate_
415415
BOOST_REQUIRE_EQUAL(unassociated3.size(), 0u);
416416

417417
// There are two unassociated blocks above block 1 (new fork point).
418-
BOOST_REQUIRE(query.set(test::block1, false, false, zero));
418+
BOOST_REQUIRE(query.set(test::block1, false, false));
419419
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1.hash()), false));
420420
BOOST_REQUIRE_EQUAL(query.get_all_unassociated().size(), 2u);
421421

422422
// There is one unassociated block above block 2 (new fork point).
423-
BOOST_REQUIRE(query.set(test::block2, false, false, zero));
423+
BOOST_REQUIRE(query.set(test::block2, false, false));
424424
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2.hash()), false));
425425
BOOST_REQUIRE_EQUAL(query.get_all_unassociated().size(), 1u);
426426

427427
// There are no unassociated blocks above block 3 (new fork point).
428-
BOOST_REQUIRE(query.set(test::block3, false, false, zero));
428+
BOOST_REQUIRE(query.set(test::block3, false, false));
429429
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3.hash()), false));
430430
BOOST_REQUIRE_EQUAL(query.get_all_unassociated().size(), 0u);
431431
}
@@ -482,15 +482,15 @@ BOOST_AUTO_TEST_CASE(query_initialize__get_unassociated_count_above__gapped_cand
482482
BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(3, 1), 0u);
483483

484484
// There is one unassociated block at block 2.
485-
BOOST_REQUIRE(query.set(test::block3, false, false, zero)); // associated
485+
BOOST_REQUIRE(query.set(test::block3, false, false)); // associated
486486
BOOST_REQUIRE_EQUAL(query.get_unassociated_count(), 1u);
487487
BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(0), 1u);
488488
BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(1), 1u);
489489
BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(2), 0u);
490490
BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(3), 0u);
491491

492492
// There are no unassociated blocks.
493-
BOOST_REQUIRE(query.set(test::block2, false, false, zero)); // associated
493+
BOOST_REQUIRE(query.set(test::block2, false, false)); // associated
494494
BOOST_REQUIRE_EQUAL(query.get_unassociated_count(), 0u);
495495
BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(0), 0u);
496496
BOOST_REQUIRE_EQUAL(query.get_unassociated_count_above(1), 0u);

0 commit comments

Comments
 (0)