内容简介:* rawGbtMap_保存最近100条gbtHash/vtxs对* jobId2GbtHash_保存最近120条jobId_/gbtHash对* BlockHeader+coinbaseTx+vtxs构造Block
btcpool矿池-BlockMaker模块解析
核心机制总结
- blkmaker可以连多个bitcoind节点
- blkmaker监听和接收4类消息:RAWGBT、STRATUM_JOB、SOLVED_SHARE和NMC_SOLVED_SHARE
- 监听RAWGBT目的为获取gbtHash/交易列表,用于构建Block,gbtHash和vtxs写入rawGbtMap_
* rawGbtMap_保存最近100条gbtHash/vtxs对
- 监听STRATUM_JOB目的为获取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 @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/ !40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/ !40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/ !40101 SET NAMES utf8 /;
/ !40103 SET @OLD_TIME_ZONE=@@TIME_ZONE /;
/ !40103 SET TIME_ZONE='+00:00' /;
/ !40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 /;
/ !40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 /;
/ !40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' /;
/ !40111 SET @OLD_SQL_NOTES=@@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 TIME_ZONE=@OLD_TIME_ZONE /;
/ !40101 SET SQL_MODE=@OLD_SQL_MODE /;
/ !40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS /;
/ !40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS /;
/ !40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /;
/ !40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/ !40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION /;
/ !40111 SET SQL_NOTES=@OLD_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;
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 兄弟连区块链教程以太坊源码分析core-genesis创世区块源码分析
- 兄弟连区块链教程eth源码解析区块数据结构
- 【以太坊源码解析】-区块数据结构
- 兄弟连区块链入门教程以太坊源码分析hashimoto源码分析(一)
- 兄弟连区块链教程以太坊源码分析chain-indexer区块链索引二
- 以太坊源码分析:fetcher模块和区块传播
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。