verify-chain node client arg (#3678)

* add parameter fast_validation to the api

* arg `verify-chain` on node client

* arg verify chain + read_timeout parameter

* change timeout to 2hours

* update with tromp review

* 2nd comment from tromp
This commit is contained in:
deevope
2022-01-07 14:45:48 +01:00
committed by GitHub
parent c92d2e9fba
commit a3eebbc0ab
7 changed files with 125 additions and 29 deletions
+36 -2
View File
@@ -45,10 +45,19 @@ impl HTTPNodeClient {
method: &str,
params: &serde_json::Value,
) -> Result<D, Error> {
let timeout = match method {
// 6 hours read timeout
"validate_chain" => client::TimeOut::new(20, 21600, 20),
_ => client::TimeOut::default(),
};
let url = format!("http://{}{}", self.node_url, ENDPOINT);
let req = build_request(method, params);
let res =
client::post::<Request, Response>(url.as_str(), self.node_api_secret.clone(), &req);
let res = client::post::<Request, Response>(
url.as_str(),
self.node_api_secret.clone(),
&req,
timeout,
);
match res {
Err(e) => {
@@ -149,6 +158,27 @@ impl HTTPNodeClient {
e.reset().unwrap();
}
pub fn verify_chain(&self, assume_valid_rangeproofs_kernels: bool) {
let mut e = term::stdout().unwrap();
let params = json!([assume_valid_rangeproofs_kernels]);
writeln!(
e,
"Checking the state of the chain. This might take time..."
)
.unwrap();
match self.send_json_request::<()>("validate_chain", &params) {
Ok(_) => {
if assume_valid_rangeproofs_kernels {
writeln!(e, "Successfully validated the sum of kernel excesses! [fast_verification enabled]").unwrap()
} else {
writeln!(e, "Successfully validated the sum of kernel excesses, kernel signature and rangeproofs!").unwrap()
}
}
Err(err) => writeln!(e, "Failed to validate chain: {:?}", err).unwrap(),
}
e.reset().unwrap();
}
pub fn ban_peer(&self, peer_addr: &SocketAddr) {
let mut e = term::stdout().unwrap();
let params = json!([peer_addr]);
@@ -191,6 +221,10 @@ pub fn client_command(client_args: &ArgMatches<'_>, global_config: GlobalConfig)
let hash = args.value_of("hash").unwrap();
node_client.invalidate_header(hash.to_string());
}
("verify-chain", Some(args)) => {
let assume_valid_rangeproofs_kernels = args.is_present("fast");
node_client.verify_chain(assume_valid_rangeproofs_kernels);
}
("ban", Some(peer_args)) => {
let peer = peer_args.value_of("peer").unwrap();
+9 -1
View File
@@ -78,9 +78,17 @@ subcommands:
- hash:
help: The header hash to reset to
required: true
- verify-chain:
about: Trigger a verication of the rangeproofs, kernel signatures and excesses.
args:
- fast:
help: if present, will skip verification of rangeproofs, kernel signatures and will only validate the sum of kernel excesses.
short: f
long: fast
takes_value: false
- invalidateheader:
about: Adds header hash to denylist
args:
- hash:
help: The header hash to invalidate
required: true
required: true