Atomic commit protocol refers to a distributed algorithm that coordinates all the processes that participate in a distributed atomic transaction on whether to commit or abort (roll back) the transaction.
Simple commit protocol is a commit protocol that allows non-coordinator participants to avoid locking during Atomic Commit between two parties. Therefore, in the Simple commit protocol, the Initiator chain also serves both the coordinator and participant roles.

Initiate step
MsgInitiateTxis submitted to the Initiator chain for validation and authentication. Note: This process is common to all commit protocols.
Prepare step(A)
Participant A executes the
ContractTransactionspecified inMsgInitiateTx.If the execution is successful, a lock is acquired to save the changes to the state store and prevent conflicts with concurrent transactions. After that, it creates a packet
PacketDataCallcontaining the information of participant B's contract function call, and sends it to the channel with B.If the execution fails, the process of this transaction is terminated by abort.
Commit step(B)
B receives the
PacketDataCalland executes the specified contract function.If execution is successful, commit is performed. After that, set
Commit_OKas Status inPacketCallAcknowledgementand send it to the channel with A.If the execution fails, abort is performed. Then, set
COMMIT_FAILEDas Status inPacketCallAcknowledgementand send it to the channel with A.
Commit step(A)
A receives a
PacketCallAcknowledgementand checks its Status.If the Status is
COMMIT_OK, A commits the state store change operation saved at Prepare and removes the lock.If Status is
COMMIT_FAILED, A discards the state store change operation saved at the prepare step and deletes the lock.
Two-phase commit (2PC) is a commit protocol that executes a two-phase flow of commit request and commit between the coordinator and participants.
The protocol flow is shown in the figure below, where X is the coordinator, A, B, and C are the respective participants, and the arrows indicate the direction of the request for each step of the flow.

Initiate step
MsgInitiateTxis submitted to the Initiator chain for validation and authentication. Note: This process is common to all commit protocols.After authentication, the Initiator chain sends a
PacketPrepare, a packet requesting Prepare to each participant chain specified in theMsgInitiateTxas coordinator.
Prepare step
Each Participant chain executes the contract function specified in
ResolvedContractTransactionon receiving aPacketPrepare.If the execution is successful, a lock is acquired to prevent conflicts between saving changes to the State store and concurrent transactions. This operation is available via State store. Finally, set the Status of the
PacketPrepareAcknowledgementtoPREPARE_RESULT_OKindicating success and send it to the coordinatorIf the execution fails, the change operation on the State store is discarded, and the Status of
PacketPrepareAcknowledgementis set toPREPARE_RESULT_FAILEDindicating failure and sent to the coordinator.
Confirm step
The Coordinator chain receives the
PacketPrepareAcknowledgementsent by each Participant chain and performs the following state transitions. (1) Wait for the next acknowledgement to be received (2) If the Status of the received acknowledgement isPREPARE_RESULT_OKand there is an unreceivedPacketPrepareAcknowledgement, transit to (1) . If all acknowledgements are received, setCOMMITto Status ofPacketCommitto send a commit request to each participant chain, and proceed to the commit step (3) If the Status of the received acknowledgement isPREPARE_RESULT_FAILED, setABORTto the Status of thePacketCommitto request abort to each participant chain, send it, and proceed to the commit step
Commit step
When a commit request is received (Status of
PacketCommitisCOMMIT), each participant chain applies the change operation saved in the Prepare step to the State store, removes the lock, and sends aPacketCommitAcknowledgementto the coordinator chain indicating that it has been completedWhen each participant chain receives an abort request (Status of
PacketCommitisABORT), it deletes the change operation and locks saved in the prepare step, and sends aPacketCommitAcknowledgementto the coordinator chain indicating that it has been completed.
** **

