• Posts tagged "比特币"

Blog Archives

HiBlock社区:区块链链上数据的认知与探索

跨界知识聚会系列文章,“知识是用来分享和传承的”,各种会议、论坛、沙龙都是分享知识的绝佳场所。我也有幸作为演讲嘉宾参加了一些国内的大型会议,向大家展示我所做的一些成果。从听众到演讲感觉是不一样的,把知识分享出来,你才能收获更多。

关于作者

  • 张丹(Conan), 程序员/Quant: Java,R,Nodejs
  • blog: http://blog.fens.me
  • email: bsspirit@gmail.com

转载请注明出处:
http://blog.fens.me/meeting-hiblock-20180826

前言

数字货币百花齐放,数字货币开发是区块链开发者的必修课也是入门课,通过ERC20智能合约很快就可以掌握开发技巧,但数字货币的安全如何保障?数字货币交易过程中产生了大量的数据,资金流转规律、操盘方式、筹码分布等等,通过数据预测数字货币价格走势也不是没有可能,除此之外区块链产生的数据还有什么价值?

本次的沙龙2个主题,一个是安全,一个是数据。

目录

  1. 我的演讲主题:区块链链上数据的认知与探索
  2. 会议体验和照片分享

1. 我的演讲主题:区块链链上数据的认知与探索

本次的沙龙2个主题,一个是安全,一个是数据,都是技术流!!所以,来听的也都是技术流,很少人,但很聊的来。

我本次分享的主题为:区块链链上数据的认知与探索,PPT下载,主要内容来自我的1篇博客文篇:区块链链上数据的认知与探索(未发布)。

分享主题的目录大纲如下:

  1. 认识区块链
  2. 区块浏览器
  3. 链上数据探索

主题简介:区块链上所有的交易都是公开透明的,链上账本会记录所有参与者交易行为,包括资金流转规律,庄家操盘,筹码分布等,价值巨大,从数据科学的角度,分享对区块链链上数据进行的认知与探索。

本此分析主要是从数据的角度切入,开始先介绍区块链,让大家有所认知;然后介绍区块链有什么样的数据,区别场内数据和场外数据;最后引出主题,对场外数据进行数据探索,通过账本的交易流水发现这些数据中的规律性的行为,坐庄行为,散户行为,拉盘行为….

数据是很有意思的,希望大家能够了解链上数据,用技术的武器去发现和鉴别真实的交易。

2. 会议体验和照片分享

本次线下沙龙的核心主题为,技术维度解读数字货币安全与数据价值,会议的主页:http://www.huodongxing.com/event/3453087067011

30人的小沙龙,定位就是区块链的技术圈,同业交流。我的分享是 “区块链链上数据的认知与探索” 也是在我这次转型积累的新的经验,跨学科的知识结合,从数据的角度理解区块链。

会议主题:

  • 14:00-14:05 开场 主办方介绍
  • 14:05-14:30 参会者自我介绍
  • 14:30-15:30《智能合约审计》分享嘉宾:赵威
  • 15:30-16:30《区块链链上数据的认知与探索》分享嘉宾:张丹
  • 16:30-17:00 合影 交流

我的介绍和照片分享。

分布式科技CTO,《R的极客理想-量化投资篇》作者,微软MVP。10年编程经验,获得10项SUN及IBM技术认证。前民生银行大数据分析师。个人博客 http://fens.me, Alexa全球排名70K。

2.2 会议相关照片

本次的场地在北京朝阳区建国路89号华贸商务楼16号B1 联合创业办公社,看上去更像是一个活动吧。

主持人:成芳

张丹,区块链链上数据的认知与探索

赵威, 智能合约审计

会后交流

政策条文: 分享开始前特意被关照,只能讲技术,不要讲其他的,最近太敏感,可能随时会被叫停!我们搞技术的人,底线是一定不会触碰的!!

布置会场。

大合照

主办方的小伙伴很辛苦,就一个小姑娘!坚持支持分享,保持高质量,坚持!坚持!

转载请注明出处:
http://blog.fens.me/meeting-hiblock-20180826

打赏作者

bitcoin比特币节点安装

比特币吸金之道系列文章,由计算机黑客发明的网络货币,无国界,无政府,无中心。没有政府滥发货币,没有通货膨胀。在全球计算机网络中,自由的实现货币兑换和流通。

本系列文章只讲程序和策略,不谈挖矿…

关于作者:

  • 张丹(Conan), 程序员/Quant: Java,R,Nodejs
  • blog: http://blog.fens.me
  • email: bsspirit@gmail.com

转载请注明出处:
http://blog.fens.me/bitcoin-install

前言

量化交易的第一步就是获取数据,那么获得比特币的数据,最直接的方法就是搭建一个比特币的客户端,直接从比特币的公链上面同步账本获得数据。比特币网络的构建基础,是基于无中心节点和透明化,这样每个节点都会获得比特币网络中的全量数据。

那么,先我们从搭建bitcoin客户端节点开始吧。

目录

  1. bitcoin安装过程
  2. 启动bitcoin的节点

1. bitcoin安装过程

从源代码安装bitcoin客户端的操作过程,分为以下7步:

  1. 从github下载代码库
  2. 切换最新的版本
  3. 安装系统依赖库
  4. 运行autogen.sh脚本
  5. 运行configure脚本
  6. 运行make和make install
  7. 验证bitcoin安装成功

接下来,我们就一步一步的进行操作。本文使用的Linux系统环境为:Linux Ubuntu 16.04 LTS 64bit。

1.1 先从bitcoin的官方github下载代码库。

安装git的过程,就不再多说了,只需要一条命令apt install git就行了。


> git clone https://github.com/bitcoin/bitcoin.git
> cd bitcoin

1.2 找到最新的tag版本为v0.16.0。


> git tag
noversion
v0.1.5
...
v0.16.0
v0.16.0rc1
v0.16.0rc2
v0.16.0rc3
v0.16.0rc4
v0.2.0
...
v0.9.3
v0.9.3rc1
v0.9.3rc2
v0.9.4
v0.9.5
v0.9.5rc1
v0.9.5rc2

切换到最新版本的分支。


> git checkout v0.16.0

1.3 安装需要依赖的系统工具,这里会用到Libtool、pkg-config、libboost、libdb工具包,需要提前安装。


> apt install libtool
> apt install pkg-config
> apt install libboost-all-dev
> apt install libdb5.3++-dev 
> apt install libevent-dev

1.4 用./autogen.sh脚本进行编译,


> ./autogen.sh 

1.5 运行configure脚本

执行完成后,发现当前目标生了configure文件,然后运行configure文件。运行时,会出现一个BerkerlyDB的错误,它指定要求装4.8版本的BerkerlyDB。解决方法有2种,第1种,去下载对应版本的BerkerlyDB;第二种,跳过这一步的检查。我们先用第2种方法,跳过BerkeleyDB的兼容性检查。


> ./configure
configure: error: Found Berkeley DB other than 4.8, required for portable wallets (--with-incompatible-bdb to ignore or --disable-wallet to disable wallet functionality)

# 跳过BerkeleyDB的兼容性检查
> ./configure --with-incompatible-bdb

1.6 执行make和make install。


> make 
> make install

1.7 验证bitcoin安装成功

验证bitcoin安装成功,有2个命令 bitcoin-cli和bitcoind。我们需要检查一下,是否这个启动命令,安装到在系统环境中。

  • bitcoind,用于启动bitcoin的节点,同步账本数据。
  • bitcoin-cli,用于与bitcoind节点通信。

查看启动命令的系统安装位置。


> which bitcoin-cli
/usr/local/bin/bitcoin-cli

> which bitcoind
/usr/local/bin/bitcoind

分别查看bitcoind 和 bitcoin-cli 命令的帮助信息。


> bitcoind -help
> bitcoin-cli -help

这样就完成了,bitcoin的客户端的安装。

2. 启动bitcoin节点

通过bitcoind命令启动bitcoin的核心客户端程序。运行前,我先要定义一个bitcoin.conf的配置文件,用于设置RPC-JSON的访问用户。

新建配置文件 .bitcoin/bitcoin.conf。设置rpc用户的账号和密码,请大家按照复杂密码设定要求设置。官方推荐的bitcoin.conf文件的配置项,打开文件


> vi .bitcoin/bitcoin.conf

rpcuser=bsspirit
rpcpassword=98jfidayelqlvjieJDIjda

启动bitcoind服务端,并把数据写入到/data/btc目录,在控制台打印输出。


> bitcoind -datadir=/data/btc -conf=/root/.bitcoin/bitcoin.conf -printtoconsole

2018-05-30 01:51:06 Bitcoin Core version v0.16.0 (release build)
2018-05-30 01:51:06 InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
2018-05-30 01:51:06 Assuming ancestors of block 0000000000000000005214481d2d96f898e3d5416e43359c145944a909d242e0 have valid signatures.
2018-05-30 01:51:06 Setting nMinimumChainWork=000000000000000000000000000000000000000000f91c579d57cad4bc5278cc
2018-05-30 01:51:06 Using the 'sse4' SHA256 implementation
2018-05-30 01:51:06 Using RdRand as an additional entropy source
2018-05-30 01:51:06 Default data directory /root/.bitcoin
2018-05-30 01:51:06 Using data directory /data/btc
2018-05-30 01:51:06 Using config file /root/.bitcoin/bitcoin.conf
2018-05-30 01:51:06 Using at most 125 automatic connections (1024 file descriptors available)
2018-05-30 01:51:06 Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements
2018-05-30 01:51:06 Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements
2018-05-30 01:51:06 Using 4 threads for script verification
2018-05-30 01:51:06 scheduler thread start
2018-05-30 01:51:06 HTTP: creating work queue of depth 16
2018-05-30 01:51:06 Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation.
2018-05-30 01:51:06 HTTP: starting 4 worker threads
2018-05-30 01:51:06 Using wallet directory /data/btc
2018-05-30 01:51:06 init message: Verifying wallet(s)...
2018-05-30 01:51:06 Using BerkeleyDB version Berkeley DB 5.3.28: (September  9, 2013)
2018-05-30 01:51:06 Using wallet wallet.dat
2018-05-30 01:51:06 CDBEnv::Open: LogDir=/data/btc/database ErrorFile=/data/btc/db.log
2018-05-30 01:51:06 Cache configuration:
2018-05-30 01:51:06 * Using 2.0MiB for block index database
2018-05-30 01:51:06 * Using 8.0MiB for chain state database
2018-05-30 01:51:06 * Using 440.0MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space)
2018-05-30 01:51:06 init message: Loading block index...
2018-05-30 01:51:06 Opening LevelDB in /data/btc/blocks/index
2018-05-30 01:51:07 Opened LevelDB successfully
2018-05-30 01:51:07 Using obfuscation key for /data/btc/blocks/index: 0000000000000000
2018-05-30 01:51:08 LoadBlockIndexDB: last block file = 0
2018-05-30 01:51:08 LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=1, size=293, heights=0...0, time=2009-01-03...2009-01-03)
2018-05-30 01:51:08 Checking all blk files are present...
2018-05-30 01:51:08 LoadBlockIndexDB: transaction index disabled
2018-05-30 01:51:08 Opening LevelDB in /data/btc/chainstate
2018-05-30 01:51:08 Opened LevelDB successfully
2018-05-30 01:51:08 Using obfuscation key for /data/btc/chainstate: 6adad0af82f188f1
2018-05-30 01:51:08 Loaded best chain: hashBestChain=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f height=0 date=2009-01-03 18:15:05 progress=0.000000
2018-05-30 01:51:08 init message: Rewinding blocks...
2018-05-30 01:51:09 init message: Verifying blocks...
2018-05-30 01:51:09  block index            2369ms
2018-05-30 01:51:09 init message: Loading wallet...
2018-05-30 01:51:09 nFileVersion = 160000
2018-05-30 01:51:09 Keys: 2001 plaintext, 0 encrypted, 2001 w/ metadata, 2001 total
2018-05-30 01:51:09  wallet                   67ms
2018-05-30 01:51:09 setKeyPool.size() = 2000
2018-05-30 01:51:09 mapWallet.size() = 0
2018-05-30 01:51:09 mapAddressBook.size() = 0
2018-05-30 01:51:09 mapBlockIndex.size() = 279999
2018-05-30 01:51:09 nBestHeight = 0
2018-05-30 01:51:09 Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there
2018-05-30 01:51:09 AddLocal(103.211.167.71:8333,1)
2018-05-30 01:51:09 Discover: IPv4 eth0: 103.211.167.71
2018-05-30 01:51:09 Bound to [::]:8333
2018-05-30 01:51:09 Bound to 0.0.0.0:8333
2018-05-30 01:51:09 init message: Loading P2P addresses...
2018-05-30 01:51:09 torcontrol thread start
2018-05-30 01:51:09 Loaded 2445 addresses from peers.dat  9ms
2018-05-30 01:51:09 init message: Loading banlist...
2018-05-30 01:51:09 init message: Starting network threads...
2018-05-30 01:51:09 dnsseed thread start
2018-05-30 01:51:09 net thread start
2018-05-30 01:51:09 addcon thread start
2018-05-30 01:51:09 init message: Done loading
2018-05-30 01:51:09 opencon thread start
2018-05-30 01:51:09 msghand thread start
2018-05-30 01:51:09 New outbound peer connected: version: 70015, blocks=525031, peer=0
2018-05-30 01:51:11 New outbound peer connected: version: 70015, blocks=525031, peer=1

....

启动参数:

  • -datadir,用于指定目录
  • -conf,用于指定配置文件
  • -printtoconsole,用于控制台输出

如果打算后台执行,可以增加-daemon参数。同时,去掉-printtoconsole参数,在后面的日志文件中,进行输出。


> bitcoind -datadir=/data/btc -conf=/root/.bitcoin/bitcoin.conf -daemon
Bitcoin server starting

# 查看日志,在数据输出的目录,跟踪debug.log文件。
> tail -f /data/btc/debug.log 
11-04-11 22:01:50' progress=0.001211 cache=23.8MiB(165438txo)
2018-05-30 04:21:12 UpdateTip: new best=00000000000044640cb1d3e034f8df6604d1ac1346e6162bfca8dc60c4bbd887 height=117873 version=0x00000001 log2_work=61.645341 tx=403428 date='2011-04-11 22:02:29' progress=0.001212 cache=23.8MiB(165441txo)
2018-05-30 04:21:12 UpdateTip: new best=0000000000006488914c16dc226f1d73d5dcd6c258c3bc926fa0f804909dbd1b height=117874 version=0x00000001 log2_work=61.645483 tx=403445 date='2011-04-11 22:19:06' progress=0.001212 cache=23.8MiB(165459txo)
2018-05-30 04:21:12 UpdateTip: new best=000000000000988f65c0d5b018241f0dd13ea6b73c6228efccbbb577b5791f06 height=117875 version=0x00000001 log2_work=61.645624 tx=403453 date='2011-04-11 22:21:40' progress=0.001212 cache=23.8MiB(165460txo)

...

运行bitcoin-cli getblockchaininfo 命令,显示关于比特币网络节点、钱包、区块链数据库状态的基础信息。


> bitcoin-cli getblockchaininfo
{
  "chain": "main",
  "blocks": 2867,
  "headers": 525050,
  "bestblockhash": "000000006d6af482c12555a44bed3a0d4bbadf0fa27274225a1ed808b8a7d405",
  "difficulty": 1,
  "mediantime": 1233666084,
  "verificationprogress": 8.75401245716694e-06,
  "initialblockdownload": true,
  "chainwork": "00000000000000000000000000000000000000000000000000000b340b340b34",
  "size_on_disk": 852350,
  "pruned": false,
  "softforks": [
    {
      "id": "bip34",
      "version": 2,
      "reject": {
        "status": false
      }
    },
    {
      "id": "bip66",
      "version": 3,
      "reject": {
        "status": false
      }
    },
    {
      "id": "bip65",
      "version": 4,
      "reject": {
        "status": false
      }
    }
  ],
  "bip9_softforks": {
    "csv": {
      "status": "defined",
      "startTime": 1462060800,
      "timeout": 1493596800,
      "since": 0
    },
    "segwit": {
      "status": "defined",
      "startTime": 1479168000,
      "timeout": 1510704000,
      "since": 0
    }
  },
  "warnings": ""
}

看到这些信息,代表你的bitcoin程序已经启动了。有几十G的数据,需要同步!

安装bitcoin相比用apt安装要复杂一些,不过按照官方文档的介绍基本能走通的,安装过程对于技术人来不是什么大问题。不同的公链,有不同的节点软件,安装方法也不同,下一篇文章将介绍以太坊的客户端Geth的安装

转载请注明出处:
http://blog.fens.me/bitcoin-install

打赏作者