Modifying the genesis block using configtxlator - hyperledger-fabric

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

Related

Does peer channel update create a transaction?

In Hyperledger Fabric you can use peer channel update to submit updates to your nextwork. For instance, once you have your block in protobuf format ready, you can submit it like so:
peer channel update -f .someupdate.pb -c somechannel
However, you can also use it to submit a channel transaction, for instance:
peer channel update -f someTransaction.tx -c somechannel
I'm really confused about this. Does peer update channel create a transaction when is submitting the update block? What are the scenarios when you would use a block instead of a transaction?
Same happens with the cyptotxgen tool. You can use it to create a genesis block:
configtxgen -outputBlock ./genesis.block \ -profile SomeProfile \ -channelID somechannel
or you can use to create a transaction:
configtxgen -outputCreateChannelTx ./sometransaction.tx \ -profile SomeProfile \ -channelID somechannel
The official docs about peer channel update says about the -f param:
-f, --file string Configuration transaction file generated by a tool such as configtxgen for submitting to orderer
So it's referring to transactions, not blocks. But apparently you can indeed use to submit a block. Is the command creating a transaction on background?
As far as I can see, peer channel update only accepts a config update transaction. It doesn't care what the file is called (and could end in .pb or .tx for example). The file will be a serialised collection of protobufs and definitely won't be a block, The format of this is described here https://hyperledger-fabric.readthedocs.io/en/latest/configtx.html#configuration-updates but suffice to say that a config update transaction is a set of diffs which the orderer will use to generate a complete channel config from putting that as the only transaction into a block. Peers will receive this block, validate it and make it the new channel configuration block
cryptogen in fabric prior to 2.3 had 2 purposes.
The first purpose is to generate a genesis block which will contain the system channel configuration. When an orderer first starts and the system channel hasn't been created it will read this file and the system channel created, subsequent restart of the orderer will ignore this file as that block is now stored in the appropriate place in the orderer.
The second purpose of configtxgen prior to 2.3 is to generate an application channel creation transaction file which can be used by peer channel create. This is submitted to the orderer which will generate a genesis block for the application channel containing the channel configuration.
In fabric 2.3 the need for the system channel was removed, now cryptogen has a 3rd purpose (as it still needs to support the system channel mechanism for now), to generate an application channel genesis block. This is then given as input to the osnadmin command to send to the first orderer who basically bootstraps the application channel with that genesis block. Then more orderers (via osnadmin) and peers can join that channel (via peer channel join) using the same genesis block.

Can we find the endorser details in smart contract during execution(Hyperledger Fabric)?

Can we find the endorser details in smart contract during execution(Hyperledger Fabric) ?
Check out the below link, by using this library you access MSPid, fabric-ca certificate details inside the chaincode
https://github.com/hyperledger/fabric-chaincode-go/blob/main/pkg/cid/README.md
https://hyperledger-fabric.readthedocs.io/en/release-2.2/endorsement-policies.html
https://github.com/hyperledger/fabric-samples/blob/main/asset-transfer-secured-agreement/chaincode-go/asset_transfer.go
If you use the internal docker build mechanism then the only thing available to chaincode is CORE_PEER_LOCALMSPID
I've not tried but if you use an external builder you could add more information yourself during the run part see https://hyperledger-fabric.readthedocs.io/en/release-2.2/cc_launcher.html?highlight=builder#external-builder-and-launcher-api
and if you use chaincode as a service then it may be possible for you to bake something into the image you use in different orgs

Dynamic Channel artifacts(channel.tx) in Hyperledger Fabric

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.

What is an Artifact in Hyperledger?

I see the word everywhere in building a Hyperledger network, but I don't exactly know what it is and the Hyperledger docs don't return a definition when I query them.
Maybe it's a dumb question because the docs don't define it and assume you should know, but I don't and can't find a precise answer to it.
Artifacts in Hyperledger are channel configuration files which are required for the Hyperledger Fabric network. They are generated at the time of network creation.
These include:
Genesis.block: First block of a chain, that initializes a block chain
Channel.tx: Channel configuration transaction
Org1MSPanchors.tx: Anchor Peer update (Defining a peer from Org1 as an anchor peer)
configtxgen command is used to create the above channel config artifacts.

What is "testchainid" channel?

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).

Resources