Skip to main content

Two Phase Commit

Overview

Two-Phase Commit (2PC) is a distributed consensus protocol that ensures atomicity across multiple systems. In Compose Network, we use 2PC to coordinate cross-rollup transactions, guaranteeing that either all rollups execute their part of a transaction or none do - preventing partial execution that could lead to inconsistent states.

Think of it like a group decision: everyone must agree to proceed, or the entire operation is cancelled. This ensures data integrity across our network of rollups.

2PC flow

Properties

Agreement

No two processes decide different values - all rollups will reach the same decision.

Validity

  • If any rollup proposes to abort (0), then abort (0) is the only decision value
  • If all rollups propose to commit (1) and there are no failures, then commit (1) is the only possible decision value

Termination

If the leader (Shared Publisher) isn't faulty, all rollups eventually decide on a value.

Algorithm

  1. Vote Collection: Every rollup sends its vote to the Shared Publisher (leader)
  2. Leader Decision: The Shared Publisher waits for all votes with a timer
    • If all votes are received and are "commit" (1), it decides "commit" and broadcasts decided(1)
    • If any vote is "abort" (0) or a rollup fails to include its vote on time, it decides "abort" and broadcasts decided(0)
  3. Replica Decision: When a rollup receives decided(X), it decides X and executes accordingly

Compose Network Use Case

In our cross-rollup environment, 2PC ensures that complex transactions spanning multiple rollups either complete entirely or fail entirely. For example, when a user wants to swap tokens across rollups:

  • Rollup A: Must have sufficient tokens to send
  • Rollup B: Must have capacity to receive tokens
  • Both rollups: Must vote "commit" for the transaction to proceed

If either rollup votes "abort" (insufficient funds, network issues, etc.), the entire transaction is cancelled, maintaining consistency across the network.

Architecture Complete

The Two-Phase Commit protocol completes the Compose Network architecture, working together with Mailbox Contracts, the Composable Shared Bridge, and the Shared Publisher to create a robust, atomic cross-rollup composability system. This foundation enables complex multi-rollup applications while maintaining the security and consistency guarantees that users expect from blockchain systems.