@@ -88,9 +88,9 @@ func calcHeightToBlockHeaderKey(height int64) []byte {
88
88
}
89
89
90
90
//存储block hash对应的block height
91
- func calcHashToHeightKey (hash []byte ) []byte {
92
- return append (hashPrefix , hash ... )
93
- }
91
+ // func calcHashToHeightKey(hash []byte) []byte {
92
+ // return append(hashPrefix, hash...)
93
+ // }
94
94
95
95
//存储block hash对应的block总难度TD
96
96
func calcHashToTdKey (hash []byte ) []byte {
@@ -407,6 +407,9 @@ func (bs *BlockStore) HasTx(key []byte) (bool, error) {
407
407
//通过短hash查询交易存在时,需要再通过全hash索引查询一下。
408
408
//避免短hash重复,而全hash不一样的情况
409
409
//return true, nil
410
+ // 查重性能对比:
411
+ // 先查短哈希,再查全哈希,单次查询平均耗时10000ns
412
+ // 直接查全哈希,单次查询平均耗时24000ns
410
413
}
411
414
if _ , err := bs .db .Get (cfg .CalcTxKey (key )); err != nil {
412
415
if err == dbm .ErrNotFoundInDb {
@@ -570,7 +573,7 @@ func (bs *BlockStore) SaveBlock(storeBatch dbm.Batch, blockdetail *types.BlockDe
570
573
storeBatch .Set (blockLastHeight , heightbytes )
571
574
572
575
//存储block hash和height的对应关系,便于通过hash查询block
573
- storeBatch .Set (calcHashToHeightKey (hash ), heightbytes )
576
+ // storeBatch.Set(calcHashToHeightKey(hash), heightbytes)
574
577
575
578
//存储block height和block hash的对应关系,便于通过height查询block
576
579
storeBatch .Set (calcHeightToHashKey (height ), hash )
@@ -618,7 +621,7 @@ func (bs *BlockStore) DelBlock(storeBatch dbm.Batch, blockdetail *types.BlockDet
618
621
storeBatch .Set (blockLastHeight , bytes )
619
622
620
623
//删除block hash和height的对应关系
621
- storeBatch .Delete (calcHashToHeightKey (hash ))
624
+ // storeBatch.Delete(calcHashToHeightKey(hash))
622
625
623
626
//删除block height和block hash的对应关系,便于通过height查询block
624
627
storeBatch .Delete (calcHeightToHashKey (height ))
@@ -748,17 +751,17 @@ func (bs *BlockStore) DelTxs(storeBatch dbm.Batch, blockDetail *types.BlockDetai
748
751
}
749
752
750
753
//GetHeightByBlockHash 从db数据库中获取指定hash对应的block高度
751
- func (bs * BlockStore ) GetHeightByBlockHash (hash []byte ) (int64 , error ) {
752
-
753
- heightbytes , err := bs .db .Get (calcHashToHeightKey (hash ))
754
- if heightbytes == nil || err != nil {
755
- if err != dbm .ErrNotFoundInDb {
756
- storeLog .Error ("GetHeightByBlockHash" , "error" , err )
757
- }
758
- return - 1 , types .ErrHashNotExist
759
- }
760
- return decodeHeight (heightbytes )
761
- }
754
+ // func (bs *BlockStore) GetHeightByBlockHash(hash []byte) (int64, error) {
755
+ //
756
+ // heightbytes, err := bs.db.Get(calcHashToHeightKey(hash))
757
+ // if heightbytes == nil || err != nil {
758
+ // if err != dbm.ErrNotFoundInDb {
759
+ // storeLog.Error("GetHeightByBlockHash", "error", err)
760
+ // }
761
+ // return -1, types.ErrHashNotExist
762
+ // }
763
+ // return decodeHeight(heightbytes)
764
+ // }
762
765
763
766
func decodeHeight (heightbytes []byte ) (int64 , error ) {
764
767
var height types.Int64
@@ -767,7 +770,7 @@ func decodeHeight(heightbytes []byte) (int64, error) {
767
770
//may be old database format json...
768
771
err = json .Unmarshal (heightbytes , & height .Data )
769
772
if err != nil {
770
- storeLog .Error ("GetHeightByBlockHash Could not unmarshal height bytes" , "error" , err )
773
+ storeLog .Error ("decodeHeight could not unmarshal height bytes" , "error" , err )
771
774
return - 1 , types .ErrUnmarshal
772
775
}
773
776
}
0 commit comments