构建一条以太坊私链

Arthur
2022-01-02 / 0 评论 / 410 阅读 / 正在检测是否收录...
  • 建立一条以太坊私链的形式,进行账户的创建、账户间以太币的转账。
    在最简单的实践过程中巩固之前的理论知识,并为深入以太坊智能合约开发打下基础。
    以太坊社区发展很快,从2016年以来已经陆续推出了多个版本的实用开发工具。
    *示例将采用以太坊 go-ethereum (Geth) 本地客户端 + web3.js 的组合。

MacOS环境下下安装Geth

  • 首先安装Geth
    brew tap ethereum/ethereum
    brew install ethereum

    截屏2022-01-02 20.05.01.png

虽然以太坊等区块链项目本身不是用JavaScript编写的,但在与区块链节点交互的场景中,却大量使用了JavaScript作为接口调用的语言。目前JavaScript的相关的开源软件包的发布、分发、编写都是通过Node.js的包管理器NPM来实现的。我们在使用以太坊的 Web3 时也选用了NPM项目包管理器来下载、管理我们的 web3.js 库依赖。

安装node.js

brew install node

查看安装好的node和npm版本

node --version
> v17.3.0
npm --version
> 8.3.0

Geth客户端的结构

Geth客户端包含面向客户的界面(命令行)、面向网络的功能以及EVM虚拟机。 除了不能编译二进制 EVM 代码外,几乎能够执行一切和用户相关、网络相关、合约相关的操作。它承接了客户对于以太坊区块链的操作,对内维持了账户体系,世界状态,虚拟机运行以及数据的存储,对外与其他网络中的客户端节点通信,交换信息

  • 账户管理功能
    • 生成、删除、管理用户的账户。
    • 签名、打包用户的交易请求。
  • 存储、虚拟机功能
    • 存储交易树、状态树、收据树。
    • 启动虚拟机,执行智能合约的代码并存储结果。
  • 网络功能
    • 与其他节点通信,同步下载、分享区块链数据。
    • 参与网络中区块的播报、交易的播报。
    • 验证区块合法性,参与挖矿。
    • 提供Web3,JSON-RPC,Websocket通讯接口。
      Picture44.png

启动一条以太坊私链

以太坊网络分为主网、测试网。这两个网络都是公开的链,为世界所有开发者和用户所用。

我们今天的学习蓝本是以太坊的私有网络,或者称为私链。

私链和公链是不互通的,通过网络进行隔离。我们教程的私链里,有且仅有我们一台计算机运行。

以太坊源代码及软件都是开源的,任何人都可以拷贝一份源代码并且运行自己的以太坊私链。以下是接入不同的网络所需下载数据量的对比。

  • main net 主网 –下载量 >1TB 的区块链数据,共需3-5天时间。
  • test net 测试网 –下载量 ~60GB的代号为Ropsten的测试网数据,约10小时。
  • private net 私链 –无需下载,创世后等待数分钟即可正常运转。

设立工作目录

mkdir ether-test
cd ether-test
touch gensis.json
mkdir db

编辑创世配置

如果读者回忆起 以太坊的特色 的讲解,与比特币不同,以太坊的创世就已经分配了约70%的以太币,随后才进入挖矿过程,大家竞争挖矿分配剩余的币。我们私链也同样可以通过创世方法分配好一些以太币供测试使用,或者从零开始一点一点通过挖矿的方式挖掘以太币。

创世配置就是供以太坊私有链第一次启动时所使用,创世区块是最特殊的区块,它没有前一个区块,因为它自己是第一个块。我们下面来配置创世区块 gensis.json 文件。

// gensis.json
{
  "config": {
      "chainId": 987,
      "homesteadBlock": 0,
      "eip155Block": 0,
      "eip158Block": 0
  },
  "difficulty": "0x400",
  "gasLimit": "0x8000000",
  "alloc": {}
}

以上就是一份最小可行的创世区块配置,包含了区块链配置,挖矿难度设置,单一区块最大包含 Gas 的上限,以及一个空置的创世币分配区alloc(意味着没有预先分配以太币)。当然,也可以扩充一些启动的其他参数诸如时间戳以及前一区块哈希等,这些都是非必填的。完整版的 gensis.json 如下所示。

{
  "config": {
      "chainId": 987,
      "homesteadBlock": 0,
      "eip155Block": 0,
      "eip158Block": 0,
      "eip150Block":0
  },
  "difficulty": "0x400",
  "gasLimit": "0xffffffff",
  // 可选填的参数
  "coinbase": "0x0000000000000000000000000000000000000000",
  "extraData": "0x00",
  "nonce": "0x0000000000000001",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp": "0x00",
  "alloc": {
    "430e986e0cca10a174baad96871ec9cb308c6d05": {"balance": "111111"}
  }
}

各个字段解释如下:

字段 解释
必填 -
chainId 自定义私链的网络ID,不同的网络ID无法互联通讯,以太坊公链ID 为1,我们设置为987以防止与网络中其他私链冲突。
homesteadBlock 是否为HomeStead版本的区块,设置为0表明是。
eip155Block EIP155 [1] 是一个以太坊分叉提议,为了和以前的以太坊经典ETC 链条分叉而存在,我们私链不需要它,设为0。
eip158Block EIP158 [2] 是一个以太坊分叉提议,为了解决之前以太坊空账户造成效率低下的协议漏洞而分叉,我们私链不需要它,设为0。
difficulty 设置当前区块难度,若难度过大挖矿就很慢,我们设置较小值。
gasLimit 单一区块最大 gas 消耗上限,用来限制能够打包进入块的交易数量与信息总和,我们在学习中可以设置为最大。
选填 -
coinbase 打包该块的矿工的奖励地址,因为是创世块,可设为0地址。
extraData 打包该块时矿工记录的笔记。
nonce 打包该块时矿工挖矿所用到的Ethash输入参数nonce。
mixHash 与nonce配合用于挖矿,创世区无前一个区块,可不填。
parentHash 前一个区块头的哈希值,创世区块无前一个区块,设为0。
timestamp 打包该块的时间戳,符合Unix Timestamp标准,设为0。
alloc 创世时各账户分配以太币的数量,不想分配则忽略。

初始化创世配置

配置gensis.json

{
    "config": {
        "chainId": 987,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0,
        "eip150Block":0
    },
    "difficulty": "0x400",
    "gasLimit": "0xffffffff",
    "alloc": {
      "430e986e0cca10a174baad96871ec9cb308c6d05": {"balance": "111111"}
    }

  }

我们已经准备好了创世的配置,接下来就是将该链条的配置初始化,形成区块链的起点,初始化之后我们就有了第一个区块,接下来就可以根据第一个区块来挖掘第二个区块了。

进入 ether-test 目录,执行初始化。

cd ether-test
geth --datadir "./db" init gensis.json

截屏2022-01-02 21.19.17.png

此时我们看到控制台上输出了 “Successfully wrote genesis state” 意味着我们的初始化已经成功

这是目录结构也发生了变化

在 db 目录数据库,程序自动新建了 geth 目录。 该目录存放了区块链的所有运行时产生的区块链数据、日志、世界状态并随着区块链增长而占据更多存储硬盘空间。 它内部的两个子目录存储了具体的区块链数据。 db 目录下还有一个 keystore 目录。该目录下保存了各个账户的私钥的加密后的文件,只有在签名的时候用户才会解锁 keystore 执行签名操作。

启动Geth 节点

一切准备就绪,弗兰肯斯坦的巨人马上就要苏醒,在我们现在的环境下,需要启动一个 Geth 节点来接入私链网络(实际上也是这个私链网络的唯一一个节点),负责在创世块后挖出第一个块。该节点也是我们与以太坊私链通信的节点服务器。下面我们来启动这样一个节点。

geth --datadir ./db/ --http --http.addr=127.0.0.1 --http.port 8545 --http.corsdomain "*" --http.api "eth,net,web3,personal,admin,shh,txpool,debug,miner" --nodiscover --maxpeers 30 --networkid 198989 --port 30303 --mine --miner.threads 1 --miner.etherbase "0x7df9a875a174b3bc565e6424a0050ebc1b2d1d82" console
  • 具体启动参数geth文档见文章末尾

启动成功后
我们可以陆续看到诸如 number=1,number=2 的输出,这表明我们已经成功地挖掘出了第1,2,3…个区块

控制台持续在输出挖矿相关信息。你的私链已经稳定运行。由于我们启动时 etherbase 参数随便设置了一个挖矿矿工奖励地址,所以挖出的区块奖励都发送到了那个地址,但我们并没有持有这个地址,这等于白白浪费了。现在,我们来与Geth通信并且让它暂停一下挖矿,等我们新建好了账户之后再继续挖。

接受挖矿奖励

请确保你的Geth节点尚在运行 ,我们新开命令行窗口执行 attach 命令依附上正在运行中的Geth节点:

geth --datadir ./db attach ipc:./db/geth.ipc

弹出控制台
截屏2022-01-02 23.19.13.png

在控制台上我们用personal功能模块新建两个账户,分别由123密码和 456来保护。

> personal.newAccount('123')
"0xa0ec4f7aad3af79907f0cab503d3b800faae0eee"
> personal.newAccount('456')
"0x9975430958d28b8d74a38475682bbb1e2efc681e"

生成后我们已经看到控制台上分别输出了两个地址,它们就是生成好的两个账户的公开地址,现在这些地址已经准备好能够收受以太币。

eth.accounts
web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")

结果如图
截屏2022-01-02 23.25.33.png

我们用 web3 功能模块的 fromWei() 换算功能帮助我们换算了账户余额,如我们所预料的,账户余额为 0 。在以太坊的世界里没有浮点数小数点,只有整数。所以形如 3.1415 的小数在以太坊里是无法表示的,这里采用了 Wei 为单位表示以太坊不可分割的最小单位,将所有小数转化为大整数运算,

为了在私链上获取以太币供测试使用,我们设定其中一个账户的地址为挖矿奖励地址,这样我们就有源源不断的以太币可以做实验使用,我们来用miner功能模块设定一下挖矿地址。

> miner.setEtherbase(eth.accounts[0])
true

我们再来用eth功能模块检查一下,是否挖矿收益地址coinbase已经是我们的地址:

> eth.coinbase
"0xa0ec4f7aad3af79907f0cab503d3b800faae0eee"

设置成功!接下来我们就可以重新通知Geth节点去启动挖矿,然后坐等我们的以太币流入第一个账户了。请重启挖矿。

miner.start(1)

这里 miner.start()代入参数 1 代表了我们启动挖矿时候仅仅启动一个线程挖矿。现在每隔 5-10 秒就有一个新的块被挖出(不包含任何交易,是空块),稍等一会儿,我们再次来检查一下各个账户的余额情况。

> eth.accounts
["0xa0ec4f7aad3af79907f0cab503d3b800faae0eee", "0x9975430958d28b8d74a38475682bbb1e2efc681e"]
> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
885
> web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")
0

可以看到已经有一个账户收到了挖矿奖励,持有650个币了。

转账与收款

先暂停挖矿

miner.stop()

同样在控制台上我们解锁的转账方的账户,输入解锁密码,以及解锁时长 300秒 。

>personal.unlockAccount(eth.accounts[0], '123', 300)
GoError: Error: account unlock with HTTP access is forbidden at web3.js:6365:37(47)
    at github.com/ethereum/go-ethereum/internal/jsre.MakeCallback.func1 (native)
    at <eval>:1:48(8)

结果返回错误 解锁账户在http下被禁止
没关系 我们重启geth服务
同时再服务后面加上一条 --allow-insecure-unlock
完整的命令就是

geth --datadir ./db/ --http --http.addr=127.0.0.1 --http.port 8545 --http.corsdomain "*" --http.api "eth,net,web3,personal,admin,shh,txpool,debug,miner" --nodiscover --maxpeers 30 --networkid 198989 --port 30303 --mine --miner.threads 1 --miner.etherbase "0x7df9a875a174b3bc565e6424a0050ebc1b2d1d82" --allow-insecure-unlock console

回到控制台重新解锁账户

> personal.unlockAccount(eth.accounts[0], '123', 300)
true

成功 返回 true
好,接下来我们发送一笔 10 个以太币的转账,转账接收方是另一个我们持有的账户。

> eth.sendTransaction({from: eth.accounts[0],to: eth.accounts[1],value: web3.toWei(10, 'ether')})
"0x16ab75f6158c6ec8fca4f465590fa7568f30dcb9f6bb38f6c995f29034d61b12"

交易发送成功!我们取回了一个长长的哈希值:
0x16ab75f6158c6ec8fca4f465590fa7568f30dcb9f6bb38f6c995f29034d61b12
这就是交易的哈希值(Transaction Hash, TxHash),这个值能够唯一索引到一笔交易。

我们查看一下接收方的余额。

> web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")
10

成功转账!!!

geth启动参数文档

命令 说明 翻译
NAME - -
geth - the go-ethereum command line interface - -
Copyright 2013-2021 The go-ethereum Authors - -
USAGE: - -
geth [options] [command] [command options] [arguments...] - -
VERSION: - -
1.10.14-stable - -
COMMANDS: - -
account Manage accounts 管理帐户
attach Start an interactive JavaScript environment (connect to node) 启动一个交互式 JavaScript 环境(连接到节点)
console Start an interactive JavaScript environment 启动交互式 JavaScript 环境
db Low level database operations 低级数据库操作
dump Dump a specific block from storage 从存储中转储特定块
dumpconfig Show configuration values 显示配置值
dumpgenesis Dumps genesis block JSON configuration to stdout 将创世块 JSON 配置转储到标准输出
export Export blockchain into file 将区块链导出到文件中
export-preimages Export the preimage database into an RLP stream 将原像数据库导出到 RLP 流中
import Import a blockchain file 导入区块链文件
import-preimages Import the preimage database from an RLP stream 从 RLP 流导入原像数据库
init Bootstrap and initialize a new genesis block 引导并初始化一个新的创世块
js Execute the specified JavaScript files 执行指定的 JavaScript 文件
license Display license information 显示许可证信息
makecache Generate ethash verification cache (for testing) 生成ethash验证缓存(用于测试)
makedag Generate ethash mining DAG (for testing) 生成 ethash 挖矿 DAG(用于测试)
removedb Remove blockchain and state databases 删除区块链和状态数据库
show-deprecated-flags Show flags that have been deprecated 显示已弃用的标志
snapshot A set of commands based on the snapshot 基于快照的一组命令
version Print version numbers 打印版本号
version-check Checks (online) whether the current version suffers from any known security vulnerabilities 检查(在线)当前版本是否存在任何已知的安全漏洞
wallet Manage Ethereum presale wallets 管理以太坊预售钱包
help, h Shows a list of commands or help for one command 显示命令列表或一个命令的帮助
ETHEREUM OPTIONS - -
--config value TOML configuration file TOML 配置文件
--datadir value Data directory for the databases and keystore (default: "/Users/arthurli/Library/Ethereum") 数据库和密钥库的数据目录(默认:“/Users/arthurli/Library/Ethereum”)
--datadir.ancient value Data directory for ancient chain segments (default = inside chaindata) 古代链段的数据目录(默认 = inside chaindata)
--datadir.minfreedisk value Minimum free disk space in MB, once reached triggers auto shut down (default = --cache.gc converted to MB, 0 = disabled) 以 MB 为单位的最小可用磁盘空间,一旦达到触发自动关闭(默认 = --cache.gc 转换为 MB,0 = 禁用)
--keystore value Directory for the keystore (default = inside the datadir) 密钥库的目录(默认 = 在 datadir 内)
--usb Enable monitoring and management of USB hardware wallets 启用 USB 硬件钱包的监控和管理
--pcscdpath value Path to the smartcard daemon (pcscd) socket file 智能卡守护程序 (pcscd) 套接字文件的路径
--networkid value Explicitly set network id (integer)(For testnets: use --ropsten, --rinkeby, --goerli instead) (default: 1) 显式设置网络 ID(整数)(对于测试网:使用 --ropsten、--rinkeby、--goerli 代替)(默认值:1)
--mainnet Ethereum mainnet 以太坊主网
--goerli Görli network: pre-configured proof-of-authority test network Görli 网络:预先配置的权威证明测试网络
--rinkeby Rinkeby network: pre-configured proof-of-authority test network Rinkeby 网络:预先配置的权威证明测试网络
--ropsten Ropsten network: pre-configured proof-of-work test network Ropsten 网络:预先配置的工作量证明测试网络
--sepolia Sepolia network: pre-configured proof-of-work test network Sepolia 网络:预先配置的工作量证明测试网络
--syncmode value Blockchain sync mode ("snap", "full" or "light") (default: snap) 区块链同步模式(“snap”、“full”或“light”)(默认:snap)
--exitwhensynced Exits after block synchronisation completes 块同步完成后退出
--gcmode value Blockchain garbage collection mode ("full", "archive") (default: "full") 区块链垃圾收集模式(“full”、“archive”)(默认:“full”)
--txlookuplimit value Number of recent blocks to maintain transactions index for (default = about one year, 0 = entire chain) (default: 2350000) 维护交易索引的最近区块数(默认值 = 大约一年,0 = 整个链)(默认值:2350000)
--ethstats value Reporting URL of a ethstats service (nodename:secret@host:port) ethstats 服务的报告 URL (nodename:secret@host:port)
--identity value Custom node name 自定义节点名称
--lightkdf Reduce key-derivation RAM & CPU usage at some expense of KDF strength 以牺牲 KDF 强度为代价减少密钥派生 RAM 和 CPU 使用率
--whitelist value Comma separated block number-to-hash mappings to enforce (=) 逗号分隔的块号到哈希映射来强制执行 (=)
LIGHT CLIENT OPTIONS: - -
--light.serve value Maximum percentage of time allowed for serving LES requests (multi-threaded processing allows values over 100) (default: 0) 服务 LES 请求所允许的最大时间百分比(多线程处理允许值超过 100)(默认值:0)
--light.ingress value Incoming bandwidth limit for serving light clients (kilobytes/sec, 0 = unlimited) (default: 0) 服务轻客户端的传入带宽限制(千字节/秒,0 = 无限制)(默认值:0)
--light.egress value Outgoing bandwidth limit for serving light clients (kilobytes/sec, 0 = unlimited) (default: 0) 服务轻客户端的传出带宽限制(千字节/秒,0 = 无限制)(默认值:0)
--light.maxpeers value Maximum number of light clients to serve, or light servers to attach to (default: 100) 要服务的轻客户端或要附加的轻服务器的最大数量(默认值:100)
--ulc.servers value List of trusted ultra-light servers 值得信赖的超轻型服务器列表
--ulc.fraction value Minimum % of trusted ultra-light servers required to announce a new head (default: 75) 宣布新头所需的可信超轻型服务器的最低百分比(默认值:75)
--ulc.onlyannounce Ultra light server sends announcements only 超轻服务器只发送公告
--light.nopruning Disable ancient light chain data pruning 禁用古老的轻链数据修剪
--light.nosyncserve Enables serving light clients before syncing 在同步之前启用服务轻客户端
DEVELOPER CHAIN OPTIONS: - -
--dev Ephemeral proof-of-authority network with a pre-funded developer account, mining enabled 具有预先资助的开发者帐户的临时权威证明网络,已启用挖矿
--dev.period value Block period to use in developer mode (0 = mine only if transaction pending) (default: 0) 在开发者模式下使用的阻止期(0 = 仅在交易挂起时我的)(默认值:0)
--dev.gaslimit value Initial block gas limit (default: 11500000) 初始区块气体限制(默认值:11500000)
ETHASH OPTIONS: - -
--ethash.cachedir value Directory to store the ethash verification caches (default = inside the datadir) 存储 ethash 验证缓存的目录(默认 = 在 datadir 内)
--ethash.cachesinmem value Number of recent ethash caches to keep in memory (16MB each) (default: 2) 要保留在内存中的最近 ethash 缓存的数量(每个 16MB)(默认值:2)
--ethash.cachesondisk value Number of recent ethash caches to keep on disk (16MB each) (default: 3) 要保留在磁盘上的最近 ethash 缓存的数量(每个 16MB)(默认值:3)
--ethash.cacheslockmmap Lock memory maps of recent ethash caches 锁定最近 ethash 缓存的内存映射
--ethash.dagdir value Directory to store the ethash mining DAGs (default: "/Users/arthurli/Library/Ethash") 存储 ethash 挖掘 DAG 的目录(默认:“/Users/arthurli/Library/Ethash”)
--ethash.dagsinmem value Number of recent ethash mining DAGs to keep in memory (1+GB each) (default: 1) 最近要保留在内存中的 ethash 挖掘 DAG 的数量(每个 1+GB)(默认值:1)
--ethash.dagsondisk value Number of recent ethash mining DAGs to keep on disk (1+GB each) (default: 2) 最近要保留在磁盘上的 ethash 挖矿 DAG 的数量(每个 1+GB)(默认值:2)
--ethash.dagslockmmap Lock memory maps for recent ethash mining DAGs 为最近的 ethash 挖矿 DAG 锁定内存映射
TRANSACTION POOL OPTIONS: - -
--txpool.locals value Comma separated accounts to treat as locals (no flush, priority inclusion) 逗号分隔的帐户作为本地人对待(无刷新,优先包含)
--txpool.nolocals Disables price exemptions for locally submitted transactions 禁用本地提交交易的价格豁免
--txpool.journal value Disk journal for local transaction to survive node restarts (default: "transactions.rlp") 本地事务的磁盘日志以生存节点重新启动(默认值:“transactions.rlp”)
--txpool.rejournal value Time interval to regenerate the local transaction journal (default: 1h0m0s) 重新生成本地事务日志的时间间隔(默认:1h0m0s)
--txpool.pricelimit value Minimum gas price limit to enforce for acceptance into the pool (default: 1) 为接受入池而强制执行的最低 gas 价格限制(默认值:1)
--txpool.pricebump value Price bump percentage to replace an already existing transaction (default: 10) 替换现有交易的价格波动百分比(默认值:10)
--txpool.accountslots value Minimum number of executable transaction slots guaranteed per account (default: 16) 每个账户保证的最小可执行交易槽数(默认:16)
--txpool.globalslots value Maximum number of executable transaction slots for all accounts (default: 5120) 所有账户的最大可执行交易槽数(默认:5120)
--txpool.accountqueue value Maximum number of non-executable transaction slots permitted per account (default: 64) 每个账户允许的最大不可执行事务槽数(默认:64)
--txpool.globalqueue value Maximum number of non-executable transaction slots for all accounts (default: 1024) 所有账户的最大不可执行事务槽数(默认:1024)
--txpool.lifetime value Maximum amount of time non-executable transaction are queued (default: 3h0m0s) 不可执行事务排队的最长时间(默认值:3h0m0s)
PERFORMANCE TUNING OPTIONS: - -
--cache value Megabytes of memory allocated to internal caching (default = 4096 mainnet full node, 128 light mode) (default: 1024) 分配给内部缓存的内存兆字节(默认 = 4096 主网全节点,128 轻模式)(默认:1024)
--cache.database value Percentage of cache memory allowance to use for database io (default: 50) 用于数据库 io 的缓存内存允许百分比(默认值:50)
--cache.trie value Percentage of cache memory allowance to use for trie caching (default = 15% full mode, 30% archive mode) (default: 15) 用于特里缓存的缓存内存允许百分比(默认值 = 15% 完整模式,30% 存档模式)(默认值:15)
--cache.trie.journal value Disk journal directory for trie cache to survive node restarts (default: "triecache") trie 缓存的磁盘日志目录以在节点重新启动后继续存在(默认值:“triecache”)
--cache.trie.rejournal value Time interval to regenerate the trie cache journal (default: 1h0m0s) 重新生成特里缓存日志的时间间隔(默认值:1h0m0s)
--cache.gc value Percentage of cache memory allowance to use for trie pruning (default = 25% full mode, 0% archive mode) (default: 25) 用于修剪修剪的缓存内存百分比(默认值 = 25% 完整模式,0% 存档模式)(默认值:25)
--cache.snapshot value Percentage of cache memory allowance to use for snapshot caching (default = 10% full mode, 20% archive mode) (default: 10) 用于快照缓存的缓存内存允许百分比(默认值 = 10% 完整模式,20% 存档模式)(默认值:10)
--cache.noprefetch Disable heuristic state prefetch during block import (less CPU and disk IO, more time waiting for data) 在块导入期间禁用启发式状态预取(更少的 CPU 和磁盘 IO,更多的时间等待数据)
--cache.preimages Enable recording the SHA3/keccak preimages of trie keys 启用记录特里密钥的 SHA3/keccak 原像
ACCOUNT OPTIONS: - -
--unlock value Comma separated list of accounts to unlock 要解锁的帐户的逗号分隔列表
--password value Password file to use for non-interactive password input 用于非交互式密码输入的密码文件
--signer value External signer (url or path to ipc file) 外部签名者(ipc 文件的 url 或路径)
--allow-insecure-unlock Allow insecure account unlocking when account-related RPCs are exposed by http 当与帐户相关的 RPC 被 http 公开时允许不安全的帐户解锁
API AND CONSOLE OPTIONS: - -
--ipcdisable Disable the IPC-RPC server 禁用 IPC-RPC 服务器
--ipcpath value Filename for IPC socket/pipe within the datadir (explicit paths escape it) 数据目录中 IPC 套接字/管道的文件名(显式路径对其进行转义)
--http Enable the HTTP-RPC server 启用 HTTP-RPC 服务器
--http.addr value HTTP-RPC server listening interface (default: "localhost") HTTP-RPC 服务器监听接口(默认:“localhost”)
--http.port value HTTP-RPC server listening port (default: 8545) HTTP-RPC 服务器监听端口(默认:8545)
--http.api value API's offered over the HTTP-RPC interface 通过 HTTP-RPC 接口提供的 API
--http.rpcprefix value HTTP path path prefix on which JSON-RPC is served. Use '/' to serve on all paths. 提供 JSON-RPC 的 HTTP 路径路径前缀。使用“/”在所有路径上提供服务。
--http.corsdomain value Comma separated list of domains from which to accept cross origin requests (browser enforced) 接受跨源请求的域的逗号分隔列表(浏览器强制执行)
--http.vhosts value Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: "localhost") 逗号分隔的虚拟主机名列表,从中接受请求(服务器强制执行)。接受“*”通配符。 (默认:“本地主机”)
--ws Enable the WS-RPC server 启用 WS-RPC 服务器
--ws.addr value WS-RPC server listening interface (default: "localhost") WS-RPC 服务器监听接口(默认:“localhost”)
--ws.port value WS-RPC server listening port (default: 8546) WS-RPC 服务器监听端口(默认:8546)
--ws.api value API's offered over the WS-RPC interface 通过 WS-RPC 接口提供的 API
--ws.rpcprefix value HTTP path prefix on which JSON-RPC is served. Use '/' to serve on all paths. 提供 JSON-RPC 的 HTTP 路径前缀。使用“/”在所有路径上提供服务。
--ws.origins value Origins from which to accept websockets requests 接受 websockets 请求的来源
--graphql Enable GraphQL on the HTTP-RPC server. Note that GraphQL can only be started if an HTTP server is started as well. 在 HTTP-RPC 服务器上启用 GraphQL。请注意,GraphQL 只能在 HTTP 服务器启动的情况下启动。
--graphql.corsdomain value Comma separated list of domains from which to accept cross origin requests (browser enforced) 接受跨源请求的域的逗号分隔列表(浏览器强制执行)
--graphql.vhosts value Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: "localhost") 逗号分隔的虚拟主机名列表,从中接受请求(服务器强制执行)。接受“*”通配符。 (默认:“本地主机”)
--rpc.gascap value Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite) (default: 50000000) 设置可以在 eth_call/estimateGas 中使用的 gas 上限(0=无限)(默认值:50000000)
--rpc.evmtimeout value Sets a timeout used for eth_call (0=infinite) (default: 5s) 设置用于 eth_call 的超时(0=无限)(默认值:5s)
--rpc.txfeecap value Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap) (default: 1) 设置可以通过 RPC API 发送的交易费用上限(以以太为单位)(0 = 无上限)(默认值:1)
--rpc.allow-unprotected-txs Allow for unprotected (non EIP155 signed) transactions to be submitted via RPC 允许通过 RPC 提交不受保护(非 EIP155 签名)的交易
--jspath loadScript JavaScript root path for loadScript (default: ".") loadScript 的 JavaScript 根路径(默认:“.”)
--exec value Execute JavaScript statement 执行 JavaScript 语句
--preload value Comma separated list of JavaScript files to preload into the console 要预加载到控制台的 JavaScript 文件的逗号分隔列表
NETWORKING OPTIONS: - -
--bootnodes value Comma separated enode URLs for P2P discovery bootstrap 用于 P2P 发现引导程序的逗号分隔的 enode URL
--discovery.dns value Sets DNS discovery entry points (use "" to disable DNS) 设置 DNS 发现入口点(使用“”禁用 DNS)
--port value Network listening port (default: 30303) 网络监听端口(默认:30303)
--maxpeers value Maximum number of network peers (network disabled if set to 0) (default: 50) 最大网络对等点数(如果设置为 0,则禁用网络)(默认值:50)
--maxpendpeers value Maximum number of pending connection attempts (defaults used if set to 0) (default: 0) 最大挂起连接尝试次数(如果设置为 0,则使用默认值)(默认值:0)
--nat value NAT port mapping mechanism (any none
--nodiscover Disables the peer discovery mechanism (manual peer addition) 禁用对等发现机制(手动对等添加)
--v5disc Enables the experimental RLPx V5 (Topic Discovery) mechanism 启用实验性 RLPx V5(主题发现)机制
--netrestrict value Restricts network communication to the given IP networks (CIDR masks) 将网络通信限制到给定的 IP 网络(CIDR 掩码)
--nodekey value P2P node key file P2P节点密钥文件
--nodekeyhex value P2P node key as hex (for testing) P2P 节点密钥为十六进制(用于测试)
MINER OPTIONS: - -
--mine Enable mining 启用挖矿
--miner.threads value Number of CPU threads to use for mining (default: 0) 用于挖掘的 CPU 线程数(默认值:0)
--miner.notify value Comma separated HTTP URL list to notify of new work packages 逗号分隔的 HTTP URL 列表以通知新的工作包
--miner.notify.full Notify with pending block headers instead of work packages 用挂起的块头而不是工作包通知
--miner.gasprice value Minimum gas price for mining a transaction (default: 1000000000) 挖掘交易的最低 gas 价格(默认:1000000000)
--miner.gaslimit value Target gas ceiling for mined blocks (default: 8000000) 已开采区块的目标气体上限(默认值:8000000)
--miner.etherbase value Public address for block mining rewards (default = first account) (default: "0") 区块挖矿奖励的公共地址(默认=第一个帐户)(默认:“0”)
--miner.extradata value Block extra data set by the miner (default = client version) 阻止矿工设置的额外数据(默认 = 客户端版本)
--miner.recommit value Time interval to recreate the block being mined (default: 3s) 重新创建正在开采的块的时间间隔(默认值:3s)
--miner.noverify Disable remote sealing verification 禁用远程密封验证
GAS PRICE ORACLE OPTIONS: - -
--gpo.blocks value Number of recent blocks to check for gas prices (default: 20) 检查gas价格的最近块数(默认值:20)
--gpo.percentile value Suggested gas price is the given percentile of a set of recent transaction gas prices (default: 60) 建议的 gas 价格是一组最近交易 gas 价格的给定百分位(默认:60)
--gpo.maxprice value Maximum transaction priority fee (or gasprice before London fork) to be recommended by gpo (default: 500000000000) gpo 推荐的最大交易优先费(或伦敦分叉前的gasprice)(默认值:500000000000)
--gpo.ignoreprice value Gas price below which gpo will ignore transactions (default: 2) 低于 gpo 将忽略交易的 Gas 价格(默认值:2)
VIRTUAL MACHINE OPTIONS: - -
--vmdebug Record information useful for VM and contract debugging 记录对 VM 和合约调试有用的信息
LOGGING AND DEBUGGING OPTIONS: - 日志和调试选项
--fakepow Disables proof-of-work verification 禁用工作量证明验证
--nocompaction Disables db compaction after import 导入后禁用数据库压缩
--verbosity value Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 3) 日志详细程度:0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 3)
--vmodule value Per-module verbosity: comma-separated list of = (e.g. eth/*=5,p2p=4) 每个模块的详细程度:以逗号分隔的 = 列表(例如 eth/*=5,p2p=4)
--log.json Format logs with JSON 使用 JSON 格式化日志
--log.backtrace value Request a stack trace at a specific logging statement (e.g. "block.go:271") 在特定的日志记录语句中请求堆栈跟踪(例如“block.go:271”)
--log.debug Prepends log messages with call-site location (file and line number) 使用呼叫站点位置(文件和行号)预置日志消息
--pprof Enable the pprof HTTP server 启用 pprof HTTP 服务器
--pprof.addr value pprof HTTP server listening interface (default: "127.0.0.1") pprof HTTP 服务器监听接口(默认:“127.0.0.1”)
--pprof.port value pprof HTTP server listening port (default: 6060) pprof HTTP 服务器监听端口(默认:6060)
--pprof.memprofilerate value Turn on memory profiling with the given rate (default: 524288) 以给定的速率打开内存分析(默认值:524288)
--pprof.blockprofilerate value Turn on block profiling with the given rate (default: 0) 以给定的速率打开块分析(默认值:0)
--pprof.cpuprofile value Write CPU profile to the given file 将 CPU 配置文件写入给定文件
--trace value Write execution trace to the given file 将执行跟踪写入给定文件
METRICS AND STATS OPTIONS: - -
--metrics Enable metrics collection and reporting 启用指标收集和报告
--metrics.expensive Enable expensive metrics collection and reporting 启用昂贵的指标收集和报告
--metrics.addr value Enable stand-alone metrics HTTP server listening interface (default: "127.0.0.1") 启用独立指标 HTTP 服务器侦听接口(默认:“127.0.0.1”)
--metrics.port value Metrics HTTP server listening port (default: 6060) 指标 HTTP 服务器侦听端口(默认值:6060)
--metrics.influxdb Enable metrics export/push to an external InfluxDB database 启用指标导出/推送到外部 InfluxDB 数据库
--metrics.influxdb.endpoint value InfluxDB API endpoint to report metrics to (default: "http://localhost:8086") InfluxDB API 端点将指标报告给(默认:“http://localhost:8086”)
--metrics.influxdb.database value InfluxDB database name to push reported metrics to (default: "geth") InfluxDB 数据库名称将报告的指标推送到(默认:“geth”)
--metrics.influxdb.username value Username to authorize access to the database (default: "test") 授权访问数据库的用户名(默认:“test”)
--metrics.influxdb.password value Password to authorize access to the database (default: "test") 授权访问数据库的密码(默认:“test”)
--metrics.influxdb.tags value Comma-separated InfluxDB tags (key/values) attached to all measurements (default: "host=localhost") 逗号分隔的 InfluxDB 标签(键/值)附加到所有测量值(默认值:“host=localhost”)
--metrics.influxdbv2 Enable metrics export/push to an external InfluxDB v2 database 启用指标导出/推送到外部 InfluxDB v2 数据库
--metrics.influxdb.token value Token to authorize access to the database (v2 only) (default: "test") 授权访问数据库的令牌(仅限 v2)(默认值:“test”)
--metrics.influxdb.bucket value InfluxDB bucket name to push reported metrics to (v2 only) (default: "geth") InfluxDB 存储桶名称将报告的指标推送到(仅限 v2)(默认值:“geth”)
--metrics.influxdb.organization value InfluxDB organization name (v2 only) (default: "geth") InfluxDB 组织名称(仅限 v2)(默认值:“geth”)
ALIASED (deprecated) OPTIONS: - -
--nousb Disables monitoring for and managing USB hardware wallets (deprecated) 禁用对 USB 硬件钱包的监控和管理(已弃用)
MISC OPTIONS: - -
--snapshot Enables snapshot-database mode (default = enable) 启用快照数据库模式(默认 = 启用)
--bloomfilter.size value Megabytes of memory allocated to bloom-filter for pruning (default: 2048) 分配给布隆过滤器用于修剪的内存兆字节(默认值:2048)
--help, -h show help 显示帮助
--catalyst Catalyst mode (eth2 integration testing) Catalyst 模式(eth2 集成测试)
--override.arrowglacier value Manually specify Arrow Glacier fork-block, overriding the bundled setting (default: 0) 手动指定 Arrow Glacier fork-block,覆盖捆绑设置(默认值:0)
--override.terminaltotaldifficulty value Manually specify TerminalTotalDifficulty, overriding the bundled setting (default: 0) 手动指定 TerminalTotalDifficulty,覆盖捆绑设置(默认值:0)
1
如果你觉得文章还不错,可以请我喝杯咖啡啊哈哈哈
wechat alipay

评论 (0)

取消