github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/docs/source/commands/peerchannel.md (about)

     1  # peer channel
     2  
     3  The `peer channel` command allows administrators to perform channel related
     4  operations on a peer, such as joining a channel or listing the channels to which
     5  a peer is joined.
     6  
     7  ## Syntax
     8  
     9  The `peer channel` command has the following subcommands:
    10  
    11    * create
    12    * fetch
    13    * getinfo
    14    * join
    15    * list
    16    * signconfigtx
    17    * update
    18  
    19  ## peer channel
    20  ```
    21  Operate a channel: create|fetch|join|list|update|signconfigtx|getinfo.
    22  
    23  Usage:
    24    peer channel [command]
    25  
    26  Available Commands:
    27    create       Create a channel
    28    fetch        Fetch a block
    29    getinfo      get blockchain information of a specified channel.
    30    join         Joins the peer to a channel.
    31    list         List of channels peer has joined.
    32    signconfigtx Signs a configtx update.
    33    update       Send a configtx update.
    34  
    35  Flags:
    36        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
    37        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
    38        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
    39        --connTimeout duration                Timeout for client to connect (default 3s)
    40    -h, --help                                help for channel
    41        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
    42    -o, --orderer string                      Ordering service endpoint
    43        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
    44        --tls                                 Use TLS when communicating with the orderer endpoint
    45        --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
    46  
    47  Use "peer channel [command] --help" for more information about a command.
    48  ```
    49  
    50  
    51  ## peer channel create
    52  ```
    53  Create a channel and write the genesis block to a file.
    54  
    55  Usage:
    56    peer channel create [flags]
    57  
    58  Flags:
    59    -c, --channelID string     In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]*
    60    -f, --file string          Configuration transaction file generated by a tool such as configtxgen for submitting to orderer
    61    -h, --help                 help for create
    62        --outputBlock string   The path to write the genesis block for the channel. (default ./<channelID>.block)
    63    -t, --timeout duration     Channel creation timeout (default 10s)
    64  
    65  Global Flags:
    66        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
    67        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
    68        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
    69        --connTimeout duration                Timeout for client to connect (default 3s)
    70        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
    71    -o, --orderer string                      Ordering service endpoint
    72        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
    73        --tls                                 Use TLS when communicating with the orderer endpoint
    74        --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
    75  ```
    76  
    77  
    78  ## peer channel fetch
    79  ```
    80  Fetch a specified block, writing it to a file.
    81  
    82  Usage:
    83    peer channel fetch <newest|oldest|config|(number)> [outputfile] [flags]
    84  
    85  Flags:
    86        --bestEffort         Whether fetch requests should ignore errors and return blocks on a best effort basis
    87    -c, --channelID string   In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]*
    88    -h, --help               help for fetch
    89  
    90  Global Flags:
    91        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
    92        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
    93        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
    94        --connTimeout duration                Timeout for client to connect (default 3s)
    95        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
    96    -o, --orderer string                      Ordering service endpoint
    97        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
    98        --tls                                 Use TLS when communicating with the orderer endpoint
    99        --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
   100  ```
   101  
   102  
   103  ## peer channel getinfo
   104  ```
   105  get blockchain information of a specified channel. Requires '-c'.
   106  
   107  Usage:
   108    peer channel getinfo [flags]
   109  
   110  Flags:
   111    -c, --channelID string   In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]*
   112    -h, --help               help for getinfo
   113  
   114  Global Flags:
   115        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   116        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   117        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   118        --connTimeout duration                Timeout for client to connect (default 3s)
   119        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   120    -o, --orderer string                      Ordering service endpoint
   121        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
   122        --tls                                 Use TLS when communicating with the orderer endpoint
   123        --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
   124  ```
   125  
   126  
   127  ## peer channel join
   128  ```
   129  Joins the peer to a channel.
   130  
   131  Usage:
   132    peer channel join [flags]
   133  
   134  Flags:
   135    -b, --blockpath string   Path to file containing genesis block
   136    -h, --help               help for join
   137  
   138  Global Flags:
   139        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   140        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   141        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   142        --connTimeout duration                Timeout for client to connect (default 3s)
   143        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   144    -o, --orderer string                      Ordering service endpoint
   145        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
   146        --tls                                 Use TLS when communicating with the orderer endpoint
   147        --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
   148  ```
   149  
   150  
   151  ## peer channel list
   152  ```
   153  List of channels peer has joined.
   154  
   155  Usage:
   156    peer channel list [flags]
   157  
   158  Flags:
   159    -h, --help   help for list
   160  
   161  Global Flags:
   162        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   163        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   164        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   165        --connTimeout duration                Timeout for client to connect (default 3s)
   166        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   167    -o, --orderer string                      Ordering service endpoint
   168        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
   169        --tls                                 Use TLS when communicating with the orderer endpoint
   170        --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
   171  ```
   172  
   173  
   174  ## peer channel signconfigtx
   175  ```
   176  Signs the supplied configtx update file in place on the filesystem. Requires '-f'.
   177  
   178  Usage:
   179    peer channel signconfigtx [flags]
   180  
   181  Flags:
   182    -f, --file string   Configuration transaction file generated by a tool such as configtxgen for submitting to orderer
   183    -h, --help          help for signconfigtx
   184  
   185  Global Flags:
   186        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   187        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   188        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   189        --connTimeout duration                Timeout for client to connect (default 3s)
   190        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   191    -o, --orderer string                      Ordering service endpoint
   192        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
   193        --tls                                 Use TLS when communicating with the orderer endpoint
   194        --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
   195  ```
   196  
   197  
   198  ## peer channel update
   199  ```
   200  Signs and sends the supplied configtx update file to the channel. Requires '-f', '-o', '-c'.
   201  
   202  Usage:
   203    peer channel update [flags]
   204  
   205  Flags:
   206    -c, --channelID string   In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]*
   207    -f, --file string        Configuration transaction file generated by a tool such as configtxgen for submitting to orderer
   208    -h, --help               help for update
   209  
   210  Global Flags:
   211        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   212        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   213        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   214        --connTimeout duration                Timeout for client to connect (default 3s)
   215        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   216    -o, --orderer string                      Ordering service endpoint
   217        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
   218        --tls                                 Use TLS when communicating with the orderer endpoint
   219        --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
   220  ```
   221  
   222  ## Example Usage
   223  
   224  ### peer channel create examples
   225  
   226  Here's an example that uses the `--orderer` global flag on the `peer channel
   227  create` command.
   228  
   229  * Create a sample channel `mychannel` defined by the configuration transaction
   230    contained in file `./createchannel.tx`. Use the orderer at `orderer.example.com:7050`.
   231  
   232    ```
   233    peer channel create -c mychannel -f ./createchannel.tx --orderer orderer.example.com:7050
   234  
   235    2018-02-25 08:23:57.548 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   236    2018-02-25 08:23:57.626 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized
   237    2018-02-25 08:23:57.834 UTC [channelCmd] readBlock -> INFO 020 Received block: 0
   238    2018-02-25 08:23:57.835 UTC [main] main -> INFO 021 Exiting.....
   239  
   240    ```
   241  
   242    Block 0 is returned indicating that the channel has been successfully created.
   243  
   244  Here's an example of the `peer channel create` command option.
   245  
   246  * Create a new channel `mychannel` for the network, using the orderer at ip
   247    address `orderer.example.com:7050`.  The configuration update transaction
   248    required to create this channel is defined the file `./createchannel.tx`.
   249    Wait 30 seconds for the channel to be created.
   250  
   251    ```
   252      peer channel create -c mychannel --orderer orderer.example.com:7050 -f ./createchannel.tx -t 30s
   253  
   254      2018-02-23 06:31:58.568 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   255      2018-02-23 06:31:58.669 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized
   256      2018-02-23 06:31:58.877 UTC [channelCmd] readBlock -> INFO 020 Received block: 0
   257      2018-02-23 06:31:58.878 UTC [main] main -> INFO 021 Exiting.....
   258  
   259      ls -l
   260  
   261      -rw-r--r-- 1 root root 11982 Feb 25 12:24 mychannel.block
   262  
   263    ```
   264  
   265    You can see that channel `mychannel` has been successfully created, as
   266    indicated in the output where block 0 (zero) is added to the blockchain for
   267    this channel and returned to the peer, where it is stored in the local
   268    directory as `mychannel.block`.
   269  
   270    Block zero is often called the *genesis block* as it provides the starting
   271    configuration for the channel.  All subsequent updates to the channel will be
   272    captured as configuration blocks on the channel's blockchain, each of which
   273    supersedes the previous configuration.
   274  
   275  ### peer channel fetch example
   276  
   277  Here's some examples of the `peer channel fetch` command.
   278  
   279  * Using the `newest` option to retrieve the most recent channel block, and
   280    store it in   the file `mychannel.block`.
   281  
   282    ```
   283    peer channel fetch newest mychannel.block -c mychannel --orderer orderer.example.com:7050
   284  
   285    2018-02-25 13:10:16.137 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   286    2018-02-25 13:10:16.144 UTC [channelCmd] readBlock -> INFO 00a Received block: 32
   287    2018-02-25 13:10:16.145 UTC [main] main -> INFO 00b Exiting.....
   288  
   289    ls -l
   290  
   291    -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block
   292  
   293    ```
   294  
   295    You can see that the retrieved block is number 32, and that the information
   296    has been written to the file `mychannel.block`.
   297  
   298  * Using the `(block number)` option to retrieve a specific block -- in this
   299    case, block number 16 -- and store it in the default block file.
   300  
   301    ```
   302    peer channel fetch 16  -c mychannel --orderer orderer.example.com:7050
   303  
   304    2018-02-25 13:46:50.296 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   305    2018-02-25 13:46:50.302 UTC [channelCmd] readBlock -> INFO 00a Received block: 16
   306    2018-02-25 13:46:50.302 UTC [main] main -> INFO 00b Exiting.....
   307  
   308    ls -l
   309  
   310    -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block
   311    -rw-r--r-- 1 root root  4783 Feb 25 13:46 mychannel_16.block
   312  
   313    ```
   314  
   315    You can see that the retrieved block is number 16, and that the information
   316    has been written to the default file `mychannel_16.block`.
   317  
   318    For configuration blocks, the block file can be decoded using the
   319    [`configtxlator` command](./configtxlator.html). See this command for an example
   320    of decoded output. User transaction blocks can also be decoded, but a user
   321    program must be written to do this.
   322  
   323  ### peer channel getinfo example
   324  
   325  Here's an example of the `peer channel getinfo` command.
   326  
   327  * Get information about the local peer for channel `mychannel`.
   328  
   329    ```
   330    peer channel getinfo -c mychannel
   331  
   332    2018-02-25 15:15:44.135 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   333    Blockchain info: {"height":5,"currentBlockHash":"JgK9lcaPUNmFb5Mp1qe1SVMsx3o/22Ct4+n5tejcXCw=","previousBlockHash":"f8lZXoAn3gF86zrFq7L1DzW2aKuabH9Ow6SIE5Y04a4="}
   334    2018-02-25 15:15:44.139 UTC [main] main -> INFO 006 Exiting.....
   335  
   336    ```
   337  
   338    You can see that the latest block for channel `mychannel` is block 5.  You
   339    can also see the cryptographic hashes for the most recent blocks in the
   340    channel's blockchain.
   341  
   342  ### peer channel join example
   343  
   344  Here's an example of the `peer channel join` command.
   345  
   346  * Join a peer to the channel defined in the genesis block identified by the file
   347    `./mychannel.genesis.block`. In this example, the channel block was
   348    previously retrieved by the `peer channel fetch` command.
   349  
   350    ```
   351    peer channel join -b ./mychannel.genesis.block
   352  
   353    2018-02-25 12:25:26.511 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   354    2018-02-25 12:25:26.571 UTC [channelCmd] executeJoin -> INFO 006 Successfully submitted proposal to join channel
   355    2018-02-25 12:25:26.571 UTC [main] main -> INFO 007 Exiting.....
   356  
   357    ```
   358  
   359    You can see that the peer has successfully made a request to join the channel.
   360  
   361  ### peer channel list example
   362  
   363    Here's an example of the `peer channel list` command.
   364  
   365    * List the channels to which a peer is joined.
   366  
   367      ```
   368      peer channel list
   369  
   370      2018-02-25 14:21:20.361 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   371      Channels peers has joined:
   372      mychannel
   373      2018-02-25 14:21:20.372 UTC [main] main -> INFO 006 Exiting.....
   374  
   375      ```
   376  
   377      You can see that the peer is joined to channel `mychannel`.
   378  
   379  ### peer channel signconfigtx example
   380  
   381  Here's an example of the `peer channel signconfigtx` command.
   382  
   383  * Sign the `channel update` transaction defined in the file
   384    `./updatechannel.tx`. The example lists the configuration transaction file
   385    before and after the command.
   386  
   387    ```
   388    ls -l
   389  
   390    -rw-r--r--  1 anthonyodowd  staff   284 25 Feb 18:16 updatechannel.tx
   391  
   392    peer channel signconfigtx -f updatechannel.tx
   393  
   394    2018-02-25 18:16:44.456 GMT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
   395    2018-02-25 18:16:44.459 GMT [main] main -> INFO 002 Exiting.....
   396  
   397    ls -l
   398  
   399    -rw-r--r--  1 anthonyodowd  staff  2180 25 Feb 18:16 updatechannel.tx
   400  
   401    ```
   402  
   403    You can see that the peer has successfully signed the configuration
   404    transaction by the increase in the size of the file `updatechannel.tx` from
   405    284 bytes to 2180 bytes.
   406  
   407  ### peer channel update example
   408  
   409  Here's an example of the `peer channel update` command.
   410  
   411  * Update the channel `mychannel` using the configuration transaction defined in
   412    the file `./updatechannel.tx`. Use the orderer at ip address
   413    `orderer.example.com:7050` to send the configuration transaction to all peers
   414    in the channel to update their copy of the channel configuration.
   415  
   416    ```
   417    peer channel update -c mychannel -f ./updatechannel.tx -o orderer.example.com:7050
   418  
   419    2018-02-23 06:32:11.569 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   420    2018-02-23 06:32:11.626 UTC [main] main -> INFO 010 Exiting.....
   421  
   422    ```
   423  
   424    At this point, the channel `mychannel` has been successfully updated.
   425  
   426  <a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.