当前位置:网站首页>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 .
边栏推荐
- Row lock analysis and deadlock
- vutils. make_ A little experience of grid () in relation to black and white images
- 深层次安全定义剖析及加密技术
- 物联网协议的王者:MQTT
- 如何将应用加入到deviceidle 白名单?
- [uniapp] the uniapp mobile terminal uses uni Troubleshooting of navigateback failure
- Get and set settings in 26class
- 背包问题求方案数
- Prometeus 2.34.0 新特性
- 请指教同花顺开户选选择哪家券商比较好?现在在线开户安全么?
猜你喜欢

数字签名论述及生成与优点分析

idea中文插件chinese(simplified) language pack

Tsinghua & Shangtang & Shanghai AI & CUHK proposed Siamese image modeling, which has both linear probing and intensive prediction performance!

Which low code platform is more friendly to Xiaobai? Here comes the professional evaluation!

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

Preparing for the Blue Bridge Cup and ccf-csp

无需人工先验!港大&同济&LunarAI&旷视提出基于语义分组的自监督视觉表征学习,显著提升目标检测、实例分割和语义分割任务!

How sparksql returns a specific day of the week by date -dayofweek function

Discussion and generation of digital signature and analysis of its advantages

Let torch cuda. is_ Experience of available() changing from false to true
随机推荐
[uniapp] the uniapp mobile terminal uses uni Troubleshooting of navigateback failure
牛客网:设计LRU缓存结构 设计LFU缓存结构
深层次安全定义剖析及加密技术
No manual prior is required! HKU & Tongji & lunarai & Kuangshi proposed self supervised visual representation learning based on semantic grouping, which significantly improved the tasks of target dete
Vscode usage - Remote SSH configuration description
[dynamic planning] Jianzhi offer II 091 Paint the house
请指教同花顺开户选选择哪家券商比较好?现在在线开户安全么?
How does Guosen Securities open an account? Is it safe to open a stock account through the link
Treasure and niche CTA animation material website sharing
How about opening a flush account? Is it safe? How to open a stock trading account
数据加密标准(DES)概念及工作原理
properties文件乱码
在国金证券开户怎么样?保障安全吗?
wechat_ Solve the problem of page Jump and parameter transfer by navigator in wechat applet
mysql Add column 失败 因为之前有数据,不是默认null 不行
wechat_微信小程序中解决navigator进行页面跳转并传递参数问题
MySQL add column failed because there was data before, not null by default
Row lock analysis and deadlock
二分查找法-1
Plt How to keep show() not closed