当前位置:网站首页>Introduction to Ethereum Technology Architecture
Introduction to Ethereum Technology Architecture
2022-06-26 18:03:00 【Here comes the classmate】
- Personal home page : Here comes the classmate
- 🤟 Copyright : This paper is written by 【 Here comes the classmate 】 original 、 stay CSDN First episode 、 If you need to reprint, please contact the blogger
- If it helps you , Welcome to your attention 、 give the thumbs-up 、 Collect and subscribe to columns
List of articles
One 、Ethereum Overall framework
Ethereum The overall architecture includes the underlying services 、 Core layer 、 There are three layers of top-level applications .
- Underlying services : Include P2P The Internet 、LevelDB、 Basic services such as cryptographic algorithms and sharding optimization ;
- Core layer : Blockchain 、 Core components such as consensus algorithms and virtual machines ;
- Top level application :API Interface 、 Smart contracts and decentralized applications (DApp).

Two 、 block
So called blocks , In fact, it can be defined as a data structure that records transactions and status results that occur over a period of time , It is a consensus on the current ledger status .
block = Block head + Deal list + Uncle block , The block structure is shown in the figure below .
1、 Block head
Block head = Parent block hash value (Prev Hash) + Block hash value (Uncles Hash)+ Status tree root hash value (state Root)+ Transaction tree root hash value (Transaction Root)+ Receipt tree root hash value (Receipt Root)+ Time stamp (Timestamp)+ random number (Nonce)
Ethereum The important change of blockchain block data structure is Add three to the block Merkle Trees , State tree 、 Transaction tree and receipt tree .
* 2、 Deal list
The transaction list is a series of transactions in the revenue block selected by the miner from the transaction pool .
* 3、 Shu block
Blocks that are not on the main chain and are passed by the main chain Uncles The orphan block of the field contained in the blockchain is called “ Shu block ” .
3、 ... and 、 Account
The account is indexed by address , The address is derived from the public key ( After taking the public key 20 byte ), Divided into external accounts (EOA) And the contract account , Both accounts are collectively referred to as “ State object ”( Storage status ), The external account stores the status of the etheric balance , Besides the balance, the contract account also has the status of smart contracts and their variables .
An account consists of four parts :
- Number of transactions at this address ( Resist heavy defense attacks )
- balance
- The binary code of the contract ( Only contract accounts have )
- Account storage ( The default is empty. )
1、 External accounts
- Created by the user , It can store ether currency , Controlled by public and private keys , Is the account actually controlled by the user .
- Three steps to generate an external account :
① Set the account private key , Common user password ;
② Use encryption algorithm to generate corresponding public key from private key (secp256k1 Elliptic algorithm );
③ Get the address according to the public key ( After the public key 20 byte ). - The private key is the only basis for the user to control the account , Need to back up frequently .
* 2、 Contract account
- Created by an external account , Is the account that contains the contract code , Not directly controlled by the private key file , Controlled by contract code ;
- The address of the contract account is the address of the contract creator when the contract is created , And transactions sent from this address ;
- Ethereum All operations on the blockchain are performed according to the transactions sent by the account , When the contract account receives a transaction message , The contract code will be executed as the transaction input , It will also be executed by each node , And the execution results as part of the new block validation .
* 3、 Public and private keys
At present, there are three forms of private keys :
- Private key: Randomly generated 256 Bit binary number ;
- Keystore & Password:Ethereum In the official wallet , Public and private key encryption is saved as JSON file , Store in keystore In the folder ;
- Memonic Code:BIP39 Put forward , Random generation 12~24 A word that is easy to remember , Create a random seed according to the function , And then generate a deterministic wallet in some way (Metamask Use ).
* 4、 wallet
Wallet includes Mist、Parity and Etherwall Other types .
Four 、 Data structure and storage
1、 Data organization form
Ethereum Use Merkle Parircia Trie Trees (MPT), Encrypted authentication data structure , The fusion Merkle Trees and Trie Trees are two data structures .
* 1.1 Merkle
- Tree data structure , But binary , Multi fork . Consists of a set of leaf nodes 、 A group of intermediate nodes and a root node ;
- The bottom leaf node contains basic data , Each intermediate node is a hash of its child nodes , The root node is a hash of its child nodes ;
- If there is malicious tampering and addition at the bottom of the tree , Will cause changes to the top and even the root of the tree .
* 1.2 Trie
- key It represents from the root to the corresponding value A real path ;
- If I have two value, They have the same prefix based key, The greater the proportion of the length of their same prefix , It represents these two value The closer you are in the tree , also Trie There will be no hash table like conflicts in the tree , One key Always correspond to one value.
* 1.3 MPT
- Ethereum be based on Merkle、Trie, Use MPT
- Each node is referenced by its hash value , be used for LevelDB Query in
- For storage in LevelDB Non leaf nodes in , Its representation in the database is :key The RLP Coded SHA3 Hash value ,value It's nodal RLP code , namely k-v:Hash(RLP( node ))-RLP( node )
MPT 4 Types of nodes :
① Blank nodes
② Leaf nodes : A list of key value pairs ,key Is a special hexadecimal code ,value yes RLP code
③ Expansion nodes : List of key value pairs , But here it is. value Is the hash value of other nodes , Connect to other nodes through this hash value
④ Branch nodes : A length of 17 A list of . It can be the end of the search path , It can also be the intermediate node of the path
The following figure takes the state tree as an example 
* 1.4 State tree
- Each node has 16 A child node , Each leaf node represents an account ;
- key Is the account address ,value Is the content of the account , Include 「nonce、balance、codeHash、storageRoot」.
* 1.5 The trading tree
- Each block has its own transaction tree ;
- key Is the transaction number ,value Is the content of the transaction .
* 1.6 The receipt tree
- Each block has a separate receipt tree , No need to update , Represents the corresponding receipt for each transaction ;
- key It's the index number , Used to guide the position of transactions related to this receipt ,value It is the contents of the receipt .
* 1.7 database LevelDB
Ethereum Three in total LevelDB database :
- BlockDB: The main content of the block is the block header + transaction ;
- StateDB: Status data of the account ;
- ExtrasDB: Receipts and other supporting information .
5、 ... and 、 Consensus mechanism
1、Ethash
- boycott ASIC;
- Let miners get random data from blockchain status , Calculate some from the end of the blockchain N Randomly selected transactions in blocks , Returns its hash . In fact, it is from a search space generated according to historical information , Select the qualified hash value through hash calculation , So it is no longer a simple hash operation , You also need to have enough memory space ;
- The transition to PoS.
* 2、Casper
Based on the number and time of digital currencies held by network participants, the benefits are distributed , Introduce the concept of currency age , Valid address 51% The attack can reach the consensus of seconds , A block in a few seconds
Added a punishment mechanism , By paying a deposit , A good piece yields , Bad pieces lose the deposit .
6、 ... and 、 transaction
Transaction refers to the signature packet of a message sent from an external account to another account on the blockchain , Include the sender's signature 、 The address of the receiver and the amount of etheric money transferred by the sender to the receiver .
1、 transaction cost
- Prevent users from sending too many meaningless transactions in the public chain , Waste computing resources ;
- Gas It is the basic unit used to measure the computing resources consumed by a transaction ;
- Gas Price yes Gas The unit of , At present, it is relatively stable , But it can float freely according to the demand ,Gas Price*Gas The higher the , The faster the transaction is processed ;
- Gas Limit Indicates the maximum amount that the sender is willing to pay for the execution of this transaction Gas Number , Protect users from the impact of error codes, resulting in excessive transaction costs .
* 2、 Transaction content
The transaction can be a simple Ethereum transfer , It can also be a message containing smart contract code
It includes the following :
- from
- to
- value
- data: Existing data fields , A delegate transaction is a transaction that creates or invokes a smart contract
- Gas Limit
- Gas Price
- nonce
- hash
- r、s、v: Three parts of transaction signature , The sender's private key pairs the transaction hash Make signature generation
* 3、 Type of transaction
- Transfer transaction ;
- Create transactions for smart contracts ;
- Execute transactions for smart contracts .
7、 ... and 、 Data encoding and compression
RLP Used to encode arbitrary binary data with nested structure , yes Ethereum Main method block of data serialization 、 Data structures such as transactions go through RLP Encoding processing , Then store it in the database .
8、 ... and 、API
- JSON-RPC API
- Web3.JavaScript API
Nine 、 Domain name service (ENS)
- Three main components : The registry 、 Parser 、 Registration service ;
- Get the name through auction ;
- There will be no revenue , All funds are deposited or destroyed .
边栏推荐
- How about opening an account at Guojin securities? Is it safe to open an account?
- 17.13 补充知识、线程池浅谈、数量谈、总结
- Li Kou daily question - day 28 -566 Reshape matrix
- 临时关闭MySQL缓存
- [npoi] C copy sheet template across workbooks to export Excel
- Daily record 2
- 一起备战蓝桥杯与CCF-CSP之大模拟炉石传说
- Get and set settings in 26class
- Hello, is it safe to open an online stock account and buy stocks now?
- How to open a stock account? Is it safe to open an account online now?
猜你喜欢

vutils.make_grid()与黑白图像有关的一个小体会

in和exsits、count(*)查询优化

Let torch cuda. is_ Experience of available() changing from false to true

Applet setting button sharing function

14 MySQL tutorial insert insert data

DoS及攻击方法详解

sparksql如何通过日期返回具体周几-dayofweek函数

pycharm的plt.show()如何保持不关闭

Preparing for the Blue Bridge Cup and ccf-csp

The difference between round and truncate in SQL (round or truncate)
随机推荐
A little experience of next (ITER (dataloader))
ZCMU--1367: Data Structure
Plt How to keep show() not closed
RSA加密解密详解
ZCMU--1367: Data Structure
丰富专业化产品线, 江铃福特领睿·极境版上市
MySQL index
Halcon's region: features of multiple regions (5)
Decision tree and random forest
接水面试题
sql中ROUND和TRUNCATE的区别(四舍五入还是截取小数点后几位)
【代码随想录-动态规划】T583、两个字符串的删除操作
JS common regular expressions
[buuctf.reverse] 126-130
用redis做用户访问数据统计HyperLogLog及Bitmap高级数据类型
How to open a stock account? Is it safe to open an account online now?
【动态规划】剑指 Offer II 091. 粉刷房子
Detailed explanation of dos and attack methods
RSA encryption and decryption details
力扣每日一题-第28天-566.重塑矩阵