-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[Sui CLI] - Support full node #4404
Conversation
4cf6727
to
14c5b86
Compare
4f72b21
to
cc806e1
Compare
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.
Looks good, but a small request as usual whenever we change CLI stuff: can we show a sample usage/output?
(ServerHandle::HttpHandler(handle, addr), "JSON-RPC") | ||
} | ||
ServerBuilder::WsBuilder(ws_builder) => { | ||
let server = ws_builder.build(listen_address).await?; | ||
let addr = server.local_addr()?; | ||
let handle = server.start(self.module)?; | ||
(ServerHandle::WsHandle(handle), addr, "Websocket") | ||
(ServerHandle::WsHandle(handle, addr), "Websocket") |
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.
Nit, but please use constant for the strs
.wallet_sync_api() | ||
.sync_account_state(player_x) | ||
.await?; | ||
if self.client.is_gateway() { |
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.
We will remove gateway completely right? When?
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.
yes, we need to do some test to make sure equivocation will rarely happens in a reasonable sized network (20 validators) before we can safely remove the gateway.
pub async fn new(http: &str, ws: Option<&str>) -> Result<Self, anyhow::Error> { | ||
let http = HttpClientBuilder::default().build(http)?; | ||
let ws = if let Some(url) = ws { | ||
Some(WsClientBuilder::default().build(url).await?) | ||
} else { | ||
None | ||
}; | ||
let info = Self::get_server_info(&http, &ws).await?; | ||
Ok(Self { http, ws, info }) | ||
} | ||
|
||
async fn get_server_info( | ||
http: &HttpClient, | ||
ws: &Option<WsClient>, | ||
) -> Result<ServerInfo, anyhow::Error> { | ||
let rpc_spec: Value = http | ||
.request("rpc.discover", None) | ||
.await | ||
.map_err(|e| anyhow!("Fail to connect to the RPC server: {e}"))?; | ||
let version = rpc_spec | ||
.pointer("/info/version") | ||
.and_then(|v| v.as_str()) | ||
.ok_or_else(|| anyhow!("Fail parsing server version from rpc.discover endpoint."))?; | ||
let rpc_methods = Self::parse_methods(&rpc_spec)?; | ||
|
||
let subscriptions = if let Some(ws) = ws { | ||
let rpc_spec: Value = ws | ||
.request("rpc.discover", None) | ||
.await | ||
.map_err(|e| anyhow!("Fail to connect to the Websocket server: {e}"))?; | ||
Self::parse_methods(&rpc_spec)? | ||
} else { | ||
Vec::new() | ||
}; | ||
Ok(ServerInfo { | ||
rpc_methods, | ||
subscriptions, | ||
version: version.to_string(), | ||
}) | ||
} | ||
|
||
fn parse_methods(server_spec: &Value) -> Result<Vec<String>, anyhow::Error> { | ||
let methods = server_spec | ||
.pointer("/methods") | ||
.and_then(|methods| methods.as_array()) | ||
.ok_or_else(|| { | ||
anyhow!("Fail parsing server information from rpc.discover endpoint.") | ||
})?; |
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.
Nit. Raw strings like this really bother me :p but it could be okay
…connecting to gateway or fullnode fixed issue #4164 print rpc server's available methods on sui console startup
cc806e1
to
34e5ff4
Compare
FYI @brad-mysten @tharbert this PR changed the client.yaml, this might break operations? |
rpc
, this can be used to point to either gateway or fullnoderpc.discover
method and determine if the client is connecting to gateway or fullnodetodos: