Skip to content

Commit cc13999

Browse files
committed
splitting the peer into a client and a server
Signed-off-by: Fedor Partanskiy <[email protected]>
1 parent cdd7bea commit cc13999

File tree

85 files changed

+1071
-802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1071
-802
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ GO_TAGS ?=
8686
RELEASE_EXES = orderer $(TOOLS_EXES)
8787
RELEASE_IMAGES = baseos ccenv orderer peer
8888
RELEASE_PLATFORMS = darwin-amd64 darwin-arm64 linux-amd64 linux-arm64 windows-amd64
89-
TOOLS_EXES = configtxgen configtxlator cryptogen discover ledgerutil osnadmin peer
89+
TOOLS_EXES = configtxgen configtxlator cryptogen discover ledgerutil osnadmin peer cli
9090

9191
pkgmap.configtxgen := $(PKGNAME)/cmd/configtxgen
9292
pkgmap.configtxlator := $(PKGNAME)/cmd/configtxlator
@@ -96,6 +96,7 @@ pkgmap.ledgerutil := $(PKGNAME)/cmd/ledgerutil
9696
pkgmap.orderer := $(PKGNAME)/cmd/orderer
9797
pkgmap.osnadmin := $(PKGNAME)/cmd/osnadmin
9898
pkgmap.peer := $(PKGNAME)/cmd/peer
99+
pkgmap.cli := $(PKGNAME)/cmd/cli
99100

100101
.DEFAULT_GOAL := all
101102

RELEASING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.e
6767
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
6868
export CORE_PEER_ADDRESS=localhost:7051
6969
70-
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basicgo --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'
70+
cli chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basicgo --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'
7171
72-
peer chaincode query -C mychannel -n basicgo -c '{"Args":["GetAllAssets"]}'
72+
cli chaincode query -C mychannel -n basicgo -c '{"Args":["GetAllAssets"]}'
7373
7474
docker logs peer0.org1.example.com
7575

cmd/cli/main.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package main
8+
9+
import (
10+
_ "net/http/pprof"
11+
"os"
12+
"strings"
13+
14+
"github.com/hyperledger/fabric-lib-go/bccsp/factory"
15+
"github.com/hyperledger/fabric/internal/peer/chaincode"
16+
"github.com/hyperledger/fabric/internal/peer/channel"
17+
"github.com/hyperledger/fabric/internal/peer/common"
18+
"github.com/hyperledger/fabric/internal/peer/lifecycle"
19+
"github.com/hyperledger/fabric/internal/peer/snapshot"
20+
"github.com/hyperledger/fabric/internal/peer/version"
21+
"github.com/spf13/cobra"
22+
"github.com/spf13/viper"
23+
)
24+
25+
// The main command describes the service and
26+
// defaults to printing the help message.
27+
var mainCmd = &cobra.Command{Use: "cli"}
28+
29+
func main() {
30+
setEnvConfig(viper.GetViper())
31+
32+
// Define command-line flags that are valid for all cli commands and
33+
// subcommands.
34+
mainFlags := mainCmd.PersistentFlags()
35+
36+
mainFlags.String("logging-level", "", "Legacy logging level flag")
37+
viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))
38+
mainFlags.MarkHidden("logging-level")
39+
40+
cryptoProvider := factory.GetDefault()
41+
42+
mainCmd.AddCommand(version.Cmd())
43+
mainCmd.AddCommand(chaincode.Cmd(nil, cryptoProvider))
44+
mainCmd.AddCommand(channel.Cmd(nil))
45+
mainCmd.AddCommand(lifecycle.Cmd(cryptoProvider))
46+
mainCmd.AddCommand(snapshot.Cmd(cryptoProvider))
47+
48+
// On failure Cobra prints the usage message and error string, so we only
49+
// need to exit with a non-0 status
50+
if mainCmd.Execute() != nil {
51+
os.Exit(1)
52+
}
53+
}
54+
55+
func setEnvConfig(v *viper.Viper) {
56+
v.SetEnvPrefix(common.CmdRoot)
57+
v.AllowEmptyEnv(true)
58+
v.AutomaticEnv()
59+
replacer := strings.NewReplacer(".", "_")
60+
v.SetEnvKeyReplacer(replacer)
61+
}

cmd/cli/main_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package main
8+
9+
import (
10+
"testing"
11+
12+
"github.com/spf13/viper"
13+
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
15+
)
16+
17+
func TestSetEnvConfig(t *testing.T) {
18+
vp := viper.New()
19+
t.Setenv("CORE_FRUIT", "Apple")
20+
t.Setenv("CORE_COLOR", "")
21+
err := vp.BindEnv("Fruit")
22+
require.NoError(t, err)
23+
err = vp.BindEnv("Color")
24+
require.NoError(t, err)
25+
vp.SetDefault("Color", "Green")
26+
27+
setEnvConfig(vp)
28+
29+
assert.Equal(t, "Apple", vp.Get("Fruit"))
30+
assert.Equal(t, "", vp.Get("Color"))
31+
}

cmd/peer/main.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ import (
1111
"os"
1212
"strings"
1313

14-
"github.com/hyperledger/fabric-lib-go/bccsp/factory"
15-
"github.com/hyperledger/fabric/internal/peer/chaincode"
16-
"github.com/hyperledger/fabric/internal/peer/channel"
1714
"github.com/hyperledger/fabric/internal/peer/common"
18-
"github.com/hyperledger/fabric/internal/peer/lifecycle"
1915
"github.com/hyperledger/fabric/internal/peer/node"
20-
"github.com/hyperledger/fabric/internal/peer/snapshot"
2116
"github.com/hyperledger/fabric/internal/peer/version"
2217
"github.com/spf13/cobra"
2318
"github.com/spf13/viper"
@@ -38,14 +33,8 @@ func main() {
3833
viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))
3934
mainFlags.MarkHidden("logging-level")
4035

41-
cryptoProvider := factory.GetDefault()
42-
4336
mainCmd.AddCommand(version.Cmd())
4437
mainCmd.AddCommand(node.Cmd())
45-
mainCmd.AddCommand(chaincode.Cmd(nil, cryptoProvider))
46-
mainCmd.AddCommand(channel.Cmd(nil))
47-
mainCmd.AddCommand(lifecycle.Cmd(cryptoProvider))
48-
mainCmd.AddCommand(snapshot.Cmd(cryptoProvider))
4938

5039
// On failure Cobra prints the usage message and error string, so we only
5140
// need to exit with a non-0 status

core/chaincode/platforms/golang/platform.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (p *Platform) Name() string {
3939
// ValidatePath is used to ensure that path provided points to something that
4040
// looks like go chainccode.
4141
//
42-
// NOTE: this is only used at the _client_ side by the peer CLI.
42+
// NOTE: this is only used at the _client_ side by the CLI.
4343
func (p *Platform) ValidatePath(rawPath string) error {
4444
_, err := DescribeCode(rawPath)
4545
if err != nil {
@@ -52,7 +52,7 @@ func (p *Platform) ValidatePath(rawPath string) error {
5252
// NormalizePath is used to extract a relative module path from a module root.
5353
// This should not impact legacy GOPATH chaincode.
5454
//
55-
// NOTE: this is only used at the _client_ side by the peer CLI.
55+
// NOTE: this is only used at the _client_ side by the CLI.
5656
func (p *Platform) NormalizePath(rawPath string) (string, error) {
5757
modInfo, err := moduleInfo(rawPath)
5858
if err != nil {
@@ -113,7 +113,7 @@ var gzipCompressionLevel = gzip.DefaultCompression
113113
// GetDeploymentPayload creates a gzip compressed tape archive that contains the
114114
// required assets to build and run go chaincode.
115115
//
116-
// NOTE: this is only used at the _client_ side by the peer CLI.
116+
// NOTE: this is only used at the _client_ side by the CLI.
117117
func (p *Platform) GetDeploymentPayload(codepath string) ([]byte, error) {
118118
codeDescriptor, err := DescribeCode(codepath)
119119
if err != nil {

core/ledger/kvledger/kv_ledger_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ func (p *Provider) Close() {
429429

430430
// deletePartialLedgers scans for and deletes any ledger with a status of UNDER_CONSTRUCTION or UNDER_DELETION.
431431
// UNDER_CONSTRUCTION ledgers represent residual structures created as a side effect of a crash during ledger creation.
432-
// UNDER_DELETION ledgers represent residual structures created as a side effect of a crash during a peer channel unjoin.
432+
// UNDER_DELETION ledgers represent residual structures created as a side effect of a crash during a cli channel unjoin.
433433
func (p *Provider) deletePartialLedgers() error {
434434
logger.Debug("Removing ledgers in state UNDER_CONSTRUCTION or UNDER_DELETION")
435435
itr := p.idStore.db.GetIterator(metadataKeyPrefix, metadataKeyStop)

docs/source/cc_basic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export PATH=${PWD}/../bin:$PATH
6868
export FABRIC_CFG_PATH=${PWD}/../config
6969

7070
# invoke the function
71-
peer chaincode query -C mychannel -n basicts -c '{"Args":["org.hyperledger.fabric:GetMetadata"]}' | jq
71+
cli chaincode query -C mychannel -n basicts -c '{"Args":["org.hyperledger.fabric:GetMetadata"]}' | jq
7272
```
7373

7474
Note that `| jq` can be omitted if `jq` is not installed. However, the metadata shows details of the deployed contract in JSON, so `jq` provides legibility. To confirm that the smart contract is working, repeat the prior commands for `org2`.

docs/source/cc_launcher.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This approach limited chaincode implementations to a handful of languages, requi
66

77
Starting with Fabric 2.0, External Builders and Launchers address these limitations by enabling operators to extend the peer with programs that can build, launch, and discover chaincode. To leverage this capability you will need to create your own buildpack and then modify the peer core.yaml to include a new `externalBuilder` configuration element which lets the peer know an external builder is available. The following sections describe the details of this process.
88

9-
Note that if no configured external builder claims a chaincode package, the peer will attempt to process the package as if it were created with the standard Fabric packaging tools such as the peer CLI.
9+
Note that if no configured external builder claims a chaincode package, the peer will attempt to process the package as if it were created with the standard Fabric packaging tools such as the CLI.
1010

1111
**Note:** This is an advanced feature which will likely require custom packaging of the peer image with everything your builders and launchers depend on unless your builders and launchers are simple enough, such as those used in the [basic asset transfer external chaincode Fabric sample](https://github.com/hyperledger/fabric-samples/blob/main/asset-transfer-basic/chaincode-external). For example, the following samples use `go` and `bash`, which are not included in the current official `fabric-peer` image.
1212

@@ -202,11 +202,11 @@ If you do not need to fallback to the legacy Docker build process for your chain
202202

203203
## Chaincode packages
204204

205-
A chaincode package contains chaincode and associated metadata in a compressed gzip file that can be installed to a peer. The peer command `peer lifecycle chaincode package` can be used to create a chaincode package. You can also create a chaincode package using third party tools.
205+
A chaincode package contains chaincode and associated metadata in a compressed gzip file that can be installed to a peer. The peer command `cli lifecycle chaincode package` can be used to create a chaincode package. You can also create a chaincode package using third party tools.
206206

207207
### Lifecycle chaincode package contents
208208

209-
A lifecycle chaincode package contains two files. The first file, `code.tar.gz` is a gzip compressed POSIX tape archive. This file includes the source artifacts for the chaincode. Packages created by the peer CLI will place the chaincode implementation source under the `src` directory and chaincode metadata (like CouchDB indexes) under the `META-INF` directory.
209+
A lifecycle chaincode package contains two files. The first file, `code.tar.gz` is a gzip compressed POSIX tape archive. This file includes the source artifacts for the chaincode. Packages created by the CLI will place the chaincode implementation source under the `src` directory and chaincode metadata (like CouchDB indexes) under the `META-INF` directory.
210210

211211
The second file, `metadata.json` is a JSON document with three keys:
212212
- `type`: the chaincode type (e.g. GOLANG, JAVA, NODE)

docs/source/cc_service.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (s *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
234234
235235
//NOTE - parameters such as ccid and endpoint information are hard coded here for illustration. This can be passed in a variety of standard ways
236236
func main() {
237-
//The ccid is assigned to the chaincode on install (using the “peer lifecycle chaincode install <package>” command) for instance
237+
//The ccid is assigned to the chaincode on install (using the “cli lifecycle chaincode install <package>” command) for instance
238238
ccid := "mycc:fcbf8724572d42e859a7dd9a7cd8e2efb84058292017df6e3d89178b64e6c831"
239239
240240
server := &shim.ChaincodeServer{
@@ -253,7 +253,7 @@ func main() {
253253
```
254254
The key to running the chaincode as an external service is the use of `shim.ChaincodeServer`. This uses the new shim API `shim.ChaincodeServer` with the chaincode service properties described below:
255255

256-
* **CCID** (string)- CCID should match chaincode's package name on peer. This is the `CCID` associated with the installed chaincode as returned by the `peer lifecycle chaincode install <package>` CLI command. This can be obtained post-install using the "peer lifecycle chaincode queryinstalled" command.
256+
* **CCID** (string)- CCID should match chaincode's package name on peer. This is the `CCID` associated with the installed chaincode as returned by the `cli lifecycle chaincode install <package>` CLI command. This can be obtained post-install using the "cli lifecycle chaincode queryinstalled" command.
257257
* **Address** (string) - Address is the listen address of the chaincode server
258258
* **CC** (Chaincode) - CC is the chaincode that handles Init and Invoke
259259
* **TLSProps** (TLSProperties) - TLSProps is the TLS properties passed to chaincode server

0 commit comments

Comments
 (0)