Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

HyperLeger Fabric SDK Development (2)-- Fabric SDK configuration

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

HyperLeger Fabric SDK development (2)-- Fabric SDK configuration 1. Fabric SDK configuration

The Fabric blockchain network application requires a large number of parameters to connect to the Fabric blockchain network. Usually, the parameters required by Fabric blockchain network applications are managed in a configuration file, which defines the configuration and user-defined parameters of Fabric SDK Go, and specifies all the information needed to connect to the Fabric blockchain network, such as the hostname and port of the Fabric blockchain network components. The configuration file provided by Fabric SDK GO for the application is usually written in the yaml file format and named config.yaml, and the configuration file is read in the application code.

The Fabric SDK Go version provides config.yaml templates, which developers can refer to

Fabric-sdk-go/pkg/core/config/testdata/template/config.yaml, which can also be rewritten according to the fabric-sdk-go/test/fixtures/config/config_e2e.yaml instance.

II. Definition of version

Version is used to define the version of the contents of the config.yaml file, and Fabric SDK Go uses version to match the appropriate parsing rules.

Version: 1.0.0

III. Definition of channels

The channels section describes the existing channel information, and what orderer and peer are contained in each channel.

The peer section can define the role attributes of the peer node. The roles are as follows:

EndorsingPeer: optional. The peer node node must install the chain code. Whether the peer node will be sent a transaction proposal for endorsement. Applications can also use this property to determine which peer node to send chain code installation requests to. Default value: true.

ChaincodeQuery: optional. The peer node must install the chain code. Only query whether the peer node will be sent a transaction proposal. The application can also use this property to determine which peer node to send the chain code installation request to. Default value: true.

LedgerQuery: optional. Whether it is possible to send a proposal to the peer node that does not have a chain code query, such as queryBlock (), queryTransaction (), etc. Default value: true.

EventSource: optional. Whether the peer node is the registered target of the SDK event listener, all peer nodes can produce events, but usually only one needs to connect to listen to the event. Default value: true.

# if the application creates a channel, you do not need this part of channels: # if no channel configuration is defined or the defined channel does not have information, use the default channel # if channel does not define peers, use the default channel's peers # if channel does not define orderes, use the default channel's orderes # if channel does not define an endorsement policy, use the default channel endorsement policy # if channel defines an endorsement policy However, some endorsement policies are missing, and the missing endorsement policies will be filled by default channel _ default: # optional, the peers list of participating organizations peers: peer1.org1.example.com: endorsingPeer: true chaincodeQuery: true ledgerQuery: true eventSource: true # optional, and the application uses the following options to perform channel operations, such as getting channel configuration policies: # optional Get the channel configuration block queryChannelConfig: # optional, the minimum number of successful response nodes minResponses: 1 # optional maxTargets: 1 # optional, query the retry options of the configuration block retryOpts: # optional, and the number of retries attempts: 5 # optional The fallback interval of the first retry initialBackoff: 500ms # is optional, the maximum fallback interval of the retry is maxBackoff: 5s backoffFactor: 2.0 # optional, and the option to obtain discovery information discovery: maxTargets: 2 # retry option retryOpts: # optional Number of retries attempts: 4 initialBackoff: 500ms maxBackoff: 5s backoffFactor: 2.0 # optional Event service option eventService: # optional resolverStrategy specifies the decision policy for selecting peer nodes when connecting to peer nodes # optional values: PreferOrg (default), MinBlockHeight, Balanced # PreferOrg: # determine which peer nodes are appropriate based on the block height lag threshold Although the peer node will be preferred in the current organization # if there is no suitable peer node in the current organization, # MinBlockHeight will be selected from other organizations: # select the best peer node according to the block height lag threshold, # the maximum block height of all peer nodes is determined Peer nodes whose block height is less than the maximum block height but within the lag threshold will be loaded, and # other peer nodes will not be considered. # Balanced: # Select peer node using configured balancer resolverStrategy: PreferOrg # optional balancer is a load balancer that chooses to connect to the peer node # optional values: Random (default), RoundRobin balancer: Random # optional, blockHeightLagThreshold sets block height lag threshold Used to select peer nodes to connect to # if a peer node lags behind the number of blocks given by the latest peer node, it will be excluded from the selection # Note: this parameter is only available when minBlockHeightResolverMode is set to ResolveByThreshold # default: 5 blockHeightLagThreshold: 5 # optional, reconnectBlockHeightLagThreshold-if the block height of the peer node lags behind the specified number of blocks # the event client will disconnect from the peer node and reconnect to a better performing peer node # if peerMonitor is set to enabled (default), this parameter is only available # default: 10 # Note: setting too low will cause frequent disconnection or reconnection of the event client, affecting performance reconnectBlockHeightLagThreshold: 8 # optional PeerMonitorPeriod is the time when the event client disconnects from the connected node and reconnects to another node # default: disabled for Balanced resolverStrategy, 0 For PreferOrg and MinBlockHeight 5s peerMonitorPeriod: 6s # required if _ default is not defined Optional if _ default has been defined. # Channel name assetchannel: # required if _ default peers is not defined, optional if _ default peers is already defined. # list of peer nodes of participating organizations peers: peer0.org1.example.com: # optional. Query only whether the peer node will be sent a transaction proposal. The peer node must install the chain code. The application can also use this attribute to determine which peer node to send the chain code installation request to. Default value: true endorsingPeer: true # optional. The peer node must install the chain code. Only query whether the peer node will be sent a transaction proposal. The application can also use this attribute to determine which peer node to send the chain code installation request to. Default value: true chaincodeQuery: true # optional. Whether it is possible to send a proposal to the peer node that does not have a chain code query, such as queryBlock (), # queryTransaction (), etc. Default value: true. LedgerQuery: true # is optional. Whether the peer node is the registered target of the SDK event listener, all peer nodes can produce events, # but usually only one needs to connect to listen to the event. Default value: true. EventSource: true IV, organizations definition

Organizations describes the organization (org) to which the peer node belongs, the certification authority, and the MSP ID of the organization.

# list of participating organizations in the Fabric blockchain network organizations: org1: mspid: Org1MSP # the MSP storage location of the organization, the absolute path or the path relative to cryptoconfig cryptoPath: peerOrganizations/org1.example.com/users/ {username} @ org1.example.com/msp peers:-peer0.org1.example.com-peer1.org1.example.com # optional, issued by the certification authority × × × Ming Fabric-CA is a special certificate authority that provides REST API support for dynamic certificate management, such as registration, revocation and re-registration # the following sections only set the certificateAuthorities:-ca.org1.example.com org2: mspid: Org2MSP # organization's MSP storage location for the Fabric-CA server Relative to the relative position or absolute path of the cryptoconfig cryptoPath: peerOrganizations/org2.example.com/users/ {username} @ org2.example.com/msp peers:-peer0.org2.example.com certificateAuthorities:-ca.org2.example.com # Orderer Organization name ordererorg: # MSPID mspID of the organization: OrdererMSP # loads the keys and certificates required by the user Absolute path or relative path cryptoPath: ordererOrganizations/example.com/users/ {username} @ example.com/ MSP V, orderers definition

Orderers must specify the hostname and port of all orderder nodes in the Hyperledger Fabric blockchain network to which you want to connect. An orderers object can contain multiple orderder nodes.

# orderers list to which to send transaction requests or channel creation and update requests # if more than one orderer,SDK is defined, which orderer is implemented by the code to specify orderers: # orderer node, you can define multiple orderer.example.com: url: orderer.example.com:7050 # the following attributes are defined by the gRPC library Will be passed to the gRPC client constructor grpcOptions: ssl-target-name-override: orderer.example.com # the following parameters are used to set the keepalive policy on the server, an incompatible setting will cause the connection to close # when keep-alive-time is set to 0 or less than the parameter of the active client The following parameters invalidate keep-alive-time: 0s keep-alive-timeout: 20s keep-alive-permit: false fail-fast: false allow-insecure: false tlsCACerts: # absolute path of certificate path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES_PATH} / ordererOrganizations/example.com/tlsca/tlsca.example.com- cert.pem6, peers definition

Peers must specify the hostnames and ports of all peer nodes in the Hyperledger Fabric blockchain network, which may be referenced elsewhere, such as channels,organizations.

# peers Node list peers: # peer Node definition You can define the absolute path of multiple peer0.org1.example.com: # URL to send endorsement and query requests url: peer0.org1.example.com:7051 grpcOptions: ssl-target-name-override: peer0.org1.example.com keep-alive-time: 0s keep-alive-timeout: 20s keep-alive-permit: false fail-fast: false allow-insecure: false tlsCACerts: # certificate Path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES_PATH} / peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com- cert.pem7, CertificateAuthorities definition

CertificateAuthorities must specify the hostname and port of the certification authority (CA) in the Hyperledger Fabric blockchain network for registering existing users and registering new users.

# Fabric-CA is a special certification authority provided by Hyperledger Fabric that can manage certificates through REST API. # applications can choose to use a standard certification authority instead of Fabric-CA. This section does not need to specify a certificateAuthorities: # CA authority You can define multiple ca.org1.example.com: url: https://ca.org1.example.com:7054 tlsCACerts: # Comma-Separated list of paths path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES_PATH} / peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem # client and Fabric CA for SSL handshake keys and certificates Client: key: path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES_PATH} / peerOrganizations/tls.example.com/users/User1@tls.example.com/tls/client.key cert: path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES_PATH} / peerOrganizations/tls.example.com/users/User1 @ tls.example.com/tls/client.crt # Fabric-CA supports dynamic user registration through REST API: registrar: enrollId: admin enrollSecret: adminpw # optional CA organization name caName: ca.org1.example.com VIII, client

The client part must define who the client application represents to interact with the Fabric blockchain network, and you can define the timeout option.

# client defines client: # the organization to which the client belongs must be the organization defined by organizations organization: org1 # define log service logging: level: debug # debug level # peer, event service, order timeout global configuration # if ignored in this section Use the following values as the default peer: timeout: connection: 10s response: 180s discovery: greylistExpiry: 10s eventService: timeout: registrationResponse: 15s orderer: timeout: connection: 15s response: 15s global: timeout: query: 180s execute: 180s resmgmt: 180s cache: connectionIdle: 30s eventServiceIdle: 2m channelConfig: 30m channelMembership: 30s discovery: 10s Selection: 10m # MSP root directory cryptoconfig: path: ${GOPATH} / src/github.com/hyperledger/fabric/AssetExchange/deploy/crypto-config # some SDK supports plug-in KV databases CredentialStore: # optional by specifying the credentialStore attribute For user certificate material storage, if all certificate materials are embedded in the profile, path: "/ tmp/state-store" # optional is not required Specify CryptoSuite implementation of Go SDK implementation cryptoStore: # specify the underlying KV database path: / tmp/msp # client's BCCSP module configuration BCCSP: security: enabled: true default: provider: "SW" hashAlgorithm: "SHA2" softVerify: true level: 256 tlsCerts: # optional, use the system certificate pool when connecting to peers,orderes Default is false systemCertPool: true # optional Client and peers key and certificate for TLS handshake with orderes client: key: path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES_PATH} / peerOrganizations/tls.example.com/users/User1@tls.example.com/tls/client.key cert: path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES_PATH } / peerOrganizations/tls.example.com/users/User1@tls.example.com/tls/ client.crt9. Config.yaml example

The configuration file of the asset trading platform application is as follows:

# Copyright SecureKey Technologies Inc. All Rights Reserved.## SPDX-License-Identifier: Apache-2.0### The network connection profile provides client applications the information about the target# blockchain network that are necessary for the applications to interact with it. These are all# knowledge that must be acquired from out-of-band sources. This file provides such a source.name: "assetchannel" # # Describe what the target network is/does.#description: "asset exchange network" # specified version version: 1.0.The client defines the organization to which the client belongs Must be organizations defined organization organization: org1 # define Log Service logging: level: debug # debug level # MSP Root cryptoconfig: path: ${GOPATH} / src/github.com/hyperledger/fabric/AssetExchange/deploy/crypto-config # some SDK supports plug-in KV databases, credentialStore: # optional by specifying the credentialStore attribute for user certificate material storage If all certificate materials are embedded in the configuration file, path: "/ tmp/state-store" # optional is not required Specify CryptoSuite implementation of Go SDK implementation cryptoStore: # specify the underlying KV database path: / tmp/msp # client's BCCSP module configuration BCCSP: security: enabled: true default: provider: "SW" hashAlgorithm: "SHA2" softVerify: true level: 256 tlsCerts: # optional, use the system certificate pool when connecting to peers,orderes Default is false systemCertPool: true # optional Client and peers key and certificate for TLS handshake with orderes client: key: # path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES_PATH} / peerOrganizations/tls.example.com/users/User1@tls.example.com/tls/client.key cert: # path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES _ PATH} / peerOrganizations/tls.example.com/users/User1@tls.example.com/tls/client.crt# if the application creates a channel Do not need this part channels: # if no channel configuration is defined or the defined channel has no information, use the default channel # if channel does not define peers, use the default channel's peers # if channel does not define orderes, use the default channel's orderes # if channel does not define an endorsement policy, use the default channel's endorsement policy # if channel defines an endorsement policy, but some endorsement policies are missing The missing endorsement policy will be populated with the default channel # required if _ default is not defined Optional if _ default has been defined. # Channel name assetchannel: # required if _ default peers is not defined, optional if _ default peers is already defined. # list of peer nodes of participating organizations peers: peer0.org1.example.com: # optional. Query only whether the peer node will be sent a transaction proposal. The peer node must install the chain code. The application can also use this attribute to determine which peer node to send the chain code installation request to. Default value: true endorsingPeer: true # optional. The peer node must install the chain code. Only query whether the peer node will be sent a transaction proposal. The application can also use this attribute to determine which peer node to send the chain code installation request to. Default value: true chaincodeQuery: true # optional. Whether it is possible to send a proposal to the peer node that does not have a chain code query, such as queryBlock (), # queryTransaction (), etc. Default value: true. LedgerQuery: true # is optional. Whether the peer node is the registered target of the SDK event listener, all peer nodes can produce events, # but usually only one needs to connect to listen to the event. Default value: true. EventSource: true # optional. The application uses the following options to perform channel operations, such as obtaining channel configuration policies: # optional, obtaining channel configuration block queryChannelConfig: # optional, minimum number of successful response nodes minResponses: 1 # optional maxTargets: 1 # optional Query the retry option of the configuration block retryOpts: # optional, the number of retries attempts: 5 # optional, and the fallback interval of the first retry initialBackoff: 500ms # optional Maximum fallback interval for retries maxBackoff: 5s backoffFactor: 2.The list of participating organizations in the Fabric blockchain network organizations: org1: mspid: Org1MSP # organization's MSP storage location Absolute path or relative cryptoconfig path cryptoPath: peerOrganizations/org1.example.com/users/ {username} @ org1.example.com/msp peers:-peer0.org1.example.com-peer1.org1.example.com # optional, issued by certification authority × × × Ming. Fabric-CA is a special certificate authority that provides REST API to support dynamic certificate management. Such as registration, revocation, re-registration # the following sections only set certificateAuthorities for the Fabric-CA server: #-ca.org1.example.com # Orderer organization name ordererorg: # organization's MSPID mspID: OrdererMSP # load the keys and certificates required by the user Absolute path or relative path cryptoPath: ordererOrganizations/example.com/users/ {username} @ example.com/msp# send transaction request or orderers list to which channel creation or update request # if more than one orderer,SDK is defined and which orderer is implemented by the code, specify the orderers: # orderer node, you can define multiple orderer.example.com: url: orderer.example.com:7050 # the following attributes are defined by the gRPC library Will be passed to the gRPC client constructor grpcOptions: ssl-target-name-override: orderer.example.com # the following parameters are used to set the keepalive policy on the server, an incompatible setting will cause the connection to close # when keep-alive-time is set to 0 or less than the parameter of the active client The following parameters fail keep-alive-time: 0s keep-alive-timeout: 20s keep-alive-permit: false fail-fast: false allow-insecure: false tlsCACerts: # absolute path to the certificate # path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES_PATH} / ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem# peers node list peers: # peer node definition You can define the absolute path of multiple peer0.org1.example.com: # URL to send endorsement and query requests url: peer0.org1.example.com:7051 grpcOptions: ssl-target-name-override: peer0.org1.example.com keep-alive-time: 0s keep-alive-timeout: 20s keep-alive-permit: false fail-fast: false allow-insecure: false tlsCACerts: # certificate # path: ${GOPATH} / src/github.com/hyperledger/fabric-sdk-go/$ {CRYPTOCONFIG_FIXTURES_PATH} / peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report