-
Notifications
You must be signed in to change notification settings - Fork 992
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
Kernel lookup api method #3000
Kernel lookup api method #3000
Conversation
Why not index these in lmdb? |
We do this for outputs. There is also a related PR #2903 that proposes storing the height per output in lmdb. We came to the conclusion in previous conversations that -
So given the tradeoff between storage costs for lots of kernels and slower lookups - we erred on the side of slower lookups. We are comfortable maintaining an index of all unspent outputs in lmdb as the UTXO set will not grow indefinitely. That said - a given node probably has a reasonable idea of which kernels it is interested in locally. so it may make sense to store/cache these in lmdb based on prior access. |
Thinking a bit more about this. I'm torn about the "index or not to index" question. |
Couple of things (that ties in with a few thoughts I've had on wallet improvements)
|
@antiochp Hmm I hadn't considered the relative kernel locks usecase. But even then increasing the storage requirement of kernels by ~40% might be a lot, especially since we can never prune them. Do you want me to already accomodate for this usecase? That means moving some of the logic into the @yeastplume Right, the kernel lookup would only be used for unconfirmed transactions, not for restores as they happen on the output level rather than the tx level.
Yes, I think incremental scanning of the utxo set is a good idea anyway. But I'm not sure if checking the tx confirmation status by looking at the presence of the inputs in the utxo set is ideal. If the user is using the seed on multiple different wallets at the same time, it could happen that the wrong tx gets marked as confirmed. |
Yep, agreed that kernel lookup is the best way to confirm transactions, we can get this implemented then look at incremental scanning as a near-term improvement. |
Do we want to always scan backwards through the MMR? Presumably if we are confirming txs they will be younger txs, present in more recent blocks? |
I'm not sure I follow what you are saying here - you mean in terms of the lmdb index/storage (if we stored the index in the db)? |
Makes sense, will change it. |
Yes if we store an index we'd need 40% more storage per kernel. Thinking about it some more, a malicious user could significantly slow down initial sync by creating lots of relative lock height kernels that rely on very old kernels. What if we only create the index during initial sync and delete it afterwards? |
Yeah I think there may be reasons why we would want to temporarily create an index during initial sync. But I don't think we want to assume this index is available for general usage after sync. I would not be overly concerned about supporting relative kernels today - we can optimize initial fast sync later as you suggest. We don't want to add 40% to the permanent storage costs today in anticipation of something that may be very rare. |
Same here :-) My left hand vote Yes for index but right hand vote for No index 😸 There could be a middle way on this:
The fast indexed kernel querying will cover 99% transaction status querying requirement, since in most cases people will query status immediately (or at least in two days) after a transaction posted. (As reference, here is my trying on a pure indexing solution: gottstech#3 and gottstech#13. if working as a wallet service backend, the config item |
@jaspervdm Is this ready for final review? |
@antiochp I think it is! I just updated the description to reflect the latest changes. |
@@ -260,6 +260,29 @@ impl TxHashSet { | |||
.elements_from_insertion_index(start_index, max_count) | |||
} | |||
|
|||
/// Find a kernel with a given excess. Work backwards from `max_index` to `min_index` |
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 might make more sense in the rewindable_kernel_view
(rather than the txhashset
).
Maybe a separate PR to refactor this.
Looks pretty fast to me. This is the coinbase kernel for the genesis block -
|
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 PR adds an API call to look up an on-chain kernel and the height of the block it is included in.
It has an optional minimum search height. If provided (and close to the actual height), the request will be really fast (<10ms). Without this parameter the request can currently take up to 2.5s. Seeing as in the worst case scenario this time will increase linearly with the chain head height (which keeps increasing forever), it is recommended to always set the minimum height parameter.
Requesting review from @antiochp since I am not very experienced with MMRs and as a result some implementation details might be sub-optimal.
Closes #2460
Use cases:
Usage:
v1/chain/kernels/XXX?min_height=YYY&max_height=ZZZ
whereXXX
is the excess commitment. Themin_height
andmax_height
parameters are both optional. If not supplied,min_height
will be set to 0 andmax_height
will be set to the head of the chain. The method will start at the block heightmax_height
and traverse the kernel MMR backwards, until either the kernel is found ormin_height
is reached.Example:
Request:
Response: