Commit 81f2f0a9 authored by Gari Singh's avatar Gari Singh Committed by Gerrit Code Review
Browse files

Merge changes I01d08c00,I4bd48ed5

* changes:
  [FAB-12901] regenerate fakes in core/chaincode
  Instrument metrics into chaincode handler
parents f3a84171 0934c083
......@@ -11,6 +11,7 @@ import (
"time"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/metrics"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/common/ccprovider"
......@@ -54,6 +55,7 @@ type ChaincodeSupport struct {
SystemCCProvider sysccprovider.SystemChaincodeProvider
Lifecycle Lifecycle
appConfig ApplicationConfigRetriever
Metrics *Metrics
}
// NewChaincodeSupport creates a new ChaincodeSupport instance.
......@@ -70,6 +72,7 @@ func NewChaincodeSupport(
SystemCCProvider sysccprovider.SystemChaincodeProvider,
platformRegistry *platforms.Registry,
appConfig ApplicationConfigRetriever,
metricsProvider metrics.Provider,
) *ChaincodeSupport {
cs := &ChaincodeSupport{
UserRunsCC: userRunsCC,
......@@ -80,6 +83,7 @@ func NewChaincodeSupport(
SystemCCProvider: SystemCCProvider,
Lifecycle: lifecycle,
appConfig: appConfig,
Metrics: NewMetrics(metricsProvider),
}
// Keep TestQueries working
......@@ -177,6 +181,7 @@ func (cs *ChaincodeSupport) HandleChaincodeStream(stream ccintf.ChaincodeStream)
UUIDGenerator: UUIDGeneratorFunc(util.GenerateUUID),
LedgerGetter: peer.Default,
AppConfig: cs.appConfig,
Metrics: cs.Metrics,
}
return handler.ProcessStream(stream)
......
......@@ -23,6 +23,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/crypto/tlsgen"
commonledger "github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/common/metrics/disabled"
mc "github.com/hyperledger/fabric/common/mocks/config"
mocklgr "github.com/hyperledger/fabric/common/mocks/ledger"
mockpeer "github.com/hyperledger/fabric/common/mocks/peer"
......@@ -192,6 +193,7 @@ func initMockPeer(chainIDs ...string) (*ChaincodeSupport, error) {
sccp,
pr,
peer.DefaultSupport,
&disabled.Provider{},
)
ipRegistry.ChaincodeSupport = chaincodeSupport
......
......@@ -30,6 +30,7 @@ import (
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/crypto/tlsgen"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/metrics/disabled"
mc "github.com/hyperledger/fabric/common/mocks/config"
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
"github.com/hyperledger/fabric/common/policies"
......@@ -140,6 +141,7 @@ func initPeer(chainIDs ...string) (net.Listener, *ChaincodeSupport, func(), erro
sccp,
pr,
peer.DefaultSupport,
&disabled.Provider{},
)
ipRegistry.ChaincodeSupport = chaincodeSupport
pb.RegisterChaincodeSupportServer(grpcServer, chaincodeSupport)
......
......@@ -2,16 +2,16 @@
package fake
import (
"sync"
sync "sync"
"github.com/hyperledger/fabric/common/channelconfig"
channelconfig "github.com/hyperledger/fabric/common/channelconfig"
)
type ApplicationConfigRetriever struct {
GetApplicationConfigStub func(cid string) (channelconfig.Application, bool)
GetApplicationConfigStub func(string) (channelconfig.Application, bool)
getApplicationConfigMutex sync.RWMutex
getApplicationConfigArgsForCall []struct {
cid string
arg1 string
}
getApplicationConfigReturns struct {
result1 channelconfig.Application
......@@ -25,21 +25,22 @@ type ApplicationConfigRetriever struct {
invocationsMutex sync.RWMutex
}
func (fake *ApplicationConfigRetriever) GetApplicationConfig(cid string) (channelconfig.Application, bool) {
func (fake *ApplicationConfigRetriever) GetApplicationConfig(arg1 string) (channelconfig.Application, bool) {
fake.getApplicationConfigMutex.Lock()
ret, specificReturn := fake.getApplicationConfigReturnsOnCall[len(fake.getApplicationConfigArgsForCall)]
fake.getApplicationConfigArgsForCall = append(fake.getApplicationConfigArgsForCall, struct {
cid string
}{cid})
fake.recordInvocation("GetApplicationConfig", []interface{}{cid})
arg1 string
}{arg1})
fake.recordInvocation("GetApplicationConfig", []interface{}{arg1})
fake.getApplicationConfigMutex.Unlock()
if fake.GetApplicationConfigStub != nil {
return fake.GetApplicationConfigStub(cid)
return fake.GetApplicationConfigStub(arg1)
}
if specificReturn {
return ret.result1, ret.result2
}
return fake.getApplicationConfigReturns.result1, fake.getApplicationConfigReturns.result2
fakeReturns := fake.getApplicationConfigReturns
return fakeReturns.result1, fakeReturns.result2
}
func (fake *ApplicationConfigRetriever) GetApplicationConfigCallCount() int {
......@@ -48,13 +49,22 @@ func (fake *ApplicationConfigRetriever) GetApplicationConfigCallCount() int {
return len(fake.getApplicationConfigArgsForCall)
}
func (fake *ApplicationConfigRetriever) GetApplicationConfigCalls(stub func(string) (channelconfig.Application, bool)) {
fake.getApplicationConfigMutex.Lock()
defer fake.getApplicationConfigMutex.Unlock()
fake.GetApplicationConfigStub = stub
}
func (fake *ApplicationConfigRetriever) GetApplicationConfigArgsForCall(i int) string {
fake.getApplicationConfigMutex.RLock()
defer fake.getApplicationConfigMutex.RUnlock()
return fake.getApplicationConfigArgsForCall[i].cid
argsForCall := fake.getApplicationConfigArgsForCall[i]
return argsForCall.arg1
}
func (fake *ApplicationConfigRetriever) GetApplicationConfigReturns(result1 channelconfig.Application, result2 bool) {
fake.getApplicationConfigMutex.Lock()
defer fake.getApplicationConfigMutex.Unlock()
fake.GetApplicationConfigStub = nil
fake.getApplicationConfigReturns = struct {
result1 channelconfig.Application
......@@ -63,6 +73,8 @@ func (fake *ApplicationConfigRetriever) GetApplicationConfigReturns(result1 chan
}
func (fake *ApplicationConfigRetriever) GetApplicationConfigReturnsOnCall(i int, result1 channelconfig.Application, result2 bool) {
fake.getApplicationConfigMutex.Lock()
defer fake.getApplicationConfigMutex.Unlock()
fake.GetApplicationConfigStub = nil
if fake.getApplicationConfigReturnsOnCall == nil {
fake.getApplicationConfigReturnsOnCall = make(map[int]struct {
......
......@@ -2,66 +2,91 @@
package fake
import (
"sync"
sync "sync"
chaincode_test "github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/common/ccprovider"
chaincode "github.com/hyperledger/fabric/core/chaincode"
ccprovider "github.com/hyperledger/fabric/core/common/ccprovider"
)
type ContextRegistry struct {
CreateStub func(txParams *ccprovider.TransactionParams) (*chaincode_test.TransactionContext, error)
CloseStub func()
closeMutex sync.RWMutex
closeArgsForCall []struct {
}
CreateStub func(*ccprovider.TransactionParams) (*chaincode.TransactionContext, error)
createMutex sync.RWMutex
createArgsForCall []struct {
txParams *ccprovider.TransactionParams
arg1 *ccprovider.TransactionParams
}
createReturns struct {
result1 *chaincode_test.TransactionContext
result1 *chaincode.TransactionContext
result2 error
}
createReturnsOnCall map[int]struct {
result1 *chaincode_test.TransactionContext
result1 *chaincode.TransactionContext
result2 error
}
GetStub func(chainID, txID string) *chaincode_test.TransactionContext
DeleteStub func(string, string)
deleteMutex sync.RWMutex
deleteArgsForCall []struct {
arg1 string
arg2 string
}
GetStub func(string, string) *chaincode.TransactionContext
getMutex sync.RWMutex
getArgsForCall []struct {
chainID string
txID string
arg1 string
arg2 string
}
getReturns struct {
result1 *chaincode_test.TransactionContext
result1 *chaincode.TransactionContext
}
getReturnsOnCall map[int]struct {
result1 *chaincode_test.TransactionContext
result1 *chaincode.TransactionContext
}
DeleteStub func(chainID, txID string)
deleteMutex sync.RWMutex
deleteArgsForCall []struct {
chainID string
txID string
}
CloseStub func()
closeMutex sync.RWMutex
closeArgsForCall []struct{}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *ContextRegistry) Create(txParams *ccprovider.TransactionParams) (*chaincode_test.TransactionContext, error) {
func (fake *ContextRegistry) Close() {
fake.closeMutex.Lock()
fake.closeArgsForCall = append(fake.closeArgsForCall, struct {
}{})
fake.recordInvocation("Close", []interface{}{})
fake.closeMutex.Unlock()
if fake.CloseStub != nil {
fake.CloseStub()
}
}
func (fake *ContextRegistry) CloseCallCount() int {
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
return len(fake.closeArgsForCall)
}
func (fake *ContextRegistry) CloseCalls(stub func()) {
fake.closeMutex.Lock()
defer fake.closeMutex.Unlock()
fake.CloseStub = stub
}
func (fake *ContextRegistry) Create(arg1 *ccprovider.TransactionParams) (*chaincode.TransactionContext, error) {
fake.createMutex.Lock()
ret, specificReturn := fake.createReturnsOnCall[len(fake.createArgsForCall)]
fake.createArgsForCall = append(fake.createArgsForCall, struct {
txParams *ccprovider.TransactionParams
}{txParams})
fake.recordInvocation("Create", []interface{}{txParams})
arg1 *ccprovider.TransactionParams
}{arg1})
fake.recordInvocation("Create", []interface{}{arg1})
fake.createMutex.Unlock()
if fake.CreateStub != nil {
return fake.CreateStub(txParams)
return fake.CreateStub(arg1)
}
if specificReturn {
return ret.result1, ret.result2
}
return fake.createReturns.result1, fake.createReturns.result2
fakeReturns := fake.createReturns
return fakeReturns.result1, fakeReturns.result2
}
func (fake *ContextRegistry) CreateCallCount() int {
......@@ -70,50 +95,94 @@ func (fake *ContextRegistry) CreateCallCount() int {
return len(fake.createArgsForCall)
}
func (fake *ContextRegistry) CreateCalls(stub func(*ccprovider.TransactionParams) (*chaincode.TransactionContext, error)) {
fake.createMutex.Lock()
defer fake.createMutex.Unlock()
fake.CreateStub = stub
}
func (fake *ContextRegistry) CreateArgsForCall(i int) *ccprovider.TransactionParams {
fake.createMutex.RLock()
defer fake.createMutex.RUnlock()
return fake.createArgsForCall[i].txParams
argsForCall := fake.createArgsForCall[i]
return argsForCall.arg1
}
func (fake *ContextRegistry) CreateReturns(result1 *chaincode_test.TransactionContext, result2 error) {
func (fake *ContextRegistry) CreateReturns(result1 *chaincode.TransactionContext, result2 error) {
fake.createMutex.Lock()
defer fake.createMutex.Unlock()
fake.CreateStub = nil
fake.createReturns = struct {
result1 *chaincode_test.TransactionContext
result1 *chaincode.TransactionContext
result2 error
}{result1, result2}
}
func (fake *ContextRegistry) CreateReturnsOnCall(i int, result1 *chaincode_test.TransactionContext, result2 error) {
func (fake *ContextRegistry) CreateReturnsOnCall(i int, result1 *chaincode.TransactionContext, result2 error) {
fake.createMutex.Lock()
defer fake.createMutex.Unlock()
fake.CreateStub = nil
if fake.createReturnsOnCall == nil {
fake.createReturnsOnCall = make(map[int]struct {
result1 *chaincode_test.TransactionContext
result1 *chaincode.TransactionContext
result2 error
})
}
fake.createReturnsOnCall[i] = struct {
result1 *chaincode_test.TransactionContext
result1 *chaincode.TransactionContext
result2 error
}{result1, result2}
}
func (fake *ContextRegistry) Get(chainID string, txID string) *chaincode_test.TransactionContext {
func (fake *ContextRegistry) Delete(arg1 string, arg2 string) {
fake.deleteMutex.Lock()
fake.deleteArgsForCall = append(fake.deleteArgsForCall, struct {
arg1 string
arg2 string
}{arg1, arg2})
fake.recordInvocation("Delete", []interface{}{arg1, arg2})
fake.deleteMutex.Unlock()
if fake.DeleteStub != nil {
fake.DeleteStub(arg1, arg2)
}
}
func (fake *ContextRegistry) DeleteCallCount() int {
fake.deleteMutex.RLock()
defer fake.deleteMutex.RUnlock()
return len(fake.deleteArgsForCall)
}
func (fake *ContextRegistry) DeleteCalls(stub func(string, string)) {
fake.deleteMutex.Lock()
defer fake.deleteMutex.Unlock()
fake.DeleteStub = stub
}
func (fake *ContextRegistry) DeleteArgsForCall(i int) (string, string) {
fake.deleteMutex.RLock()
defer fake.deleteMutex.RUnlock()
argsForCall := fake.deleteArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2
}
func (fake *ContextRegistry) Get(arg1 string, arg2 string) *chaincode.TransactionContext {
fake.getMutex.Lock()
ret, specificReturn := fake.getReturnsOnCall[len(fake.getArgsForCall)]
fake.getArgsForCall = append(fake.getArgsForCall, struct {
chainID string
txID string
}{chainID, txID})
fake.recordInvocation("Get", []interface{}{chainID, txID})
arg1 string
arg2 string
}{arg1, arg2})
fake.recordInvocation("Get", []interface{}{arg1, arg2})
fake.getMutex.Unlock()
if fake.GetStub != nil {
return fake.GetStub(chainID, txID)
return fake.GetStub(arg1, arg2)
}
if specificReturn {
return ret.result1
}
return fake.getReturns.result1
fakeReturns := fake.getReturns
return fakeReturns.result1
}
func (fake *ContextRegistry) GetCallCount() int {
......@@ -122,83 +191,53 @@ func (fake *ContextRegistry) GetCallCount() int {
return len(fake.getArgsForCall)
}
func (fake *ContextRegistry) GetCalls(stub func(string, string) *chaincode.TransactionContext) {
fake.getMutex.Lock()
defer fake.getMutex.Unlock()
fake.GetStub = stub
}
func (fake *ContextRegistry) GetArgsForCall(i int) (string, string) {
fake.getMutex.RLock()
defer fake.getMutex.RUnlock()
return fake.getArgsForCall[i].chainID, fake.getArgsForCall[i].txID
argsForCall := fake.getArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2
}
func (fake *ContextRegistry) GetReturns(result1 *chaincode_test.TransactionContext) {
func (fake *ContextRegistry) GetReturns(result1 *chaincode.TransactionContext) {
fake.getMutex.Lock()
defer fake.getMutex.Unlock()
fake.GetStub = nil
fake.getReturns = struct {
result1 *chaincode_test.TransactionContext
result1 *chaincode.TransactionContext
}{result1}
}
func (fake *ContextRegistry) GetReturnsOnCall(i int, result1 *chaincode_test.TransactionContext) {
func (fake *ContextRegistry) GetReturnsOnCall(i int, result1 *chaincode.TransactionContext) {
fake.getMutex.Lock()
defer fake.getMutex.Unlock()
fake.GetStub = nil
if fake.getReturnsOnCall == nil {
fake.getReturnsOnCall = make(map[int]struct {
result1 *chaincode_test.TransactionContext
result1 *chaincode.TransactionContext
})
}
fake.getReturnsOnCall[i] = struct {
result1 *chaincode_test.TransactionContext
result1 *chaincode.TransactionContext
}{result1}
}
func (fake *ContextRegistry) Delete(chainID string, txID string) {
fake.deleteMutex.Lock()
fake.deleteArgsForCall = append(fake.deleteArgsForCall, struct {
chainID string
txID string
}{chainID, txID})
fake.recordInvocation("Delete", []interface{}{chainID, txID})
fake.deleteMutex.Unlock()
if fake.DeleteStub != nil {
fake.DeleteStub(chainID, txID)
}
}
func (fake *ContextRegistry) DeleteCallCount() int {
fake.deleteMutex.RLock()
defer fake.deleteMutex.RUnlock()
return len(fake.deleteArgsForCall)
}
func (fake *ContextRegistry) DeleteArgsForCall(i int) (string, string) {
fake.deleteMutex.RLock()
defer fake.deleteMutex.RUnlock()
return fake.deleteArgsForCall[i].chainID, fake.deleteArgsForCall[i].txID
}
func (fake *ContextRegistry) Close() {
fake.closeMutex.Lock()
fake.closeArgsForCall = append(fake.closeArgsForCall, struct{}{})
fake.recordInvocation("Close", []interface{}{})
fake.closeMutex.Unlock()
if fake.CloseStub != nil {
fake.CloseStub()
}
}
func (fake *ContextRegistry) CloseCallCount() int {
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
return len(fake.closeArgsForCall)
}
func (fake *ContextRegistry) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
fake.createMutex.RLock()
defer fake.createMutex.RUnlock()
fake.getMutex.RLock()
defer fake.getMutex.RUnlock()
fake.deleteMutex.RLock()
defer fake.deleteMutex.RUnlock()
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
fake.getMutex.RLock()
defer fake.getMutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
......
......@@ -2,29 +2,16 @@
package fake
import (
"sync"
sync "sync"
chaincode_test "github.com/hyperledger/fabric/core/chaincode"
chaincode "github.com/hyperledger/fabric/core/chaincode"
)
type LaunchRegistry struct {
LaunchingStub func(cname string) (*chaincode_test.LaunchState, bool)
launchingMutex sync.RWMutex
launchingArgsForCall []struct {
cname string
}
launchingReturns struct {
result1 *chaincode_test.LaunchState
result2 bool
}
launchingReturnsOnCall map[int]struct {
result1 *chaincode_test.LaunchState
result2 bool
}
DeregisterStub func(cname string) error
DeregisterStub func(string) error
deregisterMutex sync.RWMutex
deregisterArgsForCall []struct {
cname string
arg1 string
}
deregisterReturns struct {
result1 error
......@@ -32,76 +19,39 @@ type LaunchRegistry struct {
deregisterReturnsOnCall map[int]struct {
result1 error
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *LaunchRegistry) Launching(cname string) (*chaincode_test.LaunchState, bool) {
fake.launchingMutex.Lock()
ret, specificReturn := fake.launchingReturnsOnCall[len(fake.launchingArgsForCall)]
fake.launchingArgsForCall = append(fake.launchingArgsForCall, struct {
cname string
}{cname})
fake.recordInvocation("Launching", []interface{}{cname})
fake.launchingMutex.Unlock()
if fake.LaunchingStub != nil {
return fake.LaunchingStub(cname)
}
if specificReturn {
return ret.result1, ret.result2
LaunchingStub func(string) (*chaincode.LaunchState, bool)
launchingMutex sync.RWMutex
launchingArgsForCall []struct {
arg1 string
}
return fake.launchingReturns.result1, fake.launchingReturns.result2
}
func (fake *LaunchRegistry) LaunchingCallCount() int {
fake.launchingMutex.RLock()
defer fake.launchingMutex.RUnlock()
return len(fake.launchingArgsForCall)
}
func (fake *LaunchRegistry) LaunchingArgsForCall(i int) string {
fake.launchingMutex.RLock()
defer fake.launchingMutex.RUnlock()
return fake.launchingArgsForCall[i].cname
}
func (fake *LaunchRegistry) LaunchingReturns(result1 *chaincode_test.LaunchState, result2 bool) {
fake.LaunchingStub = nil
fake.launchingReturns = struct {
result1 *chaincode_test.LaunchState
launchingReturns struct {
result1 *chaincode.LaunchState
result2 bool
}{result1, result2}
}
func (fake *LaunchRegistry) LaunchingReturnsOnCall(i int, result1 *chaincode_test.LaunchState, result2 bool) {
fake.LaunchingStub = nil
if fake.launchingReturnsOnCall == nil {
fake.launchingReturnsOnCall = make(map[int]struct {
result1 *chaincode_test.LaunchState
result2 bool
})
}
fake.launchingReturnsOnCall[i] = struct {
result1 *chaincode_test.LaunchState
launchingReturnsOnCall map[int]struct {
result1 *chaincode.LaunchState
result2 bool
}{result1, result2}
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *LaunchRegistry) Deregister(cname string) error {
func (fake *LaunchRegistry) Deregister(arg1 string) error {
fake.deregisterMutex.Lock()
ret, specificReturn := fake.deregisterReturnsOnCall[len(fake.deregisterArgsForCall)]
fake.deregisterArgsForCall = append(fake.deregisterArgsForCall, struct {
cname string
}{cname})