-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[cli] Add client faucet command to get gas #15940
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Ignored Deployments
|
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.
Thanks @stefan-mysten! This is timely, because @giac-mysten was just lamenting how he couldn't easily request gas from the CLI!
SUI_DEVNET_URL => "https://faucet.devnet.sui.io/v1/gas", | ||
SUI_TESTNET_URL => "https://faucet.testnet.sui.io/v1/gas", |
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 think this is right, but just to confirm -- is this the version that uses batching? (the new form of the API?)
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.
From what I know, yes.
} | ||
}; | ||
request_tokens_from_faucet(address, url).await?; | ||
SuiClientCommandResult::NoOutput |
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.
Seems like this is useful to replace some other command results as well (perhaps as a follow-up)?
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, that's the plan, but I did not want to include non related changes here.
crates/sui/src/client_commands.rs
Outdated
println!("Requested gas from faucet: {url}"); | ||
println!( |
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.
What's our current stance on println!
vs tracing
vs other output methods for the CLI? Do we have a standard now?
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've been thinking on how to do this. What we wanted to do is to use eprintln
for stderr stuff, and the rest should be mostly tabulated output. What I wanted to have as output for this is the new coin object id, but that's difficult because of the rate limiter on the faucet server (in my tests, I run the request and then the next request to check for task status returned a 429, so not easy). An alternative is to call the gas command before the faucet, and then in a loop wait until we have 1 extra coin, and then do a diff to get the id. It's hacky, but this solves the rate limiter issue.
Thoughts?
crates/sui/src/client_commands.rs
Outdated
println!("Faucet task id: {task_id}"); | ||
println!("The coin should be available in the next couple of minutes. Run sui client gas to find your coins."); |
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.
It is usually quicker than a couple of minutes, so is it worth waiting for it here? (Perhaps guarded by a flag/option?)
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.
This is something that we can follow up with as well!
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.
The issue with waiting is that often due to the rate limiter, we cannot make a request to the faucet server for the status as it will return 429. The hacky way is to call gas
command, and then in a loop call the gas command and get the coins until we have coins.len() + 1.
Maybe a --wait-for-coin-id
flag can be used to indicate that the user wants to wait to get the coin id?
The main issue is that I could have my set active network to X, and then issue faucet --url Y
, so when calling gas
command, it will use the X network instead of the Y one...
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.
Tried to do something and realized that if a custom RPC's faucet endpoint does not follow the usual faucet.network.address
it's hard to "deconstruct" the RPC endpoint to get the gas objects, so it is not so straightforward. For now, it will just tell the user to check for gas. If anyone has better ideas, I am all ears :D
crates/sui/src/client_commands.rs
Outdated
resp.status() | ||
); | ||
if resp.status() == 429 { | ||
bail!("Faucet received too many requests from this ip address. Please try again after 60 minutes."); |
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.
bail!("Faucet received too many requests from this ip address. Please try again after 60 minutes."); | |
bail!("Faucet received too many requests from this IP address. Please try again after 60 minutes."); |
crates/sui/src/client_commands.rs
Outdated
let faucet_resp: FaucetResponse = resp.json().await?; | ||
|
||
let task_id = if let Some(err) = faucet_resp.error { | ||
bail!("Faucet request was unsuccessful. Error is {err:?}") |
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.
bail!("Faucet request was unsuccessful. Error is {err:?}") | |
bail!("Faucet request was unsuccessful: {err}") |
Don't use debug output for errors -- most of the time the impl Display
for the error type displays a human-readable message, and we should use that. In the cases it doesn't, we should fix that.
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.
Oops, my bad. Thanks for spotting this!
crates/sui/src/client_commands.rs
Outdated
} else { | ||
faucet_resp.task | ||
}; | ||
println!("Faucet task id: {task_id}"); |
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.
println!("Faucet task id: {task_id}"); | |
println!("Faucet task ID: {task_id}"); |
… if it is success or error
2b880aa
to
c0df8df
Compare
Description
Added a new command
sui client faucet
to make it easier to get gas fromdevnet
,testnet
, orlocal
network. If a different network than the usual ones (fullnode.network.sui.io
) is used, it will complain and ask to pass the url to its faucet.There are two options for the command:
--url
, which is the URL to the gas faucet server--address
, which can be either an address or the alias name corresponding to an address in the wallet.Usage
Output
It will only output that the request was successful and the task id that it got from the faucet server. The user has to manually check for the gas coin if it was sent to the address or not (due to rate-limits, an automated approach fails easily).
Test Plan
If your changes are not user-facing and do not break anything, you can skip the following section. Otherwise, please briefly describe what has changed under the Release Notes section.
Type of Change (Check all that apply)
Release notes
Added a new command
sui client faucet
to make it easier to get gas fromdevnet
,testnet
, or alocal
network. If a different network than the usual ones (fullnode.network.sui.io
) is used, it will complain and ask to pass the URL to the faucet server.There are two options for the command:
--url
, which is the URL to the gas faucet server--address
, which can be either an address or the alias name corresponding to an address in the wallet.Usage
Output
It will only output that the request was successful and instruct the user to wait up to 60 seconds and then manually check (
sui client gas
) for the gas coin if it was sent to the address or not.