Geth矿池搭建教程

Geth矿池搭建教程

项目地址

使用项目:Open Ethereum Mining Pool

依赖软件

1
2
3
4
5
//go >= 1.9
//geth
//redis-server >= 2.8.0
//nodejs >= 4 LTS
//nginx

安装redis

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#先试试yum能否安装,安装成功就跳转到设置后台自启动那
yum install redis

#查看是否安装成功
redis-server -v

> Redis server v=5.0.5 sha=00000000:0 malloc=libc bits=64 build=68e07f63dcbc3d2c

#启动服务(不要执行)
#systemctl  start  redis.service

#获取源码包
wget http://download.redis.io/releases/redis-5.0.5.tar.gz

#解压
tar -zxvf redis-5.0.5.tar.gz

#安装gcc,遇到选择,输入y即可
yum install gcc

#进入目录
cd redis-5.0.5

#编译安装
make MALLOC=libc
cd src && make install

#查看是否安装成功
redis-server -v

#后台运行
cd ..
vi redis.conf
修改第136行:daemonize no为yes

#启动服务
redis-server ~/redis-5.0.5/redis.conf

#开机自启动
#在etc创建目录
mkdir /etc/redis
#将配置复制过去,命名为6379.conf
cp redis.conf /etc/redis/6379.conf
#将启动脚本复制过去
cp utils/redis_init_script /etc/init.d/redisd
#设置redis开机自启动
cd /etc/init.d

#执行自启命令
chkconfig redisd on

安装Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
#先试试yum能否安装
yum install nginx

#如果不能安装,设置源
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

#再执行安装
yum install -y nginx

#查看是否安装成功
nginx -v

> nginx version: nginx/1.16.1

搭建矿池

克隆源码

1
git clone https://github.com/XXQKLPro/open-ethereum-pool.git

编译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd open-ethereum-pool
make
#建议编译不报错后,参照注5、注6修改手续费和奖励


#编译技巧
cd open-ethereum-pool
go mod init
make

#报错 undefined: "github.com/ethereum/go-ethereum/crypto".Sha3Hash
#解决办法,注释掉代码
vi ./build/_workspace/pkg/mod/github.com/ethereum/ethash@v0.0.0-20170407112842-f5f0a8b19625/ethash.go

// "github.com/ethereum/go-ethereum/crypto" #44行
// sh = crypto.Sha3Hash(sh[:]) #436行

#重新编译即可
make
  • 注:编译时应该会有一些包错误的提示,自行查看错误,使用open-ethereum-pool运行依赖包.zip替换相应的依赖

创建配置

1
cp config.example.json config.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
vi config.json

{
//设置成服务器CPU的核心数
"threads": 2,
// redis存储的key前缀
"coin": "eth",
// 矿池名
"name": "main",

"proxy": {
"enabled": true,
// http挖矿的端口
"listen": "0.0.0.0:8888",
// 运行旷工挖矿的请求大小
"limitHeadersSize": 1024,
"limitBodySize": 256,
"behindReverseProxy": false,
"stratum": {
"enabled": true,
// socket挖矿的端口
"listen": "0.0.0.0:8008",
"timeout": "120s",
"maxConn": 8192
},

// 从geth获取新交易的间隔
"blockRefreshInterval": "120ms",
"stateUpdateInterval": "3s",
// 挖矿的难度值,当达到该难度时,才分配给旷工
"difficulty": 2000000000,
"healthCheck": true,
"maxFails": 100,
"hashrateExpiration": "3h",
"policy": {
"workers": 8,
"resetInterval": "60m",
"refreshInterval": "1m",
"banning": {
"enabled": false,
"ipset": "blacklist",
"timeout": 1800,
"invalidPercent": 30,
"checkThreshold": 30,
"malformedLimit": 5
},
"limits": {
"enabled": false,
"limit": 30,
"grace": "5m",
"limitJump": 10
}
}
},
"api": {
"enabled": true,
"listen": "0.0.0.0:8080",
"statsCollectInterval": "5s",
"purgeInterval": "10m",
"hashrateWindow": "30m",
"hashrateLargeWindow": "3h",
"luckWindow": [64, 128, 256],
"payments": 50,
"blocks": 50,
"purgeOnly": false
},
"upstreamCheckInterval": "5s",
"upstream": [
{
"name": "main",
"url": "http://127.0.0.1:8545",
"timeout": "10s"
},
{
"name": "backup",
"url": "http://127.0.0.2:8545",
"timeout": "10s"
}
],
"redis": {
"endpoint": "127.0.0.1:6379",
"poolSize": 10,
"database": 0,
"password": ""
},

// 开发者奖励设置
"unlocker": {
// 开关
"enabled": false,
// 给开发者的手续费百分比
"poolFee": 1.0,
// 开发者钱包地址
"poolFeeAddress": "",
// Donate 10% from pool fees to developers
"donate": true,
// 每挖到120个块发一次手续费
"depth": 120,
// Simply don't touch this option
"immatureDepth": 20,
// Keep mined transaction fees as pool fees
"keepTxFees": false,
// Run unlocker in this interval
"interval": "10m",
// Geth instance node rpc endpoint for unlocking blocks
"daemon": "http://127.0.0.1:8545",
// Rise error if can't reach geth in this amount of time
"timeout": "10s"
},

// 矿池旷工奖励设置
"payouts": {
// 关闭奖励分配
"enabled": false,
// 有25个旷工在矿池挖矿时,才分配奖励
"requirePeers": 25,
// 分配奖励的间隔
"interval": "12h",
// Geth instance node rpc endpoint for payouts processing
"daemon": "http://127.0.0.1:8545",
// Rise error if can't reach geth in this amount of time
"timeout": "10s",
// 矿池的钱包地址
"address": "0x0",
// Let geth to determine gas and gasPrice
"autoGas": true,
// Gas amount and price for payout tx (advanced users only)
"gas": "21000",
"gasPrice": "50000000000",
// Send payment only if miner's balance is >= 0.5 Ether
"threshold": 500000000,
// Perform BGSAVE on Redis after successful payouts session
"bgsave": false
}
}

启动矿池

1
./build/bin/open-ethereum-pool config.json
  • 注1:如果链上没有人挖矿,会报错,不用理

  • 注2:需要开启redis,否则也会报错

  • 1
    redis-server ~/redis-5.0.5/redis.conf

搭建前端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#建议:查看注3:问题处理,替换整个WWW目录

#进入前端目录
cd www

#安装依赖
npm install -g ember-cli@2.9.1
npm install -g bower
npm install
bower install --allow-root

#将example.net修改成本机的ip
vi config/environment.js

ApiUrl: '//192.168.105.215/',
HttpHost: 'http://192.168.105.215',
StratumHost: '192.168.105.215',

#修改查询区块链接
vi app/templates/blocks/block.hbs
#将4处 https://etherscan.io 修改成 区块链浏览器 的地址,例如:
http://192.168.105.215:3000
#再修改1处
vi app/templates/blocks/pending.hbs
#修改查询交易链接,修改1处
vi app/templates/account/payouts.hbs
#再修改2处
vi app/templates/payments.hbs

#编译即可
./build.sh

修改nginx配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
vi /etc/nginx/nginx.conf

#在http中添加
upstream api {
server 127.0.0.1:8080;
}

#在server中添加
root /work/gopro/src/github.com/sammy007/open-ethereum-pool/www/dist;
index index.html;
location /api {
proxy_pass http://api;
}

#重启nginx
service nginx restart

#访问地址:http://192.168.105.215/
#API地址
http://192.168.105.215/api/stats
http://192.168.105.215/api/miners
http://192.168.105.215/api/blocks
http://192.168.105.215/api/payments
http://192.168.105.215/api/accounts/{login:0x[0-9a-fA-F]{40}}

注1:environment.js配置参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module.exports = function(environment) {
var ENV = {
modulePrefix: 'open-ethereum-pool',
environment: environment,
rootURL: '/',
locationType: 'hash',
EmberENV: {
FEATURES:
}
},

APP: {
// API host and port
ApiUrl: '//192.168.105.215/',

// HTTP mining endpoint
HttpHost: 'http://192.168.105.215',
HttpPort: 8888,

// Stratum mining endpoint
StratumHost: '192.168.105.215',
StratumPort: 8008,

PoolFee: '1%',
PayoutThreshold: '0.5 Ether',
BlockTime: 14.4
}
};
if (environment === 'development') {
ENV.APP.ApiUrl = 'http://localhost:8080/'
}
if (environment === 'test') {
ENV.locationType = 'none';
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;
ENV.APP.rootElement = '#ember-testing';
}
if (environment === 'production') {
}
return ENV;
};

注2:nginx配置参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;

server {
listen 80;
server_name 192.168.105.215;
root /work/gopro/src/github.com/sammy007/open-ethereum-pool/www/dist;
index index.html;
include /etc/nginx/default.d/*.conf;

location / {
}

location /api {
proxy_pass http://api;
}
}
upstream api {
server 127.0.0.1:8080;
}
}

注3:问题处理

  • 前端console报format/cache错误,替换intl-format-cache2.1.0版本,参考链接
  • 建议直接使用包含依赖的www2.tar.gz替换整个www目录,修改environment.js后运行./build.sh即可

注4:CPU无法挖矿

注5:修改矿池开发者的手续费

1
2
3
4
5
6
7
8
vi \open-ethereum-pool\payouts\unlocker.go

//修改下面的数据
const donationFee = 10.0
const donationAccount = "0xb85150eb365e7df0941f0cf08235f987ba91506a"
//修改为
const donationFee = 0
const donationAccount = "" //改成空可能会在下面的变量map赋值中引发错误,建议修改上面的手续费为0即可

注6:修改矿池奖励计算

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
vi \open-ethereum-pool\payouts\unlocker.go

//矿池在此定义了拜占庭分叉的高度
const byzantiumHardForkHeight = 4370000

//原始奖励
var homesteadReward = math.MustParseBig256("5000000000000000000")
//拜占庭分叉奖励
var byzantiumReward = math.MustParseBig256("3000000000000000000")

//修改var homesteadReward 为:2ETC 跟目前的奖励一致
var homesteadReward = math.MustParseBig256("2000000000000000000")

//注释掉此函数中的拜占庭高度判断
func getConstReward(height int64) *big.Int {
//if height >= byzantiumHardForkHeight {
//return new(big.Int).Set(byzantiumReward)
//}
return new(big.Int).Set(homesteadReward)
}
-------------------本文结束 感谢您的阅读-------------------
0%