3 Star 6 Fork 7

Gitee 极速下载 / Hyperledger fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
configtx_util.go 4.58 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package peer
import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/resourcesconfig"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/customtx"
"github.com/hyperledger/fabric/protos/common"
protospeer "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
)
// validateAndApplyResourceConfig validates that resourceConfigTx does not have any read-write conflict with the current
// resource configuration and prepares the full configuration by applying delta in the transaction to the current config.
// Finally, this sets the full configuration.
// TODO - Make sure that ProposeConfigUpdate is either deterministic in throwing error or it should throw
// explicit throw &customtx.InvalidTxError in the case of version conflict and general error for all other error conditions
func validateAndApplyResourceConfig(chainid string, resourceConfigTx *common.Envelope) (*common.Config, error) {
chains.Lock()
defer chains.Unlock()
cs := chains.list[chainid].cs
currentBundle := cs.bundleSource.StableBundle()
fullResourceConfig, err := computeFullConfig(currentBundle, resourceConfigTx)
if err != nil {
peerLogger.Debugf("Failed to validate PEER_RESOURCE_UPDATE because: %s", err)
return nil, &customtx.InvalidTxError{Msg: fmt.Sprintf("Error in validating the resource conf transaction: %s", err)}
}
peerLogger.Debugf("Successfully validated PEER_RESOURCE_UPDATE")
rBundle, err := resourcesconfig.NewBundle(chainid, fullResourceConfig, currentBundle.ChannelConfig())
if err != nil {
return nil, err
}
cs.bundleSource.Update(rBundle)
return fullResourceConfig, nil
}
func isResConfigCapabilityOn(chainid string, chanConfig *common.Config) (bool, error) {
chanConfigBundle, err := channelconfig.NewBundle(chainid, chanConfig)
if err != nil {
return false, err
}
appConfig, exists := chanConfigBundle.ApplicationConfig()
if !exists {
return false, fmt.Errorf("Application config missing")
}
return appConfig.Capabilities().ResourcesTree(), nil
}
// extractFullConfigFromSeedTx pulls out the seed resource config tx from the config transaction in the genesis block
func extractFullConfigFromSeedTx(configEnvelope *common.ConfigEnvelope) (*common.Config, error) {
configUpdateEnvelop := &common.ConfigUpdateEnvelope{}
configUpdate := &common.ConfigUpdate{}
if configEnvelope.LastUpdate == nil {
return nil, nil
}
if _, err := utils.UnmarshalEnvelopeOfType(configEnvelope.LastUpdate, common.HeaderType_CONFIG_UPDATE, configUpdateEnvelop); err != nil {
return nil, err
}
if err := proto.Unmarshal(configUpdateEnvelop.ConfigUpdate, configUpdate); err != nil {
return nil, err
}
isolatedData := configUpdate.IsolatedData
resourceConfigSeedDataBytes := isolatedData[protospeer.ResourceConfigSeedDataKey]
if resourceConfigSeedDataBytes == nil {
return nil, nil
}
resourceConfig := &common.Config{}
if err := proto.Unmarshal(resourceConfigSeedDataBytes, resourceConfig); err != nil {
return nil, err
}
return resourceConfig, nil
}
// computeFullConfig computes the full resource configuration given the current resource bundle and the transaction (that contains the delta)
func computeFullConfig(currentResourceBundle *resourcesconfig.Bundle, resConfTx *common.Envelope) (*common.Config, error) {
fullResourceConfigEnv, err := currentResourceBundle.ConfigtxValidator().ProposeConfigUpdate(resConfTx)
if err != nil {
return nil, err
}
return fullResourceConfigEnv.Config, nil
}
// TODO preferably make the serialize/deserialize deterministic
func serialize(resConfig *common.Config) ([]byte, error) {
return proto.Marshal(resConfig)
}
func deserialize(serializedConf []byte) (*common.Config, error) {
conf := &common.Config{}
if err := proto.Unmarshal(serializedConf, conf); err != nil {
return nil, err
}
return conf, nil
}
// retrievePersistedResourceConfig retrieves the persisted resource config from statedb
func retrievePersistedResourceConfig(ledger ledger.PeerLedger) (*common.Config, error) {
qe, err := ledger.NewQueryExecutor()
if err != nil {
return nil, err
}
defer qe.Done()
return retrievePersistedConf(qe, resourcesConfigKey)
}
// retrievePersistedChannelConfig retrieves the persisted channel config from statedb
func retrievePersistedChannelConfig(ledger ledger.PeerLedger) (*common.Config, error) {
qe, err := ledger.NewQueryExecutor()
if err != nil {
return nil, err
}
defer qe.Done()
return retrievePersistedConf(qe, channelConfigKey)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/fabric.git
git@gitee.com:mirrors/fabric.git
mirrors
fabric
Hyperledger fabric
v1.1.0-alpha

搜索帮助

344bd9b3 5694891 D2dac590 5694891