技术指南丨如何在HyperLedger Fabric上实现链下存储_LibraNews_服务于区块链创新者

详情页1

本文作者Deeptiman Pattnaik是一名开发工程师,从事各种软件开发项目:Android,Go,Node.js,MongoDB,PHP,JavaScript Beacon,虚拟现实,增强现实。

在本文中,我将尝试解释Hyperledger Fabric中链下(OffChain)存储的重要性以及offchaindata应用,该应用是构建用于演示使用Hyperledger Fabric的Go编程语言进行链下存储的实现。

技术指南丨如何在HyperLedger Fabric上实现链下存储_LibraNews_服务于区块链创新者

 

链上(OnChain)和链下(OffChain)交易

任何区块链平台中的交易流都在两个不同的层中执行。涉及到区块链网络中的分布式分类帐的交易被视为链上交易,而在区块链外部执行并存储到任何集合数据库(例如CouchDB,StateDB)中的交易被视为链下交易。

 

区块链不仅仅是存储解决方案

区块链技术的概念是存储大量数据,并能够为每个交易提供当前状态。区块链网络将为分布式账本数据中执行的任何更改维护交易历史记录日志。这种技术将区块链与传统的数据库存储技术区分开来,传统的数据库存储技术仅设计为以有组织的方式存储数据。

 

链上交易问题

通常,链上交易需要更长的时间才能执行完成。由于网络中等待执行的大量交易队列,区块链性能开始下降,并且花费的交易时间更长。在区块链中的链上交易期间,业务和存储空间都涉及大量成本。

 

链上存储计算

IBM已进行分析以确定涉及存储空间的大量成本。(来源:https://www.ibm.com/downloads/cas/RXOVXAPM)

事实因素

  • 比特币每个区块存储1400笔交易。
  • 超级账本区块的大小为1 MB,每个区块有1000笔交易。
  • 每个区块链交易的大小为5 KB,可产生205 TPS(每秒的交易数)
  • 每TPS的存储量计算

通过比较公司每天平均工作8小时和每年240天的平均时间来进行交易计算。

(1 TPS / 1000 TB)* 1024 KB * 3500秒/小时* 8小时/天* 240天/年 = 每年每笔交易的数据为7,077,888 KB=6,912 MB = 6.75 GB = 0.00659 TB /交易/年

区块链的链上财务成本

IBM还提供了超级账本(Hyperledger)和以太坊等非授权区块链的平均企业级成本。

IBM Hyperledger的每月费用为$ 1000,每个活动节点的额外费用为$ 1000,因此每月总费用为$ 6000。

每笔交易的成本是:比特币为1.30美元,以太坊每笔交易为0.25美元。

在非许可式区块链中,每次交易成本将根据加密货币的当前价值而变化。

Hyperledger等基于权限的区块链的成本将随着节点数量的增加而变化。

因此,与交易成本相比,不应将所有非交易数据(例如图片,视频,PDF和其他文档)存储在区块链分类账中。

 

链下交易解决方案

链下交易不会在存储空间中为每个节点存储交易。 愿意存储特定交易的一方可以使用链下存储。 链下交易提高了计算效率,这种计算是在链下执行的,是确定性的而非共识的。

 

链下存储的设计实现

有许多链下数据库可与Hyperledger Fabric集成以存储交易明细。 我构建的offchaindata应用使用CouchDB作为链下存储。 将运行一个GRPC事件侦听器,该侦听器作为GRPC客户端连接侦听对等方。

因此,事件侦听器将每个区块的KVWriteSet值处理到链下存储区(CouchDB)中。 MapReduce技术用于从CouchDB存储中查询链下数据。

GitHub:https://github.com/Deeptiman/offchaindata

 

什么是MapReduce?

MapReduce是一种编程模型,旨在在大型集群上并行处理大量数据。

MapReduce有两个功能:

  • 映射——它提供了某些文档集合的密钥值对列表。
  • 减少——它具有一组较小的密钥值对,可处理集合中的多个节点。

CouchDB使用MapReduce技术来过滤所有收集文档。 在下面的示例中,我们将看到MapReduce如何用于一种User模型。

User模型

type SampleUser struct { Email string `json:"email"` Name string `json:"name"` Age string `json:"age"` Country string `json:"country"` }

CouchDB中的文档收集

技术指南丨如何在HyperLedger Fabric上实现链下存储_LibraNews_服务于区块链创新者

存储在CouchDB中的用户详细信息

因此,我们将创建一个MapReduce函数来查询集合中的电子邮件。

为电子邮件配置MapReduce

curl -X PUT http://127.0.0.1:5990/offchaindb/_design/emailviewdesign/ -d '{"views":{"emailview":{"map":"function(doc) { emit(doc.email,1);}", "reduce":"function (keys, values, combine) {return sum(values)}"}}}' -H 'Content-Type:application/json'

输出 {"ok": true, "id":"_design/emailviewdesign", "rev": "1-f34147f686003ff5c7da5a5e7e2759b8"}

使用参数

设计视图:emailviewdesign

MapReduce视图:

{ "views": { "emailview": { "map": "function(doc) { emit(doc.email,1);}", "reduce": "function (keys, values, combine) {return sum(values)}" } } } 查询减少功能可计算电子邮件总数 curl -X GET http://127.0.0.1:5990/offchaindb/_design/emailviewdesign/_view/emailview?reduce=true 输出

{"rows":[ {"key":null,"value":7} ]}

查询地图功能列出所有电子邮件 curl -X GET http://127.0.0.1:5990/offchaindb/_design/emailviewdesign/_view/emailview?group=true

输出

{"rows":[ {"key":"alice@gmail.com","value":1}, {"key":"john@gmail.com","value":1}, {"key":"michale@gmail.com","value":1}, {"key":"mark@mail.com","value":1}, {"key":"bob@gmail.com","value":1}, {"key":"oscar@gmail.com","value":1}, {"key":"william@example.com","value":1} ]}

因此,MapReduce以这种方式工作。 我们还可以为其他节点创建MapReduce函数,以从CouchDB查询

 

结论

所有查询都在链下存储空间中执行,并且完全忽略了链上分类帐。 就查询大量数据而言,这提高了计算效率。 执行链下查询不涉及交易成本,因为类似的链上查询具有较高的交易成本。 在公有区块链的情况下,链下存储还可以用于存储敏感的私有数据,因为并非区块链网络中的所有参与者都知道用于存储数据的附加独立存储层。

因此,这是了解任何区块链网络中链下存储的重要用例的概述。 请检查Github上的链下数据应用程序并分享您的反馈。

免责声明:本文转载自互联网,经授权后发布,版权归原作者所有,转载请联系原作者并获许可。文章观点仅代表作者本人,不代表Libra资讯立场。若内容涉及投资建议,仅供参考勿作为投资依据。投资有风险,入市需谨慎。

发表评论

电子邮件地址不会被公开。

评论列表(17条)

  • film semi layarkaca21
    film semi layarkaca21 12月 23, 2020 9:20 下午

    What i don’t realize is in truth how you’re no longer actually a lot more smartly-appreciated
    than you may be now. You are so intelligent. You realize therefore
    significantly in the case of this subject, produced me personally believe it from
    numerous varied angles. Its like women and men are not fascinated unless it is one thing to do with Woman gaga!
    Your own stuffs excellent. At all times take care
    of it up!

  • layarkaca21 film indonesia
    layarkaca21 film indonesia 12月 24, 2020 3:40 上午

    What’s up to every one, the contents present at this website
    are genuinely remarkable for people experience, well, keep up the nice work fellows.

  • situs slot online indonesia
    situs slot online indonesia 12月 25, 2020 12:38 上午

    I am extremely impressed with your writing skills as well as with the layout on your weblog.

    Is this a paid theme or did you modify it yourself? Either
    way keep up the nice quality writing, it is rare to see a great blog like this one nowadays.

  • Lorraine
    Lorraine 12月 25, 2020 7:43 上午

    This is a topic that’s near to my heart… Thank you!
    Where are your contact details though?

  • layarkaca21 xxi
    layarkaca21 xxi 12月 25, 2020 4:12 下午

    Its such as you learn my mind! You appear to understand so much about this, like you wrote the e-book in it or something.
    I feel that you could do with some % to drive the message home a little bit,
    but instead of that, this is fantastic blog. An excellent read.
    I will definitely be back.

  • Lelia
    Lelia 12月 26, 2020 12:56 下午

    Hi there, its nice post regarding media print, we all understand media is a great source of facts.

  • Helena
    Helena 12月 26, 2020 3:28 下午

    Do you mind if I quote a couple of your articles as
    long as I provide credit and sources back to your blog? My website is in the exact same area of interest as yours and
    my users would really benefit from a lot of the information you present here.

    Please let me know if this ok with you. Thanks!

  • Weldon
    Weldon 12月 26, 2020 4:21 下午

    continuously i used to read smaller posts which as well clear
    their motive, and that is also happening with this paragraph which I
    am reading now.

  • Angeline
    Angeline 12月 26, 2020 5:30 下午

    Wow, amazing weblog structure! How long have you ever
    been running a blog for? you make running a blog look easy.
    The overall look of your website is wonderful, as smartly as the content!

  • film semi layarkaca21
    film semi layarkaca21 12月 26, 2020 6:07 下午

    I’m not sure where you are getting your information, but good topic.
    I needs to spend some time learning more or understanding more.

    Thanks for wonderful info I was looking for this info for my mission.

  • Latashia
    Latashia 12月 26, 2020 9:14 下午

    Hello, I enjoy reading all of your post. I wanted to write
    a little comment to support you.

  • Simone
    Simone 12月 27, 2020 3:25 下午

    Link exchange is nothing else but it is only placing the
    other person’s weblog link on your page at suitable place and other
    person will also do similar for you.

  • Mittie
    Mittie 12月 30, 2020 10:26 下午

    whoah this weblog is great i really like studying
    your posts. Stay up the good work! You already know, lots
    of individuals are hunting round for this information, you could aid them greatly.

  • Jude
    Jude 1月 4, 2021 7:10 上午

    Hey! This post couldn’t be written any better! Reading
    through this post reminds me of my good old room mate!
    He always kept talking about this. I will forward this article to him.
    Fairly certain he will have a good read. Thank you for sharing!

  • look at this web-site Porsche Taycan For Sale

    Please let me know if you’re looking for a article writer
    for your weblog. You have some really good posts and
    I believe I would be a good asset. If you ever want to take some of the load off, I’d really like to write
    some articles for your blog in exchange for a link back to mine.
    Please send me an e-mail if interested. Regards!

  • check over here Porsche Taycan Reveal
    check over here Porsche Taycan Reveal 1月 19, 2021 9:46 上午

    This is my first time go to see at here and i am truly happy to read
    everthing at alone place.

  • his Explanation Porsche Taycan Vs Taycan S
    his Explanation Porsche Taycan Vs Taycan S 1月 20, 2021 12:36 上午

    Hi there, I read your blogs like every week. Your story-telling style is witty, keep up the good
    work!

在线客服 公众号
分享本页
返回顶部
bitcoin
Bitcoin (BTC) 202,098.25 10.14%
ethereum
Ethereum (ETH) 7,634.09 9.94%
usd-coin
USD Coin (USDC) 6.46 0.43%