The world state is divided by blocks; each new block representing a new world state. The structure of the world state is a mapping of two things:
- Account states
by using the standard recursive length prefix (RLP). This information is stored as a Merkle Patricia tree in a database backend that maintains a mapping of byte arrays to byte arrays. As a whole, the state is the sum total of database relationships in the state database.
Merkle Patricia Trees
Merkle Patricia trees are modified merkletrees where nodes represent individual characters from hashes rather than each node representing an entire hash. This permits the state data structure itself to represent not only the intrinsically correct paths in the data yet also the requisite cryptographic proofs that go into making sure that a piece of data was valid in the first place. In other words, by combining the structure of a standard merkletree with a Radix Tree structure, it helps to keep the blockchain valid. Since all searching and sorting algorithms in Ethereum must be filtered via this stringently correct database, the accuracy of information is guaranteed. The following is a search tree beginning with hexadecimal values a and 4:
- Root Node – The top (first) node in a tree.
- Child Node – A node directly connected to another node when moving away from the Root.
- Parent Node – The converse notion of a child.
- Sibling Nodes – A group of nodes with the same parent.
- Descendant Node – A node reachable by repeated proceeding from parent to child.
- Ancestor Node – A node reachable by repeated proceeding from child to parent.
- Leaf Node – A node with no children.
- Branch Node – A node with at least one child.
- Degree – A node’s number of subtrees.
- Edge – The linkage between a node and another node.
- Path – A node and edge series that connects a node to a descendant.
- Level – A node level is described by 1 + (the number of node-root connections).
- Node Height – The height of a node is the number of edges on the longest path between that node and a leaf.
- Tree Height – The height of a tree is the height of its root node.
- Depth – A node’s depth is the number of edges from the root node of the tree to the node.
- Forest – A forest is a collection of n ≥ 0 disjoint trees.
Recursive Length Prefix Encoding
Recursive Length Prefix Encoding (RLP) imposes a structure on data that intrinsically considers a prefixed hex value to position the data in the state database tree. This hex value determines the depth of a specific piece of data. There are two types of fundamental items one can encode in RLP:
- Strings of bytes
- Lists of other items
RLP encodes arrays of nested binary data to an arbitrary depth; it is the main serialization method for data in Ethereum. RLP encodes the structure of data only, so it doesn’t pay attention to the specific types of data being encoded. Positive RLP integers are represented with the most significant value stored at the lowest memory address (big endian) and without any leading zeros. As a result, the RLP integer value for 0 is represented by an empty byte array. If a non-empty deserialized integer starts with leading zeros, it is invalid. The global state database is encoded as RLP for fast traversal and inspection of data. RLP encoding creates a mapping between addresses and account states. Since it is stored on the node operator’s computers, the tree can be indexed and searched without network delay. RLP encodes values as byte-arrays, or as sequences of further values, which are subsequently encoded as byte-arrays.
There are 17 different elements in a block. The first 15 elements are part of what is known as the block header.
The Block Header Description
The information contained in a block beside the transactions list comprises of the following:
- Parent Hash – This is the Keccak-256 hash of the parent block’s header.
- Ommers Hash – This is the Keccak-256 hash of the ommer’s list portion of this block.
- Beneficiary – This is the 20-byte address to which all block rewards are transferred.
- State Root – This is the Keccak-256 hash of the root node of the state trie, after a block and its transactions are finalized.
- Transactions Root – This is the Keccak-256 hash of the root node of the trie structure populated with each transaction from a Block’s transaction list.
- Receipts Root – This is the Keccak-256 hash of the root node of the trie structure populated with the receipts of each transaction in the transactions list portion of the block.
- Logs Bloom – This is the bloom filter composed from indexable information (log address and log topic) contained in the receipt for each transaction in the transactions list portion of a block.
- Difficulty – This is the difficulty of this block – a quantity calculated from the previous block’s difficulty and its timestamp.
- Number – This is a quantity equal to the number of ancestor blocks behind the current block.
- Gas Limit – This is a quantity equal to the current maximum gas expenditure per block.
- Gas Used – This is a quantity equal to the total gas used in transactions in this block.
- Timestamp – This is a record of Unix’s time at this block’s inception.
- Extra Data – This byte-array of size 32 bytes or less contains extra data relevant to this block.
- Mix Hash – This is a 32-byte hash that verifies a sufficient amount of computation has been done on this block.
- Nonce – This is an 8-byte hash that verifies a sufficient amount of computation has been done on this block.
- Ommer Block Headers – These are the same components listed above for any ommers.
Transaction Series – That’s the block’s only non-header content.
Block Number and Difficulty
Note that is the difficulty of the genesis block. The Homestead difficulty parameter is used to affect dynamic homeostasis of time between blocks, as the time between blocks varies, as discussed below, as implemented in EIP-2. In the Homestead release, the exponential difficulty symbol, causes the difficulty to slowly increase (every 100,000 blocks) at an exponential rate, and thus increasing the block time difference, and putting time pressure on transitioning to proof-of-stake. This effect, known as the “difficulty bomb”, or “ice age”, was explained in EIP-649 and delayed and implemented earlier in EIP-2, was also modified in EIP-100 with the use of x, the adjustment factor, and the denominator 9, in order to target the mean block time including uncle blocks. Finally, in the Byzantium release, with EIP-649, the ice age was delayed by creating a fake block number, which is obtained by subtracting three million from the actual block number, which in other words reduced the time difference between blocks, in order to allow more time to develop proof-of-stake and preventing the network from “freezing” up.
Account creation definitively occurs with contract creation. Is related to: init. Lastly, there is the body which is the EVM-code that executes if/when the account containing it receives a message call.
The account state consists of details of any specific account during some specified world state. The account state is made up of four variables:
- Nonce – The number of transactions sent from this address, or the number of contract creations made by the account associated with this address.
- Balance – The amount of Wei owned by this account. Stored within the state database as a key/value pair.
- Storage_root – A 256-bit (32-byte) hash of the root node of a Merkle Patricia Tree that encodes the storage contents of the account.
- Code_hash – The hash of the EVM code of this account’s contract. Code hashes are stored in the state database. Code hashes are permanent and they are executed when the address belonging to that account receives a message call.
The Bloom Filter is composed of indexable information (logger address and log topics) contained in each log entry from the receipt of each transaction in the transactions list.