簡體   English   中英

以太坊專用網挖礦

[英]Ethereum private network mining

1)我使用以下命令建立一個專用的以太坊網絡

$geth --genesis <genesis json file path> --datadir <some path to an empty  
folder> --networkid 123 --nodiscover --maxpeers 0 console

2)創建一個帳戶

3)然后,使用miner.start()命令啟動礦工。

不久之后,以太幣被自動添加到我的帳戶中,但是我的專用網絡中沒有任何待處理的交易。 那么我的礦工從哪里可以得到以太幣呢?

即使我沒有實例化網絡中的任何事務,但一旦啟動礦機,我就能看到一些事務記錄在日志中。

日志如下:

I0118 11:59:11.696523 9427 backend.go:584] Automatic pregeneration of ethash  
DAG ON (ethash dir: /Users/minisha/.ethash)
I0118 11:59:11.696590 9427 backend.go:591] checking DAG (ethash dir:   
/Users/minisha/.ethash)
I0118 11:59:11.696728 9427 miner.go:119] Starting mining operation (CPU=4 
TOT=5)
true
> I0118 11:59:11.703907 9427 worker.go:570] commit new work on block 1 with 0
txs & 0 uncles. Took 7.109111ms
I0118 11:59:11.704083 9427 ethash.go:220] Generating DAG for epoch 0 (size 
1073739904) (0000000000000000000000000000000000000000000000000000000000000000)
I0118 11:59:12.698679 9427 ethash.go:237] Done generating DAG for epoch 0, it  
took 994.61107ms
I0118 11:59:15.163864 9427 worker.go:349]

我的創始塊代碼如下:

{
“nonce”: “0xdeadbeefdeadbeef”,
“timestamp”: “0x0”,
“parentHash”: 
“0x0000000000000000000000000000000000000000000000000000000000000000”,
“extraData”: “0x0”,
“gasLimit”: “0x8000000”,
“difficulty”: “0x400”,
“mixhash”: 
“0x0000000000000000000000000000000000000000000000000000000000000000”,
“coinbase”: “0x3333333333333333333333333333333333333333”,
“alloc”: {
}
}

由於我的網絡是孤立的,並且只有一個節點(沒有對等節點),因此我對此行為感到非常困惑。 任何見解將不勝感激。

您的客戶正在挖空區塊(不包含任何交易),並獲得挖出區塊的獎勵,即每區塊5 ETH。

如果要防止私有區塊鏈中出現空塊,則應考慮使用eth客戶端(C ++實現)。

如果是geth客戶,則可以使用JavaScript腳本來修改客戶的行為。 任何腳本都可以使用js命令加載: geth js script.js

var mining_threads = 1

function checkWork() {
    if (eth.getBlock("pending").transactions.length > 0) {
        if (eth.mining) return;
        console.log("== Pending transactions! Mining...");
        miner.start(mining_threads);
    } else {
        miner.stop(0);  // This param means nothing
        console.log("== No transactions! Mining stopped.");
    }
}

eth.filter("latest", function(err, block) { checkWork(); });
eth.filter("pending", function(err, block) { checkWork(); });

checkWork();

您可以嘗試EmbarkJS ,它可以在專用網絡上使用mineWhenNeeded選項運行geth客戶端。 它只會在有新交易進入時才開采。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM