From 779b9df2c2c3622e4ec1be943ceddf6ecf54707a Mon Sep 17 00:00:00 2001 From: cryptoAtwill Date: Tue, 28 Mar 2023 17:25:40 +0800 Subject: [PATCH 1/6] update config --- config/template.toml | 8 +++- src/config/deserialize.rs | 46 ++++++++++++++++++++- src/config/mod.rs | 15 ++++--- src/config/subnet.rs | 8 +++- src/config/tests.rs | 42 +++++++++++++------ src/manager/checkpoint.rs | 8 +--- src/server/handlers/manager/create.rs | 7 ++-- src/server/handlers/manager/fund.rs | 3 +- src/server/handlers/manager/join.rs | 3 +- src/server/handlers/manager/kill.rs | 4 +- src/server/handlers/manager/leave.rs | 4 +- src/server/handlers/manager/list_subnets.rs | 4 +- src/server/handlers/manager/propagate.rs | 3 +- src/server/handlers/manager/release.rs | 5 +-- src/server/handlers/manager/send_value.rs | 4 +- src/server/handlers/manager/subnet.rs | 5 ++- src/server/handlers/manager/wallet.rs | 4 +- src/server/handlers/manager/whitelist.rs | 4 +- src/server/handlers/validator.rs | 4 +- 19 files changed, 124 insertions(+), 57 deletions(-) diff --git a/config/template.toml b/config/template.toml index 79bfc624..a04f8112 100644 --- a/config/template.toml +++ b/config/template.toml @@ -3,14 +3,18 @@ json_rpc_address = "127.0.0.1:3030" [subnets] -[subnets.root] +[[subnets]] id = "/root" +network_name = "root" +gateway_addr = 64 jsonrpc_api_http = "https://example.org/rpc/v0" jsonrpc_api_ws = "wss://example.org/rpc/v0" auth_token = "YOUR ROOT AUTH TOKEN" -[subnets.child] +[[subnets]] id = "/root/t0100" +network_name = "child" +gateway_addr = 64 jsonrpc_api_http = "https://example.org/rpc/v2" auth_token = "YOUR CHILD AUTH TOKEN" accounts = ["t3thgjtvoi65yzdcoifgqh6utjbaod3ukidxrx34heu34d6avx6z7r5766t5jqt42a44ehzcnw3u5ehz47n42a"] \ No newline at end of file diff --git a/src/config/deserialize.rs b/src/config/deserialize.rs index b9b7e873..56428f1f 100644 --- a/src/config/deserialize.rs +++ b/src/config/deserialize.rs @@ -2,13 +2,57 @@ // SPDX-License-Identifier: MIT //! Deserialization utils for config mod. +use crate::config::Subnet; use fvm_shared::address::Address; use ipc_sdk::subnet_id::SubnetID; use serde::de::{Error, SeqAccess}; -use serde::Deserializer; +use serde::{Deserialize, Deserializer}; +use std::collections::HashMap; use std::fmt::Formatter; use std::str::FromStr; +/// A serde deserialization method to deserialize a hashmap of subnets with subnet id as key and +/// Subnet struct as value from a vec of subnets +pub(crate) fn deserialize_subnets_from_vec<'de, D>( + deserializer: D, +) -> anyhow::Result, D::Error> +where + D: Deserializer<'de>, +{ + let subnets = >::deserialize(deserializer)?; + + let mut hashmap = HashMap::new(); + for subnet in subnets { + hashmap.insert(subnet.id.clone(), subnet); + } + Ok(hashmap) +} + +/// A serde deserialization method to deserialize an address from i64 +pub(crate) fn deserialize_address_from_i64<'de, D>( + deserializer: D, +) -> anyhow::Result +where + D: Deserializer<'de>, +{ + struct Visitor; + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = Address; + + fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result { + formatter.write_str("an u64") + } + + fn visit_i64(self, v: i64) -> Result + where + E: Error, + { + Ok(Address::new_id(v as u64)) + } + } + deserializer.deserialize_i64(Visitor) +} + /// A serde deserialization method to deserialize a subnet path string into a [`SubnetID`]. pub(crate) fn deserialize_subnet_id<'de, D>(deserializer: D) -> anyhow::Result where diff --git a/src/config/mod.rs b/src/config/mod.rs index 01601e7e..6abd258f 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -18,6 +18,8 @@ use std::fs; use std::path::Path; use anyhow::Result; +use ipc_sdk::subnet_id::SubnetID; +use deserialize::deserialize_subnets_from_vec; pub use reload::ReloadableConfig; use serde::Deserialize; pub use server::JSON_RPC_ENDPOINT; @@ -32,17 +34,19 @@ pub const DEFAULT_CONFIG_TEMPLATE: &str = r#" [server] json_rpc_address = "127.0.0.1:3030" -[subnets] - -[subnets."/root"] +[[subnets]] id = "/root" +gateway_addr = 64 +network_name = "root" jsonrpc_api_http = "http://127.0.0.1:1235/rpc/v1" jsonrpc_api_ws = "wss://example.org/rpc/v0" auth_token = "YOUR TOKEN" accounts = ["t01"] -[subnets."/root/t01"] +[[subnets]] id = "/root/t01" +gateway_addr = 64 +network_name = "child" jsonrpc_api_http = "http://127.0.0.1:1235/rpc/v1" auth_token = "YOUR TOKEN" accounts = ["t01"] @@ -53,7 +57,8 @@ accounts = ["t01"] #[derive(Deserialize, Debug)] pub struct Config { pub server: Server, - pub subnets: HashMap, + #[serde(deserialize_with = "deserialize_subnets_from_vec")] + pub subnets: HashMap, } impl Config { diff --git a/src/config/subnet.rs b/src/config/subnet.rs index 3bdc5a82..b212831d 100644 --- a/src/config/subnet.rs +++ b/src/config/subnet.rs @@ -5,13 +5,19 @@ use ipc_sdk::subnet_id::SubnetID; use serde::Deserialize; use url::Url; -use crate::config::deserialize::{deserialize_accounts, deserialize_subnet_id}; +use crate::config::deserialize::{ + deserialize_accounts, deserialize_address_from_i64, deserialize_subnet_id +}; /// Represents a subnet declaration in the config. #[derive(Deserialize, Clone, Debug)] pub struct Subnet { #[serde(deserialize_with = "deserialize_subnet_id")] pub id: SubnetID, + #[serde(deserialize_with = "deserialize_address_from_i64")] + // toml is interpreting number as i64 + pub gateway_addr: Address, + pub network_name: String, pub jsonrpc_api_http: Url, pub jsonrpc_api_ws: Option, pub auth_token: Option, diff --git a/src/config/tests.rs b/src/config/tests.rs index 8058cb42..ed9b59bb 100644 --- a/src/config/tests.rs +++ b/src/config/tests.rs @@ -17,6 +17,7 @@ use crate::config::{Config, ReloadableConfig}; const SERVER_JSON_RPC_ADDR: &str = "127.0.0.1:3030"; const ROOT_ID: &str = "/root"; const CHILD_ID: &str = "/root/t0100"; +const GATEWAY_ADDR: u64 = 64; const ROOT_AUTH_TOKEN: &str = "ROOT_AUTH_TOKEN"; const CHILD_AUTH_TOKEN: &str = "CHILD_AUTH_TOKEN"; const JSONRPC_API_HTTP: &str = "https://example.org/rpc/v0"; @@ -96,8 +97,10 @@ fn check_server_config() { fn check_subnets_config() { let config = read_config().subnets; - let root = &config["root"]; + let root = &config[&ROOTNET_ID]; assert_eq!(root.id, *ROOTNET_ID); + assert_eq!(root.network_name, "root"); + assert_eq!(root.gateway_addr, Address::new_id(GATEWAY_ADDR)); assert_eq!( root.jsonrpc_api_http, Url::from_str(JSONRPC_API_HTTP).unwrap() @@ -108,8 +111,11 @@ fn check_subnets_config() { ); assert_eq!(root.auth_token.as_ref().unwrap(), ROOT_AUTH_TOKEN); - let child = &config["child"]; - assert_eq!(child.id, SubnetID::from_str(CHILD_ID).unwrap(),); + let child_id = SubnetID::from_str(CHILD_ID).unwrap(); + let child = &config[&child_id]; + assert_eq!(child.id, child_id); + assert_eq!(child.network_name, "child"); + assert_eq!(child.gateway_addr, Address::new_id(GATEWAY_ADDR)); assert_eq!( child.jsonrpc_api_http, Url::from_str(JSONRPC_API_HTTP).unwrap(), @@ -127,14 +133,18 @@ fn config_str() -> String { [server] json_rpc_address = "{SERVER_JSON_RPC_ADDR}" - [subnets] - [subnets.root] + [[subnets]] id = "{ROOT_ID}" + gateway_addr = {GATEWAY_ADDR} + network_name = "root" jsonrpc_api_http = "{JSONRPC_API_HTTP}" jsonrpc_api_ws = "{JSONRPC_API_WS}" auth_token = "{ROOT_AUTH_TOKEN}" - [subnets.child] + + [[subnets]] id = "{CHILD_ID}" + network_name = "child" + gateway_addr = {GATEWAY_ADDR} jsonrpc_api_http = "{JSONRPC_API_HTTP}" auth_token = "{CHILD_AUTH_TOKEN}" accounts = ["{ACCOUNT_ADDRESS}"] @@ -148,14 +158,18 @@ fn config_str_diff_addr() -> String { [server] json_rpc_address = "127.0.0.1:3031" - [subnets] - [subnets.root] + [[subnets]] id = "{ROOT_ID}" + network_name = "root" + gateway_addr = {GATEWAY_ADDR} jsonrpc_api_http = "{JSONRPC_API_HTTP}" jsonrpc_api_ws = "{JSONRPC_API_WS}" auth_token = "{ROOT_AUTH_TOKEN}" - [subnets.child] + + [[subnets]] id = "{CHILD_ID}" + network_name = "child" + gateway_addr = {GATEWAY_ADDR} jsonrpc_api_http = "{JSONRPC_API_HTTP}" auth_token = "{CHILD_AUTH_TOKEN}" accounts = ["{ACCOUNT_ADDRESS}"] @@ -169,16 +183,18 @@ fn read_config() -> Config { [server] json_rpc_address = "{SERVER_JSON_RPC_ADDR}" - [subnets] - - [subnets.root] + [[subnets]] id = "{ROOT_ID}" + network_name = "root" + gateway_addr = {GATEWAY_ADDR} jsonrpc_api_http = "{JSONRPC_API_HTTP}" jsonrpc_api_ws = "{JSONRPC_API_WS}" auth_token = "{ROOT_AUTH_TOKEN}" - [subnets.child] + [[subnets]] id = "{CHILD_ID}" + network_name = "child" + gateway_addr = {GATEWAY_ADDR} jsonrpc_api_http = "{JSONRPC_API_HTTP}" auth_token = "{CHILD_AUTH_TOKEN}" accounts = ["{ACCOUNT_ADDRESS}"] diff --git a/src/manager/checkpoint.rs b/src/manager/checkpoint.rs index c02dda84..513c47e2 100644 --- a/src/manager/checkpoint.rs +++ b/src/manager/checkpoint.rs @@ -123,13 +123,7 @@ impl IntoSubsystem for CheckpointSubsystem { /// manage checkpoint for. This means that for each `child_subnet` there exists at least one account /// for which we need to submit checkpoints on behalf of to `parent_subnet`, which must also be /// present in the map. -fn subnets_to_manage(subnets: &HashMap) -> Vec<(Subnet, Subnet)> { - // First, we remap subnets by SubnetID. - let subnets_by_id: HashMap = subnets - .values() - .map(|s| (s.id.clone(), s.clone())) - .collect(); - +fn subnets_to_manage(subnets_by_id: &HashMap) -> Vec<(Subnet, Subnet)> { // Then, we filter for subnets that have at least one account and for which the parent subnet // is also in the map, and map into a Vec of (child_subnet, parent_subnet) tuples. subnets_by_id diff --git a/src/server/handlers/manager/create.rs b/src/server/handlers/manager/create.rs index 2f19ffea..25a0cdb4 100644 --- a/src/server/handlers/manager/create.rs +++ b/src/server/handlers/manager/create.rs @@ -51,15 +51,14 @@ impl JsonRPCRequestHandler for CreateSubnetHandler { type Response = CreateSubnetResponse; async fn handle(&self, request: Self::Request) -> anyhow::Result { - let parent = &request.parent; - - let conn = match self.pool.get(parent) { + let parent = SubnetID::from_str(&request.parent)?; + let conn = match self.pool.get(&parent) { None => return Err(anyhow!("target parent subnet not found")), Some(conn) => conn, }; let constructor_params = ConstructParams { - parent: SubnetID::from_str(parent)?, + parent, name: request.name, ipc_gateway_addr: DEFAULT_IPC_GATEWAY_ADDR, consensus: ConsensusType::Mir, diff --git a/src/server/handlers/manager/fund.rs b/src/server/handlers/manager/fund.rs index 93615874..f0f7c342 100644 --- a/src/server/handlers/manager/fund.rs +++ b/src/server/handlers/manager/fund.rs @@ -40,8 +40,7 @@ impl JsonRPCRequestHandler for FundHandler { let subnet = SubnetID::from_str(&request.subnet)?; let parent = subnet .parent() - .ok_or_else(|| anyhow!("no parent found"))? - .to_string(); + .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, diff --git a/src/server/handlers/manager/join.rs b/src/server/handlers/manager/join.rs index f3b17f91..f776edda 100644 --- a/src/server/handlers/manager/join.rs +++ b/src/server/handlers/manager/join.rs @@ -43,8 +43,7 @@ impl JsonRPCRequestHandler for JoinSubnetHandler { let subnet = SubnetID::from_str(&request.subnet)?; let parent = subnet .parent() - .ok_or_else(|| anyhow!("no parent found"))? - .to_string(); + .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, diff --git a/src/server/handlers/manager/kill.rs b/src/server/handlers/manager/kill.rs index 05896307..91a7b5e5 100644 --- a/src/server/handlers/manager/kill.rs +++ b/src/server/handlers/manager/kill.rs @@ -39,9 +39,7 @@ impl JsonRPCRequestHandler for KillSubnetHandler { let subnet = SubnetID::from_str(&request.subnet)?; let parent = subnet .parent() - .ok_or_else(|| anyhow!("no parent found"))? - .to_string(); - + .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, diff --git a/src/server/handlers/manager/leave.rs b/src/server/handlers/manager/leave.rs index 21818254..5f3a82ca 100644 --- a/src/server/handlers/manager/leave.rs +++ b/src/server/handlers/manager/leave.rs @@ -39,9 +39,7 @@ impl JsonRPCRequestHandler for LeaveSubnetHandler { let subnet = SubnetID::from_str(&request.subnet)?; let parent = subnet .parent() - .ok_or_else(|| anyhow!("no parent found"))? - .to_string(); - + .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, diff --git a/src/server/handlers/manager/list_subnets.rs b/src/server/handlers/manager/list_subnets.rs index 7eb6fcd8..f60fc22d 100644 --- a/src/server/handlers/manager/list_subnets.rs +++ b/src/server/handlers/manager/list_subnets.rs @@ -14,6 +14,7 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::str::FromStr; use std::sync::Arc; +use ipc_sdk::subnet_id::SubnetID; #[derive(Debug, Serialize, Deserialize)] pub struct ListSubnetsParams { @@ -38,7 +39,8 @@ impl JsonRPCRequestHandler for ListSubnetsHandler { type Response = HashMap; async fn handle(&self, request: Self::Request) -> anyhow::Result { - let conn = match self.pool.get(&request.subnet_id) { + let subnet = SubnetID::from_str(&request.subnet_id)?; + let conn = match self.pool.get(&subnet) { None => return Err(anyhow!("target parent subnet not found")), Some(conn) => conn, }; diff --git a/src/server/handlers/manager/propagate.rs b/src/server/handlers/manager/propagate.rs index d0bfedd8..5d3db44d 100644 --- a/src/server/handlers/manager/propagate.rs +++ b/src/server/handlers/manager/propagate.rs @@ -37,7 +37,8 @@ impl JsonRPCRequestHandler for PropagateHandler { type Response = (); async fn handle(&self, request: Self::Request) -> anyhow::Result { - let conn = match self.pool.get(&request.subnet) { + let subnet = SubnetID::from_str(&request.subnet)?; + let conn = match self.pool.get(&subnet) { None => return Err(anyhow!("target subnet not found")), Some(conn) => conn, }; diff --git a/src/server/handlers/manager/release.rs b/src/server/handlers/manager/release.rs index caa81b15..5a865491 100644 --- a/src/server/handlers/manager/release.rs +++ b/src/server/handlers/manager/release.rs @@ -37,7 +37,8 @@ impl JsonRPCRequestHandler for ReleaseHandler { type Response = (); async fn handle(&self, request: Self::Request) -> anyhow::Result { - let conn = match self.pool.get(&request.subnet) { + let subnet = SubnetID::from_str(&request.subnet)?; + let conn = match self.pool.get(&subnet) { None => return Err(anyhow!("target subnet not found")), Some(conn) => conn, }; @@ -45,9 +46,7 @@ impl JsonRPCRequestHandler for ReleaseHandler { let subnet_config = conn.subnet(); check_subnet(subnet_config)?; - let subnet = SubnetID::from_str(&request.subnet)?; let amount = TokenAmount::from_whole(request.amount); - let from = parse_from(subnet_config, request.from)?; conn.manager().release(subnet, from, amount).await diff --git a/src/server/handlers/manager/send_value.rs b/src/server/handlers/manager/send_value.rs index d2a3cfd6..0a8fe758 100644 --- a/src/server/handlers/manager/send_value.rs +++ b/src/server/handlers/manager/send_value.rs @@ -13,6 +13,7 @@ use fvm_shared::econ::TokenAmount; use serde::{Deserialize, Serialize}; use std::str::FromStr; use std::sync::Arc; +use ipc_sdk::subnet_id::SubnetID; #[derive(Debug, Serialize, Deserialize)] pub struct SendValueParams { @@ -39,7 +40,8 @@ impl JsonRPCRequestHandler for SendValueHandler { type Response = (); async fn handle(&self, request: Self::Request) -> anyhow::Result { - let conn = match self.pool.get(&request.subnet) { + let subnet = SubnetID::from_str(&request.subnet)?; + let conn = match self.pool.get(&subnet) { None => return Err(anyhow!("target parent subnet not found")), Some(conn) => conn, }; diff --git a/src/server/handlers/manager/subnet.rs b/src/server/handlers/manager/subnet.rs index 783e1e1b..aae76ee6 100644 --- a/src/server/handlers/manager/subnet.rs +++ b/src/server/handlers/manager/subnet.rs @@ -6,6 +6,7 @@ use crate::config::{ReloadableConfig, Subnet}; use crate::jsonrpc::{JsonRpcClient, JsonRpcClientImpl}; use crate::manager::LotusSubnetManager; use std::sync::Arc; +use ipc_sdk::subnet_id::SubnetID; /// The subnet manager connection that holds the subnet config and the manager instance. pub struct Connection { @@ -37,11 +38,11 @@ impl SubnetManagerPool { } /// Get the connection instance for the subnet. - pub fn get(&self, subnet_str: &str) -> Option> { + pub fn get(&self, subnet: &SubnetID) -> Option> { let config = self.config.get_config(); let subnets = &config.subnets; - match subnets.get(subnet_str) { + match subnets.get(subnet) { Some(subnet) => { let manager = LotusSubnetManager::from_subnet(subnet); Some(Connection { diff --git a/src/server/handlers/manager/wallet.rs b/src/server/handlers/manager/wallet.rs index e72ce7a7..cc7fabf8 100644 --- a/src/server/handlers/manager/wallet.rs +++ b/src/server/handlers/manager/wallet.rs @@ -11,6 +11,7 @@ use async_trait::async_trait; use serde::{Deserialize, Serialize}; use std::str::FromStr; use std::sync::Arc; +use ipc_sdk::subnet_id::SubnetID; #[derive(Debug, Serialize, Deserialize)] pub struct WalletNewParams { @@ -40,7 +41,8 @@ impl JsonRPCRequestHandler for WalletNewHandler { type Response = WalletNewResponse; async fn handle(&self, request: Self::Request) -> anyhow::Result { - let conn = match self.pool.get(&request.subnet) { + let subnet = SubnetID::from_str(&request.subnet)?; + let conn = match self.pool.get(&subnet) { None => return Err(anyhow!("target subnet not found")), Some(conn) => conn, }; diff --git a/src/server/handlers/manager/whitelist.rs b/src/server/handlers/manager/whitelist.rs index 58fad0a4..2b5099ad 100644 --- a/src/server/handlers/manager/whitelist.rs +++ b/src/server/handlers/manager/whitelist.rs @@ -39,7 +39,8 @@ impl JsonRPCRequestHandler for WhitelistPropagatorHandler { type Response = (); async fn handle(&self, request: Self::Request) -> anyhow::Result { - let conn = match self.pool.get(&request.subnet) { + let subnet = SubnetID::from_str(&request.subnet)?; + let conn = match self.pool.get(&subnet) { None => return Err(anyhow!("target subnet not found")), Some(conn) => conn, }; @@ -47,7 +48,6 @@ impl JsonRPCRequestHandler for WhitelistPropagatorHandler { let subnet_config = conn.subnet(); check_subnet(subnet_config)?; - let subnet = SubnetID::from_str(&request.subnet)?; let to_add = request .to_add .iter() diff --git a/src/server/handlers/validator.rs b/src/server/handlers/validator.rs index 9f091cc0..6e9f1b50 100644 --- a/src/server/handlers/validator.rs +++ b/src/server/handlers/validator.rs @@ -46,11 +46,9 @@ impl JsonRPCRequestHandler for QueryValidatorSetHandler { let subnet_id = SubnetID::from_str(&request.subnet)?; let parent = subnet_id .parent() - .ok_or_else(|| anyhow!("cannot get for root"))? - .to_string(); + .ok_or_else(|| anyhow!("cannot get for root"))?; let config = self.config.get_config(); - // TODO: once get_by_subnet_id is merged, will use parent subnet id directly. let subnet = match config.subnets.get(&parent) { None => return Err(anyhow!("target parent subnet not found")), Some(s) => s, From 2017fe4763669cc3c7b223df3922456a03c6ab82 Mon Sep 17 00:00:00 2001 From: cryptoAtwill Date: Tue, 28 Mar 2023 17:40:15 +0800 Subject: [PATCH 2/6] format code --- src/config/mod.rs | 2 +- src/config/subnet.rs | 2 +- src/server/handlers/manager/fund.rs | 4 +--- src/server/handlers/manager/join.rs | 4 +--- src/server/handlers/manager/kill.rs | 4 +--- src/server/handlers/manager/leave.rs | 4 +--- src/server/handlers/manager/list_subnets.rs | 2 +- src/server/handlers/manager/send_value.rs | 2 +- src/server/handlers/manager/subnet.rs | 2 +- src/server/handlers/manager/wallet.rs | 2 +- 10 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 6abd258f..36e20d23 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -18,8 +18,8 @@ use std::fs; use std::path::Path; use anyhow::Result; -use ipc_sdk::subnet_id::SubnetID; use deserialize::deserialize_subnets_from_vec; +use ipc_sdk::subnet_id::SubnetID; pub use reload::ReloadableConfig; use serde::Deserialize; pub use server::JSON_RPC_ENDPOINT; diff --git a/src/config/subnet.rs b/src/config/subnet.rs index b212831d..adbbaa1b 100644 --- a/src/config/subnet.rs +++ b/src/config/subnet.rs @@ -6,7 +6,7 @@ use serde::Deserialize; use url::Url; use crate::config::deserialize::{ - deserialize_accounts, deserialize_address_from_i64, deserialize_subnet_id + deserialize_accounts, deserialize_address_from_i64, deserialize_subnet_id, }; /// Represents a subnet declaration in the config. diff --git a/src/server/handlers/manager/fund.rs b/src/server/handlers/manager/fund.rs index f0f7c342..d085bc36 100644 --- a/src/server/handlers/manager/fund.rs +++ b/src/server/handlers/manager/fund.rs @@ -38,9 +38,7 @@ impl JsonRPCRequestHandler for FundHandler { async fn handle(&self, request: Self::Request) -> anyhow::Result { let subnet = SubnetID::from_str(&request.subnet)?; - let parent = subnet - .parent() - .ok_or_else(|| anyhow!("no parent found"))?; + 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, diff --git a/src/server/handlers/manager/join.rs b/src/server/handlers/manager/join.rs index f776edda..29756939 100644 --- a/src/server/handlers/manager/join.rs +++ b/src/server/handlers/manager/join.rs @@ -41,9 +41,7 @@ impl JsonRPCRequestHandler for JoinSubnetHandler { async fn handle(&self, request: Self::Request) -> anyhow::Result { let subnet = SubnetID::from_str(&request.subnet)?; - let parent = subnet - .parent() - .ok_or_else(|| anyhow!("no parent found"))?; + 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, diff --git a/src/server/handlers/manager/kill.rs b/src/server/handlers/manager/kill.rs index 91a7b5e5..e4696438 100644 --- a/src/server/handlers/manager/kill.rs +++ b/src/server/handlers/manager/kill.rs @@ -37,9 +37,7 @@ impl JsonRPCRequestHandler for KillSubnetHandler { async fn handle(&self, request: Self::Request) -> anyhow::Result { let subnet = SubnetID::from_str(&request.subnet)?; - let parent = subnet - .parent() - .ok_or_else(|| anyhow!("no parent found"))?; + 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, diff --git a/src/server/handlers/manager/leave.rs b/src/server/handlers/manager/leave.rs index 5f3a82ca..314f5947 100644 --- a/src/server/handlers/manager/leave.rs +++ b/src/server/handlers/manager/leave.rs @@ -37,9 +37,7 @@ impl JsonRPCRequestHandler for LeaveSubnetHandler { async fn handle(&self, request: Self::Request) -> anyhow::Result { let subnet = SubnetID::from_str(&request.subnet)?; - let parent = subnet - .parent() - .ok_or_else(|| anyhow!("no parent found"))?; + 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, diff --git a/src/server/handlers/manager/list_subnets.rs b/src/server/handlers/manager/list_subnets.rs index f60fc22d..e4f88c41 100644 --- a/src/server/handlers/manager/list_subnets.rs +++ b/src/server/handlers/manager/list_subnets.rs @@ -10,11 +10,11 @@ use crate::server::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::collections::HashMap; use std::str::FromStr; use std::sync::Arc; -use ipc_sdk::subnet_id::SubnetID; #[derive(Debug, Serialize, Deserialize)] pub struct ListSubnetsParams { diff --git a/src/server/handlers/manager/send_value.rs b/src/server/handlers/manager/send_value.rs index 0a8fe758..215f831d 100644 --- a/src/server/handlers/manager/send_value.rs +++ b/src/server/handlers/manager/send_value.rs @@ -10,10 +10,10 @@ use anyhow::anyhow; use async_trait::async_trait; use fvm_shared::address::Address; use fvm_shared::econ::TokenAmount; +use ipc_sdk::subnet_id::SubnetID; use serde::{Deserialize, Serialize}; use std::str::FromStr; use std::sync::Arc; -use ipc_sdk::subnet_id::SubnetID; #[derive(Debug, Serialize, Deserialize)] pub struct SendValueParams { diff --git a/src/server/handlers/manager/subnet.rs b/src/server/handlers/manager/subnet.rs index aae76ee6..e04cfdc5 100644 --- a/src/server/handlers/manager/subnet.rs +++ b/src/server/handlers/manager/subnet.rs @@ -5,8 +5,8 @@ use crate::config::{ReloadableConfig, Subnet}; use crate::jsonrpc::{JsonRpcClient, JsonRpcClientImpl}; use crate::manager::LotusSubnetManager; -use std::sync::Arc; use ipc_sdk::subnet_id::SubnetID; +use std::sync::Arc; /// The subnet manager connection that holds the subnet config and the manager instance. pub struct Connection { diff --git a/src/server/handlers/manager/wallet.rs b/src/server/handlers/manager/wallet.rs index cc7fabf8..eb727fa7 100644 --- a/src/server/handlers/manager/wallet.rs +++ b/src/server/handlers/manager/wallet.rs @@ -8,10 +8,10 @@ use crate::server::handlers::manager::subnet::SubnetManagerPool; use crate::server::JsonRPCRequestHandler; use anyhow::anyhow; use async_trait::async_trait; +use ipc_sdk::subnet_id::SubnetID; use serde::{Deserialize, Serialize}; use std::str::FromStr; use std::sync::Arc; -use ipc_sdk::subnet_id::SubnetID; #[derive(Debug, Serialize, Deserialize)] pub struct WalletNewParams { From 6b81b9f2646c7567591c7fd8266bb25084faa410 Mon Sep 17 00:00:00 2001 From: cryptoAtwill <108330426+cryptoAtwill@users.noreply.github.com> Date: Tue, 28 Mar 2023 22:17:40 +0800 Subject: [PATCH 3/6] Update checkpoint.rs --- src/manager/checkpoint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manager/checkpoint.rs b/src/manager/checkpoint.rs index 513c47e2..23e638b1 100644 --- a/src/manager/checkpoint.rs +++ b/src/manager/checkpoint.rs @@ -124,7 +124,7 @@ impl IntoSubsystem for CheckpointSubsystem { /// for which we need to submit checkpoints on behalf of to `parent_subnet`, which must also be /// present in the map. fn subnets_to_manage(subnets_by_id: &HashMap) -> Vec<(Subnet, Subnet)> { - // Then, we filter for subnets that have at least one account and for which the parent subnet + // We filter for subnets that have at least one account and for which the parent subnet // is also in the map, and map into a Vec of (child_subnet, parent_subnet) tuples. subnets_by_id .values() From 5e37680bd624211c114767dfa1275066571dad79 Mon Sep 17 00:00:00 2001 From: cryptoAtwill Date: Wed, 29 Mar 2023 20:17:30 +0800 Subject: [PATCH 4/6] use addr instead of id --- config/template.toml | 4 ++-- src/config/deserialize.rs | 10 +++++----- src/config/mod.rs | 4 ++-- src/config/subnet.rs | 4 ++-- src/config/tests.rs | 18 +++++++++--------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/config/template.toml b/config/template.toml index a04f8112..4470582a 100644 --- a/config/template.toml +++ b/config/template.toml @@ -6,7 +6,7 @@ json_rpc_address = "127.0.0.1:3030" [[subnets]] id = "/root" network_name = "root" -gateway_addr = 64 +gateway_addr = "t064" jsonrpc_api_http = "https://example.org/rpc/v0" jsonrpc_api_ws = "wss://example.org/rpc/v0" auth_token = "YOUR ROOT AUTH TOKEN" @@ -14,7 +14,7 @@ auth_token = "YOUR ROOT AUTH TOKEN" [[subnets]] id = "/root/t0100" network_name = "child" -gateway_addr = 64 +gateway_addr = "t064" jsonrpc_api_http = "https://example.org/rpc/v2" auth_token = "YOUR CHILD AUTH TOKEN" accounts = ["t3thgjtvoi65yzdcoifgqh6utjbaod3ukidxrx34heu34d6avx6z7r5766t5jqt42a44ehzcnw3u5ehz47n42a"] \ No newline at end of file diff --git a/src/config/deserialize.rs b/src/config/deserialize.rs index 56428f1f..5dab1380 100644 --- a/src/config/deserialize.rs +++ b/src/config/deserialize.rs @@ -29,7 +29,7 @@ where } /// A serde deserialization method to deserialize an address from i64 -pub(crate) fn deserialize_address_from_i64<'de, D>( +pub(crate) fn deserialize_address_from_str<'de, D>( deserializer: D, ) -> anyhow::Result where @@ -40,17 +40,17 @@ where type Value = Address; fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result { - formatter.write_str("an u64") + formatter.write_str("an string") } - fn visit_i64(self, v: i64) -> Result + fn visit_str(self, v: &str) -> Result where E: Error, { - Ok(Address::new_id(v as u64)) + Address::from_str(v).map_err(E::custom) } } - deserializer.deserialize_i64(Visitor) + deserializer.deserialize_str(Visitor) } /// A serde deserialization method to deserialize a subnet path string into a [`SubnetID`]. diff --git a/src/config/mod.rs b/src/config/mod.rs index 36e20d23..3b084b9e 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -36,7 +36,7 @@ json_rpc_address = "127.0.0.1:3030" [[subnets]] id = "/root" -gateway_addr = 64 +gateway_addr = "t064" network_name = "root" jsonrpc_api_http = "http://127.0.0.1:1235/rpc/v1" jsonrpc_api_ws = "wss://example.org/rpc/v0" @@ -45,7 +45,7 @@ accounts = ["t01"] [[subnets]] id = "/root/t01" -gateway_addr = 64 +gateway_addr = "t064" network_name = "child" jsonrpc_api_http = "http://127.0.0.1:1235/rpc/v1" auth_token = "YOUR TOKEN" diff --git a/src/config/subnet.rs b/src/config/subnet.rs index adbbaa1b..eeb2c480 100644 --- a/src/config/subnet.rs +++ b/src/config/subnet.rs @@ -6,7 +6,7 @@ use serde::Deserialize; use url::Url; use crate::config::deserialize::{ - deserialize_accounts, deserialize_address_from_i64, deserialize_subnet_id, + deserialize_accounts, deserialize_address_from_str, deserialize_subnet_id, }; /// Represents a subnet declaration in the config. @@ -14,7 +14,7 @@ use crate::config::deserialize::{ pub struct Subnet { #[serde(deserialize_with = "deserialize_subnet_id")] pub id: SubnetID, - #[serde(deserialize_with = "deserialize_address_from_i64")] + #[serde(deserialize_with = "deserialize_address_from_str")] // toml is interpreting number as i64 pub gateway_addr: Address, pub network_name: String, diff --git a/src/config/tests.rs b/src/config/tests.rs index ed9b59bb..99814615 100644 --- a/src/config/tests.rs +++ b/src/config/tests.rs @@ -17,7 +17,7 @@ use crate::config::{Config, ReloadableConfig}; const SERVER_JSON_RPC_ADDR: &str = "127.0.0.1:3030"; const ROOT_ID: &str = "/root"; const CHILD_ID: &str = "/root/t0100"; -const GATEWAY_ADDR: u64 = 64; +const GATEWAY_ADDR: &str = "t064"; const ROOT_AUTH_TOKEN: &str = "ROOT_AUTH_TOKEN"; const CHILD_AUTH_TOKEN: &str = "CHILD_AUTH_TOKEN"; const JSONRPC_API_HTTP: &str = "https://example.org/rpc/v0"; @@ -100,7 +100,7 @@ fn check_subnets_config() { let root = &config[&ROOTNET_ID]; assert_eq!(root.id, *ROOTNET_ID); assert_eq!(root.network_name, "root"); - assert_eq!(root.gateway_addr, Address::new_id(GATEWAY_ADDR)); + assert_eq!(root.gateway_addr, Address::from_str(GATEWAY_ADDR).unwrap()); assert_eq!( root.jsonrpc_api_http, Url::from_str(JSONRPC_API_HTTP).unwrap() @@ -115,7 +115,7 @@ fn check_subnets_config() { let child = &config[&child_id]; assert_eq!(child.id, child_id); assert_eq!(child.network_name, "child"); - assert_eq!(child.gateway_addr, Address::new_id(GATEWAY_ADDR)); + assert_eq!(child.gateway_addr, Address::from_str(GATEWAY_ADDR).unwrap()); assert_eq!( child.jsonrpc_api_http, Url::from_str(JSONRPC_API_HTTP).unwrap(), @@ -135,7 +135,7 @@ fn config_str() -> String { [[subnets]] id = "{ROOT_ID}" - gateway_addr = {GATEWAY_ADDR} + gateway_addr = "{GATEWAY_ADDR}" network_name = "root" jsonrpc_api_http = "{JSONRPC_API_HTTP}" jsonrpc_api_ws = "{JSONRPC_API_WS}" @@ -144,7 +144,7 @@ fn config_str() -> String { [[subnets]] id = "{CHILD_ID}" network_name = "child" - gateway_addr = {GATEWAY_ADDR} + gateway_addr = "{GATEWAY_ADDR}" jsonrpc_api_http = "{JSONRPC_API_HTTP}" auth_token = "{CHILD_AUTH_TOKEN}" accounts = ["{ACCOUNT_ADDRESS}"] @@ -161,7 +161,7 @@ fn config_str_diff_addr() -> String { [[subnets]] id = "{ROOT_ID}" network_name = "root" - gateway_addr = {GATEWAY_ADDR} + gateway_addr = "{GATEWAY_ADDR}" jsonrpc_api_http = "{JSONRPC_API_HTTP}" jsonrpc_api_ws = "{JSONRPC_API_WS}" auth_token = "{ROOT_AUTH_TOKEN}" @@ -169,7 +169,7 @@ fn config_str_diff_addr() -> String { [[subnets]] id = "{CHILD_ID}" network_name = "child" - gateway_addr = {GATEWAY_ADDR} + gateway_addr = "{GATEWAY_ADDR}" jsonrpc_api_http = "{JSONRPC_API_HTTP}" auth_token = "{CHILD_AUTH_TOKEN}" accounts = ["{ACCOUNT_ADDRESS}"] @@ -186,7 +186,7 @@ fn read_config() -> Config { [[subnets]] id = "{ROOT_ID}" network_name = "root" - gateway_addr = {GATEWAY_ADDR} + gateway_addr = "{GATEWAY_ADDR}" jsonrpc_api_http = "{JSONRPC_API_HTTP}" jsonrpc_api_ws = "{JSONRPC_API_WS}" auth_token = "{ROOT_AUTH_TOKEN}" @@ -194,7 +194,7 @@ fn read_config() -> Config { [[subnets]] id = "{CHILD_ID}" network_name = "child" - gateway_addr = {GATEWAY_ADDR} + gateway_addr = "{GATEWAY_ADDR}" jsonrpc_api_http = "{JSONRPC_API_HTTP}" auth_token = "{CHILD_AUTH_TOKEN}" accounts = ["{ACCOUNT_ADDRESS}"] From ae25bd960f7d714ebf40bc55e246388860165e44 Mon Sep 17 00:00:00 2001 From: cryptoAtwill Date: Wed, 29 Mar 2023 20:38:20 +0800 Subject: [PATCH 5/6] merge with main --- src/server/handlers/manager/list_checkpoints.rs | 2 +- src/server/handlers/manager/net_addr.rs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/server/handlers/manager/list_checkpoints.rs b/src/server/handlers/manager/list_checkpoints.rs index 2c7ded02..f4ffbd51 100644 --- a/src/server/handlers/manager/list_checkpoints.rs +++ b/src/server/handlers/manager/list_checkpoints.rs @@ -46,7 +46,7 @@ impl JsonRPCRequestHandler for ListCheckpointsHandler { .parent() .ok_or_else(|| anyhow!("subnet id does not have a parent"))?; - let conn = match self.pool.get(&parent_subnet_id.to_string()) { + let conn = match self.pool.get(&parent_subnet_id) { None => return Err(anyhow!("target parent subnet not found")), Some(conn) => conn, }; diff --git a/src/server/handlers/manager/net_addr.rs b/src/server/handlers/manager/net_addr.rs index 1251723e..d99f5546 100644 --- a/src/server/handlers/manager/net_addr.rs +++ b/src/server/handlers/manager/net_addr.rs @@ -37,10 +37,7 @@ impl JsonRPCRequestHandler for SetValidatorNetAddrHandler { async fn handle(&self, request: Self::Request) -> anyhow::Result { let subnet = SubnetID::from_str(&request.subnet)?; - let parent = subnet - .parent() - .ok_or_else(|| anyhow!("no parent found"))? - .to_string(); + 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, From d678e53b0102bf2a4048ad1f4a55088e078f340a Mon Sep 17 00:00:00 2001 From: cryptoAtwill <108330426+cryptoAtwill@users.noreply.github.com> Date: Thu, 30 Mar 2023 15:11:34 +0800 Subject: [PATCH 6/6] initial commit (#142) --- src/config/mod.rs | 1 - src/manager/lotus.rs | 35 ++++++++++++++++++------ src/manager/subnet.rs | 25 +++++++++++++++-- src/server/handlers/manager/create.rs | 9 +++--- src/server/handlers/manager/fund.rs | 4 ++- src/server/handlers/manager/propagate.rs | 7 ++++- src/server/handlers/manager/release.rs | 4 ++- src/server/handlers/manager/whitelist.rs | 8 +++++- 8 files changed, 72 insertions(+), 21 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 3b084b9e..7a780049 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -27,7 +27,6 @@ pub use server::{json_rpc_methods, Server}; pub use subnet::Subnet; pub const JSON_RPC_VERSION: &str = "2.0"; -pub const DEFAULT_IPC_GATEWAY_ADDR: u64 = 64; /// Default config template pub const DEFAULT_CONFIG_TEMPLATE: &str = r#" diff --git a/src/manager/lotus.rs b/src/manager/lotus.rs index c97c6fe6..590fdce7 100644 --- a/src/manager/lotus.rs +++ b/src/manager/lotus.rs @@ -15,7 +15,7 @@ use ipc_gateway::{Checkpoint, PropagateParams, WhitelistPropagatorParams}; use ipc_sdk::subnet_id::SubnetID; use ipc_subnet_actor::{types::MANIFEST_ID, ConstructParams, JoinParams}; -use crate::config::{Subnet, DEFAULT_IPC_GATEWAY_ADDR}; +use crate::config::Subnet; use crate::jsonrpc::{JsonRpcClient, JsonRpcClientImpl}; use crate::lotus::client::LotusJsonRPCClient; use crate::lotus::message::ipc::{CheckpointResponse, SubnetInfo}; @@ -155,7 +155,13 @@ impl SubnetManager for LotusSubnetManager { Ok(map) } - async fn fund(&self, subnet: SubnetID, from: Address, amount: TokenAmount) -> Result<()> { + async fn fund( + &self, + subnet: SubnetID, + gateway_addr: Address, + from: Address, + amount: TokenAmount, + ) -> Result<()> { // When we perform the fund, we should send to the gateway of the subnet's parent let parent = subnet.parent().ok_or_else(|| anyhow!("cannot fund root"))?; if !self.is_network_match(&parent).await? { @@ -166,7 +172,7 @@ impl SubnetManager for LotusSubnetManager { let fund_params = cbor::serialize(&subnet, "fund subnet actor params")?; let mut message = MpoolPushMessage::new( - Address::new_id(DEFAULT_IPC_GATEWAY_ADDR), + gateway_addr, from, ipc_gateway::Method::Fund as MethodNum, fund_params.to_vec(), @@ -177,7 +183,13 @@ impl SubnetManager for LotusSubnetManager { Ok(()) } - async fn release(&self, subnet: SubnetID, from: Address, amount: TokenAmount) -> Result<()> { + async fn release( + &self, + subnet: SubnetID, + gateway_addr: Address, + from: Address, + amount: TokenAmount, + ) -> Result<()> { // When we perform the release, we should send to the gateway of the subnet if !self.is_network_match(&subnet).await? { return Err(anyhow!( @@ -186,7 +198,7 @@ impl SubnetManager for LotusSubnetManager { } let mut message = MpoolPushMessage::new( - Address::new_id(DEFAULT_IPC_GATEWAY_ADDR), + gateway_addr, from, ipc_gateway::Method::Release as MethodNum, vec![], @@ -197,7 +209,13 @@ impl SubnetManager for LotusSubnetManager { Ok(()) } - async fn propagate(&self, subnet: SubnetID, from: Address, postbox_msg_cid: Cid) -> Result<()> { + async fn propagate( + &self, + subnet: SubnetID, + gateway_addr: Address, + from: Address, + postbox_msg_cid: Cid, + ) -> Result<()> { if !self.is_network_match(&subnet).await? { return Err(anyhow!("propagation not targeting the correct network")); } @@ -210,7 +228,7 @@ impl SubnetManager for LotusSubnetManager { )?; let message = MpoolPushMessage::new( - Address::new_id(DEFAULT_IPC_GATEWAY_ADDR), + gateway_addr, from, ipc_gateway::Method::Propagate as MethodNum, params.to_vec(), @@ -253,6 +271,7 @@ impl SubnetManager for LotusSubnetManager { async fn whitelist_propagator( &self, subnet: SubnetID, + gateway_addr: Address, postbox_msg_cid: Cid, from: Address, to_add: Vec
, @@ -270,7 +289,7 @@ impl SubnetManager for LotusSubnetManager { )?; let message = MpoolPushMessage::new( - Address::new_id(DEFAULT_IPC_GATEWAY_ADDR), + gateway_addr, from, ipc_gateway::Method::WhiteListPropagator as MethodNum, params.to_vec(), diff --git a/src/manager/subnet.rs b/src/manager/subnet.rs index 96ac471c..d7e13fbe 100644 --- a/src/manager/subnet.rs +++ b/src/manager/subnet.rs @@ -57,13 +57,31 @@ pub trait SubnetManager { ) -> Result>; /// Fund injects new funds from an account of the parent chain to a subnet - async fn fund(&self, subnet: SubnetID, from: Address, amount: TokenAmount) -> Result<()>; + async fn fund( + &self, + subnet: SubnetID, + gateway_addr: Address, + from: Address, + amount: TokenAmount, + ) -> Result<()>; /// Release creates a new check message to release funds in parent chain - async fn release(&self, subnet: SubnetID, from: Address, amount: TokenAmount) -> Result<()>; + async fn release( + &self, + subnet: SubnetID, + gateway_addr: Address, + from: Address, + amount: TokenAmount, + ) -> Result<()>; /// Propagate a cross-net message forward - async fn propagate(&self, subnet: SubnetID, from: Address, postbox_msg_cid: Cid) -> Result<()>; + async fn propagate( + &self, + subnet: SubnetID, + gateway_addr: Address, + from: Address, + postbox_msg_cid: Cid, + ) -> Result<()>; /// Sets a new net address to an existing validator async fn set_validator_net_addr( @@ -77,6 +95,7 @@ pub trait SubnetManager { async fn whitelist_propagator( &self, subnet: SubnetID, + gateway_addr: Address, postbox_msg_cid: Cid, from: Address, to_add: Vec
, diff --git a/src/server/handlers/manager/create.rs b/src/server/handlers/manager/create.rs index 25a0cdb4..22959d7c 100644 --- a/src/server/handlers/manager/create.rs +++ b/src/server/handlers/manager/create.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: MIT //! Create subnet handler and parameters -use crate::config::DEFAULT_IPC_GATEWAY_ADDR; use crate::manager::SubnetManager; use crate::server::handlers::manager::subnet::SubnetManagerPool; use crate::server::handlers::manager::{check_subnet, parse_from}; @@ -57,10 +56,13 @@ impl JsonRPCRequestHandler for CreateSubnetHandler { Some(conn) => conn, }; + let subnet_config = conn.subnet(); + check_subnet(subnet_config)?; + let constructor_params = ConstructParams { parent, name: request.name, - ipc_gateway_addr: DEFAULT_IPC_GATEWAY_ADDR, + ipc_gateway_addr: subnet_config.gateway_addr.id()?, consensus: ConsensusType::Mir, min_validator_stake: TokenAmount::from_whole(request.min_validator_stake), // In FIL min_validators: request.min_validators, @@ -69,9 +71,6 @@ impl JsonRPCRequestHandler for CreateSubnetHandler { genesis: vec![], }; - let subnet_config = conn.subnet(); - check_subnet(subnet_config)?; - let from = parse_from(subnet_config, request.from)?; let created_subnet_addr = conn diff --git a/src/server/handlers/manager/fund.rs b/src/server/handlers/manager/fund.rs index d085bc36..4d448cff 100644 --- a/src/server/handlers/manager/fund.rs +++ b/src/server/handlers/manager/fund.rs @@ -50,6 +50,8 @@ impl JsonRPCRequestHandler for FundHandler { let from = parse_from(subnet_config, request.from)?; let amount = TokenAmount::from_whole(request.amount); - conn.manager().fund(subnet, from, amount).await + conn.manager() + .fund(subnet, subnet_config.gateway_addr, from, amount) + .await } } diff --git a/src/server/handlers/manager/propagate.rs b/src/server/handlers/manager/propagate.rs index 5d3db44d..fa2665df 100644 --- a/src/server/handlers/manager/propagate.rs +++ b/src/server/handlers/manager/propagate.rs @@ -50,7 +50,12 @@ impl JsonRPCRequestHandler for PropagateHandler { let subnet = SubnetID::from_str(&request.subnet)?; conn.manager() - .propagate(subnet, from, request.postbox_msg_cid) + .propagate( + subnet, + subnet_config.gateway_addr, + from, + request.postbox_msg_cid, + ) .await } } diff --git a/src/server/handlers/manager/release.rs b/src/server/handlers/manager/release.rs index 5a865491..a65f0a2e 100644 --- a/src/server/handlers/manager/release.rs +++ b/src/server/handlers/manager/release.rs @@ -49,6 +49,8 @@ impl JsonRPCRequestHandler for ReleaseHandler { let amount = TokenAmount::from_whole(request.amount); let from = parse_from(subnet_config, request.from)?; - conn.manager().release(subnet, from, amount).await + conn.manager() + .release(subnet, subnet_config.gateway_addr, from, amount) + .await } } diff --git a/src/server/handlers/manager/whitelist.rs b/src/server/handlers/manager/whitelist.rs index 2b5099ad..53668e75 100644 --- a/src/server/handlers/manager/whitelist.rs +++ b/src/server/handlers/manager/whitelist.rs @@ -56,7 +56,13 @@ impl JsonRPCRequestHandler for WhitelistPropagatorHandler { let from = parse_from(subnet_config, request.from)?; conn.manager() - .whitelist_propagator(subnet, request.postbox_msg_cid, from, to_add) + .whitelist_propagator( + subnet, + subnet_config.gateway_addr, + request.postbox_msg_cid, + from, + to_add, + ) .await } }