Party-state-actor
Last updated
Last updated
This actor is loaded into the 's . It is the same concept as stored procedure in traditional cloud computing webapp. There are many pure functions that handle incoming txns and modify the state (including and data).
As you already know, every runs an instance of this actor. All of them run the same txn at the same sequence and modify the same state to finally get the same new state. This is guaranteed by the consensus. As an application developer, you don't need to care too much about how it works. You can simply assume there's only one instance of your function running that updates a single state.
There are two types of requests: and . Please click the links to get to know more about them. At least you should know that queries execute immediately, but commands need to wait a period of time prior to execution.
Please go to and find the function fn txn_exec_inner(tsid: Tsid, txn_bytes: &[u8]) -> HandlerResult<()>. This is where most of the logic lives.
The code above shows how you handle the PostMessage txn.
In this function, the logic determines how much (amt) the user need to pay based on the TTL (time to live), and who should pay (the message sender). Finally, call the actor_statemachine::consume_from_account
function.
There are other txns this function handles. They are very straightforward from just reading the txn name and code.
The hidden balance is used to verify if the txn made any mistake that caused the state to be unbalanced after the update. If all the code is correct, there shouldn't be any unbalanced state.
This txn (sometimes we call it a command) is generated in the when user click post message button in .
The message has been stored to the by , the only thing this actor is supposed to do in the state level is to transfer the gas fee. Gas fee is what the end users supposed to pay for this kind of service, in this case, posting a message.
There are a few concepts we'll need to explain here. and . Please click the links for further explanation.
After the txn has been handled, all changes are not commited yet. they are just saved to . So you can see the code after all the txns ahave been handled. This code is used to commit the changes.
After the commit, the state is finally changed. Before the commit, any error causing the function to return early will not affect the state. The state remains as it was before. See for more details about atomic transaction concepts.