Replies: 2 comments 2 replies
-
Thanks for outlining these trade-offs @il3ven. If you'd like to share the sql data model, I might be able to comment on that in some detail. I'm not as familiar with SQLite, but it looks like you can use the |
Beta Was this translation helpful? Give feedback.
-
Maintaining historical state using logsIn an open office call @neatonk mentioned that it would be good to maintain historical state so that other nodes could sync up-to a particular block number. (@neatonk correct if i understood your point incorrectly) If we only maintain the latest state then syncing can still happen but it will always sync to the latest state. A consumer of neume can be thought of a node that only syncs and never crawls. So, from a consumer point of view syncing to the latest state should be good enough. However, I do agree that it will be good to sync up-to a particular block number. We can maintain historical state by the help of logs. How will log work?Suppose we have two functions to manipulate our DB:
The SQL database will maintain only the latest state. If a node wants sync upto block number 1001, it will replay the first two logs from the above example. What do you all think about this approach? Maintaining a SQL DB and a log file. |
Beta Was this translation helpful? Give feedback.
-
We currently use LevelDB and we are facing a few limitations. We want to represent one-to-many relationship but it isn't straightforward in LevelDB.
I proposed to give sqlite a try. We favored LevelDB earlier because it is faster. I also believe that even if sqlite is slower than levelDB it won't matter because network I/O should be the bottleneck and not disk I/O.
Challenges with sqlite
Creating a database that maintains history
In the spirit of blockchains, we structured LevelDB to maintain all the history. Like Ethereum we keep track of all states and not just the latest state.
It is good to have all the history though we haven't found a proper use case for it. Another advantage was that it helped in debugging. We could re-run the crawler for any block and not worry about the database being changed.
Maintaining history in SQL
Since we maintain all the previous states in LevelDB, it would have been ideal to maintain it in SQL too. I faced challenges here.
Upon researching, I found that the recommended way to maintain history in SQL is to have a
createdAt
column. Updates will result in creation of a new row with an updatedcreatedAt
column instead of updating the previous row.In the above example, we didn't update the row with
id=1
but instead added a new row.In theory, the above works but I faced development challenges while implementing it. The SQL queries start getting really complicated when we have four tables implementing one-to-many relationships with each other and each table keeping record of previous rows.
I tried implementing the above schema by creating four tables: tracks, manifestations, tokens and owners. Writing a
SELECT
query joining these four tables where each table maintains history using acreatedAt
field turned out to be difficult that I anticipated.Maintaining only the latest state
As explained above, there are implementation challenges in maintaining state. Therefore, I propose to skip the maintenance of history. Important note - we can still and should maintain the history of certain information such as owners. We will maintain only the latest state but the latest state will have a list of all the previous and the current owners.
What's the downside?
Debugging would be harder. Imagine the following scenario:
At block number 100, a track was minted with the name "Humble". At block number 101, the track's name was changed to "Humbleness". Assuming our crawler is synced up-to block number 101, the name of the track in our DB will be "Humbleness". If at this point we were to re-run a history-maintaining crawler for just block number 100 nothing would change in our DB. However, if a crawler that does not maintain history is re-run for just block number 100. It will now say the track name as "Humble".
What's the upside?
Easier development which still allows us to achieve our goal.
Open to hearing everyone's view on this.
Beta Was this translation helpful? Give feedback.
All reactions