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] Adding new API with old function call for fallback #12648

Merged
merged 4 commits into from
Jun 26, 2023

Conversation

healthydeve
Copy link
Contributor

@healthydeve healthydeve commented Jun 23, 2023

Description

Addition of a feature flag to gate the batch api behavior

Test Plan

Unit testing to make sure the send UUID can be found.

If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

@healthydeve healthydeve requested a review from amnn June 23, 2023 06:06
@vercel
Copy link

vercel bot commented Jun 23, 2023

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

6 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) Jun 26, 2023 2:02pm
explorer-storybook ⬜️ Ignored (Inspect) Jun 26, 2023 2:02pm
multisig-toolkit ⬜️ Ignored (Inspect) Jun 26, 2023 2:02pm
sui-kiosk ⬜️ Ignored (Inspect) Jun 26, 2023 2:02pm
sui-wallet-kit ⬜️ Ignored (Inspect) Jun 26, 2023 2:02pm
wallet-adapter ⬜️ Ignored (Inspect) Jun 26, 2023 2:02pm

@@ -92,6 +92,7 @@ async fn main() -> Result<(), anyhow::Error> {
.route("/gas", post(request_gas))
.route("/v1/gas", post(batch_request_gas))
.route("/v1/status", post(request_status))
.route("/v1/gas_old", post(request_gas_v1_interface))
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea of the fallback is that it's controlled by a config flag on faucet, so we shouldn't need a new endpoint, instead, based on a config flag, /v1/gas would start serving batch requests without actually batching them. This way, if there's an issue with the new implementation, we can fall back to the old one without having to tell any client to change which endpoitn they are calling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this structure.

match result {
Ok(_) => {
info!(uuid =?id, "Request is successfully served");
(StatusCode::CREATED, Json(BatchFaucetResponse::from(id)))
Copy link
Contributor

Choose a reason for hiding this comment

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

The response structure should be exactly the same as for batch_request_gas, i.e. it says that the request has been accepted, when in fact it has already successfully served the response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the same because I just send back the UUID which is what batch_request_gas sends back

Copy link
Contributor

@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.

Check out the comment about the status code, but otherwise, looks good!

match result {
Ok(_) => {
info!(uuid =?id, "Request is successfully served");
(StatusCode::CREATED, Json(BatchFaucetResponse::from(id)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Continuing the thread that was previously here -- the reason the response is not the same is because the StatusCode here is CREATED rather than ACCEPTED above. It looks like we should be able to fix that by sharing most of the implementation between the two parts (see below).

Note, I also added a logging message for the fallback path, so we can easily check that things are working by enable informational logs, when we first start the faucet with batching disabled.

let FaucetRequest::FixedAmountRequest(request) = payload else {
    return (
        StatusCode::BAD_REQUEST,
        Json(BatchFaucetResponse::from(FaucetError::Internal(
            "Input Error.".to_string(),
        ))),
    )
};

// TODO (jian): remove this feature gate when batch has proven to be baked long enough
let result = if state.config.batch_enabled {

    // TODO (jian): get rid of this task spawning since recycled coins are now handled by the batching task.
    spawn_monitored_task!(async move {
        state
            .faucet
            .batch_send(
                id,
                requests.recipient,
                &vec![state.config.amount; state.config.num_coins],
            )
            .await
    })
    .await
    .unwrap()
} else {
    info!(uuid = ?id, "Falling back to v1 implementation");
    spawn_monitored_task!(async move {
        state
            .faucet
            .send(
                id,
                requests.recipient,
                &vec![state.config.amount; state.config.num_coins],
            )
            .await
    })
    .await
    .unwrap()
}

match result {
    Ok(_) => {
        info!(uuid = ?id, "Request is successfully served");
        (StatusCode::CREATED, Json(BatchFaucetResponse::from(id))
    },
    Err(e) => {
        warn!(uuid = ?id, "Failed to request gas: {:?}", v);
        (
            StatusCode::INTERNAL_SERVER_ERROR,
            Json(BatchFaucetResponse::from(e)),
        )
    }
}

@healthydeve healthydeve merged commit 62df822 into main Jun 26, 2023
@healthydeve healthydeve deleted the jlu/v2_batch branch June 26, 2023 14:34
ebmifa pushed a commit that referenced this pull request Jul 12, 2023
## Description 

Addition of a feature flag to gate the batch api behavior

## Test Plan 

Unit testing to make sure the send UUID can be found.
---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [x] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
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.

2 participants