Offchain data

Offchain data like user and team chains, chat messages and shared files are stored in ipfs-embed. Ipfs embed is a performant rust ipfs implementation focusing on providing atomic and durable transactions. It is the first implementation to take a database centric design approach. Blocks are reference counted and insertions only succeed if all the referenced blocks are in the store. Blocks are pinned to mark them as used making sure that the block and any of it's references are not garbage collected.

Ipfs transactions are composed of insert, pin and unpin operations. In a first step when executing the transaction, these operations are expanded into insert, insert_reference, remove_reference, set_pin and remove operations. These operations are written to a write-ahead log ensuring that they are atomic and durable. The insert operations are committed atomically to paritydb where the blocks are stored. Then the metadata operations insert_reference, remove_reference and set_pin are applied to sled which is a key/value store used for maintaining and querying the block metadata. Finally the remove operations are commited to paritydb and the transaction is marked as complete in the write-ahead log. When a crash occurs and the log needs to be replayed, the following algorithm is used: If the insert operations didn't succeed, the transaction is aborted by removing the inserted blocks from the db. If the operations succeeded then the metadata and remove operations can be reapplied without adverse effects.