Skip to content

Commit c1916b8

Browse files
authored
Merge pull request #8 from CryptoCredits/step-by-step
Step by step
2 parents b77006b + 0eb4374 commit c1916b8

15 files changed

+1107
-441
lines changed

source/block.rst

Lines changed: 0 additions & 13 deletions
This file was deleted.

source/blockchain.rst

Lines changed: 175 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,181 @@
11
.. _blockchain:
22

3-
.. _blockchain-general:
4-
53
Blockchain
6-
====
4+
==========
5+
6+
The Credits Blockchain Framework as an application is a distributed software service that runs on
7+
multiple servers called :ref:`Nodes <architecture-blockchain-node>`. Every node holds a copy
8+
of the Credits blockchain as a data structure. This data structure consists of cryptographically
9+
connected :ref:`Blocks <blockchain-block>` and :ref:`States <blockchain-state>`. New blocks and
10+
states are added to the blockchain by :ref:`applying transactions <blockchain-applying-transactions>`
11+
and electing the best blocks through node :ref:`consensus <blockchain-consensus>`.
712

8-
Building from state and blocks a chain can be established. Because credits has intermediate states its not a direct link
9-
from block to block, instead a block is formed from a state, and then the application of that block forms a new state.
13+
.. _blockchain-state:
1014

11-
Imagine starting at state 0.
15+
Blockchain State
16+
^^^^^^^^^^^^^^^^
17+
18+
The State is simply just a key-value map of data. Credits Framework has one global state object,
19+
this is comprised of many different smaller states. There can be multiple different
20+
substates that can contain any information, all that is important is that every key in the
21+
state is a string. An example of a traditional state as shown:
1222

1323
.. code-block:: json
1424
1525
{
16-
"balance": {
26+
"loans": {
27+
"Bob": 200,
28+
"Dave": 200
29+
},
30+
"balances": {
1731
"Alice": 100,
18-
"Bob": 0
32+
"Carol": 100
33+
}
34+
}
35+
36+
37+
In the example above there is a ``balances`` state and a ``loans`` state, these states
38+
can have many arbitrary number of key value pairs. Usually credits addresses are used
39+
as the key in a state but this doesn't always need to be the case. The State is ordered
40+
by insertion order and is hashed to provide a state hash.
41+
42+
43+
.. _blockchain-block:
44+
45+
Blockchain Block
46+
^^^^^^^^^^^^^^^^
47+
48+
In the simplest terms, a block is just a collection of :ref:`transactions <transaction>`.
49+
Blocks are formed by taking valid unconfirmed transactions from the internal transactions
50+
pool and making a block that contains these transactions. Once the block is formed
51+
it is distributed in the network and nodes can decide to vote and commit to this block.
52+
A block also contains information on the state of the world that it is built on. By
53+
referencing the state, a node can take the block, check that it is starting in the same
54+
place as the creator of the block and then apply the transactions.
55+
56+
57+
.. _blockchain-onboarding-transactions:
58+
59+
Onboarding transactions
60+
^^^^^^^^^^^^^^^^^^^^^^^
61+
62+
Onboarding transaction, transform or proof means generally to get it accepted into the
63+
node's unconfirmed transactions pool. In case of PaaS deployment, the onboarding happens
64+
by sending the marshalled transaction to the node HTTP API. In other more complex
65+
deployments the HTTP API gateway can be replaced with other transport, e.g. TCP socket,
66+
CLI interface, RPC interface etc. Onboarding here serves as a transport agnostic term
67+
for the act of accepting transaction into the node.
68+
69+
70+
.. _blockchain-applying-transactions:
71+
72+
Applying transactions
73+
^^^^^^^^^^^^^^^^^^^^^
74+
75+
Applying a transaction means to execute the :ref:`Transform <transform>` contained
76+
inside transaction against the current global state and get the next global state.
77+
Consider same global state as above:
78+
79+
.. code-block:: json
80+
81+
{
82+
"loans": {
83+
"Bob": 200,
84+
"Dave": 200
85+
},
86+
"balances": {
87+
"Alice": 100,
88+
"Carol": 100
89+
}
90+
}
91+
92+
If we apply transaction that moves 50 credits from Alice to Bob. Then the next global state will be:
93+
94+
.. code-block:: json
95+
96+
{
97+
"loans": {
98+
"Bob": 250,
99+
"Dave": 200
100+
},
101+
"balances": {
102+
"Alice": 50,
103+
"Carol": 100
19104
}
20105
}
21106
107+
This will reflect the fact that Alice has loaned further 50 credits to Bob.
108+
109+
Applying a block is the process of applying each transaction in order. Each transaction
110+
will produce a new state once it is applied, and by applying every transaction in the block
111+
this will form the next state of the world after the block.
112+
113+
Any :ref:`Applicable <interfaces-applicable>` object should be able to apply itself.
114+
115+
116+
.. _blockchain-consensus:
117+
118+
Blockchain consensus
119+
^^^^^^^^^^^^^^^^^^^^
120+
121+
There are many different Consensus mechanisms. Two of the common mechanisms that are talked about in
122+
blockchain are Proof of Work and Proof of Stake.
123+
124+
125+
Proof of Work
126+
-------------
127+
Proof of work is the more commonly talked about mechanism for achieving consensus. Proof of work
128+
requires that a contributor do a deterministically difficult amount of work that is then easy to check.
129+
Bitcoin does this by making miners hash until they get the longest string of zeroes this
130+
artificially slows down block creation in the bitcoin network.
131+
Anyone can mine blocks but given the current normalize difficulty it takes a long time for
132+
non-specialized hardware to mine a valid block. Think of this as like a lottery,
133+
everyone is turning a crank and one person is rewarded every x minutes.
134+
135+
136+
Proof of Stake
137+
--------------
138+
139+
Proof of stake is far more like a traditional election model. Everyone locks up some value as a promise of their
140+
good intentions inside the system and then there are fixed voting rounds where each person votes using the weight of the value locked
141+
up. In an example both Alice and Bob stake 50 value into the system, they both have equal votes but neither have
142+
majority. Both together can vote and provide majority for confirming a block. Anyone can propose a block but only
143+
those with stake can vote.
22144

23-
And there is a transaction that moves 50 credits from ``Alice`` to ``Bob``.
24145

25-
This transaction can apply to state 0, so it is formed into a block that builds upon state 0.
146+
Credits consensus
147+
-----------------
148+
149+
Consensus in Credits is at its heart Proof of Stake. Validators bond value against as a promise of their honest intentions.
150+
Validators attempt to create valid blocks of unconfirmed transactions. These blocks are distributed between the validators.
151+
Each validator picks a block to vote on (currently this is the first valid block seen) and then tells the network of their
152+
intention to vote for this block. Once enough votes have been cast for that block to have a winning concensus everyone announces
153+
their intention to commit to that block. With enough voters committed to a block it becomes ratified history and the state of the
154+
world is upgraded.
155+
156+
.. _blockchain-structure:
157+
158+
Blockchain structure
159+
^^^^^^^^^^^^^^^^^^^^
160+
161+
Building from states and blocks the chain can be created. Because Credits blockchain
162+
has intermediate states it's not a direct link from block to block, instead, a
163+
block is formed from the current state, and then the application of that block to
164+
current state forms the next state.
165+
166+
Imagine starting at the following state 0:
167+
168+
.. code-block:: json
169+
170+
{
171+
"balance": {
172+
"Alice": 100,
173+
"Bob": 0
174+
}
175+
}
176+
177+
And there is a transaction that moves 50 credits from ``Alice`` to ``Bob``. This
178+
transaction can apply to state 0, so it is formed into a block that builds upon state 0.
26179
::
27180

28181
+-----------+
@@ -39,8 +192,9 @@ This transaction can apply to state 0, so it is formed into a block that builds
39192
+-----------+
40193

41194

42-
The block is distributed between the nodes and references the state it is built on, once the network agrees to make this
43-
block each node applies this block to state 0 to produce the next state.
195+
The block is then distributed between the nodes and references the state it is
196+
built on. Once the network agrees to make this block the next one in the chain
197+
each node applies this block to state 0 to produce the next state.
44198
::
45199

46200
+-----------+ +-----------+
@@ -57,7 +211,7 @@ block each node applies this block to state 0 to produce the next state.
57211
+-----------+
58212

59213

60-
The new state 1 looks like the following
214+
The new state 1 looks like the following:
61215

62216
.. code-block:: json
63217
@@ -68,8 +222,9 @@ The new state 1 looks like the following
68222
}
69223
}
70224
71-
A new transaction is formed, this transaction moves the remaining 50 from ``Alice`` to ``Bob``. Another new block is
72-
formed looking like such
225+
A new transaction is formed and posted to the blockchain, this transaction
226+
moves the remaining 50 from ``Alice`` to ``Bob``. Another new block is
227+
formed looking like such:
73228
::
74229

75230
+-----------+ +-----------+
@@ -102,7 +257,7 @@ The process continues and block 1 will be applied to state 1, forming the next f
102257
+-----------+ +-----------+
103258

104259

105-
Leaving it with a final state of
260+
Leaving it with a final state of:
106261

107262
.. code-block:: json
108263
@@ -113,3 +268,7 @@ Leaving it with a final state of
113268
}
114269
}
115270
271+
From here onwards other transactions can happen, further mutating global state
272+
and adding new blocks to the chain. The process will run indefinitely as
273+
long as there is a quorum of nodes in the network and new valid transactions
274+
are coming in.

source/common_library.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33

44
Common library
5-
====
5+
==============
66

77
Install
8-
^^^^
8+
^^^^^^^
99

1010
Common library is available through PyPI as ``credits.common``. To install it run:
1111

@@ -15,7 +15,7 @@ Common library is available through PyPI as ``credits.common``. To install it ru
1515
1616
1717
Purpose
18-
^^^^
18+
^^^^^^^
1919

2020
Having installed that you will be able to import required parts of the framework,
2121
build transactions locally, run tests against your code and interact with the remote

source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
# built documents.
6868
#
6969
# The short X.Y version.
70-
version = u"1.0.0"
70+
version = u"1.2.0"
7171
# The full version, including alpha/beta/rc tags.
72-
release = u"1.0.0"
72+
release = u"1.2.0"
7373

7474
# The language for content autogenerated by Sphinx. Refer to documentation
7575
# for a list of supported languages.

source/gcloud_signup_process.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _gcloud-reference-label:
1+
.. _gcloud-onboarding-process:
22

33
Government Agencies Onboarding
44
==============================

source/getting_started.rst

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _getting-started:
22

33
Getting started
4-
====
4+
===============
55

66
To start building a blockchain, sign up with one of our cloud platforms. The
77
public PaaS is designed for the general public, while G-Cloud infrastructure is
@@ -11,37 +11,39 @@ domains.
1111

1212

1313
Public platform onboarding
14-
^^^^
14+
^^^^^^^^^^^^^^^^^^^^^^^^^^
1515

16-
You can access Credits public cloud blockchain beta platform at `public.credits.works
17-
<https://public.credits.works>`_. You can signup directly via the platform API itself
18-
following :ref:`PaaS API documentation <paas-api>`.
16+
You can access Credits public cloud blockchain beta platform at
17+
`public.credits.works <https://public.credits.works/>`_. You can signup directly via
18+
the platform API itself following :ref:`PaaS API documentation <paas-api>`.
1919

2020
G-Cloud platform onboarding
21-
^^^^
21+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
2222

2323
In order to sign-up for our G-Cloud offering, you will need to go through our
24-
onboarding process, including verifying your organization as a qualified UK
25-
government agency. You can find more details about this process :ref:`here
26-
<gcloud-reference-label>`.
24+
:ref:`onboarding process <gcloud-onboarding-process>`, including verifying your
25+
organisation as a qualified UK government agency.
2726

2827

2928
How to interact with the system
30-
^^^^
29+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3130

32-
Once you have been ouboarded and received your API keys you will need to create
33-
your first blockchain network and start developing with it. You will bedeveloping
34-
in Python using publicly accessible ``credits.common`` library.
31+
Once you have registered with public API (or received API keys from us for GCloud)
32+
you will need to create your first blockchain network and start developing with it.
33+
You will be developing in Python using publicly accessible ``credits.common`` library.
34+
35+
The public PaaS API is available at `public.credits.works <https://public.credits.works/api/v1/status>`_.
36+
37+
The G-Cloud PaaS API is available at `gcloud.credits.works <https://gcloud.credits.works/api/v1/status>`_.
3538

36-
The G-Cloud PaaS API is available at `gcloud.credits.works <https://gcloud.credits.works>`_.
37-
The public PaaS API will become available again after the relaunch.
3839

3940
Further reading
40-
^^^^
41+
^^^^^^^^^^^^^^^
4142

42-
- :ref:`PaaS API <paas-api>`
43+
- :ref:`system architecture <system-architecture>` overview
44+
- :ref:`step by step <step-by-step>` custom blockchain creation guide
4345
- very basics of :ref:`Credits blockchain <blockchain>` mechanics
44-
- :ref:`Common library <common-library>`
45-
- :ref:`Transactions <transaction>`
46+
- :ref:`Transactions <transactions-transforms-proofs>`
4647
- :ref:`Interfaces <interfaces>`
48+
- :ref:`PaaS API <paas-api>`
4749

0 commit comments

Comments
 (0)