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

Commit 9549fe5

Browse files
committed
[FABG-768] Import latest fabric code
Change-Id: I3dd4abd58db10f643b2ae07c29efe86bd4d11f6b Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent f10bc6b commit 9549fe5

File tree

16 files changed

+228
-113
lines changed

16 files changed

+228
-113
lines changed

Gopkg.lock

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
name = "github.com/cloudflare/cfssl"
2929
version = "1.3.1"
3030

31-
[[constraint]]
32-
name = "github.com/golang/groupcache"
33-
branch = "master"
34-
3531
[[constraint]]
3632
name = "github.com/Knetic/govaluate"
3733
version = "3.0.0"

Makefile

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

6969
# Upstream fabric patching (overridable)
7070
THIRDPARTY_FABRIC_CA_BRANCH ?= master
71-
THIRDPARTY_FABRIC_CA_COMMIT ?= 54f3bcfd95cf028baac9792eee426ab793dc80bc
71+
THIRDPARTY_FABRIC_CA_COMMIT ?= 16877b8e0301ea1484af61ad5323ee1cbc0c3dd9
7272
THIRDPARTY_FABRIC_BRANCH ?= master
73-
THIRDPARTY_FABRIC_COMMIT ?= 89eb2cbe445e452daa8d008598352fe483f23071
73+
THIRDPARTY_FABRIC_COMMIT ?= 846dcd6213db8d5da55ee6453538e7f8c63056f8
7474

7575
# Force removal of images in cleanup (overridable)
7676
FIXTURE_DOCKER_REMOVE_FORCE ?= false

internal/github.com/hyperledger/fabric/bccsp/pkcs11/conf.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ type PKCS11Opts struct {
9191
Label string `mapstructure:"label" json:"label"`
9292
Pin string `mapstructure:"pin" json:"pin"`
9393
SoftVerify bool `mapstructure:"softwareverify,omitempty" json:"softwareverify,omitempty"`
94+
Immutable bool `mapstructure:"immutable,omitempty" json:"immutable,omitempty"`
9495
}
9596

96-
// FileKeystoreOpts is needed for File Based Key Store. Since currently only ECDSA operations // go to PKCS11, need a keystore still Pluggable Keystores, could add JKS, P12, etc..
97+
// FileKeystoreOpts currently only ECDSA operations go to PKCS11, need a keystore still
98+
// Pluggable Keystores, could add JKS, P12, etc..
9799
type FileKeystoreOpts struct {
98100
KeyStorePath string `mapstructure:"keystore" json:"keystore" yaml:"KeyStore"`
99101
}

internal/github.com/hyperledger/fabric/bccsp/pkcs11/impl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ type impl struct {
6565

6666
pkcs11Ctx *sdkp11.ContextHandle
6767
softVerify bool
68+
//Immutable flag makes object immutable
69+
immutable bool
6870
}
6971

7072
// KeyGen generates a key using opts.

internal/github.com/hyperledger/fabric/bccsp/pkcs11/pkcs11.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,32 @@ func (csp *impl) generateECKey(curve asn1.ObjectIdentifier, ephemeral bool) (ski
190190
return nil, nil, fmt.Errorf("P11: set-ID-to-SKI[private] failed [%s]", err)
191191
}
192192

193+
//Set CKA_Modifible to false for both public key and private keys
194+
if csp.immutable {
195+
setCKAModifiable := []*pkcs11.Attribute{
196+
pkcs11.NewAttribute(pkcs11.CKA_MODIFIABLE, false),
197+
}
198+
199+
_, pubCopyerror := csp.pkcs11Ctx.CopyObject(session, pub, setCKAModifiable)
200+
if pubCopyerror != nil {
201+
return nil, nil, fmt.Errorf("P11: Public Key copy failed with error [%s] . Please contact your HSM vendor", pubCopyerror)
202+
}
203+
204+
pubKeyDestroyError := csp.pkcs11Ctx.DestroyObject(session, pub)
205+
if pubKeyDestroyError != nil {
206+
return nil, nil, fmt.Errorf("P11: Public Key destroy failed with error [%s]. Please contact your HSM vendor", pubCopyerror)
207+
}
208+
209+
_, prvCopyerror := csp.pkcs11Ctx.CopyObject(session, prv, setCKAModifiable)
210+
if prvCopyerror != nil {
211+
return nil, nil, fmt.Errorf("P11: Private Key copy failed with error [%s]. Please contact your HSM vendor", prvCopyerror)
212+
}
213+
prvKeyDestroyError := csp.pkcs11Ctx.DestroyObject(session, prv)
214+
if pubKeyDestroyError != nil {
215+
return nil, nil, fmt.Errorf("P11: Private Key destroy failed with error [%s]. Please contact your HSM vendor", prvKeyDestroyError)
216+
}
217+
}
218+
193219
nistCurve := namedCurveFromOID(curve)
194220
if curve == nil {
195221
return nil, nil, fmt.Errorf("Cound not recognize Curve from OID")

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ type ResultsIterator interface {
4848
Close()
4949
}
5050

51+
// QueryResultsIterator - an iterator for query result set
52+
type QueryResultsIterator interface {
53+
ResultsIterator
54+
GetBookmarkAndClose() string
55+
}
56+
5157
// QueryResult - a general interface for supporting different types of query results. Actual types differ for different queries
5258
type QueryResult interface{}
5359

internal/github.com/hyperledger/fabric/common/metrics/tally_provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import (
2121
"time"
2222

2323
"github.com/cactus/go-statsd-client/statsd"
24-
logging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/sdkpatch/logbridge"
24+
flogging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/sdkpatch/logbridge"
2525
"github.com/prometheus/client_golang/prometheus"
2626
"github.com/prometheus/client_golang/prometheus/promhttp"
2727
"github.com/uber-go/tally"
2828
promreporter "github.com/uber-go/tally/prometheus"
2929
statsdreporter "github.com/uber-go/tally/statsd"
3030
)
3131

32-
var logger = logging.MustGetLogger("common/metrics/tally")
32+
var logger = flogging.MustGetLogger("common/metrics/tally")
3333

3434
var scopeRegistryKey = tally.KeyForPrefixedStringMap
3535

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

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Please review third_party pinning scripts and patches for more details.
1111
package ledger
1212

1313
import (
14+
"fmt"
15+
1416
"github.com/golang/protobuf/proto"
1517
commonledger "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/ledger"
1618
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
@@ -23,6 +25,7 @@ import (
2325
type Initializer struct {
2426
StateListeners []StateListener
2527
DeployedChaincodeInfoProvider DeployedChaincodeInfoProvider
28+
MembershipInfoProvider MembershipInfoProvider
2629
}
2730

2831
// PeerLedgerProvider provides handle to ledger instances
@@ -124,15 +127,30 @@ type QueryExecutor interface {
124127
GetStateMetadata(namespace, key string) (map[string][]byte, error)
125128
// GetStateMultipleKeys gets the values for multiple keys in a single call
126129
GetStateMultipleKeys(namespace string, keys []string) ([][]byte, error)
130+
// GetStateRangeScanIteratorWithMetadata returns an iterator that contains all the key-values between given key ranges.
131+
// startKey is included in the results and endKey is excluded. An empty startKey refers to the first available key
132+
// and an empty endKey refers to the last available key. For scanning all the keys, both the startKey and the endKey
133+
// can be supplied as empty strings. However, a full scan should be used judiciously for performance reasons.
134+
// metadata is a map of additional query parameters
135+
// The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
136+
GetStateRangeScanIteratorWithMetadata(namespace string, startKey, endKey string, metadata map[string]interface{}) (QueryResultsIterator, error)
127137
// ExecuteQuery executes the given query and returns an iterator that contains results of type specific to the underlying data store.
128138
// Only used for state databases that support query
129139
// For a chaincode, the namespace corresponds to the chaincodeId
130140
// The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
131141
ExecuteQuery(namespace, query string) (commonledger.ResultsIterator, error)
142+
// ExecuteQueryWithMetadata executes the given query and returns an iterator that contains results of type specific to the underlying data store.
143+
// metadata is a map of additional query parameters
144+
// Only used for state databases that support query
145+
// For a chaincode, the namespace corresponds to the chaincodeId
146+
// The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
147+
ExecuteQueryWithMetadata(namespace, query string, metadata map[string]interface{}) (QueryResultsIterator, error)
132148
// GetPrivateData gets the value of a private data item identified by a tuple <namespace, collection, key>
133149
GetPrivateData(namespace, collection, key string) ([]byte, error)
134150
// GetPrivateDataMetadata gets the metadata of a private data item identified by a tuple <namespace, collection, key>
135151
GetPrivateDataMetadata(namespace, collection, key string) (map[string][]byte, error)
152+
// GetPrivateDataMetadataByHash gets the metadata of a private data item identified by a tuple <namespace, collection, keyhash>
153+
GetPrivateDataMetadataByHash(namespace, collection string, keyhash []byte) (map[string][]byte, error)
136154
// GetPrivateDataMultipleKeys gets the values for the multiple private data items in a single call
137155
GetPrivateDataMultipleKeys(namespace, collection string, keys []string) ([][]byte, error)
138156
// GetPrivateDataRangeScanIterator returns an iterator that contains all the key-values between given key ranges.
@@ -196,6 +214,13 @@ type TxSimulator interface {
196214
GetTxSimulationResults() (*TxSimulationResults, error)
197215
}
198216

217+
// QueryResultsIterator - an iterator for query result set
218+
type QueryResultsIterator interface {
219+
commonledger.ResultsIterator
220+
// GetBookmarkAndClose returns a paging bookmark and releases resources occupied by the iterator
221+
GetBookmarkAndClose() string
222+
}
223+
199224
// TxPvtData encapsulates the transaction number and pvt write-set for a transaction
200225
type TxPvtData struct {
201226
SeqInBlock uint64
@@ -207,18 +232,22 @@ type TxPvtData struct {
207232
// to the ledger at the commit of the corresponding block
208233
type MissingPrivateData struct {
209234
TxId string
210-
SeqInBlock int
235+
SeqInBlock uint64
211236
Namespace string
212237
Collection string
213-
Eligible bool
238+
IsEligible bool
239+
}
240+
241+
type MissingPrivateDataList struct {
242+
List []*MissingPrivateData
214243
}
215244

216245
// BlockAndPvtData encapsulates the block and a map that contains the tuples <seqInBlock, *TxPvtData>
217246
// The map is expected to contain the entries only for the transactions that has associated pvt data
218247
type BlockAndPvtData struct {
219248
Block *common.Block
220249
BlockPvtData map[uint64]*TxPvtData
221-
Missing []*MissingPrivateData
250+
Missing *MissingPrivateDataList
222251
}
223252

224253
// BlockPvtData contains the private data for a block
@@ -227,6 +256,10 @@ type BlockPvtData struct {
227256
WriteSets map[uint64]*TxPvtData
228257
}
229258

259+
func (missing *MissingPrivateDataList) Add(txId string, txNum uint64, ns, coll string, isEligible bool) {
260+
missing.List = append(missing.List, &MissingPrivateData{txId, txNum, ns, coll, isEligible})
261+
}
262+
230263
// PvtCollFilter represents the set of the collection names (as keys of the map with value 'true')
231264
type PvtCollFilter map[string]bool
232265

@@ -348,7 +381,7 @@ type MissingBlockPvtdataInfo map[uint64][]*MissingCollectionPvtDataInfo
348381

349382
// MissingCollectionPvtDataInfo includes the name of the chaincode and collection for which private data is missing
350383
type MissingCollectionPvtDataInfo struct {
351-
ChaincodeName, CollectionName string
384+
Namespace, Collection string
352385
}
353386

354387
// CollectionConfigInfo encapsulates a collection config for a chaincode and its committing block number
@@ -357,6 +390,23 @@ type CollectionConfigInfo struct {
357390
CommittingBlockNum uint64
358391
}
359392

393+
func (missingPvtDataInfo MissingPvtDataInfo) Add(blkNum, txNum uint64, ns, coll string) {
394+
missingBlockPvtDataInfo, ok := missingPvtDataInfo[blkNum]
395+
if !ok {
396+
missingBlockPvtDataInfo = make(MissingBlockPvtdataInfo)
397+
missingPvtDataInfo[blkNum] = missingBlockPvtDataInfo
398+
}
399+
400+
if _, ok := missingBlockPvtDataInfo[txNum]; !ok {
401+
missingBlockPvtDataInfo[txNum] = []*MissingCollectionPvtDataInfo{}
402+
}
403+
404+
missingBlockPvtDataInfo[txNum] = append(missingBlockPvtDataInfo[txNum],
405+
&MissingCollectionPvtDataInfo{
406+
Namespace: ns,
407+
Collection: coll})
408+
}
409+
360410
// ErrCollectionConfigNotYetAvailable is an error which is returned from the function
361411
// ConfigHistoryRetriever.CollectionConfigAt() if the latest block number committed
362412
// is lower than the block number specified in the request.
@@ -376,6 +426,26 @@ func (NotFoundInIndexErr) Error() string {
376426
return "Entry not found in index"
377427
}
378428

429+
// CollConfigNotDefinedError is returned whenever an operation
430+
// is requested on a collection whose config has not been defined
431+
type CollConfigNotDefinedError struct {
432+
Ns string
433+
}
434+
435+
func (e *CollConfigNotDefinedError) Error() string {
436+
return fmt.Sprintf("collection config not defined for chaincode [%s], pass the collection configuration upon chaincode definition/instantiation", e.Ns)
437+
}
438+
439+
// InvalidCollNameError is returned whenever an operation
440+
// is requested on a collection whose name is invalid
441+
type InvalidCollNameError struct {
442+
Ns, Coll string
443+
}
444+
445+
func (e *InvalidCollNameError) Error() string {
446+
return fmt.Sprintf("collection [%s] not defined in the collection config for chaincode [%s]", e.Coll, e.Ns)
447+
}
448+
379449
// PvtdataHashMismatch is used when the hash of private write-set
380450
// does not match the corresponding hash present in the block
381451
// See function `PeerLedger.CommitPvtData` for the usages
@@ -418,4 +488,11 @@ type ChaincodeLifecycleDetails struct {
418488
CollectionsRemoved []string // names of the collections that are removed
419489
}
420490

491+
// MembershipInfoProvider is a dependency that is used by ledger to determine whether the current peer is
492+
// a member of a collection. Gossip module is expected to provide the dependency to ledger
493+
type MembershipInfoProvider interface {
494+
// AmMemberOf checks whether the current peer is a member of the given collection
495+
AmMemberOf(channelName string, collectionPolicyConfig *common.CollectionPolicyConfig) (bool, error)
496+
}
497+
421498
//go:generate counterfeiter -o mock/deployed_ccinfo_provider.go -fake-name DeployedChaincodeInfoProvider . DeployedChaincodeInfoProvider

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ Please review third_party pinning scripts and patches for more details.
1111
package cache
1212

1313
import (
14-
"fmt"
15-
"sync"
16-
17-
"github.com/golang/groupcache/lru"
1814
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
1915
flogging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/sdkpatch/logbridge"
16+
"github.com/pkg/errors"
2017
)
2118

2219
const (
@@ -30,13 +27,13 @@ var mspLogger = flogging.MustGetLogger("msp")
3027
func New(o msp.MSP) (msp.MSP, error) {
3128
mspLogger.Debugf("Creating Cache-MSP instance")
3229
if o == nil {
33-
return nil, fmt.Errorf("Invalid passed MSP. It must be different from nil.")
30+
return nil, errors.Errorf("Invalid passed MSP. It must be different from nil.")
3431
}
3532

3633
theMsp := &cachedMSP{MSP: o}
37-
theMsp.deserializeIdentityCache = lru.New(deserializeIdentityCacheSize)
38-
theMsp.satisfiesPrincipalCache = lru.New(satisfiesPrincipalCacheSize)
39-
theMsp.validateIdentityCache = lru.New(validateIdentityCacheSize)
34+
theMsp.deserializeIdentityCache = newSecondChanceCache(deserializeIdentityCacheSize)
35+
theMsp.satisfiesPrincipalCache = newSecondChanceCache(satisfiesPrincipalCacheSize)
36+
theMsp.validateIdentityCache = newSecondChanceCache(validateIdentityCacheSize)
4037

4138
return theMsp, nil
4239
}
@@ -45,20 +42,14 @@ type cachedMSP struct {
4542
msp.MSP
4643

4744
// cache for DeserializeIdentity.
48-
deserializeIdentityCache *lru.Cache
49-
50-
dicMutex sync.Mutex // synchronize access to cache
45+
deserializeIdentityCache *secondChanceCache
5146

5247
// cache for validateIdentity
53-
validateIdentityCache *lru.Cache
54-
55-
vicMutex sync.Mutex // synchronize access to cache
48+
validateIdentityCache *secondChanceCache
5649

5750
// basically a map of principals=>identities=>stringified to booleans
5851
// specifying whether this identity satisfies this principal
59-
satisfiesPrincipalCache *lru.Cache
60-
61-
spcMutex sync.Mutex // synchronize access to cache
52+
satisfiesPrincipalCache *secondChanceCache
6253
}
6354

6455
type cachedIdentity struct {

0 commit comments

Comments
 (0)