All India Council for Technical Education AICTE India has organised a Short Term Training Program (STTP) on Blockchain Technology for Engineering Educators across India over in this week. It was an exciting event for us in working on the convergence of academia and industry. Thanks to the support from 'The Blockchain Network' (TBN), I could present a couple of protocol and platform deep dive sessions on Hyperledger Fabric and R3 Corda. Please find the compilation of concepts and components that we have discussed on R3 Corda in this session in the attached document. Request your views and comments!
Powering Real-Time Decisions with Continuous Data Streams
Corda Blockchain Technology STTP
1. R3 Corda
AICTE STTP 2020 on Blockchain Technology by https://twitter.com/gokulgaze
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12. Corda - Basic Concepts
States - The states represent shared facts on the ledger
Transactions - The transactions update the ledger states
Contracts - The contracts govern the ways in which states can evolve over time
Flows - The flows describe the interactions that must occur between parties to achieve consensus
Nodes - Each node contains an instance of Corda, one or more CorDapps, and so on
13. Corda - Advanced Concepts
Consensus - How parties on the network reach consensus about shared facts on the ledger
Notaries - The component that assures uniqueness consensus (prevents double spends)
Vault - The component that stores on-ledger shared facts for a node
14. Corda - Novel Features
Time Windows -Transactions validated as having fallen after, before or within a particular time window
Oracles - Transactions can include off-ledger facts retrieved using Oracles
Transaction Tear-Offs - Transactions can be signed by parties who have access to only a limited view
Trade-Offs - Trade-offs that have been made in designing Corda and CorDapps
15. Nodes and Network Maps
The network map service maps each well-known node identity to an IP address. These IP addresses are
used for messaging between nodes.
Nodes can also generate confidential identities for individual transactions. The certificate chain linking a
confidential identity to a well-known node identity or real-world legal identity is only distributed on a
need-to-know basis. If confidential identities are being used, this ensures that even if an attacker gets
access to an unencrypted transaction, they cannot identify the transaction’s participants without
additional information.
16. Shared Facts
In Corda, there is no single central store of data. Instead, each node maintains its own database of those
facts that it is aware of. The result of this design is that each peer only sees a subset of facts on the ledger,
and no peer is aware of the ledger in its entirety.
On Corda, there is no central or general ledger operating with agency on behalf of all of the nodes on the
network. Instead, each node on the network maintains its own vault containing all of its known facts. You
can think of this vault as being a database or simple table.
Corda guarantees that whenever one of these facts is shared by multiple nodes on the network, it evolves
in lockstep in the database of every node that is aware of it.
17. States
A state is an immutable object representing a fact known by one or more Corda nodes at a specific point
in time.
States can contain arbitrary data, allowing them to represent facts of any kind (e.g. stocks, bonds, loans,
KYC data, identity information…).
As well as any information about the fact itself, the state also contains a reference to the contractthat
governs the evolution of the state over time.
18. State Sequences
As states are immutable, they cannot be modified directly to reflect a change in the state of the world.
Instead, the lifecycle of a shared fact over time is represented by a state sequence.
When a state needs to be updated, we create a new version of the state representing the new state of the
world, and mark the existing state as historic.
This sequence of state replacements gives us a full view of the evolution of the shared fact over time.
19. Reference States
Not all states need to be updated by the parties which use them. In the case of reference data, there is a
common pattern where one party creates reference data, which is then used (but not updated) by other
parties.
For this use-case, the states containing reference data are referred to as “reference states”. Syntactically,
reference states are no different to regular states. However, they are treated different by Corda
transactions
20. Transactions
Corda uses a UTXO (unspent transaction output) model where every state on the ledger is immutable.
The ledger evolves over time by applying transactions.
Transactions update the ledger by marking zero or more existing ledger states as historic (the inputs), and
producing zero or more new ledger states (the outputs).
Transactions represent a single link in the state sequences seen in States.
21. Transaction Dynamics
A transaction can contain any number of inputs, outputs and references of any type:
● They can include many different state types (states may represent cash or bonds, for example)
● They can be issuances (have zero inputs) or exits (have zero outputs)
● They can merge or split fungible assets (for example, they may combine a $2 state and a $5 state into a
$7 cash state)
22. Transaction Types
Transactions are atomic; either all of the transaction’s proposed changes are accepted, or none are.
There are two basic types of transactions:
● Notary-change transactions (used to change a state’s notary - see Notaries)
● General transactions (used for everything else)
23. Transaction Chains
When creating a new transaction, the output states that the transaction proposes do not exist yet, and must
therefore be created by the proposer or proposers of the transaction. However, the input states already exist as
the outputs of previous transactions. We therefore include them in the proposed transaction by reference.
These input states references are a combination of:
● The hash of the transaction that created the input
● The input’s index in the outputs of the previous transaction
24.
25. Transaction Builders
Initially, a transaction is just a proposal to update the ledger. It represents the future state of the ledger that is
desired by the transaction builders:
To become reality, the transaction must receive signatures from all of the required signers (see Commands,
below). Each required signer appends their signature to the transaction to indicate that they approve the
proposal:
26. Transaction Validity
Each required signer should only sign the transaction if the following two conditions hold:
● Transaction validity: For both the proposed transaction, and every transaction in the chain of
transactions that created the current proposed transaction’s inputs:>
○ The transaction is digitally signed by all the required parties
○ The transaction is contractually valid
● Transaction uniqueness: There exists no other committed transaction that has consumed any of the
inputs to our proposed transaction
27. Other Transaction Components
As well as input states and output states, transactions contain:
● Commands
● Attachments
● Time-Window
● Notary
28.
29. Transaction Components - Example
For example, suppose we have a transaction where Alice uses a £5 cash payment to pay off £5 of an IOU with
Bob.
This transaction comprises two commands: a settlement command which reduces the amount outstanding on
the IOU, and a payment command which changes the ownership of £5 from Alice to Bob.
It also has two supporting attachments, and will only be notarised by NotaryClusterA
if the notary pool receives it within the specified time-window.
30. Transaction Commands
Including a command in a transaction allows us to indicate the transaction’s intent, affecting how we
check the validity of the transaction.
Each command is also associated with a list of one or more signers. By taking the union of all the public
keys listed in the commands, we get the list of the transaction’s required signers.
31. Transaction Attachments
Sometimes, we have a large piece of data that can be reused across many different transactions.
Some examples: A calendar of public holidays, Supporting legal documentation, A table of currency codes
Each transaction can refer to zero or more attachments by hash.
These attachments are ZIP/JAR files containing arbitrary content.
The information in these files can then be used when checking the transaction’s validity.
32. Transaction Time Window
In some cases, we want a proposed transaction to only be approved during a certain time-window. For
example:
● An option can only be exercised after a certain date
● A bond may only be redeemed before its expiry date
In such cases, we can add a time-window to the transaction. Time-windows specify the time period during
which the transaction can be committed. The notary pool enforces time-window validity.
33. Transaction Notary
A notary pool is a network service that provides uniqueness consensus by attesting that, for a given
transaction, it has not already signed other transactions that consume any of the proposed transaction
input states. The notary pool provides the point of finality in the system.
Note that if the notary entity is absent then the transaction is not notarised at all. This is intended for
issuance/genesis transactions that don’t consume any other states and thus can’t double spend anything.
34. Transaction Verification
Recall that a transaction is only valid if it is digitally signed by all required signers. However, even if a
transaction gathers all the required signatures, it is only valid if it is also contractually valid.
Contract validity is defined as follows:
● Each transaction state specifies a contract type and a contract takes a transaction as input,
● states whether the transaction is considered valid based on the contract’s rules
● A transaction is only valid if the contract of every input state and every output state considers it to
be valid
35. Contract Capabilities
The contract code has access to the full capabilities of the language, including:
● Checking the number of inputs, outputs, commands, or attachments
● Checking whether there is a time window or not
● Checking the contents of any of these components
● Looping constructs, variable assignment, function calls, helper methods, and so on
● Grouping similar states to validate them as a group; for example, imposing a rule on the combined
value of all the cash states
36. Contract Sandbox
Transaction verification must be deterministic - a contract should either always accept or always reject a
given transaction.
For example, transaction validity cannot depend on the time at which validation is conducted, or the
amount of information the peer running the contract holds.
This is a necessary condition to ensure that all peers on the network reach consensus regarding the
validity of a given ledger update.
37. Deterministic Sandbox
The sandbox has a whitelist that prevents the contract from importing libraries that could be a source of
non-determinism.
This includes libraries that provide the current time, random number generators, libraries that provide
file system access or networking libraries, for example.
Ultimately, the only information available to the contract when verifying the transaction is the
information included in the transaction itself.
38. Corda Flows
● Flows automate the process of agreeing ledger updates
● Communication between nodes only occurs in the context of these flows, and is point-to-point
● Built-in flows are provided to automate common tasks
39. Flow Framework
Rather than having to specify these steps manually, Corda automates the process using flows. A flow is a
sequence of steps that tells a node how to achieve a specific ledger update, such as issuing an asset or
settling a trade.
Once a given business process has been encapsulated in a flow and installed on the node as part of a
CorDapp, the node’s owner can instruct the node to kick off this business process at any time using an
RPC call.
The flow abstracts all the networking, I/O and concurrency issues away from the node owner.
40. Flow Framework
All activity on the node occurs in the context of these flows. Unlike contracts, flows do not execute in a
sandbox, meaning that nodes can perform actions such as networking, I/O and use sources of randomness
within the execution of a flow.
Nodes communicate by passing messages between flows. Each node has zero or more flow classes that are
registered to respond to messages from a single other flow.
Flows can be composed by starting a flow as a subprocess in the context of another flow. The flow that is
started as a subprocess is known as a subflow. The parent flow will wait until the subflow returns.
41. Flow Library
Corda provides a library of flows to handle common tasks, meaning that developers do not have to
redefine the logic behind common processes such as:
● Notarising and recording a transaction
● Gathering signatures from counterparty nodes
● Verifying a chain of transactions
42. Concurrency in Flows
The flow framework allows nodes to have many flows active at once. These flows may last days, across
node restarts and even upgrades.
This is achieved by serializing flows to disk whenever they enter a blocking state (e.g. when they’re
waiting on I/O or a networking call). Instead of waiting for the flow to become unblocked, the node
immediately starts work on any other scheduled flows, only returning to the original flow at a later date.
43. Vault
Each node on the network maintains a vault - a database where it tracks all the current and historic states that it
is aware of, and which it considers to be relevant to itself:
50. Two Types of Consensus Algorithms
Determining whether a proposed transaction is a valid ledger update involves reaching two types of
consensus:
● Validity consensus - this is checked by each required signer before they sign the transaction
● Uniqueness consensus - this is only checked by a notary service
79. Java Concurrency in Corda
Quasar is a Java library that uses clever byte-code rewriting and exceptions to provide continuations. The
main concept is a fiber – a thread like construct that runs code, but can decide to suspend itself, at which
point the state of it gets collected and stashed away, to be re-hydrated and continued later.
In order to achieve this, Quasar requires any method that can be suspended to be annotated with its
@Suspendable annotation. At start-up time/just before JIT, it rewrites the bytecode of all these methods.
To suspend a fiber, the code calls a specific quasar function (e.g. parkAndSerialize) which throws
aSuspendExecution exception. This exception passes through all user code and gets caught by Quasar,
which can extract the call stack to squirrel it away in serialized form.
81. Corda State Machine
The state machine is the core of what is called the Flow Framework in our user documentation. It wraps
quasar and uses it to turn the linear Kotlin or Java code inside the flow logic implementation in a CorDapp
into code that can be suspended, the current state of which can be checkpointed, and that can be rerun
from any checkpoint.
The state machine has an event feed, and one or more execution threads. Events trigger transitions
between the possible states. Every flow starts in the Pending state as a start flow message, and then
transitions to running. In the easiest case, it finally reaches the end of its run function and transitions to
success, the result gets returned and any checkpoint data cleaned up.