diff --git a/include/bitcoin/node/protocols/protocol_header_in_70014.hpp b/include/bitcoin/node/protocols/protocol_header_in_70014.hpp index e5e57d28..66070f78 100644 --- a/include/bitcoin/node/protocols/protocol_header_in_70014.hpp +++ b/include/bitcoin/node/protocols/protocol_header_in_70014.hpp @@ -56,7 +56,7 @@ class BCN_API protocol_header_in_70014 system::hash_digest hash{}; system::chain::header::cptr header{}; system::siphash_key key{}; - std::vector short_ids{}; + std::vector short_ids{}; system::chain::transaction_cptrs txs{}; database::tx_links links{}; std::vector missing{}; diff --git a/include/bitcoin/node/protocols/protocol_peer.hpp b/include/bitcoin/node/protocols/protocol_peer.hpp index a96566d5..49449ee2 100644 --- a/include/bitcoin/node/protocols/protocol_peer.hpp +++ b/include/bitcoin/node/protocols/protocol_peer.hpp @@ -86,18 +86,6 @@ class BCN_API protocol_peer /// Compact blocks (bip152 version 2). /// ----------------------------------------------------------------------- - /// Short id siphash key of the header and nonce. - static system::siphash_key to_compact_key( - const system::chain::header& header, uint64_t nonce) NOEXCEPT; - - /// Short id of a witness hash (low 48 bits of its siphash). - static uint64_t to_short_id(const system::siphash_key& key, - const system::hash_digest& wtxid) NOEXCEPT; - - /// Short id wire encoding (six bytes little endian). - static uint64_t from_mini(const system::mini_hash& id) NOEXCEPT; - static system::mini_hash to_mini(uint64_t id) NOEXCEPT; - /// Compact block of an associated block (coinbase prefilled), or null. virtual network::messages::peer::compact_block::cptr make_compact_block( const database::header_link& link) const NOEXCEPT; diff --git a/src/protocols/protocol_header_in_70014.cpp b/src/protocols/protocol_header_in_70014.cpp index e6521ee1..96ed1493 100644 --- a/src/protocols/protocol_header_in_70014.cpp +++ b/src/protocols/protocol_header_in_70014.cpp @@ -177,7 +177,7 @@ void protocol_header_in_70014::collect(const compact_block& message, block.height = ctx.height; block.header = message.header_ptr; block.hash = message.header_ptr->get_hash(); - block.key = to_compact_key(*message.header_ptr, message.nonce); + block.key = chain::short_id::to_key(*message.header_ptr, message.nonce); if (!decode(block, message)) { @@ -232,7 +232,7 @@ bool protocol_header_in_70014::decode(fill& block, auto id = ids.begin(); for (position = zero; position < count; ++position) if (!block.txs.at(position)) - block.short_ids.at(position) = from_mini(*id++); + block.short_ids.at(position) = chain::short_id::from_mini(*id++); return true; } @@ -241,7 +241,7 @@ bool protocol_header_in_70014::decode(fill& block, bool protocol_header_in_70014::scan(fill& block) NOEXCEPT { BC_ASSERT(stranded()); - std::vector short_ids{}; + std::vector short_ids{}; std::vector positions{}; for (size_t position{}; position < block.txs.size(); ++position) { @@ -326,7 +326,7 @@ bool protocol_header_in_70014::handle_receive_compact_transactions( { const auto& tx = txs.at(index); const auto position = block.missing.at(index); - if (!tx || (to_short_id(block.key, tx->is_coinbase() ? + if (!tx || (chain::short_id::to_id(block.key, tx->is_coinbase() ? bitcoin_hash(tx->to_data(true)) : tx->get_hash(true)) != block.short_ids.at(position))) { diff --git a/src/protocols/protocol_peer.cpp b/src/protocols/protocol_peer.cpp index 9ab2a69f..ecc839f2 100644 --- a/src/protocols/protocol_peer.cpp +++ b/src/protocols/protocol_peer.cpp @@ -63,40 +63,6 @@ code protocol_peer::fault(const code& ec) NOEXCEPT // Compact blocks (bip152 version 2). // ---------------------------------------------------------------------------- -// static -siphash_key protocol_peer::to_compact_key(const chain::header& header, - uint64_t nonce) NOEXCEPT -{ - auto data = header.to_data(); - extend(data, to_little_endian(nonce)); - return to_siphash_key(split(sha256_hash(data)).first); -} - -// static -uint64_t protocol_peer::to_short_id(const siphash_key& key, - const hash_digest& wtxid) NOEXCEPT -{ - constexpr auto mask = unmask_right(to_bits(mini_hash_size)); - return bit_and(siphash(key, wtxid), mask); -} - -// static -uint64_t protocol_peer::from_mini(const mini_hash& id) NOEXCEPT -{ - data_array bytes{}; - std::copy(id.begin(), id.end(), bytes.begin()); - return from_little_endian(bytes); -} - -// static -mini_hash protocol_peer::to_mini(uint64_t id) NOEXCEPT -{ - mini_hash out{}; - const auto bytes = to_little_endian(id); - std::copy_n(bytes.begin(), out.size(), out.begin()); - return out; -} - network::messages::peer::compact_block::cptr protocol_peer::make_compact_block( const database::header_link& link) const NOEXCEPT { @@ -113,7 +79,7 @@ network::messages::peer::compact_block::cptr protocol_peer::make_compact_block( return {}; const auto nonce = maybe_random::next(0, max_uint64); - const auto key = to_compact_key(*header, nonce); + const auto key = chain::short_id::to_key(*header, nonce); compact_block::short_id_list ids{}; ids.reserve(sub1(wtxids.size())); @@ -122,7 +88,8 @@ network::messages::peer::compact_block::cptr protocol_peer::make_compact_block( if (*it == null_hash) return {}; - ids.push_back(to_mini(to_short_id(key, *it))); + const auto id = chain::short_id::to_id(key, *it); + ids.push_back(chain::short_id::to_mini(id)); } return to_shared(compact_block diff --git a/test/functional/p2p_compact.cpp b/test/functional/p2p_compact.cpp index 7f800a6e..a7f4e63f 100644 --- a/test/functional/p2p_compact.cpp +++ b/test/functional/p2p_compact.cpp @@ -25,14 +25,6 @@ using namespace network::messages::peer; constexpr uint64_t full_node = service::node_network | service::node_witness; -struct compact_accessor - : node::protocol_peer -{ - using protocol_peer::to_compact_key; - using protocol_peer::to_short_id; - using protocol_peer::to_mini; -}; - static compact_block prefilled(const chain::block& block, const chain::transaction::cptr& coinbase) { @@ -41,11 +33,11 @@ static compact_block prefilled(const chain::block& block, static compact_block shortened(const chain::block& block) { - const auto key = compact_accessor::to_compact_key(block.header(), 42); + const auto key = chain::short_id::to_key(block.header(), 42); const auto& coinbase = *block.transactions_ptr()->front(); const auto hash = bitcoin_hash(coinbase.to_data(true)); - const auto short_id = compact_accessor::to_short_id(key, hash); - const auto id = compact_accessor::to_mini(short_id); + const auto integer = chain::short_id::to_id(key, hash); + const auto id = chain::short_id::to_mini(integer); return { block.header_ptr(), 42, { id }, {} }; }