ADR-48: Locking Collections in the builder

More details about this document
Latest published version:
https://adr.decentraland.org/adr/ADR-48
Authors:
nicosantangelo
LautaroPetaccio
nachomazzara
Feedback:
GitHub decentraland/adr (pull requests, new issue, open issues)
Edit this documentation:
GitHub View commits View commits on githistory.xyz

Abstract

The builder allows users to create items which are composed of GLB or PNG files, and group them in Collections. There's a distinction here between Decentraland Collections and Third Party Collections, we'll point out the differences as they arise. Managing items and collections is done off-chain until you decide to publish. This means that you can take items in and out of collections, modify their data, etc and it will be saved in our database. Once the publication occurs, some of the data (like the Decentraland's collection name for example) cannot change, and will be stored both in the blockchain and in our database

Publications vary for each type described above:

Problem

Publishing is done by sending a transaction. This means that the user will craft a transaction and send it to our server where it will ultimately be sent to the corresponding Polygon network to be processed. This process is usually pretty quick, but it can still take a while. It's a combination of a remote request to our server, and waiting for a transaction to be confirmed. The problem is therefore, that while we're waiting for the transaction to complete we should lock the collection/items that are being published, to avoid having missmatching data between the blockchain and our database.

Solution

We propose a locking mechanism for both types of Collections and Items. We'll lock the collection/items for a day while the publication is still going. The lock is released after that if the publication ends successfully. The idea behind it is to lock the UI while the publish transaction is loading, preventing the user from making changes and the data to be in a missmatched state.

To do this we'll have to put two mechanisms in place, for both Decentraland and Third Party data:

An example of how we can implement the method is:

function isLocked(element: Collection | Item) {
  if (element.isPublished) {
    return false
  }

  const { lock } = element
  const deadline = new Date(lock)
  deadline.setDate(deadline.getDate() + 1)

  return deadline.getTime() > Date.now()
}

What's being locked

As we said before, the locking mechanism is in place so we can avoid desynching the database with the blockchain. Anyone consuming this data can read this property and disable all components that change data that's being commited to the Blockchain.

Implementation

License

Copyright and related rights waived via CC0-1.0. DRAFT Living