以太坊区块数据结构,以太坊 区块链
请查看相关英文文档
Ⅰ Ethereum Technology Series - Ethereum Data Structure
This article will introduce to you the data structure of Ethereum. In the last article we mentioned that in order to achieve The smart contract function uses an account-based model. Let’s take a look at the data structure in Ethereum.
Since it is an account-based model, we need to find the status of the account through the account address. Just like you can find various information about you in the bank through your bank card number. The simplest idea is of course a simple hash table where the key is the account address and the value is the account status. But there is a problem here that cannot be solved.
How do light nodes verify the legitimacy of accounts?
As we said in the previous article, there are two types of nodes in the blockchain, full nodes and light nodes. Light nodes only store block headers, so how can light nodes verify whether the account is legal?
This idea is consistent with the md5 verification we usually use. We will perform a hash operation on the information in the block to obtain the unique value of the information in the block. This value among all nodes in the blockchain The values are all the same.
In this process, we use a data structure Merkle Tree (hash tree). Let's first look at the schematic diagram of the Merkle Tree (hash tree).
The last article mentioned that the linked list (hash chain) in the blockchain is different from our usual linked lists in that the pointer is changed from the address to the hash pointer. The same is true here, hash tree and binary tree There are 2 differences
1. Change the address to a hash value
2. Only leaf nodes store data
Back to the previous question How do light nodes verify whether an account or transaction is on the chain?
The entire process is shown in the figure above
1. Light nodes need to determine whether an account is legal
2. Light nodes only store block headers , so when you get an account, you will send a request to the full node
3. The full node stores all account status and returns the hash value in the account path that needs to be calculated to the light node< br />
4. The light node calculates the root hash value locally. If the calculation result is consistent with its own storage, the account is legal. If it is inconsistent, the account is illegal.
Is this the data structure of account information in Ethereum?
Directly using such a data structure to store account information willThere are 2 problems
Difficult to find
The generated hash value is uncertain
The first problem should be easier to find, look for 1 in this tree The complexity required for each account is O(n) because there is no order.
The second problem is actually caused by disorder. In disordered combination, the hash values generated by each node for the same batch of accounts are inconsistent, which makes it impossible to reach a consensus.
Since both problems are related to order, can we solve the problem by using a hash sorting tree, similar to a binary sorting tree?
Using a sorted tree will bring about another problem
Insertion difficulties
Because the tree must be maintained in order, it is likely to cause Big changes to the tree structure.
Another data structure dictionary tree is used in Ethereum. Unlike hash trees, dictionary trees should be used in many places. Let's briefly look at the structure of the dictionary tree.
The dictionary tree can better solve the two shortcomings of the hash tree: 1. Difficulty in searching; 2. The generated hash value is uncertain and one of the shortcomings of the sorted binary tree is the difficulty of insertion.
But in the dictionary tree, we can see that the depth of the tree may be very deep due to some elements.
At this time we can further optimize and compress the same path. This is a compressed dictionary tree.
Combining the hash tree and the compressed dictionary tree, you can get the final data structure of the Ethereum storage account - MPT.
Just change the pointers in the compressed dictionary tree from addresses to pointers, and store the data in the leaf nodes.
After introducing the data structure of the status tree, we next discuss a question, what is the scope of the account status stored in the block. There are 2 options.
Only the account status of transactions generated in the block at that time is saved.
Save all global accounts.
We can look at these two methods, which are nothing more than a balance between space and time. Saving only the transactions generated in the current block means lazy loading (finding accounts only when needed). This cost in the blockchain is very high.Because the account you are looking for has never traded before, this will traverse the entire blockchain. Although another method of saving global accounts seems to consume a lot of space, it is fast to search, and we can optimize the space problem through other methods. So in the end, Ethereum chose the second method of reporting an error to all global accounts in every block.
Let’s take a look at how the state tree is saved in Ethereum.
You can see that although each block in Ethereum saves all accounts, it will point the unchanged account status to the previous node, and only store the changed status. This can Optimize space usage to the greatest extent.
After introducing the more complex state trees in Ethereum, we continue to look at the other two trees in Ethereum, the transaction tree and the receipt tree.
First, let me introduce why transaction tree & receipt tree are needed.
1. Transaction tree
Although Ethereum is an account-based model, just like a bank will not only store the balance of the bank card, but also store every money in the card How it came and how it was spent. The transaction tree stores all transactions included in the current block.
2. Receipt tree
Since the introduction of smart contracts has added a lot of complexity, Ethereum uses a receipt tree to store some additional information about transaction operations. For example, the execution log during the transaction process is included in the receipt tree for easy query. There is a one-to-one correspondence between the receipt tree and the transaction tree. There is a receipt for every transaction that occurs.
Unlike the state tree, the transaction tree and the receipt tree only maintain transactions that occur in the current block, because when a transaction occurs in the block, there is no need to search for another transaction, which means that it may be traversed before. Search operation of the entire blockchain.
Due to the fast block generation speed in Ethereum, we will face the problem of difficulty in traversing a large amount of data when we query some eligible transactions. The introduction of Bloom filters in the receipt tree can help us effectively alleviate this difficulty.
The Bloom filter performs a hash operation on each element in the large set and maps it to a smaller set. At this time, when another element comes to determine whether it is in the large set, there is no need to traverse the entire set. For a large set, perform a hash operation to find whether it exists in a small set. If it does not exist, it is definitely not in the large set. If it exists, it cannot explain any problems.
As shown in the figure above, the Bloom filter can only prove that a certain element is not in the set, but cannot prove that an element is not in the set.Elements are combined.
If we want to find a certain transaction in many blocks in Ethereum, we can use the Bloom filter to filter out blocks where the target transaction definitely does not exist, and then enter the receipt tree Continue to use the Bloom filter to filter, and the remaining transactions are the possible target transactions, and you can compare them one by one.
We introduced the core data structures of Ethereum, state tree & transaction tree & receipt tree. They all use the same data structure - hash compression dictionary tree. However, the status tree maintains a global account tree, and the transaction tree and receipt tree maintain transactions or receipts within this block.
After introducing the data structure, we will use several articles to introduce some core algorithms in Ethereum, such as consensus mechanism, mining algorithm, etc.
Ⅱ Introduction to Ethereum
How to buy ETH?
How to buy ETH with credit/debit card?
Binance (in the case of currency exchange) allows you to purchase ETH seamlessly through your browser. Operation steps:
You can also buy and sell ETH in the P2P market. You can buy tokens from other users through the mobile app Shannian Coin. Here are the steps:
Unlike Bitcoin, Ethereum is not just for cryptocurrency networks. It can also be used to build decentralized uses, and Ether, as a tradable token, has become the fuel of the ecosystem. So the main function of Ether is to provide power to the Ethereum network.
Not only that, Ether can be used to purchase goods and services like other traditional currencies.
Heat map of retailers accepting ether as a payment method
People can use Ethereum’s native currency, ETH, as digital currency or collateral. Some people also regard ETH as a store of value like Bitcoin. But it is different from Bitcoin because the high programmability of the Ethereum blockchain gives ETH more utility. It also means that Ether has become the source of vitality for decentralized financial applications, decentralized markets, exchanges, games and other applications.
ETH is not based on any bank, which means you will be responsible for your own funds. You can store your tokens on exchanges or in your own wallet. But remember, when you use a wallet for self-protection, be sure to keep the mnemonic securely so that if you lose access to the wallet, you can recover your money.
Once data is added to the Ethereum blockchain, it can hardly be changed or deleted. This means that the destination address and amount of funds to be sent must be carefully checked before the transaction is fixed (before the trading order is issued). When remitting large amounts, it is best to remit small amounts to the address for address confirmation.
Due to the smart contract being hacked, Ethereum was forced to hard fork in 2016 in order to reverse malicious transactions. However, this reversal is only an extreme measure for special events and is not the norm.
All transactions added to the Ethereum blockchain are visible to the public. Even if your real name is not shown on the Ethereum address, observers will know it by itsHis method determines your identity.
Since ETH is not a stable asset, it may cause you gains and losses. Some people choose to hold ether for the long term, betting that the network will become a global programmable settlement layer in the future. Others choose to use ether to trade with other Altcoins (counterfeit coins). Both strategies also have their own financial risks.
As a mainstay of decentralized finance (DeFi), ETH can also be used to lend, serve as collateral for loans, mint synthetic assets, or as a bet on the future.
Some investors may invest in Bitcoin for the long term and do not include other digital assets in their portfolios. Some investors are more flexible, mixing ETH and other fake coins in their portfolios, or using a certain percentage of their funds for short-term trading (such as day trading or swing trading). There is no universal way to make money in the market, and every investor must choose the strategy that best suits him based on his actual situation.
There are many ways to store tokens on the market, and each method has its advantages and disadvantages. Like anything else that is risky, the best way to choose is to diversify among the options available. Tonghe
Typically, storage solutions are either managed or unmanaged. A custody solution means you can entrust your funds to a third party (such as an exchange). At this time, you need to log in to the custodian platform to trade crypto assets.
A non-custodial solution is just the opposite: 3354 uses a cryptocurrency wallet to manage funds. Crypto wallets do not hold coins like physical wallets, but instead provide cryptographic keys that allow you to access your assets on the blockchain. Remember: When using a non-custodial wallet, always back up your mnemonics!
If you want to deposit ether on an exchange, please follow the steps below:
You need to deposit ETH into an exchange account to facilitate various trading activities. Storing ETH on Binance is easy and secure. The Binance ecosystem also allows you to earn income through loans, job rebates, airdrop promotions, and sweepstakes.
If you want to withdraw ETH from your exchange account, you need to follow these steps:
If you want to store ETH in your wallet, then there are two options: hot wallet and cold wallet.
Cryptocurrency wallets that are connected to the Internet in some way are called hot wallets. It is usually a mobile or desktop application and allows you to check your balance, or send and receive tokens. Because the hot wallet is connected to the Internet, it is easy to be attacked, but it is very convenient for people's daily use. Trust Wallet is a mobile wallet that supports multiple currencies.
A cold wallet is a crypto wallet that is not exposed to the Internet. Because there are no network attack vectors, the probability of being attacked is significantly reduced. However, cold wallets are not as portable and easy to use as hot wallets. Both hardware wallets and paper wallets are cold wallets. Nowadays, few people use outdated and risky banknote bags.
For details on the classification of crypto wallets, please see "Interpreting Crypto Wallet Types".
Vitalik Buterin designed the original Ethereum pattern. It consists of two rotational summation symbols (the Greek alphabet for local uniquenessDigging horses). Ethereum’s final logo (based on this pattern) was surrounded by a rhombus (called an octahedron) and four triangles. Similar to other cryptocurrencies, Ethereum is composed of standard Unicode symbols, so the price of Ethereum can be easily displayed in applications and websites. Just like the U.S. dollar uses the symbol $, the symbol used by Ethereum is
Related questions and answers: What does Ethereum mean?
Ethereum (ETH) is a digital token of Ethereum. Like other digital currencies, Ethereum can be bought and sold on the trading platform. However, due to the recent instability in currency prices, few people speculate in currencies now! But you don’t have to only speculate to get the virtual currency ETH. You can also get it through mining. Salmon miners can quickly obtain Ethereum, so you can quickly understand what Ethereum is!
Ⅲ What is the world’s second largest digital currency?
The world’s second largest digital currency is Ethereum (ETH). Ethereum is an open source public blockchain platform with smart contract functions. , providing a decentralized virtual machine to process peer-to-peer contracts through its dedicated cryptocurrency Ethereum. The concept of Ethereum was first proposed by programmer Vitalik Buterin between 2013 and 2014, inspired by Bitcoin, to the effect of "the next generation of cryptocurrency." and decentralized application platform, which began development through ICO crowdfunding in 2014. Ethereum is software that runs on a computer network, allowing data and programs called smart contracts to be exchanged without a central coordinator. Can be copied and processed on the network. The vision of Ethereum is to create a decentralized world computer that is non-stop, censorship-resistant, and self-sustaining.
Extended information
1. The connection between Ethereum and Bitcoin
1. Ethereum will also form a blockchain. Like Bitcoin, Ethereum will also form a blockchain. Blockchain The chain contains data blocks including transaction data and smart contract code. After certain participants create and dig out blocks, they are distributed to other participants to verify the compliance of the block.
2. Ethereum is a permissionless open network. Like Bitcoin, the Ethereum mainnet is open and permissionless. Anyone can connect to the network through downloaded or self-written software, and can start creating transactions and smart contracts, verifying transactions, and even mining or mining blocks without logging into a website or reporting to anyone.
3. Ethereum uses Proof of Work (PoW) for mining. Ethereum miners need to find a solution to a type of mathematical problem when creating a valid block. The solution process is unstructured, so a large amount of electricity must be invested. Computers are constantly calculating.
2. What are the core values of Ethereum?
The core value of Ethereum is to advocate scarcity. All activities on the Ethereum blockchain have brought about a general lack of ETH. As the native asset of Ethereum, ETH With a privileged role, miners will not affect the supply rules, only user consensus can be used by all on Ethereum.An inseparable connection is established between asset-based economic activities and financial applications and the scarcity of ETH.
IV What is Fossage Ethereum
Full name: Fossage Ethereum Blockchain.
The Ethereum blockchain is an open, permissionless blockchain that developers can use to create any type of application they want.
Forsage Ethereum is a global open source platform for decentralized applications. On Ethereum, you can write code to control digital values, run completely programmatically and be accessible from anywhere in the world. Ethereum is the foundation of a new era of the internet: built-in currency and payments. Users have personal data sovereignty and will not be monitored or stolen by various applications. Everyone has the right to use open financial systems. Based on a neutral and open source infrastructure that is not controlled by any organization or individual. The Ethereum mainnet was launched in 2015 and is the world's leading programmable blockchain.
IV How to maintain Ethereum
The maintenance of Ethereum is carried out through miners’ festivals and excitation points. Miner nodes refer to nodes that obtain Ether coins through computer mining. They maintain the Ethereum network while also earning profits for themselves. These miner nodes will compete for the right to produce the next block through a computing power competition, obtain the right to produce the next block by solving mathematical puzzles, and add new blocks to the blockchain. When adding a new block, the miner node needs to verify whether all transactions in the block are legal, such as whether they meet the requirements of the account balance, whether they meet the requirements of the smart contract, etc. If the verification passes, the block is added to the blockchain, otherwise it is rejected.
In addition to the maintenance of miner nodes, Ethereum also has some other maintenance measures, such as node management, smart contract review, etc. Node management refers to improving the stability and security of the network by increasing the number of nodes. Smart contract audit refers to the review and testing of new smart contracts to ensure that they comply with specifications and have no loopholes, so as to avoid security incidents caused by smart contract issues.
In short, the maintenance of Ethereum is to ensure the security and stability of the network through various measures such as miner nodes, node management, and Trembling Oak smart contract audits.