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

[iota-faucet] Enable the use of batched mode on faucet #4110

Merged
merged 7 commits into from
Nov 28, 2024

Conversation

samuel-rufi
Copy link
Member

@samuel-rufi samuel-rufi commented Nov 18, 2024

Description of change

Enables the use of batched mode on the faucet.
It appeared that if only 5 coins are provided to the faucet (which is the default for the wallet context) all coins will be added to the default gas queue available at /gas and not to the batch queue at /v1/gas. This logic has been refactored.

Links to any relevant issues

Fixes #4065

Type of change

  • Bug fix (a non-breaking change which fixes an issue)

How the change has been tested

Provided a test for batch send.

Change checklist

  • I have followed the contribution guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that new and existing unit tests pass locally with my changes

@samuel-rufi samuel-rufi added the infrastructure Issues related to the Infrastructure Team label Nov 18, 2024
@samuel-rufi samuel-rufi self-assigned this Nov 18, 2024
@samuel-rufi samuel-rufi requested review from a team as code owners November 18, 2024 13:02
// This is to handle the case where there is only 1 coin, we want it to go to
// the normal queue
let split_point = if coins.len() > 10 {
coins.len() / 2
Copy link
Member

Choose a reason for hiding this comment

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

@samuel-rufi could you elaborate on how the gas pool handles gas tokens? Why were there multiple gas coins put into it before and why do we only put one now? Is the faucet capable of issuing concurrent transactions with different gas coins?

Copy link
Member Author

@samuel-rufi samuel-rufi Nov 28, 2024

Choose a reason for hiding this comment

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

Great question @lzpap !

So first of all each user request to the gas pool will be handled in a dedicated task spawn in

async fn request_gas(
.

Each task, will try to get a free gas object from the queue (protected by an Mutex to make sure each request gets a different gas object). The gas pool can serve multiple requests using multiple gas objects basically at the same time.

So how does it work in more detail? For each TX, it will try to get an available coin from this queue. This coin will be locked and unlocked (also called "recycled") once the transaction was successful. If the transaction fails, the coin will stay locked and the queue with available objects shrinks.

So if batch is activated, only one gas object is allocated to the normal gas pool and all others are added to the batch pool. If batch is deactivated, all gas coins are added to the gas pool. Do you think we should change this splitting logic?

In case we don't want to use batch mode, but still want to be able to serve multiple faucet requests (basically at the same time) we can make use of the gas pool, but need to make sure that it was initialized with multiple gas coins. Also for the batch mode, multiple gas coins are needed in order to handle multiple batches at the same time.

--

In case a request comes in and there is no gas coin available (for both modes), it will wait some seconds and then return an error if the queue is still empty.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the answers!
So currently on the testnet we have the non-batch mode and 2 objects in the gas pool (obj 1) and (obj 2), right?
@junwei0117 next time the faucet gets topped up would be nice to send the coins in smaller batches to it, so it has 5-10 coins and can serve concurrent requests as well.

@samuel-rufi samuel-rufi merged commit 3ff8bf8 into develop Nov 28, 2024
38 of 40 checks passed
@samuel-rufi samuel-rufi deleted the l1sc/infra/fix-faucet-batch-send branch November 28, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Issues related to the Infrastructure Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iota-faucet] Enable the use of batched mode on faucet
6 participants