Skip to content
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

[faucet] updates to enable faucet web app #20846

Merged
merged 13 commits into from
Jan 16, 2025

Conversation

stefan-mysten
Copy link
Member

@stefan-mysten stefan-mysten commented Jan 10, 2025

Description

This PR updates the faucet service to support requests from Faucet Web, which for testnet are authenticated via a token. It keeps track of each ip address and the number of requests, and limits to a predefined number of requests per a time window. In authenticated mode, it expects that requests go through /v1/faucet_web_gas. If requests go through the original /v1/gas, they will be under strict rate limit.

In addition, it adds a new route /health, and moves the logic of / to this new route. The old route / has a redirect logic to the faucet.sui.io web app for requesting tokens.

Finally, the CLI is updated to error if sui client faucet is called on the testnet network, and provides a message with the url to open to request tokens.

Test plan

Added tests for the logic on cleaning up the list of banned IPs once the reset time passes.
cargo test -p sui-faucet -- server


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI: sui client faucet now instructs users to use the Faucet web app (faucet.sui.io) to request Testnet tokens. For Devnet and localhost, behavior is unchanged.
  • Rust SDK:

@stefan-mysten stefan-mysten requested a review from a team January 10, 2025 00:09
Copy link

vercel bot commented Jan 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 15, 2025 11:30pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Jan 15, 2025 11:30pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Jan 15, 2025 11:30pm

Copy link
Contributor

@wlmyng wlmyng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

largely looks good, excited to see the faucet web app go live!

crates/sui-faucet/src/errors.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Show resolved Hide resolved
crates/sui-faucet/src/errors.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/faucet/mod.rs Outdated Show resolved Hide resolved
crates/sui/src/client_commands.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@wlmyng wlmyng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, this is p dope

Comment on lines +135 to +141
// Check if the request was successful.
if !resp.status().is_success() {
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
FaucetError::Internal("Verification failed".to_string()),
));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a 400 instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh that's handled below

then what could be a possible receive response but is not success?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I mostly handle this case in case some weird stuff comes back from cloudflare...

Copy link
Member

@amnn amnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking much cleaner, thank you! Left a couple more comments on how to make best use of the entry API.

crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
crates/sui/src/client_commands.rs Outdated Show resolved Hide resolved
crates/sui-faucet/src/server.rs Outdated Show resolved Hide resolved
@stefan-mysten stefan-mysten temporarily deployed to sui-typescript-aws-kms-test-env January 15, 2025 23:28 — with GitHub Actions Inactive
@stefan-mysten stefan-mysten merged commit 8a5f697 into MystenLabs:main Jan 16, 2025
48 of 49 checks passed
@stefan-mysten stefan-mysten deleted the faucet_web_app branch January 16, 2025 00:10
stefan-mysten added a commit to stefan-mysten/sui that referenced this pull request Jan 16, 2025
## Description 

This PR updates the faucet service to support requests from Faucet Web,
which for testnet are authenticated via a token. It keeps track of each
ip address and the number of requests, and limits to a predefined number
of requests per a time window. In authenticated mode, it expects that
requests go through `/v1/faucet_web_gas`. If requests go through the
original `/v1/gas`, they will be under strict rate limit.

In addition, it adds a new route `/health`, and moves the logic of `/`
to this new route. The old route `/` has a redirect logic to the
`faucet.sui.io` web app for requesting tokens.

Finally, the CLI is updated to error if `sui client faucet` is called on
the testnet network, and provides a message with the url to open to
request tokens.

## Test plan 

Added tests for the logic on cleaning up the list of banned IPs once the
reset time passes.
`cargo test -p sui-faucet -- server`

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] gRPC:
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [x] CLI: `sui client faucet` will now instruct users to use the Faucet
Web App (faucet.sui.io) to request testnet tokens. For devnet/localhost,
behaviour is unchanged.
- [ ] Rust SDK:
ebmifa pushed a commit that referenced this pull request Jan 16, 2025
## Description 

This PR updates the faucet service to support requests from Faucet Web,
which for testnet are authenticated via a token. It keeps track of each
ip address and the number of requests, and limits to a predefined number
of requests per a time window. In authenticated mode, it expects that
requests go through `/v1/faucet_web_gas`. If requests go through the
original `/v1/gas`, they will be under strict rate limit.

In addition, it adds a new route `/health`, and moves the logic of `/`
to this new route. The old route `/` has a redirect logic to the
`faucet.sui.io` web app for requesting tokens.

Finally, the CLI is updated to error if `sui client faucet` is called on
the testnet network, and provides a message with the url to open to
request tokens.

## Test plan 

Added tests for the logic on cleaning up the list of banned IPs once the
reset time passes.
`cargo test -p sui-faucet -- server`

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] gRPC:
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [x] CLI: `sui client faucet` will now instruct users to use the Faucet
Web App (faucet.sui.io) to request testnet tokens. For devnet/localhost,
behaviour is unchanged.
- [ ] Rust SDK:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants