Skip to content

Commit 35af405

Browse files
authored
Merge pull request #909 from evoskuil/master
Parse and integrate database.turbo setting and ?turbo=true param.
2 parents 3bdcf31 + b9e07ef commit 35af405

File tree

4 files changed

+68
-44
lines changed

4 files changed

+68
-44
lines changed

include/bitcoin/node/protocols/protocol_explore.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,34 +134,33 @@ class BCN_API protocol_explore
134134

135135
bool handle_get_address(const code& ec, interface::address,
136136
uint8_t version, uint8_t media,
137-
const system::hash_cptr& hash) NOEXCEPT;
137+
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
138138
bool handle_get_address_confirmed(const code& ec,
139139
interface::address_confirmed, uint8_t version, uint8_t media,
140-
const system::hash_cptr& hash) NOEXCEPT;
140+
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
141141
bool handle_get_address_unconfirmed(const code& ec,
142142
interface::address_unconfirmed, uint8_t version, uint8_t media,
143-
const system::hash_cptr& hash) NOEXCEPT;
143+
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
144144
bool handle_get_address_balance(const code& ec,
145145
interface::address_balance, uint8_t version, uint8_t media,
146-
const system::hash_cptr& hash) NOEXCEPT;
146+
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
147147

148148
private:
149149
using balance_handler = std::function<void(code, uint8_t, uint64_t)>;
150150
using address_handler = std::function<void(code, uint8_t,
151151
database::outpoints&&)>;
152152

153-
void do_get_address(uint8_t media, const system::hash_cptr& hash,
154-
const address_handler& handler) NOEXCEPT;
155-
void do_get_address_confirmed(uint8_t media, const system::hash_cptr& hash,
156-
const address_handler& handler) NOEXCEPT;
157-
void do_get_address_unconfirmed(uint8_t media,
158-
const system::hash_cptr& hash,
159-
const address_handler& handler) NOEXCEPT;
153+
void do_get_address(uint8_t media, bool turbo,
154+
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
155+
void do_get_address_confirmed(uint8_t media, bool turbo,
156+
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
157+
void do_get_address_unconfirmed(uint8_t media, bool turbo,
158+
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
160159
void complete_get_address(const code& ec, uint8_t media,
161160
const database::outpoints& set) NOEXCEPT;
162161

163-
void do_get_address_balance(uint8_t media, const system::hash_cptr& hash,
164-
const balance_handler& handler) NOEXCEPT;
162+
void do_get_address_balance(uint8_t media, bool turbo,
163+
const system::hash_cptr& hash, const balance_handler& handler) NOEXCEPT;
165164
void complete_get_address_balance(const code& ec, uint8_t media,
166165
const uint64_t balance) NOEXCEPT;
167166

src/parse/query.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ using namespace system;
2727
using namespace network;
2828
using namespace network::http;
2929

30+
BC_PUSH_WARNING(NO_ARRAY_INDEXING)
31+
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
32+
3033
bool parse_query(rpc::request_t& out, const request& request) NOEXCEPT
3134
{
3235
wallet::uri uri{};
@@ -45,15 +48,30 @@ bool parse_query(rpc::request_t& out, const request& request) NOEXCEPT
4548
return false;
4649

4750
auto& params = std::get<rpc::object_t>(out.params.value());
48-
const auto& witness = query["witness"];
4951

50-
// Validate prper bool value if set.
51-
if (!witness.empty() && witness != "true" && witness != "false")
52-
return false;
52+
// Validate proper witness bool value if set.
53+
const auto witness = query.find("witness");
54+
if (witness != query.end())
55+
{
56+
if (witness->second != "true" && witness->second != "false")
57+
return false;
5358

54-
// Witness is optional<true> (where applicable) so only set if false.
55-
if (witness == "false")
56-
params["witness"] = false;
59+
// Witness is optional<true> (where applicable), so only set if false.
60+
if (witness->second == "false")
61+
params["witness"] = false;
62+
}
63+
64+
// Validate proper turbo bool value if set.
65+
const auto turbo = query.find("turbo");
66+
if (turbo != query.end())
67+
{
68+
if (turbo->second != "true" && turbo->second != "false")
69+
return false;
70+
71+
// Turbo is optional<true> (where applicable), so only set if false.
72+
if (turbo->second == "false")
73+
params["turbo"] = false;
74+
}
5775

5876
const auto accepts = to_media_types((request)[field::accept]);
5977

@@ -80,5 +98,8 @@ bool parse_query(rpc::request_t& out, const request& request) NOEXCEPT
8098
return true;
8199
}
82100

101+
BC_POP_WARNING()
102+
BC_POP_WARNING()
103+
83104
} // namespace node
84105
} // namespace libbitcoin

src/parser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,11 @@ options_metadata parser::load_settings() THROWS
11251125
value<std::filesystem::path>(&configured.database.path),
11261126
"The blockchain database directory, defaults to 'blockchain'."
11271127
)
1128+
(
1129+
"database.turbo",
1130+
value<bool>(&configured.database.turbo),
1131+
"Allow indiviudal non-validation queries to use all CPUs, defaults to false."
1132+
)
11281133

11291134
/* header */
11301135
(

src/protocols/protocol_explore.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ void protocol_explore::start() NOEXCEPT
107107
SUBSCRIBE_EXPLORE(handle_get_output_spender, _1, _2, _3, _4, _5, _6);
108108
SUBSCRIBE_EXPLORE(handle_get_output_spenders, _1, _2, _3, _4, _5, _6);
109109

110-
SUBSCRIBE_EXPLORE(handle_get_address, _1, _2, _3, _4, _5);
111-
SUBSCRIBE_EXPLORE(handle_get_address_confirmed, _1, _2, _3, _4, _5);
112-
SUBSCRIBE_EXPLORE(handle_get_address_unconfirmed, _1, _2, _3, _4, _5);
113-
SUBSCRIBE_EXPLORE(handle_get_address_balance, _1, _2, _3, _4, _5);
110+
SUBSCRIBE_EXPLORE(handle_get_address, _1, _2, _3, _4, _5, _6);
111+
SUBSCRIBE_EXPLORE(handle_get_address_confirmed, _1, _2, _3, _4, _5, _6);
112+
SUBSCRIBE_EXPLORE(handle_get_address_unconfirmed, _1, _2, _3, _4, _5, _6);
113+
SUBSCRIBE_EXPLORE(handle_get_address_balance, _1, _2, _3, _4, _5, _6);
114114
protocol_html::start();
115115
}
116116

@@ -480,10 +480,8 @@ bool protocol_explore::handle_get_block_filter_header(const code& ec,
480480
switch (media)
481481
{
482482
case data:
483-
{
484483
send_chunk(to_chunk(filter_head));
485484
return true;
486-
}
487485
case text:
488486
send_text(encode_base16(filter_head));
489487
return true;
@@ -935,7 +933,7 @@ bool protocol_explore::handle_get_output_spenders(const code& ec,
935933
// ----------------------------------------------------------------------------
936934

937935
bool protocol_explore::handle_get_address(const code& ec, interface::address,
938-
uint8_t, uint8_t media, const hash_cptr& hash) NOEXCEPT
936+
uint8_t, uint8_t media, const hash_cptr& hash, bool turbo) NOEXCEPT
939937
{
940938
if (stopped(ec))
941939
return false;
@@ -947,16 +945,17 @@ bool protocol_explore::handle_get_address(const code& ec, interface::address,
947945
}
948946

949947
address_handler complete = BIND(complete_get_address, _1, _2, _3);
950-
PARALLEL(do_get_address, media, hash, std::move(complete));
948+
PARALLEL(do_get_address, media, turbo, hash, std::move(complete));
951949
return true;
952950
}
953951

954952
// private
955-
void protocol_explore::do_get_address(uint8_t media, const hash_cptr& hash,
956-
const address_handler& handler) NOEXCEPT
953+
void protocol_explore::do_get_address(uint8_t media, bool turbo,
954+
const hash_cptr& hash, const address_handler& handler) NOEXCEPT
957955
{
958956
outpoints set{};
959-
if (const auto ec = archive().get_address_outputs(stopping_, set, *hash))
957+
if (const auto ec = archive().get_address_outputs(stopping_, set,
958+
*hash, turbo))
960959
{
961960
handler(ec, {}, {});
962961
return;
@@ -965,7 +964,7 @@ void protocol_explore::do_get_address(uint8_t media, const hash_cptr& hash,
965964
handler(network::error::success, media, std::move(set));
966965
}
967966

968-
// This is shared by the tree get_address.. methods.
967+
// This is shared by the three get_address... methods.
969968
void protocol_explore::complete_get_address(const code& ec, uint8_t media,
970969
const outpoints& set) NOEXCEPT
971970
{
@@ -1008,7 +1007,7 @@ void protocol_explore::complete_get_address(const code& ec, uint8_t media,
10081007

10091008
bool protocol_explore::handle_get_address_confirmed(const code& ec,
10101009
interface::address_confirmed, uint8_t, uint8_t media,
1011-
const hash_cptr& hash) NOEXCEPT
1010+
const hash_cptr& hash, bool turbo) NOEXCEPT
10121011
{
10131012
if (stopped(ec))
10141013
return false;
@@ -1020,17 +1019,17 @@ bool protocol_explore::handle_get_address_confirmed(const code& ec,
10201019
}
10211020

10221021
address_handler complete = BIND(complete_get_address, _1, _2, _3);
1023-
PARALLEL(do_get_address_confirmed, media, hash, std::move(complete));
1022+
PARALLEL(do_get_address_confirmed, media, turbo, hash, std::move(complete));
10241023
return true;
10251024
}
10261025

10271026
// private
1028-
void protocol_explore::do_get_address_confirmed(uint8_t media,
1027+
void protocol_explore::do_get_address_confirmed(uint8_t media, bool turbo,
10291028
const hash_cptr& hash, const address_handler& handler) NOEXCEPT
10301029
{
10311030
outpoints set{};
1032-
if (const auto ec = archive().get_confirmed_unspent_outputs(stopping_, set,
1033-
*hash))
1031+
if (const auto ec = archive().get_confirmed_unspent_outputs(stopping_,
1032+
set, *hash, turbo))
10341033
{
10351034
handler(ec, {}, {});
10361035
return;
@@ -1044,7 +1043,7 @@ void protocol_explore::do_get_address_confirmed(uint8_t media,
10441043

10451044
bool protocol_explore::handle_get_address_unconfirmed(const code& ec,
10461045
interface::address_unconfirmed, uint8_t, uint8_t media,
1047-
const hash_cptr& hash) NOEXCEPT
1046+
const hash_cptr& hash, bool turbo) NOEXCEPT
10481047
{
10491048
if (stopped(ec))
10501049
return false;
@@ -1054,11 +1053,11 @@ bool protocol_explore::handle_get_address_unconfirmed(const code& ec,
10541053
return true;
10551054

10561055
address_handler complete = BIND(complete_get_address, _1, _2, _3);
1057-
PARALLEL(do_get_address_unconfirmed, media, hash, std::move(complete));
1056+
PARALLEL(do_get_address_unconfirmed, media, turbo, hash, std::move(complete));
10581057
return true;
10591058
}
10601059

1061-
void protocol_explore::do_get_address_unconfirmed(uint8_t media,
1060+
void protocol_explore::do_get_address_unconfirmed(uint8_t media, bool,
10621061
const system::hash_cptr&, const address_handler& handler) NOEXCEPT
10631062
{
10641063
handler(network::error::success, media, {});
@@ -1069,7 +1068,7 @@ void protocol_explore::do_get_address_unconfirmed(uint8_t media,
10691068

10701069
bool protocol_explore::handle_get_address_balance(const code& ec,
10711070
interface::address_balance, uint8_t, uint8_t media,
1072-
const hash_cptr& hash) NOEXCEPT
1071+
const hash_cptr& hash, bool turbo) NOEXCEPT
10731072
{
10741073
if (stopped(ec))
10751074
return false;
@@ -1082,16 +1081,16 @@ bool protocol_explore::handle_get_address_balance(const code& ec,
10821081
}
10831082

10841083
balance_handler complete = BIND(complete_get_address_balance, _1, _2, _3);
1085-
PARALLEL(do_get_address_balance, media, hash, std::move(complete));
1084+
PARALLEL(do_get_address_balance, media, turbo, hash, std::move(complete));
10861085
return true;
10871086
}
10881087

1089-
void protocol_explore::do_get_address_balance(uint8_t media,
1088+
void protocol_explore::do_get_address_balance(uint8_t media, bool turbo,
10901089
const system::hash_cptr& hash, const balance_handler& handler) NOEXCEPT
10911090
{
10921091
uint64_t balance{};
10931092
if (const auto ec = archive().get_confirmed_balance(stopping_, balance,
1094-
*hash))
1093+
*hash, turbo))
10951094
{
10961095
handler(ec, {}, {});
10971096
return;

0 commit comments

Comments
 (0)