Skip to content

Commit bde05ec

Browse files
committed
Style.
1 parent 3da061c commit bde05ec

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/protocols/protocol_electrum.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,30 +179,35 @@ void protocol_electrum::handle_blockchain_block_headers(const code& ec,
179179
void protocol_electrum::blockchain_block_headers(size_t starting,
180180
size_t quantity, size_t waypoint, bool multiplicity) NOEXCEPT
181181
{
182+
const auto prove = !is_zero(quantity) && !is_zero(waypoint);
183+
const auto target = starting + sub1(quantity);
184+
const auto& query = archive();
182185
using namespace system;
186+
187+
// The documented requirement: `start_height + (count - 1) <= cp_height` is
188+
// ambiguous at count = 0 so guard must be applied to both args and prover.
183189
if (is_add_overflow(starting, quantity))
184190
{
185191
send_code(error::argument_overflow);
186192
return;
187193
}
188-
189-
// The documented requirement: `start_height + (count - 1) <= cp_height` is
190-
// ambiguous at count = 0 so guard must be applied to both args and prover.
191-
const auto target = starting + sub1(quantity);
192-
const auto prove = !is_zero(quantity) && !is_zero(waypoint);
193-
if (prove && target > waypoint)
194+
else if (prove && target > waypoint)
194195
{
195196
send_code(error::target_overflow);
196197
return;
197198
}
199+
else if (prove && waypoint > query.get_top_confirmed())
200+
{
201+
send_code(error::not_found);
202+
return;
203+
}
198204

199205
// Recommended to be at least one difficulty retarget period, e.g. 2016.
200206
// The maximum number of headers the server will return in single request.
201207
const auto maximum = server_settings().electrum.maximum_headers;
202208

203209
// Returned headers are assured to be contiguous despite intervening reorg.
204210
// No headers may be returned, which implies start > confirmed top block.
205-
const auto& query = archive();
206211
const auto count = limit(quantity, maximum);
207212
const auto links = query.get_confirmed_headers(starting, count);
208213
constexpr auto header_size = chain::header::serialized_size();

0 commit comments

Comments
 (0)