Skip to content

Commit c7c8827

Browse files
nickgaskimastersingh24
authored andcommitted
[FAB-6568] Fabcar Documentation for 15049
This updates the main RTD doc, as well as the accompanying low level explanation. Dependent on 15049; DO NOT MERGE independently. They must be added together; Fix merge conflict Incorporate Dave, Bret, JZ & Gari feedback. Update code snippets to mirror our javascript programs Update doc to reflect new key store location Update CouchDB references with capitalization [ci-skip] Change-Id: I43afad0ae946c7277f35e9ed5627097ec0c5ae2a Signed-off-by: Nick Gaski <[email protected]> Signed-off-by: Gari Singh <[email protected]> (cherry picked from commit ad9fc9c)
1 parent 8395434 commit c7c8827

File tree

2 files changed

+239
-168
lines changed

2 files changed

+239
-168
lines changed

docs/source/understand_fabcar_network.rst

+38-46
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Obscuring the underpinnings of the network to that degree is fine for the
1010
majority of application developers. They don't necessarily need to know how
1111
network components actually work in detail in order to create their app.
1212

13-
But for those who do want to know about the fun stuff going on under the covers
14-
(so to speak), let's go through how applications **connect** to the network and
13+
But for those who do want to know about the fun stuff going on under the covers,
14+
let's go through how applications **connect** to the network and
1515
how they propose **queries** and **updates** on a more granular level, as well
1616
as point out the differences between a small scale test network like Fabcar and
1717
how apps will usually end up working in the real world.
@@ -23,18 +23,18 @@ role an application plays.
2323
Components of the Fabcar Network
2424
--------------------------------
2525

26-
The Fabcar network consists of one peer node, one ordering node (aka, the
27-
"orderer"), a couchDB container, and a CLI container. This represents a
28-
very limited network, without a certificate authority or any other
29-
peers.
26+
Fabcar uses the "basic-network" sample as its limited development network. It
27+
consists of a single peer node configured to use CouchDB as the state database,
28+
a single "solo" ordering node, a certificate authority (CA) and a CLI container
29+
for executing commands.
3030

3131
For detailed information on these components and what they do, refer to
3232
:doc:`build_network`.
3333

3434
These components are bootstrapped by the ``./startFabric.sh`` script, which
3535
also:
3636
* creates a channel and joins the peer to the channel
37-
* installs smart contract onto the peer's file system and instantiates it on the channel (instantiate starts a container)
37+
* installs the ``fabcar`` smart contract onto the peer's file system and instantiates it on the channel (instantiate starts a container)
3838
* calls the ``initLedger`` function to populate the channel ledger with 10 unique cars
3939

4040
These operations would typically be done by an organizational or peer admin.
@@ -53,74 +53,66 @@ against is ``dev-peer0.org1.example.com``.
5353

5454
APIs are accessible with an SDK. For purposes of this exercise, we're using the
5555
`Hyperledger Fabric Node SDK <https://fabric-sdk-node.github.io/>`__ though
56-
there is also a Java SDK and CLI that can be used to develop applications.
56+
there is also a Java SDK and CLI that can be used to drive transactions.
5757
SDKs encapsulate all access to the ledger by allowing an application to
58-
use smart contracts, run queries, or receive ledger updates. These APIs use
58+
communicate with smart contracts, run queries, or receive ledger updates. These APIs use
5959
several different network addresses and are run with a set of input parameters.
6060

61-
Smart contracts are installed and instantiated on a channel through the
62-
consensus process. The script that launched our simplified Fabcar test network
63-
bypassed this process by installing and instantiating the smart contracts for
64-
us on the lone peer in our network.
65-
66-
One crucial aspect of networks missing from Fabcar is the roll a certificate
67-
authority (CA) plays issuing the certificates that allow users to query,
68-
transact, and govern a network. This simplification was made because Fabcar is
69-
really meant to show how applications connect to the network and issue queries
70-
and updates rather than highlighting the enrollment and governance process.
71-
72-
In future iterations of Fabcar we'll go more into how enrollment works and how
73-
different kinds of certificates are issued.
61+
Smart contracts are installed by a peer administrator and then instantiated on a
62+
channel by an identity fulfilling the chaincode's instantiation policy, which by
63+
default is comprised of channel administrators. The instantiation of
64+
the smart contract follows the same transaction flow as a normal invocation - endorse,
65+
order, validate, commit - and is a prerequisite to interacting with a chaincode
66+
container. The script that launched our simplified Fabcar test network took care
67+
of the installation and instantiation for us.
7468

7569
Query
7670
^^^^^
7771

78-
Queries are the simplest kind of invocation: a call and response. Applications
79-
can query different ledgers at the same time. Those results are returned to
80-
the application **synchronously**. This does not necessarily ensure that each
81-
ledger will return exactly the same information (a peer can go down, for
82-
example, and miss updates). Given that our sample Fabcar network has only one
83-
peer, that's not really an issue here, but it's an important consideration
84-
when developing applications in a real world scenario.
72+
Queries are the simplest kind of invocation: a call and response. The most common query
73+
will interrogate the state database for the current value associated
74+
with a key (``GetState``). However, the `chaincode shim interface <https://github.com/hyperledger/fabric/blob/release/core/chaincode/shim/interfaces.go>`__
75+
also allows for different types of ``Get`` calls (e.g. ``GetHistoryForKey`` or ``GetCreator``).
8576

86-
The peers hold the hash chain (the record of updates), while the updates
87-
themselves are stored in a separate couchDB container (which allows for the
88-
storage of rich queries, written in JSON).
77+
In our example, the peer holds a hash chain of all transactions and maintains
78+
chaincode state through use of a state database, which in our case is a CouchDB container. CouchDB
79+
provides the added functionality of rich queries, contingent upon the chaincode data (key/val pairs)
80+
being modeled as JSON. When we call the ``GetState`` API in our smart contract, we
81+
are retrieving the JSON value associated with a car from the CouchDB state database.
8982

90-
Queries are built using a **var request** -- identifying the correct ledger, the
91-
smart contracts it will use, the search parameters etc -- and then invoking the
92-
``chain.queryByChaincode`` API to send the query. An API called
93-
``response_payload`` returns the result to the application.
83+
Queries are constructed by identifying a peer, a chaincode, a channel and a set of
84+
inputs (e.g. the key) for an available chaincode function and then utilizing the
85+
``chain.queryByChaincode`` API to send the query to the peer. The corresponding
86+
value to the supplied inputs is returned to the application client as a response.
9487

9588
Updates
9689
^^^^^^^
9790

98-
Ledger updates start with an application generating a transaction proposal. A
99-
request is constructed to identify the channel ID, function, and specific smart
100-
contract to target for the transaction. The program then calls the
91+
Ledger updates start with an application generating a transaction proposal. As with
92+
query, a request is constructed to identify a peer, chaincode, channel, function, and
93+
set of inputs for the transaction. The program then calls the
10194
``channel.SendTransactionProposal`` API to send the transaction proposal to the
10295
peer(s) for endorsement.
10396

104-
The network (i.e., the endorsing peer) returns a proposal response, which the
97+
The network (i.e. the endorsing peer(s)) returns a proposal response, which the
10598
application uses to build and sign a transaction request. This request is sent
10699
to the ordering service by calling the ``channel.sendTransaction`` API. The
107100
ordering service bundles the transaction into a block and delivers it to all
108-
peers on a channel for validation (the Fabcar network has only one endorsing
109-
peer and one channel).
101+
peers on a channel for validation (the Fabcar network has only one peer and one channel).
110102

111103
Finally the application uses two event handler APIs: ``eh.setPeerAddr`` to
112104
connect to the peer's event listener port and ``eh.registerTxEvent`` to
113-
register events associated with a specific transaction ID. The
114-
``eh.registerTxEvent`` API registers a callback for the transactionID that
115-
checks whether ledger was updated or not.
105+
register for events associated with a specific transaction ID. The
106+
``eh.registerTxEvent`` API allows the application to be notified about the fate
107+
of a transaction (i.e. valid or invalid).
116108

117109
For More Information
118110
--------------------
119111

120112
To learn more about how a transaction flow works beyond the scope of an
121113
application, check out :doc:`txflow`.
122114

123-
To get started developing chaincode, read :doc:'chaincode4ade'.
115+
To get started developing chaincode, read :doc:`chaincode4ade`.
124116

125117
For more information on how endorsement policies work, check out
126118
:doc:`endorsement-policies`.

0 commit comments

Comments
 (0)