'"Atomic-transaction" in NEAR protocol
i'm trying to understand deeper in Near protocol and how the transaction process.
I know that txn in near not atomic and if contract call contract, one may fail and one mail success. but i want to ask if contract A call contract B(txn-1), then contract B call back to contract A(txn-2), is this '2-txn' happened continuously? i mean there won't be no others txn between 2 of them(??), which mean the state after txn-1 is what txn-2 begin with to process.
I want to know this because i want to make sure the state of contract in first call and the call back txn is trustable!
Thanks!
Solution 1:[1]
A contract call is atomic, but can result in a list of receipts for future contract calls, each of which are atomic.
-0-> A -1-> B -2-> A
In your example, contract A would execute and create the receipts ( call B; then call A). Any changes to contract A's state in this initial call would be atomic. That is if a separate new call to A from a different account were execute before the final call to A (-2-> A), it would see the updated state.
On the EVM an error at the end of a cross contract chain will cancel the transaction and any state changes. This is different on NEAR because if the last -2-> A fails the state changes in -0-> A will remain. This is why you any failure in -2-> A ( or it detects a failure in B), needs to roll back any state changes. It's tricky to get right but much more flexible than the EVM.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sirwillem |
