Scaling Gas Payment Sponsorship with the Sui Gas Pool
The Sui Gas Pool service allows developers to easily sponsor transactions at scale.
![Scaling Gas Payment Sponsorship with the Sui Gas Pool](/content/images/size/w1200/2024/07/07-17-Blog-Header--1800x700---2-.png)
Mysten Labs is open-sourcing the Sui Gas Pool to the Sui developer community. This innovative service is designed to sponsor gas payments for transactions on Sui at scale, addressing important needs around user onboarding for apps with high concurrency needs.
Sui's native support for sponsored transactions allows a transaction to use a gas coin owned by a different address than the sender for gas payment. This feature allows a service to subsidize their users' transaction costs, significantly enhancing the onboarding experience for users new to Web3. Being able to get started without funding a wallet significantly enhances the user experience by providing greater flexibility and ease of use. Despite these advantages, app builders often struggle with the complexities of managing gas payments at scale.
The Sui Gas Pool allows apps to easily offer greater user onboarding experiences through sponsorship of gas payments at scale. Additionally, the Sui Gas Pool alleviates the burden that apps handling highly concurrent transactions experience, allowing them to streamline their operations through efficiently managed gas sponsorship.
How a Sui Gas Pool works
The Sui Gas Pool was developed with two primary goals in mind, horizontal scalability and generality. The system can easily scale by adding more instances to meet higher throughput demands, ensuring it can handle increased transaction volumes. It is also designed to be generic, allowing any builder to integrate and operate it as either a standalone service or part of their system.
When initializing a gas pool, it queries all gas coins dedicated to sponsoring transactions owned by the sponsor address then splits them into smaller gas coins with a configurable target initial balance. These gas coins are then added to the gas pool database which manages available gas coins and gas coin reservations.
Funding the gas pool is straightforward: simply send a large balance gas coin to the sponsor address, and the gas pool will automatically detect and process it. To ensure that funding within the gas pool is maintained, the system periodically checks for any large gas coin owned by the sponsor and then splits it before adding to the gas pool.
The gas pool service operates an RPC server, with permission control managed through a secret bearer token in HTTP requests. The interaction workflow is as follows:
- The client sends a reserve_gas request to the gas pool to reserve gas coins that meet the specified gas budget.
- The client attaches the gas coins to the transaction and obtains the user's signature on the transaction.
- The client sends the user-signed transaction to the gas pool through the execute_transaction request.
- The gas pool signs the transaction, sends it to a full node to execute, and releases the gas coins.
Scaling a Sui Gas Pool
The Sui Gas Pool service scales efficiently through several mechanisms.
- Automated gas coin splitting: The automated gas coin splitting creates many smaller gas coin objects, allowing for increased throughput.
- Controlled transaction execution: Conservative waiting heuristics are not needed since the gas pool retains full control over transaction execution, ensuring gas coins are released promptly.
- Centralized data persistence: Data persistence is handled through central Redis storage, allowing individual gas pool servers to run without local data persistence requirements or crash recovery. This allows app builders to run as many gas pool servers as needed per sponsor address with minimal overhead.
- Multiple sponsors and services: The system can further scale by having multiple sponsors and deploying multiple gas pool services.
Get started
By addressing these needs and implementing a robust, scalable solution, the Sui Gas Pool significantly enhances the user experience and operational efficiency of apps on Sui. Enoki, Mysten Lab's customer experience platform, already uses the Sui Gas Pool for its sponsored transaction feature. Through its usage in Enoki, the Sui Gas Pool demonstrates its reliability and efficiency in a production environment, highlighting its capability to enhance user experience and operational efficiency for apps on Sui.
Making the Sui Gas Pool component open source ensures the entire Sui community can effectively scale sponsored transactions, supporting new apps with large user bases.
To learn more about the Sui Gas Pool, visit the GitHub repository. Feel free to contact engineers for any questions or problems experienced.