0

As stated, if I use PDA (Program Derived Address) to store user data, do I face transactional issues similar to traditional databases, where my version might get updated by another user before I save, resulting in overwriting the latest data? If this issue exists, how should I address it?

enter image description here

1 Answer 1

1

This depends on what you mean by "atomicity." In standard relational DB systems, atomicity is one of the ACID properties, which guarantees that "all operations in a set happen, or none of them do." For more details, see this Stack Overflow discussion.

From this perspective, a "Solana transaction" works as a single unit of work that cannot be interleaved. It is processed as a whole (all instructions one by one at once): no other transaction can write to the data the transaction works with. The result is either a complete success (the result is written to the blockchain ledger) or a complete failure (no state change is recorded on the ledger).

All other aspects depend on your application, just as with any other application interacting with a DB system. Sending transactions to Solana works asynchronously, and any further ordering needs to be managed by your code. For instance, if you send two transactions performing "an update," the processing order could be arbitrary.

If you wonder whether it could be that two transactions landed at the validator would create two different PDA accounts and the code could work with two different "states" then - no this cannot happen.

The transactions "touching" the same accounts are executed in serial order. That means only one transaction may create the account and the following one will get already created state.

You can check some info on processing of the transaction at e.g.,

2
  • thanks very much u answer. so. can i think Are concurrent calls to the same contract executed in order? There will not be a situation where A calls get --> B calls update --> A calls update, with interleaved execution. Commented Jun 29 at 5:37
  • The thing is that the transaction is the atomic unit of work. All instruction within the transaction is executed in order. Then there is the execution of transactions. The Solana runtime runs it in order if the two transactions touch the same accounts. Transactions with different accounts can be run in parallel without interleaving issues. Yes, it cannot happen that the validator that builds the block would run in parallel in two separate execution threads those operations interleaved.
    – chalda
    Commented Jul 1 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.