兄弟连区块链教程btcpool矿池源码分析BlockMaker模块解析

btcpool矿池-BlockMaker模块解析

核心机制总结

  • blkmaker可以连多个bitcoind节点
  • blkmaker监听和接收4类消息:RAWGBT、STRATUM_JOB、SOLVED_SHARE和NMC_SOLVED_SHARE
  • 监听RAWGBT目的为获取gbtHash/交易列表,用于构建Block,gbtHash和vtxs写入rawGbtMap_
    ??* rawGbtMap_保存最近100条gbtHash/vtxs对
  • 监听STRATUMJOB目的为获取jobId/gbtHash,jobId和gbtHash写入jobId2GbtHash
    ??* jobId2GbtHash保存最近120条jobId/gbtHash对
  • 监听SOLVED_SHARE目的为获取BlockHeader和coinbaseTx
    ??* BlockHeader+coinbaseTx+vtxs构造Block
  • 构造好的Block会提交连接的所有bitcoind节点
  • 构造好的Block入库,入库字段包括:
    ?? puid、worker_id、worker_full_name、job_id、height、hash
    ??
    rewards(即coinbaseValue)、size(即blksize)、prev_hash、bits、version、created_at
    ??* created_at为入库时间非爆块时间

BlockMaker命令使用

BlockMaker用于监听kafka获取新的比特币区块和域名币区块,同时监听kafka获取Gbt消息和Job消息以构造交易列表,最后拼装完整区块提交给比特币节点。

blkmaker -c blkmaker.cfg -l log_dir
#-c指定blkmaker配置文件
#-l指定日志目录

blkmaker.cfg配置文件

//比特币节点
bitcoinds = (
{
rpc_addr = ""; //rpc地址
rpc_userpwd = ""; //rpc权限,格式如username:password
}
);

//kafka集群
kafka = {
brokers = "1.1.1.1:9092,2.2.2.2:9092,3.3.3.3:9092";
};

//mysql配置,用于存储已发现的块
pooldb = {
host = "";
port = 3306;
username = "dbusername";
password = "dbpassword";
dbname = "";
};

found_blocks数据库结构

-- MySQL dump 10.13? Distrib 5.7.20, for Linux (x86_64)

-- Host: 172.17.228.162? ? Database: bpool_local_db



-- Server version 5.7.18-16-log

/!40101 SET @[email protected]@CHARACTER_SET_CLIENT /;
/!40101 SET @[email protected]@CHARACTER_SET_RESULTS /;
/!40101 SET @[email protected]@COLLATION_CONNECTION /;
/!40101 SET NAMES utf8 /;
/!40103 SET @[email protected]@TIME_ZONE /;
/!40103 SET TIME_ZONE=‘+00:00‘ /;
/!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 /;
/!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 /;
/!40101 SET @[email protected]@SQL_MODE, SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO‘ /;
/!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 /;

--
-- Table structure for table found_blocks

DROP TABLE IF EXISTS found_blocks;
/!40101 SET @saved_cs_client? ? ?= @@character_set_client /;
/!40101 SET character_set_client = utf8 /;
CREATE TABLE found_blocks (
? id int(11) NOT NULL AUTO_INCREMENT,
? puid int(11) NOT NULL,
? worker_id bigint(20) NOT NULL,
? worker_full_name varchar(50) NOT NULL,
? job_id bigint(20) unsigned NOT NULL,
? height int(11) NOT NULL,
? is_orphaned tinyint(4) NOT NULL DEFAULT ‘0‘,
? hash char(64) NOT NULL,
? rewards bigint(20) NOT NULL,
? size int(11) NOT NULL,
? prev_hash char(64) NOT NULL,
? bits int(10) unsigned NOT NULL,
? version int(11) NOT NULL,
? created_at datetime DEFAULT NULL,
? PRIMARY KEY (id),
? UNIQUE KEY hash (hash),
? KEY height (height)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/!40101 SET character_set_client = @saved_cs_client /;

--
-- Table structure for table found_nmc_blocks

DROP TABLE IF EXISTS found_nmc_blocks;
/!40101 SET @saved_cs_client? ? ?= @@character_set_client /;
/!40101 SET character_set_client = utf8 /;
CREATE TABLE found_nmc_blocks (
? id int(11) NOT NULL AUTO_INCREMENT,
? bitcoin_block_hash char(64) NOT NULL,
? aux_block_hash char(64) NOT NULL,
? aux_pow text NOT NULL,
? is_orphaned tinyint(4) NOT NULL DEFAULT ‘0‘,
? created_at datetime NOT NULL,
? PRIMARY KEY (id),
? UNIQUE KEY aux_block_hash (aux_block_hash)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/!40101 SET character_set_client = @saved_cs_client /;

--
-- Table structure for table mining_workers

DROP TABLE IF EXISTS mining_workers;
/!40101 SET @saved_cs_client? ? ?= @@character_set_client /;
/!40101 SET character_set_client = utf8 /;
CREATE TABLE mining_workers (
? worker_id bigint(20) NOT NULL,
? puid int(11) NOT NULL,
? group_id int(11) NOT NULL,
? worker_name varchar(20) DEFAULT NULL,
? accept_1m bigint(20) NOT NULL DEFAULT ‘0‘,
? accept_5m bigint(20) NOT NULL DEFAULT ‘0‘,
? accept_15m bigint(20) NOT NULL DEFAULT ‘0‘,
? reject_15m bigint(20) NOT NULL DEFAULT ‘0‘,
? accept_1h bigint(20) NOT NULL DEFAULT ‘0‘,
? reject_1h bigint(20) NOT NULL DEFAULT ‘0‘,
? accept_count int(11) NOT NULL DEFAULT ‘0‘,
? last_share_ip char(16) NOT NULL DEFAULT ‘0.0.0.0‘,
? last_share_time timestamp NOT NULL DEFAULT ‘1970-01-01 00:00:01‘,
? miner_agent varchar(30) DEFAULT NULL,
? created_at timestamp NULL DEFAULT NULL,
? updated_at timestamp NULL DEFAULT NULL,
? UNIQUE KEY puid_worker_id (puid,worker_id),
? KEY puid_group_id (puid,group_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/!40101 SET character_set_client = @saved_cs_client /;

--
-- Table structure for table mining_workers_tmp

DROP TABLE IF EXISTS mining_workers_tmp;
/!40101 SET @saved_cs_client? ? ?= @@character_set_client /;
/!40101 SET character_set_client = utf8 /;
CREATE TABLE mining_workers_tmp (
? worker_id bigint(20) NOT NULL,
? puid int(11) NOT NULL,
? group_id int(11) NOT NULL,
? worker_name varchar(20) DEFAULT NULL,
? accept_1m bigint(20) NOT NULL DEFAULT ‘0‘,
? accept_5m bigint(20) NOT NULL DEFAULT ‘0‘,
? accept_15m bigint(20) NOT NULL DEFAULT ‘0‘,
? reject_15m bigint(20) NOT NULL DEFAULT ‘0‘,
? accept_1h bigint(20) NOT NULL DEFAULT ‘0‘,
? reject_1h bigint(20) NOT NULL DEFAULT ‘0‘,
? accept_count int(11) NOT NULL DEFAULT ‘0‘,
? last_share_ip char(16) NOT NULL DEFAULT ‘0.0.0.0‘,
? last_share_time timestamp NOT NULL DEFAULT ‘1970-01-01 00:00:01‘,
? miner_agent varchar(30) DEFAULT NULL,
? created_at timestamp NULL DEFAULT NULL,
? updated_at timestamp NULL DEFAULT NULL,
? UNIQUE KEY puid_worker_id (puid,worker_id),
? KEY puid_group_id (puid,group_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/!40101 SET character_set_client = @saved_cs_client /;
/!40103 SET [email protected]_TIME_ZONE /;

/!40101 SET [email protected]_SQL_MODE /;
/!40014 SET [email protected]_FOREIGN_KEY_CHECKS /;
/!40014 SET [email protected]_UNIQUE_CHECKS /;
/!40101 SET [email protected]_CHARACTER_SET_CLIENT /;
/!40101 SET [email protected]_CHARACTER_SET_RESULTS /;
/!40101 SET [email protected]_COLLATION_CONNECTION /;
/!40111 SET [email protected]_SQL_NOTES /;

-- Dump completed on 2018-02-22 14:02:44

CREATE TABLE `found_blocks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`puid` int(11) NOT NULL,
`worker_id` bigint(20) NOT NULL,
`worker_full_name` varchar(50) NOT NULL,
`job_id` bigint(20) unsigned NOT NULL,
`height` int(11) NOT NULL,
`is_orphaned` tinyint(4) NOT NULL DEFAULT ‘0‘,
`hash` char(64) NOT NULL,
`rewards` bigint(20) NOT NULL,
`size` int(11) NOT NULL,
`prev_hash` char(64) NOT NULL,
`bits` int(10) unsigned NOT NULL,
`version` int(11) NOT NULL,
`created_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `hash` (`hash`),
KEY `height` (`height`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

原文地址:http://blog.51cto.com/12918475/2300756

时间: 2024-07-29 19:26:08

兄弟连区块链教程btcpool矿池源码分析BlockMaker模块解析的相关文章

区块链教程btcpool矿池源码分析StratumServer模块解析

兄弟连区块链教程btcpool矿池源码分析StratumServer模块解析 核心机制总结 接收的job延迟超过60秒将丢弃 如果job中prevHash与本地job中prevHash不同,即为已产生新块,job中isClean状态将置为true????* true即要求矿机立即切换job 三种情况下将向矿机下发新job:???? 收到新高度的job???? 过去一个job为新高度且为空块job,且最新job为非空块job????* 达到预定的时间间隔30秒 最近一次下发job的时间将写入文件(

兄弟连区块链教程btcpool矿池源码分析JobMaker模块解析

核心机制总结 同时监听kafka KAFKA_TOPIC_RAWGBT和KAFKA_TOPIC_NMC_AUXBLOCK,以支持混合挖矿 接收的Gbt消息,如果与本地时间延迟超过60秒将丢弃,如果延迟超过3秒将打印log 可用的Gbt消息,将以gbtTime+isEmptyBlock+height来构造key写入本地Map,另gbtHash也会写入本地队列 本地gbtHash队列仅保存最近20条,本地gbtMap中Gbt消息有效期:非空Gbt有效期90秒,空Gbt有效期15秒,过期将清除??*

兄弟连区块链教程open-ethereum-pool矿池源码分析unlocker模块

兄弟连区块链教程open-ethereum-pool以太坊矿池源码分析unlocker模块open-ethereum-pool以太坊矿池-unlocker模块 unlocker模块配置 json"unlocker": {????"enabled": false,????"poolFee": 1.0,????"poolFeeAddress": "",????"donate": true,?

兄弟连区块链教程btcpool矿池源码分析核心机制总结及优化思考

btcpool矿池-核心机制总结及优化思考 核心机制总结 ①gbtmaker 监听Bitcoind ZMQ中BITCOIND_ZMQ_HASHBLOCK消息,一有新块产生,将立即向kafka发送新Gbt 另默认每5秒间隔(可从配置文件中指定)主动RPC请求Bitcoind,获取Gbt发送给kafka Gbt消息大小约2M,含交易列表 ②jobmaker 同时监听kafka KAFKA_TOPIC_RAWGBT和KAFKA_TOPIC_NMC_AUXBLOCK,以支持混合挖矿 接收的Gbt消息,如

兄弟连区块链教程open-ethereum-pool矿池源码分析policy模块

open-ethereum-pooleth矿池-policy模块 PolicyServer定义 type PolicyServer struct { sync.RWMutex statsMu sync.Mutex config *Config stats map[string]*Stats banChannel chan string startedAt int64 grace int64 timeout int64 blacklist []string whitelist []string s

兄弟连区块链教程open-ethereum-pool矿池源码分析payouts模块

open-ethereum-pooleth矿池-payouts模块 PayoutsProcessor定义 type PayoutsProcessor struct { config *PayoutsConfig backend *storage.RedisClient rpc *rpc.RPCClient halt bool lastFail error } GetPendingPayments原理 func (r *RedisClient) GetPendingPayments() []*Pe

兄弟连区块链教程open-ethereum-pool矿池源码分析环境安装

安装Geth //安装parity cd /tmp/ wget d1h4xl4cr1h0mo.cloudfront.net/v1.8.11/x86_64-unknown-linux-gnu/parity_1.8.11_ubuntu_amd64.deb dpkg -i parity_1.8.11_ubuntu_amd64.deb //安装screen apt-get update apt-get -y install screen //启动parity screen parity --base-p

兄弟连区块链教程open-ethereum-pool矿池源码分析API分析

ApiServer相关定义 type ApiConfig struct { Enabled bool `json:"enabled"` Listen string `json:"listen"` StatsCollectInterval string `json:"statsCollectInterval"` HashrateWindow string `json:"hashrateWindow"` HashrateLarge

区块链教程open-ethereum-pool矿池源码分析main入口

兄弟连区块链教程open-ethereum-pool矿池源码分析main入口,2018年下半年,区块链行业正逐渐褪去发展之初的浮躁.回归理性,表面上看相关人才需求与身价似乎正在回落.但事实上,正是初期泡沫的渐退,让人们更多的关注点放在了区块链真正的技术之上. open-ethereum-pool以太坊矿池-main入口 命令行启动 ./build/bin/open-ethereum-pool config.json config.json配置文件 { ????"threads": 2,