Open alfredomusumeci opened 1 year ago
Unfortunately, the Fabric endorsement/validation plugins was introduced in Fabric v1.2. Notice the import path of the protobufs in v1.2 and the same path in the latest Fabric.
Since Go plugins only work if the plugin was compiled with the exact same version of all dependencies as the binary that loads it, you need the fabric-protos-go and fabric repositories to have the same protobuf versions.
In the beginning it was easy to ensure that, as everything was in the same project, but then it was decided to split Fabric core into several projects... which makes things harder but it should still be possible.
It seems that the google protobuf's versions are the same in both fabric-protos-go and fabric so I think that part should work.
I still need to import "github.com/hyperledger/fabric/protoutil". If I don't do this, the file won't build as the compiler will complain that:
You can try and copy the code from that package into your program. The protoutil only has helper functions.
In any case, you should also read this JIRA issue.
Hello yacovm, thank you for your answer. In that case, why hasn't it been proposed to update the binary that loads the plugin to the latest version of fabric? Also, do you know the name of such binary? Perhaps, if I were to disassemble it, I could see what are the different versions of packages required, as this feels much like I am playing random with finding the correct dependencies. Moreover, the dependencies in my go.mod are the exact same as the latest branch, hence I would need to start modifying all deps inside the cloned fabric repository and that may start to break everything, so I believe it may be a better approach if I had a list of deps versions I could look at?
Also, I see that you're planning to remove the support for plugins altogether. In that case, if I wanted to modify both the Lifecycle Endorsement Policy and also the Chaincode Endorsement Policy, I have no choice but to change the underlying fabric source code and rebuild the images, is that right?
In that case, why hasn't it been proposed to update the binary that loads the plugin to the latest version of fabric?
What do you mean? That binary... is the Fabric peer.
Moreover, the dependencies in my go.mod are the exact same as the latest branch, hence I would need to start modifying all deps inside the cloned fabric repository and that may start to break everything, so I believe it may be a better approach if I had a list of deps versions I could look at?
What I suggest is that you first check if your solution works with Fabric 1.2 codebase. Compile a Fabric v1.2 peer and a plugin and try to make the validation plugin work. If it doesn't work there, you have a fundamental problem unrelated to Fabric. If it works, then the problem is some dependency discrepancy.
Also, I see that you're planning to remove the support for plugins altogether. In that case, if I wanted to modify both the Lifecycle Endorsement Policy and also the Chaincode Endorsement Policy, I have no choice but to change the underlying fabric source code and rebuild the images, is that right?
I don't think there is any plan to do anything in that area, anytime soon :-)
Description
I've been trying for a few weeks now to create a custom pluggable validation and have that instead of DefaultValidation. The code is as below:
I have then added this to my core.yaml file after having compiled it as a plugin (.so):
and started up my network.sh file with the command network.sh up.
Finally, I get the error:
To give a bit more context, this is my go.mod:
In order to ensure that I am using the same compiler options, I have cloned fabric-tools container, and made an image out of it. Then, I started my own container which I use only to build my plugin in .so (this takes care of using the right version of glibc, go, and various other options). When the file is compiled, I then move it in the folder where I have mounted my volume for the ./network.sh to locate the file. In this particular instance, my error is related to
google.golang.org/protobuf/internal/detrand
, however, before this wasgoogle.golang.org/protobuf
, and earlierruntime/internal/atomic
. In essence, a new error always pop-ups.Things I noticed: although I am using a clone of fabric 2.5.0 repo, I still need to import "github.com/hyperledger/fabric/protoutil". If I don't do this, the file won't build as the compiler will complain that:
It seems like, there might be a problem with google-protobuf package as that is the one that seems to be complaining the most. However, I have made sure that my go.mod is identical to the one used in the fabric branch 2.5.0, thus I have no idea why this is happening.
Lastly, I tried building a plugin out of a hello world plugin, and that worked (it complained about missing specific interfaces, but that was expected as I didn't add PluginFactory and all that). However, I'd need to add dependencies specifically to protobuf to unpack my message and as soon as I do that everything would break.
Useful Info: I am using a clone of 2.5.0 Fabric branch, the docker images are also up to date.
Steps to reproduce
NB: this uses the fabric samples with 3 orgs.
Commit the existing container to a new Docker image: docker commit :
Run the container docker run -d --name : tail -f /dev/null
Install necessary packages docker exec -it sh
then type su and install vim and git-build-essentials.
su
apt-get install -y curl git build-essential
apt-get install -y curl vim
Copy cloned repository to the container GOPATH (NB: adjust paths accordingly) docker cp /home/alfredo/go/src/github.com/alfredom/fabric:/opt/gopath/src/github.com/fabric
Copy plugin to the container docker cp /home/alfredo/go/src/github.com/alfredom/fabric-samples/test-network-3-orgs/custom_validation/test_validation.go 5f2397807828:/opt/gopath/src/github.com/hyperledger/fabric/peer/test_validation.go
Run go mod and edit go mod init main echo 'replace github.com/alfredom/fabric => /opt/gopath/src/github.com/fabric' >> go.mod (adjust this accordingly) echo 'replace github.com/willf/bitset v1.2.1 => github.com/bits-and-blooms/bitset v1.2.1' >> go.mod
Build the plugin go build -buildmode=plugin -o test_validation_no_flags.so test_validation.go
Copy it out to the destination folder (adjust accordingly) docker cp:/opt/gopath/src/github.com/hyperledger/fabric/peer/test_validation_no_flags.so /home/alfredo/go/src/github.com/alfredom/fabric-samples/test-network-3-orgs/custom_validation/test_validation_no_flags.so
./network.sh down; ./network.sh up; then show logs or alternatively change the following line in the network.sh file DOCKER_SOCK="${DOCKER_SOCK}" ${CONTAINER_CLI_COMPOSE} ${COMPOSE_FILES} up -d 2>&1 to DOCKER_SOCK="${DOCKER_SOCK}" ${CONTAINER_CLI_COMPOSE} ${COMPOSE_FILES} up.