Skip to content
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

Fixes in syncer #52

Merged
merged 18 commits into from
Jun 6, 2023
Merged

Fixes in syncer #52

merged 18 commits into from
Jun 6, 2023

Conversation

janekolszak
Copy link
Contributor

@janekolszak janekolszak commented Jun 6, 2023

#40

  • Add timestamp column to sync state

@janekolszak janekolszak merged commit a15202d into main Jun 6, 2023

// Gets L1 (Arweave) interactions from the DB in batches
// Fills in last_sort_key for each interaction before emiting to the output channel
type ArweaveFetcher struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is kinda confusing to me - at first I thought that this code is responislbe for syncing/fetching data from the Arweave nodes.

For me the main purpose of this code is to fill the last sort keys for the already synced L1 transactions - so I would rename it to sth like ArweaveTxLastSortKeyFiller...

err = self.db.Table(model.TableInteraction).
Where("block_height = ?", height).
Where("source=?", "arweave").
Limit(self.Config.Forwarder.FetcherBatchSize).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limit with Offset usually have some performance penalty...can't we simply use limit here and remember the last tx sortKey from the previous batch (and add sortKey > prevBatchLastSortKey condition) - which would allow to use the existing index on the sortKey column.

Transaction(func(tx *gorm.DB) (err error) {
// Get a batch of L1 interactions
err = self.db.Table(model.TableInteraction).
Where("block_height = ?", height).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This again reminds me how I hate ORMs :-) can't we use raw sql queries here? :-)

Limit(self.Config.Forwarder.FetcherBatchSize).
Offset(offset * self.Config.Forwarder.FetcherBatchSize).

// FIXME: -----------------> IS THIS ORDERING CORRECT? <-----------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is correct.

}

if state.FinishedBlockHeight < height {
state.FinishedBlockHeight = height
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow - how do we know at this point that we've processed ALL the L1 interactions for the given height and that FinishedBlockHeight can be safely set?

Shouldn't this be run (maybe it already is - but I don't see that in code) only for interactions from the last batch for the given height? which can be easilly verified (number of returned interactions < limit)

}).
Error
if err != nil {
self.Log.WithError(err).Error("Failed to update stmonitorate after last block")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF stmonitorate is? :-) shouldn't it rather be 'FinishedBlockHeight' or sth similar


// Update last sort key for each contract
for _, interaction := range interactions {
err = tx.Model(interaction).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to make a batch update here? instead of updating each row independently?

// Omit those that are already in the lastSortKeys map
newContractIds := self.getNewContractIds(interactions, lastSortKeys)

// Get last sort key for each contract
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those commens are sometimes kinda misleading :-) not for each, but for each NEW contract.

return self
}

func (self *ArweaveFetcher) run() (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add some sanity check at the end of this function and verify that the newly set sortKey -> lastSortKey sequence is correct...at least for the first few weeks of running this in prod...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants