github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/docs/source/configtx.rst (about)

     1  Channel Configuration (configtx)
     2  ================================
     3  
     4  .. note:: This topic describes how channels are configured when the network has
     5            not been bootstrapped using a system channel genesis block. For
     6            information about the structure of configurations, including the
     7            configuration of the system channel, check out
     8            `Channel Configuration (configtx) <https://hyperledger-fabric.readthedocs.io/en/release-2.2/configtx.html>`_
     9            from the v2.2 documentation.
    10  
    11  Shared configuration for a Hechain blockchain network is
    12  stored in a collection configuration transactions, one per channel. Each
    13  configuration transaction is usually referred to by the shorter name
    14  *configtx*.
    15  
    16  Channel configuration has the following important properties:
    17  
    18  1. **Versioned**: All elements of the configuration have an associated
    19     version which is advanced with every modification. Further, every
    20     committed configuration receives a sequence number.
    21  2. **Permissioned**: Each element of the configuration has an associated
    22     policy which governs whether or not modification to that element is
    23     permitted. Anyone with a copy of the previous configtx (and no
    24     additional info) may verify the validity of a new config based on
    25     these policies.
    26  3. **Hierarchical**: A root configuration group contains sub-groups, and
    27     each group of the hierarchy has associated values and policies. These
    28     policies can take advantage of the hierarchy to derive policies at
    29     one level from policies of lower levels.
    30  
    31  Anatomy of a configuration
    32  --------------------------
    33  
    34  Configuration is stored as a transaction of type ``HeaderType_CONFIG``
    35  in a block with no other transactions. These blocks are referred to as
    36  *Configuration Blocks*, the first of which is referred to as the
    37  *Genesis Block*.
    38  
    39  The proto structures for configuration are stored in
    40  ``fabric-protos/common/configtx.proto``. The Envelope of type
    41  ``HeaderType_CONFIG`` encodes a ``ConfigEnvelope`` message as the
    42  ``Payload`` ``data`` field. The proto for ``ConfigEnvelope`` is defined
    43  as follows:
    44  
    45  ::
    46  
    47      message ConfigEnvelope {
    48          Config config = 1;
    49          Envelope last_update = 2;
    50      }
    51  
    52  The ``last_update`` field is defined below in the **Updates to
    53  configuration** section, but is only necessary when validating the
    54  configuration, not reading it. Instead, the currently committed
    55  configuration is stored in the ``config`` field, containing a ``Config``
    56  message.
    57  
    58  ::
    59  
    60      message Config {
    61          uint64 sequence = 1;
    62          ConfigGroup channel_group = 2;
    63      }
    64  
    65  The ``sequence`` number is incremented by one for each committed
    66  configuration. The ``channel_group`` field is the root group which
    67  contains the configuration. The ``ConfigGroup`` structure is recursively
    68  defined, and builds a tree of groups, each of which contains values and
    69  policies. It is defined as follows:
    70  
    71  ::
    72  
    73      message ConfigGroup {
    74          uint64 version = 1;
    75          map<string,ConfigGroup> groups = 2;
    76          map<string,ConfigValue> values = 3;
    77          map<string,ConfigPolicy> policies = 4;
    78          string mod_policy = 5;
    79      }
    80  
    81  Because ``ConfigGroup`` is a recursive structure, it has hierarchical
    82  arrangement. The following example is expressed for clarity in Go
    83  syntax.
    84  
    85  ::
    86  
    87      // Assume the following groups are defined
    88      var root, child1, child2, grandChild1, grandChild2, grandChild3 *ConfigGroup
    89  
    90      // Set the following values
    91      root.Groups["child1"] = child1
    92      root.Groups["child2"] = child2
    93      child1.Groups["grandChild1"] = grandChild1
    94      child2.Groups["grandChild2"] = grandChild2
    95      child2.Groups["grandChild3"] = grandChild3
    96  
    97      // The resulting config structure of groups looks like:
    98      // root:
    99      //     child1:
   100      //         grandChild1
   101      //     child2:
   102      //         grandChild2
   103      //         grandChild3
   104  
   105  Each group defines a level in the config hierarchy, and each group has
   106  an associated set of values (indexed by string key) and policies (also
   107  indexed by string key).
   108  
   109  Values are defined by:
   110  
   111  ::
   112  
   113      message ConfigValue {
   114          uint64 version = 1;
   115          bytes value = 2;
   116          string mod_policy = 3;
   117      }
   118  
   119  Policies are defined by:
   120  
   121  ::
   122  
   123      message ConfigPolicy {
   124          uint64 version = 1;
   125          Policy policy = 2;
   126          string mod_policy = 3;
   127      }
   128  
   129  Note that Values, Policies, and Groups all have a ``version`` and a
   130  ``mod_policy``. The ``version`` of an element is incremented each time
   131  that element is modified. The ``mod_policy`` is used to govern the
   132  required signatures to modify that element. For Groups, modification is
   133  adding or removing elements to the Values, Policies, or Groups maps (or
   134  changing the ``mod_policy``). For Values and Policies, modification is
   135  changing the Value and Policy fields respectively (or changing the
   136  ``mod_policy``). Each element's ``mod_policy`` is evaluated in the
   137  context of the current level of the config. Consider the following
   138  example mod policies defined at ``Channel.Groups["Application"]`` (Here,
   139  we use the Go map reference syntax, so
   140  ``Channel.Groups["Application"].Policies["policy1"]`` refers to the base
   141  ``Channel`` group's ``Application`` group's ``Policies`` map's
   142  ``policy1`` policy.)
   143  
   144  * ``policy1`` maps to ``Channel.Groups["Application"].Policies["policy1"]``
   145  * ``Org1/policy2`` maps to
   146    ``Channel.Groups["Application"].Groups["Org1"].Policies["policy2"]``
   147  * ``/Channel/policy3`` maps to ``Channel.Policies["policy3"]``
   148  
   149  Note that if a ``mod_policy`` references a policy which does not exist,
   150  the item cannot be modified.
   151  
   152  Configuration updates
   153  ---------------------
   154  
   155  Configuration updates are submitted as an ``Envelope`` message of type
   156  ``HeaderType_CONFIG_UPDATE``. The ``Payload`` ``data`` of the
   157  transaction is a marshaled ``ConfigUpdateEnvelope``. The ``ConfigUpdateEnvelope``
   158  is defined as follows:
   159  
   160  ::
   161  
   162      message ConfigUpdateEnvelope {
   163          bytes config_update = 1;
   164          repeated ConfigSignature signatures = 2;
   165      }
   166  
   167  The ``signatures`` field contains the set of signatures which authorizes
   168  the config update. Its message definition is:
   169  
   170  ::
   171  
   172      message ConfigSignature {
   173          bytes signature_header = 1;
   174          bytes signature = 2;
   175      }
   176  
   177  The ``signature_header`` is as defined for standard transactions, while
   178  the signature is over the concatenation of the ``signature_header``
   179  bytes and the ``config_update`` bytes from the ``ConfigUpdateEnvelope``
   180  message.
   181  
   182  The ``ConfigUpdateEnvelope`` ``config_update`` bytes are a marshaled
   183  ``ConfigUpdate`` message which is defined as follows:
   184  
   185  ::
   186  
   187      message ConfigUpdate {
   188          string channel_id = 1;
   189          ConfigGroup read_set = 2;
   190          ConfigGroup write_set = 3;
   191      }
   192  
   193  The ``channel_id`` is the channel ID the update is bound for, this is
   194  necessary to scope the signatures which support this reconfiguration.
   195  
   196  The ``read_set`` specifies a subset of the existing configuration,
   197  specified sparsely where only the ``version`` field is set and no other
   198  fields must be populated. The particular ``ConfigValue`` ``value`` or
   199  ``ConfigPolicy`` ``policy`` fields should never be set in the
   200  ``read_set``. The ``ConfigGroup`` may have a subset of its map fields
   201  populated, so as to reference an element deeper in the config tree. For
   202  instance, to include the ``Application`` group in the ``read_set``, its
   203  parent (the ``Channel`` group) must also be included in the read set,
   204  but, the ``Channel`` group does not need to populate all of the keys,
   205  such as the ``Orderer`` ``group`` key, or any of the ``values`` or
   206  ``policies`` keys.
   207  
   208  The ``write_set`` specifies the pieces of configuration which are
   209  modified. Because of the hierarchical nature of the configuration, a
   210  write to an element deep in the hierarchy must contain the higher level
   211  elements in its ``write_set`` as well. However, for any element in the
   212  ``write_set`` which is also specified in the ``read_set`` at the same
   213  version, the element should be specified sparsely, just as in the
   214  ``read_set``.
   215  
   216  For example, given the configuration:
   217  
   218  ::
   219  
   220      Channel: (version 0)
   221          Orderer (version 0)
   222          Application (version 3)
   223             Org1 (version 2)
   224  
   225  To submit a configuration update which modifies ``Org1``, the
   226  ``read_set`` would be:
   227  
   228  ::
   229  
   230      Channel: (version 0)
   231          Application: (version 3)
   232  
   233  and the ``write_set`` would be
   234  
   235  ::
   236  
   237      Channel: (version 0)
   238          Application: (version 3)
   239              Org1 (version 3)
   240  
   241  When the ``CONFIG_UPDATE`` is received, the orderer computes the
   242  resulting ``CONFIG`` by doing the following:
   243  
   244  1. Verifies the ``channel_id`` and ``read_set``. All elements in the
   245     ``read_set`` must exist at the given versions.
   246  2. Computes the update set by collecting all elements in the
   247     ``write_set`` which do not appear at the same version in the
   248     ``read_set``.
   249  3. Verifies that each element in the update set increments the version
   250     number of the element update by exactly 1.
   251  4. Verifies that the signature set attached to the
   252     ``ConfigUpdateEnvelope`` satisfies the ``mod_policy`` for each
   253     element in the update set.
   254  5. Computes a new complete version of the config by applying the update
   255     set to the current config.
   256  6. Writes the new config into a ``ConfigEnvelope`` which includes the
   257     ``CONFIG_UPDATE`` as the ``last_update`` field and the new config
   258     encoded in the ``config`` field, along with the incremented
   259     ``sequence`` value.
   260  7. Writes the new ``ConfigEnvelope`` into a ``Envelope`` of type
   261     ``CONFIG``, and ultimately writes this as the sole transaction in a
   262     new configuration block.
   263  
   264  When the peer (or any other receiver for ``Deliver``) receives this
   265  configuration block, it should verify that the config was appropriately
   266  validated by applying the ``last_update`` message to the current config
   267  and verifying that the orderer-computed ``config`` field contains the
   268  correct new configuration.
   269  
   270  Permitted configuration groups and values
   271  -----------------------------------------
   272  
   273  Any valid configuration is a subset of the following configuration. Here
   274  we use the notation ``peer.<MSG>`` to define a ``ConfigValue`` whose
   275  ``value`` field is a marshaled proto message of name ``<MSG>`` defined
   276  in ``fabric-protos/peer/configuration.proto``. The notations
   277  ``common.<MSG>``, ``msp.<MSG>``, and ``orderer.<MSG>`` correspond
   278  similarly, but with their messages defined in
   279  ``fabric-protos/common/configuration.proto``,
   280  ``fabric-protos/msp/mspconfig.proto``, and
   281  ``fabric-protos/orderer/configuration.proto`` respectively.
   282  
   283  Note, that the keys ``{{org_name}}`` and ``{{consortium_name}}``
   284  represent arbitrary names, and indicate an element which may be repeated
   285  with different names.
   286  
   287  ::
   288  
   289      &ConfigGroup{
   290          Groups: map<string, *ConfigGroup> {
   291              "Application":&ConfigGroup{
   292                  Groups:map<String, *ConfigGroup> {
   293                      {{org_name}}:&ConfigGroup{
   294                          Values:map<string, *ConfigValue>{
   295                              "MSP":msp.MSPConfig,
   296                              "AnchorPeers":peer.AnchorPeers,
   297                          },
   298                      },
   299                  },
   300              },
   301              "Orderer":&ConfigGroup{
   302                  Groups:map<String, *ConfigGroup> {
   303                      {{org_name}}:&ConfigGroup{
   304                          Values:map<string, *ConfigValue>{
   305                              "MSP":msp.MSPConfig,
   306                          },
   307                      },
   308                  },
   309  
   310                  Values:map<string, *ConfigValue> {
   311                      "ConsensusType":orderer.ConsensusType,
   312                      "BatchSize":orderer.BatchSize,
   313                      "BatchTimeout":orderer.BatchTimeout,
   314                      "KafkaBrokers":orderer.KafkaBrokers,
   315                  },
   316              },
   317              "Consortiums":&ConfigGroup{
   318                  Groups:map<String, *ConfigGroup> {
   319                      {{consortium_name}}:&ConfigGroup{
   320                          Groups:map<string, *ConfigGroup> {
   321                              {{org_name}}:&ConfigGroup{
   322                                  Values:map<string, *ConfigValue>{
   323                                      "MSP":msp.MSPConfig,
   324                                  },
   325                              },
   326                          },
   327                          Values:map<string, *ConfigValue> {
   328                              "ChannelCreationPolicy":common.Policy,
   329                          }
   330                      },
   331                  },
   332              },
   333          },
   334  
   335          Values: map<string, *ConfigValue> {
   336              "HashingAlgorithm":common.HashingAlgorithm,
   337              "BlockDataHashingStructure":common.BlockDataHashingStructure,
   338              "Consortium":common.Consortium,
   339              "OrdererAddresses":common.OrdererAddresses,
   340          },
   341      }
   342  
   343  Channel configuration
   344  ---------------------
   345  
   346  Application configuration is for channels which are designed for
   347  application type transactions. It is defined as follows:
   348  
   349  ::
   350  
   351      &ConfigGroup{
   352          Groups: map<string, *ConfigGroup> {
   353              "Application":&ConfigGroup{
   354                  Groups:map<String, *ConfigGroup> {
   355                      {{org_name}}:&ConfigGroup{
   356                          Values:map<string, *ConfigValue>{
   357                              "MSP":msp.MSPConfig,
   358                              "AnchorPeers":peer.AnchorPeers,
   359                          },
   360                      },
   361                  },
   362              },
   363          },
   364      }
   365  
   366  Just like with the ``Orderer`` section, each organization is encoded as
   367  a group. However, instead of only encoding the ``MSP`` identity
   368  information, each org additionally encodes a list of ``AnchorPeers``.
   369  This list allows the peers of different organizations to contact each
   370  other for peer gossip networking.
   371  
   372  Channel creation
   373  ----------------
   374  
   375  For information about how to create a channel, check out :doc:`create_channel/create_channel_participation`.
   376  
   377  .. Licensed under Creative Commons Attribution 4.0 International License
   378     https://creativecommons.org/licenses/by/4.0/