以太坊区块链同步

by Lukas Lukac

卢卡斯·卢卡奇(Lukas Lukac)

Ethereu M 69:如何在10分钟内建立完全同步的区块链节点 (Ethereum 69: how to set up a fully synced blockchain node in 10 mins)

Welcome in the first article of our new go-ethereum series!

欢迎来到我们新的以太坊系列的第一篇文章!

In the next 10 mins you will:

在接下来的10分钟内,您将:

  • Learn the first blockchain glossary without any necessary prior ecosystem knowledge在没有任何必要的先前生态系统知识的情况下学习第一个区块链词汇表
  • Setup your fully synced testing node (“client/server”) in under 10mins

    10分钟下 你的设置完全同步测试节点 (“客户端/服务器”)

  • Create your account and receive a transaction of 8ETH from the Ethereum foundation for FREE

    创建您的帐户并免费获得以太坊基金会的8ETH交易

Our motto is, practice before theory — so let’s jump straight into the installation of a fully synced Ethereum testing node connected to a Rinkeby test network!

我们的座右铭是理论实践之前的实践-因此,让我们直接进入连接到Rinkeby测试网络的完全同步的以太坊测试节点的安装!

格思 (Geth)

Geth is a command line interface (CLI), a compiled binary, program, and client for running a full Ethereum node implemented in Go.

Geth是一个命令行界面(CLI),是一个已编译的二进制文件,程序和客户端,用于运行Go中实现的完整以太坊节点。

We will use Geth to:

我们将使用Geth来:

  • run a fully synced Ethereum node to connect to a test network called Rinkeby运行完全同步的以太坊节点以连接到名为Rinkeby的测试网络
  • create a new account to be able to send and receive transactions创建一个新帐户以能够发送和接收交易
  • for reading the EVM state, e.g. checking a balance of any account (want to know how much balance your girlfriend, boyfriend, wife, neighbour has? Sweet transparency!)用于读取EVM状态,例如检查任何帐户的余额(想知道您的女朋友,男朋友,妻子,邻居的余额是多少?透明性好!)

安装Geth (Installing Geth)

We can install it directly from the repositories:

我们可以直接从存储库安装它:

Mac

苹果电脑

brew tap ethereum/ethereumbrew install ethereum

Linux

的Linux

sudo apt-get install software-properties-commonsudo add-apt-repository -y ppa:ethereum/ethereumsudo apt-get updatesudo apt-get install ethereum

Windows

视窗

Good luck :)

Verify the installation:

验证安装:

which geth> /usr/local/bin/geth
geth version> Geth> Version: 1.8.20-stable

Ensure you are running the same version in order to be able to perform a full sync of a Rinkeby network, as described in the next steps because Rinkeby actioned a constantinople hardfork supported by Geth 1.8.20. This detailed blog post explains more details if you are intrigued!

确保能够运行同一版本,以便能够完全同步Rinkeby网络,如以下步骤所述,因为Rinkeby采取了Geth 1.8.20支持的君士坦丁堡硬叉。 如果您对此感兴趣,这篇详细的博客文章将解释更多详细信息!

运行区块链节点 (Running a blockchain node)

Well, the devil is in the details…but getting started is actually simple. Kudos to the Ethereum developers.

好吧,魔鬼在细节中……但是入门实际上很简单。 对以太坊开发人员表示敬意。

Let’s setup a new fully synced Rinkeby (Ethereum test network using the Clique PoA protocol) node.

让我们设置一个新的完全同步的Rinkeby (使用Clique PoA协议的以太坊测试网络) 节点

The Rinkeby PoA implementation is much faster but significantly less secure. It is more centralised from the mainnet concensus PoW which is perfectly fine being a test network. Rinkeby manages to approve a new block with a bunch of transactions every 15s.

Rinkeby PoA实施速度更快,但安全性大大降低。 它是从Mainnet共识PoW集中的,这是一个很好的测试网络。 Rinkeby设法每15秒批准一堆新交易。

Ok, ok, ok...What do those words actually mean?

好吧,好吧,好吧...这些词实际上是什么意思?

  • Rinkeby: name of the Proof of Authority test network

    Rinkeby:权威证明测试网络的名称

  • Node: basically a traditional server executing Ethereum client/server

    节点:基本上是执行以太坊客户端/服务器的传统服务器

  • Concensus: an algorithm defining how the transactions will be validated, appended, and persisted in the database on every Node

    共识:一种算法,定义如何在每个节点上的数据库中验证,附加和持久化事务

  • Block: a bunch of transactions in a complicated array dispatched around the wire between all the nodes of the network every 15s

    块:每15秒围绕网络的所有节点之间的电线分派一堆复杂阵列中的交易

  • Transaction: don’t think about a bank transaction. A blockchain transaction is a state change. Renaming the owner of a smart contract from Alice to Bob? Changing balance of your account from 1ETH to 5ETH? Setting variable “foo” value to “foo_value_123” in your smart contract? That’s a transaction.

    交易:不要考虑银行交易。 区块链交易是一种状态变化。 将智能合约的所有者从爱丽丝重命名为鲍勃? 您的帐户余额从1ETH更改为5ETH? 在您的智能合约中将变量“ foo”的值设置为“ foo_value_123”吗? 那是一笔交易。

You can read more about the Rinkeby PoA proposal here: https://github.com/ethereum/EIPs/issues/225

您可以在此处阅读有关Rinkeby PoA提案的更多信息: https : //github.com/ethereum/EIPs/issues/225

geth --rinkeby --datadir=~/.gophersland_ethereum_r1 --port=30304 --cache=2048 --rpc --rpcport=8546 --rpcapi=eth,web3,net,personal --syncmode=fast

The above command will:

上面的命令将:

  • initialize a new directory where all data will be stored in ~/.gophersland_ethereum_r1. The default directory would be: ~/.ethereum

    初始化一个新目录,所有数据都将存储在~/.gophersland_ethereum_r1 。 默认目录为: ~/.ethereum

  • start downloading the Ethereum history necessary to become a new fully valid, synced Node of the network开始下载以太坊历史记录,以成为网络的一个新的完全有效的,同步的节点
  • the communication will happen over port 30304通信将通过端口30304进行
  • cache, a kind of a buffer, will be set to 2GB to speed up the sync process缓存(一种缓冲区)将设置为2GB,以加快同步过程
  • additional RPC API will launch so we can communicate with our node through consoles, nice GUI over on port 8546, later on还将启动其他RPC API,以便我们可以通过控制台,端口8546上的漂亮GUI与控制台与节点通信,稍后再通过

Wait for few hours until the blockchain is fully synced.

等待几个小时,直到区块链完全同步。

The current block number as of 24th of September is: 3039786. On my AMD Ryzen 5 2600, 3.4Ghz, the sync process took 3 hours. Oh yes, I have a new gaming PC!

截至9月24日,当前块编号为:3039786。在我的AMD Ryzen 5 2600(3.4Ghz)上,同步过程花费了3个小时。 哦,是的,我有一台新的游戏PC!

Meanwhile you can follow GophersLand on Twitter or prepare dinner, probably breakfast as well, go to the gym… let’s just say, blockchain is not the fastest database :)

同时,您可以在Twitter上关注GophersLand或准备晚餐,可能还包括早餐,还可以去体育馆……让我们说,区块链不是最快的数据库:)

Eventually the printed message will be:

最终,打印出来的消息将是:

  • INFO [<time>] Imported new chain segment count=1INFO [<时间>]导入的新链段数= 1
  • INFO [<time>] Imported new chain segment count=1INFO [<时间>]导入的新链段数= 1
  • INFO [<time>] Imported new chain segment count=1INFO [<时间>]导入的新链段数= 1
  • INFO [<time>] Imported new chain segment count=1INFO [<时间>]导入的新链段数= 1

Congratulation, you are now part of the blockchain revolution in less than 10mins!!!

恭喜,您现在不到10分钟即可参与区块链革命!!!

创建您的第一个区块链账户 (Creating your first blockchain account)

密钥库 (Keystore)

All the Ethereum accounts and their keys are stored in a directory called the “keystore”. The directory is empty by default as we haven’t created our own account yet!

所有以太坊账户及其密钥都存储在名为“ keystore ”的目录中。 默认情况下该目录为空,因为我们尚未创建自己的帐户!

enchanter@lukas-gaming:~$ ls -la ~/.gophersland_ethereum_r1/
drwx------  4 enchanter enchanter 4096 sep 24 15:26 .drwxr-xr-x 18 enchanter enchanter 4096 sep 24 11:51 ..drwx------  4 enchanter enchanter 4096 sep 24 15:26 gethsrw-------  1 enchanter enchanter    0 sep 24 15:26 geth.ipcdrwx------  2 enchanter enchanter 4096 sep 23 09:54 keystore
enchanter@lukas-gaming:~$ ls -la ~/.gophersland_ethereum_r1/keystore/
drwx------ 2 enchanter enchanter 4096 sep 23 09:54 .drwx------ 4 enchanter enchanter 4096 sep 24 15:26 ..

帐户 (Account)

To create a new account, execute the following, already familiar, geth cmd.

要创建一个新帐户,请执行以下已经很熟悉的geth cmd。

geth --datadir=~/.gophersland_ethereum_r1 account new

You will be prompted to enter a passphrase (this is your SUPER SECRET PASSWORD). This is required for decrypting your newly generated private key associated with your new Ethereum address, as it allows you to use it later on for signing transactions on the blockchain. Note it down somewhere, since we will need it later. But don’t worry if you forget it, this is just a test network anyway.

系统将提示您输入密码(这是您的超级密码)。 这是解密与新的以太坊地址关联的新生成的私钥所必需的,因为它允许您以后使用它在区块链上签署交易。 记下它,因为稍后我们将需要它。 但是请放心,如果您忘记了它,无论如何这只是一个测试网络。

enchanter@lukas-gaming:~$ ls -la ~/.gophersland_ethereum_r1/keystore/
drwx------ 2 enchanter enchanter 4096 sep 23 09:54 .drwx------ 4 enchanter enchanter 4096 sep 24 15:26 ..
enchanter@lukas-gaming:~$ geth --datadir=~/.gophersland_ethereum_r1 account new
INFO [09-24|15:36:33.566] Maximum peer count                       ETH=25 LES=0 total=25
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: Repeat passphrase:
Address: {ceee57f2b700c2f37d1476a7974965e149fce2d4}
enchanter@lukas-gaming:~$ ls -la ~/.gophersland_ethereum_r1/keystore/
drwx------ 2 enchanter enchanter 4096 sep 24 15:36 .drwx------ 4 enchanter enchanter 4096 sep 24 15:26 ..-rw------- 1 enchanter enchanter  491 sep 24 15:36
UTC--2018-09-24T13-36-43.069452577Z--ceee57f2b700c2f37d1476a7974965e149fce2d4

Woohoo! My new Ethereum address is alive: ceee57f2b700c2f37d1476a7974965e149fce2d4.

hoo! 我新的以太坊地址还活着: ceee57f2b700c2f37d1476a7974965e149fce2d4.

You will normally encounter this address prefixed with “0x” to indicate the address encoding, HEX.

通常,您会遇到以“ 0x ”为前缀的该地址,以指示地址编码HEX

The newest format of the keyfiles is: UTC--<created_at UTC ISO8601>-<your address in hex encoding>. The order of accounts when listing is lexicographic, but as a consequence of the timespamp format, it is actually in order of creation.

密钥文件的最新格式为:UTC- UTC--<created_at UTC ISO8601>-<your address in hex编码UTC--<created_at UTC ISO8601>-<your address in hex >。 列出时的帐户顺序是按字典顺序排列的,但由于时间戳格式的影响,实际上是按创建顺序排列的。

If you are curious what is inside of the file, feel free to open it! You will see:

如果您好奇文件的内容,请随时打开它! 你会看见:

  • Address: your new hex address

    地址:您的新十六进制地址

  • Crypto: bunch of mathematical variables responsible for representing your private key in encrypted form, don’t worry about that magic for now

    加密:一堆数学变量,负责以加密形式表示您的私钥,暂时不必担心这种魔术

Interesting note: the account generation happens in offline mode and doesn’t require a synced blockchain node. Curious how is it possible to generate a unique address in an offline mode from the technical perspective? We will check out the go-ethereum source code itself in the next article.

有趣的是:帐户生成在离线模式下进行,不需要同步的区块链节点。 好奇从技术角度来看如何在离线模式下生成唯一地址? 我们将在下一篇文章中查看go-ethereum源代码本身。

Spoiler: it’s because the address is a hash of your public key which is based on your unique, private key.

破坏者:这是因为地址是基于您的唯一私钥的公钥的哈希。

Okay I have a new shinny Ethereum account, what’s my balance and how do I deposit some testing Ether?

好的,我有一个新的以太坊账户,我的余额是多少?如何存入一些测试以太币?

Speaking of Ether… what is it actually?

说到以太……实际上是什么?

醚 (Ether)

Ether is the cryptocurrency powering the Ethereum network. It’s used as a unit of value and for paying miners for validating, appending, and persisting the transactions to the collective DB. But mainly its a technique for preventing SPAM because miners are rewarded 5 (since last month “just” 3) ETH for each successfully mined block. Yes, that’s $600 at the current price on 24th of September, every 15s. Not a bad business.

以太是为以太坊网络提供动力的加密货币。 它被用作价值单位,并用于向矿工付费以验证,附加交易并将交易持久化到集体数据库中。 但主要是它的一种防止SPAM的技术,因为每成功开采一个区块,矿工将获得5个ETH的奖励(自上个月以来仅为3个)。 是的,按9月24日的当前价格(每15秒)计算,价格为600美元。 生意不错。

如何免费从以太坊基金会接收8ETH交易 (How to receive a transaction of 8ETH from the Ethereum foundation for FREE)

查看账户余额 (Checking account balance)

Let’s make sure our account balance is 0 first, unless someone already managed to send some Ether out of the goodness of their heart.

让我们确保我们的帐户余额首先为0,除非有人已经设法将一些以太币发送出去。

Geth provides a JavaScript console that can be attached to the executable binary for interacting with the blockchain conveniently. We can connect to it by specifying a socket file that is exposed once Geth boots up. Socket files are very useful for “inter process communication on the same machine”, aka IPC.

Geth提供了一个JavaScript控制台,可以将其附加到可执行二进制文件中,以方便地与区块链进行交互。 我们可以通过指定一个在Geth启动后公开的套接字文件来连接到它。 套接字文件对于“同一机器上的进程间通信”(也称为IPC)非常有用。

You can locate this file in the the default data directory while the Geth program is running:

在Geth程序运行时,可以在默认数据目录中找到此文件:

enchanter@lukas-gaming:~$ ls -la ~/.gophersland_ethereum_r1/
drwx------  4 enchanter enchanter 4096 Sep 24 15:44 .drwxr-xr-x 18 enchanter enchanter 4096 Sep 24 15:47 ..drwx------  4 enchanter enchanter 4096 Sep 24 15:44 gethsrw-------  1 enchanter enchanter    0 Sep 24 15:44 geth.ipcdrwx------  2 enchanter enchanter 4096 Sep 24 15:47 keystore

Let’s interact with the Rinkeby network using the “geth attach” cmd in another terminal while your blockchain node is still running. Make sure to pass the absolute path to the IPC file, otherwise you will get an error.

当您的区块链节点仍在运行时,让我们在另一个终端中使用“ geth attach ” cmd与Rinkeby网络进行交互。 确保将绝对路径传递到IPC文件,否则会出现错误。

enchanter@lukas-gaming:~$ geth attach ipc:/home/enchanter/.gophersland_ethereum_r1/geth.ipc
Welcome to the Geth JavaScript console!
instance: Geth/v1.8.15-stable-89451f7c/linux-amd64/go1.10.1coinbase: 0xceee57f2b700c2f37d1476a7974965e149fce2d4at block: 3044891 (Mon, 24 Sep 2018 16:42:36 CEST)
datadir: /home/enchanter/.gophersland_ethereum_r1modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
&gt; eth.accounts["0xceee57f2b700c2f37d1476a7974965e149fce2d4"]
&gt; eth.syncingfalse
&gt; eth.getBalance("0xceee57f2b700c2f37d1476a7974965e149fce2d4")0

查询区块链: (Query blockchain:)

eth.accounts: to check your currently available accounts

eth.accounts:检查您当前可用的帐户

eth.syncing: to make sure our state, DB is fully up to date with rest of the network to ensure the getBalance response will be based on the latest state

eth.syncing:为确保我们的状态,数据库与网络的其余部分完全保持最新,以确保getBalance响应将基于最新状态

eth.getBalance(“<your address&gt;”): to query the DB.

eth.getBalance(“ <您的地址& gt;”)):查询数据库。

免费从以太坊基金会接收8ETH交易 (Receiving a transaction of 8ETH from the Ethereum foundation for FREE)

The Ethereum foundation has a very neat program called “Faucet” available online for assigning Ether to accounts requesting it in real-time.

以太坊基金会有一个非常简洁的程序,称为“ 水龙头 ”,可以在线使用,用于将以太币实时分配给请求它的账户。

Requesting Ether:

请求以太币:

  1. Publish your account address on one of the public social networks在一个公共社交网络上发布您的帐户地址
  2. E.g, post a tweet containing your Ethereum address anywhere in the tweet like this one https://twitter.com/EnchanterIO/status/1044238559224483841, make sure you tag @BlocksByLukas and @freeCodeCamp and let us know if you like the tutorial!

    例如,像这样的一条推文中的任何地方发布一条包含您的以太坊地址的推文https://twitter.com/EnchanterIO/status/1044238559224483841 ,确保您标记@BlocksByLukas和@freeCodeCamp并让我们知道您是否喜欢本教程!

  3. Open https://www.rinkeby.io/#faucet and paste the tweet URL

    打开https://www.rinkeby.io/#faucet并粘贴推文URL

  4. Click on “Give me Ether”, choose between 3, 7.5 or 18.75 Ether点击“给我以太币”,在3、7.5或18.75以太币之间进行选择
  5. Wait few seconds等待几秒钟
  6. Query your account balance again再次查询您的帐户余额

Voilà (Voilà)

You are rich… in a test network. Congratulation for getting so far. More content coming soon!

您很有钱……拥有一个测试网络。 恭喜! 更多内容即将推出!

继续我的课程:以太坊101 (Continue in my course: Ethereum 101)

https://www.lukaslukac.io/courses/ethereum-101-glossary-smart-contracts-tests-frameworks

https://www.lukaslukac.io/courses/ethereum-101-glossary-smart-contracts-tests-frameworks

翻译自: https://www.freecodecamp.org/news/ethereum-69-how-to-set-up-a-fully-synced-blockchain-node-in-10-mins-f6318d7aad40/

以太坊区块链同步

以太坊区块链同步_以太坊69:如何在10分钟内建立完全同步的区块链节点相关推荐

  1. 【手把手】如何在10分钟内搭建一个以太坊私有链?

    在开发以太坊时,很多时候需要搭建一条以太坊私有链,这篇来自作者熊丽兵的文章,手把手教你10分钟内如何在Mac上进行搭建. 作者 | 熊丽兵 整理 | 科科 阅读本文前,你应该对以太坊语言有所了解,如果 ...

  2. 用python做预测模型的好处_如何用Python在10分钟内建立一个预测模型

    匿名用户 1级 2017-01-01 回答 预测模型的分解过程 我总是集中于投入有质量的时间在建模的初始阶段,比如,假设生成.头脑风暴.讨论或理解可能的结果范围.所有这些活动都有助于我解决问题,并最终 ...

  3. github创建静态页面_如何在10分钟内使用GitHub Pages创建免费的静态站点

    github创建静态页面 Static sites have become all the rage, and with good reason – they are blazingly fast a ...

  4. 愉快的舞会c++_如何在5分钟内建立一个令人愉快的加载屏幕

    愉快的舞会c++ First, here is what we will build. Set your timer! 首先,这是我们将要建立的. 设置您的计时器! Does this look fa ...

  5. es6 ... 添加属性_如何在10分钟内免费将HTTPS添加到您的网站,以及为什么您现在不止需要这样做......

    es6 ... 添加属性 by Ayo Isaiah 通过Ayo Isaiah 如何在10分钟内免费将HTTPS添加到您的网站,以及为什么现在比以往更需要这样做 (How to add HTTPS t ...

  6. javascript创建类_如何在10分钟内使用JavaScript创建费用管理器

    javascript创建类 by Per Harald Borgen 通过Per Harald Borgen 如何在10分钟内使用JavaScript创建费用管理器 (How to create an ...

  7. 机器人坐标系建立_如何在30分钟内建立一个简单的搜索机器人

    机器人坐标系建立 by Quinn Langille 奎因·兰吉尔(Quinn Langille) 如何在30分钟内建立一个简单的搜索机器人 (How to Build A Simple Search ...

  8. 钢铁侠头盔制作图纸下载_如何在10分钟内制作头盔图

    钢铁侠头盔制作图纸下载 我每天的大部分时间都涉及创建,修改和部署Helm图表以管理应用程序的部署. Helm是Kubernetes的应用程序包管理器,负责协调应用程序的下载,安装和部署. Helm图表 ...

  9. bootstrap设计登录页面_前端小白如何在10分钟内打造一个爆款Web响应式登录界面?...

    对于前端小白(例如:专注后端代码N年的攻城狮),自己编写一个漂亮的Web登录页面似乎在设计上有些捉襟见肘,不懂UI设计,颜色搭配极度的混乱(主色,辅助色,配色,色彩渐变,动画效果等等,看起来一堆乱七八 ...

最新文章

  1. UITextField长度限制的写法
  2. python绘制多个条形图_python – 在Matplotlib中绘制多个直方图 – 颜色或并排条形图...
  3. Flume的Channel
  4. UILabel的高度自适应
  5. openpyxl删除添加excel列_Python | 如何使用Python操作Excel(二)
  6. 摘抄自知乎的redis相关
  7. Python常见设计模式
  8. 优达学城数据分析笔记3--------数据分析过程(python篇)
  9. android 33 对话框控件
  10. 将Ajax请求返回的json数据,转换成json对象
  11. c++ const
  12. 微信实现双向跨境支付,将向香港用户开放内地支付服务
  13. mysql数据库语法——(六)
  14. 【BZOJ-4556】字符串 后缀数组+二分+主席树 / 后缀自动机+线段树合并+二分
  15. Unity2 学习 制作和动态加载预制体
  16. 电力仿真需要学的软件?5款有实力的电力仿真软件
  17. 太平洋车险条款 太平洋保险 条款 中国保险机动车交通事故责任强制保险条款 中国保险行业协会机动车综合商业保险示范条款 中国太平洋财产保险股份有限公司神行车保机动车损失保险(IACJQL0001)条款
  18. 如何在Mozilla Firefox中启用(或禁用)Cookie
  19. java.lang.NegativeArraySizeException
  20. Monaco Editor教程(十八):使用api来完成某些键盘操作,格式化,查找,显示右侧菜单等。

热门文章

  1. 4- flutter - Widget
  2. 是否可以人为修改发表时间
  3. P4722 【模板】最大流
  4. flask的客户端服务端
  5. mysql++读写BLOB数据
  6. Ubuntu安装Anaconda
  7. Day2 - Python基础2作业【文件操作--购物车程序(用户操作及商户操作)】
  8. 克里斯坦森的破坏性创新—《可以量化的管理学》
  9. 详解使用DockerHub官方的mysql镜像生成容器
  10. webpack入门(二)what is webpack