# How a Bitcoin transaction gets confirmed

> A process map exported from forks.world (https://forks.world). Author: Brian. Source: https://forks.world/p/cmv0kpt9x004ijn06dgbntm2w
> It describes who does what, in what order, and with which technology. Read the plain-language sections first; the JSON at the end is the exact, complete data.

## Summary

- 18 steps across 2 layers
- Persona: You, Miners
- Technology / systems: Your wallet, The network, The blockchain

## Pain points

Where this process hurts, worst first:

- **Race to solve a hard puzzle (proof of work)** (How a Bitcoin transaction gets confirmed; painful): Contested: mining uses a lot of electricity

## How to read this file

- A process is made of **layers**. The main layer is the top level; any step of kind `subprocess` opens a detail layer with its own lanes and steps.
- **Lanes** are either persona (people/roles) or technology (systems). Each step belongs to one lane; `using` lists tools a person uses for that step.
- Step kinds: `start`, `task`, `decision` (its arrows carry the answer as a label), `subprocess`, `end`.

## How a Bitcoin transaction gets confirmed

Lanes:
- You: person / role (id `you`)
- Your wallet: technology / system (id `wallet`)
- The network: technology / system (id `net`)
- Miners: person / role (id `miners`)
- The blockchain: technology / system (id `chain`)

Steps, in the order they run:

1. **Send bitcoin to an address** [start; You; id `b1`]
   - then Sign the transaction with your private key
2. **Sign the transaction with your private key** [task; Your wallet; id `b2`]
   - then Broadcast it to the network
3. **Broadcast it to the network** [task; The network; id `b3`]
   - then Nodes check: valid signature and enough funds
4. **Nodes check: valid signature and enough funds** [task; The network; id `b4`]
   - then Is it valid?
5. **Is it valid?** [decision; The network; id `b5`]
   - if "Yes" go to Collected into a candidate block; if "No" go to Rejected
6. **Collected into a candidate block** [task; Miners; id `b6`]
   - then Race to solve a hard puzzle (proof of work)
7. **Race to solve a hard puzzle (proof of work)** [subprocess; Miners; id `b7`] ⚠ PAIN POINT (painful): Contested: mining uses a lot of electricity, opens the detail layer "Proof of work"
   - then One miner wins and broadcasts the block
8. **One miner wins and broadcasts the block** [task; The blockchain; id `b8`]
   - then Nodes verify and add the block
9. **Nodes verify and add the block** [task; The network; id `b9`]
   - then One confirmation: your payment is in a block
10. **One confirmation: your payment is in a block** [task; You; id `b10`]
   - then Wait for more blocks on top, often six
11. **Wait for more blocks on top, often six** [task; You; id `b11`]
   - then Practically irreversible
12. **Practically irreversible** [end; The blockchain; id `b12`]
13. **Rejected** [end; The network; id `b5a`]

```mermaid
flowchart LR
  subgraph l_you["You"]
    n_b1(["Send bitcoin to an address"])
    n_b10["One confirmation: your payment is in a block"]
    n_b11["Wait for more blocks on top, often six"]
  end
  subgraph l_wallet["Your wallet"]
    n_b2["Sign the transaction with your private key"]
  end
  subgraph l_net["The network"]
    n_b3["Broadcast it to the network"]
    n_b4["Nodes check: valid signature and enough funds"]
    n_b5{"Is it valid?"}
    n_b5a(["Rejected"])
    n_b9["Nodes verify and add the block"]
  end
  subgraph l_miners["Miners"]
    n_b6["Collected into a candidate block"]
    n_b7[["Race to solve a hard puzzle (proof of work)"]]
  end
  subgraph l_chain["The blockchain"]
    n_b8["One miner wins and broadcasts the block"]
    n_b12(["Practically irreversible"])
  end
  n_b1 --> n_b2
  n_b2 --> n_b3
  n_b3 --> n_b4
  n_b4 --> n_b5
  n_b5 -->|"Yes"| n_b6
  n_b5 -->|"No"| n_b5a
  n_b6 --> n_b7
  n_b7 --> n_b8
  n_b8 --> n_b9
  n_b9 --> n_b10
  n_b10 --> n_b11
  n_b11 --> n_b12
```

### Proof of work (detail of step "Race to solve a hard puzzle (proof of work)")

Lanes:
- Miners: person / role (id `miners`)

Steps, in the order they run:

1. **Combine the block data with a number (a nonce)** [start; Miners; id `p1`]
   - then Hash it
2. **Hash it** [task; Miners; id `p2`]
   - then Does the hash start with enough zeros?
3. **Does the hash start with enough zeros?** [decision; Miners; id `p3`]
   - if "Yes" go to Block found; if "No" go to Change the nonce and try again
4. **Block found** [end; Miners; id `p4`]
5. **Change the nonce and try again** [task; Miners; id `p5`]
   - then Hash it

```mermaid
flowchart LR
  subgraph l_miners["Miners"]
    n_p1(["Combine the block data with a number (a nonce)"])
    n_p2["Hash it"]
    n_p3{"Does the hash start with enough zeros?"}
    n_p5["Change the nonce and try again"]
    n_p4(["Block found"])
  end
  n_p1 --> n_p2
  n_p2 --> n_p3
  n_p3 -->|"Yes"| n_p4
  n_p3 -->|"No"| n_p5
  n_p5 --> n_p2
```

## Full data (JSON)

```json
{
  "title": "How a Bitcoin transaction gets confirmed",
  "maps": {
    "m_pow": {
      "id": "m_pow",
      "lanes": [
        {
          "id": "miners",
          "name": "Miners",
          "type": "person"
        }
      ],
      "steps": [
        {
          "id": "p1",
          "kind": "start",
          "lane": "miners",
          "next": [
            {
              "to": "p2"
            }
          ],
          "uses": [],
          "label": "Combine the block data with a number (a nonce)"
        },
        {
          "id": "p2",
          "kind": "task",
          "lane": "miners",
          "next": [
            {
              "to": "p3"
            }
          ],
          "uses": [],
          "label": "Hash it"
        },
        {
          "id": "p3",
          "kind": "decision",
          "lane": "miners",
          "next": [
            {
              "to": "p4",
              "label": "Yes"
            },
            {
              "to": "p5",
              "label": "No"
            }
          ],
          "uses": [],
          "label": "Does the hash start with enough zeros?"
        },
        {
          "id": "p5",
          "kind": "task",
          "lane": "miners",
          "next": [
            {
              "to": "p2"
            }
          ],
          "uses": [],
          "label": "Change the nonce and try again"
        },
        {
          "id": "p4",
          "kind": "end",
          "lane": "miners",
          "next": [],
          "uses": [],
          "label": "Block found"
        }
      ],
      "title": "Proof of work",
      "parent": {
        "map": "m_root",
        "step": "b7"
      }
    },
    "m_root": {
      "id": "m_root",
      "lanes": [
        {
          "id": "you",
          "name": "You",
          "type": "person"
        },
        {
          "id": "wallet",
          "name": "Your wallet",
          "type": "system"
        },
        {
          "id": "net",
          "name": "The network",
          "type": "system"
        },
        {
          "id": "miners",
          "name": "Miners",
          "type": "person"
        },
        {
          "id": "chain",
          "name": "The blockchain",
          "type": "system"
        }
      ],
      "steps": [
        {
          "id": "b1",
          "kind": "start",
          "lane": "you",
          "next": [
            {
              "to": "b2"
            }
          ],
          "uses": [],
          "label": "Send bitcoin to an address"
        },
        {
          "id": "b2",
          "kind": "task",
          "lane": "wallet",
          "next": [
            {
              "to": "b3"
            }
          ],
          "uses": [],
          "label": "Sign the transaction with your private key"
        },
        {
          "id": "b3",
          "kind": "task",
          "lane": "net",
          "next": [
            {
              "to": "b4"
            }
          ],
          "uses": [],
          "label": "Broadcast it to the network"
        },
        {
          "id": "b4",
          "kind": "task",
          "lane": "net",
          "next": [
            {
              "to": "b5"
            }
          ],
          "uses": [],
          "label": "Nodes check: valid signature and enough funds"
        },
        {
          "id": "b5",
          "kind": "decision",
          "lane": "net",
          "next": [
            {
              "to": "b6",
              "label": "Yes"
            },
            {
              "to": "b5a",
              "label": "No"
            }
          ],
          "uses": [],
          "label": "Is it valid?"
        },
        {
          "id": "b5a",
          "kind": "end",
          "lane": "net",
          "next": [],
          "uses": [],
          "label": "Rejected"
        },
        {
          "id": "b6",
          "kind": "task",
          "lane": "miners",
          "next": [
            {
              "to": "b7"
            }
          ],
          "uses": [],
          "label": "Collected into a candidate block"
        },
        {
          "id": "b7",
          "kind": "subprocess",
          "lane": "miners",
          "next": [
            {
              "to": "b8"
            }
          ],
          "pain": {
            "note": "Contested: mining uses a lot of electricity",
            "level": 2
          },
          "uses": [],
          "child": "m_pow",
          "label": "Race to solve a hard puzzle (proof of work)"
        },
        {
          "id": "b8",
          "kind": "task",
          "lane": "chain",
          "next": [
            {
              "to": "b9"
            }
          ],
          "uses": [],
          "label": "One miner wins and broadcasts the block"
        },
        {
          "id": "b9",
          "kind": "task",
          "lane": "net",
          "next": [
            {
              "to": "b10"
            }
          ],
          "uses": [],
          "label": "Nodes verify and add the block"
        },
        {
          "id": "b10",
          "kind": "task",
          "lane": "you",
          "next": [
            {
              "to": "b11"
            }
          ],
          "uses": [],
          "label": "One confirmation: your payment is in a block"
        },
        {
          "id": "b11",
          "kind": "task",
          "lane": "you",
          "next": [
            {
              "to": "b12"
            }
          ],
          "uses": [],
          "label": "Wait for more blocks on top, often six"
        },
        {
          "id": "b12",
          "kind": "end",
          "lane": "chain",
          "next": [],
          "uses": [],
          "label": "Practically irreversible"
        }
      ],
      "title": "How a Bitcoin transaction gets confirmed",
      "parent": null
    }
  }
}
```
