從頭到尾使用Geth的說明-2-cli可用命令-有2個地方標紅,之后查查源碼后看看能不能解決


geth - the go-ethereum command line interface 以太坊命令行接口

格式:

geth [options] command [command options] [arguments...]

 

支持的命令:

account    管理賬戶
attach     啟動交互式JavaScript環境(連接到節點)
bug        上報bug Issues
console    啟動交互式JavaScript環境
copydb     從目標chaindata文件夾創建本地鏈
dump       Dump(分析)一個特定的塊存儲
dumpconfig 顯示配置值
export     導出區塊鏈到文件
import     導入一個區塊鏈文件
init       啟動並初始化一個新的創世紀塊
js         執行指定的JavaScript文件(多個)
license    顯示許可信息
makecache  生成ethash驗證緩存(用於測試)
makedag    生成ethash 挖礦DAG(用於測試)
monitor    監控和可視化節點指標
removedb   刪除區塊鏈和狀態數據庫
version    打印版本號
wallet     管理Ethereum預售錢包
help,h     顯示一個命令或幫助一個命令列表

 

geth命令說明:

1.account

管理賬戶,列舉所有已存在的賬戶信息,導入一個私鑰來生成一個新賬戶,創建新賬戶或更新存在的賬戶

它支持交互模式(即當提示輸入密碼時)和非交互模式(通過給定密碼文件提供密碼。非交互模式僅用於在測試網絡或已知的安全環境中進行腳本化使用。
確保您在創建新帳戶(使用新帳戶或導入帳戶)時記住您給出的密碼。沒有它,你就不能解鎖你的賬戶。

注意,不支持以未加密格式導出密鑰。
密鑰存儲在/keystore下。通過簡單的復制,在ethereum節點之間傳輸整個目錄或其中的單個鍵是安全的。
確保你定期備份你的鑰匙。

userdeMacBook-Pro:~ user$ geth account -h
NAME:
   geth account - USAGE: geth account command [command options] [arguments...] COMMANDS: list Print summary of existing accounts 打印現有賬戶摘要 new Create a new account 創建新賬戶 update Update an existing account 更新現有賬戶 import Import a private key into a new account 將私鑰導入生成新帳戶 OPTIONS: --help, -h show help

 

1> list

格式:

list [command options] [arguments...]

選項:

userdeMacBook-Pro:~ user$ geth account list -h

ETHEREUM OPTIONS:
  --datadir "/Users/user/Library/Ethereum" Data directory for the databases and keystore 指明數據庫和密鑰存儲文件的數據目錄 --keystore Directory for the keystore (default = inside the datadir) 密鑰存儲文件的數據目錄(默認在--datadir參數指定的目錄下)

打印所有帳戶的簡短摘要

舉例:

userdeMacBook-Pro:~ user$ geth account list --datadir './today2/data0' INFO [12-29|17:49:51] Maximum peer count ETH=25 LES=0 total=25 Account #0: {3b896fb3e31fc9b91921d19b8c7271d1c3af5b35} keystore:///Users/user/today2/data0/keystore/UTC--2018-07-12T06-48-20.253726408Z--3b896fb3e31fc9b91921d19b8c7271d1c3af5b35 Account #1: {39f03934f1d9afbff39a395364416e71eae375cd} keystore:///Users/user/today2/data0/keystore/UTC--2018-09-25T09-15-10.502888824Z--39f03934f1d9afbff39a395364416e71eae375cd

打印的是部署在./today2/data0目錄下的所有賬戶信息

 

2>  new

格式:

geth account new [command options] [arguments...]

選項:

userdeMacBook-Pro:~ user$ geth account new -h ETHEREUM OPTIONS: 以太坊選項 --datadir "/Users/user/Library/Ethereum" Data directory for the databases and keystore 指明數據庫和密鑰存儲文件的數據目錄 --keystore Directory for the keystore (default = inside the datadir) 密鑰存儲文件的數據目錄(默認在--datadir參數指定的目錄下) --lightkdf Reduce key-derivation RAM & CPU usage at some expense of KDF strength 以犧牲KDF的強度為代價,減少鍵派生中RAM和CPU的使用 ACCOUNT OPTIONS:賬戶選項 --password value Password file to use for non-interactive password input 非交互式密碼輸入中使用的密碼文件

創建一個新帳戶並打印地址,帳戶將以加密格式(即得到個UTC文件)保存,提示您輸入密碼。你必須記住這個密碼才能在將來解鎖你的賬戶。
對於非交互式使用,可以使用--password標記直接指定密碼:
⚠️注意,這僅用於測試,將密碼保存為文件或以任何其他方式公開是一個壞主意。

舉例:

一開始在本地環境中有兩個賬戶,如圖:

 然后現在我們使用上面的命令生成一個新的賬戶:

userdeMBP:today2 user$ geth account new --datadir ./data0 --password ./password INFO [01-10|16:09:36] Maximum peer count ETH=25 LES=0 total=25 Address: {d3f19f6c7cb02787c06792456351851f242a935b}

--datadir指定你是通過連接當前目錄下的/data0/geth.ipc來連接這個geth客戶端的,--password指定你密碼存儲的文件

然后可見成功生成了一個新的賬戶:

 

3>import

格式:

geth account import [options] <keyfile>

選項:

userdeMacBook-Pro:~ user$ geth account import -h ETHEREUM OPTIONS: 以太坊選項 --datadir "/Users/user/Library/Ethereum" Data directory for the databases and keystore 指明數據庫和密鑰存儲文件的數據目錄 --keystore Directory for the keystore (default = inside the datadir) 密鑰存儲文件的數據目錄(默認在--datadir參數指定的目錄下) --lightkdf Reduce key-derivation RAM & CPU usage at some expense of KDF strength 以犧牲KDF的強度為代價,減少鍵派生中RAM和CPU的使用 ACCOUNT OPTIONS:賬戶選項 --password value Password file to use for non-interactive password input 非交互式密碼輸入中使用的密碼文件

導入一個未加密的私鑰,並創建一個新帳戶,並打印的地址。

假設<keyfile>密鑰文件包含十六進制格式的未加密私鑰。得到的帳戶將以加密格式(即得到個UTC文件)保存,提示你輸入密碼。
⚠️你必須記住這個密碼才能在將來解鎖你的賬戶。

舉例說明:

geth account import --datadir '/Users/geth-environment/data0/' --password '/Users/geth-environment/password' /Users/user/geth-environment/coinbase.key

該命令的意思就是導入並生成一個賬戶的UTC文件到--datadir參數指定的geth客戶端的目錄的/keystore中,其密碼從--password參數指定的文件夾中讀取,/Users/user/geth-environment/coinbase.key文件中記錄着該賬戶的私鑰,然后你就能看見在/Users/geth-environment/data0/keystore文件夾中生成了對應的一個UTC文件

也可以不使用--password參數,然后他就會進行進入交互模式,終端提示輸入密碼

 

4>update

格式:

update [command options] [arguments...]

    geth account update <address>

選項:

ETHEREUM OPTIONS: 以太坊選項
  --datadir "/Users/user/Library/Ethereum" Data directory for the databases and keystore 指明數據庫和密鑰存儲文件的數據目錄 --keystore Directory for the keystore (default = inside the datadir) 密鑰存儲文件的數據目錄(默認在--datadir參數指定的目錄下) --lightkdf Reduce key-derivation RAM & CPU usage at some expense of KDF strength 以犧牲KDF的強度為代價,減少鍵派生中RAM和CPU的使用

更新現有帳戶。
該帳戶以加密格式保存在最新版本中,提示您輸入一個密碼來解鎖該帳戶,另一個密碼來保存更新后的文件。
因此,可以使用相同的命令將棄用的格式的帳戶遷移到最新的格式或更改帳戶的密碼。
對於非交互式使用,可以使用--password標志指定密碼:

geth account update [options] <address>

由於只能給出一個密碼,因此只能執行格式更新,因此只能交互式地更改密碼。所以update不使用--password參數

舉例:

更改上面生成的新賬戶:

userdeMBP:today2 user$ geth account update --datadir ./data0 d3f19f6c7cb02787c06792456351851f242a935b
INFO [01-10|16:27:31] Maximum peer count ETH=25 LES=0 total=25 Unlocking account d3f19f6c7cb02787c06792456351851f242a935b | Attempt 1/3 Passphrase: //舊的密碼 INFO [01-10|16:27:38] Unlocked account address=0xd3F19F6C7cB02787C06792456351851f242a935B Please give a new password. Do not forget this password. Passphrase: //新的設置的密碼 Repeat passphrase: 

 

 

2.attach

格式:

geth attach [command options] [arguments...]

選項:

ETHEREUM OPTIONS:
  --datadir "/Users/user/Library/Ethereum"  數據庫和keystore的數據目錄

API AND CONSOLE OPTIONS:
  --jspath loadScript  loadScript命令調用的JavaScript根路徑 (默認為: ".")
  --exec value         要執行JavaScript語句
  --preload value      要預加載到控制台的JavaScript文件的逗號分隔列表

該命令允許在運行的geth節點上打開控制台

Geth控制台是一個在JavaScript運行環境中的交互式shell,用於暴露節點管理界面以及Ðapp JavaScript API。
詳情見https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console。

首先你要已經將geth運行起來了,geth.toml中的配置可見從頭到尾使用Geth的說明-3-geth參數說明和環境配置

userdeMBP:today2 user$ geth --config geth.toml 2>>geth.log

然后查看日志信息:

userdeMBP:today2 user$ tail -f geth.log
INFO [01-10|17:08:10] Regenerated local transaction journal    transactions=0 accounts=0
WARN [01-10|17:08:10] Blockchain not empty, fast sync disabled 
INFO [01-10|17:08:10] Starting P2P networking 
INFO [01-10|17:08:11] UDP listener up                          self=enode://14a6c2c3c78951126326bbaa11f1c863347567f66273ffe663d1b351ebb96f2b315d4603f4ce13cc664a5ace0b290909c0e69c394114018a64b040ff2f4cdb10@10.240.100.98:61911
INFO [01-10|17:08:11] RLPx listener up                         self=enode://14a6c2c3c78951126326bbaa11f1c863347567f66273ffe663d1b351ebb96f2b315d4603f4ce13cc664a5ace0b290909c0e69c394114018a64b040ff2f4cdb10@10.240.100.98:61911
INFO [01-10|17:08:11] IPC endpoint opened                      url=/Users/user/today2/data0/geth.ipc
INFO [01-10|17:08:11] HTTP endpoint opened                     url=http://127.0.0.1:8202                cors=* vhosts=localhost
INFO [01-10|17:08:11] WebSocket endpoint opened                url=ws://127.0.0.1:8546
INFO [01-10|17:08:11] Mapped network port                      proto=udp extport=61911 intport=61911 interface=NAT-PMP(192.168.199.1)
INFO [01-10|17:08:11] Mapped network port                      proto=tcp extport=61911 intport=61911 interface=NAT-PMP(192.168.199.1)

可見已經成功啟動,然后就能夠使用attach來連接這個geth客戶端了

1)geth attach有http\ws\ipc三種方式連接,看你配置geth.toml開啟了哪種方式,如:

$ geth attach ipc:/some/custom/path
$ geth attach http://191.168.1.1:8545
$ geth attach ws://191.168.1.1:8546

下面使用ipc連接:

userdeMBP:today2 user$ geth attach --datadir ./data0
Welcome to the Geth JavaScript console!

instance: Geth/v1.8.3-stable/darwin-amd64/go1.10.1
coinbase: 0x3b896fb3e31fc9b91921d19b8c7271d1c3af5b35
at block: 6486 (Thu, 10 Jan 2019 11:37:33 CST)
 datadir: /Users/user/today2/data0
 modules: admin: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

> 

--datadir指明geth所在目錄,將會自動連接當前目錄的/data0/geth.ipc,然后進入控制台

2)如果你只是想要執行某個命令,並不想要進入控制台的話,可以使用--exec:

userdeMBP:today2 user$ geth attach --datadir ./data0 --exec "eth.accounts" 
["0x3b896fb3e31fc9b91921d19b8c7271d1c3af5b35", "0x39f03934f1d9afbff39a395364416e71eae375cd", "0xd3f19f6c7cb02787c06792456351851f242a935b"]

可見上面的例子得到了所有賬戶address的信息

3)--preload用於將定制的JavaScript文件下載到控制台中,它可以將經常使用的函數下載進去,用於建立合約等,如:

geth --preload "/my/scripts/folder/utils.js,/my/scripts/folder/contracts.js" console

然后你就能夠在geth控制台調用文件的函數了

或者你也可以使用--jspath--exec結合實現類似上面的功能,如:

$ geth --jspath "/tmp" --exec 'loadScript("checkbalances.js")' attach http://123.123.123.123:8545

--jspath指定文件所在的目錄,--exec執行loadScript("js腳本文件"),然后該文件就下載到了geth客戶端

 或者:

geth --exec “personal.newAccount(‘password’)“ attach rpc:http://127.0.0.1:61911

該命令的意思就是attach通過rpc接口連接某個正在打開的區塊鏈,並在區塊鏈中運行語句personal.newAccount(‘password’)

 

3.bug

格式:

geth bug [arguments...]

上報bug

舉例:

在終端運行:

userdeMBP:today2 user$ geth bug

然后就會在瀏覽器中彈出下面的界面,用於填寫你遇見的bug,並發布:

 

 

4.copydb

格式:

geth copydb [command options] [arguments...]

選項:

ETHEREUM OPTIONS:
  --datadir "/Users/user/Library/Ethereum"  數據庫和keystore的數據目錄
  --syncmode "fast"                            區塊鏈同步模式 ("fast", "full", or "light")
  --testnet                                    說明連接的是Ropsten network: 預配置的工作量證明的測試網絡
  --rinkeby                                    說明連接的是Rinkeby network: 預配置的股權證明的測試網絡

PERFORMANCE TUNING OPTIONS:性能調優選項
  --cache value  分配給內部緩存的內存的兆字節 (默認值為: 1024)

LOGGING AND DEBUGGING OPTIONS:日志記錄和調試選項
  --fakepow  禁用工作量證明驗證

第一個參數必須是包含要從其中下載的區塊鏈的目錄,如我本地的geth區塊鏈目錄

舉例:

首先再建一個要將復制得到的數據存放的新區塊鏈目錄:

userdeMBP:~ user$ mkdir testCopy
userdeMBP:~ user$ cd testCopy/
userdeMBP:testCopy user$ mkdir data0

要先初始化創世區塊:

userdeMBP:testCopy user$ geth --datadir ./data0 init genesis.json 
INFO [01-11|11:04:14] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|11:04:14] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=16 handles=16
INFO [01-11|11:04:14] Writing custom genesis block 
INFO [01-11|11:04:14] Persisted trie from memory database      nodes=0 size=0.00B time=8.482µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-11|11:04:14] Successfully wrote genesis state         database=chaindata                                    hash=a0e580…a5e82e
INFO [01-11|11:04:14] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/lightchaindata cache=16 handles=16
INFO [01-11|11:04:14] Writing custom genesis block 
INFO [01-11|11:04:14] Persisted trie from memory database      nodes=0 size=0.00B time=1.893µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-11|11:04:14] Successfully wrote genesis state         database=lightchaindata                                    hash=a0e580…a5e82e

然后復制today1的數據:

userdeMBP:testCopy user$ geth --datadir ./data0 copydb /Users/user/geth/data0/

會得到下面的錯誤:

Genesis not found in chain

這是因為復制的區塊鏈目錄寫錯了,應該改成:

userdeMBP:testCopy user$ geth --datadir ./data0 copydb /Users/user/geth/data0/geth/chaindata
INFO [01-11|11:04:19] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|11:04:19] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=768 handles=1024
INFO [01-11|11:04:19] Disk storage enabled for ethash caches   dir=/Users/user/testCopy/data0/geth/ethash count=3
INFO [01-11|11:04:19] Disk storage enabled for ethash DAGs     dir=/Users/user/.ethash                    count=2
INFO [01-11|11:04:19] Loaded most recent local header          number=0 hash=a0e580…a5e82e td=262144
INFO [01-11|11:04:19] Loaded most recent local full block      number=0 hash=a0e580…a5e82e td=262144
INFO [01-11|11:04:19] Loaded most recent local fast block      number=0 hash=a0e580…a5e82e td=262144
INFO [01-11|11:04:19] Allocated cache and file handles         database=/Users/user/today1/data0/geth/chaindata   cache=1024 handles=256
INFO [01-11|11:04:19] Block synchronisation started 
INFO [01-11|11:04:20] Imported new chain segment               blocks=7 txs=0 mgas=0.000 elapsed=1.055s mgasps=0.000 number=7 hash=5462f1…94d464 cache=1.09kB
INFO [01-11|11:04:22] Imported new chain segment               blocks=1484 txs=186 mgas=50.173 elapsed=1.808s mgasps=27.745 number=1491 hash=6af9a8…27f4f1 cache=279.71kB
Database copy done in 2.989308101s
Compacting entire database...
Compaction done in 30.029904ms.

然后就能夠看見geth下的data0/geth/chaindata數據下載到了/Users/user/testCopy/data0/目錄下:

然后去兩邊的控制台中查看可見兩邊的數據已經成功同步,eth.blockNumber的數量都為3,詳細比較eth.getBlock(1)等區塊中的數據也是相同的:

⚠️這個過程並不是直接復制過去的,而是通過 downloader 模塊里的 NewFakePeer 創建一個虛擬對等節點,然后再進行數據同步完成的。 

 

中間還有這樣的錯誤:

resource temporarily unavailable

這可能是因為你要復制的區塊鏈還在運行,記得停止運行,否則不能復制它的數據

還有這樣的錯誤:

ERROR[01-11|10:58:40] 
########## BAD BLOCK #########
Chain config: {ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: <nil> Engine: ethash}

Number: 1
Hash: 0xb1c860c895da7d1e912bba497d163e8f5e775362588520c1d6054b67dcfafd94


Error: unknown ancestor
##############################
 
WARN [01-11|10:58:40] Synchronisation failed, dropping peer    peer=local err="retrieved hash chain is invalid"
WARN [01-11|10:58:40] Downloader wants to drop peer, but peerdrop-function is not set peer=local
retrieved hash chain is invalid

這是因為你必須先初始化你自己的創世區塊,然后再去復制別人的chaindata

 

5.dump

格式:

geth dump [<blockHash> | <blockNum>]

選項:

ETHEREUM OPTIONS:
  --datadir "/Users/user/Library/Ethereum"  指明數據庫和密鑰存儲文件的數據目錄

PERFORMANCE TUNING OPTIONS: 性能調優選項
  --cache value  分配給內部緩存的內存的兆字節 (默認值為: 1024)

參數被解釋為塊號或塊hash。
使用“ethereum dump 0”來得到genesis創世塊。輸出區塊的信息

舉例:

有一個本地環境如下:

userdeMBP:testCopy user$ geth --datadir ./data0 console 2>>geth.log
Welcome to the Geth JavaScript console!

instance: Geth/v1.8.3-stable/darwin-amd64/go1.10.1
coinbase: 0xe4029d8e973c6e61ece8f9ce03abb002fe4f29ba
at block: 2 (Fri, 11 Jan 2019 11:33:58 CST)
 datadir: /Users/user/testCopy/data0
 modules: admin: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

> eth.blockNumber
2
> exit

輸出第二個區塊的信息:

userdeMBP:testCopy user$ geth --datadir ./data0 dump 2
INFO [01-11|11:41:52] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|11:41:52] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=768 handles=1024
INFO [01-11|11:41:52] Disk storage enabled for ethash caches   dir=/Users/user/testCopy/data0/geth/ethash count=3
INFO [01-11|11:41:52] Disk storage enabled for ethash DAGs     dir=/Users/user/.ethash                    count=2
INFO [01-11|11:41:52] Loaded most recent local header          number=2 hash=84d34d…36d579 td=761209
INFO [01-11|11:41:52] Loaded most recent local full block      number=2 hash=84d34d…36d579 td=761209
INFO [01-11|11:41:52] Loaded most recent local fast block      number=2 hash=84d34d…36d579 td=761209
{
    "root": "09eaf04aa8f7683f10f6e936300a60ef9c18b0fbd80319a9e99e872c64f3682e",
    "accounts": {
        "e4029d8e973c6e61ece8f9ce03abb002fe4f29ba": {
            "balance": "6000000000000000000",
            "nonce": 0,
            "root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
            "codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
            "code": "",
            "storage": {}
        }
    }
}
INFO [01-11|11:41:52] Database closed                          database=/Users/user/testCopy/data0/geth/chaindata

如果是一個不存在的區塊,會報錯:

userdeMBP:testCopy user$ geth --datadir ./data0 dump 1492
INFO [01-11|16:42:52] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|16:42:52] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=768 handles=1024
INFO [01-11|16:42:52] Disk storage enabled for ethash caches   dir=/Users/user/testCopy/data0/geth/ethash count=3
INFO [01-11|16:42:52] Disk storage enabled for ethash DAGs     dir=/Users/user/.ethash                    count=2
INFO [01-11|16:42:52] Loaded most recent local header          number=2 hash=fdf89d…d6af3b td=761209
INFO [01-11|16:42:52] Loaded most recent local full block      number=1491 hash=6af9a8…27f4f1 td=216562781
INFO [01-11|16:42:52] Loaded most recent local fast block      number=2    hash=fdf89d…d6af3b td=761209
{}
Fatal: block not found

但是中間有報另一個錯:

userdeMBP:testCopy user$ geth --datadir ./data0 dump 10
INFO [01-11|11:46:30] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|11:46:30] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=768 handles=1024
INFO [01-11|11:46:30] Disk storage enabled for ethash caches   dir=/Users/user/testCopy/data0/geth/ethash count=3
INFO [01-11|11:46:30] Disk storage enabled for ethash DAGs     dir=/Users/user/.ethash                    count=2
INFO [01-11|11:46:30] Loaded most recent local header          number=2 hash=84d34d…36d579 td=761209
INFO [01-11|11:46:30] Loaded most recent local full block      number=2 hash=84d34d…36d579 td=761209
INFO [01-11|11:46:30] Loaded most recent local fast block      number=2 hash=84d34d…36d579 td=761209
Fatal: could not create new state: missing trie node af696276bd40988db6e69cb43231b378a6e802ff4230c8f79ed56e98ef94bc73 (path )

這個的對應代碼是:

            state, err := state.New(block.Root(), state.NewDatabase(chainDb))
            if err != nil { utils.Fatalf("could not create new state: %v", err)

 好像是在區塊驗證過程中出現了錯誤

 

6.dumpconfig

格式:

geth dumpconfig [command options] [arguments...]

顯示配置信息

選項:基本就是geth的所有選項,這些選項可以改變配置的對應值的信息

舉例:

得到所有的配置信息

userdeMBP:testCopy user$ geth --datadir ./data0 dumpconfig
INFO [01-11|14:17:13] Maximum peer count                       ETH=25 LES=0 total=25
[Eth]
NetworkId = 1
SyncMode = "fast"
LightPeers = 100
DatabaseCache = 768
GasPrice = 18000000000
EnablePreimageRecording = false

[Eth.Ethash]
CacheDir = "ethash"
CachesInMem = 2
CachesOnDisk = 3
DatasetDir = "/Users/user/.ethash"
DatasetsInMem = 1
DatasetsOnDisk = 2
PowMode = 0

[Eth.TxPool]
NoLocals = false
Journal = "transactions.rlp"
Rejournal = 3600000000000
PriceLimit = 1
PriceBump = 10
AccountSlots = 16
GlobalSlots = 4096
AccountQueue = 64
GlobalQueue = 1024
Lifetime = 10800000000000

[Eth.GPO]
Blocks = 20
Percentile = 60

[Shh]
MaxMessageSize = 1048576
MinimumAcceptedPOW = 2e-01

[Node]
DataDir = "data0"
IPCPath = "geth.ipc"
HTTPPort = 8545
HTTPVirtualHosts = ["localhost"]
HTTPModules = ["net", "web3", "eth", "shh"]
WSPort = 8546
WSModules = ["net", "web3", "eth", "shh"]

[Node.P2P]
MaxPeers = 25
NoDiscovery = false
BootstrapNodes = ["enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303", "enode://3f1d12044546b76342d59d4a05532c14b85aa669704bfe1f864fe079415aa2c02d743e03218e57a33fb94523adb54032871a6c51b2cc5514cb7c7e35b3ed0a99@13.93.211.84:30303", "enode://78de8a0916848093c73790ead81d1928bec737d565119932b98c6b100d944b7a95e94f847f689fc723399d2e31129d182f7ef3863f2b4c820abbf3ab2722344d@191.235.84.50:30303", "enode://158f8aab45f6d19c6cbf4a089c2670541a8da11978a2f90dbf6a502a4a3bab80d288afdbeb7ec0ef6d92de563767f3b1ea9e8e334ca711e9f8e2df5a0385e8e6@13.75.154.138:30303", "enode://1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082@52.74.57.123:30303", "enode://979b7fa28feeb35a4741660a16076f1943202cb72b6af70d327f053e248bab9ba81760f39d0701ef1d8f89cc1fbd2cacba0710a12cd5314d5e0c9021aa3637f9@5.1.83.226:30303"]
BootstrapNodesV5 = ["enode://06051a5573c81934c9554ef2898eb13b33a34b94cf36b202b69fde139ca17a85051979867720d4bdae4323d4943ddf9aeeb6643633aa656e0be843659795007a@35.177.226.168:30303", "enode://0cc5f5ffb5d9098c8b8c62325f3797f56509bff942704687b6530992ac706e2cb946b90a34f1f19548cd3c7baccbcaea354531e5983c7d1bc0dee16ce4b6440b@40.118.3.223:30304", "enode://1c7a64d76c0334b0418c004af2f67c50e36a3be60b5e4790bdac0439d21603469a85fad36f2473c9a80eb043ae60936df905fa28f1ff614c3e5dc34f15dcd2dc@40.118.3.223:30306", "enode://85c85d7143ae8bb96924f2b54f1b3e70d8c4d367af305325d30a61385a432f247d2c75c45c6b4a60335060d072d7f5b35dd1d4c45f76941f62a4f83b6e75daaf@40.118.3.223:30307"]
StaticNodes = []
TrustedNodes = []
ListenAddr = ":30303"
EnableMsgEvents = false

[Dashboard]
Host = "localhost"
Port = 8080
Refresh = 5000000000

比如使用了--networkid 1500,對應的配置信息也會變化:

userdeMBP:testCopy user$ geth --datadir ./data0 --networkid 1500 dumpconfig
INFO [01-11|14:23:19] Maximum peer count                       ETH=25 LES=0 total=25
[Eth]
NetworkId = 1500
SyncMode = "fast"

 

7.export

格式:

geth export [command options] [arguments...]

選項:

ETHEREUM OPTIONS:
  --datadir "/Users/user/Library/Ethereum"  數據庫和keystore的數據目錄

PERFORMANCE TUNING OPTIONS:性能調優選項
  --cache value  分配給內部緩存的內存的兆字節 (默認值為: 1024)

DEPRECATED OPTIONS:棄用選項
  --light  啟用輕客戶模式

用來導出一個區塊鏈文件,即所有區塊數據

舉例:

userdeMBP:testCopy user$ geth --datadir ./data0 export
Fatal: This command requires an argument.

//后面要有參數,我猜測是導出文件的名字,這里命名為exportFile1
userdeMBP:testCopy user$ geth --datadir ./data0 export exportFile1
INFO [01-11|14:30:14] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|14:30:14] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=768 handles=1024
INFO [01-11|14:30:14] Disk storage enabled for ethash caches   dir=/Users/user/testCopy/data0/geth/ethash count=3
INFO [01-11|14:30:14] Disk storage enabled for ethash DAGs     dir=/Users/user/.ethash                    count=2
INFO [01-11|14:30:14] Loaded most recent local header          number=2 hash=84d34d…36d579 td=761209
INFO [01-11|14:30:14] Loaded most recent local full block      number=2 hash=84d34d…36d579 td=761209
INFO [01-11|14:30:14] Loaded most recent local fast block      number=2 hash=84d34d…36d579 td=761209
INFO [01-11|14:30:14] Exporting blockchain                     file=exportFile1
INFO [01-11|14:30:14] Exporting batch of blocks                count=3
INFO [01-11|14:30:14] Exported blockchain                      file=exportFile1
Export done in 409.624µs

然后就能在當前目錄中看見生成了一個exportFile1可執行文件,里面內容為:

f901 f9f9 01f4 a000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 00a0 1dcc 4de8 dec7 5d7a
ab85 b567 b6cc d41a d312 451b 948a 7413
f0a1 42fd 40d4 9347 9400 0000 0000 0000
0000 0000 0000 0000 0000 0000 00a0 56e8
1f17 1bcc 55a6 ff83 45e6 92c0 f86e 5b48
e01b 996c adc0 0162 2fb5 e363 b421 a056
e81f 171b cc55 a6ff 8345 e692 c0f8 6e5b
48e0 1b99 6cad c001 622f b5e3 63b4 21a0
56e8 1f17 1bcc 55a6 ff83 45e6 92c0 f86e
5b48 e01b 996c adc0 0162 2fb5 e363 b421
b901 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
...

 

8.export-preimages

格式:

export-preimages [command options] [arguments...]

選項:

ETHEREUM OPTIONS:
  --datadir "/Users/user/Library/Ethereum"  數據庫和keystore的數據目錄

PERFORMANCE TUNING OPTIONS:性能調優選項
  --cache value  分配給內部緩存的內存的兆字節 (默認值為: 1024)

DEPRECATED OPTIONS:棄用選項
  --light  啟用輕客戶模式

將hash預鏡像導出到RLP編碼的流

舉例:

userdeMBP:testCopy user$ geth --datadir ./data0 export-preimages exportPreImage
INFO [01-11|14:38:14] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|14:38:14] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=768 handles=1024
INFO [01-11|14:38:14] Exporting preimages                      file=exportPreImage
INFO [01-11|14:38:14] Exported preimages                       file=exportPreImage
Export done in 4.128379ms

然后就能在當前目錄中看見生成了一個exportPreImage可執行文件,里面內容為:

”䝎—<naìèùΫ°þO)º

 

9.import

格式:

geth import [command options] [arguments...]

選項:

ETHEREUM OPTIONS:
  --datadir "/Users/user/Library/Ethereum"  數據庫和keystore的數據目錄
  --gcmode value                               區塊鏈垃圾收集模式 ("full", "archive") (default: "full")

PERFORMANCE TUNING OPTIONS:性能調優選項
  --cache value           分配給內部緩存的內存的兆字節 (默認值為: 1024)
  --cache.database value  用於數據庫io的緩存內存預留百分比 (default: 75)
  --cache.gc value        用於trie修剪的緩存內存預留百分比 (default: 25)

DEPRECATED OPTIONS:棄用選項
  --light  啟用輕客戶模式

import命令從rlp編碼的表單導入塊。表單可以是一個包含幾個rlp編碼塊的文件,也可以使用多個文件。
如果只使用一個文件,導入錯誤將導致失敗。如果使用多個文件,即使出現單獨的rlp文件導入失敗,處理也將繼續。

用來導入一個區塊鏈文件,基本上相當於同步操作

舉例,導入剛剛導出的數據:

userdeMBP:testCopy user$ geth --datadir ./data0 import exportFile1
INFO [01-11|14:43:09] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|14:43:09] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=768 handles=1024
INFO [01-11|14:43:09] Disk storage enabled for ethash caches   dir=/Users/user/testCopy/data0/geth/ethash count=3
INFO [01-11|14:43:09] Disk storage enabled for ethash DAGs     dir=/Users/user/.ethash                    count=2
INFO [01-11|14:43:09] Loaded most recent local header          number=2 hash=84d34d…36d579 td=761209
INFO [01-11|14:43:09] Loaded most recent local full block      number=2 hash=84d34d…36d579 td=761209
INFO [01-11|14:43:09] Loaded most recent local fast block      number=2 hash=84d34d…36d579 td=761209
INFO [01-11|14:43:09] Importing blockchain                     file=exportFile1
INFO [01-11|14:43:09] Skipping batch as all blocks present     batch=0 first=309fc9…1b7bde last=84d34d…36d579
INFO [01-11|14:43:09] Writing cached state to disk             block=2 hash=84d34d…36d579 root=09eaf0…f3682e
INFO [01-11|14:43:09] Persisted trie from memory database      nodes=0 size=0.00B time=33.291µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-11|14:43:09] Writing cached state to disk             block=1 hash=309fc9…1b7bde root=a5122d…57851e
INFO [01-11|14:43:09] Persisted trie from memory database      nodes=0 size=0.00B time=1.068µs  gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-11|14:43:09] Blockchain manager stopped 
Import done in 849.233µs.

Compactions
 Level |   Tables   |    Size(MB)   |    Time(sec)  |    Read(MB)   |   Write(MB)
-------+------------+---------------+---------------+---------------+---------------
   0   |          5 |       0.00108 |       0.00000 |       0.00000 |       0.00000
   1   |          1 |       0.61511 |       0.00000 |       0.00000 |       0.00000

Read(MB):0.15649 Write(MB):0.10170
Trie cache misses:  0
Trie cache unloads: 0

Object memory: 194.334 MB current, 194.111 MB peak
System memory: 405.694 MB current, 405.444 MB peak
Allocations:   0.017 million
GC pause:      305.935µs

Compacting entire database...
Compaction done in 152.183203ms.

Compactions
 Level |   Tables   |    Size(MB)   |    Time(sec)  |    Read(MB)   |   Write(MB)
-------+------------+---------------+---------------+---------------+---------------
   0   |          0 |       0.00000 |       0.00119 |       0.00000 |       0.00021
   1   |          1 |       0.61511 |       0.15276 |       1.23150 |       1.23021

Read(MB):1.23723 Write(MB):1.23117
INFO [01-11|14:43:09] Database closed                          database=/Users/user/testCopy/data0/geth/chaindata

 

10.import-preimages

格式:

geth import-preimages [command options] [arguments...]

選項:

ETHEREUM OPTIONS:
  --datadir "/Users/user/Library/Ethereum"  數據庫和keystore的數據目錄

PERFORMANCE TUNING OPTIONS:性能調優選項
  --cache value  分配給內部緩存的內存的兆字節 (默認值為: 1024)

DEPRECATED OPTIONS:棄用選項
  --light  啟用輕客戶模式

從RLP編碼的流導入hash預鏡像

 

結合

import和export其實是結合起來使用的用於同步兩個區塊的數據

比如一開始我的testCopy目錄中的數據只同步了2個區塊,today1目錄下的區塊有1491個區塊,同步兩邊區塊的方法就是使用export導出today1下的區塊鏈文件,然后將該區塊鏈文件導入testCopy中,同步就完成了,執行如下:

1)首先export出today1的區塊鏈文件:

userdeMBP:~ user$ cd today1
userdeMBP:today1 user$ geth --datadir ./data0 export exportFile
INFO [01-11|14:56:34] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|14:56:34] Allocated cache and file handles         database=/Users/user/today1/data0/geth/chaindata cache=768 handles=1024
INFO [01-11|14:56:34] Disk storage enabled for ethash caches   dir=/Users/user/today1/data0/geth/ethash count=3
INFO [01-11|14:56:34] Disk storage enabled for ethash DAGs     dir=/Users/user/.ethash                  count=2
INFO [01-11|14:56:34] Loaded most recent local header          number=1491 hash=6af9a8…27f4f1 td=216562781
INFO [01-11|14:56:34] Loaded most recent local full block      number=1491 hash=6af9a8…27f4f1 td=216562781
INFO [01-11|14:56:34] Loaded most recent local fast block      number=1491 hash=6af9a8…27f4f1 td=216562781
INFO [01-11|14:56:34] Exporting blockchain                     file=exportFile
INFO [01-11|14:56:34] Exporting batch of blocks                count=1492
INFO [01-11|14:56:34] Exported blockchain                      file=exportFile
Export done in 222.88291ms

2)然后將導出的exportFile文件放到testCopy目錄下,然后import:

userdeMBP:today1 user$ cd ..
userdeMBP:~ user$ cd testCopy/
userdeMBP:testCopy user$ geth --datadir ./data0 import exportFile
INFO [01-11|14:58:56] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|14:58:56] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=768 handles=1024
INFO [01-11|14:58:56] Disk storage enabled for ethash caches   dir=/Users/user/testCopy/data0/geth/ethash count=3
INFO [01-11|14:58:56] Disk storage enabled for ethash DAGs     dir=/Users/user/.ethash                    count=2
INFO [01-11|14:58:56] Loaded most recent local header          number=2 hash=84d34d…36d579 td=761209
INFO [01-11|14:58:56] Loaded most recent local full block      number=2 hash=84d34d…36d579 td=761209
INFO [01-11|14:58:56] Loaded most recent local fast block      number=2 hash=84d34d…36d579 td=761209
INFO [01-11|14:58:56] Importing blockchain                     file=exportFile
INFO [01-11|14:58:56] Imported new chain segment               blocks=1 txs=0 mgas=0.000 elapsed=2.528ms mgasps=0.000 number=1 hash=b1c860…fafd94 cache=200.00B
INFO [01-11|14:58:56] Imported new chain segment               blocks=1490 txs=186 mgas=50.173 elapsed=494.983ms mgasps=101.362 number=1491 hash=6af9a8…27f4f1 cache=279.71kB
INFO [01-11|14:58:56] Writing cached state to disk             block=1491 hash=6af9a8…27f4f1 root=ff8472…04736e
INFO [01-11|14:58:56] Persisted trie from memory database      nodes=401 size=160.91kB time=1.697075ms gcnodes=4361 gcsize=829.44kB gctime=7.321206ms livenodes=632 livesize=118.81kB
INFO [01-11|14:58:56] Writing cached state to disk             block=1490 hash=ea103c…e25dda root=036ca7…ab9892
INFO [01-11|14:58:56] Persisted trie from memory database      nodes=4   size=766.00B  time=55.975µs   gcnodes=0    gcsize=0.00B    gctime=0s         livenodes=628 livesize=118.04kB
INFO [01-11|14:58:56] Writing cached state to disk             block=1364 hash=2a246d…f79e6c root=86c771…0d678a
INFO [01-11|14:58:56] Persisted trie from memory database      nodes=32  size=4.73kB   time=163.8µs    gcnodes=0    gcsize=0.00B    gctime=0s         livenodes=596 livesize=113.31kB
INFO [01-11|14:58:56] Blockchain manager stopped 
Import done in 516.917879ms.

Compactions
 Level |   Tables   |    Size(MB)   |    Time(sec)  |    Read(MB)   |   Write(MB)
-------+------------+---------------+---------------+---------------+---------------
   0   |          1 |       0.00023 |       0.00000 |       0.00000 |       0.00000
   1   |          1 |       0.61511 |       0.00000 |       0.00000 |       0.00000

Read(MB):0.47825 Write(MB):1.77525
Trie cache misses:  0
Trie cache unloads: 0

Object memory: 205.098 MB current, 194.027 MB peak
System memory: 408.772 MB current, 404.944 MB peak
Allocations:   1.389 million
GC pause:      770.634µs

Compacting entire database...
Compaction done in 40.568772ms.

Compactions
 Level |   Tables   |    Size(MB)   |    Time(sec)  |    Read(MB)   |   Write(MB)
-------+------------+---------------+---------------+---------------+---------------
   0   |          0 |       0.00000 |       0.01313 |       0.00000 |       0.77336
   1   |          1 |       0.70644 |       0.01905 |       1.38869 |       0.70644

Read(MB):1.37347 Write(MB):3.25529
INFO [01-11|14:58:56] Database closed                          database=/Users/user/testCopy/data0/geth/chaindata

3)這個時候去查看testCopy控制台的區塊數,果然變成了:

> eth.blockNumber
1491

4)這時候再導出testCopy的區塊鏈文件,可以發現和today1的區塊鏈文件的值是相同的L:

userdeMBP:testCopy user$ geth --datadir ./data0 export exportFile2
INFO [01-11|14:59:16] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|14:59:16] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=768 handles=1024
INFO [01-11|14:59:16] Disk storage enabled for ethash caches   dir=/Users/user/testCopy/data0/geth/ethash count=3
INFO [01-11|14:59:16] Disk storage enabled for ethash DAGs     dir=/Users/user/.ethash                    count=2
INFO [01-11|14:59:16] Loaded most recent local header          number=2 hash=fdf89d…d6af3b td=761209
INFO [01-11|14:59:16] Loaded most recent local full block      number=1491 hash=6af9a8…27f4f1 td=216562781
INFO [01-11|14:59:16] Loaded most recent local fast block      number=2    hash=fdf89d…d6af3b td=761209
INFO [01-11|14:59:16] Exporting blockchain                     file=exportFile2
INFO [01-11|14:59:16] Exporting batch of blocks                count=1492
INFO [01-11|14:59:16] Exported blockchain                      file=exportFile2
Export done in 130.764885ms

⚠️import和export運行的比較慢,因為區塊上的所有交易都會被檢查

 

11.init

格式:

geth init [command options] [arguments...]

選項:

ETHEREUM OPTIONS:
  --datadir "/Users/user/Library/Ethereum"  數據庫和keystore的數據目錄

DEPRECATED OPTIONS:棄用選項
  --light  啟用輕客戶模式

init命令初始化網絡的新genesis塊和定義。
這是一個破壞性的行為,會改變你所參與的網絡。
它希望將genesis.json文件作為參數。

舉例:

userdeMBP:testCopy user$ geth --datadir ./data0 init genesis.json 
INFO [01-11|11:04:14] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|11:04:14] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/chaindata cache=16 handles=16
INFO [01-11|11:04:14] Writing custom genesis block 
INFO [01-11|11:04:14] Persisted trie from memory database      nodes=0 size=0.00B time=8.482µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-11|11:04:14] Successfully wrote genesis state         database=chaindata                                    hash=a0e580…a5e82e
INFO [01-11|11:04:14] Allocated cache and file handles         database=/Users/user/testCopy/data0/geth/lightchaindata cache=16 handles=16
INFO [01-11|11:04:14] Writing custom genesis block 
INFO [01-11|11:04:14] Persisted trie from memory database      nodes=0 size=0.00B time=1.893µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-11|11:04:14] Successfully wrote genesis state         database=lightchaindata                                    hash=a0e580…a5e82e

genesis.json類似:

{
    "config": {
    "chainId": 1500,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "ByzantiumBlock": 0
    },
    "coinbase" : "0x0000000000000000000000000000000000000000",
    "difficulty" : "0x40000",
    "extraData" : "",
    "gasLimit" : "0xffffffff",
    "nonce" : "0x0000000000000042",
    "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "timestamp" : "0x00",
    "alloc": {}
}

 

12.js

格式:

geth js <jsfile> [jsfile...]

選項:基本就是geth的所有選項

JavaScript VM暴露節點管理界面以及Ðapp JavaScript API。參見https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console

執行指定的JavaScript文件(可以為多個文件)

舉例:

生成一個test.js文件:

console.log("hello")

然后運行:

userdeMBP:today2 user$ geth js test.js
INFO [01-11|15:35:10] Maximum peer count                       ETH=25 LES=0 total=25
INFO [01-11|15:35:10] Starting peer-to-peer node               instance=Geth/v1.8.3-stable/darwin-amd64/go1.10.1
INFO [01-11|15:35:10] Allocated cache and file handles         database=/Users/user/Library/Ethereum/geth/chaindata cache=768 handles=128
INFO [01-11|15:35:10] Initialised chain configuration          config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: <nil> Engine: ethash}"
INFO [01-11|15:35:10] Disk storage enabled for ethash caches   dir=/Users/user/Library/Ethereum/geth/ethash count=3
INFO [01-11|15:35:10] Disk storage enabled for ethash DAGs     dir=/Users/user/.ethash                      count=2
INFO [01-11|15:35:10] Initialising Ethereum protocol           versions="[63 62]" network=1
INFO [01-11|15:35:10] Loaded most recent local header          number=654395 hash=410ec3…d5895e td=3904096205036238619
INFO [01-11|15:35:10] Loaded most recent local full block      number=0      hash=d4e567…cb8fa3 td=17179869184
INFO [01-11|15:35:10] Loaded most recent local fast block      number=652112 hash=18a7ea…21dbcf td=3886518230582438446
INFO [01-11|15:35:10] Loaded local transaction journal         transactions=0 dropped=0
INFO [01-11|15:35:10] Regenerated local transaction journal    transactions=0 accounts=0
INFO [01-11|15:35:10] Starting P2P networking 
INFO [01-11|15:35:10] UDP listener up                          self=enode://0a6a3338224c1e12308ca3084b99f2661ef94f8ad228ce8d82879feb6eadb0fbc1d0fc8ca909342f3a68d66c94879888546bbdb638a51b0f9526e36b40333914@10.240.100.98:30303
INFO [01-11|15:35:10] RLPx listener up                         self=enode://0a6a3338224c1e12308ca3084b99f2661ef94f8ad228ce8d82879feb6eadb0fbc1d0fc8ca909342f3a68d66c94879888546bbdb638a51b0f9526e36b40333914@10.240.100.98:30303
INFO [01-11|15:35:10] IPC endpoint opened                      url=/Users/user/Library/Ethereum/geth.ipc
hello
INFO [01-11|15:35:10] IPC endpoint closed                      endpoint=/Users/user/Library/Ethereum/geth.ipc
INFO [01-11|15:35:10] Blockchain manager stopped 
INFO [01-11|15:35:10] Stopping Ethereum protocol 
INFO [01-11|15:35:10] Ethereum protocol stopped 
INFO [01-11|15:35:10] Transaction pool stopped 
INFO [01-11|15:35:10] Database closed                          database=/Users/user/Library/Ethereum/geth/chaindata
INFO [01-11|15:35:10] Mapped network port                      proto=udp extport=30303 intport=30303 interface=NAT-PMP(192.168.199.1)
INFO [01-11|15:35:11] Mapped network port                      proto=tcp extport=30303 intport=30303 interface=NAT-PMP(192.168.199.1)

目的是為了干啥??????

如果運行復雜一點的內容:

var ethers = require('ethers');
var customHttpProvider = new ethers.providers.JsonRpcProvider("http://localhost:8202");
console.log(customHttpProvider.getBalance("0x39f03934f1d9afbff39a395364416e71eae375cd"));

會報錯:

Fatal: Failed to execute test.js: Error: Cannot find module 'ethers'

但是這個模塊命名安裝在today2目錄里面,不懂??????

 

13.license

格式:

geth license

舉例:

userdeMBP:~ user$ geth license
Geth is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Geth is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with geth. If not, see <http://www.gnu.org/licenses/>.

 

14.makecache

格式:

geth makecache <block number> <outputdir>

makecache命令在中生成一個ethash驗證緩存。
此命令用於在<outputDir>支持系統測試項目。
普通用戶不需要執行它。

舉例,對區塊1生成ethash緩存:

userdeMBP:testCopy user$ geth --datadir data0 makecache 1 .

結果就是在當前目錄下生成了一個如下圖所示的cache-R23-0000000000000000文件:

 

 15.makedag

格式:

geth makedag <block number> <outputdir>

makedag命令在<outputDir>中生成挖礦需要的 DAG 數據集。
此命令用於支持系統測試項目。
普通用戶不需要執行它。

⚠️Ethash是PoW系統,它需要一個大約1GB的數據集,它就是DAG。這通常需要幾個小時才能生成,所以我們傾向於在硬盤中存儲它

 舉例:

userdeMBP:testCopy user$ geth --datadir data0 makedag 1 .
INFO [01-11|16:01:19] Generating DAG in progress               epoch=0 percentage=0 elapsed=1.322s
INFO [01-11|16:01:20] Generating DAG in progress               epoch=0 percentage=1 elapsed=2.422s
INFO [01-11|16:01:21] Generating DAG in progress               epoch=0 percentage=2 elapsed=3.490s
INFO [01-11|16:01:22] Generating DAG in progress               epoch=0 percentage=3 elapsed=4.554s
INFO [01-11|16:01:23] Generating DAG in progress               epoch=0 percentage=4 elapsed=5.692s
INFO [01-11|16:01:25] Generating DAG in progress               epoch=0 percentage=5 elapsed=6.718s
INFO [01-11|16:01:26] Generating DAG in progress               epoch=0 percentage=6 elapsed=7.752s
...
INFO [01-11|16:03:22] Generating DAG in progress               epoch=0 percentage=98 elapsed=2m4.000s
INFO [01-11|16:03:24] Generating DAG in progress               epoch=0 percentage=99 elapsed=2m5.783s
INFO [01-11|16:03:24] Generated ethash verification cache      epoch=0 elapsed=2m5.786s

然后會在當前目錄下生成full-R23-0000000000000000文件

⚠️一般我們在新生成一個私有網絡時,當我們運行miner.start()要開始挖礦之前,都會先生成挖礦需要使用的DAG數據集,它是用於以太坊工作量證明PoW算法的數據集

 

16.monitor

格式:

geth monitor [command options] [arguments...]

選項:

MISC OPTIONS:
  --attach value   連接的API端點(default: "/Users/user/Library/Ethereum/geth.ipc")
  --rows value     圖表網格中的最大行數(default: 5)
  --refresh value  刷新間隔(秒)(default: 3)

Geth monitor是一種工具,用於收集和可視化節點收集的各種內部指標,支持不同的圖表類型以及同時顯示多個指標的能力。

 舉例:

userdeMBP:today2 user$ geth --datadir data0 monitor --attach=/Users/user/today2/data0/geth.ipc
Fatal: Unable to attach to geth node: dial unix /Users/user/today2/data0/geth.ipc: connect: connection refused

錯誤因為沒有打開today2控制台

userdeMBP:today2 user$ geth --datadir data0 monitor --attach=/Users/user/today2/data0/geth.ipc
Fatal: No metrics specified.

Available:
 - chain/inserts/AvgRate01Min
 - chain/inserts/AvgRate05Min
 - chain/inserts/AvgRate15Min
 - chain/inserts/MeanRate
...
 - txpool/queued/discard/Overall
 - txpool/queued/nofunds/Overall
 - txpool/queued/ratelimit/Overall
 - txpool/queued/replace/Overall
 - txpool/underpriced/Overall

有錯:

Fatal: No metrics specified.

並不懂,可能是需要什么參數??????

 

 

17.removedb

格式:

geth removedb

選項:

ETHEREUM OPTIONS:
  --datadir "/Users/user/Library/Ethereum"  數據庫和keystore的數據目錄

DEPRECATED OPTIONS:棄用選項
  --light  啟用輕客戶模式

移除區塊鏈和狀態數據庫,其實就是把"chaindata", "lightchaindata"兩個文件夾中的數據刪除

userdeMBP:testCopy user$ geth --datadir data0 removedb
INFO [01-11|17:00:17] Maximum peer count                       ETH=25 LES=0 total=25
/Users/user/testCopy/data0/geth/chaindata
Remove this database? [y/N] y
Remove this database? [y/N] y
INFO [01-11|17:00:21] Database successfully deleted            database=chaindata elapsed=6.990ms
/Users/user/testCopy/data0/geth/lightchaindata
Remove this database? [y/N] y
Remove this database? [y/N] y
INFO [01-11|17:00:31] Database successfully deleted            database=lightchaindata elapsed=574.6µs
userdeMBP:testCopy user$ 

然后就可以看見對應目錄下的這兩個文件就沒了:

 

 

18.version

舉例:

userdeMBP:today2 user$ geth version
Geth
Version: 1.8.3-stable
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10.1
Operating System: darwin
GOPATH=/Users/user/go
GOROOT=/usr/local/opt/go/libexec

這個命令的輸出應該是機器可讀的

 

19.wallet

舉例:

geth wallet import /path/to/my/presale.wallet

將提示您的密碼,並導入您的以太預售帳戶。
它可以與--password選項非交互式地使用,該選項將passwordfile作為參數,其中包含明文形式的錢包密碼。

 

20.console

Geth控制台是一個交互式shell的JavaScript運行時環境暴露節點管理界面以及Ðapp JavaScript API。
見https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console。

//將配置信息寫入geth.toml文件中
userdeMBP:today2 user$geth --datadir data0 --networkid 1500 --port 61911 --rpc --rpcapi 'eth,net,web3,admin,personal,miner,debug' --rpccorsdomain '*' --rpcport 8202 dumpconfig > ./geth.toml 

//然后使用--config指向配置文件來運行控制台,並將日志寫到geth.log文件中
userdeMBP:today2 user$ geth --config geth.toml console 2>>geth.log
Welcome to the Geth JavaScript console!

instance: Geth/v1.8.3-stable/darwin-amd64/go1.10.1
coinbase: 0x3b896fb3e31fc9b91921d19b8c7271d1c3af5b35
at block: 6486 (Thu, 10 Jan 2019 11:37:33 CST)
 datadir: /Users/user/today2/data0
 modules: admin: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

> 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM