-
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 4 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 |
---|---|---|
|
@@ -80,17 +80,20 @@ impl Owner { | |
|
||
/// Trigger a validation of the chain state. | ||
/// | ||
/// # Arguments | ||
/// * `fast_validation` - if false verify the rangeproof associated with each unspent output and all kernels | ||
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. i'd prefer this is called something like assume_valid_rangeproofs_kernels, |
||
/// | ||
/// # Returns | ||
/// * Result Containing: | ||
/// * `Ok(())` if the validation was done successfully | ||
/// * or [`Error`](struct.Error.html) if an error is encountered. | ||
/// | ||
|
||
pub fn validate_chain(&self) -> Result<(), Error> { | ||
pub fn validate_chain(&self, fast_validation: bool) -> Result<(), Error> { | ||
let chain_validation_handler = ChainValidationHandler { | ||
chain: self.chain.clone(), | ||
}; | ||
chain_validation_handler.validate_chain() | ||
chain_validation_handler.validate_chain(fast_validation) | ||
} | ||
|
||
/// Trigger a compaction of the chain state to regain storage space. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,10 +45,20 @@ impl HTTPNodeClient { | |
method: &str, | ||
params: &serde_json::Value, | ||
) -> Result<D, Error> { | ||
let read_timeout: Option<u64> = match method { | ||
// 2hours | ||
"validate_chain" => Some(7200), | ||
// (default) 20sec | ||
_ => None, | ||
}; | ||
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, | ||
read_timeout, | ||
); | ||
|
||
match res { | ||
Err(e) => { | ||
|
@@ -149,6 +159,21 @@ impl HTTPNodeClient { | |
e.reset().unwrap(); | ||
} | ||
|
||
pub fn validate_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. how come this is a new method, rather than a changed method? 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. I don't really get what you mean here by a new or changed method? 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. I mean that it looks like you're adding a validate_chain method to HTTPNodeClient, 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. ah ok, will call it, 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. I don't object to the name. If it behaves identical to those others, then the same name is appropriate. But I just wondered, since I'm not very familiar with this code, why HTTPNodeClient didn't need such a method before and does now. |
||
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(_) => writeln!(e, "Successfully validated chain.").unwrap(), | ||
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. This output should reflect whether rangeproofs and kernels were validated. |
||
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 +216,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 = if args.is_present("fast") { false } else { true }; | ||
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. This is simply let fast_validation = !args.is_present("fast") |
||
node_client.validate_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