Skip to content

Commit

Permalink
[FAB-10195] Bump to latest fabric
Browse files Browse the repository at this point in the history
Change-Id: I38bbe729e5e1856ba07d0f1f81a423b9894120d4
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed Jun 1, 2018
1 parent 943ad4f commit 38d3ff8
Show file tree
Hide file tree
Showing 24 changed files with 402 additions and 237 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ FABRIC_DEV_REGISTRY_PRE_CMD ?= docker login -u docker -p docker nexus3.hyperledg

# Upstream fabric patching (overridable)
THIRDPARTY_FABRIC_CA_BRANCH ?= master
THIRDPARTY_FABRIC_CA_COMMIT ?= 2032d7736ec3254f7ad2555770743b90c5956274
THIRDPARTY_FABRIC_CA_COMMIT ?= 7c3fc1addc046055f66d45d35a1c47c98364c627
THIRDPARTY_FABRIC_BRANCH ?= master
THIRDPARTY_FABRIC_COMMIT ?= d78be9f4567d98e8c14542446a85ec5f8fcb5e5a
THIRDPARTY_FABRIC_COMMIT ?= 8f79ea1aebdaee1c844d1b5f2c8f89dff18bcffc

# Force removal of images in cleanup (overridable)
FIXTURE_DOCKER_REMOVE_FORCE ?= false
Expand Down
19 changes: 14 additions & 5 deletions internal/github.com/hyperledger/fabric-ca/lib/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type GetCAInfoResponse struct {
CAChain []byte
// Idemix issuer public key of the CA
IssuerPublicKey []byte
// Idemix issuer revocation public key of the CA
IssuerRevocationPublicKey []byte
// Version of the server
Version string
}
Expand Down Expand Up @@ -199,19 +201,26 @@ func (c *Client) Enroll(req *api.EnrollmentRequest) (*EnrollmentResponse, error)
return c.handleX509Enroll(req)
}

// Convert from network to local server information
func (c *Client) net2LocalServerInfo(net *common.CAInfoResponseNet, local *GetCAInfoResponse) error {
// Convert from network to local CA information
func (c *Client) net2LocalCAInfo(net *common.CAInfoResponseNet, local *GetCAInfoResponse) error {
caChain, err := util.B64Decode(net.CAChain)
if err != nil {
return err
return errors.WithMessage(err, "Failed to decode CA chain")
}
if net.IssuerPublicKey != "" {
ipk, err := util.B64Decode(net.IssuerPublicKey)
if err != nil {
return err
return errors.WithMessage(err, "Failed to decode issuer public key")
}
local.IssuerPublicKey = ipk
}
if net.IssuerRevocationPublicKey != "" {
rpk, err := util.B64Decode(net.IssuerRevocationPublicKey)
if err != nil {
return errors.WithMessage(err, "Failed to decode issuer revocation key")
}
local.IssuerRevocationPublicKey = rpk
}
local.CAName = net.CAName
local.CAChain = caChain
local.Version = net.Version
Expand Down Expand Up @@ -290,7 +299,7 @@ func (c *Client) newEnrollmentResponse(result *common.EnrollmentResponseNet, id
resp := &EnrollmentResponse{
Identity: NewIdentity(c, id, []credential.Credential{x509Cred}),
}
err = c.net2LocalServerInfo(&result.ServerInfo, &resp.CAInfo)
err = c.net2LocalCAInfo(&result.ServerInfo, &resp.CAInfo)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ Please review third_party pinning scripts and patches for more details.

package common

const (
// IdemixTokenVersion1 represents version 1 of the authorization token created using Idemix credential
IdemixTokenVersion1 = "1"
)

// CAInfoResponseNet is the response to the GET /info request
type CAInfoResponseNet struct {
// CAName is a unique name associated with fabric-ca-server's CA
CAName string
// Base64 encoding of PEM-encoded certificate chain
CAChain string
// Base64 encoding of idemix issuer public key
// Base64 encoding of Idemix issuer public key
IssuerPublicKey string
// Base64 encoding of PEM-encoded Idemix issuer revocation public key
IssuerRevocationPublicKey string
// Version of the server
Version string
}
Expand Down
9 changes: 9 additions & 0 deletions internal/github.com/hyperledger/fabric-ca/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
mrand "math/rand"
"net/http"
"os"
"path"
"path/filepath"
"reflect"
"regexp"
Expand Down Expand Up @@ -92,6 +93,14 @@ func ReadFile(file string) ([]byte, error) {

// WriteFile writes a file
func WriteFile(file string, buf []byte, perm os.FileMode) error {
dir := path.Dir(file)
// Create the directory if it doesn't exist
if _, err := os.Stat(dir); os.IsNotExist(err) {
err = os.MkdirAll(dir, 0755)
if err != nil {
return errors.Wrapf(err, "Failed to create directory '%s' for file '%s'", dir, file)
}
}
return ioutil.WriteFile(file, buf, perm)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,10 @@ type ErrCollectionConfigNotYetAvailable struct {
func (e *ErrCollectionConfigNotYetAvailable) Error() string {
return e.Msg
}

// NotFoundInIndexErr is used to indicate missing entry in the index
type NotFoundInIndexErr string

func (NotFoundInIndexErr) Error() string {
return "Entry not found in index"
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ type ChannelResponse interface {
// The selection is based on the given selection hints:
// PrioritySelector: Determines which endorsers are selected over others
// ExclusionFilter: Determines which endorsers are not selected
Endorsers(cc string, ps PrioritySelector, ef ExclusionFilter) (Endorsers, error)
// The given InvocationChain specifies the chaincode calls (along with collections)
// that the client passed during the construction of the request
Endorsers(invocationChain InvocationChain, ps PrioritySelector, ef ExclusionFilter) (Endorsers, error)
}

// LocalResponse aggregates responses for a channel-less scope
Expand Down
130 changes: 96 additions & 34 deletions internal/github.com/hyperledger/fabric/discovery/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package discovery
import (
"bytes"
"context"
"encoding/json"
"math/rand"
"time"

Expand All @@ -38,8 +39,9 @@ type Client struct {
// NewRequest creates a new request
func NewRequest() *Request {
r := &Request{
queryMapping: make(map[discovery.QueryType]map[string]int),
Request: &discovery.Request{},
invocationChainMapping: make(map[int][]InvocationChain),
queryMapping: make(map[discovery.QueryType]map[string]int),
Request: &discovery.Request{},
}
// pre-populate types
for _, queryType := range configTypes {
Expand All @@ -52,8 +54,10 @@ func NewRequest() *Request {
type Request struct {
lastChannel string
lastIndex int
// map from query type to channel (or channel + chaincode) to expected index in response
// map from query type to channel to expected index in response
queryMapping map[discovery.QueryType]map[string]int
// map from expected index in response to invocation chains
invocationChainMapping map[int][]InvocationChain
*discovery.Request
}

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

// AddEndorsersQuery adds to the request a query for given chaincodes
func (req *Request) AddEndorsersQuery(chaincodes ...string) *Request {
// interests are the chaincode interests that the client wants to query for.
// All interests for a given channel should be supplied in an aggregated slice
func (req *Request) AddEndorsersQuery(interests ...*discovery.ChaincodeInterest) (*Request, error) {
if err := validateInterests(interests...); err != nil {
return nil, err
}
ch := req.lastChannel
q := &discovery.Query_CcQuery{
CcQuery: &discovery.ChaincodeQuery{},
}
for _, cc := range chaincodes {
q.CcQuery.Interests = append(q.CcQuery.Interests, &discovery.ChaincodeInterest{
Chaincodes: []*discovery.ChaincodeCall{{Name: cc}},
})
CcQuery: &discovery.ChaincodeQuery{
Interests: interests,
},
}
req.Queries = append(req.Queries, &discovery.Query{
Channel: ch,
Query: q,
})
var invocationChains []InvocationChain
for _, interest := range interests {
invocationChains = append(invocationChains, interest.Chaincodes)
}
req.addChaincodeQueryMapping(invocationChains)
req.addQueryMapping(discovery.ChaincodeQueryType, ch)
return req
return req, nil
}

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

func (req *Request) addChaincodeQueryMapping(invocationChains []InvocationChain) {
req.invocationChainMapping[req.lastIndex] = invocationChains
}

func (req *Request) addQueryMapping(queryType discovery.QueryType, key string) {
req.queryMapping[queryType][key] = req.lastIndex
req.lastIndex++
Expand Down Expand Up @@ -169,7 +184,7 @@ func (c *Client) Send(ctx context.Context, req *Request, auth *discovery.AuthInf
if n := len(resp.Results); n != req.lastIndex {
return nil, errors.Errorf("Sent %d queries but received %d responses back", req.lastIndex, n)
}
return computeResponse(req.queryMapping, resp)
return req.computeResponse(resp)
}

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

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

// Else, the service returned a response that isn't an error
res, exists := cr.response[key{
queryType: discovery.ChaincodeQueryType,
channel: cr.channel,
chaincode: cc,
queryType: discovery.ChaincodeQueryType,
channel: cr.channel,
invocationChain: invocationChain.String(),
}]

if !exists {
Expand Down Expand Up @@ -294,20 +309,20 @@ func (resp response) ForChannel(ch string) ChannelResponse {
}

type key struct {
queryType discovery.QueryType
channel string
chaincode string
queryType discovery.QueryType
channel string
invocationChain string
}

func computeResponse(queryMapping map[discovery.QueryType]map[string]int, r *discovery.Response) (response, error) {
func (req *Request) computeResponse(r *discovery.Response) (response, error) {
var err error
resp := make(response)
for configType, channel2index := range queryMapping {
for configType, channel2index := range req.queryMapping {
switch configType {
case discovery.ConfigQueryType:
err = resp.mapConfig(channel2index, r)
case discovery.ChaincodeQueryType:
err = resp.mapEndorsers(channel2index, r)
err = resp.mapEndorsers(channel2index, r, req.queryMapping, req.invocationChainMapping)
case discovery.PeerMembershipQueryType:
err = resp.mapPeerMembership(channel2index, r, discovery.PeerMembershipQueryType)
case discovery.LocalMembershipQueryType:
Expand Down Expand Up @@ -404,36 +419,46 @@ func isStateInfoExpected(qt discovery.QueryType) bool {
return qt != discovery.LocalMembershipQueryType
}

func (resp response) mapEndorsers(channel2index map[string]int, r *discovery.Response) error {
func (resp response) mapEndorsers(
channel2index map[string]int,
r *discovery.Response,
queryMapping map[discovery.QueryType]map[string]int,
chaincodeQueryMapping map[int][]InvocationChain) error {
for ch, index := range channel2index {
ccQueryRes, err := r.EndorsersAt(index)
if ccQueryRes == nil && err == nil {
return errors.Errorf("expected QueryResult of either ChaincodeQueryResult or Error but got %v instead", r.Results[index])
}

key := key{
queryType: discovery.ChaincodeQueryType,
channel: ch,
}

if err != nil {
key := key{
queryType: discovery.ChaincodeQueryType,
channel: ch,
}
resp[key] = errors.New(err.Content)
continue
}

if err := resp.mapEndorsersOfChannel(ccQueryRes, ch); err != nil {
if err := resp.mapEndorsersOfChannel(ccQueryRes, ch, chaincodeQueryMapping[index]); err != nil {
return errors.Wrapf(err, "failed assembling endorsers of channel %s", ch)
}
}
return nil
}

func (resp response) mapEndorsersOfChannel(ccRs *discovery.ChaincodeQueryResult, channel string) error {
for _, desc := range ccRs.Content {
func (resp response) mapEndorsersOfChannel(ccRs *discovery.ChaincodeQueryResult, channel string, invocationChain []InvocationChain) error {
if len(ccRs.Content) < len(invocationChain) {
return errors.Errorf("expected %d endorsement descriptors but got only %d", len(invocationChain), len(ccRs.Content))
}
for i, desc := range ccRs.Content {
expectedCCName := invocationChain[i][0].Name
if desc.Chaincode != expectedCCName {
return errors.Errorf("expected chaincode %s but got endorsement descriptor for %s", expectedCCName, desc.Chaincode)
}
key := key{
queryType: discovery.ChaincodeQueryType,
channel: channel,
chaincode: desc.Chaincode,
queryType: discovery.ChaincodeQueryType,
channel: channel,
invocationChain: invocationChain[i].String(),
}

descriptor, err := resp.createEndorsementDescriptor(desc, channel)
Expand Down Expand Up @@ -548,3 +573,40 @@ func validateStateInfoMessage(message *gossip.SignedGossipMessage) error {
}
return nil
}

func validateInterests(interests ...*discovery.ChaincodeInterest) error {
if len(interests) == 0 {
return errors.New("no chaincode interests given")
}
for _, interest := range interests {
if interest == nil {
return errors.New("chaincode interest is nil")
}
if err := InvocationChain(interest.Chaincodes).ValidateInvocationChain(); err != nil {
return err
}
}
return nil
}

// InvocationChain aggregates ChaincodeCalls
type InvocationChain []*discovery.ChaincodeCall

// String returns a string representation of this invocation chain
func (ic InvocationChain) String() string {
s, _ := json.Marshal(ic)
return string(s)
}

// ValidateInvocationChain validates the InvocationChain's structure
func (ic InvocationChain) ValidateInvocationChain() error {
if len(ic) == 0 {
return errors.New("invocation chain should not be empty")
}
for _, cc := range ic {
if cc.Name == "" {
return errors.New("chaincode name should not be empty")
}
}
return nil
}
1 change: 1 addition & 0 deletions internal/github.com/hyperledger/fabric/msp/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type MSPVersion int
const (
MSPv1_0 = iota
MSPv1_1
MSPv1_3
)

// NewOpts represent
Expand Down
Loading

0 comments on commit 38d3ff8

Please sign in to comment.