1. 賬戶
賬戶類型
Ethereum has two account types:
- Externally-owned – controlled by anyone with the private keys
- Contract – a smart contract deployed to the network, controlled by code.
Both account types have the ability to:
- Receive, hold and send ETH and tokens
- Interact with deployed smart contracts
不同
Externally-owned
- Creating an account costs nothing 創(chuàng)建一個帳戶不花錢
- Can initiate transactions 可以發(fā)起交易
- Transactions between externally-owned accounts can only be ETH transfers 外部賬戶之間的交易只能是ETH轉(zhuǎn)賬
Contract
- Creating an account has a cost because you're using network storage 創(chuàng)建帳戶需要付費(fèi)款熬,因?yàn)槟谑褂镁W(wǎng)絡(luò)存儲
- Can only send transactions in response to receiving a transaction 只能發(fā)送交易以響應(yīng)收到交易
- Transactions from an external account to a contract account can trigger code which can execute many different actions, such as transferring tokens or even creating a new contract 外部帳戶到合同帳戶的交易可以觸發(fā)代碼,該代碼可以執(zhí)行許多不同的操作捻勉,例如轉(zhuǎn)移令牌甚至創(chuàng)建新合同
一個賬戶
Ethereum accounts have four fields:
-
nonce
– a counter that indicates the number of transactions sent from the account. This ensures transactions are only processed once.In a contract account, this number represents the number of contracts created by the account
balance
– the number of wei owned by this address. Wei is a denomination of ETH and there are 1e+18 wei per ETH.codeHash
– this hash refers to the code of an account on the Ethereum virtual machine (EVM). Contract accounts have code fragments programmed in that can perform different operations. This EVM code gets executed if the account gets a message call. It cannot be changed unlike the other account fields. All such code fragments are contained in the state database under their corresponding hashes for later retrieval. This hash value is known as a codeHash. For externally owned accounts, the codeHash field is the hash of an empty string. 該哈希表示以太坊虛擬機(jī)(EVM)上的帳戶代碼豁辉。合約帳戶具有編程的代碼片段庶橱,可以執(zhí)行不同的操作夷恍。如果帳戶收到消息調(diào)用,則將執(zhí)行此EVM代碼棉安。不能像其他帳戶字段一樣更改它底扳。所有這些代碼片段都包含在狀態(tài)數(shù)據(jù)庫中的相應(yīng)哈希值下,以供以后檢索贡耽。此哈希值稱為codeHash衷模。對于外部擁有的帳戶,codeHash字段是空字符串的哈希菇爪。storageRoot
– Sometimes known as a storage hash. A 256-bit hash of the root node of a Merkle Patricia trie that encodes the storage contents of the account (a mapping between 256-bit integer values), encoded into the trie as a mapping from the Keccak 256-bit hash of the 256-bit integer keys to the RLP-encoded 256-bit integer values. This trie encodes the hash of the storage contents of this account, and is empty by default. 有時稱為存儲哈希算芯。Merkle Patricia trie的根節(jié)點(diǎn)的256位哈希柒昏,該哈希對帳戶的存儲內(nèi)容進(jìn)行編碼(256位整數(shù)值之間的映射)凳宙,并編碼為Trie,作為來自256的Keccak 256位哈希的映射位整數(shù)鍵职祷,用于RLP編碼的256位整數(shù)值氏涩。此Trie對此帳戶的存儲內(nèi)容的哈希進(jìn)行編碼,默認(rèn)情況下為空有梆。
外部賬戶和密鑰對
An account is made up of a cryptographic pair of keys: public and private. They help prove that a transaction was actually signed by the sender and prevent forgeries. Your private key is what you use to sign transactions, so it grants you custody over the funds associated with your account. You never really hold cryptocurrency, you hold private keys – the funds are always on Ethereum's ledger.
This prevents malicious actors from broadcasting fake transactions because you can always verify the sender of a transaction.
If Alice wants to send ether from her own account to Bob’s account, Alice needs to create a transaction request and send it out to the network for verification. Ethereum’s usage of public-key cryptography ensures that Alice can prove that she originally initiated the transaction request. Without cryptographic mechanisms, a malicious adversary Eve could simply publicly broadcast a request that looks something like “send 5 ETH from Alice’s account to Eve’s account,” and no one would be able to verify that it didn’t come from Alice.
賬戶的創(chuàng)建
When you want to create an account most libraries will generate you a random private key.
A private key is made up of 64 hex characters and can be encrypted with a password.
Example:
fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036415f
The public key is generated from the private key using the Elliptic Curve Digital Signature Algorithm.
You get a public address for your account by taking the last 20 bytes of the public key and adding 0x
to the beginning.
Here's an example of creating an account in the console using GETH's personal_newAccount
> personal.newAccount()
Passphrase:
Repeat passphrase:
"0x5e97870f263700f46aa00d967821199b9bc5a120"
> personal.newAccount("h4ck3r")
"0x3d80b31a78c30fc628f20b2c89d7ddbf6e53cedc"
It is possible to derive new public keys from your private key but you cannot derive a private key from public keys. This means it's vital to keep a private key safe and, as the name suggests, PRIVATE.
You need a private key to sign messages and transactions which output a signature. Others can then take the signature to derive your public key, proving the author of the message. In your application, you can use a javascript library to send transactions to the network.
合約賬戶
Contract accounts also have a 42 character hexadecimal address:
Example:
0x06012c8cf97bead5deae237070f9587f8e7a266d
The contract address is usually given when a contract is deployed to the Ethereum Blockchain. The address comes from the creator's address and the number of transactions sent from that address (the “nonce”).
錢包
An account is not a wallet. A wallet is the keypair associated with a user-owned account, which allow a user to make transactions from or manage the account.
2. 交易
Transactions are cryptographically signed instructions from accounts. An account will initiate a transaction to update the state of the Ethereum network. The simplest transaction is transferring ETH from one account to another.
交易是來自帳戶的加密簽名指令是尖。一個賬戶將發(fā)起一個交易以更新以太坊網(wǎng)絡(luò)的狀態(tài)。最簡單的交易是將ETH從一個帳戶轉(zhuǎn)移到另一個帳戶泥耀。
什么是交易
An Ethereum transaction refers to an action initiated by an externally-owned account, in other words an account managed by a human, not a contract. For example, if Bob sends Alice 1 ETH, Bob's account must be debited and Alice's must be credited. This state-changing action takes place within a transaction.
以太坊交易是指由外部賬戶發(fā)起的操作饺汹,換句話說,是由人管理的賬戶痰催,而不是合約兜辞。例如,如果Bob向Alice發(fā)送1 ETH夸溶,則必須從Bob的帳戶中扣款逸吵,并向Alice的帳戶貸記。這種狀態(tài)改變動作發(fā)生在交易中缝裁。
Transactions, which change the state of the EVM, need to be broadcast to the whole network. Any node can broadcast a request for a transaction to be executed on the EVM; after this happens, a miner will execute the transaction and propagate the resulting state change to the rest of the network.
Transactions require a fee and must be mined to become valid. To make this overview simpler we'll cover gas fees and mining elsewhere.
A submitted transaction includes the following information:
-
recipient
– the receiving address (if an externally-owned account, the transaction will transfer value. If a contract account, the transaction will execute the contract code) -
signature
– the identifier of the sender. This is generated when the sender's private key signs the transaction and confirms the sender has authorised this transaction -
value
– amount of ETH to transfer from sender to recipient (in WEI, a denomination of ETH) -
data
– optional field to include arbitrary data -
gasLimit
– the maximum amount of gas units that can be consumed by the transaction. Units of gas represent computational steps -
gasPrice
– the fee the sender pays per unit of gas
Gas is a reference to the computation required to process the transaction by a miner. Users have to pay a fee for this computation. The gasLimit
and gasPrice
determine the maximum transaction fee paid to the miner.
The transaction object will look a little like this:
{
from: "0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8",
to: "0xac03bb73b6a9e108530aff4df5077c2b3d481e5a",
gasLimit: "21000",
gasPrice: "200",
nonce: "0",
value: "10000000000",
}
But a transaction object needs to be signed using the sender's private key. This proves that the transaction could only have come from the sender and was not sent fraudulently.
An Ethereum client like Geth will handle this signing process.
{
"id": 2,
"jsonrpc": "2.0",
"method": "account_signTransaction",
"params": [
{
"from": "0x1923f626bb8dc025849e00f99c25fe2b2f7fb0db",
"gas": "0x55555",
"gasPrice": "0x1234",
"input": "0xabcd",
"nonce": "0x0",
"to": "0x07a565b7ed7d7a678680a4c162885bedbb695fe0",
"value": "0x1234"
}
]
}
Example response:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"raw": "0xf88380018203339407a565b7ed7d7a678680a4c162885bedbb695fe080a44401a6e4000000000000000000000000000000000000000000000000000000000000001226a0223a7c9bcf5531c99be5ea7082183816eb20cfe0bbc322e97cc5c7f71ab8b20ea02aadee6b34b45bb15bc42d9c09de4a6754e7000908da72d48cc7704971491663",
"tx": {
"nonce": "0x0",
"gasPrice": "0x1234",
"gas": "0x55555",
"to": "0x07a565b7ed7d7a678680a4c162885bedbb695fe0",
"value": "0x1234",
"input": "0xabcd",
"v": "0x26",
"r": "0x223a7c9bcf5531c99be5ea7082183816eb20cfe0bbc322e97cc5c7f71ab8b20e",
"s": "0x2aadee6b34b45bb15bc42d9c09de4a6754e7000908da72d48cc7704971491663",
"hash": "0xeba2df809e7a612a0a0d444ccfa5c839624bdc00dd29e3340d46df3870f8a30e"
}
}
}
- the
raw
is the signed transaction in Recursive Length Prefix (RLP) encoded form - the
tx
is the signed transaction in JSON form
With the signature hash, the transaction can be cryptographically proven that it came from the sender and submitted to the network.
gas
As mentioned, transactions cost gas to execute. Simple transfer transactions require 21000 units of Gas.
So for Bob to send Alice 1ETH at a gasPrice
of 200 Gwei, he'll need to pay the following fee:
200*21000 = 4,200,000 GWEI
--or--
0.0042 ETH
Bob's account will be debited -1.0042 ETH
Alice's account will be credited +1.0 ETH
The miner processing the transaction will get +0.0042 ETH
Gas is required for any smart contract interaction too.
Any gas not used in a transaction is refunded to the user account.
交易生命周期
Once the transaction has been submitted the following happens:
Once you send a transaction, cryptography generates a transaction hash:
0x97d99bc7729211111a21b12c933c949d4f31684f1d6954ff477d0477538ff017
The transaction is then broadcast to the network and included in a pool with lots of other transactions.
-
A miner must pick your transaction and include it in a block in order to verify the transaction and consider it "successful".
-
You may end up waiting at this stage if the network is busy and miners aren't able to keep up. Miners will always prioritise transactions with higher
GASPRICE
because they get to keep the fees.如果網(wǎng)絡(luò)繁忙且礦工無法跟上扫皱,您可能最終會在此階段等待。礦工將始終優(yōu)先考慮較高的交易,
GASPRICE
因?yàn)樗麄兛梢员A糍M(fèi)用韩脑。
-
-
Your transaction will also get a block confirmation number. This is the number of blocks created since the block that your transaction was included in. The higher the number, the greater the certainty that the transaction was processed and recognised by the network. This is because sometimes the block your transaction was included in may not have made it into the chain. 您的交易還將獲得確認(rèn)號碼氢妈。這是自從您的交易包含在其中以來創(chuàng)建的區(qū)塊數(shù)。數(shù)字越大段多,網(wǎng)絡(luò)處理和識別交易的確定性就越高允懂。這是因?yàn)橛袝r您的交易所包含的區(qū)塊可能尚未進(jìn)入鏈中。
-
The larger the block confirmation number the more immutable the transaction is. So for higher value transactions, more block confirmations may be desired.
區(qū)塊確認(rèn)號越大衩匣,交易越不變蕾总。因此,對于更高價值的交易琅捏,可能需要更多的區(qū)塊確認(rèn)生百。
-
3. 區(qū)塊
Blocks are batches of transactions with a hash of the previous block in the chain. This links blocks together (in a chain) because hashes are cryptographically derived from the block data. This prevents fraud, because one change in any block in history would invalidate all the following blocks as all subsequent hashes would change and everyone running the blockchain would notice.
區(qū)塊是具有鏈中前一個區(qū)塊的哈希值的交易批次。這將塊鏈接在一起(成一個鏈)柄延,因?yàn)楣J菑膲K數(shù)據(jù)中加密得出的蚀浆。這可以防止欺詐,因?yàn)闅v史上任何區(qū)塊的一次更改都會使隨后的所有區(qū)塊失效搜吧,因?yàn)樗泻罄m(xù)哈希值都會更改市俊,并且運(yùn)行區(qū)塊鏈的每個人都會注意到。
為什么blocks
To ensure that all participants on the Ethereum network maintain a synchronized state and agree on the precise history of transactions, we batch transactions into blocks. This means dozens (or hundreds) of transactions are committed, agreed on, and synchronized on all at once.
By spacing out commits, we give all network participants enough time to come to consensus: even though transaction requests occur dozens of times per second, blocks on Ethereum are committed approximately once every fifteen seconds.
通過間隔提交滤奈,我們?yōu)樗芯W(wǎng)絡(luò)參與者提供了足夠的時間來達(dá)成共識:即使每秒發(fā)生數(shù)十次事務(wù)請求摆昧,以太坊上的區(qū)塊也大約每十五秒提交一次。
block如何工作
To preserve the transaction history, blocks are strictly ordered (every new block created contains a reference to its parent block), and transactions within blocks are strictly ordered as well. Except in rare cases, at any given time, all participants on the network are in agreement on the exact number and history of blocks, and are working to batch the current live transaction requests into the next block.
Once a block is put together (mined) by some miner on the network, it is propagated to the rest of the network; all nodes add this block to the end of their blockchain, and mining continues. The exact block-assembly (mining) process and commitment/consensus process is currently specified by Ethereum’s “Proof-of-Work” protocol.
為了保留事務(wù)歷史記錄蜒程,對塊進(jìn)行嚴(yán)格排序(每個創(chuàng)建的新塊均包含對其父塊的引用)绅你,并且對塊內(nèi)的事務(wù)也進(jìn)行嚴(yán)格排序。除極少數(shù)情況外昭躺,在任何給定時間忌锯,網(wǎng)絡(luò)上的所有參與者都同意區(qū)塊的確切數(shù)量和歷史記錄,并正在努力將當(dāng)前的實(shí)時交易請求分批到下一個區(qū)塊领炫。
一旦某個區(qū)塊被網(wǎng)絡(luò)上的某個礦工放在一起(挖掘)偶垮,它就會傳播到網(wǎng)絡(luò)的其余部分;所有節(jié)點(diǎn)都將此塊添加到其區(qū)塊鏈的末尾帝洪,并且繼續(xù)挖掘似舵。當(dāng)前,以太坊的“工作量證明”協(xié)議指定了確切的塊組裝(挖掘)過程和承諾/共識過程碟狞。
工作量證明
Proof of work means the following:
- Mining nodes have to spend a variable but substantial amount of energy, time, and computational power to produce a “certificate of legitimacy” for a block they propose to the network. This helps protect the network from spam/denial-of-service attacks, among other things*, since certificates are expensive to produce.
- Other miners who hear about a new block with a valid certificate of legitimacy must* accept the new block as the canonical next block on the blockchain.
- The exact amount of time needed for any given miner to produce this certificate is a random variable with high variance. This ensures that it is unlikely that two miners produce validations for a proposed next block simultaneously; when a miner produces and propagates a certified new block, they can be almost certain that the block will be accepted by the network as the canonical next block on the blockchain, without conflict (though there is a protocol for dealing with conflicts as well in the case that two chains of certified blocks are produced almost simultaneously).
什么是區(qū)塊
- Timestamp – the time when the block was mined.
- Block number – the length of the blockchain in blocks.
- Difficulty – the effort required to mine the block.
- mixHash – a unique identifier for that block.
- A parent hash – the unique identifier for the block that came before (this is how blocks are linked in a chain).
- Transactions list – the transactions included in the block.
- State root – the entire state of the system: account balances, contract storage, contract code and account nonces are inside.
- Nonce – a hash that, when combined with the mixHash, proves that the block has gone through proof of work.
區(qū)塊大小
A final important note is that blocks themselves are bounded in size. Each block has a block gas limit which is set by the network and the miners collectively: the total amount of gas expended by all transactions in the block must be less than the block gas limit. This is important because it ensures that blocks can’t be arbitrarily large. If blocks could be arbitrarily large, then less performant full nodes would gradually stop being able to keep up with the network due to space and speed requirements. The block gas limit at block 0 was initialized to 5,000; any miner who mines a new block can alter the gas limit by up to about 0.1% in either direction from the parent block gas limit. The gas limit as of April 2021 currently hovers around 15,000,000.
最后一個重要的注意事項(xiàng)是啄枕,塊本身的大小是有限的。每個區(qū)塊都有一個由網(wǎng)絡(luò)和礦工共同設(shè)定的區(qū)塊gas限制:區(qū)塊中所有交易消耗的gas總量必須小于區(qū)塊gas limit族沃。這很重要频祝,因?yàn)樗梢源_保塊不能任意大泌参。如果塊可以任意大,那么由于空間和速度的要求常空,性能較低的完整節(jié)點(diǎn)將逐漸無法跟上網(wǎng)絡(luò)沽一。block 0的塊gas limit被初始化為5,000;任何開采新區(qū)塊的礦工都可以從父區(qū)塊的gas limit中的任一方向?qū)as limit最多改變約0.1%漓糙。截至2021年4月铣缠,gas limit目前徘徊在1500萬左右。
4. 以太坊虛擬機(jī)(EVM)
The EVM’s physical instantiation can’t be described in the same way that one might point to a cloud or an ocean wave, but it does exist as one single entity maintained by thousands of connected computers running an Ethereum client.
The Ethereum protocol itself exists solely for the purpose of keeping the continuous, uninterrupted, and immutable operation of this special state machine; It's the environment in which all Ethereum accounts and smart contracts live. At any given block in the chain, Ethereum has one and only one 'canonical' state, and the EVM is what defines the rules for computing a new valid state from block to block.
EVM的物理實(shí)例無法以可能指向云或海浪的相同方式來描述昆禽,但它確實(shí)是由運(yùn)行以太坊客戶端的數(shù)千臺已連接計算機(jī)維護(hù)的單個實(shí)體而存在蝗蛙。
以太坊協(xié)議本身的存在僅僅是為了保持這種特殊狀態(tài)機(jī)的連續(xù),不間斷和不變的運(yùn)行醉鳖。這是所有以太坊賬戶和智能合約賴以生存的環(huán)境捡硅。在鏈中任何給定的區(qū)塊上,以太坊只有一個“規(guī)范”狀態(tài)盗棵,而EVM定義了計算區(qū)塊之間新的有效狀態(tài)的規(guī)則壮韭。
從賬本到狀態(tài)機(jī)
The analogy of a 'distributed ledger' is often used to describe blockchains like Bitcoin, which enable a decentralized currency using fundamental tools of cryptography. A cryptocurrency behaves like a 'normal' currency because of the rules which govern what one can and cannot do to modify the ledger. For example, a Bitcoin address cannot spend more Bitcoin than it has previously received. These rules underpin all transactions on Bitcoin and many other blockchains.
While Ethereum has its own native cryptocurrency (Ether) that follows almost exactly the same intuitive rules, it also enables a much more powerful function: smart contracts. For this more complex feature, a more sophisticated analogy is required. Instead of a distributed ledger, Ethereum is a distributed state machine. Ethereum's state is a large data structure which holds not only all accounts and balances, but a machine state, which can change from block to block according to a pre-defined set of rules, and which can execute arbitrary machine code. The specific rules of changing state from block to block are defined by the EVM.
通常使用“分布式分類帳”的類比來描述像比特幣這樣的區(qū)塊鏈,它使用密碼學(xué)的基本工具來實(shí)現(xiàn)去中心化的貨幣纹因。加密貨幣的行為類似于“正撑缥荩”貨幣,這是因?yàn)橐?guī)則支配著人們可以做什么和不可以做什么來修改分類賬瞭恰。例如屯曹,比特幣地址不能花費(fèi)比以前更多的比特幣。這些規(guī)則是比特幣和許多其他區(qū)塊鏈上所有交易的基礎(chǔ)寄疏。
以太坊擁有自己的本機(jī)加密貨幣(Ether)是牢,幾乎遵循完全相同的直觀規(guī)則僵井,但它還啟用了更強(qiáng)大的功能:智能合約陕截。對于此更復(fù)雜的功能,需要一個更復(fù)雜的類比批什。以太坊不是分布式賬本农曲,而是分布式狀態(tài)機(jī)。以太坊的狀態(tài)是一個大型數(shù)據(jù)結(jié)構(gòu)驻债,不僅擁有所有賬戶和余額乳规,而且擁有機(jī)器狀態(tài),它可以根據(jù)一組預(yù)定義的規(guī)則在不同的塊之間變化合呐,并且可以執(zhí)行任意機(jī)器代碼暮的。EVM定義在塊之間更改狀態(tài)的特定規(guī)則。
以太坊狀態(tài)轉(zhuǎn)換函數(shù)
The EVM behaves as a mathematical function would: Given an input, it produces a deterministic output. It therefore is quite helpful to more formally describe Ethereum as having a state transition function:
Y(S, T)= S'
Given an old valid state (S)
and a new set of valid transactions (T)
, the Ethereum state transition function Y(S, T)
produces a new valid output state S'
狀態(tài)
In the context of Ethereum, the state is an enormous data structure called a modified Merkle Patricia Trie, which keeps all accounts linked by hashes and reducible to a single root hash stored on the blockchain.
交易
Transactions are cryptographically signed instructions from accounts. There are two types of transactions: those which result in message calls and those which result in contract creation.
Contract creation results in the creation of a new contract account containing compiled smart contract bytecode. Whenever another account makes a message call to that contract, it executes its bytecode.
EVM 指令
The EVM executes as a stack machine with a depth of 1024 items. Each item is a 256-bit word, which was chosen for the ease of use with 256-bit cryptography (such as Keccak-256 hashes or secp256k1 signatures).
During execution, the EVM maintains a transient memory (as a word-addressed byte array), which does not persist between transactions.
Contracts, however, do contain a Merkle Patricia storage trie (as a word-addressable word array), associated with the account in question and part of the global state.
Compiled smart contract bytecode executes as a number of EVM opcodes, which perform standard stack operations like XOR
, AND
, ADD
, SUB
, etc. The EVM also implements a number of blockchain-specific stack operations, such as ADDRESS
, BALANCE
, KECCAK256
, BLOCKHASH
, etc.
EVM 實(shí)現(xiàn)
All implementations of the EVM must adhere to the specification described in the Ethereum Yellow paper.
Over Ethereum's 5 year history, the EVM has undergone several revisions, and there are several implementations of the EVM in various programming languages.
All Ethereum clients include an EVM implementation. Additionally there are multiple standalone implementations, including:
- Py-EVM - Python
- evmone - C++
- ethereumjs-vm - JavaScript
- eEVM - C++
- Hyperledger Burrow - Go
5. Gas and Fees
Gas is essential to the Ethereum network. It is the fuel that allows it to operate, in the same way that a car needs gasoline to run.
什么是Gas
Gas refers to the unit that measures the amount of computational effort required to execute specific operations on the Ethereum network.
Since each Ethereum transaction requires computational resources to execute, each transaction requires a fee. Gas refers to the fee required to successfully conduct a transaction on Ethereum
In essence, gas fees are paid in Ethereum's native currency, ether (ETH). Gas prices are denoted in Gwei, which itself is a denomination of ETH - each Gwei is equal to 0.000000001 ETH (10-9 ETH). For example, instead of saying that your gas costs 0.000000001 Ether, you can say your gas costs 1 Gwei.
本質(zhì)上淌实, gas fees是以太坊的本幣以太(ETH)支付的冻辩。Gas價格以Gwei表示猖腕,Gwei本身是ETH的名稱-每個Gwei等于0.000000001 ETH(10 -9 ETH)。例如恨闪,您可以說您的汽油成本為1 Gwei倘感,而不是說您的汽油成本為0.000000001 Ether。
為什么要存在Gas fees
In short, gas fees help keep the Ethereum network secure. By requiring a fee for every computation executed on the network, we prevent actors from spamming the network. In order to prevent accidental or hostile infinite loops or other computational wastage in code, each transaction is required to set a limit to how many computational steps of code execution it can use. The fundamental unit of computation is "gas".
Although a transaction includes a limit, any gas not used in a transaction is returned to the user.
6. 節(jié)點(diǎn)和客戶端
Ethereum is a distributed network of computers running software (known as nodes) that can verify blocks and transaction data. You need an application, known as a client, on your computer to "run" a node.
什么是節(jié)點(diǎn)和客戶端
"Node" refers to a running piece of client software. A client is an implementation of Ethereum that verifies all transactions in each block, keeping the network secure and the data accurate.
You can see a real-time view of the Ethereum network by looking at this map of nodes.
Many Ethereum clients exist, in a variety of programming languages such as Go, Rust, JavaScript, Python, C# .NET and Java. What these implementations have in common is they all follow a formal specification (originally the Ethereum Yellow Paper). This specification dictates how the Ethereum network and blockchain functions.
節(jié)點(diǎn)類型
If you want to run your own node, you should understand that there are different types of node that consume data differently. In fact, clients can run 3 different types of node - light, full and archive. There are also options of different sync strategies which enables faster synchronization time. Synchronization refers to how quickly it can get the most up-to-date information on Ethereum's state.
全節(jié)點(diǎn)
- Stores full blockchain data.
- Participates in block validation, verifies all blocks and states.
- All states can be derived from a full node.
- Serves the network and provides data on request.
輕節(jié)點(diǎn)
- Stores the header chain and requests everything else.
- Can verify the validity of the data against the state roots in the block headers.
- Useful for low capacity devices, such as embedded devices or mobile phones, which can't afford to store gigabytes of blockchain data.
存檔節(jié)點(diǎn)
- Stores everything kept in the full node and builds an archive of historical states. Needed if you want to query something like an account balance at block #4,000,000.
- These data represent units of terabytes which makes archive nodes less attractive for average users but can be handy for services like block explorers, wallet vendors, and chain analytics.
Syncing clients in any mode other than archive will result in pruned blockchain data. This means, there is no archive of all historical state but the full node is able to build them on demand.
為什么要運(yùn)行以太坊節(jié)點(diǎn)
Running a node allows you to trustlessly and privately use Ethereum while supporting the ecosystem.
受益于你
Running your own node enables you to use Ethereum in a truly private, self-sufficient and trustless manner. You don't need to trust the network because you can verify the data yourself with your client. "Don't trust, verify" is a popular blockchain mantra.
Your node verifies all the transactions and blocks against consensus rules by itself. This means you don’t have to rely on any other nodes in the network or fully trust them.
You won't have to leak your addresses and balances to random nodes. Everything can be checked with your own client.
Your dapp can be more secure and private if you use your own node. Metamask, MyEtherWallet and some other wallets can be easily pointed to your own local node.
您的節(jié)點(diǎn)將驗(yàn)證所有交易咙咽,并自行阻止遵守共識規(guī)則老玛。這意味著您不必依賴網(wǎng)絡(luò)中的任何其他節(jié)點(diǎn)或完全信任它們。
您不必將地址和余額泄漏給隨機(jī)節(jié)點(diǎn)钧敞。一切都可以由您自己的客戶檢查蜡豹。
如果使用自己的節(jié)點(diǎn),則dapp可以更安全和私有溉苛。Metamask余素,MyEtherWallet和其他一些錢包可以很容易地指向您自己的本地節(jié)點(diǎn)。
網(wǎng)絡(luò)受益
A diverse set of nodes is important for Ethereum’s health, security and operational resiliency.
- They provide access to blockchain data for lightweight clients that depend on it. In high peaks of usage, there need to be enough full nodes to help light nodes sync. Light nodes don't store the whole blockchain, instead they verify data via the state roots in block headers. They can request more information from blocks if they need it.
- Full nodes enforce the proof-of-work consensus rules so they can’t be tricked into accepting blocks that don't follow them. This provides extra security in the network because if all the nodes were light nodes, which don't do full verification, miners could attack the network and, for example, create blocks with higher rewards.
If you run a full node, the whole Ethereum network benefits from it.
多樣化的節(jié)點(diǎn)集對于以太坊的健康炊昆,安全性和運(yùn)營彈性至關(guān)重要桨吊。
- 他們?yōu)橐蕾囁妮p量級客戶端提供對區(qū)塊鏈數(shù)據(jù)的訪問。在使用高峰期凤巨,需要有足夠的完整節(jié)點(diǎn)來幫助燈光節(jié)點(diǎn)同步视乐。輕型節(jié)點(diǎn)不存儲整個區(qū)塊鏈,而是通過塊頭中的狀態(tài)根來驗(yàn)證數(shù)據(jù)敢茁。他們可以根據(jù)需要從塊中請求更多信息佑淀。
- 完整節(jié)點(diǎn)會強(qiáng)制執(zhí)行工作量證明共識規(guī)則,因此它們不會被欺騙來接受不遵循這些規(guī)則的塊彰檬。這提供了網(wǎng)絡(luò)中的額外安全性伸刃,因?yàn)槿绻泄?jié)點(diǎn)都是輕型節(jié)點(diǎn)(不進(jìn)行完全驗(yàn)證),則礦工可能會攻擊網(wǎng)絡(luò)逢倍,例如捧颅,創(chuàng)建具有更高獎勵的區(qū)塊。
如果您運(yùn)行一個完整的節(jié)點(diǎn)较雕,則整個以太坊網(wǎng)絡(luò)將從中受益碉哑。
運(yùn)行自己的節(jié)點(diǎn)
Projects
Select a client and follow their instructions
ethnode - Run an Ethereum node (Geth or Parity) for local development.
DAppNode - An operating system GUI for running Web3 nodes, including Ethereum and the beacon chain, on a dedicated machine.
Resources
- Running Ethereum Full Nodes: A Complete Guide Nov 7, 2019 - Justin Leroux
- Node Configuration Cheat Sheet Jan 5, 2019 - Afri Schoeden
- How To Install & Run a Geth Node Oct 4, 2020 - Sahil Sen
- How To Install & Run a OpenEthereum (fka. Parity) Node Sept 22, 2020 - Sahil Sen
替代品
Running your own node can be difficult and you don’t always need to run your own instance. In this case, you can use a third party API provider like Infura, Alchemy, or QuikNode. Alternatively ArchiveNode is a community-funded Archive node that hopes to bring archive data on the Ethereum blockchain to independent developers who otherwise couldn't afford it. For an overview of using these services, check out nodes as a services.
If somebody runs an Ethereum node with a public API in your community, you can point your light wallets (like MetaMask) to a community node via Custom RPC and gain more privacy than with some random trusted third party.
On the other hand, if you run a client, you can share it with your friends who might need it.
客戶端
The Ethereum community maintains multiple open-source clients, developed by different teams using different programming languages. This makes the network stronger and more diverse. The ideal goal is to achieve diversity without any client dominating to reduce any single points of failure.
This table summarizes the different clients. All of them are actively worked on and pass client tests.
Client | Language | Operating systems | Networks | Sync strategies | State pruning |
---|---|---|---|---|---|
Geth | Go | Linux, Windows, macOS | Mainnet, G?rli, Rinkeby, Ropsten | Fast, Full | Archive, Pruned |
OpenEthereum | Rust | Linux, Windows, macOS | Mainnet, Kovan, Ropsten, and more | Warp, Full | Archive, Pruned |
Nethermind | C#, .NET | Linux, Windows, macOS | Mainnet, G?rli, Ropsten, Rinkeby, and more | Fast, Full | Archive, Pruned |
Besu | Java | Linux, Windows, macOS | Mainnet, Rinkeby, Ropsten, and G?rli | Fast, Full | Archive, Pruned |
Trinity | Python | Linux, macOS | Mainnet, G?rli, Ropsten, and more | Full, Beam, Fast/Header | Archive |
For more on supported networks, read up on Ethereum networks.
不同實(shí)現(xiàn)的優(yōu)勢
Each client has unique use cases and advantages, so you should choose one based on your own preferences. Diversity allows implementations to be focused on different features and user audiences. You may want to choose a client based on features, support, programming language, or licences.
Go Ethereum
Go Ethereum (Geth for short) is one of the original implementations of the Ethereum protocol. Currently, it is the most widespread client with the biggest user base and variety of tooling for users and developers. It is written in Go, fully open source and licensed under the GNU LGPL v3.
OpenEthereum
OpenEthereum is a fast, feature-rich and advanced CLI-based Ethereum client. It's built to provide the essential infrastructure for speedy and reliable services which require fast synchronisation and maximum up-time. OpenEthereum’s goal is to be the fastest, lightest, and most secure Ethereum client. It provides a clean, modular codebase for:
- easy customisation.
- light integration into services or products.
- minimal memory and storage footprint.
OpenEthereum is developed using the cutting-edge Rust programming language and licensed under the GPLv3.
Nethermind
Nethermind is an Ethereum implementation created with the C# .NET tech stack, running on all major platforms including ARM. It offers great performance with:
- an optimized virtual machine
- state access
- networking and rich features like Prometheus/Graphana dashboards, seq enterprise logging support, JSON RPC tracing, and analytics plugins.
Nethermind also has detailed documentation, strong dev support, an online community and 24/7 support available for premium users.
Besu
Hyperledger Besu is an enterprise-grade Ethereum client for public and permissioned networks. It runs all of the Ethereum mainnet features, from tracing to GraphQL, has extensive monitoring and is supported by ConsenSys, both in open community channels and through commercial SLAs for enterprises. It is written in Java and is Apache 2.0 licensed.
Sync modes
- Full – downloads all blocks (including headers, transactions and receipts) and generates the state of the blockchain incrementally by executing every block.
- Fast (Default) – downloads all blocks (including headers, transactions and receipts), verifies all headers, and downloads the state and verifies it against the headers.
- Light – downloads all block headers, block data, and verifies some randomly.
- Warp sync – Every 5,000 blocks, nodes will take a consensus-critical snapshot of that block’s state. Any node can fetch these snapshots over the network, enabling a fast sync. More on Warp
- Beam sync – A sync mode that allows you to get going faster. It doesn't require long waits to sync, instead it back-fills data over time. More on Beam
- Header sync – you can use a trusted checkpoint to start syncing from a more recent header and then leave it up to a background process to fill the gaps eventually
You define the type of sync when you get set up, like so:
Setting up light sync in GETH
geth --syncmode "light"
Setting up header sync in Trinity
trinity --sync-from-checkpoint eth://block/byhash/0xa65877df954e1ff2012473efee8287252eee956c0d395a5791f1103a950a1e21?score=15,835,269,727,022,672,760,774
硬件
Hardware requirements differ by client but generally are not that high since the node just needs to stay synced. Don't confuse it with mining which requires much more computing power. Sync time and performance do improve with more powerful hardware however. Depending on your needs and wants, Ethereum can be run on your computer, home server, single-board computers or virtual private servers in the cloud.
An easy way to run your own node is using 'plug and play' boxes like DAppNode. It provides hardware for running clients and applications that depend on them with a simple user interface.
要求
Before installing any client, please ensure your computer has enough resources to run it. Minimum and recommended requirements can be found below, however the key part is the disk space. Syncing the Ethereum blockchain is very input/output intensive. It is best to have a solid-state drive (SSD). To run an Ethereum client on HDD, you will need at least 8GB of RAM to use as a cache.
最小要求
- CPU with 2+ cores
- 4 GB RAM minimum with an SSD, 8 GB+ if you have an HDD
- 8 MBit/s bandwidth
推薦要求
- Fast CPU with 4+ cores
- 16 GB+ RAM
- Fast SSD with at least 500 GB free space
- 25+ MBit/s bandwidth
Depending on which software and sync mode are you going to use, hundreds of GBs of disk space is need. Approximate numbers and growth can be found below.
Client | Disk size (fast sync) | Disk size (full archive) |
---|---|---|
Geth | 400GB+ | 6TB+ |
OpenEthereum | 280GB+ | 6TB+ |
Nethermind | 200GB+ | 5TB+ |
Besu | 750GB+ | 5TB+ |
單計算機(jī)上的以太坊
The most convenient and cheap way of running Ethereum node is to use a single board computer with ARM architecture like Raspberry Pi. Ethereum on ARM provides images of Geth, Parity, Nethermind, and Besu clients. Here's a simple tutorial on how to build and setup an ARM client.
Small, affordable and efficient devices like these are ideal for running a node at home.
ETH2 客戶端
There is a lot of instructions and information about Ethereum clients on the internet, here are few that might be helpful.
- Ethereum 101 - Part 2 - Understanding Nodes – Wil Barnes, 13 February 2019
- Running Ethereum Full Nodes: A Guide for the Barely Motivated – Justin Leroux, 7 November 2019
- Running an Ethereum Node – ETHHub, updated often
- Analyzing the hardware requirements to be an Ethereum full validated node – Albert Palau, 24 September 2018
- Running a Hyperledger Besu Node on the Ethereum Mainnet: Benefits, Requirements, and Setup – Felipe Faraggi, 7 May 2020
6.1 運(yùn)行一個節(jié)點(diǎn)
Running your own node provides you various benefits, opens new possibilities, and helps to support the ecosystem. This page will guide you through spinning up your own node and taking part in validating Ethereum transactions.
選擇一個方法
The first step in spinning up your node is choosing your approach. You have to choose the client (the software), the environment, and the parameters you want to start with. See all the available mainnet clients.
Client settings
Client implementations enable different sync modes and various other options. Sync modes represent different methods of downloading and validating blockchain data. Before starting the node, you should decide what network and sync mode to use. The most important things to consider is the disk space and sync time client will need.
All features and options can be found in documentation of each client. Various client configurations can be set by executing client with corresponding flags. You can get more information on flags from EthHub or client documentation. For testing purposes, you might prefer running client on one of testnet networks. See overview of supported networks.
Environment and hardware
Local or cloud
Ethereum clients are able to run on consumer grade computers and don't require special hardware like mining for example. Therefore you have various options for deploying based on your needs. To simplify let's think about running a node on both a local physical machine and a cloud server:
- Cloud
- Providers offer high server uptime, static public IP addresses
- Getting dedicated or virtual server can be more comfortable then building your own
- Trade off is trusting a third party - server provider
- Because of required storage size for full node, price of a rented server might get high
- Own hardware
- More trustless and sovereign approach
- One time investment
- An option to buy preconfigured machines
- You have to physically prepare, maintain, and potentially troubleshoot the machine
Both options have different advantages summed up above. If you are looking for a cloud solution, in addition to many traditional cloud computing providers, there are also services focused on deploying nodes, for example:
Hardware
However, a censorship-resistant, decentralized network should not rely on cloud providers. It's healthier for the ecosystem if you run your own node on hardware. The easiest options are preconfigured machines like:
Check the minimum and recommended disk space requirements for each client and sync mod. Generally, modest computing power should be enough. The problem is usually drive speed. During initial sync, Ethereum clients perform a lot of read/write operations, therefore SSD is strongly recommended. A client might not even be able to sync current state on HDD and get stuck a few blocks behind mainnet. You can run most of the clients on a single board computer with ARM. You can also use the Ethbian operating system for Raspberry Pi 4. This lets you [run a client by flashing the SD card. Based on your software and the hardware choices, the initial synchronization time and storage requirements may vary. Be sure to check sync times and storage requirements. Also make sure your internet connection is not limited by a bandwidth cap. It's recommended to use an unmetered connection since initial sync and data broadcasted to the network could exceed your limit.
Operating system
All clients support major operating systems - Linux, MacOS, Windows. This means you can run nodes on regular desktop or server machines with the operating system (OS) that suits you the best. Make sure your OS is up to date to avoid potential issues and security vulnerabilities.
部署節(jié)點(diǎn)
Getting the client software
First, download your preferred client software
You can simply download an executable application or installation package which suits your operating system and architecture. Always verify signatures and checksums of downloaded packages. Some clients also offer repositories for easier installation and updates. If you prefer, you can build from source. All of the clients are open source so you can build them from source code with the proper compiler.
Executable binaries for stable mainnet client implementations can be downloaded from their release pages:
Starting the client
Before starting Ethereum client software, perform a last check that your environment is ready. For example, make sure:
- There is enough disk space considering chosen network and sync mode.
- Memory and CPU is not halted by other programs.
- Operating system is updated to latest version.
- System has correct time and date.
- Your router and firewall accept connections on listening ports. By default Ethereum clients use a listener (TCP) port and a discovery (UDP) port, both on 30303 by default.
Run your client on a testnet first to help make sure everything is working correctly. Running a Geth light node should help. You need to declare any client settings that aren't default at the start. You can use flags or the config file to declare your preferred configuration. Check out your client's documentation for the specifics Client execution will initiate its core functions, chosen endpoints, and start looking for peers. After successfully discovering peers, the client starts synchronization. Current blockchain data will be available once the client is successfully synced to the current state.
Using the client
Clients offer RPC API endpoints that you can use to control the client and interact with the Ethereum network in various ways:
- Manually calling them with a suitable protocol (e.g. using
curl
) - Attaching a provided console (e.g.
geth attach
) - Implementing them in applications
Different clients have different implementations of the RPC endpoints. But there is a standard JSON-RPC which you can use with every client. For an overview read the JSON-RPC docs. Applications that need information from the Ethereum network can use this RPC. For example, popular wallet MetaMask lets you run a local blockchain instance and connect to it.
Reaching RPC
The default port of JSON-RPC is 8545
but you can modify the ports of local endpoints in the config file. By default, the RPC interface is only reachable on the localhost of your computer. To make it remotely accessible, you might want to expose it to the public by changing the address to 0.0.0.0
. This will make it reachable over local and public IP addresses. In most cases you'll also need to set up port forwarding on your router.
You should do this with caution as this will let anyone on the internet control your node. Malicious actors could access your node to bring down your system or steal your funds if you're using your client as a wallet.
A way around this is to prevent potentially harmful RPC methods from being modifiable. For example, with geth
, you can declare modifiable methods with a flag: --http.api web3,eth,txpool
.
You can also host access to your RPC interface by pointing service of web server, like Nginx, to your client's local address and port.
The most privacy-preserving and simple way to set up a publicly reachable endpoint, you can host it on your own Tor onion service. This will let you reach the RPC outside your local network without a static public IP address or opened ports. To do this:
- Install
tor
- Edit
torrc
config to enable hidden service with address of your client's RPC address and port - Restart
tor
service
Once you restart Tor, you'll get hidden service keys and a hostname in your desired directory. From then, your RPC will be reachable on a .onion
hostname.
Operating the node
You should regularly monitor your node to make sure it's running properly. You may need to do occasional maintenance.
Keeping node online
Your node doesn't have to be online nonstop but you should keep it online as much as possible to keep it in sync with the network. You can shut it down to restart it but keep in mind that:
- Shutting down can take up to a few minutes if the recent state is still being written on disk.
- Forced shut downs can damage the database.
- Your client will go out of sync with the network and will need to resync when you restart it.
This doesn't apply on Eth2 validator nodes. Taking your node offline will affect all services dependent on it. If you are running a node for staking purposes you should try to minimize downtime as much as possible.
您的節(jié)點(diǎn)不一定必須不間斷在線,但您應(yīng)盡可能使它保持在線狀態(tài)亮蒋,以使其與網(wǎng)絡(luò)保持同步扣典。您可以關(guān)閉它以重新啟動它,但請記咨骶痢:
- 如果最近的狀態(tài)仍在磁盤上贮尖,則關(guān)閉可能需要花費(fèi)幾分鐘。
- 強(qiáng)制關(guān)閉會損壞數(shù)據(jù)庫趁怔。
- 您的客戶端將與網(wǎng)絡(luò)不同步湿硝,并且在重新啟動時需要重新同步闰蛔。
這不適用于Eth2驗(yàn)證程序節(jié)點(diǎn)。使您的節(jié)點(diǎn)脫機(jī)將影響所有依賴于該節(jié)點(diǎn)的服務(wù)图柏。如果要出于放樣目的而運(yùn)行節(jié)點(diǎn)序六,則應(yīng)盡量減少停機(jī)時間。
Creating client service
Consider creating a service to run your client automatically on startup. For example on Linux servers, good practice would be creating a service that executes the client with proper config, under user with limited privileges and automatically restarts.
Updating client
You need to keep your client software up-to-date with the latest security patches, features, and EIPs. Especially before hard forks, make sure you are running the correct client version.
您需要使用最新的安全補(bǔ)丁蚤吹,功能和EIP使客戶端軟件保持最新例诀。特別是在硬分叉之前,請確保您運(yùn)行的是正確的客戶端版本裁着。
Running additional services
Running your own node lets you use services that require direct access to Ethereum client RPC. These are services built on top of Ethereum like layer 2 solutions, Eth2 clients, and other Ethereum infrastructure.
運(yùn)行自己的節(jié)點(diǎn)使您可以使用需要直接訪問以太坊客戶端RPC的服務(wù)繁涂。這些服務(wù)是建立在以太坊之上的服務(wù),例如第2層解決方案二驰,Eth2客戶端和其他以太坊基礎(chǔ)架構(gòu)扔罪。
Monitoring the node
"To properly monitor your node, consider collecting metrics. Clients provide metrics endpoints so you can get comprehensive data about your node. Use tools like InfluxDB or Prometheus to create databases which you can turn into visualizations and charts in software like Grafana. There are many setups for using this software and different Grafana dashboards for you to visualise your node and the network as a whole. TAs part of your monitoring, make sure to keep an eye on your machine's performance. During your node's initial sync, the client software may be very heavy on CPU and RAM. In addition to Grafana, you can use the tools your OS offers like htop
or uptime
to do this.
“要正確監(jiān)視節(jié)點(diǎn),請考慮收集指標(biāo)桶雀】蠼停客戶端提供指標(biāo)端點(diǎn),以便您可以獲取有關(guān)節(jié)點(diǎn)的全面數(shù)據(jù)矗积。使用InfluxDB或Prometheus之類的工具來創(chuàng)建數(shù)據(jù)庫全肮,然后可以在諸如Grafana的軟件中將其轉(zhuǎn)變?yōu)榭梢暬Ч蛨D表。使用此軟件的設(shè)置以及不同的Grafana儀表板棘捣,以使您的節(jié)點(diǎn)和整個網(wǎng)絡(luò)可視化辜腺。作為監(jiān)控的一部分,請務(wù)必注意計算機(jī)的性能乍恐。在節(jié)點(diǎn)的初始同步期間评疗,客戶端軟件可能是除了Grafana之外,您還可以使用操作系統(tǒng)提供的類似工具htop
或uptime
執(zhí)行此操作茵烈。
6.2 節(jié)點(diǎn)作為服務(wù)
Running your own Ethereum node can be challenging, especially when getting started or while scaling fast. There are a number of services that run optimized node infrastructures for you, so you can focus on developing your application or product instead. We'll explain how node services work, the pros and cons for using them and list providers if you are interested in getting started.
怎樣工作
Node service providers run distributed node clients behind the scenes for you, so you don't have to.
These services typically provide an API key that you can use to write to and read from the blockchain. They often including access to Ethereum testnets in addition to the mainnet.
Some services offer you your own dedicated node that they manage for you, while others use load balancers to distribute activity across nodes.
Almost all node services are extremely easy to integrate with, involving one line changes in your code to swap out your self hosted node, or even switch between the services themselves.
Often times node services will run a variety of node clients and types, allowing you to access full and archive nodes in addition to client specific methods in one API.
It's important to note that node services do not and should not store your private keys or information.
節(jié)點(diǎn)服務(wù)提供商為您在后臺運(yùn)行分布式節(jié)點(diǎn)客戶端百匆,因此您不必這樣做。
這些服務(wù)通常提供一個API密鑰瞧毙,您可以使用該API密鑰來寫入和讀取區(qū)塊鏈胧华。除主網(wǎng)外,它們通常還包括對以太坊測試網(wǎng)的訪問宙彪。
一些服務(wù)為您提供自己的專用節(jié)點(diǎn),由它們?yōu)槟芾碛星桑渌?wù)則使用負(fù)載平衡器在節(jié)點(diǎn)之間分配活動释漆。
幾乎所有節(jié)點(diǎn)服務(wù)都非常易于集成,涉及到代碼中的一行更改以換出您自己的托管節(jié)點(diǎn)篮迎,甚至在服務(wù)本身之間進(jìn)行切換男图。
通常示姿,節(jié)點(diǎn)服務(wù)將運(yùn)行各種節(jié)點(diǎn)客戶端和類型,從而允許您在一個API中訪問除客戶端特定方法之外的完整節(jié)點(diǎn)和存檔節(jié)點(diǎn)逊笆。
重要的是要注意栈戳,節(jié)點(diǎn)服務(wù)不也不應(yīng)存儲您的私鑰或信息。
好處
The main benefit for using a node service is not having to spend engineering time maintaining and managing nodes yourself. This allows you to focus on building your product rather than having to worry about infrastructure maintenance.
Running your own nodes can be very expensive from storage to bandwidth to valuable engineering time. Things like spinning up more nodes when scaling, upgrading nodes to the latest versions, and ensuring state consistency, can detract from building and spending resources on your desired web3 product.
缺點(diǎn)
By using a node service you are centralizing the infrastructure aspect of your product. For this reason, projects that hold decentralization to the upmost importance might prefer self-hosting nodes rather than outsourcing to a 3rd party.
Read more about the benefits of running your own node.
熱門節(jié)點(diǎn)服務(wù)
-
Alchemy
- Docs
- Features
- Free tier option
- Scale as you go
- Free archival data
- Analytics tools
- Dashboard
- Unique API endpoints
- Webhooks
- Direct support
-
BlockDaemon
- Docs
- Benefits
- Dashboard
- Per node basis
- Analytics
-
Chainstack
- Docs
- Features
- Free shared nodes
- Shared archive nodes
- GraphQL support
- RPC and WSS endpoints
- Dedicated full and archive nodes
- Fast sync time for dedicated deployments
- Bring your cloud
- Pay-per-hour pricing
- Direct 24/7 support
-
GetBlock
- Docs
- Features
- Access to 40+ blockchain nodes
- 40K free daily requests
- Unlimited number of API keys
- High connection speed at 1GB/sec
- Trace+Archive
- Advanced analytics
- Automated updates
- Technical support
-
Infura
- Docs
- Features
- Free tier option
- Scale as you go
- Paid archival data
- Direct Support
- Dashboard
-
QuikNode
- Features
- 7 day free trial
- Varied support
- Webhooks
- Dashboard
- Analytics
- Features
-
Rivet
- Docs
- Features
- Free tier option
- Scale as you go
7. 網(wǎng)絡(luò)
Since Ethereum is a protocol, this means there can be multiple independent "networks" conforming to this protocol that do not interact with each other.
Networks are different Ethereum environments you can access for development, testing, or production use cases. Your Ethereum account will work across the different networks but your account balance and transaction history wont carry over from the main Ethereum network. For testing purposes, it's useful to know which networks are available and how to get testnet ETH so you can play around with it.
由于以太坊是一種協(xié)議难裆,因此這意味著可以有多個獨(dú)立的“網(wǎng)絡(luò)”與該協(xié)議兼容子檀,并且彼此之間不會相互作用。
網(wǎng)絡(luò)是您可以訪問的不同以太坊環(huán)境乃戈,用于開發(fā)褂痰,測試或生產(chǎn)用例。您的以太坊賬戶將在不同的網(wǎng)絡(luò)上運(yùn)行症虑,但您的賬戶余額和交易歷史記錄不會從主要的以太坊網(wǎng)絡(luò)中繼承下來缩歪。出于測試目的,了解哪些網(wǎng)絡(luò)可用以及如何獲取testnet ETH很有用谍憔,以便您可以試用它匪蝙。
公共網(wǎng)絡(luò)
Public networks are accessible to anyone in the world with an internet connection. Anyone can read or create transactions on a public blockchain and validate the transactions being executed. Agreement on transactions and the state of the network is decided by a consensus of peers.
Mainnet
Mainnet is the primary public Ethereum production blockchain, where actual-value transactions occur on the distributed ledger.
When people and exchanges discuss ETH prices, they're talking about mainnet ETH.
Testnets
In addition to mainnet, there are public testnets. These are networks used by protocol developers or smart contract developers to test both protocol upgrades as well as potential smart contracts in a production-like environment before deployment to mainnet. Think of this as an analog to production versus staging servers.
It’s generally important to test any contract code you write on a testnet before deploying to the mainnet. If you're building a dapp that integrates with existing smart contracts, most projects have copies deployed to testnests that you can interact with.
Most testnets use a proof-of-authority consensus mechanism. This means a small number of nodes are chosen to validate transactions and create new blocks – staking their identity in the process. It's hard to incentivise mining on a proof-of-work testnet which can leave it vulnerable.
除主網(wǎng)外抓狭,還有公共測試網(wǎng)聪建。這些是協(xié)議開發(fā)人員或智能合約開發(fā)人員使用的網(wǎng)絡(luò),用于在部署到主網(wǎng)之前在類似生產(chǎn)的環(huán)境中測試協(xié)議升級以及潛在的智能合約诅福∩蛱酰可以將其視為生產(chǎn)服務(wù)器與登臺服務(wù)器的模擬需忿。
通常,在部署到主網(wǎng)上之前蜡歹,測試您在測試網(wǎng)上編寫的所有合同代碼都是很重要的屋厘。如果您要構(gòu)建一個與現(xiàn)有智能合約集成的dapp,則大多數(shù)項(xiàng)目都將副本部署到您可以與之交互的測試對象上月而。
大多數(shù)測試網(wǎng)都使用權(quán)威證明共識機(jī)制汗洒。這意味著選擇了少數(shù)節(jié)點(diǎn)來驗(yàn)證交易并創(chuàng)建新的塊,從而在過程中保全其身份父款。很難激勵在工作量證明測試網(wǎng)上進(jìn)行挖掘溢谤,這可能會使它容易受到攻擊。
G?rli
A proof-of-authority testnet that works across clients.
Kovan
A proof-of-authority testnet for those running OpenEthereum clients.
Rinkeby
A proof-of-authority testnet for those running Geth client.
Ropsten
A proof-of-work testnet. This means it's the best like-for-like representation of Ethereum.
Testnet Faucets
ETH on testnets has no real value; therefore, there are no markets for testnet ETH. Since you need ETH to actually interact with Ethereum, most people get testnet ETH from faucets. Most faucets are webapps where you can input an address which you request ETH to be sent to.
測試網(wǎng)上的ETH沒有實(shí)際價值憨攒;因此世杀,testnet ETH沒有市場。由于您需要ETH與以太坊進(jìn)行實(shí)際交互肝集,因此大多數(shù)人都從水龍頭那里獲得了testnet ETH瞻坝。大多數(shù)水龍頭都是webapp,您可以在其中輸入請求將ETH發(fā)送到的地址杏瞻。
私有網(wǎng)絡(luò)
An Ethereum network is a private network if its nodes are not connected to a public network (i.e. mainnet or a testnet). In this context, private only means reserved or isolated, rather than protected or secure.
Development networks
To develop an Ethereum application, you'll want to run it on a private network to see how it works before deploying it. Similar to how you create a local server on your computer for web development, you can create a local blockchain instance to test your dapp. This allows for much faster iteration than a public testnet.
There are projects and tools dedicated to assist with this. Learn more about development networks.
Consortium networks
The consensus process is controlled by a pre-defined set of nodes that are trusted. For example, a private network of known academic institutions that each govern a single node, and blocks are validated by a threshold of signatories within the network.
If a public Ethereum network is like the public internet, you can think of a consortium network as a private intranet.
8. 共識機(jī)制
When it comes to blockchains like Ethereum, which are in essence distributed databases, the nodes of the network must be able to reach agreement on the current state of the system. This is achieved using consensus mechanisms.
Although not a part of building a dapp, understanding consensus mechanisms will help explain things that are relevant to you and your users' experience, like gas prices and transaction times.
什么是共識機(jī)制
Consensus mechanisms (also known as consensus protocols or consensus algorithms) allow distributed systems (networks of computers) to work together and stay secure.
For decades, these mechanisms have been used to establish consensus among database nodes, application servers, and other enterprise infrastructure. In recent years, new consensus protocols have been invented to allow cryptoeconomic systems, such as Ethereum, to agree on the state of the network.
A consensus mechanism in a cryptoeconomic system also helps prevent certain kinds of economic attacks. In theory, an attacker can compromise consensus by controlling 51% of the network. Consensus mechanisms are designed to make this "51% attack" unfeasible. Different mechanisms are engineered to solve this security problem differently.
密碼經(jīng)濟(jì)系統(tǒng)中的共識機(jī)制也有助于防止某些類型的經(jīng)濟(jì)攻擊所刀。從理論上講衙荐,攻擊者可以通過控制51%的網(wǎng)絡(luò)來破壞共識。共識機(jī)制旨在使這種“ 51%攻擊”不可行浮创。設(shè)計了不同的機(jī)制來不同地解決此安全問題忧吟。
共識機(jī)制類型
Proof of work
Ethereum, like Bitcoin, currently uses a proof-of-work (PoW) consensus protocol.
Block creation
Proof-of-work is done by miners, who compete to create new blocks full of processed transactions. The winner shares the new block with the rest of the network and earns some freshly minted ETH. The race is won by whoever's computer can solve a math puzzle fastest – this produces the cryptographic link between the current block and the block that went before. Solving this puzzle is the work in "proof of work".
Security
The network is kept secure by the fact that you'd need 51% of the network's computing power to defraud the chain. This would require such huge investments in equipment and energy, you're likely to spend more than you'd gain.
More on proof-of-work (PoW)
Proof of stake
Ethereum has plans to upgrade to a proof-of-stake (PoS) consensus protocol.
Block creation
Proof-of-stake is done by validators who have staked ETH to participate in the system. A validator is chosen at random to create new blocks, share them with the network and earn rewards. Instead of needing to do intense computational work, you simply need to have staked your ETH in the network. This is what incentivises healthy network behaviour.
權(quán)益證明是由已抵押ETH參與系統(tǒng)的驗(yàn)證者完成的。隨機(jī)選擇一個驗(yàn)證器來創(chuàng)建新塊斩披,與網(wǎng)絡(luò)共享它們并獲得獎勵溜族。無需進(jìn)行大量的計算工作,您只需要將ETH放入網(wǎng)絡(luò)中即可雏掠。這就是增強(qiáng)健康網(wǎng)絡(luò)行為的原因斩祭。
Security
A proof-of-stake system is kept secure by the fact that you'd need 51% of the total staked ETH to defraud the chain. And that your stake is slashed for malicious behaviour.
事實(shí)證明您需要抵押的ETH總量的51%來欺騙鏈條,從而確保了權(quán)益證明系統(tǒng)的安全乡话。而且摧玫,您的賭注也因惡意行為而大為減少。
More on proof-of-stake (PoS)
8.1 工作量證明
Ethereum, like Bitcoin, currently uses a consensus protocol called Proof-of-work (PoW). This allows the nodes of the Ethereum network to agree on the state of all information recorded on the Ethereum blockchain, and prevents certain kinds of economic attacks.
Over the next few years, proof-of-work will be phased out in favour of proof of stake. This will also phase out mining from Ethereum. For more details on timing, check the progress of the Eth2 merge upgrade.
什么是工作量證明
Proof of Work (PoW) is the mechanism that allows the decentralized Ethereum network to come to consensus, or agree on things like account balances and the order of transactions. This prevents users "double spending" their coins and ensures that the Ethereum chain is incredibly difficult to attack or overwrite.
工作量證明和礦工
Proof-of-work is the underlying algorithm that sets the difficulty and rules for the work miners do. Mining is the "work" itself. It's the act of adding valid blocks to the chain. This is important because the chain's length helps the network spot the valid Ethereum chain and understand Ethereum's current state. The more "work" done, the longer the chain, and the higher the block number, the more certain the network can be of the current state of things.
工作量證明是為礦工設(shè)定難度和規(guī)則的基礎(chǔ)算法绑青。采礦本身就是“工作”诬像。這是向鏈中添加有效塊的行為。這一點(diǎn)很重要闸婴,因?yàn)殒湹拈L度有助于網(wǎng)絡(luò)發(fā)現(xiàn)有效的以太坊鏈并了解以太坊的當(dāng)前狀態(tài)坏挠。完成的“工作”越多,鏈條越長邪乍,塊數(shù)越高降狠,網(wǎng)絡(luò)就可以更加確定當(dāng)前狀態(tài)。
以太坊的工作量證明如何工作庇楞?
Ethereum transactions are processed into blocks. Each block has a:
- block difficulty – for example: 3,324,092,183,262,715
- mixHash – for example:
0x44bca881b07a6a09f83b130798072441705d9a665c5ac8bdf2f39a3cdf3bee29
- nonce – for example:
0xd3ee432b4fb3d26b
This block data is directly related to PoW.
The work in proof of work
The proof-of-work protocol, known as Ethash, requires miners to go through an intense race of trial and error to find the nonce for a block. Only blocks with a valid nonce can be added to the chain.
When racing to create a block, a miner will repeatedly put a dataset, that you can only get from downloading and running the full chain (as a miner does), through a mathematical function. This is to generate a mixHash that is below a target nonce, as dictated by the block difficulty. The best way to do this is through trial and error.
The difficulty determines the target for the hash. The lower the target, the smaller the set of valid hashes. Once generated, this is incredibly easy for other miners and clients to verify. Even if one transaction was to change, the hash would be completely different, signalling fraud.
Hashing makes fraud easy to spot. But PoW as a process is also a big deterrent to attacking the chain.
Proof-of-work and security
Miners are incentivised to do this work on the main Ethereum chain. There is little incentive for a subset of miners to start their own chain – it undermines the system. Blockchains rely on having a single state as a source of truth. And users will always choose the longest or "heaviest" chain.
The objective of PoW is to extend the chain. The longest chain is most believable as the valid one because it's had the most computational work done on it. Within Ethereum's PoW system it's nearly impossible to create new blocks that erase transactions or create fake ones, or maintain a second chain. That's because a malicious miner would need to always be solving the block nonce faster than everyone else.
To consistently create malicious, yet valid, blocks, you'd need over 51% of the network mining power to beat everyone else. You'd need a lot of computing power to be able to do this amount of "work". And the energy spend might even outweigh the gains you'd make in an attack.
激勵礦工在以太坊主鏈上進(jìn)行這項(xiàng)工作榜配。一部分礦工建立自己的鏈,幾乎沒有動力–這破壞了該系統(tǒng)吕晌。區(qū)塊鏈依賴于將單一狀態(tài)作為真理的來源蛋褥。用戶將始終選擇最長或“最重”的鏈。
PoW的目標(biāo)是延長鏈條睛驳。最長的鏈?zhǔn)怯行ф溊有模虼俗羁尚牛驗(yàn)樗淹瓿闪俗疃嗟挠嬎愎ぷ鞣Ψ小T谝蕴坏腜oW系統(tǒng)中淫茵,幾乎不可能創(chuàng)建新塊來擦除交易,創(chuàng)建假交易或維持第二條鏈屎蜓。這是因?yàn)閻阂獾V工將始終需要比其他所有人更快地解決區(qū)塊隨機(jī)數(shù)痘昌。
為了持續(xù)創(chuàng)建惡意但有效的阻止,您需要超過51%的網(wǎng)絡(luò)挖掘能力才能擊敗其他所有人炬转。您需要大量的計算能力才能完成這一“工作”辆苔。而且能量消耗甚至可能超過您在攻擊中所獲得的收益。
Proof-of-work economics
PoW is also responsible for issuing new currency into the system and incentivising miners to do the work.
Miners who successfully create a block are rewarded in 2 freshly minted ETH and all the transaction fees within the block. A miner may also get 1.75ETH for an uncle block. This is a valid block, created simultaneously to the succcessful block, by another miner. This usually happens due to network latency.
PoW還負(fù)責(zé)向系統(tǒng)中發(fā)行新貨幣并激勵礦工從事這項(xiàng)工作扼劈。
成功創(chuàng)建區(qū)塊的礦工將獲得2個新鮮鑄造的ETH以及該區(qū)塊內(nèi)的所有交易費(fèi)用的獎勵驻啤。礦工還可以獲得1.75ETH的叔叔塊。這是另一個礦工與成功塊同時創(chuàng)建的有效塊荐吵。這通常是由于網(wǎng)絡(luò)延遲而發(fā)生的骑冗。
最后
In distributed networks, a transaction has "finality" when it's part of a block that can't change.
Because miners work in a decentralized way, it's possible for two valid blocks to be mined at the same time. This creates a temporary fork. Eventually one chain will become the accepted chain once a subsequent block has been mined and added, making it longer.
But to complicate things further, transactions that were rejected on the temporary fork may have been included in the accepted chain. This means it could get reversed. So finality refers to the time you should wait before considering a transaction irreversible. For Ethereum the recommended time is 6 blocks or just over 1 minute. Following that you can say with relative confidence that the transaction has been a success. Of course, you can wait longer for even greater assurances.
This is something to bear in mind when designing dapps, as it would be a poor user experience to misrepresent transaction information to your users. Especially if the transaction is high value.
Remember, this timing doesn't include the wait times for having a transaction picked up by a miner.
在分布式網(wǎng)絡(luò)中,當(dāng)事務(wù)是不可更改的塊的一部分時先煎,它具有“最終性”贼涩。
由于礦工以分散的方式工作,因此有可能同時開采兩個有效區(qū)塊薯蝎。這將創(chuàng)建一個臨時叉遥倦。最終,一旦挖掘并添加了下一個塊占锯,則一條鏈將成為可接受的鏈袒哥,從而使鏈更長。
但是消略,更復(fù)雜的是堡称,在臨時分支上被拒絕的交易可能已包含在接受的鏈中。這意味著它可能會被逆轉(zhuǎn)艺演。因此却紧,確定性是指您在考慮不可逆交易之前應(yīng)等待的時間。對于以太坊胎撤,建議的時間是6塊或剛好超過1分鐘晓殊。之后,您可以相對確信地說該交易已成功哩照。當(dāng)然挺物,您可以等待更長的時間以獲得更大的保證。
設(shè)計dapp時要牢記這一點(diǎn)飘弧,因?yàn)閷⒂脩翦e誤地表示交易信息會給用戶帶來糟糕的體驗(yàn)识藤。特別是如果交易是高價值的。
請記住次伶,這個時間不包括礦工提起交易的等待時間痴昧。
優(yōu)缺點(diǎn)
Pros | Cons |
---|---|
PoW is neutral. You don't need ETH to get started and block rewards allow you to go from 0ETH to a positive balance. With proof of stake you need ETH to start with. | PoW uses up so much energy that it's bad for the environment. |
PoW is a tried and tested consensus mechanism that has kept Bitcoin and Ethereum secure and decentralized for many years. | If you want to mine, you need such specialized equipment that it's a big investment to start. |
Compared to proof-of-stake it's relatively easy to implement. | Due to increasing computation needed, mining pools could potentially dominate the mining game, leading to centralization and security risks. |
優(yōu)點(diǎn) | 缺點(diǎn) |
---|---|
PoW是中性的。您不需要ETH上手冠王,而區(qū)塊獎勵可以使您從0ETH達(dá)到正余額赶撰。有了股權(quán)證明,您需要ETH入手。 | PoW消耗了太多能量豪娜,對環(huán)境不利餐胀。 |
PoW是一種久經(jīng)考驗(yàn)的共識機(jī)制,已使比特幣和以太坊安全并分散了許多年瘤载。 | 如果您想進(jìn)行開采否灾,則需要如此專業(yè)的設(shè)備,這是一項(xiàng)巨大的投資鸣奔。 |
與權(quán)益證明相比墨技,它相對容易實(shí)現(xiàn)。 | 由于需要增加的計算量挎狸,采礦池可能會主導(dǎo)采礦游戲扣汪,從而導(dǎo)致集中化和安全風(fēng)險。 |
與PoS比
At a high level, proof-of-stake has the same end goal as proof-of-work: to help the decentralized network reach consensus, securely. But it has some differences in process and personnel:
PoS switches out the importance of computational power for staked ETH.
PoS replaces miners with validators. Validators stake their ETH to activate the ability to create new blocks.
Validators don't compete to create blocks, instead they are chosen at random by an algorithm.
Finality is clearer: at certain checkpoints, if 2/3 validators agree on the state of the block it is considered final. Validators must bet their entire stake on this, so if they try to collude down the line, they'll lose their entire stake.
PoS切換了對抵押ETH的計算能力的重要性锨匆。
PoS將礦工替換為驗(yàn)證人崭别。驗(yàn)證者通過投入其ETH來激活創(chuàng)建新區(qū)塊的能力。
驗(yàn)證程序不競爭創(chuàng)建塊统刮,而是由算法隨機(jī)選擇它們紊遵。
最終性更加明確:在某些檢查點(diǎn),如果2/3驗(yàn)證者對塊的狀態(tài)達(dá)成共識侥蒙,則將其視為最終狀態(tài)暗膜。驗(yàn)證者必須將全部賭注都押在此上,因此鞭衩,如果他們試圖串通一局学搜,就會失去全部賭注。
8.1.1 礦工
以太坊挖礦是什么论衍?
Mining is the process of creating a block of transactions to be added to the Ethereum blockchain.
Ethereum, like Bitcoin, currently uses a proof-of-work (PoW) consensus mechanism. Mining is the lifeblood of proof-of-work. Ethereum miners - computers running software - using their time and computation power to process transactions and produce blocks.
為什么礦工存在瑞佩?
In decentralized systems like Ethereum, we need to ensure that everyone agrees on the order of transactions. Miners help this happen by solving computationally difficult puzzles in order to produce blocks, which serves as a way to secure the network from attacks.
以太坊交易如何開采
- A user writes and signs a transaction request with the private key of some account.
- The user broadcasts the transaction request to the entire Ethereum network from some node.
- Upon hearing about the new transaction request, each node in the Ethereum network adds the request to their local mempool, a list of all transaction requests they’ve heard about that have not yet been committed to the blockchain in a block.
- At some point, a mining node aggregates several dozen or hundred transaction requests into a potential block, in a way that maximizes the transaction fees they earn while still staying under the block gas limit. The mining node then:
- Verifies the validity of each transaction request (i.e. no one is trying to transfer ether out of an account they haven’t produced a signature for, the request is not malformed, etc.), and then executes the code of the request, altering the state of their local copy of the EVM. The miner awards the transaction fee for each such transaction request to their own account.
- Begins the process of producing the Proof-of-Work “certificate of legitimacy” for the potential block, once all transaction requests in the block have been verified and executed on the local EVM copy.
- Eventually, a miner will finish producing a certificate for a block which includes our specific transaction request. The miner then broadcasts the completed block, which includes the certificate and a checksum of the claimed new EVM state.
- Other nodes hear about the new block. They verify the certificate, execute all transactions on the block themselves (including the transaction originally broadcasted by our user), and verify that the checksum of their new EVM state after the execution of all transactions matches the checksum of the state claimed by the miner’s block. Only then do these nodes append this block to the tail of their blockchain, and accept the new EVM state as the canonical state.
- Each node removes all transactions in the new block from their local mempool of unfulfilled transaction requests.
- New nodes joining the network download all blocks in sequence, including the block containing our transaction of interest. They initialize a local EVM copy (which starts as a blank-state EVM), and then go through the process of executing every transaction in every block on top of their local EVM copy, verifying state checksums at each block along the way.
Every transaction is mined (included in a new block and propagated for the first time) once, but executed and verified by every participant in the process of advancing the canonical EVM state. This highlights one of the central mantras of blockchain: Don’t trust, verify.
- 用戶用某個帳戶的私鑰編寫并簽署交易請求。
- 用戶從某個節(jié)點(diǎn)向整個以太坊網(wǎng)絡(luò)廣播交易請求坯台。
- 聽說新的交易請求后炬丸,以太坊網(wǎng)絡(luò)中的每個節(jié)點(diǎn)都會將該請求添加到其本地內(nèi)存池中,這是他們所聽說的尚未提交到區(qū)塊鏈中的所有交易請求的列表蜒蕾。
- 在某個時候稠炬,一個采礦節(jié)點(diǎn)將數(shù)十個或數(shù)百個交易請求聚合到一個潛在的區(qū)塊中,以最大程度地使他們賺取的交易費(fèi)用保持在區(qū)塊天然氣限制之下咪啡。然后首启,挖掘節(jié)點(diǎn):
- 驗(yàn)證每個交易請求的有效性(即,沒有人試圖將以太幣從他們沒有為其生成簽名的帳戶中轉(zhuǎn)出撤摸,該請求沒有格式錯誤等)毅桃,然后執(zhí)行請求的代碼褒纲,更改他們的EVM本地副本的狀態(tài)。礦工將每個此類交易請求的交易費(fèi)用獎勵給他們自己的帳戶钥飞。
- 一旦驗(yàn)證了區(qū)塊中的所有交易請求并在本地EVM副本上執(zhí)行了該代碼莺掠,便開始為該潛在區(qū)塊生成工作量證明“合法性證明”。
- 最終代承,一個礦工將為包含我們特定交易請求的區(qū)塊完成證書的生產(chǎn)汁蝶。礦工然后廣播完成的塊渐扮,該塊包括證書和要求保護(hù)的新EVM狀態(tài)的校驗(yàn)和论悴。
- 其他節(jié)點(diǎn)將聽到有關(guān)新塊的信息。他們驗(yàn)證證書墓律,自己執(zhí)行區(qū)塊上的所有交易(包括最初由我們的用戶廣播的交易)膀估,并在執(zhí)行所有交易后驗(yàn)證其新EVM狀態(tài)的校驗(yàn)和與礦機(jī)區(qū)塊要求的狀態(tài)的校驗(yàn)和相匹配。 耻讽。然后察纯,這些節(jié)點(diǎn)才將此塊附加到其區(qū)塊鏈的尾部,并接受新的EVM狀態(tài)作為規(guī)范狀態(tài)针肥。
- 每個節(jié)點(diǎn)將從其未完成的事務(wù)請求的本地內(nèi)存池中刪除新塊中的所有事務(wù)饼记。
- 加入網(wǎng)絡(luò)的新節(jié)點(diǎn)將按順序下載所有塊,包括包含我們感興趣的交易的塊慰枕。他們初始化本地EVM副本(以空白狀態(tài)EVM開頭)具则,然后執(zhí)行在其本地EVM副本頂部的每個塊中執(zhí)行每個事務(wù)的過程,并在此過程中驗(yàn)證每個塊的狀態(tài)校驗(yàn)和具帮。
每個事務(wù)都被挖掘一次(包含在一個新塊中博肋,并且第一次傳播),但是在推進(jìn)標(biāo)準(zhǔn)EVM狀態(tài)的過程中蜂厅,每個參與者都執(zhí)行并驗(yàn)證了該事務(wù)匪凡。這凸顯了區(qū)塊鏈的中心口號之一:不信任,驗(yàn)證掘猿。
8.2 股權(quán)證明
Ethereum is moving to a consensus mechanism called proof-of-stake (PoS) from proof-of-work (PoW). This was always the plan as it's a key part in the community's strategy to scale Ethereum via the Eth2 upgrades. However getting PoS right is a big technical challenge and not as straightforward as using PoW to reach consensus across the network.
什么是權(quán)益證明(POS)
Proof of stake is a type of consensus mechanism used by blockchain networks to achieve distributed consensus.
It requires users to stake their ETH to become a validator in the network. Validators are responsible for the same thing as miners in proof-of-work: ordering transactions and creating new blocks so that all nodes can agree on the state of the network.
Proof-of-stake comes with a number of improvements to the proof-of-work system:
better energy efficiency – you don't need to use lots of energy mining blocks
lower barriers to entry, reduced hardware requirements – you don't need elite hardware to stand a chance of creating new blocks
stronger immunity to centralization – proof-of-stake should lead to more nodes in the network
stronger support for shard chains – a key upgrade in scaling the Ethereum network
更高的能源效率–您無需使用大量的能源開采塊
降低進(jìn)入門檻病游,降低硬件要求–您不需要精良的硬件就可以創(chuàng)建新模塊
對集中化的抵抗力更強(qiáng)–權(quán)益證明應(yīng)導(dǎo)致網(wǎng)絡(luò)中更多的節(jié)點(diǎn)
增強(qiáng)對分片鏈的支持–擴(kuò)展以太坊網(wǎng)絡(luò)的關(guān)鍵升級
權(quán)益證明,權(quán)益和驗(yàn)證器
Proof-of-stake is the underlying mechanism that activates validators upon receipt of enough stake. For Ethereum, users will need to stake 32 ETH to become a validator. Validators are chosen at random to create blocks and are responsible for checking and confirming blocks they don't create. A user's stake is also used as a way to incentivise good validator behavior. For example, a user can lose a portion of their stake for things like going offline (failing to validate) or their entire stake for deliberate collusion.
股權(quán)證明是一種基礎(chǔ)機(jī)制稠通,可在收到足夠的賭注后激活驗(yàn)證程序衬衬。對于以太坊,用戶將需要投入32 ETH才能成為驗(yàn)證者采记。驗(yàn)證者是隨機(jī)選擇的以創(chuàng)建塊佣耐,并負(fù)責(zé)檢查和確認(rèn)未創(chuàng)建的塊。用戶的股份也被用作激勵良好驗(yàn)證者行為的一種方式唧龄。例如兼砖,用戶可能因?yàn)槊摍C(jī)(無法驗(yàn)證)而失去部分股份奸远,或者因故意串通而失去全部股份。
以太坊的權(quán)益證明如何運(yùn)作讽挟?
Unlike proof-of-work, validators don't need to use significant amounts of computational power because they're selected at random and aren't competing. They don't need to mine blocks; they just need to create blocks when chosen and validate proposed blocks when they're not. This validation is known as attesting. You can think of attesting as saying "this block looks good to me." Validators get rewards for proposing new blocks and for attesting to ones they've seen.
If you attest to malicious blocks, you lose your stake.
與工作量證明不同懒叛,驗(yàn)證器不需要使用大量的計算能力,因?yàn)樗鼈兪请S機(jī)選擇的耽梅,并且不會競爭薛窥。他們不需要挖塊。他們只需要在選擇時創(chuàng)建塊眼姐,然后在未選擇時驗(yàn)證提議的塊即可诅迷。此驗(yàn)證稱為證明。您可以認(rèn)為證明是說“此區(qū)塊對我而言很好”众旗。驗(yàn)證者通過提出新的塊并證明他們所看到的塊而獲得獎勵罢杉。
如果您證明存在惡意阻止,那么您將失去賭注贡歧。
The beacon chain
When Ethereum replaces proof-of-work with proof-of-stake, there will be the added complexity of shard chains. These are separate blockchains that will need validators to process transactions and create new blocks. The plan is to have 64 shard chains, with each having a shared understanding of the state of the network. As a result, extra coordination is necessary and will be done by the beacon chain.
The beacon chain receives state information from shards and makes it available for other shards, allowing the network to stay in sync. The beacon chain will also manage the validators from registering their stake deposits to issuing their rewards and penalties.
Here's how that process works.
當(dāng)以太坊用工作量證明代替工作量證明時滩租,分片鏈會變得更加復(fù)雜。這些是獨(dú)立的區(qū)塊鏈利朵,將需要驗(yàn)證程序來處理交易并創(chuàng)建新的區(qū)塊律想。該計劃將擁有64個分片鏈,每個分片鏈對網(wǎng)絡(luò)狀態(tài)都有共同的了解绍弟。結(jié)果技即,額外的協(xié)調(diào)是必要的,并且將由信標(biāo)鏈來完成晌柬。
信標(biāo)鏈從分片接收狀態(tài)信息姥份,并使?fàn)顟B(tài)信息可用于其他分片,從而使網(wǎng)絡(luò)保持同步年碘。信標(biāo)鏈還將管理驗(yàn)證者澈歉,從注冊其股份存款到頒發(fā)其獎勵和罰款。
這是該過程的工作方式屿衅。
How validation works
When you submit a transaction on a shard, a validator will be responsible for adding your transaction to a shard block. Validators are algorithmically chosen by the beacon chain to propose new blocks.
當(dāng)您在分片上提交交易時埃难,驗(yàn)證程序?qū)⒇?fù)責(zé)將您的交易添加到分片塊中。信標(biāo)鏈通過算法選擇驗(yàn)證器以提出新的塊涤久。
Attestation
If a validator isn't chosen to propose a new shard block, they'll have to attest to another validator's proposal and confirm that everything looks as it should. It's the attestation that is recorded in the beacon chain rather than the transaction itself.
At least 128 validators are required to attest to each shard block – this is known as a "committee."
The committee has a time-frame in which to propose and validate a shard block. This is known as a "slot." Only one valid block is created per slot, and there are 32 slots in an "epoch." After each epoch, the committee is disbanded and reformed with different, random participants. This helps keep shards safe from committees of bad actors.
該委員會有一個提出建議和驗(yàn)證分片的時間表涡尘。這稱為“插槽”。每個插槽僅創(chuàng)建一個有效塊响迂,并且“時代”中有32個插槽考抄。在每個時期之后,委員會將解散蔗彤,并由不同的隨機(jī)參與者進(jìn)行改革川梅。這有助于使碎片免受不良行為者委員會的傷害疯兼。
Crosslinks
Once a new shard block proposal has enough attestations, a "crosslink" is created which confirms the inclusion of the block and your transaction in the beacon chain.
Once there's a crosslink, the validator who proposed the block gets their reward.
一旦新的分片阻止提議具有足夠的證明,便會創(chuàng)建一個“交叉鏈接”贫途,以確認(rèn)該阻止和您的交易在信標(biāo)鏈中的包含吧彪。
一旦有了交叉鏈接,提議該區(qū)塊的驗(yàn)證者將獲得獎勵丢早。
Finality
In distributed networks, a transaction has "finality" when it's part of a block that can't change.
To do this in proof-of-stake, Casper, a finality protocol, gets validators to agree on the state of a block at certain checkpoints. So long as 2/3 of the validators agree, the block is finalised. Validators will lose their entire stake if they try and revert this later on via a 51% attack.
As Vlad Zamfir put it, this is like a miner participating in a 51% attack, causing their mining hardware to immediately burn down.
在分布式網(wǎng)絡(luò)中姨裸,當(dāng)事務(wù)是不可更改的塊的一部分時,它具有“最終性”怨酝。
為此傀缩,在最終證明協(xié)議中,Casper(一種確定性協(xié)議)使驗(yàn)證程序在某些檢查點(diǎn)上就塊的狀態(tài)達(dá)成共識凫碌。只要2/3的驗(yàn)證者同意扑毡,就可以最終確定該區(qū)塊。如果驗(yàn)證者稍后嘗試通過51%攻擊將其還原盛险,他們將失去全部股份。
正如弗拉德·扎姆菲爾(Vlad Zamfir)所說勋又,這就像一個礦工參與了51%的攻擊苦掘,導(dǎo)致其采礦硬件立即燒毀。
權(quán)益證明和安全性
The threat of a 51% attack still exists in proof-of-stake, but it's even more risky for the attackers. To do so, you'd need to control 51% of the staked ETH. Not only is this a lot of money, but it would probably cause ETH's value to drop. There's very little incentive to destroy the value of a currency you have a majority stake in. There are stronger incentives to keep the network secure and healthy.
Stake slashings, ejections, and other penalties, coordinated by the beacon chain, will exist to prevent other acts of bad behavior. Validators will also be responsible for flagging these incidents.
股權(quán)證明中仍然存在51%攻擊的威脅楔壤,但對攻擊者而言鹤啡,風(fēng)險甚至更高。為此蹲嚣,您需要控制所抵押的ETH的51%递瑰。這不僅是很多錢,而且可能會導(dǎo)致ETH的價值下降隙畜。幾乎沒有什么動機(jī)可以破壞您擁有多數(shù)股份的貨幣的價值抖部。還有更強(qiáng)有力的動機(jī)來保持網(wǎng)絡(luò)的安全和健康。
由信標(biāo)鏈協(xié)調(diào)的放樣议惰,彈出和其他懲罰將存在慎颗,以防止發(fā)生其他不良行為。驗(yàn)證者還將負(fù)責(zé)標(biāo)記這些事件言询。
優(yōu)缺點(diǎn)
Pros | Cons |
---|---|
Staking makes it easier for you to run a node. It doesn't require huge investments in hardware or energy, and if you don't have enough ETH to stake, you can join staking pools. | Proof-of-stake is still in its infancy, and less battle-tested, compared to proof-of-work |
Staking is more decentralized. It allows for increased participation, and more nodes doesn't mean increased % returns, like with mining. | |
Staking allows for secure sharding. Shard chains allow Ethereum to create multiple blocks at the same time, increasing transaction throughput. Sharding the network in a proof-of-work system would simply lower the power needed to compromise a portion of the network. |
優(yōu)點(diǎn) | 缺點(diǎn) |
---|---|
權(quán)益使您更輕松地運(yùn)行節(jié)點(diǎn)俯萎。它不需要在硬件或能源上進(jìn)行大量投資,并且如果您沒有足夠的ETH來投資运杭,您可以加入賭注池夫啊。 | 與工作量證明相比,權(quán)益證明仍處于起步階段辆憔,并且經(jīng)過較少的戰(zhàn)斗測試 |
權(quán)益更加分散撇眯。它允許增加參與度谆趾,而更多的節(jié)點(diǎn)并不意味著像采礦一樣增加了%的回報。 | |
權(quán)益可實(shí)現(xiàn)安全的分片叛本。分片鏈允許以太坊同時創(chuàng)建多個區(qū)塊沪蓬,從而提高交易吞吐量。在工作量證明系統(tǒng)中對網(wǎng)絡(luò)進(jìn)行分片將僅降低破壞一部分網(wǎng)絡(luò)所需的功率来候。 |