client invalidateheader and resetchainhead (#3618)
* wip - "reset_head" via owner api functionality * jsonrpc pass hash in as a string * sort of works * not a reorg if we simply accept several blocks at once * remember to reset header MMR separately as it is readonly when interacting with txhashset extension * basic client integration needs error handling etc. * reset sync status when reset chain head * track "denylist" (todo) and validate headers against this via the ctx * track denylist (header hashes) in chain itself * header denylist in play * expose invalidateheader as client cmd * rework reset_chain_head - rewind txhashset then header MMR
This commit is contained in:
@@ -129,6 +129,26 @@ impl HTTPNodeClient {
|
||||
e.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn reset_chain_head(&self, hash: String) {
|
||||
let mut e = term::stdout().unwrap();
|
||||
let params = json!([hash]);
|
||||
match self.send_json_request::<()>("reset_chain_head", ¶ms) {
|
||||
Ok(_) => writeln!(e, "Successfully reset chain head {}", hash).unwrap(),
|
||||
Err(_) => writeln!(e, "Failed to reset chain head {}", hash).unwrap(),
|
||||
}
|
||||
e.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn invalidate_header(&self, hash: String) {
|
||||
let mut e = term::stdout().unwrap();
|
||||
let params = json!([hash]);
|
||||
match self.send_json_request::<()>("invalidate_header", ¶ms) {
|
||||
Ok(_) => writeln!(e, "Successfully invalidated header: {}", hash).unwrap(),
|
||||
Err(_) => writeln!(e, "Failed to invalidate header: {}", hash).unwrap(),
|
||||
}
|
||||
e.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn ban_peer(&self, peer_addr: &SocketAddr) {
|
||||
let mut e = term::stdout().unwrap();
|
||||
let params = json!([peer_addr]);
|
||||
@@ -163,6 +183,14 @@ pub fn client_command(client_args: &ArgMatches<'_>, global_config: GlobalConfig)
|
||||
("listconnectedpeers", Some(_)) => {
|
||||
node_client.list_connected_peers();
|
||||
}
|
||||
("resetchainhead", Some(args)) => {
|
||||
let hash = args.value_of("hash").unwrap();
|
||||
node_client.reset_chain_head(hash.to_string());
|
||||
}
|
||||
("invalidateheader", Some(args)) => {
|
||||
let hash = args.value_of("hash").unwrap();
|
||||
node_client.invalidate_header(hash.to_string());
|
||||
}
|
||||
("ban", Some(peer_args)) => {
|
||||
let peer = peer_args.value_of("peer").unwrap();
|
||||
|
||||
|
||||
@@ -72,3 +72,15 @@ subcommands:
|
||||
long: peer
|
||||
required: true
|
||||
takes_value: true
|
||||
- resetchainhead:
|
||||
about: Resets the local chain head
|
||||
args:
|
||||
- hash:
|
||||
help: The header hash to reset to
|
||||
required: true
|
||||
- invalidateheader:
|
||||
about: Adds header hash to denylist
|
||||
args:
|
||||
- hash:
|
||||
help: The header hash to invalidate
|
||||
required: true
|
||||
Reference in New Issue
Block a user