Skip to content

Commit

Permalink
[FAB-18169] Add DevMode support in ChaincodeEndorsementInfoSource
Browse files Browse the repository at this point in the history
* Added DevMode support in ChaincodeEndorsementInfoSource, when
  chaincode is launched by developer and missing Installinfo from
  chaincodeInfo cache, rebuild Installinfo and return accordinly.

Signed-off-by: Chongxin Luo <Chongxin.Luo@ibm.com>
  • Loading branch information
DereckLuo authored and sykesm committed Aug 28, 2020
1 parent 8bbedb8 commit 9da753a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package lifecycle
import (
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/scc"

"github.com/pkg/errors"
)

Expand Down Expand Up @@ -46,6 +45,7 @@ type ChaincodeEndorsementInfoSource struct {
Cache ChaincodeInfoCache
LegacyImpl Lifecycle
BuiltinSCCs scc.BuiltinSCCs
UserRunsCC bool
}

func (cei *ChaincodeEndorsementInfoSource) CachedChaincodeInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*LocalChaincodeInfo, bool, error) {
Expand Down Expand Up @@ -90,6 +90,12 @@ func (cei *ChaincodeEndorsementInfoSource) CachedChaincodeInfo(channelID, chainc
}

if chaincodeInfo.InstallInfo == nil {
if cei.UserRunsCC {
chaincodeInfo.InstallInfo = &ChaincodeInstallInfo{
PackageID: chaincodeName + ":" + chaincodeInfo.Definition.EndorsementInfo.Version,
}
return chaincodeInfo, true, nil
}
return nil, false, errors.Errorf("chaincode definition for '%s' exists, but chaincode is not installed", chaincodeName)
}

Expand Down Expand Up @@ -130,6 +136,10 @@ func (cei *ChaincodeEndorsementInfoSource) ChaincodeEndorsementInfo(channelID, c
return cei.LegacyImpl.ChaincodeEndorsementInfo(channelID, chaincodeName, qe)
}

if chaincodeInfo.InstallInfo == nil {
chaincodeInfo.InstallInfo = &ChaincodeInstallInfo{}
}

return &ChaincodeEndorsementInfo{
Version: chaincodeInfo.Definition.EndorsementInfo.Version,
EnforceInit: chaincodeInfo.Definition.EndorsementInfo.InitRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,40 @@ var _ = Describe("ChaincodeEndorsementInfoSource", func() {
Expect(err).To(MatchError("could not get current sequence for chaincode 'name' on channel '': could not get state for key namespaces/fields/name/Sequence: invalid channel-less operation"))
})
})

Context("when running chaincode in devmode", func() {
BeforeEach(func() {
testInfo.InstallInfo = nil
cei.UserRunsCC = true
})

It("set chaincode installInfo to {chaincodeName}:{chaincodeVersion}", func() {
info, ok, err := cei.CachedChaincodeInfo("channel-id", "name", fakeQueryExecutor)
Expect(err).NotTo(HaveOccurred())
Expect(ok).To(BeTrue())
Expect(info).To(Equal(&lifecycle.LocalChaincodeInfo{
Definition: &lifecycle.ChaincodeDefinition{
Sequence: 7,
EndorsementInfo: &lb.ChaincodeEndorsementInfo{
Version: "version",
EndorsementPlugin: "endorsement-plugin",
},
ValidationInfo: &lb.ChaincodeValidationInfo{
ValidationPlugin: "validation-plugin",
ValidationParameter: []byte("validation-parameter"),
},
},
InstallInfo: &lifecycle.ChaincodeInstallInfo{
PackageID: "name:version",
},
Approved: true,
}))
Expect(fakeCache.ChaincodeInfoCallCount()).To(Equal(1))
channelID, chaincodeName := fakeCache.ChaincodeInfoArgsForCall(0)
Expect(channelID).To(Equal("channel-id"))
Expect(chaincodeName).To(Equal("name"))
})
})
})

Describe("ChaincodeEndorsementInfo", func() {
Expand Down
1 change: 1 addition & 0 deletions internal/peer/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ func serve(args []string) error {
Resources: lifecycleResources,
Cache: lifecycleCache,
BuiltinSCCs: builtinSCCs,
UserRunsCC: userRunsCC,
}

containerRuntime := &chaincode.ContainerRuntime{
Expand Down

0 comments on commit 9da753a

Please sign in to comment.