以太坊同步节点

by Zack

由Zack

如何同步以太坊节点而不会犯我的错误 (How to sync an Ethereum node without making the mistakes I made)

When I first started developing on the Ethereum platform, syncing a node was one of the first few things I did. With no one to hold my hand and nowhere to consolidate all the common errors I encountered, I wasted weeks just syncing a node. It was such a headache that I almost gave up.

当我第一次开始在以太坊平台上进行开发时,同步节点是我做的头几件事之一。 没有人牵着我的手,也没有地方巩固我遇到的所有常见错误,我浪费了数周的时间来同步一个节点。 太头疼了,我差点放弃了。

Not knowing the terminology only made it harder.

不知道术语只会使它更难。

And so, in this article, I want to consolidate all the common errors you might face and explain the reasons behind each step when syncing a node. Hopefully, you won’t have such a nasty early experience as I did.

因此,在本文中,我想整合您可能会遇到的所有常见错误,并解释同步节点时每个步骤背后的原因。 希望您不会像我那样讨厌。

快速介绍 (A quick intro)

In Ethereum, developers create pieces of an application that run on the network. These are called smart contracts. Although you can deploy them manually without syncing to an Ethereum node, in the long run it’s more convenient for the development process to sync (especially when we want to use development frameworks like Truffle).

在以太坊中,开发人员创建在网络上运行的应用程序。 这些被称为智能合约 。 尽管您可以在不同步到以太坊节点的情况下手动部署它们,但是从长远来看,开发过程可以更方便地进行同步(尤其是当我们想使用Truffle等开发框架时)。

To sync an Ethereum node, we will need the following software:

要同步以太坊节点,我们将需要以下软件:

  • Geth — Client for an Ethereum node.Geth —以太坊节点的客户端。
  • Ethereum Wallet — User interface for an Ethereum node.以太坊钱包-以太坊节点的用户界面。

Let’s get started.

让我们开始吧。

安装Geth (Install Geth)

To download Geth, go here for Windows users. Then click on the “Geth for Windows” button.

要下载Geth,请前往Windows用户此处 。 然后单击“ Geth for Windows”按钮。

For MacOS users, I recommend that you download using homebrew. You can do so with the following commands:

对于MacOS用户,建议您使用自制软件下载。 您可以使用以下命令进行操作:

brew tap ethereum/ethereumbrew install ethereum

Refer to Geth’s instructions for more details.

有关更多详细信息,请参阅Geth的说明 。

Check that Geth is installed properly by typing geth version in the terminal (MacOS) or PowerShell (Windows).

通过在终端(MacOS)或PowerShell(Windows)中键入geth version来检查Geth是否已正确安装。

安装以太坊钱包 (Install Ethereum Wallet)

We call the GUI that interacts with the network the “wallet”. You can find many different wallets for Ethereum with a quick Google search (such as Parity, Jaxx, and MyEtherWallet). I personally like using Ethereum Wallet. It has a user-friendly interface, and I’m also a bit biased because it is developed by Ethereum itself.

我们将与网络交互的GUI称为“钱包”。 您可以通过快速的Google搜索为以太坊找到许多不同的钱包(例如Parity,Jaxx和MyEtherWallet)。 我个人喜欢使用以太坊钱包。 它具有用户友好的界面,我也有些偏颇,因为它是由以太坊本身开发的。

You can find the installer here.

您可以在此处找到安装程序。

Note: I prefer Ethereum Wallet to Mist. Mist is basically a browser that renders decentralized applications (dApps) and websites.

注意:我更喜欢Ethereum Wallet不是 Mist 。 Mist本质上是一种浏览器,用于呈现分散式应用程序(dApps)和网站。

For the development of a smart contract, we will only need the Ethereum Wallet.

为了开发智能合约,我们只需要以太坊钱包。

主网与测试网 (Mainnet vs Testnet)

In Ethereum, there are two main networks: the mainnet and the testnet.

在以太坊中,有两个主要的网络:主网和测试网。

The mainnet is used to transact real Ether. The Ether’s value is tied to real fiat currency via cryptocurrency exchanges.

主网用于交易真实的以太币。 以太币的价值通过加密货币交易与实际法定货币挂钩。

As developers, we do not want to run application tests with real money. That is what the testnet is for.

作为开发人员,我们不想用真钱来运行应用程序测试。 这就是testnet的目的。

We call the testnet Ropsten.

我们称测试网为Ropsten

Run Geth和以太坊钱包 (Run Geth and Ethereum Wallet)

When you’re developing a smart contract, you should sync the testnet first. We will only need to sync the mainnet when we are ready to deploy.

在开发智能合约时,应首先同步测试网。 当我们准备部署时,我们仅需要同步主网。

You will need about 30GB of storage space to sync a testnet. As there are more transactions in the mainnet, you will need about 100GB to sync a mainnet.

您将需要大约30GB的存储空间来同步测试网。 随着主网中有更多事务,您将需要大约100GB来同步主网。

Note: some say that you need an SSD storage for fast writing so that the sync can catch up with the latest block. Personally, I find that HDD storage is alright. However, if given the choice, I would definitely use SSD storage.

注意:有人说您需要用于快速写入的SSD存储,以便同步可以赶上最新的块。 就个人而言,我发现硬盘存储还可以。 但是,如果可以选择的话,我肯定会使用SSD存储。

对于Windows用户 (For Windows users)

For easy access, I recommend that you create a folder to store the blockchain. For example, “C:\EthereumTestnet”.

为了便于访问,我建议您创建一个文件夹来存储区块链。 例如,“ C:\ EthereumTestnet”。

After creating the folder, try running the following command:

创建文件夹后,请尝试运行以下命令:

geth — testnet — data-dir=”C:\EthereumTestnet” — rpc — rpcapi eth,web3,net,personal

Edit: It seems like some arguments have changed. If you encountered such error “flag provided but not defined: -data-dir”, try changing the argument name to — datadir instead to data-dir.

编辑:似乎有些论点已经改变。 如果遇到此类错误“提供了但未定义的标志:-data-dir”,请尝试将参数名称更改为— datadir,而不是data-dir。

The argument --testnet specifies that we want to sync to the Ropsten network. Thus, to sync the mainnet, you just need to take out the argument --testnet and change the data directory. For example:

参数--testnet指定我们要同步到Ropsten网络。 因此,要同步主网,您只需要取出参数--testnet并更改数据目录。 例如:

geth — data-dir=”C:\EthereumMainnet” — rpc — rpcapi eth,web3,net,personal

geth — data-dir=”C:\EthereumMainnet” — rpc — rpcapi eth,web3,net,personal

The --rpc argument enables the HTTP-RPC server. This allows us to use certain services, such as what is stated in --rpcapi eth,web3,net,personal.

--rpc参数启用HTTP-RPC服务器。 这使我们可以使用某些服务,例如--rpcapi eth,web3,net,personal

After entering the command, you should see something like this:

输入命令后,您应该会看到以下内容:

In order not to corrupt the blockchain, especially after many hours of syncing, you should NOT close the command prompt abruptly. Always stop the sync by pressing Ctrl + C and wait until Geth shuts down the program for you.

为了不损坏区块链,尤其是在经过多个小时的同步之后, 请勿突然关闭命令提示符。 始终通过按Ctrl + C停止同步,并等待直到Geth为您关闭程序。

However, it is difficult to remember all the command and rpc services you need. That’s why I suggest creating a shortcut or a batch file to help you.

但是,很难记住您需要的所有命令和rpc服务。 这就是为什么我建议创建快捷方式或批处理文件来帮助您的原因。

Simply create a file using any text editor you have and save it as .bat file. For example, RunGethTestnet.bat (the name is not important). Copy and paste the command into the file and save it. The next time you need to run Geth for Ropsten, just double click on the file.

只需使用您拥有的任何文本编辑器创建文件,然后将其另存为.bat文件即可。 例如, RunGethTestnet.bat (名称不重要)。 将命令复制并粘贴到文件中并保存。 下次您需要运行Geth for Ropsten时,只需双击该文件。

After running Geth, we have to run the Ethereum Wallet. As we want the interface to locate the exact location where we synced our files using Geth, we execute it from the console.

运行Geth之后,我们必须运行以太坊钱包。 因为我们希望界面找到使用Geth同步文件的确切位置,所以我们从控制台执行它。

Similar to Geth, I saved a batch file for it as well with an example command, such as the one below:

与Geth相似,我还为它保存了一个批处理文件以及一个示例命令,例如以下命令:

Note that your command might look a little different from mine, as you might store your application in a different directory.

请注意,您的命令可能与我的命令略有不同,因为您可能会将应用程序存储在其他目录中。

Alternatively, you can add the application to your path.

或者,您可以将应用程序添加到路径中。

The argument --node-datadir="C:\EthereumTestnet" states where I stored my chaindata, which is the exact same one I specified for Geth.

参数--node-datadir="C:\EthereumTestnet"表示我存储链数据的位置,这与我为Geth指定的地址完全相同。

对于Mac用户 (For Mac Users)

It is slightly simpler for MacOS, because the chaindata is downloaded automatically to the library and not hidden from us. So, we won’t need to specify the data directory.

对于MacOS来说,它稍微简单一些,因为chaindata会自动下载到该库中,而不是对我们隐藏。 因此,我们无需指定数据目录。

Nevertheless, I recommend creating a script file to make running Geth and Ethereum Wallet easier.

不过,我建议创建一个脚本文件,以使运行Geth和Ethereum Wallet更加容易。

Note: Geth has to run before Ethereum Wallet.

注意: Geth必须在以太坊钱包之前运行

Running Ethereum Wallet alone will automatically start the syncing process as it will automatically run a Geth client in the background. This is user-friendly, but does not enable the RPC services we want to use. Thus, we want to ensure RPC is enabled in both our Geth and Ethereum Wallet execution.

单独运行以太坊钱包将自动启动同步过程,因为它将在后台自动运行Geth客户端。 这是用户友好的,但未启用我们要使用的RPC服务。 因此,我们要确保在Geth和Ethereum Wallet执行过程中都启用RPC。

一些注意事项 (A few notes)

  1. The syncing process is very long, and can take up to 2–3 days. Please have patience and consider leaving your computer turned on overnight.同步过程很长,最多可能需要2到3天。 请耐心等待,并考虑让您的计算机保持通宵开机状态。
  2. The syncing speed depends on your internet speed, peers count, and writing speed of your storage drive.同步速度取决于您的互联网速度,对等方数和存储驱动器的写入速度。
  3. As the data are stored in blocks and linked together, corruption in one block can corrupt the whole chaindata. This can potentially waste your effort in waiting days for the node to sync. Therefore, it is very important to shut down your Geth properly. In certain cases, you might want to rollback. But prevention is better than cure here.

    由于数据存储在块中并链接在一起,因此一个块中的损坏会损坏整个chaindata。 这可能会浪费您的时间来等待节点同步。 因此,正确关闭Geth非常重要。 在某些情况下,您可能需要回滚 。 但是在这里预防胜于治疗。

  4. The progress bar on your Ethereum Wallet is NOT accurate. Relying on it will give you a lot of anxiety and frustration.

    以太坊钱包上的进度条正确。 依靠它会给您带来很多焦虑和沮丧。

  5. Geth runs on port 30303 for external listening.Geth在端口30303上运行以进行外部侦听。
  6. The default port used for internal communication, for example between your wallet and Geth, is 8545.用于内部通信(例如,您的钱包和Geth之间)的默认端口为8545。

确保您的Geth客户端端口已打开 (Make sure your port to Geth client is opened)

It’s really important to make sure that the connection to your Geth client is not limited. One huge headache I encountered was to let my firewall limit the number of connections I could have through the Geth client.

确保与Geth客户端的连接不受限制非常重要。 我遇到的一个巨大的麻烦就是让防火墙限制我可以通过Geth客户端建立的连接数。

You can spot this problem by looking at the peers count. If it stays consistently low at about 1–3 peers (for at least half an hour), there is a good chance your connection is limited. A healthy range is above 5 peers.

您可以通过查看同行人数来发现此问题。 如果它始终保持在大约1-3个对等方的最低水平(至少半小时),则很有可能会限制您的连接。 健康范围高于5个同行。

MacOS用户 (MacOS users)

When you run Geth, there should be a notification for you to allow connection. Well, of course, click on “Allow.

当您运行Geth时,应该有一条通知通知您允许连接。 好吧,当然,请单击“允许。

To check, go to System Preferences> System & Privacy.

要进行检查,请转到系统偏好设置>系统和隐私。

Under Firewall tab, click on Firewall Options.

在“ 防火墙”选项卡下,单击“ 防火墙选项”

Windows用户 (Windows users)

To open your port, go to Control panel > System and Security > Windows defender firewall.

要打开端口,请转到“控制面板”>“系统和安全性”>“ Windows Defender防火墙”。

Click on Advanced settings. On the side panel, click on Inbound Rules.

单击高级设置 。 在侧面板上,点击入站规则

The inbound ports you want to open are TCP and UDP 30303. So I created one rule for TCP 30303 and another for UDP 30303.

您要打开的入站端口是TCP和UDP30303。因此,我为TCP 30303创建了一个规则,为UDP 30303创建了另一个规则。

You may need to open your outbound ports for TCP 30303 too.

您可能还需要打开TCP 30303的出站端口。

Note that any third party firewall/anti-virus might limit your connections as well, so make sure to configure it accordingly.

请注意,任何第三方防火墙/防病毒软件也可能会限制您的连接,因此请确保对其进行相应配置。

依附于葛思 (Attach to Geth)

To retrieve more information about your node, you can attach to the Geth client and execute commands with it using the RPC services.

要检索有关节点的更多信息,您可以附加到Geth客户端并使用RPC服务对其执行命令。

Here’s a simple way to check your syncing status: attach to the client by entering the following command on a separate terminal/console.

这是检查同步状态的简单方法:在单独的终端/控制台上输入以下命令,将其连接到客户端。

geth attach http://127.0.0.1:8545

geth attach http://127.0.0.1:8545

Again, you might want to store it in a batch/script file for your own convenience.

同样,您可能希望将其存储在批处理/脚本文件中以方便自己。

After running the command, you should see something like this.

运行命令后,您应该会看到类似这样的信息。

Type web3.eth and you should see a lot of information. To retrieve specific information on syncing, type web3.eth.syncing instead.

键入web3.eth ,您应该会看到很多信息。 要检索有关同步的特定信息, web3.eth.syncing改为键入web3.eth.syncing

As you can see, the progress bar found at the top of the Ethereum Wallet is merely a comparison between the highestBlock and the currentBlock. As the highestBlock known to your computer might not be the actual highest block, the progress bar might not reflect the real progress.

如您所见,在以太坊钱包顶部找到的进度条仅是mostBlockcurrentBlock之间的比较。 由于您的计算机已知的highestBlock可能不是实际的最高块,因此进度条可能无法反映实际进度。

In fact, the highestBlock and knownStates will continue to increase as you sync your nodes.

实际上,当您同步节点时, highestBlockknownStates将继续增加。

最后几点 (Some final points)

As the technology is rapidly changing, always use the stable version of the client and wallet to avoid giving yourself more headaches.

随着技术的快速变化,请始终使用客户端和钱包的稳定版本,以免给自己带来更多麻烦。

Also, note that there is always a workaround for any of the issues you face. When you face a problem syncing, you can try to search for solutions as you are likely not the first one to face the same problem.

另外,请注意,对于您遇到的任何问题,总会有一种解决方法。 同步时遇到问题,您可以尝试搜索解决方案,因为您可能不是第一个遇到相同问题的人。

And always remind yourself that you do not need to sync a node to develop a smart contract. Doing so only helps to facilitate your understanding of the environment as well as your development process. So, don’t beat yourself up over it if you encounter problems so early in the development process.

并始终提醒自己,您无需同步节点即可开发智能合约。 这样做仅有助于促进您对环境以及开发过程的理解。 因此,如果您在开发过程中这么早就遇到问题,请不要打败自己。

For more of such articles, follow me or visit my site — A developer’s perspective.

有关此类文章的更多信息,请关注我或访问我的网站- 开发人员的观点 。

翻译自: https://www.freecodecamp.org/news/how-to-sync-an-ethereum-node-using-geth-and-ethereum-wallet-81423d42a583/

以太坊同步节点

以太坊同步节点_如何同步以太坊节点而不会犯我的错误相关推荐

  1. 一致性hash算法虚拟节点_一致性哈希虚拟节点

    采用固定哈希算法平衡负载 在大规模的缓存应用中,应运而生了分布式缓存系统.key-value如何均匀的分散到集群中?最常规的方式莫过于hash取模的方式.比如集群中可用机器适量为N,那么key值为K的 ...

  2. 一致性hash算法虚拟节点_一致性hash和虚拟节点

    consistent hashing 算法的原理 consistent hashing 是一种 hash 算法,简单的说,在移除 / 添加一个 cache 时,它能够尽可能小的改变已存在key 映射关 ...

  3. canal mysql多节点_数据同步的终极解决方案,阿里巴巴开源的Canal框架当之无愧!!...

    写在前面 在当今互联网行业,尤其是现在分布式.微服务开发环境下,为了提高搜索效率,以及搜索的精准度,会大量使用Redis.Memcached等NoSQL数据库,也会使用大量的Solr.Elastics ...

  4. argb可以和rgb同步吗_神光同步酷炫幻彩,安钛克光棱120 RGB风扇套装

    目前这个时代,电脑的各种配件来说,走向了万物皆要有光的风格.相信发光耳机,发光键盘,发光鼠标大家也都见过不少.侧透机箱甚至全透机箱搭配各类酷炫光效在电竞游戏领域也变得越来越火.许多小伙伴在组装一款电脑 ...

  5. 印象笔记mac版 同步问题_印象笔记同步失败怎么办?Mac电脑版

    在使用Mac端时,可能会看到客户端同步按钮出现红色感叹号❗️:刚刚编辑的笔记一直有上传的蓝色箭头⬆️:或者是有其他的错误弹窗提示等等

  6. sqlserver数据库同步软件_sqlserver同步工具_ 数据库同步解决方案

    SyncNavigator v8.6.2 SyncNavigator是一款功能强大的数据库同步软件,适用于SQL SERVER, MySQL,具有自动/定时同步数据.无人值守.故障自动恢复.同构/异构 ...

  7. amd同步多线程_首次同步多线程!AMD第三代锐龙3 3300X/3100上市:4核心8线程、PCIe 4加持...

    4月21日晚,AMD正式发布了第三代锐龙3系列处理器,这也是继线程撕裂者.锐龙9/7/5系列之后,7nm工艺.Zen2架构首次来到入门级市场. 第三代锐龙3包括锐龙3 3300X.锐龙3 3100两款 ...

  8. java json删除节点_指定json的某个节点进行增、删、改

    有时候我们需要对json结构的数据进行更新,或增,或改,或删. 当json层级比较复杂时操作起来是比较麻烦的,得一层层找下去找到要更新的节点才能操作它. 我用python语言封装了一个类,提供三个函数 ...

  9. js判断是由含有a节点_怎么判断某个dom节点是否包含某个dom节点?

    .center { display: flex; justify-content: center; align-items: center; } .main { width: 300px; heigh ...

最新文章

  1. 设置datagridview的数据源为(DATASET)SQL查寻结果
  2. [Java入门笔记] 面向对象三大特征之:封装
  3. migo获取header sap_Adjust Stock(MI06, MI07, MIGO)
  4. matlab边算边出图命令,Matlab:不包含边境和工具栏的figure(移除保存图片的白边)...
  5. (转)使用Spring的注解方式实现AOP的细节
  6. python 函数图解_Python函数说明(一)
  7. mysql search yum_mysql的yum安装与配置
  8. 苹果录屏没声音_苹果手机外放没声音,自己动手就能解决
  9. 《计算机网络:自顶向下方法》阅读笔记
  10. 从键盘输入一个阿拉伯数字,输出对应的财务数字, 用switch。/*零、壹、贰、叁、肆、伍、陆、柒、捌、玖、亿、万、仟、佰、拾。
  11. matlab逻辑回归两次成绩录取查询,【多元逻辑回归分类】基于matlab的MNIST实践
  12. javascript:alert(document.cookie)
  13. OSPF在NBMA网络中的五种模式
  14. 统计公司员工喜欢吃的水果,并打印出最喜欢吃的前K中水果【map关联式容器,k/V结构】
  15. 财务人员的6大数据分析方法
  16. 常耀俊老师经典《非人力资源经理的人力资源管理》课程
  17. 防火墙的基础配置(一)
  18. matlab 龙格现象,利用MATLAB分析数值积分中的龙格(Runge)现象(1)
  19. 一文带你吃透计算机网络(下)
  20. wampserver 2.4 配置虚拟主机

热门文章

  1. Java缓存Ehcache-核心类和方法介绍及代码实例
  2. 泛型集合 有序泛型 c#
  3. vs2012安装过程 1006
  4. django-redis的使用,利用配置中的缓存绑定数据库,直接获取连接对象
  5. mysql-外键-随堂
  6. mysql数据表的创建-数据类型
  7. 移动开发技术有哪些?
  8. OSS 上传出现异常
  9. linux中MySQL密码的恢复方法
  10. microsoft office 2007 完全 卸载 工具 来自微软官方