Skip to content

Commit a2a17a1

Browse files
committed
splitting the peer into a client and a server - part 1
Signed-off-by: Fedor Partanskiy <fredprtnsk@gmail.com>
1 parent 9c01421 commit a2a17a1

116 files changed

Lines changed: 3551 additions & 410 deletions

File tree

Some content is hidden

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

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 peercli
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.peercli := $(PKGNAME)/cmd/peercli
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/Admin@org1.example.com/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+
peercli 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+
peercli chaincode query -C mychannel -n basicgo -c '{"Args":["GetAllAssets"]}'
7373
7474
docker logs peer0.org1.example.com
7575

cmd/peer/main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ func main() {
4242

4343
mainCmd.AddCommand(version.Cmd())
4444
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))
49-
45+
// Deprecated: use peercli
46+
mainCmd.AddCommand(chaincode.Cmd(nil, cryptoProvider, false))
47+
// Deprecated: use peercli or osnadmin
48+
mainCmd.AddCommand(channel.Cmd(nil, false))
49+
// Deprecated: use peercli
50+
mainCmd.AddCommand(lifecycle.Cmd(cryptoProvider, false))
51+
// Deprecated: use peercli
52+
mainCmd.AddCommand(snapshot.Cmd(cryptoProvider, false))
5053
// On failure Cobra prints the usage message and error string, so we only
5154
// need to exit with a non-0 status
5255
if mainCmd.Execute() != nil {

cmd/peercli/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: "peercli"}
28+
29+
func main() {
30+
setEnvConfig(viper.GetViper())
31+
32+
// Define command-line flags that are valid for all peercli 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, true))
44+
mainCmd.AddCommand(channel.Cmd(nil, true))
45+
mainCmd.AddCommand(lifecycle.Cmd(cryptoProvider, true))
46+
mainCmd.AddCommand(snapshot.Cmd(cryptoProvider, true))
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/peercli/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+
}

core/chaincode/platforms/golang/platform.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (p *Platform) Name() string {
4141
// ValidatePath is used to ensure that path provided points to something that
4242
// looks like go chainccode.
4343
//
44-
// NOTE: this is only used at the _client_ side by the peer CLI.
44+
// NOTE: this is only used at the _client_ side by the peercli.
4545
func (p *Platform) ValidatePath(rawPath string) error {
4646
_, err := DescribeCode(rawPath)
4747
if err != nil {
@@ -54,7 +54,7 @@ func (p *Platform) ValidatePath(rawPath string) error {
5454
// NormalizePath is used to extract a relative module path from a module root.
5555
// This should not impact legacy GOPATH chaincode.
5656
//
57-
// NOTE: this is only used at the _client_ side by the peer CLI.
57+
// NOTE: this is only used at the _client_ side by the peercli.
5858
func (p *Platform) NormalizePath(rawPath string) (string, error) {
5959
modInfo, err := moduleInfo(rawPath)
6060
if err != nil {
@@ -115,7 +115,7 @@ var gzipCompressionLevel = gzip.DefaultCompression
115115
// GetDeploymentPayload creates a gzip compressed tape archive that contains the
116116
// required assets to build and run go chaincode.
117117
//
118-
// NOTE: this is only used at the _client_ side by the peer CLI.
118+
// NOTE: this is only used at the _client_ side by the peercli.
119119
func (p *Platform) GetDeploymentPayload(codepath string) ([]byte, error) {
120120
codeDescriptor, err := DescribeCode(codepath)
121121
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 peercli 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/command_ref.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ Commands Reference
99
commands/peerlifecycle.md
1010
commands/peerchannel.md
1111
commands/peersnapshot.md
12-
commands/peerversion.md
1312
commands/peernode.md
13+
commands/peerversion.md
14+
commands/peerclicommand.md
15+
commands/peerclichaincode.md
16+
commands/peerclilifecycle.md
17+
commands/peerclichannel.md
18+
commands/peerclisnapshot.md
19+
commands/peercliversion.md
1420
commands/osnadminchannel.md
1521
commands/configtxgen.md
1622
commands/configtxlator.md

docs/source/commands/peerchaincode.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ localhost:7051"`.
7777

7878
## peer chaincode invoke
7979
```
80-
Invoke the specified chaincode. It will try to commit the endorsed transaction to the network.
80+
[DEPRECATED] Invoke the specified chaincode. It will try to commit the endorsed transaction to the network. Instead of this command, use "peercli chaincode invoke".
8181
8282
Usage:
8383
peer chaincode invoke [flags]
@@ -110,7 +110,7 @@ Global Flags:
110110

111111
## peer chaincode query
112112
```
113-
Get endorsed result of chaincode function call and print it. It won't generate transaction.
113+
[DEPRECATED] Get endorsed result of chaincode function call and print it. It won't generate transaction. Instead of this command, use "peercli chaincode query".
114114
115115
Usage:
116116
peer chaincode query [flags]

docs/source/commands/peerchannel.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ The `peer channel` command has the following subcommands:
2525

2626
## peer channel
2727
```
28-
Operate a channel: create|fetch|join|joinbysnapshot|joinbysnapshotstatus|list|update|signconfigtx|getinfo.
28+
[DEPRECATED] Operate a channel: create|fetch|join|joinbysnapshot|joinbysnapshotstatus|list|update|signconfigtx|getinfo. Instead of this command, use "peercli channel".
2929
3030
Usage:
3131
peer channel [command]
3232
3333
Available Commands:
34-
create [DEPRECATED] Create a channel
35-
fetch Fetch a block
36-
getinfo get blockchain information of a specified channel.
37-
join Joins the peer to a channel.
38-
joinbysnapshot Joins the peer to a channel by the specified snapshot
39-
joinbysnapshotstatus Query if joinbysnapshot is running for any channel
40-
list List of channels peer has joined.
41-
signconfigtx Signs a configtx update.
42-
update Send a configtx update.
34+
create [DEPRECATED] Create a channel (use the "osnadmin join").
35+
fetch [DEPRECATED] Fetch a block (use the "peercli channel fetch" or "osnadmin fetch").
36+
getinfo [DEPRECATED] get blockchain information of a specified channel (use the "peercli channel getinfo").
37+
join [DEPRECATED] Joins the peer to a channel (use the "peercli channel join").
38+
joinbysnapshot [DEPRECATED] Joins the peer to a channel by the specified snapshot (use the "peercli channel joinbysnapshot").
39+
joinbysnapshotstatus [DEPRECATED] Query if joinbysnapshot is running for any channel (use the "peercli channel joinbysnapshotstatus").
40+
list [DEPRECATED] List of channels peer has joined (use the "peercli channel list").
41+
signconfigtx [DEPRECATED] Signs a configtx update (use the "peercli channel signconfigtx").
42+
update [DEPRECATED] Send a configtx update (use the "osnadmin update").
4343
4444
Flags:
4545
--cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
@@ -86,7 +86,7 @@ Global Flags:
8686

8787
## peer channel fetch
8888
```
89-
Fetch a specified block, writing it to a file.
89+
[DEPRECATED] Fetch a specified block from peer or orderer, writing it to a file. Instead of this command, use "peercli channel fetch" or "osnadmin fetch".
9090
9191
Usage:
9292
peer channel fetch <newest|oldest|config|(number)> [outputfile] [flags]
@@ -111,7 +111,7 @@ Global Flags:
111111

112112
## peer channel getinfo
113113
```
114-
get blockchain information of a specified channel. Requires '-c'.
114+
[DEPRECATED] get blockchain information of a specified channel. Requires '-c'. Instead of this command, use "peercli channel getinfo".
115115
116116
Usage:
117117
peer channel getinfo [flags]
@@ -135,7 +135,7 @@ Global Flags:
135135

136136
## peer channel join
137137
```
138-
Joins the peer to a channel.
138+
[DEPRECATED] Joins the peer to a channel. Instead of this command, use "peercli channel join".
139139
140140
Usage:
141141
peer channel join [flags]
@@ -159,7 +159,7 @@ Global Flags:
159159

160160
## peer channel joinbysnapshot
161161
```
162-
Joins the peer to a channel by the specified snapshot
162+
[DEPRECATED] Joins the peer to a channel by the specified snapshot. Instead of this command, use "peercli channel joinbysnapshot".
163163
164164
Usage:
165165
peer channel joinbysnapshot [flags]
@@ -183,7 +183,7 @@ Global Flags:
183183

184184
## peer channel joinbysnapshotstatus
185185
```
186-
Query if joinbysnapshot is running for any channel
186+
[DEPRECATED] Query if joinbysnapshot is running for any channel. Instead of this command, use "peercli channel joinbysnapshotstatus".
187187
188188
Usage:
189189
peer channel joinbysnapshotstatus [flags]
@@ -206,7 +206,7 @@ Global Flags:
206206

207207
## peer channel list
208208
```
209-
List of channels peer has joined.
209+
[DEPRECATED] List of channels peer has joined. Instead of this command, use "peercli channel list".
210210
211211
Usage:
212212
peer channel list [flags]
@@ -229,7 +229,7 @@ Global Flags:
229229

230230
## peer channel signconfigtx
231231
```
232-
Signs the supplied configtx update file in place on the filesystem. Requires '-f'.
232+
[DEPRECATED] Signs the supplied configtx update file in place on the filesystem. Requires '-f'. Instead of this command, use "peercli channel signconfigtx".
233233
234234
Usage:
235235
peer channel signconfigtx [flags]
@@ -253,7 +253,7 @@ Global Flags:
253253

254254
## peer channel update
255255
```
256-
Signs and sends the supplied configtx update file to the channel. Requires '-f', '-o', '-c'.
256+
[DEPRECATED] Signs and sends the supplied configtx update file to the channel. Requires '-f', '-o', '-c'. . Instead of this command, use Orderer Service Node (OSN).
257257
258258
Usage:
259259
peer channel update [flags]

0 commit comments

Comments
 (0)