Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 38d3ff8

Browse files
committed
[FAB-10195] Bump to latest fabric
Change-Id: I38bbe729e5e1856ba07d0f1f81a423b9894120d4 Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent 943ad4f commit 38d3ff8

File tree

24 files changed

+402
-237
lines changed

24 files changed

+402
-237
lines changed

Gopkg.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ FABRIC_DEV_REGISTRY_PRE_CMD ?= docker login -u docker -p docker nexus3.hyperledg
6464

6565
# Upstream fabric patching (overridable)
6666
THIRDPARTY_FABRIC_CA_BRANCH ?= master
67-
THIRDPARTY_FABRIC_CA_COMMIT ?= 2032d7736ec3254f7ad2555770743b90c5956274
67+
THIRDPARTY_FABRIC_CA_COMMIT ?= 7c3fc1addc046055f66d45d35a1c47c98364c627
6868
THIRDPARTY_FABRIC_BRANCH ?= master
69-
THIRDPARTY_FABRIC_COMMIT ?= d78be9f4567d98e8c14542446a85ec5f8fcb5e5a
69+
THIRDPARTY_FABRIC_COMMIT ?= 8f79ea1aebdaee1c844d1b5f2c8f89dff18bcffc
7070

7171
# Force removal of images in cleanup (overridable)
7272
FIXTURE_DOCKER_REMOVE_FORCE ?= false

internal/github.com/hyperledger/fabric-ca/lib/client.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ type GetCAInfoResponse struct {
6565
CAChain []byte
6666
// Idemix issuer public key of the CA
6767
IssuerPublicKey []byte
68+
// Idemix issuer revocation public key of the CA
69+
IssuerRevocationPublicKey []byte
6870
// Version of the server
6971
Version string
7072
}
@@ -199,19 +201,26 @@ func (c *Client) Enroll(req *api.EnrollmentRequest) (*EnrollmentResponse, error)
199201
return c.handleX509Enroll(req)
200202
}
201203

202-
// Convert from network to local server information
203-
func (c *Client) net2LocalServerInfo(net *common.CAInfoResponseNet, local *GetCAInfoResponse) error {
204+
// Convert from network to local CA information
205+
func (c *Client) net2LocalCAInfo(net *common.CAInfoResponseNet, local *GetCAInfoResponse) error {
204206
caChain, err := util.B64Decode(net.CAChain)
205207
if err != nil {
206-
return err
208+
return errors.WithMessage(err, "Failed to decode CA chain")
207209
}
208210
if net.IssuerPublicKey != "" {
209211
ipk, err := util.B64Decode(net.IssuerPublicKey)
210212
if err != nil {
211-
return err
213+
return errors.WithMessage(err, "Failed to decode issuer public key")
212214
}
213215
local.IssuerPublicKey = ipk
214216
}
217+
if net.IssuerRevocationPublicKey != "" {
218+
rpk, err := util.B64Decode(net.IssuerRevocationPublicKey)
219+
if err != nil {
220+
return errors.WithMessage(err, "Failed to decode issuer revocation key")
221+
}
222+
local.IssuerRevocationPublicKey = rpk
223+
}
215224
local.CAName = net.CAName
216225
local.CAChain = caChain
217226
local.Version = net.Version
@@ -290,7 +299,7 @@ func (c *Client) newEnrollmentResponse(result *common.EnrollmentResponseNet, id
290299
resp := &EnrollmentResponse{
291300
Identity: NewIdentity(c, id, []credential.Credential{x509Cred}),
292301
}
293-
err = c.net2LocalServerInfo(&result.ServerInfo, &resp.CAInfo)
302+
err = c.net2LocalCAInfo(&result.ServerInfo, &resp.CAInfo)
294303
if err != nil {
295304
return nil, err
296305
}

internal/github.com/hyperledger/fabric-ca/lib/common/serverresponses.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@ Please review third_party pinning scripts and patches for more details.
1010

1111
package common
1212

13+
const (
14+
// IdemixTokenVersion1 represents version 1 of the authorization token created using Idemix credential
15+
IdemixTokenVersion1 = "1"
16+
)
17+
1318
// CAInfoResponseNet is the response to the GET /info request
1419
type CAInfoResponseNet struct {
1520
// CAName is a unique name associated with fabric-ca-server's CA
1621
CAName string
1722
// Base64 encoding of PEM-encoded certificate chain
1823
CAChain string
19-
// Base64 encoding of idemix issuer public key
24+
// Base64 encoding of Idemix issuer public key
2025
IssuerPublicKey string
26+
// Base64 encoding of PEM-encoded Idemix issuer revocation public key
27+
IssuerRevocationPublicKey string
2128
// Version of the server
2229
Version string
2330
}

internal/github.com/hyperledger/fabric-ca/util/util.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
mrand "math/rand"
3434
"net/http"
3535
"os"
36+
"path"
3637
"path/filepath"
3738
"reflect"
3839
"regexp"
@@ -92,6 +93,14 @@ func ReadFile(file string) ([]byte, error) {
9293

9394
// WriteFile writes a file
9495
func WriteFile(file string, buf []byte, perm os.FileMode) error {
96+
dir := path.Dir(file)
97+
// Create the directory if it doesn't exist
98+
if _, err := os.Stat(dir); os.IsNotExist(err) {
99+
err = os.MkdirAll(dir, 0755)
100+
if err != nil {
101+
return errors.Wrapf(err, "Failed to create directory '%s' for file '%s'", dir, file)
102+
}
103+
}
95104
return ioutil.WriteFile(file, buf, perm)
96105
}
97106

internal/github.com/hyperledger/fabric/core/ledger/ledger_interface.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,10 @@ type ErrCollectionConfigNotYetAvailable struct {
320320
func (e *ErrCollectionConfigNotYetAvailable) Error() string {
321321
return e.Msg
322322
}
323+
324+
// NotFoundInIndexErr is used to indicate missing entry in the index
325+
type NotFoundInIndexErr string
326+
327+
func (NotFoundInIndexErr) Error() string {
328+
return "Entry not found in index"
329+
}

internal/github.com/hyperledger/fabric/discovery/client/api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ type ChannelResponse interface {
5353
// The selection is based on the given selection hints:
5454
// PrioritySelector: Determines which endorsers are selected over others
5555
// ExclusionFilter: Determines which endorsers are not selected
56-
Endorsers(cc string, ps PrioritySelector, ef ExclusionFilter) (Endorsers, error)
56+
// The given InvocationChain specifies the chaincode calls (along with collections)
57+
// that the client passed during the construction of the request
58+
Endorsers(invocationChain InvocationChain, ps PrioritySelector, ef ExclusionFilter) (Endorsers, error)
5759
}
5860

5961
// LocalResponse aggregates responses for a channel-less scope

internal/github.com/hyperledger/fabric/discovery/client/client.go

Lines changed: 96 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ package discovery
1313
import (
1414
"bytes"
1515
"context"
16+
"encoding/json"
1617
"math/rand"
1718
"time"
1819

@@ -38,8 +39,9 @@ type Client struct {
3839
// NewRequest creates a new request
3940
func NewRequest() *Request {
4041
r := &Request{
41-
queryMapping: make(map[discovery.QueryType]map[string]int),
42-
Request: &discovery.Request{},
42+
invocationChainMapping: make(map[int][]InvocationChain),
43+
queryMapping: make(map[discovery.QueryType]map[string]int),
44+
Request: &discovery.Request{},
4345
}
4446
// pre-populate types
4547
for _, queryType := range configTypes {
@@ -52,8 +54,10 @@ func NewRequest() *Request {
5254
type Request struct {
5355
lastChannel string
5456
lastIndex int
55-
// map from query type to channel (or channel + chaincode) to expected index in response
57+
// map from query type to channel to expected index in response
5658
queryMapping map[discovery.QueryType]map[string]int
59+
// map from expected index in response to invocation chains
60+
invocationChainMapping map[int][]InvocationChain
5761
*discovery.Request
5862
}
5963

@@ -72,22 +76,29 @@ func (req *Request) AddConfigQuery() *Request {
7276
}
7377

7478
// AddEndorsersQuery adds to the request a query for given chaincodes
75-
func (req *Request) AddEndorsersQuery(chaincodes ...string) *Request {
79+
// interests are the chaincode interests that the client wants to query for.
80+
// All interests for a given channel should be supplied in an aggregated slice
81+
func (req *Request) AddEndorsersQuery(interests ...*discovery.ChaincodeInterest) (*Request, error) {
82+
if err := validateInterests(interests...); err != nil {
83+
return nil, err
84+
}
7685
ch := req.lastChannel
7786
q := &discovery.Query_CcQuery{
78-
CcQuery: &discovery.ChaincodeQuery{},
79-
}
80-
for _, cc := range chaincodes {
81-
q.CcQuery.Interests = append(q.CcQuery.Interests, &discovery.ChaincodeInterest{
82-
Chaincodes: []*discovery.ChaincodeCall{{Name: cc}},
83-
})
87+
CcQuery: &discovery.ChaincodeQuery{
88+
Interests: interests,
89+
},
8490
}
8591
req.Queries = append(req.Queries, &discovery.Query{
8692
Channel: ch,
8793
Query: q,
8894
})
95+
var invocationChains []InvocationChain
96+
for _, interest := range interests {
97+
invocationChains = append(invocationChains, interest.Chaincodes)
98+
}
99+
req.addChaincodeQueryMapping(invocationChains)
89100
req.addQueryMapping(discovery.ChaincodeQueryType, ch)
90-
return req
101+
return req, nil
91102
}
92103

93104
// AddLocalPeersQuery adds to the request a local peer query
@@ -122,6 +133,10 @@ func (req *Request) OfChannel(ch string) *Request {
122133
return req
123134
}
124135

136+
func (req *Request) addChaincodeQueryMapping(invocationChains []InvocationChain) {
137+
req.invocationChainMapping[req.lastIndex] = invocationChains
138+
}
139+
125140
func (req *Request) addQueryMapping(queryType discovery.QueryType, key string) {
126141
req.queryMapping[queryType][key] = req.lastIndex
127142
req.lastIndex++
@@ -169,7 +184,7 @@ func (c *Client) Send(ctx context.Context, req *Request, auth *discovery.AuthInf
169184
if n := len(resp.Results); n != req.lastIndex {
170185
return nil, errors.Errorf("Sent %d queries but received %d responses back", req.lastIndex, n)
171186
}
172-
return computeResponse(req.queryMapping, resp)
187+
return req.computeResponse(resp)
173188
}
174189

175190
type resultOrError interface {
@@ -228,7 +243,7 @@ func (cr *channelResponse) Peers() ([]*Peer, error) {
228243
return parsePeers(discovery.PeerMembershipQueryType, cr.response, cr.channel)
229244
}
230245

231-
func (cr *channelResponse) Endorsers(cc string, ps PrioritySelector, ef ExclusionFilter) (Endorsers, error) {
246+
func (cr *channelResponse) Endorsers(invocationChain InvocationChain, ps PrioritySelector, ef ExclusionFilter) (Endorsers, error) {
232247
// If we have a key that has no chaincode field,
233248
// it means it's an error returned from the service
234249
if err, exists := cr.response[key{
@@ -240,9 +255,9 @@ func (cr *channelResponse) Endorsers(cc string, ps PrioritySelector, ef Exclusio
240255

241256
// Else, the service returned a response that isn't an error
242257
res, exists := cr.response[key{
243-
queryType: discovery.ChaincodeQueryType,
244-
channel: cr.channel,
245-
chaincode: cc,
258+
queryType: discovery.ChaincodeQueryType,
259+
channel: cr.channel,
260+
invocationChain: invocationChain.String(),
246261
}]
247262

248263
if !exists {
@@ -294,20 +309,20 @@ func (resp response) ForChannel(ch string) ChannelResponse {
294309
}
295310

296311
type key struct {
297-
queryType discovery.QueryType
298-
channel string
299-
chaincode string
312+
queryType discovery.QueryType
313+
channel string
314+
invocationChain string
300315
}
301316

302-
func computeResponse(queryMapping map[discovery.QueryType]map[string]int, r *discovery.Response) (response, error) {
317+
func (req *Request) computeResponse(r *discovery.Response) (response, error) {
303318
var err error
304319
resp := make(response)
305-
for configType, channel2index := range queryMapping {
320+
for configType, channel2index := range req.queryMapping {
306321
switch configType {
307322
case discovery.ConfigQueryType:
308323
err = resp.mapConfig(channel2index, r)
309324
case discovery.ChaincodeQueryType:
310-
err = resp.mapEndorsers(channel2index, r)
325+
err = resp.mapEndorsers(channel2index, r, req.queryMapping, req.invocationChainMapping)
311326
case discovery.PeerMembershipQueryType:
312327
err = resp.mapPeerMembership(channel2index, r, discovery.PeerMembershipQueryType)
313328
case discovery.LocalMembershipQueryType:
@@ -404,36 +419,46 @@ func isStateInfoExpected(qt discovery.QueryType) bool {
404419
return qt != discovery.LocalMembershipQueryType
405420
}
406421

407-
func (resp response) mapEndorsers(channel2index map[string]int, r *discovery.Response) error {
422+
func (resp response) mapEndorsers(
423+
channel2index map[string]int,
424+
r *discovery.Response,
425+
queryMapping map[discovery.QueryType]map[string]int,
426+
chaincodeQueryMapping map[int][]InvocationChain) error {
408427
for ch, index := range channel2index {
409428
ccQueryRes, err := r.EndorsersAt(index)
410429
if ccQueryRes == nil && err == nil {
411430
return errors.Errorf("expected QueryResult of either ChaincodeQueryResult or Error but got %v instead", r.Results[index])
412431
}
413432

414-
key := key{
415-
queryType: discovery.ChaincodeQueryType,
416-
channel: ch,
417-
}
418-
419433
if err != nil {
434+
key := key{
435+
queryType: discovery.ChaincodeQueryType,
436+
channel: ch,
437+
}
420438
resp[key] = errors.New(err.Content)
421439
continue
422440
}
423441

424-
if err := resp.mapEndorsersOfChannel(ccQueryRes, ch); err != nil {
442+
if err := resp.mapEndorsersOfChannel(ccQueryRes, ch, chaincodeQueryMapping[index]); err != nil {
425443
return errors.Wrapf(err, "failed assembling endorsers of channel %s", ch)
426444
}
427445
}
428446
return nil
429447
}
430448

431-
func (resp response) mapEndorsersOfChannel(ccRs *discovery.ChaincodeQueryResult, channel string) error {
432-
for _, desc := range ccRs.Content {
449+
func (resp response) mapEndorsersOfChannel(ccRs *discovery.ChaincodeQueryResult, channel string, invocationChain []InvocationChain) error {
450+
if len(ccRs.Content) < len(invocationChain) {
451+
return errors.Errorf("expected %d endorsement descriptors but got only %d", len(invocationChain), len(ccRs.Content))
452+
}
453+
for i, desc := range ccRs.Content {
454+
expectedCCName := invocationChain[i][0].Name
455+
if desc.Chaincode != expectedCCName {
456+
return errors.Errorf("expected chaincode %s but got endorsement descriptor for %s", expectedCCName, desc.Chaincode)
457+
}
433458
key := key{
434-
queryType: discovery.ChaincodeQueryType,
435-
channel: channel,
436-
chaincode: desc.Chaincode,
459+
queryType: discovery.ChaincodeQueryType,
460+
channel: channel,
461+
invocationChain: invocationChain[i].String(),
437462
}
438463

439464
descriptor, err := resp.createEndorsementDescriptor(desc, channel)
@@ -548,3 +573,40 @@ func validateStateInfoMessage(message *gossip.SignedGossipMessage) error {
548573
}
549574
return nil
550575
}
576+
577+
func validateInterests(interests ...*discovery.ChaincodeInterest) error {
578+
if len(interests) == 0 {
579+
return errors.New("no chaincode interests given")
580+
}
581+
for _, interest := range interests {
582+
if interest == nil {
583+
return errors.New("chaincode interest is nil")
584+
}
585+
if err := InvocationChain(interest.Chaincodes).ValidateInvocationChain(); err != nil {
586+
return err
587+
}
588+
}
589+
return nil
590+
}
591+
592+
// InvocationChain aggregates ChaincodeCalls
593+
type InvocationChain []*discovery.ChaincodeCall
594+
595+
// String returns a string representation of this invocation chain
596+
func (ic InvocationChain) String() string {
597+
s, _ := json.Marshal(ic)
598+
return string(s)
599+
}
600+
601+
// ValidateInvocationChain validates the InvocationChain's structure
602+
func (ic InvocationChain) ValidateInvocationChain() error {
603+
if len(ic) == 0 {
604+
return errors.New("invocation chain should not be empty")
605+
}
606+
for _, cc := range ic {
607+
if cc.Name == "" {
608+
return errors.New("chaincode name should not be empty")
609+
}
610+
}
611+
return nil
612+
}

internal/github.com/hyperledger/fabric/msp/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type MSPVersion int
1515
const (
1616
MSPv1_0 = iota
1717
MSPv1_1
18+
MSPv1_3
1819
)
1920

2021
// NewOpts represent

0 commit comments

Comments
 (0)