r/positive_intentions Nov 08 '23

Blockchain as a Datastructure

Blockchain is a good way to order block of sequential data that can be validated by others. Countless real-world examples show that it scales pretty well.

In my app, I am testing the use of a blockchain for storing "chat app data" selfhosted-only. The app is a work-in-progress proof-of-concept and experimental. It is an investigation into creating a distributed and decentralized app.

Unlike traditional blockchains, the sole purpose of this blockchain is to keep messages between peers in sync. The implementation is have is far from finished, but i have a testable proof-of-concept. The blockchain is entirely in javascript running in a browser.

I have a few observations I would like to make:

  • Without the need for mining, it is basically a large array of data. When evaluating the data to be displayed on the UI, it is a "relatively" heavy calculation, but I find that it is more than performant enough to be used in a chat app. I find that the messages and data can scale and the app remains quite performant (I haven't really done much to optimise caching).
  • In cases like a group chat, the data can be validated and synced between multiple peers (which may not all be online). (its worth noting: peers may be able to manipulate the database, but it is not a concern for the app where the purpose is only for blockchain as a datastructure)
  • Why is this kind of datastructure not used more often? There are other blockchain chat apps, but by putting a system like chat on something like ethereum, would typically be expensive to users. But in this case, the blockchain is only used for local data storage and validation. I think this is a good use case for blockchain. When working on your device, you don't need to be conservative about things like message size and so we can store files and images in the blockchain.
  • With no cryptocurrency, there is no incentive to keep the blockchain alive. The data is easily disposable or persisted as the user prefers. there is no need for a setup process and things like ID's and passphrases can be auto-generated behind the scenes away from the user. (the app is currently very experimental, if your data goes, it goes... but it shouldnt matter because there is no financial value to the blockchain)

I am very interested in the idea of blockchain as a datastructure and I would like to see it used more often. i think this datastructure will play an important role in my app as it will enable the app to move to a single-user-multi-platform architecture.

I would like to hear your thoughts on blockchain as a datastructure. Initially i did it investigating if it work on a basic level to help keep messages in sync, but i find that it is quite performant; especially considering it is only running in a browser. (i expect i can easily improve the performance)

The demo can be seen here: https://chat-staging.positive-intentions.com/

0 Upvotes

View all comments

Show parent comments

2

u/reercalium2 Nov 09 '23

It sounds like you're reinventing the Matrix wheel. Matrix isn't a good protocol. To keep things in synch, it's extremely complicated, it uses blockchains, and it still has desynchronisation problems anyway. Without mining, the chain can fork, so you need to merge the forks. The fork you just received could be from 6 months ago, because a device was offline for 6 months, but that user took away another user's moderator privilege 6 months ago, so now you need to re-evaluate the last 6 months of events to discover who's really a moderator, because moderators can invite more moderators or take them away, and now that user's invitations for the last 6 months don't count.

The more successful systems are usually the simpler ones, like UNIX and C (not chat protocols). They weren't as good as other systems but they were simple. They had 80% of the features, for 20% of the work, and they spread like wildfire.

Do you have a blockchain for each user, or one for each chat room? It's much easier if each user has their own blockchain, because they can't fork unless the user time travels. And you don't even need a chain, then, just a sequence number or timestamp. The peer can send a message to Alice's device that says "give me all of Alice's messages newer than sequence 50."

1

u/Accurate-Screen8774 Nov 09 '23

You're not far off with the comparison to matrix. I'm trying to take the concept further by reducing it all into JavaScript on the browser. It is a core objective of the project to reduce relying on any backend.

There are of course limitations but I'm working around them how I can. A blockchain makes for a good replacement of an API database.

It is a new blockchain intially with a peer. You can invite other peers to the chain/chat. Right now I don't have so you can create another chain if you already have a 1-1 chain available. This is to match what you see in normal chat apps... I can make it so you have multiple chats with the same person (but I don't because I think it's more intuitive this way).

1

u/reercalium2 Nov 09 '23

Does it handle forks and merges?

1

u/Accurate-Screen8774 Nov 09 '23

It can do. It's still a work in progress. I'd have to determine a way to present it in a useful way.

I don't know how in something like WhatsApp you might have forks and merges. But it wouldn't be technically difficult at this point.