Skip to content

Commit 0bd607a

Browse files
author
Srinivasan Muralidharan
committed
FAB-1128 finalize protos - remove api and devops
https://jira.hyperledger.org/browse/FAB-1128 This changeset takes closer to final protos . remove protos for devops and api . remove Message and related structures . copies needed function from devops into peer/chaincode . with gossip support . peer no longer is a chat server . peer no longer provides discovery . peer no longer syncs Change-Id: I72a4dfff8e3325b44da4123ad2e137cf97bccb82 Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent 8ae8147 commit 0bd607a

Some content is hidden

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

41 files changed

+319
-6398
lines changed

core/devops.go

+12-246
Original file line numberDiff line numberDiff line change
@@ -19,78 +19,42 @@ package core
1919
import (
2020
"errors"
2121
"fmt"
22-
"strings"
2322

2423
"github.com/op/go-logging"
2524
"github.com/spf13/viper"
2625
"golang.org/x/net/context"
2726

28-
"encoding/asn1"
29-
"encoding/base64"
30-
"sync"
31-
3227
"github.com/hyperledger/fabric/core/chaincode"
3328
"github.com/hyperledger/fabric/core/chaincode/platforms"
3429
"github.com/hyperledger/fabric/core/container"
35-
crypto "github.com/hyperledger/fabric/core/crypto"
36-
"github.com/hyperledger/fabric/core/peer"
37-
"github.com/hyperledger/fabric/core/util"
3830
pb "github.com/hyperledger/fabric/protos/peer"
3931
)
4032

4133
var devopsLogger = logging.MustGetLogger("devops")
4234

4335
// NewDevopsServer creates and returns a new Devops server instance.
44-
func NewDevopsServer(coord peer.MessageHandlerCoordinator) *Devops {
36+
func NewDevopsServer() *Devops {
4537
d := new(Devops)
46-
d.coord = coord
47-
d.isSecurityEnabled = viper.GetBool("security.enabled")
48-
d.bindingMap = &bindingMap{m: make(map[string]crypto.TransactionHandler)}
4938
return d
5039
}
5140

52-
// bindingMap Used to store map of binding to TransactionHandler
53-
type bindingMap struct {
54-
sync.RWMutex
55-
m map[string]crypto.TransactionHandler
56-
}
57-
5841
// Devops implementation of Devops services
5942
type Devops struct {
60-
coord peer.MessageHandlerCoordinator
61-
isSecurityEnabled bool
62-
bindingMap *bindingMap
63-
}
64-
65-
func (b *bindingMap) getKeyFromBinding(binding []byte) string {
66-
return base64.StdEncoding.EncodeToString(binding)
67-
}
68-
69-
func (b *bindingMap) addBinding(bindingToAdd []byte, txHandler crypto.TransactionHandler) {
70-
b.Lock()
71-
defer b.Unlock()
72-
key := b.getKeyFromBinding(bindingToAdd)
73-
b.m[key] = txHandler
7443
}
7544

76-
func (b *bindingMap) getTxHandlerForBinding(binding []byte) (crypto.TransactionHandler, error) {
77-
b.Lock()
78-
defer b.Unlock()
79-
key := b.getKeyFromBinding(binding)
80-
txHandler, ok := b.m[key]
81-
if ok != true {
82-
// TXhandler not found by key, return error
83-
return nil, fmt.Errorf("Transaction handler not found for binding key = %s", key)
45+
// checkSpec to see if chaincode resides within current package capture for language.
46+
func checkSpec(spec *pb.ChaincodeSpec) error {
47+
// Don't allow nil value
48+
if spec == nil {
49+
return errors.New("Expected chaincode specification, nil received")
8450
}
85-
return txHandler, nil
86-
}
87-
88-
// Login establishes the security context with the Devops service
89-
func (d *Devops) Login(ctx context.Context, secret *pb.Secret) (*pb.Response, error) {
9051

91-
return &pb.Response{Status: pb.Response_FAILURE, Msg: []byte("login command has been removed")}, nil
52+
platform, err := platforms.Find(spec.Type)
53+
if err != nil {
54+
return fmt.Errorf("Failed to determine platform type: %s", err)
55+
}
9256

93-
// TODO: Handle timeout and expiration
57+
return platform.ValidateSpec(spec)
9458
}
9559

9660
// Build builds the supplied chaincode image
@@ -99,7 +63,7 @@ func (*Devops) Build(context context.Context, spec *pb.ChaincodeSpec) (*pb.Chain
9963
var codePackageBytes []byte
10064
if mode != chaincode.DevModeUserRunsChaincode {
10165
devopsLogger.Debugf("Received build request for chaincode spec: %v", spec)
102-
if err := CheckSpec(spec); err != nil {
66+
if err := checkSpec(spec); err != nil {
10367
return nil, err
10468
}
10569

@@ -117,201 +81,3 @@ func (*Devops) Build(context context.Context, spec *pb.ChaincodeSpec) (*pb.Chain
11781
chaincodeDeploymentSpec := &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec, CodePackage: codePackageBytes}
11882
return chaincodeDeploymentSpec, nil
11983
}
120-
121-
// GetChaincodeBytes get chaincode deployment spec given the chaincode spec
122-
func GetChaincodeBytes(context context.Context, spec *pb.ChaincodeSpec) (*pb.ChaincodeDeploymentSpec, error) {
123-
mode := viper.GetString("chaincode.mode")
124-
var codePackageBytes []byte
125-
if mode != chaincode.DevModeUserRunsChaincode {
126-
devopsLogger.Debugf("Received build request for chaincode spec: %v", spec)
127-
var err error
128-
if err = CheckSpec(spec); err != nil {
129-
return nil, err
130-
}
131-
132-
codePackageBytes, err = container.GetChaincodePackageBytes(spec)
133-
if err != nil {
134-
err = fmt.Errorf("Error getting chaincode package bytes: %s", err)
135-
devopsLogger.Error(fmt.Sprintf("%s", err))
136-
return nil, err
137-
}
138-
}
139-
chaincodeDeploymentSpec := &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec, CodePackage: codePackageBytes}
140-
return chaincodeDeploymentSpec, nil
141-
}
142-
143-
// Deploy deploys the supplied chaincode image to the validators through a transaction
144-
func (d *Devops) Deploy(ctx context.Context, spec *pb.ChaincodeSpec) (*pb.ChaincodeDeploymentSpec, error) {
145-
// get the deployment spec
146-
chaincodeDeploymentSpec, err := GetChaincodeBytes(ctx, spec)
147-
148-
if err != nil {
149-
devopsLogger.Error(fmt.Sprintf("Error deploying chaincode spec: %v\n\n error: %s", spec, err))
150-
return nil, err
151-
}
152-
153-
// Now create the Transactions message and send to Peer.
154-
155-
transID := chaincodeDeploymentSpec.ChaincodeSpec.ChaincodeID.Name
156-
157-
var tx *pb.Transaction
158-
159-
if devopsLogger.IsEnabledFor(logging.DEBUG) {
160-
devopsLogger.Debugf("Creating deployment transaction (%s)", transID)
161-
}
162-
tx, err = pb.NewChaincodeDeployTransaction(chaincodeDeploymentSpec, transID)
163-
if err != nil {
164-
return nil, fmt.Errorf("Error deploying chaincode: %s ", err)
165-
}
166-
167-
if devopsLogger.IsEnabledFor(logging.DEBUG) {
168-
devopsLogger.Debugf("Sending deploy transaction (%s) to validator", tx.Txid)
169-
}
170-
resp := d.coord.ExecuteTransaction(tx)
171-
if resp.Status == pb.Response_FAILURE {
172-
err = errors.New(string(resp.Msg))
173-
}
174-
175-
return chaincodeDeploymentSpec, err
176-
}
177-
178-
func (d *Devops) invokeOrQuery(ctx context.Context, chaincodeInvocationSpec *pb.ChaincodeInvocationSpec, attributes []string, invoke bool) (*pb.Response, error) {
179-
180-
if chaincodeInvocationSpec.ChaincodeSpec.ChaincodeID.Name == "" {
181-
return nil, errors.New("name not given for invoke/query")
182-
}
183-
184-
// Now create the Transactions message and send to Peer.
185-
var customIDgenAlg = strings.ToLower(chaincodeInvocationSpec.IdGenerationAlg)
186-
var id string
187-
var generr error
188-
if invoke {
189-
if customIDgenAlg != "" {
190-
ctorbytes, merr := asn1.Marshal(*chaincodeInvocationSpec.ChaincodeSpec.CtorMsg)
191-
if merr != nil {
192-
return nil, fmt.Errorf("Error marshalling constructor: %s", merr)
193-
}
194-
id, generr = util.GenerateIDWithAlg(customIDgenAlg, ctorbytes)
195-
if generr != nil {
196-
return nil, generr
197-
}
198-
} else {
199-
id = util.GenerateUUID()
200-
}
201-
} else {
202-
id = util.GenerateUUID()
203-
}
204-
devopsLogger.Infof("Transaction ID: %v", id)
205-
var transaction *pb.Transaction
206-
var err error
207-
var sec crypto.Client
208-
209-
transaction, err = d.createExecTx(chaincodeInvocationSpec, attributes, id, invoke, sec)
210-
if err != nil {
211-
return nil, err
212-
}
213-
devopsLogger.Debugf("Sending invocation transaction (%s) to validator", transaction.Txid)
214-
resp := d.coord.ExecuteTransaction(transaction)
215-
if resp.Status == pb.Response_FAILURE {
216-
err = errors.New(string(resp.Msg))
217-
} else {
218-
if !invoke && nil != sec && viper.GetBool("security.privacy") {
219-
if resp.Msg, err = sec.DecryptQueryResult(transaction, resp.Msg); nil != err {
220-
devopsLogger.Errorf("Failed decrypting query transaction result %s", string(resp.Msg[:]))
221-
//resp = &pb.Response{Status: pb.Response_FAILURE, Msg: []byte(err.Error())}
222-
}
223-
}
224-
}
225-
return resp, err
226-
}
227-
228-
func (d *Devops) createExecTx(spec *pb.ChaincodeInvocationSpec, attributes []string, uuid string, invokeTx bool, sec crypto.Client) (*pb.Transaction, error) {
229-
var tx *pb.Transaction
230-
var err error
231-
232-
//TODO What should we do with the attributes
233-
if nil != sec {
234-
if devopsLogger.IsEnabledFor(logging.DEBUG) {
235-
devopsLogger.Debugf("Creating secure invocation transaction %s", uuid)
236-
}
237-
if invokeTx {
238-
tx, err = sec.NewChaincodeExecute(spec, uuid, attributes...)
239-
} else {
240-
tx, err = sec.NewChaincodeQuery(spec, uuid, attributes...)
241-
}
242-
if nil != err {
243-
return nil, err
244-
}
245-
} else {
246-
if devopsLogger.IsEnabledFor(logging.DEBUG) {
247-
devopsLogger.Debugf("Creating invocation transaction (%s)", uuid)
248-
}
249-
var t pb.Transaction_Type
250-
if invokeTx {
251-
t = pb.Transaction_CHAINCODE_INVOKE
252-
} else {
253-
t = pb.Transaction_CHAINCODE_QUERY
254-
}
255-
tx, err = pb.NewChaincodeExecute(spec, uuid, t)
256-
if nil != err {
257-
return nil, err
258-
}
259-
}
260-
return tx, nil
261-
}
262-
263-
// Invoke performs the supplied invocation on the specified chaincode through a transaction
264-
func (d *Devops) Invoke(ctx context.Context, chaincodeInvocationSpec *pb.ChaincodeInvocationSpec) (*pb.Response, error) {
265-
return d.invokeOrQuery(ctx, chaincodeInvocationSpec, chaincodeInvocationSpec.ChaincodeSpec.Attributes, true)
266-
}
267-
268-
// Query performs the supplied query on the specified chaincode through a transaction
269-
func (d *Devops) Query(ctx context.Context, chaincodeInvocationSpec *pb.ChaincodeInvocationSpec) (*pb.Response, error) {
270-
return d.invokeOrQuery(ctx, chaincodeInvocationSpec, chaincodeInvocationSpec.ChaincodeSpec.Attributes, false)
271-
}
272-
273-
// CheckSpec to see if chaincode resides within current package capture for language.
274-
func CheckSpec(spec *pb.ChaincodeSpec) error {
275-
// Don't allow nil value
276-
if spec == nil {
277-
return errors.New("Expected chaincode specification, nil received")
278-
}
279-
280-
platform, err := platforms.Find(spec.Type)
281-
if err != nil {
282-
return fmt.Errorf("Failed to determine platform type: %s", err)
283-
}
284-
285-
return platform.ValidateSpec(spec)
286-
}
287-
288-
// EXP_GetApplicationTCert retrieves an application TCert for the supplied user
289-
func (d *Devops) EXP_GetApplicationTCert(ctx context.Context, secret *pb.Secret) (*pb.Response, error) {
290-
291-
devopsLogger.Warning("GetApplicationTCert no longer supported")
292-
return &pb.Response{Status: pb.Response_FAILURE, Msg: []byte("no longer supported")}, nil
293-
// TODO: Handle timeout and expiration
294-
}
295-
296-
// EXP_PrepareForTx prepares a binding/TXHandler pair to be used in subsequent TX
297-
func (d *Devops) EXP_PrepareForTx(ctx context.Context, secret *pb.Secret) (*pb.Response, error) {
298-
299-
devopsLogger.Warning("PrepareForTx no longer supported")
300-
return &pb.Response{Status: pb.Response_FAILURE, Msg: []byte("no longer supported")}, nil
301-
// TODO: Handle timeout and expiration
302-
}
303-
304-
// EXP_ProduceSigma produces a sigma as []byte and returns in response
305-
func (d *Devops) EXP_ProduceSigma(ctx context.Context, sigmaInput *pb.SigmaInput) (*pb.Response, error) {
306-
307-
devopsLogger.Warning("ProduceSigma no longer supported")
308-
return &pb.Response{Status: pb.Response_FAILURE, Msg: []byte("no longer supported")}, nil
309-
310-
}
311-
312-
// EXP_ExecuteWithBinding executes a transaction with a specific binding/TXHandler
313-
func (d *Devops) EXP_ExecuteWithBinding(ctx context.Context, executeWithBinding *pb.ExecuteWithBinding) (*pb.Response, error) {
314-
315-
devopsLogger.Warning("ExecuteWithBinding no longer supported")
316-
return &pb.Response{Status: pb.Response_FAILURE, Msg: []byte("no longer supported")}, nil
317-
}

core/devops_test.go

+2-39
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
func TestDevops_Build_NilSpec(t *testing.T) {
2828
t.Skip("Skipping until we have the Validator system setup properly for testing.")
2929
// TODO Cannot pass in nil to NewDevopsServer
30-
devopsServer := NewDevopsServer(nil)
30+
devopsServer := NewDevopsServer()
3131

3232
_, err := devopsServer.Build(context.Background(), nil)
3333
if err == nil {
@@ -41,7 +41,7 @@ func TestDevops_Build_NilSpec(t *testing.T) {
4141
func TestDevops_Build(t *testing.T) {
4242
t.Skip("Skipping until we have the Validator system setup properly for testing.")
4343
// TODO Cannot pass in nil to NewDevopsServer
44-
devopsServer := NewDevopsServer(nil)
44+
devopsServer := NewDevopsServer()
4545

4646
// Build the spec
4747
chaincodePath := "github.com/hyperledger/fabric/core/example/chaincode/chaincode_example01"
@@ -55,40 +55,3 @@ func TestDevops_Build(t *testing.T) {
5555
t.Logf("Build result = %s", buildResult.ChaincodeSpec.ChaincodeID)
5656
//performHandshake(t, peerClientConn)
5757
}
58-
59-
func TestDevops_Deploy(t *testing.T) {
60-
t.Skip("Skipping until we have the Validator system setup properly for testing.")
61-
// TODO Cannot pass in nil to NewDevopsServer
62-
devopsServer := NewDevopsServer(nil)
63-
64-
// Build the spec
65-
chaincodePath := "github.com/hyperledger/fabric/core/example/chaincode/chaincode_example01"
66-
spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG, ChaincodeID: &pb.ChaincodeID{Path: chaincodePath}}
67-
68-
buildResult, err := devopsServer.Deploy(context.Background(), spec)
69-
if err != nil {
70-
t.Fail()
71-
t.Logf("Error in Devops.Build call: %s", err)
72-
}
73-
t.Logf("Deploy result = %s", buildResult.ChaincodeSpec)
74-
//performHandshake(t, peerClientConn)
75-
}
76-
77-
func TestDevops_Spec_NoVersion(t *testing.T) {
78-
t.Skip("Skipping until we have the Validator system setup properly for testing.")
79-
// TODO Cannot pass in nil to NewDevopsServer
80-
devopsServer := NewDevopsServer(nil)
81-
82-
// Build the spec
83-
chaincodePath := "github.com/hyperledger/fabric/core/example/chaincode/chaincode_example01"
84-
spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG, ChaincodeID: &pb.ChaincodeID{Path: chaincodePath}}
85-
86-
buildResult, err := devopsServer.Deploy(context.Background(), spec)
87-
if err == nil {
88-
t.Fail()
89-
t.Log("Expected error with no version specified")
90-
return
91-
}
92-
t.Logf("Deploy result = %s, err = %s", buildResult, err)
93-
//performHandshake(t, peerClientConn)
94-
}

core/endorser/endorser.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/hyperledger/fabric/core/chaincode"
2727
"github.com/hyperledger/fabric/core/ledger"
2828
"github.com/hyperledger/fabric/core/ledger/kvledger"
29-
"github.com/hyperledger/fabric/core/peer"
3029
"github.com/hyperledger/fabric/msp"
3130
"github.com/hyperledger/fabric/protos/common"
3231
pb "github.com/hyperledger/fabric/protos/peer"
@@ -40,13 +39,11 @@ var endorserLogger = logging.MustGetLogger("endorser")
4039

4140
// Endorser provides the Endorser service ProcessProposal
4241
type Endorser struct {
43-
coord peer.MessageHandlerCoordinator
4442
}
4543

4644
// NewEndorserServer creates and returns a new Endorser server instance.
47-
func NewEndorserServer(coord peer.MessageHandlerCoordinator) pb.EndorserServer {
45+
func NewEndorserServer() pb.EndorserServer {
4846
e := new(Endorser)
49-
e.coord = coord
5047
return e
5148
}
5249

@@ -202,7 +199,7 @@ func (e *Endorser) endorseProposal(ctx context.Context, proposal *pb.Proposal, s
202199

203200
// marshalling event bytes
204201
var err error
205-
var eventBytes []byte = nil
202+
var eventBytes []byte
206203
if event != nil {
207204
eventBytes, err = putils.GetBytesChaincodeEvent(event)
208205
if err != nil {

0 commit comments

Comments
 (0)