Allow dropping light client RPC query with no results (#9318)

* OnDemand no longer loop until there is a query.
All peer known at the time will be queried, and the query fail if all
return no reply.
Returning the failure is done through an empty Vec of reply (the type
of the oneshot channel remains unchanged).
Before this commit the query were send randomly to any peer until there
is a reply (for a query that got no result it was an issue, for other
queries it was quering multiple times the same peers).
After this commit the first query is random but next queries
follows hashmap iterator order.

Test no_capability was broken by this commit (the pending query was
removed).

* OnDemand no longer loop until there is a query.
All peer known at the time will be queried, and the query fail if all
return no reply.
Returning the failure is done through an empty Vec of reply (the type
of the oneshot channel remains unchanged).
Before this commit the query were send randomly to any peer until there
is a reply (for a query that got no result it was an issue, for other
queries it was quering multiple times the same peers).
After this commit the first query is random but next queries
follows hashmap iterator order.

Test no_capability was broken by this commit (the pending query was
removed). If adding some kind of timeout mechanism it could be restored.

* Comment plus better field names.

* No panick on dropped oneshot channel.

* Use Set to avoid counter heuristic

* Cli option `on_demand_nb_retry` for maximum number of retry when doing
on demand query in light client.

* Missing test update for previous commit

* Add a timeout (only when there is no peer to query), that way we do not
set number of query to minimum current number peer or configured number
of query : that way capability test was restored.

* Adding an error type for on_demand, it helps having variant of error
reported at rpc level : choice of rpc error code error might not be
right.

* Duration as constant is nice

* Switch to duration in main too

* Fix indentation (sorry for that).

* Fix error management (bad merge in previous commit)

* Lots of english corrections, major change on the new command parameters :
 - use standard '-' instead of '_'
 - renaming nb_retry params to 'on-demand-retry-count'
This commit is contained in:
cheme
2018-09-12 11:47:01 +02:00
committed by Afri Schoedon
parent 69667317c1
commit 61f4534e2a
10 changed files with 299 additions and 65 deletions

View File

@@ -407,7 +407,7 @@ usage! {
"--port=[PORT]",
"Override the port on which the node should listen.",
ARG arg_interface: (String) = "all", or |c: &Config| c.network.as_ref()?.interface.clone(),
ARG arg_interface: (String) = "all", or |c: &Config| c.network.as_ref()?.interface.clone(),
"--interface=[IP]",
"Network interfaces. Valid values are 'all', 'local' or the ip of the interface you want parity to listen to.",
@@ -471,7 +471,7 @@ usage! {
"--jsonrpc-port=[PORT]",
"Specify the port portion of the HTTP JSON-RPC API server.",
ARG arg_jsonrpc_interface: (String) = "local", or |c: &Config| c.rpc.as_ref()?.interface.clone(),
ARG arg_jsonrpc_interface: (String) = "local", or |c: &Config| c.rpc.as_ref()?.interface.clone(),
"--jsonrpc-interface=[IP]",
"Specify the hostname portion of the HTTP JSON-RPC API server, IP should be an interface's IP address, or all (all interfaces) or local.",
@@ -508,7 +508,7 @@ usage! {
"--ws-port=[PORT]",
"Specify the port portion of the WebSockets JSON-RPC server.",
ARG arg_ws_interface: (String) = "local", or |c: &Config| c.websockets.as_ref()?.interface.clone(),
ARG arg_ws_interface: (String) = "local", or |c: &Config| c.websockets.as_ref()?.interface.clone(),
"--ws-interface=[IP]",
"Specify the hostname portion of the WebSockets JSON-RPC server, IP should be an interface's IP address, or all (all interfaces) or local.",
@@ -562,6 +562,15 @@ usage! {
"--ipfs-api-cors=[URL]",
"Specify CORS header for IPFS API responses. Special options: \"all\", \"none\".",
["Light Client Options"]
ARG arg_on_demand_retry_count: (Option<usize>) = None, or |c: &Config| c.light.as_ref()?.on_demand_retry_count,
"--on-demand-retry-count=[RETRIES]",
"Specify the query retry count.",
ARG arg_on_demand_inactive_time_limit: (Option<u64>) = None, or |c: &Config| c.light.as_ref()?.on_demand_inactive_time_limit,
"--on-demand-inactive-time-limit=[MS]",
"Specify light client query inactive time limit. O for no limit.",
["Secret Store Options"]
FLAG flag_no_secretstore: (bool) = false, or |c: &Config| c.secretstore.as_ref()?.disable.clone(),
"--no-secretstore",
@@ -875,7 +884,7 @@ usage! {
"Target size of the whisper message pool in megabytes.",
["Legacy Options"]
// Options that are hidden from config, but are still unique for its functionality.
// Options that are hidden from config, but are still unique for its functionality.
FLAG flag_geth: (bool) = false, or |_| None,
"--geth",
@@ -1100,6 +1109,7 @@ struct Config {
misc: Option<Misc>,
stratum: Option<Stratum>,
whisper: Option<Whisper>,
light: Option<Light>,
}
#[derive(Default, Debug, PartialEq, Deserialize)]
@@ -1364,12 +1374,19 @@ struct Whisper {
pool_size: Option<usize>,
}
#[derive(Default, Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
struct Light {
on_demand_retry_count: Option<usize>,
on_demand_inactive_time_limit: Option<u64>,
}
#[cfg(test)]
mod tests {
use super::{
Args, ArgsError,
Config, Operating, Account, Ui, Network, Ws, Rpc, Ipc, Dapps, Ipfs, Mining, Footprint,
Snapshots, Misc, Whisper, SecretStore,
Snapshots, Misc, Whisper, SecretStore, Light,
};
use toml;
use clap::{ErrorKind as ClapErrorKind};
@@ -1772,6 +1789,10 @@ mod tests {
arg_snapshot_at: "latest".into(),
flag_no_periodic_snapshot: false,
// -- Light options.
arg_on_demand_retry_count: Some(15),
arg_on_demand_inactive_time_limit: Some(15000),
// -- Whisper options.
flag_whisper: false,
arg_whisper_pool_size: 20,
@@ -2019,6 +2040,10 @@ mod tests {
scale_verifiers: Some(false),
num_verifiers: None,
}),
light: Some(Light {
on_demand_retry_count: Some(12),
on_demand_inactive_time_limit: Some(20000),
}),
snapshots: Some(Snapshots {
disable_periodic: Some(true),
}),

View File

@@ -155,6 +155,10 @@ fat_db = "auto"
scale_verifiers = true
num_verifiers = 6
[light]
on_demand_retry_count = 15
on_demand_inactive_time_limit = 15000
[snapshots]
disable_periodic = false

View File

@@ -70,6 +70,10 @@ db_compaction = "ssd"
fat_db = "off"
scale_verifiers = false
[light]
on_demand_retry_count = 12
on_demand_inactive_time_limit = 20000
[snapshots]
disable_periodic = true