Is there any other way to generate a generic channel artifacts(channel.tx) for Hyperledger-Fabric channel creation, So that a channel name alone can be changed at runtime instead of issuing the below command with different channel name for every new channel.
./bin/configtxgen -profile OneOrgChannel -outputCreateChannelTx
./config/channel5.txt
It's not exactly the answer you are looking for but we do this dynamically inside a java application with a ProcessBuilder. That way we can create new channels on demand - it's embedded ultimately in a REST service that allows you (one) to pass up a configtx file as required.
So long as the crypto is already generated (we do that in another service) you can do this on demand.
So aatk's answer applies the sidecar pattern to solve the issue, by running the configtxgen on the side of the actual application. However you can do this from within the application itself.
A channel configuration transaction that is generated with configtxgen is a file containing a protobuf of the common.Envelope message. There is support for protobuf in Java, and the Envelope message has been compiled to Java thanks to the Fabric Java SDK. We can piggyback on the SDK to create the objects and get the ByteArray to create the ChannelConfiguration object that will be used to create a channel. This method doesn't require a configtx.yaml file at all, so you will need to keep track of organizations and their MSP IDs in the app.
Related
I am new to the latest Hyperledger fabric 2. Before deprecating fabric-composer (a very well thought and intuitive framework) if you wanted to add multiple assests you could call AssetRegistry.addAll() method to add not just one asset but an array of assets. Is there an equivalent in the new hlf version 2? If I have an array of assets/states that I want added in the world-state database and I call putState() multiple times for each state/asset is it not less efficient than calling a putStateList() method that would take as param an array of states? (BTW the old naming of asset from the times of hyperledger composer is much more intuitive than the new name of state ... composer vs de-composer :)))
There is no putStateList in Hyperledger Fabric.
As you mentioned, the only way is to call PutState the number of times you want.
In terms of performance, the data to be sent by the chaincode to the peer is the same length, but I understand that if Peer node could accept a list of states, it could be more efficient on the server-side.
If we look at the internals of Node.JS library, we can see that handlePutState connects to the peer and waits:
And then, it will send the message to the peer, writing the msg to the stream:
I am new in this field and therefore I am still doing studies and researches, I would like to know if JSON files can be imported in Hyperldeger Fabric--if it is better Hyperledeger Fabric or Fabric Composer. more precisely I would like to understand if there is a way to populate the DLT of Hyperledger Fabric automatically.
for now, I have only tried Hyperledger Composer online playground
Fabric don't have any feature to automatically populate the ledger.
You have to develop a solution in order to upoload each Json file and put that on the ledger state.
Any type of data can be inserted on the ledged because it stores byte arrays so its up to you how to serialize.
in case you're asking to making your chaincode or smart contract like talking to the file system and read file or even call some API to collect JSON files,
it could be done but this will break your transaction flow specially during the endorsement process due to during the endorsement process it's expected from each peer to return the same value after executing the transaction against the chaincode to consider the transaction is a valid transaction,
so in case one of the endorsers failed to call the API or failed to read file from file system the transaction will considered to be invalid.
so it's not recommended to do any third party activity in your chaincode or smart contract even if it's possible to do so.
about populating the ledger it can be done it's eventually a database so you can dump it's data, However, if you're trying to backup to recover the ledger in case the whole network down it's impossible due to when you'll reinstall the network the whole config and certificates which were bounded to the transaction will be changed so it has no sense to do it.
I am reading about chaincode in hyperledger fabric for my project. I have a doubt on
How to invoke chaincode automatically based on events like time. If so, are any working examples available.
Thank you in advance.
You cannot invoke transactions automatically without a client. If you look at the transaction flow of Hyperledger Fabric, the client has a lot of responsibilities signing the transactions, like collecting the endorsement, optionally filtering out the proposal responses (bad ones) and sending it for ordering. So, you cannot replace all this logic in the chaincode layer which is essentially responsible for endorsement.
You have to do this invocation based on events like time with the help of the client whose rules you are supposed to define.
So, best way would be put some sort of authorization logic on the chaincode function you want to invoke at regular intervals of time and use a client and a user's certificate to call the functions on the chaincode using some cron mechanism.
Reference to Authorization in Chaincode:
Summary Video: https://www.youtube.com/watch?v=WTW9QVO28l0
Chaincode Reference: https://github.com/hyperledger/fabric-samples/tree/release-1.2/chaincode/abac/go
Documentation: https://docs.google.com/document/d/1GP5tcN0oK9Zewed9h5pLiM2BowWPhtgFUGXEDKjeGGo/edit
I built fabric network using kafka.
I created new "mytestchannel".
When I saw /var/hyperledger/production/ledgersData/chains/chains on peer server,
I found that both "mytestchannel" and "testchainid" directories.
Also, I checked kafka topic, I found both "mytestchannel" and "testchainid".
What is "testchainid"?
This channel contains important data?
I mean that if I delete(break) "testchainid" data in Kafka topic, does it affect my entire fabric network?
TL;DR - You cannot delete testchainid. It is the system channel.
Assuming you followed the normal configtxgen sequence of creating the genesis block first and then doing a create channel transaction, then testchainid is actually the system channel (if you don't specify a channel name using the -channelID flag when using the -outputBlock flag then the system channel name defaults to testchainid).
I'm a little confused as to how to modify the system channel configuration once the Fabric network is operational.
I gather that the configtxlator tool can be used to create a patch transaction with the necessary changes, but how is this transaction then applied to the system channel? Can the peer channel update CLI tool be used for this?
You can find how-to tour on reconfiguring the channel with configtxlator tool. Basically the high level flow will be:
Decode the configuration into json using configtxlator.
Extract config section
Create new configuration
Encode both new and old configs
Send them to compute the config update delta
Decode the config update and wrap up into envelope
Produce new config transaction
Update channel by submitting new config.
Here is the link for official docs describing reconfiguration flow in details.
And yes you can use peer cli tool to update the configuration as following:
peer channel update -f config_update_as_envelope.pb -c mychannel -o orderer:7050