This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from consensus-shipyard/fix/netWorkerAddr
Support setValidatorNetAddr, setValidatorWorkerAddr, listValidators
- Loading branch information
Showing
13 changed files
with
8,157 additions
and
7,027 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2022-2023 Protocol Labs | ||
// SPDX-License-Identifier: MIT | ||
//! List subnet validators cli command | ||
|
||
use async_trait::async_trait; | ||
use clap::Args; | ||
use std::fmt::Debug; | ||
|
||
use crate::cli::commands::get_ipc_agent_url; | ||
use crate::cli::{CommandLineHandler, GlobalArguments}; | ||
use crate::config::json_rpc_methods; | ||
use crate::jsonrpc::{JsonRpcClient, JsonRpcClientImpl}; | ||
use crate::lotus::message::ipc::QueryValidatorSetResponse; | ||
use crate::server::query_validators::QueryValidatorSetParams; | ||
|
||
/// The command to create a new subnet actor. | ||
pub(crate) struct ListValidators; | ||
|
||
#[async_trait] | ||
impl CommandLineHandler for ListValidators { | ||
type Arguments = ListValidatorsArgs; | ||
|
||
async fn handle(global: &GlobalArguments, arguments: &Self::Arguments) -> anyhow::Result<()> { | ||
log::debug!("list validators with args: {:?}", arguments); | ||
|
||
let url = get_ipc_agent_url(&arguments.ipc_agent_url, global)?; | ||
let json_rpc_client = JsonRpcClientImpl::new(url, None); | ||
|
||
let params = QueryValidatorSetParams { | ||
subnet: arguments.subnet.clone(), | ||
}; | ||
|
||
let valset = json_rpc_client | ||
.request::<QueryValidatorSetResponse>( | ||
json_rpc_methods::QUERY_VALIDATOR_SET, | ||
serde_json::to_value(params)?, | ||
) | ||
.await?; | ||
|
||
log::info!("validators number: {}", valset.min_validators); | ||
log::info!("validator set: {:?}", valset.validator_set); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
#[command(name = "list-validators", about = "Show the validators of the subnet")] | ||
pub(crate) struct ListValidatorsArgs { | ||
#[arg(long, short, help = "The JSON RPC server url for ipc agent")] | ||
pub ipc_agent_url: Option<String>, | ||
#[arg(long, short, help = "The subnet id to query validators")] | ||
pub subnet: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2022-2023 Protocol Labs | ||
// SPDX-License-Identifier: MIT | ||
//! The command to set the validator worker address | ||
|
||
use crate::cli::commands::get_ipc_agent_url; | ||
use crate::cli::{CommandLineHandler, GlobalArguments}; | ||
use crate::config::json_rpc_methods; | ||
use crate::jsonrpc::{JsonRpcClient, JsonRpcClientImpl}; | ||
use crate::server::worker_addr::SetValidatorWorkerAddrParams; | ||
use async_trait::async_trait; | ||
use clap::Args; | ||
|
||
/// Setting the validator worker address | ||
pub(crate) struct SetValidatorWorkerAddr; | ||
|
||
#[async_trait] | ||
impl CommandLineHandler for SetValidatorWorkerAddr { | ||
type Arguments = SetValidatorWorkerAddrArgs; | ||
|
||
async fn handle(global: &GlobalArguments, arguments: &Self::Arguments) -> anyhow::Result<()> { | ||
log::debug!("set the validator worker addr args: {:?}", arguments); | ||
|
||
let url = get_ipc_agent_url(&arguments.ipc_agent_url, global)?; | ||
let json_rpc_client = JsonRpcClientImpl::new(url, None); | ||
|
||
let params = SetValidatorWorkerAddrParams { | ||
subnet: arguments.subnet.clone(), | ||
from: arguments.from.clone(), | ||
validator_worker_addr: arguments.validator_worker_addr.clone(), | ||
}; | ||
|
||
json_rpc_client | ||
.request::<()>( | ||
json_rpc_methods::SET_VALIDATOR_WORKER_ADDR, | ||
serde_json::to_value(params)?, | ||
) | ||
.await?; | ||
|
||
log::info!( | ||
"set the validator worker addr to: {:} in subnet: {:}", | ||
arguments.validator_worker_addr, | ||
arguments.subnet | ||
); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
#[command(about = "Set the validator worker address")] | ||
pub(crate) struct SetValidatorWorkerAddrArgs { | ||
#[arg(long, short, help = "The JSON RPC server url for ipc agent")] | ||
pub ipc_agent_url: Option<String>, | ||
#[arg(long, short, help = "Owner address of the validator being updated")] | ||
pub from: Option<String>, | ||
#[arg(long, short, help = "The subnet to set the validator")] | ||
pub subnet: String, | ||
#[arg(long, short, help = "New validator worker address")] | ||
pub validator_worker_addr: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2022-2023 Protocol Labs | ||
// SPDX-License-Identifier: MIT | ||
//! Set the subnet actor validator worker addr | ||
|
||
use crate::server::subnet::SubnetManagerPool; | ||
use crate::server::{check_subnet, parse_from, JsonRPCRequestHandler}; | ||
use anyhow::anyhow; | ||
use async_trait::async_trait; | ||
use fvm_shared::address::Address; | ||
use ipc_sdk::subnet_id::SubnetID; | ||
use serde::{Deserialize, Serialize}; | ||
use std::str::FromStr; | ||
use std::sync::Arc; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct SetValidatorWorkerAddrParams { | ||
pub subnet: String, | ||
pub from: Option<String>, | ||
pub validator_worker_addr: String, | ||
} | ||
|
||
/// Sets a new worker address to an existing validator | ||
pub(crate) struct SetValidatorWorkerAddrHandler { | ||
pool: Arc<SubnetManagerPool>, | ||
} | ||
|
||
impl SetValidatorWorkerAddrHandler { | ||
pub(crate) fn new(pool: Arc<SubnetManagerPool>) -> Self { | ||
Self { pool } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl JsonRPCRequestHandler for SetValidatorWorkerAddrHandler { | ||
type Request = SetValidatorWorkerAddrParams; | ||
type Response = (); | ||
|
||
async fn handle(&self, request: Self::Request) -> anyhow::Result<Self::Response> { | ||
let subnet = SubnetID::from_str(&request.subnet)?; | ||
let parent = subnet.parent().ok_or_else(|| anyhow!("no parent found"))?; | ||
let conn = match self.pool.get(&parent) { | ||
None => return Err(anyhow!("target parent subnet not found")), | ||
Some(conn) => conn, | ||
}; | ||
|
||
let subnet_config = conn.subnet(); | ||
check_subnet(subnet_config)?; | ||
|
||
let from = parse_from(subnet_config, request.from)?; | ||
|
||
let worker_addr = Address::from_str(&request.validator_worker_addr)?; | ||
|
||
conn.manager() | ||
.set_validator_worker_addr(subnet, from, worker_addr) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters