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

feat: apply view_tag to reduce sync time #32

Merged
merged 13 commits into from
Dec 6, 2022

Conversation

thanhdanh
Copy link

@thanhdanh thanhdanh commented Nov 13, 2022

Summary

One of the most common complaints around using Monero day-to-day is the time that it can take to sync up a wallet before being able to send Monero. It seems important to speed up scan times. I think we can easily reduce the sync timing ~30-40% with 1 additional byte per output; call it the 'view tag’.

The principle is simple (and has likely been suggested before), make a shared secret between the sender and receiver, hash it, then record the first 1 byte in the chain (the view tag). Recipients calculate the shared secret, hash it, and check if it matches any view tags in the tx. If it does match, then continue checking for owned outputs in the normal way. It will only match about 1/256 of the time, so scan time will be primarily a function of checking view tags.

I did many timing tests and saw the difference between before and after applying view_tag. The duration of sync has been reduced around by around 30 -> 40%.

Depending on adding the threadpool module in monero-core-custom

Screenshots

Here is my test when syncing +30k blocks before and after using view_tag

Before

Screenshot 2022-11-14 at 00 10 21

After

Screenshot 2022-11-14 at 00 27 36

@thanhdanh thanhdanh self-assigned this Nov 13, 2022
@thanhdanh thanhdanh added the enhancement New feature or request label Nov 13, 2022
@thanhdanh thanhdanh changed the title Andyvo/apply view tag to reduce sync time feat: apply view_tag to reduce sync time Nov 13, 2022
Copy link

@feri42 feri42 left a comment

Choose a reason for hiding this comment

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

How much of the speed up is due to threading and how much due to view tags. Just wondering why implementing view tags depends on adding threadpool support?

Did I see correctly that we always choose only one thread, so the above question doesn't make sense?

@thanhdanh
Copy link
Author

thanhdanh commented Dec 6, 2022

How much of the speed up is due to threading and how much due to view tags. Just wondering why implementing view tags depends on adding threadpool support?

Did I see correctly that we always choose only one thread, so the above question doesn't make sense?

@feri42 , good question.
I did a performance check about syncing the latest 100k blocks with 2 scenarios:

  1. apply viewTag with parallel batches (~20 mins)

parallel_100k_blocks

  1. apply viewTag without parallel batches. (~20 mins)

100k_blocks

They are pretty much the same as each other. No significant benefit from batching process (parallel handling)

  1. Without view-tag

Screenshot 2022-12-06 at 19 01 18

The duration is ~29 mins

@thanhdanh thanhdanh requested review from feri42 and gutenye and removed request for Sekhmet December 6, 2022 14:48
@feri42
Copy link

feri42 commented Dec 6, 2022

Another question about view tags. Are we able to fetch all transactions using view tags? It it seems to me like sent transactions to different addresses would all have different view tags and during a refresh or an initial scan we do not know all of those view tags. So there are scenarios where we do not fetch all transactions.

@thanhdanh
Copy link
Author

Yes, we must fetch all transactions. We don't know exactly which view-tag belongs to the sender. We have to let the wallet loop for each output of a transaction and then do compare the output's view-tag with the derived view-tag from the sender's keys. This is exactly the way that Monero Wallet is doing.

The view-tag is just the checkpoint to quickly decide to skip some EC operators, and we could reduce ~30% time to sync.

@feri42
Copy link

feri42 commented Dec 6, 2022

Yes, we must fetch all transactions. We don't know exactly which view-tag belongs to the sender. We have to let the wallet loop for each output of a transaction and then do compare the output's view-tag with the derived view-tag from the sender's keys. This is exactly the way that Monero Wallet is doing.

The view-tag is just the checkpoint to quickly decide to skip some EC operators, and we could reduce ~30% time to sync.

Ahh. I see. We look at every transaction. From the transaction we know the sender (?) and once we have the sender we can get the view tag for this sender (sender/recipient). And once we have the view tags we can skip non-matching outputs. Is that it?

1 similar comment
@feri42
Copy link

feri42 commented Dec 6, 2022

Yes, we must fetch all transactions. We don't know exactly which view-tag belongs to the sender. We have to let the wallet loop for each output of a transaction and then do compare the output's view-tag with the derived view-tag from the sender's keys. This is exactly the way that Monero Wallet is doing.

The view-tag is just the checkpoint to quickly decide to skip some EC operators, and we could reduce ~30% time to sync.

Ahh. I see. We look at every transaction. From the transaction we know the sender (?) and once we have the sender we can get the view tag for this sender (sender/recipient). And once we have the view tags we can skip non-matching outputs. Is that it?

@thanhdanh
Copy link
Author

Yes @feri42 , it's correct.

Copy link

@feri42 feri42 left a comment

Choose a reason for hiding this comment

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

utACK

@thanhdanh thanhdanh merged commit 86ff550 into master Dec 6, 2022
@thanhdanh thanhdanh deleted the andyvo/apply-view-tag-to-reduce-sync-time branch December 6, 2022 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants