如何用Pantheon客户端挖矿

在这篇文章中,我继续我的系列Pantheon,新的基于Java的以太坊客户端,今天我将介绍如何使用Pantheon。我是Java的忠实粉丝,所以我非常高兴能够撰写更多关于这个基于Java的新工具,并在未来的帖子中探索所有企业就绪功能。

为了使用Pantheon挖矿以太,您首先需要创建一个钱包来存储我们的矿工节点将获得的资金。Pantheon不支持客户端内部的密钥管理,因此您需要使用MetaMask等第三方工具来创建和管理您的以太坊帐户。MetaMask是一个以太坊钱包作为浏览器扩展运行,这使得管理您的以太坊帐户的整个过程变得非常容易。让我们从使用MetaMask创建一个帐户开始。

使用MetaMask创建钱包

1.使用Chrome安装MetaMask插件

在浏览器中导航到 https://metamask.io。在主页上,单击“获取chrome扩展”(如果您使用其他浏览器,请单击相关链接)。

点击“添加到Chrome”,然后按照其他提示完成安装。

2.创建一个新的MetaMask钱包

MetaMask安装完成后,单击“开始”按钮,然后您将看到此页面。点击“创建电子钱包”以开始创建第一个钱包的过程。

首先输入MetaMask钱包的新密码,接受条款和条件,然后单击“创建”。

按照其他提示确认您的秘密备份短语,然后您应该看到MetaMask主屏幕。

3.在MetaMask中创建一个新的以太坊帐户

在MetaMask主屏幕上,单击右上角的圆圈图标,然后单击“创建帐户”。

输入新帐户的名称,然后点击“创建”。在下面的这个例子中,我将帐户命名为“Pantheon Miner”。请注意,创建新帐户只会生成新的公钥/私钥对和地址。在您开始使用该网络上的帐户发送某些交易之前,此帐户的详细信息实际上不会发送到任何以太坊网络。您可以在多个网络上使用相同的帐户,但在一个网络上获得的以太坊将与在另一个网络上获得的以太坊分开。

我们现在可以在MetaMask主屏幕中看到我们的新帐户,它显示我们目前在主以太坊网络(又名主网络)上没有以太坊。您可以在右上角的网络下拉列表中选择其他网络之一,它仍然会显示我们没有以太坊。在经营矿工后,我们将看到随着我们的开采价值增长。

然后单击Pantheon Miner帐户的地址(在“详细信息”按钮下方)将值复制到剪贴板。我们将在本教程的其余部分中使用此帐户地址。

在本地开发网络上挖矿

让我们首先在本地运行一个开发人员,获得一些以太,然后在MetaMask中查看我们当前的余额。要启动矿工运行此命令:

pantheon --network=dev --miner-enabled --miner-coinbase=<account> --rpc-http-cors-origins="all" --rpc-http-enabled --data-path=<blockchain-data-dir>

‘miner-coinbase’论证告诉Pantheon哪个以太坊账户将获得的以太币发送给。您还需要设置’miner-enabled’标志来启动矿工。请注意,下面,我已将’miner-coinbase’参数设置为我之前复制到剪贴板的Pantheon矿工帐户的值。运行命令我们可以看到Pantheon节点启动并开始挖矿块。这些块的添加速度非常快,因为这是一个开发网络,默认情况下难以配置低挖矿:

$pantheon --network=dev --miner-enabled --miner-coinbase=0x04fCE695a0aa69C3e9943A0c3e6667449e7D5fDa --rpc-http-cors-origins="all" --rpc-http-enabled --data-path=/tmp/tmpDatdir
 2019-06-01 18:39:30.956+08:00 | main | INFO  | StaticNodesParser | StaticNodes file /tmp/tmpDatdir/static-nodes.json does not exist, no static connections will be created.
 2019-06-01 18:39:30.958+08:00 | main | INFO  | Pantheon | Connecting to 0 static nodes.
 2019-06-01 18:39:31.481+08:00 | main | INFO  | KeyPairUtil | Loaded key 0x9d8ce22bd36e72e4b1a272a362c1521df2a46ac2feb1f976a8044ac7dd7cbf38daf4f330e44edb1fad970130ea2e6d2becef2edd6ce7546079c87c5677e262eb from /tmp/tmpDatdir/key
 2019-06-01 18:39:31.719+08:00 | main | INFO  | ProtocolScheduleBuilder | Protocol schedule created with milestones: [ConstantinopleFix: 0]
 2019-06-01 18:39:32.026+08:00 | nioEventLoopGroup-2-1 | INFO  | NettyP2PNetwork | P2PNetwork started and listening on /0:0:0:0:0:0:0:0:30303
 2019-06-01 18:39:32.058+08:00 | main | INFO  | Runner | Starting Ethereum main loop …
 2019-06-01 18:39:32.059+08:00 | main | INFO  | NetworkRunner | Starting Network.
 2019-06-01 18:39:32.060+08:00 | main | INFO  | PeerDiscoveryAgent | Starting peer discovery agent on host=0.0.0.0, port=30303
 2019-06-01 18:39:32.116+08:00 | vert.x-eventloop-thread-2 | INFO  | VertxPeerDiscoveryAgent | Started peer discovery agent successfully, on effective host=0:0:0:0:0:0:0:0 and port=30303
 2019-06-01 18:39:32.133+08:00 | main | INFO  | NettyP2PNetwork | Enode URL enode://9d8ce22bd36e72e4b1a272a362c1521df2a46ac2feb1f976a8044ac7dd7cbf38daf4f330e44edb1fad970130ea2e6d2becef2edd6ce7546079c87c5677e262eb@127.0.0.1:30303
 2019-06-01 18:39:32.140+08:00 | main | INFO  | DefaultSynchronizer | Starting synchronizer.
 2019-06-01 18:39:32.146+08:00 | main | INFO  | WaitForPeersTask | Waiting for 1 peers to connect.
 2019-06-01 18:39:32.149+08:00 | main | INFO  | JsonRpcHttpService | Starting JsonRPC service on 127.0.0.1:8545
 2019-06-01 18:39:32.277+08:00 | vert.x-eventloop-thread-5 | INFO  | JsonRpcHttpService | JsonRPC service started and listening on 127.0.0.1:8545
 2019-06-01 18:39:32.277+08:00 | main | INFO  | WebSocketService | Starting Websocket service on 127.0.0.1:8546
 2019-06-01 18:39:32.283+08:00 | vert.x-eventloop-thread-7 | INFO  | WebSocketService | Websocket service started and listening on 127.0.0.1:8546
 2019-06-01 18:39:32.284+08:00 | main | INFO  | Runner | Ethereum main loop is up.
 2019-06-01 18:39:33.284+08:00 | pool-9-thread-1 | INFO  | BlockMiner | Produced and imported block #27 / 0 tx / 0 om / 0 (0.0%) gas / (0x4eec78c714c0b28c98518c4cc7164007e746875d9f7b10658b86bca92721fb65) in 1.484s
 2019-06-01 18:39:33.686+08:00 | pool-9-thread-2 | INFO  | BlockMiner | Produced and imported block #28 / 0 tx / 0 om / 0 (0.0%) gas / (0x61d50c1240229ae8ac3abd59ed1bc682b4cc0390419b033843b7fec48dfc32cd) in 0.406s
 2019-06-01 18:39:34.378+08:00 | pool-9-thread-1 | INFO  | BlockMiner | Produced and imported block #29 / 0 tx / 0 om / 0 (0.0%) gas / (0xf01fecc15cd4a09008cf0d1d68f75cec34ea2bb2da773c52165d6e2ed169ec81) in 0.691s
 2019-06-01 18:39:35.018+08:00 | pool-9-thread-2 | INFO  | BlockMiner | Produced and imported block #30 / 0 tx / 0 om / 0 (0.0%) gas / (0xce9e22da4814a370aa8d3a648a16439803fb915461dd886816d715ab82f7afc3) in 0.640s
 2019-06-01 18:39:35.026+08:00 | pool-9-thread-1 | INFO  | BlockMiner | Produced and imported block #31 / 0 tx / 0 om / 0 (0.0%) gas / (0x7273626d67d8bcf2ff1984ed86eaf4eef010cc5905849a85faad4492b9c7b3a0) in 0.008s
 2019-06-01 18:39:35.043+08:00 | pool-9-thread-2 | INFO  | BlockMiner | Produced and imported block #32 / 0 tx / 0 om / 0 (0.0%) gas / (0x9b795c0710638cf542b6e776e4bbd3e34564f29270f614f5a87016c41cb2d71b) in 0.017s
 2019-06-01 18:39:35.081+08:00 | pool-9-thread-1 | INFO  | BlockMiner | Produced and imported block #33 / 0 tx / 0 om / 0 (0.0%) gas / (0x39163684a559e61c1d2aa4b6b0c5ed285df670981e2a68a3d3bde411507c6015) in 0.038s

现在再次打开MetaMask,然后单击右上角的“网络”按钮并选择“Localhost 8545”。MetaMask应该成功连接到本地运行的dev Pantheon节点。

现在我们的Pantheon矿工正在运行,我们现在可以看到我们帐户中的以太(在本地开发网络上)已经增加到124以太并继续增长:

在测试网络上挖矿

MetaMask支持通过JSON-RPC连接到任何以太坊网络。在“网络”标签中,您可以从五个不同的公共以太坊网络中进行选择,包括Mainnet,Robsten,Kovan,Rinkeby和Goerli。请注意,在MetaMask中,您还可以使用“自定义RPC”选项连接到不在“网络”下拉列表中的任何其他以太坊网络。Mainnet当然是真正的公共以太坊网络,它使用真正的以太坊,允许任何人成为矿工并使用工作证明共识协议(类似于比特币)。Ropsten是与mainnet最相似的测试网络,也允许任何人成为矿工并使用工作证明共识协议。Kovan,Rinkeby和Goerli是使用称为权威证明的共识协议的测试网络,该协议不支持挖矿。

在Ropsten网络上运行Pantheon矿工

现在让我们设置Pantheon在Ropsten公共测试网上挖以太坊。为此,请运行以下命令:

pantheon --network=ropsten  --rpc-http-cors-origins="all" --rpc-http-enabled --miner-enabled --miner-coinbase <account> --data-path=<blockchain-data-dir>

不要忘记使用’data-path’参数设置区块链数据的目录。如果您忘记设置数据目录,Pantheon将使用默认目录,该目录可能已包含来自另一个网络(在我的主题网络中)的区块链数据,在这种情况下,Pantheon将退出并显示错误。我还使用’rpc-http-enabled’参数打开了JSON-RPC http端点,因此我们可以监视节点的状态。启用后,RPC端点将侦听并且仅允许端口8545上的localhost连接。如果我们想使用MetaMask连接到本地运行的Pantheon节点,我们还需要设置’rpc-http-cors-origins’参数。

$pantheon --network=ropsten  --rpc-http-cors-origins="all" --rpc-http-enabled --miner-enabled --miner-coinbase 0x04fCE695a0aa69C3e9943A0c3e6667449e7D5fDa --data-path=/blockchain-data/ropsten
 2019-06-01 22:53:19.837+08:00 | main | INFO  | StaticNodesParser | StaticNodes file /blockchain-data/ropsten/static-nodes.json does not exist, no static connections will be created.
 2019-06-01 22:53:19.839+08:00 | main | INFO  | Pantheon | Connecting to 0 static nodes.
 2019-06-01 22:53:20.369+08:00 | main | INFO  | KeyPairUtil | Loaded key 0x57e801e79ffcbf7b457ca1fe53356553f20b9405e001902705a5cfee1f67195f49db454dfee768d2bd1539cad7c6d369f4020b7fff01c5185baa1c4f96a92712 from /blockchain-data/ropsten/key
 2019-06-01 22:53:20.587+08:00 | main | INFO  | ProtocolScheduleBuilder | Protocol schedule created with milestones: [TangerineWhistle: 0, SpuriousDragon: 10, Byzantium: 1700000, Constantinople: 4230000, ConstantinopleFix: 4939394]
 2019-06-01 22:53:20.928+08:00 | nioEventLoopGroup-2-1 | INFO  | NettyP2PNetwork | P2PNetwork started and listening on /0:0:0:0:0:0:0:0:30303
 2019-06-01 22:53:20.951+08:00 | main | INFO  | Runner | Starting Ethereum main loop …
 2019-06-01 22:53:20.951+08:00 | main | INFO  | NetworkRunner | Starting Network.
 2019-06-01 22:53:20.952+08:00 | main | INFO  | PeerDiscoveryAgent | Starting peer discovery agent on host=0.0.0.0, port=30303
 2019-06-01 22:53:20.990+08:00 | vert.x-eventloop-thread-1 | INFO  | VertxPeerDiscoveryAgent | Started peer discovery agent successfully, on effective host=0:0:0:0:0:0:0:0 and port=30303
 2019-06-01 22:53:21.021+08:00 | main | INFO  | NettyP2PNetwork | Enode URL enode://57e801e79ffcbf7b457ca1fe53356553f20b9405e001902705a5cfee1f67195f49db454dfee768d2bd1539cad7c6d369f4020b7fff01c5185baa1c4f96a92712@127.0.0.1:30303
 2019-06-01 22:53:21.024+08:00 | main | INFO  | DefaultSynchronizer | Starting synchronizer.
 2019-06-01 22:53:21.027+08:00 | main | INFO  | WaitForPeersTask | Waiting for 1 peers to connect.
 2019-06-01 22:53:21.030+08:00 | main | INFO  | JsonRpcHttpService | Starting JsonRPC service on 127.0.0.1:8545
 2019-06-01 22:53:21.167+08:00 | vert.x-eventloop-thread-4 | INFO  | JsonRpcHttpService | JsonRPC service started and listening on 127.0.0.1:8545
 2019-06-01 22:53:21.168+08:00 | main | INFO  | Runner | Ethereum main loop is up.
 2019-06-01 22:53:22.670+08:00 | nioEventLoopGroup-3-1 | INFO  | WaitForPeersTask | Finished waiting for peers to connect.
 2019-06-01 22:53:26.258+08:00 | nioEventLoopGroup-3-1 | INFO  | SyncTargetManager | Found common ancestor with peer 0x6332792c4a00e3e4ee… at block 199
 2019-06-01 22:53:26.261+08:00 | nioEventLoopGroup-3-1 | INFO  | AbstractMiningCoordinator | Pausing mining while behind chain head
 2019-06-01 22:53:35.532+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 200 to 399
 2019-06-01 22:53:36.881+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 400 to 599
 2019-06-01 22:53:39.122+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 600 to 799
 2019-06-01 22:53:41.873+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 800 to 999
 2019-06-01 22:53:44.639+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 1000 to 1199
 2019-06-01 22:53:46.998+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 1200 to 1399
 2019-06-01 22:53:49.388+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 1400 to 1599

我们可以看到节点开始运行并开始从网络同步区块链数据,在同步完成之前它不会开始挖矿。在撰写本文时,Ropsten网络有大约5700000个块,这需要很长时间才能完全同步,所以我不会等待这个完成。

监控Pantheon同步状态

我们可以通过使用curl命中RPC eth_syncing方法来监视同步的状态:

$curl -X POST --data '{"jsonrpc":"2.0","method":"eth_syncing","paras":[],"id":1}' localhost:8545
 {
   "jsonrpc" : "2.0",
   "id" : 1,
   "result" : {
     "startingBlock" : "0x17f97",
     "currentBlock" : "0x1a76f",
     "highestBlock" : "0x572693"
   }

在节点完成同步区块链数据后,我们将看到它开始挖矿块,Ropsten网络上我们账户中的以太坊将开始增长。

在主网上挖矿

最后在主网上启动Pantheon挖矿运行以下命令:

pantheon  --rpc-http-cors-origins="all" --rpc-http-enabled --miner-enabled --miner-coinbase 

请记住,Mainnet比Ropsten网络拥有更多的块,并且需要更长的时间来同步区块链。在这种情况下,我没有使用’data-path’参数设置区块链数据目录位置,因此Pantheon会将mainnet块数据存储在默认目录中。和以前一样,我已经将’miner-coinbase’参数设置为我之前使用的相同’Pantheon Miner’以太坊帐户地址。

$pantheon  --rpc-http-cors-origins="all" --rpc-http-enabled --miner-enabled --miner-coinbase 0x04fCE695a0aa69C3e9943A0c3e6667449e7D5fDa
 2019-06-02 00:16:22.793+08:00 | main | INFO  | StaticNodesParser | StaticNodes file /usr/local/Cellar/pantheon/1.1.0/static-nodes.json does not exist, no static connections will be created.
 2019-06-02 00:16:22.795+08:00 | main | INFO  | Pantheon | Connecting to 0 static nodes.
 2019-06-02 00:16:23.323+08:00 | main | INFO  | KeyPairUtil | Loaded key 0xcad384ba9cd24761c10c852d18a4d2b1d562f89a3dbcffed2b307aae168d5abe3cd5d688d2471b2ef41d5e25b20ba578d273c606763c1a4f1eaf40da8cc7ede9 from /usr/local/Cellar/pantheon/1.1.0/key
 2019-06-02 00:16:23.660+08:00 | main | INFO  | ProtocolScheduleBuilder | Protocol schedule created with milestones: [Frontier: 0, Homestead: 1150000, DaoRecoveryInit: 1920000, DaoRecoveryTransition: 1920001, Homestead: 1920010, TangerineWhistle: 2463000, SpuriousDragon: 2675000, Byzantium: 4370000, ConstantinopleFix: 7280000]
 2019-06-02 00:16:24.454+08:00 | nioEventLoopGroup-2-1 | INFO  | NettyP2PNetwork | P2PNetwork started and listening on /0:0:0:0:0:0:0:0:30303
 2019-06-02 00:16:24.484+08:00 | main | INFO  | Runner | Starting Ethereum main loop …
 2019-06-02 00:16:24.485+08:00 | main | INFO  | NetworkRunner | Starting Network.
 2019-06-02 00:16:24.486+08:00 | main | INFO  | PeerDiscoveryAgent | Starting peer discovery agent on host=0.0.0.0, port=30303
 2019-06-02 00:16:24.555+08:00 | vert.x-eventloop-thread-1 | INFO  | VertxPeerDiscoveryAgent | Started peer discovery agent successfully, on effective host=0:0:0:0:0:0:0:0 and port=30303
 2019-06-02 00:16:24.597+08:00 | main | INFO  | NettyP2PNetwork | Enode URL enode://cad384ba9cd24761c10c852d18a4d2b1d562f89a3dbcffed2b307aae168d5abe3cd5d688d2471b2ef41d5e25b20ba578d273c606763c1a4f1eaf40da8cc7ede9@127.0.0.1:30303
 2019-06-02 00:16:24.600+08:00 | main | INFO  | DefaultSynchronizer | Starting synchronizer.
 2019-06-02 00:16:24.604+08:00 | main | INFO  | WaitForPeersTask | Waiting for 1 peers to connect.
 2019-06-02 00:16:24.608+08:00 | main | INFO  | JsonRpcHttpService | Starting JsonRPC service on 127.0.0.1:8545
 2019-06-02 00:16:24.748+08:00 | vert.x-eventloop-thread-4 | INFO  | JsonRpcHttpService | JsonRPC service started and listening on 127.0.0.1:8545
 2019-06-02 00:16:24.749+08:00 | main | INFO  | Runner | Ethereum main loop is up.
 2019-06-02 00:16:30.947+08:00 | nioEventLoopGroup-3-1 | INFO  | WaitForPeersTask | Finished waiting for peers to connect.
 2019-06-02 00:16:45.959+08:00 | EthScheduler-Timer-0 | INFO  | FullSyncTargetManager | No sync target, wait for peers.
 2019-06-02 00:16:50.965+08:00 | EthScheduler-Timer-0 | INFO  | FullSyncTargetManager | No sync target, wait for peers.
 2019-06-02 00:16:54.598+08:00 | vert.x-eventloop-thread-1 | INFO  | PeerDiscoveryController | Peer table refresh triggered by timer expiry
 2019-06-02 00:16:57.032+08:00 | nioEventLoopGroup-3-1 | INFO  | SyncTargetManager | Found common ancestor with peer 0xabf71fd1bbbf6d739b… at block 178800
 2019-06-02 00:16:57.034+08:00 | nioEventLoopGroup-3-1 | INFO  | AbstractMiningCoordinator | Pausing mining while behind chain head
 2019-06-02 00:17:01.904+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 178801 to 179000
 2019-06-02 00:17:03.308+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 179001 to 179200
 2019-06-02 00:17:05.499+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 179201 to 179400
 2019-06-02 00:17:06.722+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 179401 to 179600
 2019-06-02 00:17:08.161+08:00 | EthScheduler-Services-4 | INFO  | ParallelValidateAndImportBodiesTask | Completed importing chain segment 179601 to 179800

使用JSON-RPC监视和配置Pantheon挖矿

您可以使用以下JSON-RPC API方法来监视和配置Pantheon挖矿器。要使用这些方法,您需要设置’rpc-http-apis’Pantheon参数以包含值’miner’和’eth’。如果您忘记执行此操作,将返回“未启用方法”错误消息。

1. miner_start

使用miner_start在Pantheon节点上开始挖矿。这允许我们在已经运行但未挖矿的Pantheon节点上启动矿工:

$curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[],"id":1}' http://127.0.0.1:8545
 {
   "jsonrpc" : "2.0",
   "id" : 1,
   "result" : true
 }

2. minor_stop

使用miner_stop停止Pantheon节点上的挖矿。这允许我们停止已经在运行矿工的Pantheon节点上的矿工:

$curl -X POST --data '{"jsonrpc":"2.0","method":"miner_stop","params":[],"id":1}' http://127.0.0.1:8545
 {
   "jsonrpc" : "2.0",
   "id" : 1,
   "result" : true
 }

3. eth_mining

使用eth_mining确定Pantheon是否正在积极挖矿新块:

$curl -X POST --data '{"jsonrpc":"2.0","method":"eth_mining","params":[],"id":1}' http://127.0.0.1:8545
 {
   "jsonrpc" : "2.0",
   "id" : 1,
   "result" : true
 }

eth_hashrate

使用eth_hashrate获取节点挖矿的每秒哈希数:

$curl -X POST --data '{"jsonrpc":"2.0","method":"eth_hashrate","parms":[],"id":1}' http://127.0.0.1:8545
 {
   "jsonrpc" : "2.0",
   "id" : 1,
   "result" : "0x141"
 }

摘要

这样就可以简要概述如何使用Pantheon。我们使用MetaMask成功创建了一个以太坊帐户,并启动了一个开发Pantheon节点,并启用了挖矿和RPC。之后我们看到我们帐户中的以太使用MetaMask增长,因为我们的开发人员添加了新块。然后,我们运行命令启动矿工并观察数据开始在Ropsten和Mainnet上同步。我还介绍了一些可用于配置和监控Pantheon矿工的JSON-RPC方法。我希望您发现此信息有用。请随时向我发送您的意见或问题,如果您想在Web3 开发工程师上关注我以后的帖子,请不要忘记订阅。

原文:https://kauri.io/article/1016a4a10e5742638a5445d6268bdcdf/v1/mining-with-pantheon

提示:投资有风险,入市需谨慎,本资讯不作为投资理财建议。请理性投资,切实提高风险防范意识;如有发现的违法犯罪线索,可积极向有关部门举报反映。
你可能还喜欢