Mental Model: Blockchains
Blockchains as databases
A distributed database is a database where some number of machines (nodes) store a full copy of the database, and agree on a set of rules for updating the database.
A blockchain is a special kind of distributed database.
The structure of this database is a key-value store. The snapshot of this key-value data, at any given time, is the "state" of the blockchain.
Each write operation ("transaction") transitions the state of the database from . Since any two given transactions may involve changes to data at the same keys, the state changes of transactions are applied in a discrete, serial order to only allow for valid state changes.
Transactions are batched into "blocks". The state transition applied to the database as a consequence of a block of transactions is .
A blockchain generally has some fair algorithm for selecting a node that gets the right to propose the next block. The selected node takes a set of transactions from the pool of all submitted transactions, assembles them into a block (up to a given capacity limit of the block), and processes it. This block is then propagated across the nodes of the blockchain network for verification → confirmation → enshrinement.
The database is updated once every fixed period ("block time") as a consequence of one block of transactions. The state updates of blocks are chained: each block's state updates are applied on the state in which the prior block left the database.
Blockchains as a record of accounts
The blockchain key-value database is a record of "accounts". The key-space is addresses, where each address is the unique identifier for an account. The value-space is the data that makes up an account.
The data associated with each account is owned by a private-key. Each account's address is derived from the corresponding public-key of the private-key that owns it. For example, in the Ethereum blockchain, an address 0xabc... is the first 20 bytes of the hash of the corresponding public-key.
A transaction encodes instructions for how to update the blockchain database. A user signs transaction data with their private-key to express their intent for making the updates that the transaction encodes.
At minimum, each transaction submitted by a user updates the nonce value stored in association with their account. Nonce is an increment-only count of transactions initiated by the account on the blockchain.
Blockchains as valuable infrastructure
What makes blockchains valuable, as a distributed database, is that:
- Anyone can permissionlessly join the network of nodes that run the blockchain.
- Anyone can permissionlessly submit a transaction to update the blockchain database.
- Anyone can permissionlessly read the current and historical state of the blockchain database, and re-execute its transactions, to verify the correctness of all state transitions.
- Once a database state change is confirmed, it is enshrined and cannot be rolled back.
These properties of permissionlessness, trustlessness and immutability make blockchains fantastic infrastructure for storing and updating, over time, a record of critical data that needs to be publicly auditable for honesty and correctness at all times.