|
24 | 24 | #include <numeric> |
25 | 25 | #include <set> |
26 | 26 | #include <type_traits> |
27 | | -#include <unordered_map> |
28 | 27 | #include <utility> |
29 | 28 | #include <bitcoin/system/chain/context.hpp> |
30 | 29 | #include <bitcoin/system/chain/enums/flags.hpp> |
@@ -384,7 +383,7 @@ bool block::is_forward_reference() const NOEXCEPT |
384 | 383 | return false; |
385 | 384 |
|
386 | 385 | const auto sum_txs = sub1(txs_->size()); |
387 | | - unordered_set_of_constant_referenced_hashes hashes{ sum_txs }; |
| 386 | + unordered_set_of_hash_cref hashes{ sum_txs }; |
388 | 387 | const auto spent = [&hashes](const input::cptr& input) NOEXCEPT |
389 | 388 | { |
390 | 389 | return hashes.find(std::ref(input->point().hash())) != hashes.end(); |
@@ -417,7 +416,7 @@ bool block::is_internal_double_spend() const NOEXCEPT |
417 | 416 |
|
418 | 417 | const auto tx1 = std::next(txs_->begin()); |
419 | 418 | const auto spends_count = std::accumulate(tx1, txs_->end(), zero, sum_ins); |
420 | | - unordered_set_of_constant_referenced_points points{ spends_count }; |
| 419 | + unordered_set_of_point_cref points{ spends_count }; |
421 | 420 | const auto spent = [&points](const input::cptr& in) NOEXCEPT |
422 | 421 | { |
423 | 422 | return !points.emplace(in->point()).second; |
@@ -478,7 +477,7 @@ bool block::is_hash_limit_exceeded() const NOEXCEPT |
478 | 477 | return false; |
479 | 478 |
|
480 | 479 | // A set is used to collapse duplicates. |
481 | | - unordered_set_of_constant_referenced_hashes hashes{}; |
| 480 | + unordered_set_of_hash_cref hashes{}; |
482 | 481 |
|
483 | 482 | // Just the coinbase tx hash, skip its null input hashes. |
484 | 483 | hashes.emplace(txs_->front()->get_hash(false)); |
@@ -548,7 +547,7 @@ bool block::is_malleated32(size_t width) const NOEXCEPT |
548 | 547 | auto mally = txs_->rbegin(); |
549 | 548 | auto legit = std::next(mally, width); |
550 | 549 | while (!is_zero(width--)) |
551 | | - if ((*mally++)->hash(false) != (*legit++)->hash(false)) |
| 550 | + if ((*mally++)->get_hash(false) != (*legit++)->get_hash(false)) |
552 | 551 | return false; |
553 | 552 |
|
554 | 553 | return true; |
@@ -705,22 +704,24 @@ bool block::is_unspent_coinbase_collision() const NOEXCEPT |
705 | 704 | // Search is not ordered, forward references are caught by block.check. |
706 | 705 | bool block::populate() const NOEXCEPT |
707 | 706 | { |
708 | | - std::unordered_map<point, output::cptr> points{}; |
709 | 707 | uint32_t index{}; |
| 708 | + unordered_map_of_cref_point_to_output_cptr_cref points{}; |
710 | 709 |
|
711 | 710 | // Populate outputs hash table. |
712 | 711 | for (auto tx = txs_->begin(); tx != txs_->end(); ++tx, index = 0) |
713 | 712 | for (const auto& out: *(*tx)->outputs_ptr()) |
714 | | - points.emplace(std::pair{ point{ (*tx)->hash(false), index++ }, |
715 | | - out }); |
| 713 | + points.emplace(cref_point{ (*tx)->get_hash(false), index++ }, out); |
716 | 714 |
|
717 | 715 | // Populate input prevouts from hash table and obtain locked state. |
718 | | - bool locked{}; |
| 716 | + auto locked = false; |
719 | 717 | for (auto tx = txs_->begin(); tx != txs_->end(); ++tx) |
720 | 718 | { |
721 | 719 | for (const auto& in: *(*tx)->inputs_ptr()) |
722 | 720 | { |
723 | | - const auto point = points.find(in->point()); |
| 721 | + // Map chain::point to cref_point for search, should optimize away. |
| 722 | + const auto point = points.find({ in->point().hash(), |
| 723 | + in->point().index() }); |
| 724 | + |
724 | 725 | if (point != points.end()) |
725 | 726 | { |
726 | 727 | in->prevout = point->second; |
|
0 commit comments