-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: remove steps from StateSync
interface
#709
base: tomyrd-sync-component-alt
Are you sure you want to change the base?
Conversation
Not a review (I haven't really looked at the code) - but to make a few comments:
Why is this necessary? Could the
What exactly do we need to check in the store? Can this info be pre-loaded into the |
This can be done. It would move the responsibility of dealing with intermediate updates from the callback to the component itself. The only issue I see with this is that the callback wouldn't be called for every event, just those for which the component doesn't already have the internal version and need to be queried from the store. If we wanted users to be able to react to certain events with the callbacks, this would limit that ability, as it's not called for every instance. Also, this would create some code duplication but I don't think it would be very much as some of it can be moved to helper functions.
The |
Regarding this part:
@igamigo mentioned we could use an |
An update on some of the ideas mentioned earlier today:
I wasn't able to use RefCell because it isn't send+sync so I ended up using a RwLock instead. The chages for this are isolated in commit 174c995 so it can be reverted if we don't like it.
The note checker also uses the store to check that the account contains the necessary assets to consume a swap note, we don't have access to this information inside the |
I think we should try to go this route. There are only two things that can happen during state sync: we get a committed note or a note gets nullifies. I think state transitions for these are pretty straight forward (unless I'm missing something, of course).
Shouldn't the note checker be run inside the note handling callback? |
I think it would be possible, I can move the block relevance check to the |
6993159
to
c1fe5fa
Compare
Update: in c1fe5fa I ended up merging the callbacks as mentioned above. The callback interfaces changed a bit because they now need some extra information about the sync response to decide the correct state changes. I think it looks cleaner now which is good! Tomorrow, I'll look into changing the way we pass the entire |
This version is still a WIP.
The idea is to remove the sync steps from the interface of the
StateSync
so that the user doesn't have to deal with them and the sync is shown as a single step process.After some bug fixing, the rust tests are passing so this version works! It's a bit messy and the documentation is now outdated. Will be working on this next but the main changes can be discussed:
Main changes
The main change with this new functionality is that we relied on store to persist the updates on each step but if we remove the steps, we need to store the intermediate states of notes on each step and update them accordingly without storing them. The changes made in
state_sync.rs
can be summarized as:NoteUpdates
: Instead of being 4 vectors of notes, now it's 2 maps (one for input and another for output notes). This means that it is better for retrieving the state of a specific note. Additionally, a newinsert_or_ignore
is used to add the state in the store (before starting the sync process) to the note update, if the note is not tracked in the update it is inserted but if it's tracked (meaning that it was modified in a previous step) then it is ignored.NoteUpdates
with the state of changed notes since the start of the sync process. The callbacks use theinsert_or_ignore
to add notes if needed and then apply the state changes to theNoteUpdates
to update it with the new event. The updatedNoteUpdates
is returned.NoteUpdates
? This was my first approach but there are problems with the lifetimes of the closures and the received references. In theory it wouldn't be a problem as both lifetimes are the same but the rust compiler can be sure of this and will doesn't like the references in the closure.BlockUpdates
: Now aSyncStateUpdate
represents an update after multiple steps, so it may contain multiple new block headers. All of the data related to each new block is stored in a newBlockUpdates
struct.OnBlockReceived
callback: This callback was added to deal with the arrival of each new block. It is used to have a store access to check the relevance of each block received. The component in general still doesn't have access to the store so this callback is needed.