Skip to content

Commit 704c109

Browse files
committed
style.
1 parent b2ae4e6 commit 704c109

5 files changed

Lines changed: 18 additions & 16 deletions

File tree

include/bitcoin/server/protocols/protocol_electrum.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ class BCS_API protocol_electrum
355355
std::atomic_bool stopping_{};
356356
std::atomic_bool subscribed_height_{};
357357
std::atomic_bool subscribed_header_{};
358+
std::atomic_bool subscribed_address_{};
358359
std::atomic_bool subscribed_outpoint_{};
359-
std::atomic_bool subscribed_scripthash_{};
360360

361361
// This is mostly thread safe, and used in a thread safe manner.
362362
const channel_t::ptr channel_;
@@ -365,8 +365,8 @@ class BCS_API protocol_electrum
365365
network::asio::strand notification_strand_;
366366

367367
// These are protected by notification strand.
368+
std::map<hash_digest, subscription> address_subscriptions_{};
368369
std::set<system::chain::point> outpoint_subscriptions_{};
369-
std::map<hash_digest, subscription> scripthash_subscriptions_{};
370370
};
371371

372372
} // namespace server

src/protocols/electrum/protocol_electrum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ bool protocol_electrum::handle_event(const code&, node::chase event_,
161161
NOTIFY(do_outpoint, std::get<node::header_t>(value));
162162
}
163163

164-
if (subscribed_scripthash_.load(relaxed))
164+
if (subscribed_address_.load(relaxed))
165165
{
166166
BC_ASSERT(archive().address_enabled());
167167
BC_ASSERT(std::holds_alternative<node::header_t>(value));

src/protocols/electrum/protocol_electrum_headers.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace server {
3131
using namespace system;
3232
using namespace network::rpc;
3333
using namespace std::placeholders;
34+
constexpr auto relaxed = std::memory_order_relaxed;
3435

3536
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
3637

@@ -46,7 +47,7 @@ void protocol_electrum::handle_blockchain_number_of_blocks_subscribe(
4647
return;
4748
}
4849

49-
subscribed_height_.store(true, std::memory_order_relaxed);
50+
subscribed_height_.store(true, relaxed);
5051
const auto top_height = archive().get_top_confirmed();
5152
send_result(top_height, 42, BIND(complete, _1));
5253
}
@@ -362,7 +363,7 @@ void protocol_electrum::handle_blockchain_headers_subscribe(const code& ec,
362363
return;
363364
}
364365

365-
subscribed_header_.store(true, std::memory_order_relaxed);
366+
subscribed_header_.store(true, relaxed);
366367
send_result(object_t
367368
{
368369
{ "height", top },

src/protocols/electrum/protocol_electrum_outputs.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace server {
2929
using namespace system;
3030
using namespace network::rpc;
3131
using namespace std::placeholders;
32+
constexpr auto relaxed = std::memory_order_relaxed;
3233

3334
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
3435

@@ -131,7 +132,7 @@ void protocol_electrum::handle_blockchain_outpoint_subscribe(const code& ec,
131132

132133
// TODO: subscribe.
133134
///////////////////////////////////////////////////////////////////////////
134-
subscribed_outpoint_.store(true, std::memory_order_relaxed);
135+
subscribed_outpoint_.store(true, relaxed);
135136
///////////////////////////////////////////////////////////////////////////
136137

137138
chain::point prevout{ hash, index };
@@ -165,7 +166,7 @@ void protocol_electrum::handle_blockchain_outpoint_unsubscribe(const code& ec,
165166

166167
// TODO: unsubscribe.
167168
///////////////////////////////////////////////////////////////////////////
168-
const auto prior = subscribed_outpoint_.load(std::memory_order_relaxed);
169+
const auto prior = subscribed_outpoint_.load(relaxed);
169170
///////////////////////////////////////////////////////////////////////////
170171

171172
send_result(prior, 16, BIND(complete, _1));

src/protocols/electrum/protocol_electrum_scripthash_subscribe.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace server {
3030
using namespace system;
3131
using namespace network::rpc;
3232
using namespace std::placeholders;
33+
constexpr auto relaxed = std::memory_order_relaxed;
3334

3435
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
3536

@@ -71,7 +72,7 @@ void protocol_electrum::scripthash_subscribe(const hash_digest& hash,
7172
return;
7273
}
7374

74-
if (scripthash_subscriptions_.size() >= options_.maximum_subscriptions)
75+
if (address_subscriptions_.size() >= options_.maximum_subscriptions)
7576
{
7677
send_code(error::subscription_limit);
7778
return;
@@ -93,9 +94,8 @@ void protocol_electrum::do_scripthash_subscribe(const hash_digest& hash,
9394
BC_ASSERT(notification_strand_.running_in_this_thread());
9495

9596
// Subscription response is idempotent.
96-
subscribed_scripthash_.store(true, std::memory_order_relaxed);
97-
auto [it, inserted] = scripthash_subscriptions_.try_emplace(hash, type,
98-
midstate{});
97+
subscribed_address_.store(true, relaxed);
98+
auto [it, in] = address_subscriptions_.try_emplace(hash, type, midstate{});
9999

100100
hash_digest status{};
101101
const auto ec = get_scripthash_status(status, it->second, it->first);
@@ -169,9 +169,9 @@ void protocol_electrum::do_scripthash_unsubscribe(
169169
{
170170
BC_ASSERT(notification_strand_.running_in_this_thread());
171171

172-
const auto found = to_bool(scripthash_subscriptions_.erase(hash));
173-
if (is_zero(scripthash_subscriptions_.size()))
174-
subscribed_scripthash_.store(false, std::memory_order_relaxed);
172+
const auto found = to_bool(address_subscriptions_.erase(hash));
173+
if (is_zero(address_subscriptions_.size()))
174+
subscribed_address_.store(false, relaxed);
175175

176176
POST(complete_scripthash_unsubscribe, found);
177177
}
@@ -192,7 +192,7 @@ void protocol_electrum::do_scripthash(node::header_t) NOEXCEPT
192192

193193
code ec{};
194194
hash_digest status{};
195-
for (auto& [key, sub]: scripthash_subscriptions_)
195+
for (auto& [key, sub]: address_subscriptions_)
196196
{
197197
if ((ec = get_scripthash_status(status, sub, key)))
198198
{
@@ -227,7 +227,7 @@ void protocol_electrum::do_regressed(node::header_t) NOEXCEPT
227227
{
228228
BC_ASSERT(notification_strand_.running_in_this_thread());
229229

230-
for (auto& [key, sub]: scripthash_subscriptions_)
230+
for (auto& [key, sub]: address_subscriptions_)
231231
{
232232
// writer.flush resets hash accumulator, sub.type remains unchanged.
233233
sub.state.writer.flush();

0 commit comments

Comments
 (0)