二维码

5.5 区块索引 - 数据结构 - 机器学习

1099 人阅读 | 时间:2021年01月15日 01:20
5.5 区块索引 - 数据结构 - 机器学习 #daohang ul li t,.reed .riqi,a.shangg,a.xiatt,a.shangg:hover,a.xiatt:hover,a.shang,a.xiat,a.shang:hover,a.xiat:hover,.reed-pinglun-anniu,span.now-page,#daohangs-around,#caidan-tubiao,#daohangs,#daohangs li,#btnPost{background-color:#D10B04;} .dinglanyou1 h3{border-bottom:3px solid #D10B04;} #dibuer{border-top:2px solid #D10B04;}.cebianlan .rongqi h3{border-bottom:1px solid #D10B04;} #edtSearch{border:1px solid #D10B04;} #daohang .zuo ul li{border-right:1px solid #;} #daohang ul li t a{border-top:1px solid #;border-right:1px solid #D10B04;} #daohang ul li t a:hover{border-right:1px solid #;} #daohang .you ul li a:hover,#daohang .zuo ul li a:hover,.reed-pinglun-anniu:hover{background-color:#;} a:hover,.reed h6 a:hover,#dibuer a:hover,.reed .riqiding,.cebianlan .rongqi li a:hover,#pinglun-liebiao ul.fubens li.depth-1 dl dd span.shu a,#pinglun-liebiao ul.fubens li.depth-1 dl dd span.huifuliuyan a:hover,.reed-biaoti h6 span{color:#D10B04;} .reed .kan a{color:#0A0AF5;}.reed .kan a:hover{color:#D10101;} @media screen and (max-width:1492px){a.shang,a.xiat{background:none;} a.xiat:hover,a.shang:hover{background-color:#f9f9f9;background-image:none;text-decoration:none;}} var _hmt = _hmt || [];(function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?b19db5ba3b437a9e8698d2bc8fc64334"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s);})(); var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?b19db5ba3b437a9e8698d2bc8fc64334"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?2d748c9763cfc72fb7d1ccab29f0770d"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?f6d451f3f1be23f3abf240c64c469c1b"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();

当前位置:首页 » 区块链精品文章 » 正文

(function() { var s = "_" + Math.random().toString(36).slice(2); document.write('
'); (window.slotbydup = window.slotbydup || []).push({ id: "u3646201", container: s }); })();
(function() { var s = "_" + Math.random().toString(36).slice(2); document.write('
'); (window.slotbydup = window.slotbydup || []).push({ id: "u3646162", container: s }); })();

5.5 区块索引

1232 人参与  2018年10月15日 10:45  分类 : 区块链精品文章  评论

超级账本提供多种区块索引(Block Index)方式,以便能够快速找到区块。这些方式包括:

·区块编号;

·区块哈希;

·交易编号;

·同时按区块编号和交易编号;加 入 会 员 微 信 dedao555

·区块交易编号;

·交易验证码。

5.5.1 文件位置指针

索引的内容是文件位置指针(File Location Pointer),位置指针的结构如下所示:


type fileLocPointer struct {
   fileSuffixNum int
   locPointer
}

type locPointer struct {
   offset      int
   bytesLength int
}


文件位置指针由3个部分组成:

·所在文件的编号fileSuffixNum;

·文件内的偏移量offset;

·区块占用的字节数bytesLength。

区块查找是一个三级索引过程,查找一个区块就是先确定是哪个链,然后根据文件编号找到对应的文件,再根据文件的偏移量和占用的字节数确定区块的内容,如图5-3所示。

5.5 区块索引 - 数据结构 - 机器学习

图5-3 多链下区块的三级索引

文件位置指针序列化后保存到LevelDB数据库中,不同的索引方式对应的键如表5-1所示(“+”是逻辑符号,不是真实的键组成部分):

构建哪些索引类型是可配置的,默认是所有类型都建立索引(排序服务也会建立索引,但只有区块编号这种索引类型)。有两种途径可以构建索引:

·提交区块(Commit Block);

·同步索引(Sync Index)。

表5-1 区块索引类型

5.5 区块索引 - 数据结构 - 机器学习

提交区块到账本的时候会自动按照表5-1所示的区块类型构建索引,下面来看一下索引的同步过程。

5.5.2 索引的同步过程

索引同步只在创建区块文件管理器(blockfileMgr)的时候执行,验证数据库里保存的索引是否和区块文件系统里的一致。

数据库记录了两个检查点的信息:

·索引检查点信息(indexCheckpointKey);

·区块检查点信息(blkMgrInfo)。

索引检查点信息记录的是最后建立索引的区块编号。通过索引检查点信息的区块编号,可以查询到区块编号对应的文件位置指针,它代表了数据库中记录的最新状态。这个状态由于系统异常等原因可能和区块文件系统存储的不一致。

区块检查点信息记录的是已提交到账本的区块信息,数据结构如下:


type checkpointInfo struct {
   latestFileChunkSuffixNum int      // 最新区块的文件编号
   latestFileChunksize      int      // 最新区块的文件偏移
   isChainEmpty             bool     // 是否为空链
   lastBlockNumber          uint64   // 最新的区块编号
}


区块检查点信息记录的是区块文件系统的一个状态,可能和索引检查点信息记录的区块编号不一致,也可能和区块文件系 统不一致。由于记录过程是先提交区块到区块文件系统,再记录区块检查点信息,最后是索引检查点信息,所以区块文件系统的信息是最完整的。可以通过区块文件 系统同步区块检查点信息和索引检查点信息。区块检查点信息和索引检查点信息记录的状态可能不是最新的,代表的是过去某个时刻正确的状态,索引同步可以从检 查点记录的状态开始,更新为区块文件系统的最新状态,减少同步时间。

区块文件管理器在创建的时候会从数据库中获取区块检查点信息,并且需要和区块文件系统对比检查其是否为最新的状 态。检查过程是基于区块检查点的文件编号和文件内由偏移构建的一个区块文件流(blockfileStream),从这个偏移开始验证该文件是否还有区块 数据。如果确实还有区块,找到该文件实际存储的最大区块编号,更新区块检查点信息。这里用的是区块文件流,它只会检查单个文件。这可能会存在一个特殊情 况,就是上一个区块刚好写满这个文件,达到了上限maxBlockfileSize,这个区块从下一个文件开始写,写完区块数据以后,更新区块检查点信息 的时候出现异常,这时会导致区块检查点信息记录和区块文件系统的永久性不一致。

经过上面的检查后,区块检查点信息就和区块文件系统完全一致了。根据区块检查点信息,构建区块流,从索引检查点信息记录的区块文件和偏移开始,到区块检查点记录的最新区块的文件编号为止,全部重新构建索引,并更新索引检查点信息。

来源:我是码农,转载请保留出处和链接!

本文链接:http://www.54manong.com/?id=1066

(function() { var s = "_" + Math.random().toString(36).slice(2); document.write('
'); (window.slotbydup = window.slotbydup || []).push({ id: "u3646208", container: s }); })();
(function() { var s = "_" + Math.random().toString(36).slice(2); document.write('
'); (window.slotbydup = window.slotbydup || []).push({ id: "u3646147", container: s }); })();
window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdPic":"","bdStyle":"0","bdSize":"16"},"share":{},"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到:","viewSize":"16"},"selectShare":{"bdContainerClass":null,"bdSelectMiniList":["qzone","tsina","tqq","renren","weixin"]}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
区块链是什么  

微信号:qq444848023    QQ号:444848023

加入【我是码农】QQ群:864689844(加群验证:我是码农)

<< 上一篇 下一篇 >>
(function() { var s = "_" + Math.random().toString(36).slice(2); document.write('
'); (window.slotbydup = window.slotbydup || []).push({ id: "u3646186", container: s }); })();
(function() { var s = "_" + Math.random().toString(36).slice(2); document.write('
'); (window.slotbydup = window.slotbydup || []).push({ id: "u3646175", container: s }); })();
搜索

网站分类

标签列表

最近发表

    (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https'){ bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else{ bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();

全站首页 | 数据结构 | 区块链| 大数据 | 机器学习 | 物联网和云计算 | 面试笔试

var cnzz_protocol = (("https:" == document.location.protocol) ? "https://" : "http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1276413723'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s23.cnzz.com/z_stat.php%3Fid%3D1276413723%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));本站资源大部分来自互联网,版权归原作者所有!

jQuery(document).ready(function($){ /* prepend menu icon */ $('#daohangs-around').prepend('
'); /* toggle nav */ $("#caidan-tubiao").on("click", function(){ $("#daohangs").slideToggle(); $(this).toggleClass("active"); }); });

©著作权归作者所有:来自ZhiKuGroup博客作者没文化的原创作品,如需转载,请注明出处,否则将追究法律责任 来源:ZhiKuGroup博客,欢迎分享。

评论专区
  • 昵 称必填
  • 邮 箱选填
  • 网 址选填
◎已有 0 人评论
搜索
作者介绍
30天热门
×
×
本站会员尊享VIP特权,现在就加入我们吧!登录注册×
»
会员登录
新用户注册
×
会员注册
已有账号登录
×