1 Star 0 Fork 0

BUPT-ZKJC / fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
types.go 3.29 KB
一键复制 编辑 原始数据 按行查看 历史
MJL 提交于 2021-08-06 18:37 . first commit
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package validation
import (
"github.com/hyperledger/fabric-protos-go/peer"
"gitee.com/bupt-zkjc/fabric/core/ledger/internal/version"
"gitee.com/bupt-zkjc/fabric/core/ledger/kvledger/txmgmt/privacyenabledstate"
"gitee.com/bupt-zkjc/fabric/core/ledger/kvledger/txmgmt/rwsetutil"
)
// block is used to used to hold the information from its proto format to a structure
// that is more suitable/friendly for validation
type block struct {
num uint64
txs []*transaction
}
// transaction is used to hold the information from its proto format to a structure
// that is more suitable/friendly for validation
type transaction struct {
indexInBlock int
id string
rwset *rwsetutil.TxRwSet
validationCode peer.TxValidationCode
containsPostOrderWrites bool
}
// publicAndHashUpdates encapsulates public and hash updates. The intended use of this to hold the updates
// that are to be applied to the statedb as a result of the block commit
type publicAndHashUpdates struct {
publicUpdates *privacyenabledstate.PubUpdateBatch
hashUpdates *privacyenabledstate.HashedUpdateBatch
}
// newPubAndHashUpdates constructs an empty PubAndHashUpdates
func newPubAndHashUpdates() *publicAndHashUpdates {
return &publicAndHashUpdates{
privacyenabledstate.NewPubUpdateBatch(),
privacyenabledstate.NewHashedUpdateBatch(),
}
}
// containsPvtWrites returns true if this transaction is not limited to affecting the public data only
func (t *transaction) containsPvtWrites() bool {
for _, ns := range t.rwset.NsRwSets {
for _, coll := range ns.CollHashedRwSets {
if coll.PvtRwSetHash != nil {
return true
}
}
}
return false
}
// retrieveHash returns the hash of the private write-set present
// in the public data for a given namespace-collection
func (t *transaction) retrieveHash(ns string, coll string) []byte {
if t.rwset == nil {
return nil
}
for _, nsData := range t.rwset.NsRwSets {
if nsData.NameSpace != ns {
continue
}
for _, collData := range nsData.CollHashedRwSets {
if collData.CollectionName == coll {
return collData.PvtRwSetHash
}
}
}
return nil
}
// applyWriteSet adds (or deletes) the key/values present in the write set to the publicAndHashUpdates
func (u *publicAndHashUpdates) applyWriteSet(
txRWSet *rwsetutil.TxRwSet,
txHeight *version.Height,
db *privacyenabledstate.DB,
containsPostOrderWrites bool,
) error {
u.publicUpdates.ContainsPostOrderWrites =
u.publicUpdates.ContainsPostOrderWrites || containsPostOrderWrites
txops, err := prepareTxOps(txRWSet, txHeight, u, db)
logger.Debugf("txops=%#v", txops)
if err != nil {
return err
}
for compositeKey, keyops := range txops {
if compositeKey.coll == "" {
ns, key := compositeKey.ns, compositeKey.key
if keyops.isDelete() {
u.publicUpdates.Delete(ns, key, txHeight)
} else {
u.publicUpdates.PutValAndMetadata(ns, key, keyops.value, keyops.metadata, txHeight)
}
} else {
ns, coll, keyHash := compositeKey.ns, compositeKey.coll, []byte(compositeKey.key)
if keyops.isDelete() {
u.hashUpdates.Delete(ns, coll, keyHash, txHeight)
} else {
u.hashUpdates.PutValHashAndMetadata(ns, coll, keyHash, keyops.value, keyops.metadata, txHeight)
}
}
}
return nil
}
1
https://gitee.com/bupt-zkjc/fabric.git
git@gitee.com:bupt-zkjc/fabric.git
bupt-zkjc
fabric
fabric
98d302355562

搜索帮助