-
Notifications
You must be signed in to change notification settings - Fork 573
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
Fast construction of Transaction
when reading from the chain db
#5078
Fast construction of Transaction
when reading from the chain db
#5078
Conversation
e9cd83a
to
6107b89
Compare
cda90fb
to
6a9d58f
Compare
6107b89
to
9ada9d8
Compare
6a9d58f
to
c5bf574
Compare
9ada9d8
to
f22f92c
Compare
c5bf574
to
94f12e5
Compare
f22f92c
to
bf4472f
Compare
94f12e5
to
10cd266
Compare
d8dffe5
to
3e9976f
Compare
8a381ed
to
6679059
Compare
3e9976f
to
1839dab
Compare
6679059
to
8d1f93e
Compare
1839dab
to
5bc24e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me 👍
I wonder if it's possible, or desirable, to enforce that we only skip validation when deserializing from stored values.
I think it may be hard to have a general rule like that for skipping validation, but I do wonder about how we can ensure that validation always happens somewhere.
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
import { Transaction } from '../../primitives/transaction' | ||
|
||
function areTransactionsEqual(a: unknown, b: unknown): boolean | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this used as part of these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, implicitly, whenever you call expect(...).toEqual
on something that has a transaction in it
Yes, I think it's both possible and desiderable. This could even be done using types, so that mistakes would be caught at build time. |
8d1f93e
to
8c16d8d
Compare
Transactions that contains mints involve parsing assets, which in turn involve parsing public addresses of the owner for those assets. Parsing a public address is currently an expensive operation, because it involves elliptic curve point multiplications. Transactions containing mints are therefore harmful for the performance of wallet scans. To improve the performance of wallet scans, this commit: - introduces a new `PublicAddress::new_unchecked` (in Rust) constructor that speeds up construction of public addresses from trusted input; - adds a `skipValidation` parameter to `Transaction` (in TypeScript) to allow using the "unchecked" variants of constructors; - changes the chain db deserializer to read transactions using `skipValidation: true`. Note that, while the goal of this commit is to improve wallet scan performance, the impact of this commit is actually broader: it impacts all reads from the chain db. This is good for performance, but may be a concern for security and stability. The assumption is that if something is stored in the chain db, then it was previously validated and therefore it can be trusted.
5bc24e7
to
bcbaa5f
Compare
Summary
Transactions that contains mints involve parsing assets, which in turn involve parsing public addresses of the owner for those assets. Parsing a public address is currently an expensive operation, because it involves elliptic curve point multiplications.
Transactions containing mints are therefore harmful for the performance of wallet scans.
To improve the performance of wallet scans, this commit:
PublicAddress::new_unchecked
(in Rust) constructor that speeds up construction of public addresses from trusted input;skipValidation
parameter toTransaction
(in TypeScript) to allow using the "unchecked" variants of constructors;skipValidation: true
.Note that, while the goal of this commit is to improve wallet scan performance, the impact of this commit is actually broader: it impacts all reads from the chain db. This is good for performance, but may be a concern for security and stability. The assumption is that if something is stored in the chain db, then it was previously validated and therefore it can be trusted.
Testing Plan
ironfish-rust-nodejs
withyarn build:stats
(see Add a development-only feature to print statistics related to notes encryption #5074)yarn start wallet:rescan
wallet:rescan
process. Observe that the number of note decryptions and the number of elliptic curve point multiplications match (i.e. there are no additional multiplications performed)Documentation
N/A
Breaking Change
N/A