systemchaincode.rst 2.61 KB
Newer Older
1
2
3
4
5
6
7
System Chaincode Plugins
========================

System chaincodes are specialized chaincodes that run as part of the peer process
as opposed to user chaincodes that run in separate docker containers. As
such they have more access to resources in the peer and can be used for
implementing features that are difficult or impossible to be implemented through
8
user chaincodes. Examples of System Chaincodes include QSCC (Query System Chaincode)
9
for ledger and other Fabric-related queries, CSCC (Configuration System Chaincode)
10
which helps regulate access control, and LSCC (Lifecycle System Chaincode).
11
12

Unlike a user chaincode, a system chaincode is not installed and instantiated
13
14
using proposals from SDKs or CLI. It is registered and deployed by the peer at
start-up.
15

16
System chaincodes can be linked to a peer in two ways: statically, and dynamically
17
18
19
20
21
22
23
24
25
26
27
28
using Go plugins. This tutorial will outline how to develop and load system chaincodes
as plugins.

Developing Plugins
------------------

A system chaincode is a program written in `Go <https://golang.org>`_ and loaded
using the Go `plugin <https://golang.org/pkg/plugin>`_ package.

A plugin includes a main package with exported symbols and is built with the command
``go build -buildmode=plugin``.

29
Every system chaincode must implement the `Chaincode Interface <https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#Chaincode>`_
30
31
and export a constructor method that matches the signature ``func New() shim.Chaincode``
in the main package. An example can be found in the repository at ``examples/plugin/scc``.
32
33

Existing chaincodes such as the QSCC can also serve as templates for certain
34
features, such as access control, that are typically implemented through
35
36
system chaincodes. The existing system chaincodes also serve as a reference for
best-practices on things like logging and testing.
37
38

.. note:: On imported packages: the Go standard library requires that a plugin must
39
40
          include the same version of imported packages as the host application
          (Fabric, in this case).
41
42
43
44

Configuring Plugins
-------------------

45
Plugins are configured in the ``chaincode.systemPlugin`` section in ``core.yaml``:
46
47
48
49
50
51
52
53
54
55
56
57

.. code-block:: bash

  chaincode:
    systemPlugins:
      - enabled: true
        name: mysyscc
        path: /opt/lib/syscc.so
        invokableExternal: true
        invokableCC2CC: true


58
59
A system chaincode must also be whitelisted in the ``chaincode.system`` section
in ``core.yaml``:
60
61
62
63
64
65
66
67
68
69

.. code-block:: bash

  chaincode:
    system:
      mysyscc: enable


.. Licensed under Creative Commons Attribution 4.0 International License
   https://creativecommons.org/licenses/by/4.0/