-
Notifications
You must be signed in to change notification settings - Fork 990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
verify-chain
node client arg
#3678
Changes from 5 commits
d6f592f
880a65e
1e8ba0c
7547631
eeeee1a
12e79c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,9 +53,9 @@ pub struct ChainValidationHandler { | |
} | ||
|
||
impl ChainValidationHandler { | ||
pub fn validate_chain(&self) -> Result<(), Error> { | ||
pub fn validate_chain(&self, fast_validation: bool) -> Result<(), Error> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use assume_valid_rangeproofs_kernels here as well? |
||
w(&self.chain)? | ||
.validate(true) | ||
.validate(fast_validation) | ||
.map_err(|_| ErrorKind::Internal("chain error".to_owned()).into()) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, fast_validation: bool) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use the name assume_valid_rangeproofs_kernels here as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done but i let |
||
let mut e = term::stdout().unwrap(); | ||
let params = json!([fast_validation]); | ||
writeln!( | ||
e, | ||
"Checking the state of the chain. This might take time..." | ||
) | ||
.unwrap(); | ||
match self.send_json_request::<()>("validate_chain", ¶ms) { | ||
Ok(_) => { | ||
if fast_validation { | ||
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 fast_validation = args.is_present("fast"); | ||
node_client.verify_chain(fast_validation); | ||
} | ||
("ban", Some(peer_args)) => { | ||
let peer = peer_args.value_of("peer").unwrap(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding Option parameters to multiple methods, isn't it preferable to add a new timeout member,
and a method to change it from its default value of 20secs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it a bit more cleaner but just adding a method in api/client.rs and trigger a change of timeout in function of the api method used in the request is a bit painful in the form it's built. If you have better idea, i'm open.
However these method are almost only used for cmd/client.rs