rooch-network / rooch

VApp Container with Move Language
https://rooch.network
Apache License 2.0
128 stars 54 forks source link

[Move] Hybrid Object and Global Storage in Move #21

Closed jolestar closed 1 year ago

jolestar commented 1 year ago

In core Move, global storage is part of the programming model and can be accessed through special operations, such as move_to, move_from and many more global storage operators. Both resources and modules are stored in the core Move global storage.

Sui introduce Object model in Move, and disable all global storage operators.

We try to hybridize the two features and make the Move language more expressive.

The developers can use global storage to save the Object index and use Objects to express Resources.

pause125 commented 1 year ago

What are the advantages of Object and global storage respectively?

jolestar commented 1 year ago

What are the advantages of Object and global storage respectively?

Give an example. We use Move to write a Blog system.

Where to save the Article? If we save the Article in the author's storage, How do we aggregate the author's articles for the list?

A solution uses the Object and Global Storage:

  1. We define the Article as an Object and save the Article to the object store.
  2. We reference articles by the ObjectID, make an index for every list, and save the index to the global storage.
jolestar commented 1 year ago

The Object in StateDB

moveos statedb
  1. Anything is an Object, including the Table.
  2. A user has two tables, one for store Resources and another for store Modules.
  3. Object in the global state tree, the key is ObjectID.
  4. Every Table is an SMT tree. The Table Object stores the SMT's state root.
  5. Normal resource struct can ref an object by the ObjectRef(TODO).
jolestar commented 1 year ago

An idea about ResourceTable

We can only save ObjectRef in the ResourceTable, requiring the struct with the key ability to be an Object, like Sui.

jolestar commented 1 year ago

Some ideas about ObjectRef

We need two types of ObjectRef:

Question:

pause125 commented 1 year ago

What are the advantages of Object and global storage respectively?

Give an example. We use Move to write a Blog system.

Where to save the Article? If we save the Article in the author's storage, How do we aggregate the author's articles for the list?

A solution uses the Object and Global Storage:

  1. We define the Article as an Object and save the Article to the object store.
  2. We reference articles by the ObjectID, make an index for every list, and save the index to the global storage.

Got it.

pause125 commented 1 year ago

In hybrid mode, We need a method to get the Object from it's id.

For example, there is a function

public entry fun update_article(article: &mut Article, content: vector<u8>)

If we retrieve the ObjectID of article from the global storage, we need a method like borrow_mut_object_from_id<Article>(id: address): &mut Article to get the Article object, and then we can pass it to the update_article function.

jolestar commented 1 year ago

I haven't decided whether to provide this method. In Sui, an Object can only be passed through transaction parameters and cannot be directly retrieved from the Object Store using the ObjectID. This relies on the design of ObjectRef.