feat: migrate to fabric-chaincode-go/v2 and release as cc-tools/v2 - #57
Open
PsychoPunkSage wants to merge 1 commit into
Open
PsychoPunkSage wants to merge 1 commit into
PsychoPunkSage wants to merge 1 commit into
Conversation
Signed-off-by: Abhinav Prakash <abhinav.prakash319@gmail.com>
Member
|
Hey @PsychoPunkSage, this looks good overall. I'm just running some tests on cc-tools-demo with this code before proceeding with the approval |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Retargets cc-tools from the 2021-era Fabric Go packages to their current successors, and moves the module to the
/v2path:github.com/hyperledger-labs/cc-toolsgithub.com/hyperledger-labs/cc-tools/v2fabric-chaincode-go v0.0.0-20210603161043fabric-chaincode-go/v2 v2.3.0fabric-protos-go v0.0.0-20210528200356fabric-protos-go-apiv2 v0.3.7github.com/golang/protobufgoogle.golang.org/protobufCloses #56
Why
Consumers that have migrated to
fabric-chaincode-go/v2cannot use cc-tools at all. The v1 and v2 module lines are distinct types to the Go compiler, sotx.Run(stub)andTxError.GetErrorResponse()reject v2 values. This surfaced in Hyperledger Fabric Private Chaincode, where theconfidential-escrowsample stopped building after FPC's v2 migration. It isn't fixable at the call site, since the signatures are cc-tools'.Breaking changes
This is why it needs
/v2rather than a patch release:ICCError.GetErrorResponse()now returns*peer.Responseinstead ofpeer.Response. Required because shim v2'sInvokereturns*peer.Response, so the commonresponse = err.GetErrorResponse()pattern needs a pointer. protobuf-go v2 messages also shouldn't be copied by value.MockStub.MockInit,MockInvoke,MockInvokeWithSignedProposal,InvokeChaincodereturn*pb.Response.MockStub.TxTimestampis*timestamppb.Timestampinstead of*timestamp.Timestamp.Existing users are unaffected. Under semantic import versioning
cc-tools/v2is a separate module, so anything pinned at v1.0.x keeps resolving v1.0.x.Changes
cc-tools/v2/..., and Fabric imports tofabric-chaincode-go/v2/...andfabric-protos-go-apiv2/.... Mechanical.GetErrorResponse()returns a pointer.ptypes.TimestampNow()becomestimestamppb.Now()), pointer responses, and five methods added to satisfy the v2ChaincodeStubInterface:GetMultipleStatesandGetMultiplePrivateData, implemented by looping the single-key getterGetAllStatesCompositeKeyWithPagination, returnsnil, nil, nilto match the existing*WithPaginationstubsStartWriteBatchandFinishWriteBatch, no-ops since MockStub doesn't batchfabric-chaincode-go/v2declaresgo 1.22.0and CI images pinGOTOOLCHAIN=local, so 1.21 hard-refuses rather than fetching a newer toolchain.Compatibility with older Fabric peers
Checked before proposing this, since cc-tools has users on older peers. Full write-up: hyperledger/fabric-private-chaincode#957 (comment)
Summary:
ChaincodeMessage.Typevalues 0-22 are identical betweenfabric-protos-goand-apiv2, with the same names, same numbers, and nothing renumbered or removed. Protobuf encoding depends only on those numbers, so the wire bytes are unchanged. The v1 to v2 move is Go codegen, not protocol.PURGE_PRIVATE_DATA(23) andGET_STATE_MULTIPLE(25) are only emitted from their opt-in stub methods.WRITE_BATCH_STATE(24) is negotiated: the shim readsChaincodeAdditionalParamsfrom the peer'sREGISTEREDpayload, and an older peer that predates the field leavesUseWriteBatchfalse, so writes go out as ordinaryPUT_STATE. Upstream tests this instub_test.gounder"WriteBatch - Old peer (usePeerWriteBatch false)".MockStub.So runtime behaviour against older peers is unchanged. The one real constraint is the build toolchain: chaincode using this will need a Go 1.22 or newer build path, which means a newer
ccenvincore.yamlor an external builder for anyone on an older peer's default build image.Testing
go build ./...,go vet ./...,go test ./...all passNotes and possible follow-ups
github.com/hyperledger/fabric v2.1.1+incompatibleis still a direct dependency, used only forutil.ComputeSHA256instubwrapper. It's+incompatibleso it contributes no transitive requirements and doesn't reintroduce v1 protos. I left it alone to keep this PR to the migration, but it could be dropped forcrypto/sha256separately.doc.gois flagged by newer gofmt. Pre-existing, untouched here.