Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement query committed chaincodes in channel #88

Merged

Conversation

samuelvenzi
Copy link
Contributor

  • Implement query committed function
  • Implement query committed unit test
  • Add query committed to e2e test

Signed-off-by: Samuel Venzi samuel.venzi@me.com

Signed-off-by: Samuel Venzi <samuel.venzi@me.com>
@samuelvenzi samuelvenzi marked this pull request as ready for review February 9, 2023 13:02
@samuelvenzi samuelvenzi mentioned this pull request Feb 9, 2023
22 tasks
Signed-off-by: Samuel Venzi <samuel.venzi@me.com>
@samuelvenzi
Copy link
Contributor Author

I let slip a small type error in the cc sequence verification. It's corrected and e2e test should be successful now.


// QueryCommitted chaincode on a specific peer.
func QueryCommitted(ctx context.Context, connection grpc.ClientConnInterface, signingID identity.SigningIdentity, channelID string) (*lifecycle.QueryChaincodeDefinitionsResult, error) {
queryArgs := &lifecycle.QueryChaincodeDefinitionsArgs{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/hyperledger/fabric/blob/main/internal/peer/lifecycle/chaincode/querycommitted.go#L223-L227
if I am correct, we can add chaincode name a parameter? ref to fabric code as example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, @bestbeforetoday , we removed name as parameter at https://github.com/hyperledger/fabric-protos-go-apiv2/blob/main/peer/lifecycle/lifecycle.pb.go#L1290-L1328 ?
are we able to pass QueryChaincodeDefinitionsArgs with name in fabric-protos-go-apiv2?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, @bestbeforetoday , we removed name as parameter at https://github.com/hyperledger/fabric-protos-go-apiv2/blob/main/peer/lifecycle/lifecycle.pb.go#L1290-L1328 ?
are we able to pass QueryChaincodeDefinitionsArgs with name in fabric-protos-go-apiv2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are currently two options for querying committed chaincodes in Fabric. One of them queries all committed in the channel and the other filters it by chaincode name.

One uses QueryChaincodeDefinitions tx name and the other uses QueryChaincodeDefinition.

Should I proceed to add both options then? In separate functions or the same?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose if possible, we should support both query all and query by name.

Copy link
Contributor Author

@samuelvenzi samuelvenzi Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we able to pass QueryChaincodeDefinitionsArgs with name in fabric-protos-go-apiv2?

We can use QueryChaincodeDefinitionArgs with name. I can do this after this PR.

type QueryChaincodeDefinitionArgs struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by default, I will merge this PR before Monday, will keep this PR open for other reviewers. :-)
it's 11 pm my local time, I am going to have a rest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelvenzi , you are able to have another PR for query by name after this PR been merged.

Copy link
Member

@bestbeforetoday bestbeforetoday Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When querying installed chaincode, there are two options: query all installed chaincodes, or query a specific named chaincode. Both options return exactly the same information about the installed chaincode(s). The difference is whether you get information about all or only one of the installed chaincodes. I can't see much point in the versions where you specify the name since you can just pick the name you are interested in from the all installed chaincodes result.

When querying committed chaincode, there are the same two options: query all committed, or query a specific named chaincode. I have no idea why, but for this query they actually return slightly different information. Querying for a specific named chaincode returns all the information returned from querying all, and also includes the approvals for that chaincode.

So for query installed, I am personally happy with just querying for all installed chaincodes. Query for a specific installed chaincode just means more code to maintain for no value.

For query committed, I think we will need to prove API calls for both options. I would prefer to have two different API calls. Any preferences on the naming? It could be QueryAllCommitted and QueryCommitted, or QueryCommitted and QueryCommittedWithName, or something else...? That can happen in a later PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer QueryCommitted and QueryCommittedWithName. I didn't realize the information was slightly different, but you're right.

SamYuan1990
SamYuan1990 previously approved these changes Feb 9, 2023
Copy link
Contributor

@SamYuan1990 SamYuan1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, as comments with nit enhancement maybe blocked by proto definitions and I don't want that block this PR.

Copy link
Member

@bestbeforetoday bestbeforetoday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. Thank you for the contribution! I've added my thoughts to the discussions in the comments but generally happy with this PR as-is. Just one change to the e2e test code that I think would be worth making - see in-line comments.


// QueryCommitted chaincode on a specific peer.
func QueryCommitted(ctx context.Context, connection grpc.ClientConnInterface, signingID identity.SigningIdentity, channelID string) (*lifecycle.QueryChaincodeDefinitionsResult, error) {
queryArgs := &lifecycle.QueryChaincodeDefinitionsArgs{}
Copy link
Member

@bestbeforetoday bestbeforetoday Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When querying installed chaincode, there are two options: query all installed chaincodes, or query a specific named chaincode. Both options return exactly the same information about the installed chaincode(s). The difference is whether you get information about all or only one of the installed chaincodes. I can't see much point in the versions where you specify the name since you can just pick the name you are interested in from the all installed chaincodes result.

When querying committed chaincode, there are the same two options: query all committed, or query a specific named chaincode. I have no idea why, but for this query they actually return slightly different information. Querying for a specific named chaincode returns all the information returned from querying all, and also includes the approvals for that chaincode.

So for query installed, I am personally happy with just querying for all installed chaincodes. Query for a specific installed chaincode just means more code to maintain for no value.

For query committed, I think we will need to prove API calls for both options. I would prefer to have two different API calls. Any preferences on the naming? It could be QueryAllCommitted and QueryCommitted, or QueryCommitted and QueryCommittedWithName, or something else...? That can happen in a later PR.

test/e2e_test.go Outdated
@@ -273,6 +273,14 @@ var _ = Describe("e2e", func() {
printGrpcError(err)
Expect(err).NotTo(HaveOccurred(), "commit chaincode")

result, err := chaincode.QueryCommitted(specCtx, peerConnections[0].connection, peerConnections[0].id, channelName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit above should have caused the chaincode to be committed on all network peers where it was installed. We could confirm this by querying installed chaincode on both org peers.

However, we only know for sure that the commit has completed on the (Gateway) peer where we invoked the commit since that is where we observe the successfully committed transaction in the ledger. The other peers may not yet have processed the transaction. So I think this approach of querying just the peer used for the commit is reasonable.

One thing I would change though... using peerConnections[0] happens to be the same peer that was used for the commit but that could change if somebody changed the code above later. I think it would be better to be more explicit about the peer being used with n_conn1 as the connection and org1MSP as the identity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer, @bestbeforetoday. Changing it now.

Signed-off-by: Samuel Venzi <samuel.venzi@me.com>
@bestbeforetoday bestbeforetoday merged commit a37ccb5 into hyperledger:main Feb 9, 2023
@samuelvenzi samuelvenzi deleted the feature/querycommitted branch February 10, 2023 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants