Skip to content

Commit 1be0e57

Browse files
committed
Comments, style.
1 parent 171f520 commit 1be0e57

3 files changed

Lines changed: 13 additions & 18 deletions

File tree

src/protocols/electrum/protocol_electrum.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ bool protocol_electrum::handle_event(const code&, node::chase event_,
184184
return true;
185185
}
186186

187-
// regress
187+
// reorganization
188188
// ----------------------------------------------------------------------------
189+
// outpoint subscriptions do not require modification.
189190

190191
// The chain has been reduced in height, clear all midstate cache and cursors.
191192
void protocol_electrum::do_reorganized(node::header_t) NOEXCEPT

src/protocols/electrum/protocol_electrum_outpoints.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ bool protocol_electrum::get_outpoint_history(outpoint_subscription& out,
133133
return false;
134134
}
135135

136-
// TODO: this could be accept stopping_ but it's a small query.
137136
out.spenders = query.get_spenders_history(prevout);
138137
return true;
139138
}
@@ -169,6 +168,7 @@ void protocol_electrum::handle_blockchain_outpoint_subscribe(const code& ec,
169168
NOTIFY(do_outpoint_subscribe, point{ hash, index });
170169
}
171170

171+
// Subscription response is idempotent.
172172
void protocol_electrum::do_outpoint_subscribe(const point& prevout) NOEXCEPT
173173
{
174174
// Cancellability is preserved because not on channel strand.
@@ -180,7 +180,6 @@ void protocol_electrum::do_outpoint_subscribe(const point& prevout) NOEXCEPT
180180
{
181181
ec = get_outpoint_history(sub, prevout) ?
182182
error::success : ec = error::not_found;
183-
184183
outpoint_subscriptions_.emplace(prevout, sub);
185184
subscribed_outpoint_.store(true, relaxed);
186185
}
@@ -207,9 +206,9 @@ void protocol_electrum::complete_outpoint_subscribe(const code& ec,
207206
// Send first spender only.
208207
send_result(to_outpoint_status(sub), 128, BIND(complete, _1));
209208

209+
// Send remaining spenders as notifications.
210210
// Send here vs. completion handler because asio will queue it up
211211
// behind the send anyway, and this prevents another sub copy.
212-
// Send remaining spenders as notifications.
213212
if (!sub.spenders.empty())
214213
{
215214
const auto height = sub.outpoint.tx.height();
@@ -283,40 +282,40 @@ void protocol_electrum::do_outpoint(node::header_t) NOEXCEPT
283282
auto& sub = subscription.second;
284283
const auto& prevout = subscription.first;
285284

286-
outpoint_subscription res{};
287-
if (!get_outpoint_history(res, prevout))
285+
outpoint_subscription result{};
286+
if (!get_outpoint_history(result, prevout))
288287
{
289288
LOGV("Electrum::do_outpoint, outpoint not found.");
290289
continue;
291290
}
292291

293292
// There is no change.
294-
if (sub == res) continue;
293+
if (sub == result) continue;
295294

296295
const auto height = sub.outpoint.tx.height();
297296
if (!sub.outpoint.valid() || sub.outpoint.tx.height() != height)
298297
{
299298
// Outpoint changed (or newly found), send all current spenders.
300-
if (res.spenders.empty())
299+
if (result.spenders.empty())
301300
{
302301
POST(outpoint_notify, make_status(height), prevout);
303302
}
304-
else for (const auto& spender: res.spenders)
303+
else for (const auto& spender: result.spenders)
305304
{
306305
POST(outpoint_notify, make_status(height, spender), prevout);
307306
}
308307
}
309308
else
310309
{
311310
// Outpoint unchanged, send only new or changed spenders.
312-
for (const auto& spender: difference(res.spenders, sub.spenders))
311+
for (const auto& spender: difference(result.spenders, sub.spenders))
313312
{
314313
POST(outpoint_notify, make_status(height, spender), prevout);
315314
}
316315
}
317316

318317
// Update subscription state.
319-
sub = std::move(res);
318+
sub = std::move(result);
320319
}
321320
}
322321

src/protocols/electrum/protocol_electrum_subscribe.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,23 @@ void protocol_electrum::scripthash_subscribe(const hash_digest& hash,
8181
NOTIFY(do_scripthash_subscribe, hash, type);
8282
}
8383

84+
// Subscription response is idempotent.
8485
void protocol_electrum::do_scripthash_subscribe(const hash_digest& hash,
8586
notify_t type) NOEXCEPT
8687
{
8788
// Cancellability is preserved because not on channel strand.
8889
BC_ASSERT(notification_strand_.running_in_this_thread());
8990

90-
code ec{};
9191
hash_digest status{};
92+
code ec{ error::subscription_limit };
9293
if (address_subscriptions_.size() < options_.maximum_subscriptions)
9394
{
9495
using mid = midstate;
9596
const auto limit = options().maximum_history;
96-
97-
// Subscription response is idempotent.
9897
auto& at = *address_subscriptions_.try_emplace(hash, type, mid{}).first;
9998
ec = get_scripthash_history(status, at.second, at.first, limit);
10099
subscribed_address_.store(true, relaxed);
101100
}
102-
else
103-
{
104-
ec = error::subscription_limit;
105-
}
106101

107102
POST(complete_scripthash_subscribe, ec, hash, status);
108103
}

0 commit comments

Comments
 (0)