-
Notifications
You must be signed in to change notification settings - Fork 773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP][DOC] High level specs of transaction model #877
Comments
@diminator and I just had a quick chat about asset use cases: Composable Assets or Asset assemblyTL;DR: Different assets ( DescriptionWrigleyMate Org. found an exciting and delicious new receipt for mate. All the cool kids love mate. Even more so when all the ingredients are sourced from fair trade and organic dealers. Since WrigleyMate Org. believes in transparency, they decide to track their new mate's supply chain on an immutable and open ledger. The receipt goes like this:
On BigchainDB, each of these ingredients is registered separately as a divisible asset by the respective dealers/manufacturers:
The following describes WrigleyMate's manufacturing process: Cinnamondo Europe receives FairTrade Bottle Inc.'s 0.5l bottles as well as water from Organic Water GmbH's. To each bottle, it adds 3g of cinnamon, as well as 0.45l of water. To represent this in BigchainDB, it needs to support the assembly of assets:
By mixing together ingredients, we create a new, non-final asset on the fly: a mixture of cinnamon, water and a bottle.
To proceed, Cinnamondo Europe transfers the mixture (both physically and digitally) to WrigleyMate Org. WrigleyMate Org. boils the mixture and adds 10g of their organic mate tea to it.
A lit is put on the bottle. It's ready to be sold to the cool kids on the Block ;). Edit: This use case is also relevant for partners that want to use COALA IP with SourceRights. |
Looks great already! At first sight, it seems that for some cases there should be a conservation of amounts (all in same units ofc). This can be done through summing the input amounts and making sure the output amounts to the same. In this case the amount would be in the input rather than in the asset
|
👍 |
Transaction Model
TL;DR
Update and spec out the transaction model such that users can:
owners_*
,details
, ...CREATE
transactionContext and definitions
In BigchainDB, Transactions are used to store both data and ownership Policy of. A somewhat fair representation is shown below.
Each state update to the replicated state machine (RSM) is embedded in a transaction. A validation node in the RSM needs to check the integrity of a transaction and apply all policies. When all checks are valid, then the node will vote the transaction (or it's surrounding block)
VALID
otherwiseINVALID
.Transactions interact with the nodes as follows:
Remember: each step in the validation phase costs computation and directly affects throughput!
Policies
You might have noticed a new notion of policy. A policy is a set of rules that a node can validate.
Some policy are inherent to the RSM: "Rules to create a valid chain". Let's call it Server Policy for now, but it could also be name chain policy, node policy, consistency rules, etc. Some examples include avoiding double spends, making sure the input amounts match the outputs or . This policy is hard coded in each validation node. Clients cannot alter existing or impose their own server policy. It's up to the federation of server nodes to decide and impose the server policy.
Other policies are on the client level: "Rules for a client to spend a transaction output". Let's call it Client Policy for now, but it could also be named transaction policy, user policy, etc. Some examples include providing the right fulfillment at the input to match a condition at the output. Each time a new transaction spends an output it allows the user to create a new policy in the output (eg. setting a new output condition). Note that client policies are not necessarily limited to the insides of a transactions. It could also inherit or import policies from other places such as the previous transaction or somewhere else. This last note is important when you want to create reusable policies. More about that in a later section.
Server policy
In a UTXO model, transactions are chained by linking a transactions and follow a Server Policy. Such policy defines the rules to construct a chain or DAG. Examples are:
Server policies are shared among the nodes in the system. Possible implementations use a configuration file, load plugins or fork of the code.
Client policy
To create a transaction
BigchainDB@v0.8.0
, you need to comply to theCREATE
policy. There are many paths to implement such a policy (see #327 #347 #794). In practice the nodes will decide whether or not to use an implicit policy, hence such create policy is part of server policy.Client policy really restricts itself to rules that are applied by clients to the system. A typical placeholder for these rules is the output of a transaction - but not need to be. A generic representation of a
CREATE
andTRANSFER
transaction using the notion of policies is given below (policy0
andpolicy1
are client policies).When you own something then you have control to whom you would give it next. In transaction world this means that a user can specify how to spend the output of a transaction. This means that on each transaction, the client policy can change for that transaction. Typically we store the new policy in the output of a transaction - but more generally (parts of) the policy could exist in other locations (think assets and contract addresses).
How does client policy look like? Policy is mathematically enforced by some cryptographic validation like checking signatures or maybe even executing a stateful smart contract. Client policy is bytecode. One could also think of it as a
lock
andkey
pair, where unlocking a transaction requires to provide a key - ( in general: the input to a script ) - and try to fit it on the lock - (in general: evaluating the bytecode of the script with the input, possibly in a VM ).In
BigchainDB@v0.8.0
, thelock
andkey
pairs are implemented using crypto-conditions withconditions
andfulfillments
. Every time a transaction arrives at a node, all policies are executed and verified by each node. Only if the execution of the code is valid by consensus, the state of the ledger is updated by appending the transaction to the chain.Assets & Tokens vs Policy?
The above context doesn't really speak about Assets nor Tokens. It's framed in terms of Transactions and Policy. Tokens and Transactions have a similar meaning. Each Transaction contains a Token. You could think of Assets as a specific implementation of a reusable policy: a pointer to a set of rules.
Multiple inputs and outputs & divisible assets
A transaction can have
m
inputs andn
outputs, each with a specific amount. This way you can implement divisible assets like currency or kilograms of gold. To do so, a transaction combines the amount at each input and splits the outputs different amounts and a conservation policy (subset of the server policy, as it is enforced by the nodes, not the clients) makes sure that the amount at the input match the output. A simplistic representation is shown below.Proposed changes and path forward
Transaction
The transaction interface needs to be human understandable, compact and generic.
Transactions is a container that fits in a graph: It contains data, policy code, references and so on and the server policy decides the rules to append a transaction to the graph (block-chain).
The model should reflect these dynamics and have a clear and concise representation
Updatable and Reusable Policies
The client and server policy layers discussed above do not take into account the following:
A creator of an asset might want to make sure that some checks or signatures are always provided upon every future transfer of this asset - even when the policy creator is not directly involved in the act of asset transfer. You might even want to only enforce a Policy for a limited amount of future transactions, or until eternity
Every asset is tied to the issuance of the underlying token. Creating an asset policy implies creating a token. How to create new tokens with the same policy? How to update the policies? Is there a BigchainDB address where I can store my asset policy?
The above implies to add an Asset policy layer that can be stored in a Transaction and treated as such:
Validation
Terminology:
key
andlock
orfulfillment
andcondition
- albeit in the ownership layer of a transaction or embedded in an asset policy, there must be a clear definition on locks and keys. This means:a clear specification on the scope of
locks
andkeys
, including terminologyabstraction of the language that is used to generate and validate
locks
andkeys
, this also implies clean versioning of the language (egcc-v0
to point to a version of the crypto-conditions RFC and corresponding implementation andbdb-cc-v0
to shim crypto-conditions with non-RFC features)if
locks
orkeys
need to be queryable, make sure that they can be indexed in a way that is consistent with the provided scripts. The system should be able to validate that keywords-to-be-indexed (such as public_keys to query unspents) actually match the signature of the lock. This signature will be requiredWhat not to expect
Policy validation
Things like
Status Quo
Or in expanded form
Proposed changes
Assets
In
BigchainDB@v0.8.0
, a digitalasset
entry can be defined upon aCREATE
transaction. Here, the future of that asset can be controlled somewhat by specifying the amount of division, whether the asset or the amount can be updated in the future. A great start - and we love to keep going down that road. A few improvement suggestions for the Asset feature include:1. Separate the definition of the asset and it's tokenization
Problem statement
The definition of an
asset
is currently bound to the minting of the asset. This means that if you transfer your asset, you lose the control over the asset. Moreover, it becomes tedious to reuse or re-issue new assets with the same definition (and policy).Improvement Proposal
First of all definitions are in order:
CREATE
Transaction.Being able to store
In practice this means that:
In this definition:
Some analogies:
class
or atype
, whilst a Token is aninstance
or anobject
.schema
and a Token is anentry
(a row) in that schema.Motivation (vs. BigchainDB@0.8.0 and below)
Renaming
Assets
toPolicy
Separate
Asset/Policy
definition from issuanceDescription and enforcement of
Policy
rulesSome examples:
ISIN Trading
An exchange platform might want to trade securities, which are defined by a spec called ISIN. The ISIN definition is a schema with mandatory and optional fields. The ISIN could thus be converted to a Policy:
policy_ISIN = Policy(schema=schema_ISIN)
Each security can now be issued as a Token on the blockchain using the ISIN Policy:
security_apple = _Token_(policy=policy_ISIN, )
Tokens as well as the :
Transactions are a general structure (like a container) that allow you make append-only changes to the truth (ie the blockchain or the transactions in approved blocks). Each transaction has an Ownership layer and a Data layer.
kk
For example:
Transaction
The text was updated successfully, but these errors were encountered: