1 Star 0 Fork 0

妥協/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
optimization.go 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package privacyenabledstate
import (
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
)
type metadataHint struct {
cache map[string]bool
bookkeeper *leveldbhelper.DBHandle
}
func newMetadataHint(bookkeeper *leveldbhelper.DBHandle) *metadataHint {
cache := map[string]bool{}
itr := bookkeeper.GetIterator(nil, nil)
defer itr.Release()
for itr.Next() {
namespace := string(itr.Key())
cache[namespace] = true
}
return &metadataHint{cache, bookkeeper}
}
func (h *metadataHint) metadataEverUsedFor(namespace string) bool {
return h.cache[namespace]
}
func (h *metadataHint) setMetadataUsedFlag(updates *UpdateBatch) {
batch := leveldbhelper.NewUpdateBatch()
for ns := range filterNamespacesThatHasMetadata(updates) {
if h.cache[ns] {
continue
}
h.cache[ns] = true
batch.Put([]byte(ns), []byte{})
}
h.bookkeeper.WriteBatch(batch, true)
}
func filterNamespacesThatHasMetadata(updates *UpdateBatch) map[string]bool {
namespaces := map[string]bool{}
pubUpdates, hashUpdates := updates.PubUpdates, updates.HashUpdates
// add ns for public data
for _, ns := range pubUpdates.GetUpdatedNamespaces() {
for _, vv := range updates.PubUpdates.GetUpdates(ns) {
if vv.Metadata == nil {
continue
}
namespaces[ns] = true
}
}
// add ns for private hashes
for ns, nsBatch := range hashUpdates.UpdateMap {
for _, coll := range nsBatch.GetCollectionNames() {
for _, vv := range nsBatch.GetUpdates(coll) {
if vv.Metadata == nil {
continue
}
namespaces[ns] = true
}
}
}
return namespaces
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liurenhao/fabric.git
git@gitee.com:liurenhao/fabric.git
liurenhao
fabric
fabric
v1.4.0

搜索帮助