MultiChain as distributed MVCC

+2 votes

Basically, I want to put an arbitrary database on a blockchain (let's assume for argument's sake that I'm not trying to squeeze a silly amount of data into every transaction).

In this blog post, http://www.multichain.com/blog/2015/07/bitcoin-vs-blockchain-debate/, Gideon refers to using a blockchain as a form of distributed multiversion concurrency control for a database.

How would I go about using MultiChain to do this? My initial attempts have been to change a row of a table into a stringified JSON object, to be sent as transactional metadata. This feels hackish though. Is there a better way?

asked Jan 23, 2016 by Leo

1 Answer

0 votes
 
Best answer

Interesting question. You would actually need to express each row of the database table as metadata within a single transaction output, rather than per-transaction, i.e. using OP_DROP within that output script. MultiChain doesn't currently provide an easy API for doing this, so you'd need to create a raw transaction using createrawtransaction, then find a library which picks apart and puts together bitcoin transactions, and add the OP_DROP inside the script for the output. You can find some code for doing decoding and encoding transactions in our OP_RETURN libraries for PHP and Python: https://github.com/coinspark

answered Jan 23, 2016 by MultiChain
selected Jan 23, 2016 by Leo
Thanks for the response, and thanks for the resources. I'll be sure to have a look at them.

I don't understand fully what you mean by "express each row of the database table as metadata within a single transaction output, rather than per-transaction".

Do you mean that whenever there's a change to the database table, I would keep things up to date by
 * encoding the entire database table as metadata
 * making a transaction containing this metadata

so that the entire network sees this on the blockchain, and hence can see what the database should look like?
Every database transaction deletes some rows and inserts others. (Modifying a row is equivalent to delete the old version of that row and creating a new one in its place.) Each deleted row is one input of a blockchain transaction, and each created row is one output, with the content of the rows encoded as OP_DROP metadata within that output.
...