rooch-network / rooch

VApp Container with Move Language for Bitcoin ecosystem
https://rooch.network
Apache License 2.0
163 stars 87 forks source link

[rooch-rpc-api] SyncStateFilter of the syncStates method supports filtering by application #2838

Open yubing744 opened 3 weeks ago

yubing744 commented 3 weeks ago

Proposal Details

Background: When developing a game, in order to quickly synchronize the game status, the general strategy of the client is to synchronize the latest status of the game in full, and then synchronize subsequent status changes incrementally. Currently, Rooch supports incremental synchronization of the Object status through tx_order. However, it does not support synchronization of the entire game status. In order to support synchronization of the entire game status, there are two solutions: 1: synchronization through the address of the game contract; 2: synchronization through the game Root object ID.

Expected functions:

  1. Add ParentObjectID filter to SyncStateFilterView of syncStates

Code

pub enum SyncStateFilterView {
    /// Sync by object id.
    ObjectID(ObjectIDView),
    ParentObjectID(ObjectIDView),
    /// Sync all.
    All,
}

Filter logic: Traverse the queried StateChangeSetWithTxOrder, if the recursive Parent Object of ObjectChange matches ParentObjectID, keep it

  1. Add StructTag filter to SyncStateFilterView of syncStates

Code

pub enum SyncStateFilterView {
    /// Sync by object id.
    ObjectID(ObjectIDView),
    StructTagPattern(StrView),
    /// Sync all.
    All,
}

StructTagPattern example: 0x1::::, 0x1::gas_coin::*, 0x1::gas_coin::RGas

Filtering logic: Traverse the queried StateChangeSetWithTxOrder, and keep the embedded StructTag of ObjectChange if it matches StructTagPattern

Parent Issue: https://github.com/rooch-network/rooch/issues/768

wfnuser commented 2 weeks ago

May I have a try on this one?

wfnuser commented 3 days ago

@jolestar I'm still on a vocation. I think I can start on this next weekend (11/30). If it is in a hurry, maybe just assign to some one else. Sorry for that. If it's not, I will try to finish it as soon as possible.