-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Silent payment index (for light wallets and consistency check) #28241
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
I'd like to keep this based on #28122 but that requires some refactoring there. See #28122 (comment). |
you can also rebase on #27827 , which has everything, or just the receiving PR. Might be easier then to reason about which functions belong in which PRs if we can see it all together. I think the functions you need are introduced in the receiving PR (#28202) |
I'll take a stab at rebasing on the bigger thing. It makes sense to do that and then unrebase / debase(?) it later. |
c23e4e7
to
d589099
Compare
I ended up "borrowing" some code from the followup PRs, without having to rebase on them. This code compiles and the index doesn't crash. That's about the extend of it though :-) For now. |
d589099
to
92897d6
Compare
92897d6
to
ea825ae
Compare
Hi, I have a little question about the motivation for making this index in Core. Afaiu, an implementation of electrum server (or any light client backend) could construct this index as easily, and I think it would be better separation of concerns to let them take responsibility for this instead of Core. Or maybe it's necessary for the consistency check you're mentioning? I'm not sure of what it is. |
@Sosthene00 I find it useful to have this index for developing and reviewing the silent payment implementation. But as you say, it may not be worth merging eventually. I'm not sure about that yet. There's also the possibility of building something like this on top of the Kernel, when that project is a bit further along. |
ea825ae
to
4a7dccb
Compare
Rebased to use |
Pushed a simple RPC method to get the tweaked public key for a given transaction. I'd like to sanity check it against some other implementation. Signet: dacb55db5c506a34771bf8ac3664e2510c17e80ada81347300fb4223f2d6c545
|
🚧 At least one of the CI tasks failed. HintsMake sure to run all tests locally, according to the documentation. The failure may happen due to a number of reasons, for example:
Leave a comment here, if you need help tracking down a confusing failure. |
🐙 This pull request conflicts with the target branch and needs rebase. |
Personally I think Electrum is for SPV wallet things. Silent Payments would be considered part of a full node and not just an SPV thing. That is why I would think it makes it worthy of being in bitcoind. |
return std::nullopt; | ||
} | ||
|
||
bool MaybeSilentPayment(CTransactionRef &tx) { |
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.
bool MaybeSilentPayment(CTransactionRef &tx) { | |
bool MaybeSilentPayment(const CTransactionRef &tx) { |
|
||
BIP352Index::~BIP352Index() = default; | ||
|
||
bool BIP352Index::GetSilentPaymentKeys(std::vector<CTransactionRef> txs, CBlockUndo& block_undo, tweak_index_entry& index_entry) |
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.
bool BIP352Index::GetSilentPaymentKeys(std::vector<CTransactionRef> txs, CBlockUndo& block_undo, tweak_index_entry& index_entry) | |
bool BIP352Index::GetSilentPaymentKeys(const std::vector<CTransactionRef>& txs, const CBlockUndo& block_undo, tweak_index_entry& index_entry) const |
{ | ||
assert(txs.size() - 1 == block_undo.vtxundo.size()); | ||
|
||
for (uint32_t i=0; i < txs.size(); i++) { |
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.
Compare apples to apples and also use idiomatic pre-increment to avoid a temporary in unoptimized builds.
for (uint32_t i=0; i < txs.size(); i++) { | |
for (size_t i = 0; i < txs.size(); ++i) { |
assert(txs.size() - 1 == block_undo.vtxundo.size()); | ||
|
||
for (uint32_t i=0; i < txs.size(); i++) { | ||
auto& tx = txs.at(i); |
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.
at
unnecessary here (and in various places below).. since i
is guaranteed to be in-range, since the loop is looping on txs.size()
.
CTxUndo undoTX{block_undo.vtxundo.at(i - 1)}; | ||
std::map<COutPoint, Coin> coins; | ||
|
||
for (uint32_t j = 0; j < tx->vin.size(); j++) { |
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.
Apples to apples, and also use pre-increment.
for (uint32_t j = 0; j < tx->vin.size(); j++) { | |
for (size_t j = 0; j < tx->vin.size(); ++j) { |
const CCoinsViewCache& coins_cache = m_chainstate->CoinsTip(); | ||
|
||
uint32_t spent{0}; | ||
for (uint32_t i{0}; i < tx->vout.size(); i++) { |
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 loop index shadows an outer variable i
. Also should be using size_t
here.
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.
I'll fix this in Sjors#86
Ah ok I can review/comment there too. Thanks for the tip. |
⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
Closing this for now, given after a year and a half it's still a draft, based on a draft, based on another PR that is still being worked on. Maybe a new PR can be opened in future. |
This PR adds an index with the silent payment tweak for every transaction. It builds on top of #28122. Supersedes #24897.
Usage:
bitcoind -bip352index
The index does not have wallet dependencies, so it can be built with
--disable-wallet
.It also adds a
getsilentpaymentblockdata
RPC that returns an array of silent payment tweaked public keys, one for each qualifying transaction.This index serves two purposes:
TODO:
-bip352ctindex
)