-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Atomic Transaction and Batch Transaction #1791
Comments
Is it? It's relatively easy to check for account existence ( That said, I'm not against the ability to set "revert points" in runtime execution, it's just quite a bit of work to introduce it without pessimising the average case and in most instances really isn't required. I fear batch transactions would require fairly substantial reworking of the transaction queue and introducing such mutual dependencies at the lowest level would inevitably risk introducing numerous attack vectors. I think a better solution would be to keep transactions simple but introduce a simple module that allowed for multiple e.g. Account A wants to call X, Account B wants to call Y, but neither should succeed unless both succeed. A sends a transaction: commit( |
Even for simple case like transfer, it can be tricky to handle all the edge cases. e.g. For this case, the pre-checks may include account creation fee twice because C did not exist without checking both transfer goes to a same account. It is very easy to make mistake. A much harder example is make two smart contract calls, you simply cannot calculate the gas fee required upfront. Thanks for the suggestion of using a module to handle the multiple Also this issue does not only exists in the multi- substrate/srml/balances/src/lib.rs Line 300 in 50bfe37
Or call any methods that have side-effect and returns Result multiple times.It is not easy to write the pre-conditios to ensure all the has-side-effect fallible methods won't fail. In summary, I think this limitation increase the barrier of module re-use, increase the complexity to implement complicate logics and allow developers to easily make mistakes. It doesn't scales. |
Another benefit of be able to return error anytime without unwanted side effects is that it will be easy to always use checked arithmetic without worry if an operation could overflow or not. |
If you require to know whether gas costs are sufficient for a arbitrary code to execute before making state changes or not, then you have just created yourself a trivially attackable chain. Now I'm not saying that being able to return errors at any point is without its benefits. But the complexity and potential for pessimisation it would introduce on the client side is too high a cost to bear for us right now. It also introduces a programming style that makes it way easier to create code that is economically insecure, as you have huge potential for introducing substantial computation that results in an The smart contract environment is designed to provide this higher level functionality as the speed I'm afraid my position is that parachain developers will just have to be mindful for now. |
@gavofyork Thanks for the explanation. Is it possible to design the runtime such that the transaction fee are still charged even the transaction failed? So they have similar property to smart contract. There is already developed solution for contract, is it possible to generalize this solution so it works for all the runtime modules? The fees module needs some special case handling so its writes are not revertible, but we have a single place to do the modification. |
Fixed by #6269 |
Currently transactions are not applied atomically that if it failed halfway through, the previously applied storage updates are kept and not reverted. Therefore we have to perform all the checks before first storage write and cannot return error after first storage write happened.
That means if a runtime module wants make multiple fallible calls, it have to first check all of them won't fail upfront. This can be hard to implement. Image I want to implement a runtime call to transfer token to 3 different accounts, which may or may not be already created (hence different transaction fee will be deduced). It is hard to calculate the exact total balances required to make this action without failure.
Another feature I would like to implement in future is atomic batch transaction (Thanks to Schnorr, only one signature will be needed). It needs to ensure either all or none of the transactions success. That means it needs ability to revert previously applied transaction if the last one failed.
The text was updated successfully, but these errors were encountered: