Merge multiple transactions into one #291
Edison-Yeah
started this conversation in
Enhancements - Technical
Replies: 1 comment 2 replies
-
The primary objective of this proposal appears to be to reduce gas costs (as a proxy for network resource usage). Could you quantify how much is saved by batches of various sizes? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Aggregating multiple transactions into a single transaction optimizes the user experience and reduces user overhead as paying for each transaction is expensive and cumbersome.
Abstract
In the process of transaction creation, multiple transactions are aggregated into one transaction, and they are processed separately in the execution,
thus reducing the cost of transaction execution and saving the cost of users.
Change Motivation
Chain bandwidth is a valuable resource, necessary for both critical network operations and product use.
Avoiding frequent and high-gas-cost operations reduces contention, costs, and chain validation latency.
Given the state of the network, users have to pay a fee for each transaction, and the cost of calling multiple methods in a period of time is a significant cost to the user. Imagine a scenario where a user needs to transfer money to multiple addresses at the same time, but each transaction can only be transferred to one address,
which is extremely inconvenient for the user. On the other hand, it is also a very troublesome thing when the user needs to check the fund flow of his account.
Specification
Design Rationale
The handling of messages in the official project is quite mature, so changing the logic of the actor part of the code is not desirable. Therefore, in the stage of message routing, the message is intercepted, and then the message is split, and the transaction cycle execution after splitting is the most appropriate way. The advantage of this is that it does not affect the native logic, but only extends the functionality, ensuring the security and compatibility of the code.
The data structure of the message itself has jSON-formatted parameters, which can be used to carry multiple transactions. Multiple transactions are serialized into parameters and parsed at execution time.
Most of the cost of aggregating multiple transactions goes to tipping miners, whose job is simply to package transactions, so cutting tipping for miners can significantly reduce transaction costs for users.
Backwards Compatibility
None of these changes are intrusive changes to the official native code, but simply extend functionality to accommodate all operations.
Incentive Considerations
Aggregated transactions can greatly save users' expenses and facilitate users to check the flow of funds in their personal accounts.
Product Considerations
This proposal will greatly reduce the cost of user transactions, generally making use of the Filecoin blockchain cheaper.
Implementation
Implemented in lotus in filecoin-project/lotus#7727.
The preliminary implementation
1. The realization idea of transaction aggregation
The execution of transactions is implemented in the spec-actor layer. If intrusive changes are made to the execution logic of the transaction itself and the official code is changed significantly, the Lotus layer needs to work with the spec-actor to make the changes. So after thinking about it, try to intercept the transactions during the VM execution phase, route the aggregated transactions to specific processing methods, and break the aggregated transactions into small ordinary transactions to be executed by the VM.
2. Implementation method
2.1 Parameters and Methods
In the format of Message, the property params is []byte:
The parameters of a particular data structure can then be serialized through JSON into Params. The data structure of parameters is shown as follows:
You only need to define the recipient address (to), the amount of transfer (value), the method to call (method), the parameter to call the method (Params), multiple Receive tokens to call multiple times, and then serialize it into the Params property of Message via JSON.
To indicate that Message is an aggregated transaction without changing the structure of the Message, the only way to do this is through the Message's Method, by specifying a special Method.
Message's Method must be MultiMsgMethod as long as it is an aggregate transaction.
2.2 Perform
HandleMultiMsg() breaks down transactions into small transactions and executes them in VM. Each small transaction is handled by the corresponding Method. The State of the entire transaction is shared, that is, the execution of each small transaction has an impact on the State of other small transactions, ensuring that the change of State is correct after the completion of the entire transaction.
The failure of one small transaction can cause the failure of the entire large transaction, and State does not record the changes made by that transaction. Each small transaction has its own Method, so, in theory, this Method can be used for aggregate calls to multiple different methods.
2.3 Thinking about how to reduce user costs
In the execution of the VM, the message execution logic of the actor is not changed, so we cannot reduce the execution cost in the specific execution of the aggregate transaction by breaking it into smaller transactions. However, in the simulation calculation of Gas consumption for aggregated transactions, the calculated GasLimit will become very large. As a result, after the final transaction is executed, the MinerTip for miners will become very high, which is much higher than the sum of MinerTip for executing multiple ordinary transactions.
In this case, the idea is to cut miners' consumption. Here's why:
2.4 implementation
To calculate the final Gas consumption, we have chosen to adjust the MinerTip, currently halving the consumption.
That's all I have to say about trade aggregation.I've implemented the base code and tested it, and the results are as expected. This is the reference implementation link: https://github.com/IversonHan/lotus/tree/testhan
Beta Was this translation helpful? Give feedback.
All reactions