HyperledgerHandsOn / trade-finance-logistics

Trade Finance and Logistics based on Letter of Credit and Proof of Shipment
Apache License 2.0
178 stars 1.5k forks source link

Invalid yaml definition in trade-finance-logistics/network/configtx.yaml #36

Closed JerryKwan closed 6 years ago

JerryKwan commented 6 years ago

When i run configtxgen to generate genesis block i encountered the following errors

ubuntu@ubuntu:~/go/src/trade-finance-logistics/network$ configtxgen -profile FourOrgsTradeOrdererGenesis -outputBlock ./channelartifacts/genesis.block 2018-08-30 01:58:27.690 EDT [common/tools/configtxgen] main -> WARN 001 Omitting the channel ID for configtxgen is deprecated. Explicitly passing the channel ID will be required in the future, defaulting to 'testchainid'. 2018-08-30 01:58:27.690 EDT [common/tools/configtxgen] main -> INFO 002 Loading configuration 2018-08-30 01:58:27.691 EDT [common/tools/configtxgen/localconfig] Load -> CRIT 003 Error reading configuration: While parsing config: yaml: unknown anchor 'ChannelCapabilities' referenced 2018-08-30 01:58:27.691 EDT [common/tools/configtxgen] func1 -> CRIT 004 Error reading configuration: While parsing config: yaml: unknown anchor 'ChannelCapabilities' referenced panic: Error reading configuration: While parsing config: yaml: unknown anchor 'ChannelCapabilities' referenced [recovered] panic: Error reading configuration: While parsing config: yaml: unknown anchor 'ChannelCapabilities' referenced

goroutine 1 [running]: github.com/hyperledger/fabric/vendor/github.com/op/go-logging.(Logger).Panic(0xc4201abe00, 0xc42039dd00, 0x1, 0x1) /home/ubuntu/go/src/github.com/hyperledger/fabric/vendor/github.com/op/go-logging/logger.go:188 +0xbd main.main.func1() /home/ubuntu/go/src/github.com/hyperledger/fabric/common/tools/configtxgen/main.go:254 +0x1ae panic(0xc6ea00, 0xc42039dcf0) /usr/lib/go-1.10/src/runtime/panic.go:505 +0x229 github.com/hyperledger/fabric/vendor/github.com/op/go-logging.(Logger).Panic(0xc4201abc50, 0xc4201a57a0, 0x2, 0x2) /home/ubuntu/go/src/github.com/hyperledger/fabric/vendor/github.com/op/go-logging/logger.go:188 +0xbd github.com/hyperledger/fabric/common/tools/configtxgen/localconfig.Load(0x7ffd1ef6d6d8, 0x1b, 0x0, 0x0, 0x0, 0x1) /home/ubuntu/go/src/github.com/hyperledger/fabric/common/tools/configtxgen/localconfig/config.go:277 +0x469 main.main() /home/ubuntu/go/src/github.com/hyperledger/fabric/common/tools/configtxgen/main.go:265 +0xce7

And after digging deeper, i thought it was caused by the wrong yaml definition, we used alias ChannelCapabilities before anchor ChannelCapabilities, so the parser thought it was invalid, and the following are the yaml specification about Anchor and Alias

3.3.1. Well-Formed Streams and Identified Aliases A well-formed character stream must match the BNF productions specified in the following chapters. Successful loading also requires that each alias shall refer to a previous node identified by the anchor. A YAML processor should reject ill-formed streams and unidentified aliases. A YAML processor may recover from syntax errors, possibly by ignoring certain parts of the input, but it must provide a mechanism for reporting such errors.

And if we move the Profiles's definition to the bottom of the file, then it will be considered as a valid yaml file, and configtxgen succeed.

VRamakrishna commented 6 years ago

What version of Fabric are you using? This code was built and tested for release-1.1. The YAML file won't work with configtxgen if you built it using the release-1.2 (or master) code.

JerryKwan commented 6 years ago

@VRamakrishna , please read the error message carefully, it complains about the wrong format of the yaml file, and i have tested the yaml file using Python and using https://codebeautify.org/yaml-validator too, all of them prompted similar error,

Error : Reference "ChannelCapabilities" does not exist. Line : 5 <<: *ChannelCapabilities

VRamakrishna commented 6 years ago

I understood the error message. And yes, the YAML file is not in a standard format: some parsers fail (I remember JavaScript parsers failing, and you point out that your Python parser is reporting an error too), but I also remember that parsing in Golang worked.

Luckily, you don't have to explicitly parse the file using a third-party parser. The configtxgen tool (which is used in the shell script you run to create a network) takes care of that for you. The YAML file that's checked in here works with the tool IF you built it using the release-1.1 branch of hyperledger/fabric. (The file also follows the same template used in other toy examples you'll find in the Hyperledger repo.)

I know for a fact that this YAML file fails to parse if you use a tool built from release-1.2 (or any version of Fabric later than 1.1.) Which is why I asked you to make sure you had the right versions. If you can promise me you did that, I'm willing to dig further. Otherwise, I'm going to assume that what's been working for many months now continues to work.

JerryKwan commented 6 years ago

@VRamakrishna , thank you for your explanation The version i am using is 1.2.1, and after i changed the .yaml definition, configtxgen succeed

VRamakrishna commented 6 years ago

OK, that's good, but just to be clear, I was referring to the branches of the Fabric source: https://github.com/hyperledger/fabric/. It has branches named release-1.1, release-1.2, etc. Not sure exactly what 1.2.1 refers to (is that the fabric-client npm package)?

Also, there's no guarantee that the rest of the code (middleware and application) will work with 1.2. I spent a little bit of time porting the network part (involved changing the YAML file, as you've experienced), but the Javascript failed. I'll return to that project when I get time.

So, just to reiterate, if you want the code in this repo to work, use the release-1.1 branches of the source code. Otherwise, if you are experimenting, go right ahead. Good luck!

JerryKwan commented 6 years ago

Hi @VRamakrishna , i checked it again, i am using release-1.2. sorry for the wrong info. Is there any chance i can participate in migrating it work with 1.2? I have a lot of spare time and want to digger deeper in fabric.

VRamakrishna commented 6 years ago

You are free to try out the migration by forking the code base. If you want to merge your changes, submit a pull request (though be warned that I may not get to it immediately; I'll have to spend time reviewing and testing it out.)