Atomic commit protocol
Atomic commit protocol is a protocol that allows a set of multiple operations to be executed as a single operation. Typical examples include Two-phase commit and Three-phase commit. In our context, it refers to a protocol that allows multiple blockchain transactions to be executed as a single transaction.
Cross Framework currently supports two protocols, Simple commit protocol and Two-phase commit protocol, which can be specified when creating a transaction. In these protocols, there are two roles: the participants, or cohorts, who execute each process specified in the transaction and the coordinator who coordinates the participants to obtain a common decision. Simple protocol is limited to two participants, and one of the participants is the coordinator. On the other hand, Two-phase commit protocol is not limited to participants and can use a coordinator who is not a participant. However, compared to Simple protocol, the number of steps in the flow is larger, and the completion time is longer. Details of each of these methods are described in Two-phase commit protocol and Simple commit protocol. Also, details on transaction creation are described in Cross-chain Transaction.
Two-phase commit protocol
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 requestingPrepareto 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
Statusof thePacketPrepareAcknowledgementtoPREPARE_RESULT_OKindicating success and send it to the coordinator - If the execution fails, the change operation on the State store is discarded, and the
StatusofPacketPrepareAcknowledgementis set toPREPARE_RESULT_FAILEDindicating failure and sent to the coordinator.
- Each Participant chain executes the contract function specified in
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
Statusof the received acknowledgement isPREPARE_RESULT_OKand there is an unreceivedPacketPrepareAcknowledgement, transit to (1). . If all acknowledgements are received, setCOMMITtoStatusofPacketCommitto send a commit request to each participant chain, and proceed to the commit step(3) If the
Statusof the received acknowledgement isPREPARE_RESULT_FAILED, setABORTto theStatusof thePacketCommitto request abort to each participant chain, send it, and proceed to the commit step
Commit step
- When a commit request is received (
StatusofPacketCommitisCOMMIT), 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 completed - When each participant chain receives an abort request (
StatusofPacketCommitisABORT), it deletes the change operation and locks saved in the prepare step, and sends aPacketCommitAcknowledgementto the coordinator chain indicating that it has been completed.
- When a commit request is received (
Simple commit protocol
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.
- Participant A executes the
Commit step(B)
- B receives the
PacketDataCalland executes the specified contract function. - If execution is successful, commit is performed. After that, set
Commit_OKasStatusinPacketCallAcknowledgementand send it to the channel with A. - If the execution fails, abort is performed. Then, set
COMMIT_FAILEDasStatusinPacketCallAcknowledgementand send it to the channel with A.
- B receives the
Commit step(A)
- A receives a
PacketCallAcknowledgementand checks itsStatus. - If the
StatusisCOMMIT_OK, A commits the state store change operation saved at Prepare and removes the lock. - If
StatusisCOMMIT_FAILED, A discards the state store change operation saved at the prepare step and deletes the lock.
- A receives a