Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SwimmingTiger/1fde11c8806db921ba4a2f77220509db to your computer and use it in GitHub Desktop.
Save SwimmingTiger/1fde11c8806db921ba4a2f77220509db to your computer and use it in GitHub Desktop.
创建一个低难度的Beam私有测试网络

创建一个低难度的Beam私有测试网络

步骤

  1. 点击右上角的Download ZIP下载该Gist中的相关配置文件。
  2. 下载 beam节点源代码 的Beam源代码。 如果要使用git获取源代码,请检出cold_wallet这个tag。注意某些分支或tag可能由于equihash参数不同,导致GPU Miner无法挖矿。 参考命令:
git clone https://github.com/BeamMW/beam.git
cd beam
git checkout cold_wallet
  1. 打开源代码中的core/block_crypt.cpp,找到Rules::Rules()函数,把840行的
		TreasuryChecksum = {
			0x5d, 0x9b, 0x18, 0x78, 0x9c, 0x02, 0x1a, 0x1e,
			0xfb, 0x83, 0xd9, 0x06, 0xf4, 0xac, 0x7d, 0xce,
			0x99, 0x7d, 0x4a, 0xc5, 0xd4, 0x71, 0xd7, 0xb4,
			0x6f, 0x99, 0x77, 0x6e, 0x7a, 0xbd, 0x2e, 0xc9
		};

		Prehistoric = {
			// BTC Block #556833
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x25, 0x2d, 0x12, 0x33, 0xb4, 0x5d, 0xb2,
			0x39, 0x81, 0x47, 0x67, 0x6e, 0x16, 0x62, 0xf4,
			0x3c, 0x26, 0xa5, 0x26, 0xd2, 0xe2, 0x20, 0x63,
		};

修改为

		TreasuryChecksum = Zero;
		Prehistoric = Zero;

因为使用的是MainNet的分支,初始挖矿难度较高,需要打开core/block_crypt.h,然后把107行的

			Difficulty Difficulty0	= Difficulty(22 << Difficulty::s_MantissaBits); // 2^22 = 4,194,304. For GPUs producing 7 sol/sec this is roughly equivalent to 10K GPUs.

修改为

			Difficulty Difficulty0	= Difficulty(3 << Difficulty::s_MantissaBits); // 2^3 = 8. For GPUs producing 7 sol/sec this is roughly equivalent to 1 GPU.
  1. 编译该项目(构建说明),参考的构建参数(Ubuntu 18.04):
# 创建构建文件夹
mkdir build && cd build
# 创建makefile
cmake -DBEAM_NO_QT_UI_WALLET=ON ..
# 构建
make -j
  1. 进入构建目录(build/)中的beam子目录,你可以看到构建好的beam-node就在这里。把在第一步中下载的ZIP里的配置文件 beam-node.cfgstratum.api.keysstratum.crtstratum.key都放在该目录,然后使用以下命令启动节点:
./beam-node
  1. 可以用GPU Miner连接节点进行挖矿了。 (GPU Miner 下载地址,其中的*-opencl-miner.*就是)。 参考参数:
beamMiner --server 127.0.0.1:3333 --key 12345678
  1. 即使不连接GPU Miner,节点也会从区块1开始通过CPU进行挖矿,不过速度可能较慢。你可以修改配置文件中的mining_threads来启用更多挖矿线程。 正常运行的节点日志参考:
I 2018-12-31.21:35:59.208 Rules signature: a865248b891a3b22
I 2018-12-31.21:35:59.343 starting a node on 8200 port...
I 2018-12-31.21:35:59.405 Node ID=20b95c72db61b27c
I 2018-12-31.21:35:59.405 Initial Tip: 0-0000000000000000
I 2018-12-31.21:35:59.406 Sync mode
I 2018-12-31.21:35:59.406 Searching for the best peer...
I 2018-12-31.21:35:59.427 stratum server listens to 0.0.0.0:3333
I 2018-12-31.21:35:59.428 GenerateNewBlock: size of block = 294; amount of tx = 0
I 2018-12-31.21:35:59.428 Block generated: Height=1, Fee=0, Difficulty=02-000000(4), Size=294
I 2018-12-31.21:35:59.428 New job for external miner
I 2018-12-31.21:35:59.428 stratum server new job 1 will be sent to 0 connected peers
I 2018-12-31.21:35:59.428 Mining nonce = a834d1bed1dc5df6
D 2018-12-31.21:36:33.120 stratum server +peer 127.0.0.1:3492
V 2018-12-31.21:36:33.125 got {"method":"login", "api_key":"12345678", "id":"login","jsonrpc":"2.0"}
V 2018-12-31.21:36:33.720 got {"method" : "solution", "id": "1", "nonce": "e207f872d58f120b", "output": "1dc4ae5dd850fa32ef3316042735113cdb25be2b2a046b2acaa237e1076b66fee6204d2339a3ae742d4f3d4efb6a473eeb58e85620a5befb4d93854d8bf6074a464670ffac6fbab57c73ff09280f4bdf592129f5b74ed85224a19b6908daae110e878a34ff2cfb2b", "jsonrpc":"2.0" }
D 2018-12-31.21:36:33.721  sol.nonce=e207f872d58f120b sol.output=1dc4ae5dd850fa32ef3316042735113cdb25be2b2a046b2acaa237e1076b66fee6204d2339a3ae742d4f3d4efb6a473eeb58e85620a5befb4d93854d8bf6074a464670ffac6fbab57c73ff09280f4bdf592129f5b74ed85224a19b6908daae110e878a34ff2cfb2b
I 2018-12-31.21:36:33.721 stratum server solution to 1 from 127.0.0.1:3492
I 2018-12-31.21:36:33.722 New block mined: 1-e6820193db6b0da2
I 2018-12-31.21:36:33.722 1-e6820193db6b0da2 Header accepted
I 2018-12-31.21:36:33.723 1-e6820193db6b0da2 Block received
I 2018-12-31.21:36:33.724 1-e6820193db6b0da2 Block interpreted. Fwd=1
I 2018-12-31.21:36:33.724 My Tip: 1-e6820193db6b0da2, Work = 4
I 2018-12-31.21:36:33.760 GenerateNewBlock: size of block = 294; amount of tx = 0
I 2018-12-31.21:36:33.760 Block generated: Height=2, Fee=0, Difficulty=02-000000(4), Size=294
I 2018-12-31.21:36:33.760 New job for external miner
I 2018-12-31.21:36:33.760 stratum server new job 2 will be sent to 1 connected peers
  1. 挖矿的初始难度为4,后续难度会随着算力的增减而调整。

疑难解答

如何手动测试与node的连接(类似telnet localhost 3333

可以使用openssl命令:

openssl s_client -connect localhost:3333

然后就可以像telnet那样使用了。 例如:

openssl s_client -connect localhost:3333
{"method":"login","api_key":"12345678","id":"login","jsonrpc":"2.0"}
{"difficulty":104080254,"id":"1","input":"736705edb35b6c6e9bfafc4349adf236ac479d271b222927dd9428d8c4af3925","jsonrpc":"2.0","method":"job"}

无法启动节点,错误提示为Data configuration is incompatible

例如:

I 2018-12-31.21:38:51.481 Rules signature: c322cb3e12d24375
I 2018-12-31.21:38:51.602 starting a node on 8200 port...
I 2018-12-31.21:38:51.603 Node stopping...
I 2018-12-31.21:38:51.603 Node stopped
E 2018-12-31.21:38:51.603 Data configuration is incompatible: a865248b891a3b22. Current configuration: c322cb3e12d24375

原因:

区块链数据库(node.db)与节点所在的区块链参数不兼容。 因为我们修改了区块链参数TreasuryChecksum,如果你在修改前启动过节点,产生了数据文件,就会出现该问题。

解决方法:

删除节点目录下的node.db文件。

无法通过GPU Miner挖矿,错误提示为invalid solution from external miner

例如:

V 2018-12-31.21:41:03.797 got {"method" : "solution", "id": "2", "nonce": "efb5a163191948f9", "output": "070f980e090eb8c21dbbf4578c8251fde326e9d89ab14f92981f358a61797ea669ec8bcec151f64ccdbafd21e4a9b837af4dfce52ce2b294d46c7ad6b2632a8b705198573c5adbeb7f037753d19c3047906a5efe749dcf954b597f5f76bcd929c65a0cb75abf06a2", "jsonrpc":"2.0" }
D 2018-12-31.21:41:03.797  sol.nonce=efb5a163191948f9 sol.output=070f980e090eb8c21dbbf4578c8251fde326e9d89ab14f92981f358a61797ea669ec8bcec151f64ccdbafd21e4a9b837af4dfce52ce2b294d46c7ad6b2632a8b705198573c5adbeb7f037753d19c3047906a5efe749dcf954b597f5f76bcd929c65a0cb75abf06a2
I 2018-12-31.21:41:03.798 stratum server solution to 2 from 127.0.0.1:3573
I 2018-12-31.21:41:03.798 invalid solution from external miner

原因:

testnet4_release (8bf66967e6af7f33d97479bfa3a7ffdbc9d9e046) 这个Release修改了equihash参数,改为了N = 150, K = 5。其他分支(比如master)可能不是这个参数,导致与GPU Miner的挖矿结果对不上。

解决方法:

下载 testnet4_release 的Beam源代码。 如果你通过git获得源代码,请 git checkout testnet4_release

无法通过GPU Miner挖矿,连接服务器后没有反应

原因:

官方的GPU Miner似乎不支持localhost这个域名,需要改成具体的IP地址。

解决方法:

使用--server 127.0.0.1:端口代替--server localhost:端口

配置文件安全性说明

为了方便使用,配置文件中内置了挖矿奖励所用的私钥(key_mine)和对应的密码pass。 这意味着,任何看过该Gist的人都有能力转走该私钥在公有区块链中的数字资产。

不过,由于我们要创建的是一个私有测试网络,里面的币没有任何价值,并且其他人也不能访问我们的节点,所以没有安全性担忧。

但是,我们在任何情况下都不应该把该配置文件中的公钥、私钥及密码(key_minekey_ownerpass)用于生产环境或Beam主链。

本Gist及其作者不为任何丢币损失负责。

################################################################################
# General options:
################################################################################
# port to start server on
port=8200
# log level [info|debug|verbose]
log_level=verbose
# file log level [info|debug|verbose]
file_log_level=verbose
################################################################################
# Node options:
################################################################################
# node storage path
# storage=node.db
# directory for compressed history
# history_dir=
# temp directory for compressed history, must be on the same volume
# temp_dir=
# number of mining threads(there is no mining if 0)
mining_threads=1
# nodes to connect to
#peer = 127.0.0.1:8100
#peer = 54.153.111.172:8100
# port to start stratum server on
stratum_port=3333
# path to stratum server api keys file, and tls certificate and private key
stratum_secrets_path=.
# Specify the blockchain height to import. The compressed history is asumed to be downloaded the the specified directory
# import=0
# Enforce re-synchronization (soft reset)
# resync=0
# Induce crash (test proper handling)
# crash=0
# Owner viewer key
key_owner=B9mVV96Rwf6+TssMpUPdOyciTSfd5Mp2nnK0NK3KC3bJM0YQ2AUgtzCoztN1ZZEcyBiRUnT0/9bJ44OySq2N89zSRGuy6tpbxGgfkMK9XaZiSvkKO5yDCKFjQ4N7HPdMWpFdro7OtFaGVg3B
# Standalone miner key
key_mine=m5H9ab0cy/ad2Mx6AUyhw8znvkLXjLg/fXCN6KQFgHCCPwK0gBRS9A4MrzFST4hoBnT7jTeWMewBKA3cIzMKkiR2qxo+IvLn0Vk=
# password for keys
pass=7b6MAJUiRo8FisBgKfqiUDum
#FakePoW=1
-----BEGIN CERTIFICATE-----
MIIDYDCCAkigAwIBAgIJAO8aCxWledf8MA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
aWRnaXRzIFB0eSBMdGQwHhcNMTgxMDE1MTM0ODMxWhcNMTkxMDE1MTM0ODMxWjBF
MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA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pXBUcwKiqDnLMK4xQYEQNqv7Ns3Ys7i+how/ucIvUC7K
jkdObrve8hNG3O3RPAZwnel+L5TGCnWIBOEUD7zjj/TpP7CzL8bUMq+WVqMCgYB+
jtkwchApPTizytj1d0SMKZVyO4A1Z5UVW2Vzp5QmgEHY7b4sN56e7ufFaKd1hN4S
mYQPXvG0H+LzpX4CzpMpAHg6DicoXUDyGq4mLOlI2tRlmdR55jBU2NuxdxaKyUlk
3fd5Xi2aTjbErD1Ebaw0L8v10gQZEXZDpyw4887NIQKBgFrFGqf1/50OBMezNGlv
1wgLemjrZB19cV1b+sheiRABGx6d2Ly4/ygGz49RP0UqXKOTv/AKJEv//lPJ60nL
jykZV3Upu6NHHNfbqiyvV5HOqm9bXJJG17opXZO9r0DraaR18Kjz5HglTuiqeQvq
nDqdnbiVMrqSbel8EbRkgGZe
-----END PRIVATE KEY-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment