Skip to content

Commit

Permalink
Merge pull request libbitcoin#1467 from evoskuil/master
Browse files Browse the repository at this point in the history
Performance optimizations, style, comments.
  • Loading branch information
evoskuil authored May 31, 2024
2 parents ab5548f + 9701658 commit 434772a
Show file tree
Hide file tree
Showing 25 changed files with 1,120 additions and 902 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,9 @@ include_bitcoin_system_hash_sha_HEADERS = \

include_bitcoin_system_impl_chaindir = ${includedir}/bitcoin/system/impl/chain
include_bitcoin_system_impl_chain_HEADERS = \
include/bitcoin/system/impl/chain/compact.ipp
include/bitcoin/system/impl/chain/compact.ipp \
include/bitcoin/system/impl/chain/operation.ipp \
include/bitcoin/system/impl/chain/script.ipp

include_bitcoin_system_impl_datadir = ${includedir}/bitcoin/system/impl/data
include_bitcoin_system_impl_data_HEADERS = \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\..\include\bitcoin\system\impl\chain\compact.ipp" />
<None Include="..\..\..\..\include\bitcoin\system\impl\chain\operation.ipp" />
<None Include="..\..\..\..\include\bitcoin\system\impl\chain\script.ipp" />
<None Include="..\..\..\..\include\bitcoin\system\impl\data\array_cast.ipp" />
<None Include="..\..\..\..\include\bitcoin\system\impl\data\byte_cast.ipp" />
<None Include="..\..\..\..\include\bitcoin\system\impl\data\collection.ipp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,12 @@
<None Include="..\..\..\..\include\bitcoin\system\impl\chain\compact.ipp">
<Filter>include\bitcoin\system\impl\chain</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\system\impl\chain\operation.ipp">
<Filter>include\bitcoin\system\impl\chain</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\system\impl\chain\script.ipp">
<Filter>include\bitcoin\system\impl\chain</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\system\impl\data\array_cast.ipp">
<Filter>include\bitcoin\system\impl\data</Filter>
</None>
Expand Down
19 changes: 18 additions & 1 deletion include/bitcoin/system/chain/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#ifndef LIBBITCOIN_SYSTEM_CHAIN_BLOCK_HPP
#define LIBBITCOIN_SYSTEM_CHAIN_BLOCK_HPP

#include <functional>
#include <memory>
#include <unordered_set>
#include <vector>
#include <bitcoin/system/chain/context.hpp>
#include <bitcoin/system/chain/header.hpp>
Expand Down Expand Up @@ -165,13 +167,24 @@ class BC_API block
bool is_unspent_coinbase_collision() const NOEXCEPT;

private:
using point_cref = std::reference_wrapper<const point>;
using point_hash = std::hash<std::reference_wrapper<const point>>;
using hash_cref = std::reference_wrapper<const hash_digest>;
using hash_hash = unique_hash_t<>;

using unordered_map_of_constant_referenced_points =
std::unordered_map<point_cref, output::cptr, point_hash>;
using unordered_set_of_constant_referenced_points =
std::unordered_set<point_cref, point_hash>;
using unordered_set_of_constant_referenced_hashes =
std::unordered_set<hash_cref, hash_hash>;

static block from_data(reader& source, bool witness) NOEXCEPT;

// context free
hash_digest generate_merkle_root(bool witness) const NOEXCEPT;

// contextual
size_t non_coinbase_inputs() const NOEXCEPT;
uint64_t reward(size_t height, uint64_t subsidy_interval,
uint64_t initial_block_subsidy_satoshi, bool bip42) const NOEXCEPT;

Expand All @@ -186,7 +199,11 @@ class BC_API block
// copy: 4 * 64 + 1 = 33 bytes (vs. 16 when shared).
chain::header::cptr header_;
chain::transactions_cptr txs_;

// Cache.
bool valid_;
////size_t nominal_size_;
////size_t witness_size_;
};

typedef std::vector<block> blocks;
Expand Down
4 changes: 4 additions & 0 deletions include/bitcoin/system/chain/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class BC_API input
/// -----------------------------------------------------------------------

bool is_final() const NOEXCEPT;
bool is_roller() const NOEXCEPT;
bool reserved_hash(hash_digest& out) const NOEXCEPT;

/// Assumes coinbase if prevout not populated (returns only legacy sigops).
Expand Down Expand Up @@ -137,7 +138,10 @@ class BC_API input
chain::script::cptr script_;
chain::witness::cptr witness_;
uint32_t sequence_;

// Cache.
bool valid_;
////size_t size_;

public:
/// Public mutable metadata access, copied but not compared for equality.
Expand Down
Loading

0 comments on commit 434772a

Please sign in to comment.