国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

《如何搭建一條私有多Geth節(jié)點(diǎn)的鏈》最新版以太坊私鏈搭建官方文檔要點(diǎn)翻譯

這篇具有很好參考價(jià)值的文章主要介紹了《如何搭建一條私有多Geth節(jié)點(diǎn)的鏈》最新版以太坊私鏈搭建官方文檔要點(diǎn)翻譯。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

私鏈 Private Networks

Last edited on January 31, 2023

This guide explains how to set up a private network of multiple Geth nodes. An Ethereum network is private if the nodes are not connected to the main network. In this context private only means reserved or isolated, rather than protected or secure. A fully controlled, private Ethereum network is useful as a backend for core developers working on issues relating to networking/blockchain syncing etc. Private networks are also useful for Dapp developers testing multi-block and multi-user scenarios.

如何搭建一條私有多Geth節(jié)點(diǎn)的鏈

Prerequisites

To follow the tutorial on this page it is necessary to have a working Geth installation (instructions here). It is also helpful to understand Geth fundamentals (see Getting Started).

私鏈 Private Networks

A private network is composed of multiple Ethereum nodes that can only connect to each other. In order to run multiple nodes locally, each one requires a separate data directory (--datadir). The nodes must also know about each other and be able to exchange information, share an initial state and a common consensus algorithm. The remainder of this page will explain how to configure Geth so that these basic requirements are met, enabling a private network to be started.

網(wǎng)絡(luò)ID Choosing A Network ID

Ethereum Mainnet has Network ID = 1. There are also many other networks that Geth can connect to by providing alternative Chain IDs, some are testnets and others are alternative networks built from forks of the Geth source code. Providing a network ID that is not already being used by an existing network or testnet means the nodes using that network ID can only connect to each other, creating a private network. A list of current network IDs is available at Chainlist.org(可用于鏈id的輔助查重). The network ID is controlled using the networkid flag, e.g.

geth --networkid 12345

共識(shí)算法 Choosing A Consensus Algorithm

While the main network uses proof-of-stake (PoS) to secure the blockchain, Geth also supports the the 'Clique' proof-of-authority (PoA) consensus algorithm and the Ethash proof-of-work (POW)algorithm as alternatives for private networks. Clique is strongly recommended for private testnets because PoA(能耗低,強(qiáng)推薦) is far less resource-intensive than PoW. The key differences(關(guān)鍵不同點(diǎn)) between the consensus algorithms available in Geth are:

Ethash (×)

Geth's PoW algorithm, Ethash, is a system that allows open participation by anyone willing to dedicate resources to mining. While this is a critical property for a public network, the overall security of the blockchain strictly depends on the total amount of resources used to secure it. As such, PoW is a poor choice (不是好選項(xiàng)對(duì)私鏈來(lái)說(shuō)) for private networks with few miners. The Ethash mining 'difficulty' is adjusted automatically so that new blocks are created approximately 12 seconds apart. As more mining resources are deployed on the network, creating a new block becomes harder so that the average block time matches the target block time.

Clique(√)

Clique consensus is a PoA system where new blocks can be created by authorized 'signers' only.? 塊只可以在被授權(quán)為“signers”的節(jié)點(diǎn)產(chǎn)生。The clique consenus protocol is specified in EIP-225. The initial set of authorized signers is configured in the genesis block. 創(chuàng)世塊中初始化設(shè)置授權(quán)的簽名者。 Signers can be authorized and de-authorized using a voting mechanism, 簽名者可以被授權(quán)或者反授權(quán)通過(guò)投票的機(jī)制。thus allowing the set of signers to change while the blockchain operates. Clique can be configured to target any block time (within reasonable limits) since it isn't tied to the difficulty adjustment.

創(chuàng)建創(chuàng)世區(qū)塊? Creating The Genesis Block

Every blockchain starts with a genesis block. When Geth is run with default settings for the first time, it commits the Mainnet genesis to the database. For a private network, it is generally preferable to use a different genesis block. The genesis block is configured using a genesis.json 唯它可將geth從主鏈引開(kāi)? file whose path must be provided to Geth on start-up. When creating a genesis block, a few initial parameters for the private blockchain must be defined:

  • Ethereum platform features enabled at launch (config).鏈的特征只能在配置階段定義? Enabling and disabling features once the blockchain is running requires scheduling a hard fork. 一旦鏈跑起來(lái)后,就只能在日程上增加一次硬分叉

  • Initial block gas limit (gasLimit). This impacts how much EVM computation can happen within a single block. Mirroring the main Ethereum network is generally a good choice. The block gas limit can be adjusted after launch using the --miner.gastarget command-line flag. gas limit可以在啟動(dòng)后調(diào)整使用 --miner.gastarget 命令行標(biāo)簽

  • Initial allocation(配額) of ether (alloc). This determines how much ether is available to the addresses listed in the genesis block. Additional ether can be created through mining as the chain progresses. alloc在創(chuàng)世區(qū)塊中列明的預(yù)置資產(chǎn),之外的資產(chǎn)就只能在后期的挖礦中創(chuàng)造了

Clique Example(POA示例)

Below is an example of a genesis.json file for a PoA network. The config section ensures that all known protocol changes are available and configures the 'clique' engine to be used for consensus. Note that the initial signer set must be configured through the extradata field(初始的簽名者必須通過(guò)extradata字段去配置好,POA共識(shí)下這個(gè)字段必須配置才能正常工作). This field is required for Clique to work.

The signer account keys can be generated using the geth account command (this command can be run multiple times to create more than one signer key). 簽名者的鑰匙可以通過(guò)geth account命令產(chǎn)生(可多次運(yùn)行以創(chuàng)造多個(gè)簽名者key,如下)

geth account new --datadir data  #指明數(shù)據(jù)位置,創(chuàng)建一個(gè)singer key

The Ethereum address printed by this command should be recorded(記下上面命令返回的地址). To encode the signer addresses in extradata, concatenate 32 zero bytes, all signer addresses and 65 further zero bytes(extradata字段里編碼簽名者地址的方法). The result of this concatenation is then used as the value accompanying the extradata key in genesis.json. In the example below, extradata contains a single initial signer address, (將這個(gè)連接的結(jié)果作為值與genesis.json中的extradata鍵一起使用。在下面的示例中,extradata包含一個(gè)初始簽名者地址。)0x7df9a875a174b3bc565e6424a0050ebc1b2d1d82.

The period configuration option sets the target block time of the chain.

{
  "config": {
    "chainId": 12345,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "berlinBlock": 0,
    "clique": {
      "period": 5,
      "epoch": 30000
    }
  },
  "difficulty": "1",
  "gasLimit": "8000000",
  "extradata": "0x00000000000000000000000000000000000000000000000000000000000000007df9a875a174b3bc565e6424a0050ebc1b2d1d820000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "alloc": {
    "7df9a875a174b3bc565e6424a0050ebc1b2d1d82": { "balance": "300000" },
    "f41c74c9ae680c1aa78f42e5647a62f353b7bdde": { "balance": "400000" }
  }
}

Ethash Example(POW示例)

Since Ethash is the default consensus algorithm, no additional parameters need to be configured in order to use it.自從POW成為以太坊默認(rèn)共識(shí),它不需要額外的參數(shù)配置就能生效。 The initial mining difficulty is influenced using the difficulty parameter, but note that the difficulty adjustment algorithm will quickly adapt to the amount of mining resources deployed on the chain.(初始的挖礦難度受到難度參數(shù)的影響,但需要注意的是,難度調(diào)整算法將快速適應(yīng)鏈上部署的挖礦資源量。)

{
  "config": {
    "chainId": 12345,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "berlinBlock": 0,
    "ethash": {}
  },
  "difficulty": "1",
  "gasLimit": "8000000",
  "alloc": {
    "7df9a875a174b3bc565e6424a0050ebc1b2d1d82": { "balance": "300000" },
    "f41c74c9ae680c1aa78f42e5647a62f353b7bdde": { "balance": "400000" }
  }
}

初始化Geth數(shù)據(jù)庫(kù)? Initializing the Geth Database

To create a blockchain node that uses this genesis block, first use geth init to import and sets the canonical genesis block for the new chain. This requires the path to genesis.json to be passed as an argument. (要?jiǎng)?chuàng)建一個(gè)使用此創(chuàng)世塊的區(qū)塊鏈節(jié)點(diǎn),首先使用geth?init導(dǎo)入并設(shè)置新鏈的規(guī)范創(chuàng)世塊。這需要將genesis.json的路徑作為參數(shù)傳遞。)

geth init --datadir data genesis.json

When Geth is started using 【 --datadir data】 the genesis block defined in genesis.json will be used. For example:

geth --datadir data --networkid 12345

計(jì)劃硬分叉 Scheduling Hard Forks

As Ethereum protocol development progresses, new features become available. To enable these features on an existing private network, a hard fork must be scheduled.當(dāng)以太坊協(xié)議不斷開(kāi)發(fā)進(jìn)展,為了讓這些新特性在已經(jīng)存在的私鏈上生效,硬分叉必須提上日程。 To do this, a future block number must be chosen which determines precisely when the hard fork will activate. Continuing the genesis.json example above and assuming the current block number is 35421, a hard fork might be scheduled for block 40000. This hard fork might upgrade the network to conform to the 'London' specs. First, all the Geth instances on the private network must be recent enough to support the specific hard fork. If so, genesis.json can be updated so that the londonBlock key gets the value 40000. The Geth instances are then shut down and geth init is run to update their configuration. When the nodes are restarted they will pick up where they left off and run normally until block 40000, at which point they will automatically upgrade.(為此,必須選擇一個(gè)未來(lái)的塊號(hào),以精確確定硬分叉何時(shí)激活。繼續(xù)上面的 genesis.json 示例并假設(shè)當(dāng)前區(qū)塊號(hào)為 35421,可能會(huì)為區(qū)塊 40000 安排硬分叉。這個(gè)硬分叉可能會(huì)升級(jí)網(wǎng)絡(luò)以符合“倫敦”規(guī)范。首先,私有網(wǎng)絡(luò)上的所有 Geth 實(shí)例都必須足夠新,以支持特定的硬分叉。如果是這樣,genesis.json可以更新,以便londonBlock密鑰獲得值40000。然后關(guān)閉 Geth 實(shí)例并運(yùn)行 geth init 以更新其配置。當(dāng)節(jié)點(diǎn)重新啟動(dòng)時(shí),它們將從中斷的地方繼續(xù)并正常運(yùn)行,直到塊 40000,此時(shí)它們將自動(dòng)升級(jí)。
翻譯中文)

The modification to genesis.json is as follows:

{
  "config": {
    "londonBlock": 40000
  }
}

The upgrade command is:

geth init --datadir data genesis.json

搭建網(wǎng)絡(luò) Setting Up Networking

With the node configured and initialized, the next step is to set up a peer-to-peer network. This requires a bootstrap node. The bootstrap node is a normal node that is designated to be the entry point that other nodes use to join the network. Any node can be chosen to be the bootstrap node.

To configure a bootstrap node, the IP address of the machine the bootstrap node will run on must be known. The bootsrap node needs to know its own IP address so that it can broadcast it to other nodes. On a local machine this can be found using tools such as ifconfig and on cloud instances such as Amazon EC2 the IP address of the virtual machine can be found in the management console. Any firewalls must allow UDP and TCP traffic on port 30303.

The bootstrap node IP is set using the --nat flag (the command below contains an example address - replace it with the correct one).

配置并初始化節(jié)點(diǎn)后,下一步是設(shè)置P2P網(wǎng)絡(luò)。這需要一個(gè)引導(dǎo)節(jié)點(diǎn)。引導(dǎo)節(jié)點(diǎn)是一個(gè)普通節(jié)點(diǎn),被指定為其他節(jié)點(diǎn)用于加入網(wǎng)絡(luò)的入口點(diǎn)??梢赃x擇任何節(jié)點(diǎn)作為引導(dǎo)節(jié)點(diǎn)。

要配置引導(dǎo)節(jié)點(diǎn),必須知道將運(yùn)行引導(dǎo)節(jié)點(diǎn)的計(jì)算機(jī)的 IP 地址。引導(dǎo)節(jié)點(diǎn)需要知道自己的 IP 地址,以便它可以將其廣播到其他節(jié)點(diǎn)。在本地計(jì)算機(jī)上,可以使用 ifconfig 等工具找到此地址,而在 Amazon EC2 等云實(shí)例上,可以在管理控制臺(tái)中找到虛擬機(jī)的 IP 地址。任何防火墻都必須允許端口 30303 上的 UDP 和 TCP 流量。

引導(dǎo)節(jié)點(diǎn) IP 是使用 --nat 標(biāo)志設(shè)置的(下面的命令包含一個(gè)示例地址 - 將其替換為正確的地址)。

geth --datadir data --networkid 15 --nat extip:172.16.254.4

The 'node record' of the bootnode can be extracted using the JS console:(引導(dǎo)節(jié)點(diǎn)的“節(jié)點(diǎn)記錄”可以使用?JS?控制臺(tái)提?。?/p>

geth attach --exec admin.nodeInfo.enr data/geth.ipc

This command should print a base64 string such as the following example. Other nodes will use the information contained in the bootstrap node record to connect to the peer-to-peer network. 此命令應(yīng)打印?base64?字符串,如以下示例所示。其他節(jié)點(diǎn)將使用引導(dǎo)節(jié)點(diǎn)記錄中包含的信息連接到對(duì)等網(wǎng)絡(luò)。

"enr:-Je4QEiMeOxy_h0aweL2DtZmxnUMy-XPQcZllrMt_2V1lzynOwSx7GnjCf1k8BAsZD5dvHOBLuldzLYxpoD5UcqISiwDg2V0aMfGhGlQhqmAgmlkgnY0gmlwhKwQ_gSJc2VjcDI1NmsxoQKX_WLWgDKONsGvxtp9OeSIv2fRoGwu5vMtxfNGdut4cIN0Y3CCdl-DdWRwgnZf"

If the nodes are intended to connect across the Internet, the bootnode and all other nodes must have public IP addresses assigned, and both TCP and UDP traffic can pass their firewalls. If Internet connectivity is not required or all member nodes connect using well-known IPs, Geth should be set up to restrict peer-to-peer connectivity to an IP subnet. Doing so will further isolate the network and prevents cross-connecting with other blockchain networks in case the nodes are reachable from the Internet. Use the --netrestrict flag to configure a whitelist of IP networks:(如果節(jié)點(diǎn)打算通過(guò) Internet 連接,則引導(dǎo)節(jié)點(diǎn)和所有其他節(jié)點(diǎn)必須分配有公共 IP 地址,并且 TCP 和 UDP 流量都可以通過(guò)其防火墻。如果不需要互聯(lián)網(wǎng)連接或所有成員節(jié)點(diǎn)都使用已知 IP 進(jìn)行連接,則應(yīng)將 Geth 設(shè)置為只限于某一 IP 子網(wǎng)內(nèi)的P2P連接。這樣做將進(jìn)一步隔離網(wǎng)絡(luò),并防止與其他區(qū)塊鏈網(wǎng)絡(luò)交叉連接,以防節(jié)點(diǎn)可以從互聯(lián)網(wǎng)訪(fǎng)問(wèn)。使用 --netlimit 標(biāo)志配置 IP 網(wǎng)絡(luò)白名單:)

geth <other-flags> --netrestrict 172.16.254.0/24  #僅限這個(gè)子網(wǎng)

With the above setting, Geth will only allow connections from the 172.16.254.0/24 subnet, and will not attempt to connect to other nodes outside of the set IP range.

跑成員節(jié)點(diǎn) Running Member Nodes

Before running a member node, it must be initialized with the same genesis file as used for the bootstrap node. With the bootnode operational and externally reachable (telnet <ip> <port> will confirm that it is indeed reachable), more Geth nodes can be started and connected to them via the bootstrap node using the --bootnodes flag. The process is to start Geth on the same machine as the bootnode, with a separate data directory and listening port and the bootnode node record provided as an argument:

在運(yùn)行成員節(jié)點(diǎn)之前,必須使用與引導(dǎo)節(jié)點(diǎn)相同的創(chuàng)世文件對(duì)其進(jìn)行初始化。隨著引導(dǎo)節(jié)點(diǎn)正常運(yùn)行且可從外部訪(fǎng)問(wèn)(telnet <ip> <port> 將確認(rèn)它確實(shí)可訪(fǎng)問(wèn)),可以使用 --bootnodes 標(biāo)志通過(guò)引導(dǎo)節(jié)點(diǎn)啟動(dòng)更多 Geth 節(jié)點(diǎn)并連接到它們。該過(guò)程是在與引導(dǎo)節(jié)點(diǎn)相同的機(jī)器上啟動(dòng) Geth,具有單獨(dú)的數(shù)據(jù)目錄和偵聽(tīng)端口以及作為參數(shù)提供的引導(dǎo)節(jié)點(diǎn)節(jié)點(diǎn)記錄:

例如,使用數(shù)據(jù)目錄(例如:data2)和偵聽(tīng)端口(例如:30305):

For example, using data directory (example: data2) and listening port (example: 30305):

geth --datadir data2 --networkid 12345 --port 30305 --bootnodes <bootstrap-node-record>

With the member node running, it is possible to check that it is connected to the bootstrap node or any other node in the network by attaching a console and running admin.peers. It may take up to a few seconds for the nodes to get connected.在成員節(jié)點(diǎn)運(yùn)行時(shí),可以通過(guò)連接控制臺(tái)并運(yùn)行?admin.peers?來(lái)檢查它是否已連接到引導(dǎo)節(jié)點(diǎn)或網(wǎng)絡(luò)中的任何其他節(jié)點(diǎn)。節(jié)點(diǎn)最多可能需要幾秒鐘才能連接。

geth attach data2/geth.ipc --exec admin.peers

跑一個(gè)簽名者(POA的) Running A Signer (Clique)

To set up Geth for signing blocks in Clique, a signer account must be available. The account must already be available as a keyfile in the keystore. To use it for signing blocks, it must be unlocked. The following command, for address 0x7df9a875a174b3bc565e6424a0050ebc1b2d1d82 will prompt for the account password, then start signing blocks:要設(shè)置 Geth 以在 Clique 中簽署塊,簽名者帳戶(hù)必須可用。該帳戶(hù)必須已作為密鑰庫(kù)中的密鑰文件提供。要將其用于簽名塊,必須將其解鎖。以下命令,對(duì)于地址0x7df9a875a174b3bc565e6424a0050ebc1b2d1d82將提示輸入帳戶(hù)密碼,然后開(kāi)始簽名塊:

geth <other-flags> --unlock 0x7df9a875a174b3bc565e6424a0050ebc1b2d1d82 --mine

Mining can be further configured by changing the default gas limit blocks converge to (with --miner.gastarget) and the price transactions are accepted at (with --miner.gasprice).

挖礦可以通過(guò)更改默認(rèn)的氣體限制塊收斂到(使用 --miner.gastarget)和價(jià)格交易被接受在 (使用 --miner.gasprice) 來(lái)進(jìn)一步配置。
運(yùn)行礦工(Ethash)

跑一個(gè)曠工(POW的) Running A Miner (Ethash)

For PoW in a simple private network, a single CPU miner instance is enough to create a stable stream of blocks at regular intervals. To start a Geth instance for mining, it can be run with all the usual flags plus the following to configure mining:對(duì)于簡(jiǎn)單內(nèi)網(wǎng)中的PoW,單個(gè)CPU礦工實(shí)例足以定期創(chuàng)建穩(wěn)定的區(qū)塊流。要啟動(dòng)用于挖礦的 Geth 實(shí)例,可以使用所有常用標(biāo)志以及以下內(nèi)容來(lái)配置挖礦:

geth <other-flags> --mine --miner.threads=1 --miner.etherbase=0xf41c74c9ae680c1aa78f42e5647a62f353b7bdde

This will start mining blocks and transactions on a single CPU thread, crediting all block rewards to the account specified by --miner.etherbase(指定挖礦獲益地址).

端到端 End-to-end example

This section will run through the commands for setting up a simple private network of two nodes. Both nodes will run on the local machine using the same genesis block and network ID. The data directories for each node will be named node1 and node2. 本節(jié)將介紹用于設(shè)置兩個(gè)節(jié)點(diǎn)的簡(jiǎn)單專(zhuān)用網(wǎng)絡(luò)的命令。兩個(gè)節(jié)點(diǎn)將使用相同的創(chuàng)世區(qū)塊和網(wǎng)絡(luò) ID 在本地計(jì)算機(jī)上運(yùn)行。每個(gè)節(jié)點(diǎn)的數(shù)據(jù)目錄將命名為 node1 和node2。

`mkdir node1 node2`

Each node will have an associated account that will receive some ether at launch. The following command creates an account for Node 1:每個(gè)節(jié)點(diǎn)都有一個(gè)關(guān)聯(lián)的賬戶(hù),該賬戶(hù)將在啟動(dòng)時(shí)收到一些以太幣。以下命令為節(jié)點(diǎn)?1?創(chuàng)建一個(gè)帳戶(hù):

geth --datadir node1 account new

This command returns a request for a password. Once a password has been provided the following information is returned to the terminal:此命令返回密碼請(qǐng)求。提供密碼后,以下信息將返回給終端:

Your new account is locked with a password. Please give a password. Do not forget this password.

Password:

Repeat password:

Your new key was generated Public address of the key: 0xC1B2c0dFD381e6aC08f34816172d6343Decbb12b

Path of the secret key file: node1/keystore/UTC--2022-05-13T14-25-49.229126160Z--c1b2c0dfd381e6ac08f34816172d6343decbb12b

- You can share your public address with anyone. Others need it to interact with you.

- You must NEVER share the secret key with anyone! The key controls access to your funds!

- You must BACKUP your key file! Without the key, it's impossible to access account funds!

- You must remember your password! Without the password, it's impossible to decrypt the key!

The keyfile and account password should be backed up securely. These steps can then be repeated for Node 2. These commands create keyfiles that are stored in the keystore directory in node1 and node2 data directories. In order to unlock the accounts later the passwords for each account should be saved to a text file in each node's data directory.密鑰文件和帳戶(hù)密碼應(yīng)安全備份。然后,可以對(duì)Node2 重復(fù)這些步驟。這些命令創(chuàng)建存儲(chǔ)在node1 和node2 數(shù)據(jù)目錄中的keystore目錄中的密鑰文件。為了稍后解鎖帳戶(hù),每個(gè)帳戶(hù)的密碼應(yīng)保存到每個(gè)節(jié)點(diǎn)數(shù)據(jù)目錄中的文本文件中。

In each data directory save a copy of the following genesis.json to the top level project directory. The account addresses in the alloc field should be replaced with those created for each node in the previous step (without the leading 0x).在每個(gè)數(shù)據(jù)目錄中,將以下 genesis.json 的副本保存到頂級(jí)項(xiàng)目目錄。alloc字段中的帳戶(hù)地址應(yīng)替換為上一步中為每個(gè)節(jié)點(diǎn)創(chuàng)建的帳戶(hù)地址(不帶前導(dǎo) 0x)。

{
  "config": {
    "chainId": 12345,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "muirGlacierBlock": 0,
    "berlinBlock": 0,
    "londonBlock": 0,
    "arrowGlacierBlock": 0,
    "grayGlacierBlock": 0,
    "clique": {
      "period": 5,
      "epoch": 30000
    }
  },
  "difficulty": "1",
  "gasLimit": "800000000",
  "extradata": "0x00000000000000000000000000000000000000000000000000000000000000007df9a875a174b3bc565e6424a0050ebc1b2d1d820000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "alloc": {
    "C1B2c0dFD381e6aC08f34816172d6343Decbb12b": { "balance": "500000" },
    "c94d95a5106270775351eecfe43f97e8e75e59e8": { "balance": "500000" }
  }
}

The nodes can now be set up using geth init as follows:現(xiàn)在可以使用?geth?init?設(shè)置節(jié)點(diǎn),如下所示

geth init --datadir node1 genesis.json

This should be repeated for both nodes. The following will be returned to the terminal:

INFO [05-13|15:41:47.520] Maximum peer count ETH=50 LES=0 total=50

INFO [05-13|15:41:47.520] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"

INFO [05-13|15:41:47.520] Set global gas cap cap=50,000,000

INFO [05-13|15:41:47.520] Allocated cache and file handles database=/home/go-ethereum/node2/geth/chaindata cache=16.00MiB handles=16

INFO [05-13|15:41:47.542] Writing custom genesis block

INFO [05-13|15:41:47.542] Persisted trie from memory database nodes=3 size=397.00B time="41.246μs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B

INFO [05-13|15:41:47.543] Successfully wrote genesis state database=chaindata hash=c9a158..d415a0

INFO [05-13|15:41:47.543] Allocated cache and file handles database=/home/go-ethereum/node2/geth/chaindata cache=16.00MiB handles=16

INFO [05-13|15:41:47.556] Writing custom genesis block

INFO [05-13|15:41:47.557] Persisted trie from memory database nodes=3 size=397.00B time="81.801μs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B

INFO [05-13|15:41:47.558] Successfully wrote genesis state database=chaindata hash=c9a158..d415a0

The next step is to configure a bootnode. This can be any node, but for this tutorial the developer tool bootnode will be used to quickly and easily configure a dedicated bootnode. First the bootnode requires a key, which can be created with the following command, which will save a key to boot.key:下一步是配置引導(dǎo)節(jié)點(diǎn)。這可以是任何節(jié)點(diǎn),但在本教程中,開(kāi)發(fā)人員工具引導(dǎo)節(jié)點(diǎn)將用于快速輕松地配置專(zhuān)用引導(dǎo)節(jié)點(diǎn)。首先,引導(dǎo)節(jié)點(diǎn)需要一個(gè)密鑰,可以使用以下命令創(chuàng)建該密鑰,該命令將保存一個(gè)密鑰以進(jìn)行啟動(dòng).key:

bootnode -genkey boot.key

This key can then be used to generate a bootnode as follows:

bootnode -nodekey boot.key -addr :30305

The choice of port passed to -addr is arbitrary, but public Ethereum networks use 30303, so this is best avoided. The bootnode command returns the following logs to the terminal, confirming that it is running:傳遞給?-addr?的端口選擇是任意的,但公共以太坊網(wǎng)絡(luò)使用?30303,因此最好避免這種情況。bootnode?命令將以下日志返回到終端,確認(rèn)它正在運(yùn)行:

enode://f7aba85ba369923bffd3438b4c8fde6b1f02b1c23ea0aac825ed7eac38e6230e5cadcf868e73b0e28710f4c9f685ca71a86a4911461637ae9ab2bd852939b77f@127.0.0.1:0?discport=30305 Note: you're using cmd/bootnode, a developer tool. We recommend using a regular node as bootstrap node for production deployments.

INFO [05-13|15:50:03.645] New local node record seq=1,652,453,403,645 id=a2d37f4a7d515b3a ip=nil udp=0 tcp=0

The two nodes can now be started. Open separate terminals for each node, leaving the bootnode running in the original terminal. In each terminal, run the following command (replacing node1 with node2 where appropriate, and giving each node different --port and authrpc.port IDs. The account address and password file for node 1 must also be provided:現(xiàn)在可以啟動(dòng)這兩個(gè)節(jié)點(diǎn)。為每個(gè)節(jié)點(diǎn)打開(kāi)單獨(dú)的終端,使引導(dǎo)節(jié)點(diǎn)在原始終端中運(yùn)行。在每個(gè)終端中,運(yùn)行以下命令(在適當(dāng)?shù)那闆r下將node1替換為node2,并為每個(gè)節(jié)點(diǎn)提供不同的--port和authrpc.port ID。還必須提供節(jié)點(diǎn) 1 的帳戶(hù)地址和密碼文件:

./geth --datadir node1 --port 30306 --bootnodes enode://f7aba85ba369923bffd3438b4c8fde6b1f02b1c23ea0aac825ed7eac38e6230e5cadcf868e73b0e28710f4c9f685ca71a86a4911461637ae9ab2bd852939b77f@127.0.0.1:0?discport=30305  --networkid 123454321 --unlock 0xC1B2c0dFD381e6aC08f34816172d6343Decbb12b --password node1/password.txt --authrpc.port 8551

This will start the node using the bootnode as an entry point. Repeat the same command with the information appropriate to node 2. In each terminal, the following logs indicate success:這將使用引導(dǎo)節(jié)點(diǎn)作為入口點(diǎn)啟動(dòng)節(jié)點(diǎn)。使用適用于節(jié)點(diǎn) 2 的信息重復(fù)相同的命令。在每個(gè)終端中,以下日志指示成功:

INFO [05-13|16:17:40.061] Maximum peer count ETH=50 LES=0 total=50

INFO [05-13|16:17:40.061] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"

INFO [05-13|16:17:40.061] Set global gas cap cap=50,000,000

INFO [05-13|16:17:40.061] Allocated trie memory caches clean=154.00MiB dirty=256.00MiB

INFO [05-13|16:17:40.061] Allocated cache and file handles database=/home/go-ethereum/node1/geth/chaindata cache=512.00MiB handles=524,288

INFO [05-13|16:17:40.094] Opened ancient database database=/home/go-ethereum/node1/geth/chaindata/ancient readonly=false

INFO [05-13|16:17:40.095] Initialised chain configuration config="{ChainID: 123454321 Homestead: 0 DAO: nil DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: 0 Petersburg: 0 Istanbul: nil, Muir Glacier: nil, Berlin: nil, London: nil, Arrow Glacier: nil, MergeFork: nil, Terminal TD: nil, Engine: clique}"

INFO [05-13|16:17:40.096] Initialising Ethereum protocol network=123,454,321 dbversion=8

INFO [05-13|16:17:40.098] Loaded most recent local header number=0 hash=c9a158..d415a0 td=1 age=53y1mo2w

INFO [05-13|16:17:40.098] Loaded most recent local full block number=0 hash=c9a158..d415a0 td=1 age=53y1mo2w

INFO [05-13|16:17:40.098] Loaded most recent local fast block number=0 hash=c9a158..d415a0 td=1 age=53y1mo2w

INFO [05-13|16:17:40.099] Loaded local transaction journal transactions=0 dropped=0

INFO [05-13|16:17:40.100] Regenerated local transaction journal transactions=0 accounts=0

INFO [05-13|16:17:40.100] Gasprice oracle is ignoring threshold set threshold=2

WARN [05-13|16:17:40.100] Unclean shutdown detected booted=2022-05-13T16:16:46+0100 age=54s

INFO [05-13|16:17:40.100] Starting peer-to-peer node instance=Geth/v1.10.18-unstable-8d84a701-20220503/linux-amd64/go1.18.1

INFO [05-13|16:17:40.130] New local node record seq=1,652,454,949,228 id=f1364e6d060c4625 ip=127.0.0.1 udp=30306 tcp=30306

INFO [05-13|16:17:40.130] Started P2P networking self=enode://87606cd0b27c9c47ca33541d4b68cf553ae6765e22800f0df340e9788912b1e3d2759b3d1933b6f739c720701a56ce26f672823084420746d04c25fc7b8c6824@127.0.0.1:30306

INFO [05-13|16:17:40.133] IPC endpoint opened url=/home/go-ethereum/node1/geth.ipc INFO [05-13|16:17:40.785] Unlocked account address=0xC1B2c0dFD381e6aC08f34816172d6343Decbb12b

INFO [05-13|16:17:42.636] New local node record seq=1,652,454,949,229 id=f1364e6d060c4625 ip=82.11.59.221 udp=30306 tcp=30306

INFO [05-13|16:17:43.309] Mapped network port proto=tcp extport=30306 intport=30306 interface="UPNP IGDv1-IP1"

INFO [05-13|16:17:43.822] Mapped network port proto=udp extport=30306 intport=30306 interface="UPNP IGDv1-IP1" [05-13|16:17:50.150] Looking for peers peercount=0 tried=0 static=0

INFO [05-13|16:18:00.164] Looking for peers peercount=0 tried=0 static=0

In the first terminal that is currently running the logs resembling the following will be displayed, showing the discovery process in action:在當(dāng)前正在運(yùn)行的第一個(gè)終端中,將顯示類(lèi)似于以下內(nèi)容的日志,顯示正在運(yùn)行的發(fā)現(xiàn)過(guò)程:

INFO [05-13|15:50:03.645] New local node record seq=1,652,453,403,645 id=a2d37f4a7d515b3a ip=nil udp=0 tcp=0

TRACE[05-13|16:15:49.228] PING/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil TRACE[05-13|16:15:49.229] PONG/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil TRACE[05-13|16:15:49.229] PING/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil TRACE[05-13|16:15:49.230] PONG/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil TRACE[05-13|16:15:49.730] FINDNODE/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:49.731] NEIGHBORS/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:50.231] FINDNODE/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:50.231] NEIGHBORS/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:50.561] FINDNODE/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:50.561] NEIGHBORS/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:50.731] FINDNODE/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:50.731] NEIGHBORS/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:51.231] FINDNODE/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:51.232] NEIGHBORS/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:52.591] FINDNODE/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:52.591] NEIGHBORS/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

TRACE[05-13|16:15:57.767] PING/v4 id=f1364e6d060c4625 addr=127.0.0.1:30306 err=nil

It is now possible to attach a Javascript console to either node to query the network properties:現(xiàn)在可以將?Javascript?控制臺(tái)附加到任一節(jié)點(diǎn)以查詢(xún)網(wǎng)絡(luò)屬性

geth attach node1/geth.ipc

Once the Javascript console is running, check that the node is connected to one other peer (node 2):運(yùn)行 Javascript 控制臺(tái)后,檢查節(jié)點(diǎn)是否連接到另一個(gè)對(duì)等節(jié)點(diǎn)(節(jié)點(diǎn) 2):

net.peerCount

The details of this peer can also be queried and used to check that the peer really is Node 2:還可以查詢(xún)此peer的詳細(xì)信息,并用于檢查該peer是否確實(shí)是節(jié)點(diǎn) 2:

admin.peers

This should return the following:

[{ caps: ["eth/66", "snap/1"], enode: "enode://6a4576fb12004aa13949dbf25de978102483a6521e6d5d87c5b7ccb1944bbf8995dc730303ae891732410b1dd2e684277e9292fc0a17372a789bb4e87bdf366b@127.0.0.1:30307", id: "d300c59ba301abcb5f4a3866aab6f833857c3ddf2f0febb583410b1dc466f175", name: "Geth/v1.10.18-unstable-8d84a701-20220503/linux-amd64/go1.18.1", network: { inbound: false, localAddress: "127.0.0.1:56620", remoteAddress: "127.0.0.1:30307", static: false, trusted: false }, protocols: { eth: { difficulty: 1, head: "0xc9a158a687eff8a46128bd5b9aaf6b2f04f10f0683acbd7f031514db9ad415a0", version: 66 }, snap: { version: 1 } } }]

The account associated with Node 1 was supposed to be funded with some ether at the chain genesis. This can be checked easily using eth.getBalance():

eth.getBalance(eth.accounts[0])

This account can then be unlocked and some ether sent to Node 2, using the following commands:

// send some Wei
eth.sendTransaction({
  to: '0xc94d95a5106270775351eecfe43f97e8e75e59e8',
  from: eth.accounts[0],
  value: 25000
});

//check the transaction was successful by querying Node 2's account balance
eth.getBalance('0xc94d95a5106270775351eecfe43f97e8e75e59e8');

The same steps can then be repeated to attach a console to Node 2.

Summary

This page explored the various options for configuring a local private network. A step by step guide showed how to set up and launch a private network, unlock the associated accounts, attach a console to check the network status and make some basic interactions.本頁(yè)探討了配置本地私鏈網(wǎng)絡(luò)的各種選項(xiàng)。分步指南展示了如何設(shè)置和啟動(dòng)私鏈網(wǎng)絡(luò)、解鎖關(guān)聯(lián)帳戶(hù)、附加控制臺(tái)以檢查網(wǎng)絡(luò)狀態(tài)以及進(jìn)行一些基本交互。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-477161.html

到了這里,關(guān)于《如何搭建一條私有多Geth節(jié)點(diǎn)的鏈》最新版以太坊私鏈搭建官方文檔要點(diǎn)翻譯的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 如何安裝官網(wǎng)最新版Android Studio

    如何安裝官網(wǎng)最新版Android Studio

    1、進(jìn)入android studio官網(wǎng),點(diǎn)擊下載。 2、下滑查看協(xié)議,勾選同意按鈕,點(diǎn)擊下載。 3、打開(kāi)安裝程序,點(diǎn)擊Next。 4、選擇虛擬機(jī),點(diǎn)擊Next。 5、選擇安裝路徑,點(diǎn)擊Next。 6、點(diǎn)擊Install。 7、等待安裝成功,點(diǎn)擊Next。 8、點(diǎn)擊Finish。 9、點(diǎn)擊OK。 10、開(kāi)始打開(kāi)Android Studio。 11、第

    2024年02月08日
    瀏覽(22)
  • IntelliJ IDEA 2023 最新版如何試用?IntelliJ IDEA 2023最新版試用方法及驗(yàn)證ja-netfilter配置成功提示

    IntelliJ IDEA 2023 最新版如何試用?IntelliJ IDEA 2023最新版試用方法及驗(yàn)證ja-netfilter配置成功提示

    ???? 博主貓頭虎 帶您 Go to New World.??? ?? 博客首頁(yè)——貓頭虎的博客?? ??《面試題大全專(zhuān)欄》 文章圖文并茂??生動(dòng)形象??簡(jiǎn)單易學(xué)!歡迎大家來(lái)踩踩~?? ?? 《IDEA開(kāi)發(fā)秘籍專(zhuān)欄》學(xué)會(huì)IDEA常用操作,工作效率翻倍~?? ?? 《100天精通Golang(基礎(chǔ)入門(mén)篇)》學(xué)會(huì)Golang語(yǔ)言

    2024年02月05日
    瀏覽(26)
  • 忘記mysql密碼后如何修改密碼(2022最新版詳細(xì)教程保姆級(jí))

    忘記mysql密碼后如何修改密碼(2022最新版詳細(xì)教程保姆級(jí))

    一共用到兩個(gè)cmd窗口,每一個(gè)都要以管理員身份打開(kāi) ,且在修改密碼后,要先關(guān)閉第一個(gè) 跳過(guò)驗(yàn)證密碼的mysql服務(wù) 的cmd窗口,再啟動(dòng)mysql,否則會(huì)出錯(cuò)。 在修改密碼前,mysql必須處于關(guān)閉狀態(tài)。 1.以 管理員的身份 打開(kāi) cmd窗口 , 找到mysql安裝的路徑并打開(kāi)bin目錄 2.在 bin路徑

    2024年02月06日
    瀏覽(29)
  • Spring Security6 最新版配置該怎么寫(xiě),該如何實(shí)現(xiàn)動(dòng)態(tài)權(quán)限管理

    Spring Security6 最新版配置該怎么寫(xiě),該如何實(shí)現(xiàn)動(dòng)態(tài)權(quán)限管理

    Spring Security 在最近幾個(gè)版本中配置的寫(xiě)法都有一些變化,很多常見(jiàn)的方法都廢棄了,并且將在未來(lái)的 Spring Security7 中移除,因此又補(bǔ)充了一些新的內(nèi)容,重新發(fā)一下,供各位使用 Spring Security 的小伙伴們參考。 接下來(lái),我把從 Spring Security5.7 開(kāi)始(對(duì)應(yīng) Spring Boot2.7 開(kāi)始),各

    2024年02月12日
    瀏覽(24)
  • 以太坊最新windows安裝Geth并啟動(dòng)私有鏈

    以太坊最新windows安裝Geth并啟動(dòng)私有鏈

    最近開(kāi)始研究區(qū)塊鏈,因?yàn)榉N種原因,最終選擇在win10下去安裝基于golang的以太坊客戶(hù)端Geth。并且搭建了一條屬于自己的私有鏈,在私有鏈的環(huán)境下實(shí)現(xiàn)轉(zhuǎn)賬交易。 先保證自己配置了golang的語(yǔ)言環(huán)境,然后下載geth,進(jìn)入官網(wǎng)https://geth.ethereum.org/downloads/,選擇windows版本。但是

    2024年02月02日
    瀏覽(15)
  • 貓頭虎分享:Linux 如何安裝最新版的Docker和Docker-Compose 教程 ?

    貓頭虎分享:Linux 如何安裝最新版的Docker和Docker-Compose 教程 ?

    博主貓頭虎的技術(shù)世界 ?? 歡迎來(lái)到貓頭虎的博客 — 探索技術(shù)的無(wú)限可能! 專(zhuān)欄鏈接 : ?? 精選專(zhuān)欄 : 《面試題大全》 — 面試準(zhǔn)備的寶典! 《IDEA開(kāi)發(fā)秘籍》 — 提升你的IDEA技能! 《100天精通Golang》 — Go語(yǔ)言學(xué)習(xí)之旅! 領(lǐng)域矩陣 : ?? 貓頭虎技術(shù)領(lǐng)域矩陣 : 深入探索

    2024年02月01日
    瀏覽(100)
  • 如何在本地(個(gè)人電腦上)安裝Tomcat服務(wù)器并部署web項(xiàng)目?【2023最新版】

    如何在本地(個(gè)人電腦上)安裝Tomcat服務(wù)器并部署web項(xiàng)目?【2023最新版】

    服務(wù)器軟件:apache-tomcat-8.5.27 操作系統(tǒng):Windows 10 64位 家庭版 構(gòu)成: 硬件 : 電腦 ,提供服務(wù)供其它客戶(hù)電腦訪(fǎng)問(wèn) 軟件 : 電腦上安裝的服務(wù)器軟件 ,安裝后能提供服務(wù)給網(wǎng)絡(luò)中的其他計(jì)算機(jī), 將本地文件映射成一個(gè)虛擬的url地址供網(wǎng)絡(luò)中的其他人訪(fǎng)問(wèn)。 作用: Web服務(wù)器

    2024年02月10日
    瀏覽(138)
  • 如何在本地搭建Maven環(huán)境并整合進(jìn)IDEA中以及創(chuàng)建web工程?【2023最新版】

    如何在本地搭建Maven環(huán)境并整合進(jìn)IDEA中以及創(chuàng)建web工程?【2023最新版】

    編譯軟件:IntelliJ IDEA 2019.2.4 x64 操作系統(tǒng):win10 x64 位 家庭版 Maven版本:apache-maven-3.6.3 使用Maven之前 : 自行在網(wǎng)絡(luò)中下載iar包,效率較低 。如在谷歌、百度中搜素相關(guān) jar包資源 使用Maven之后 : 統(tǒng)一在一個(gè)地址下載jar包等資源 。如使用阿里云鏡像服務(wù)器下載等.… 使用Mave

    2024年02月02日
    瀏覽(29)
  • 如何在macOS上使用最新版的Bison來(lái)構(gòu)建項(xiàng)目,而不是Xcode工具鏈內(nèi)嵌的2.3版本

    在很多項(xiàng)目的編譯中需要使用 Bison,而且版本需要至少為 3.0,不然會(huì)出現(xiàn)以下錯(cuò)誤。 這時(shí)候你可能使用 brew install bison 安裝了最新版的 Bison,但是還是會(huì)有這個(gè)問(wèn)題。 解決這個(gè)問(wèn)題有兩種方案: 讓手動(dòng)安裝版本在環(huán)境變量 PATH 的位置在 Xcode 安裝的版本前面; 手動(dòng)指定一下

    2024年02月09日
    瀏覽(28)
  • SpringSecurity最新版從入門(mén)到精通,WebSecurityConfigurerAdapter已經(jīng)過(guò)時(shí)?最新版來(lái)了。

    SpringSecurity最新版從入門(mén)到精通,WebSecurityConfigurerAdapter已經(jīng)過(guò)時(shí)?最新版來(lái)了。

    提示:文章寫(xiě)完后,目錄可以自動(dòng)生成,如何生成可參考右邊的幫助文檔 spring security的超詳細(xì)配置和使用攻略,包括從登錄校驗(yàn)開(kāi)始到不同頁(yè)面、不同功能的權(quán)限管理,包括了整合thymeleaf框架、用戶(hù)登錄信息持久化處理、csrf防護(hù)等web安全。 SpringSecurity是SpringBoot支持的高度可

    2024年02月13日
    瀏覽(27)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包