Commit Graph

18 Commits

Author SHA1 Message Date
tomFlowee 1d309cd7ae P2PNet: re-do SVP's bloom filter and mempool.
Every peer that we connect to should get the bloom filter set and it
should also get the 'mempool' call sent once which will make that peer
respond with all matches of the bloom filters which are in the mempool.

The tricky part is that we should have the latest bloom filter set on
each of those peers before the mempool is sent, since they work
together.
Also if we are behind, the mempool should not be sent. (It can cause
problems in the wallet if we receive unconfirmed transactions before
mined transactions)

So, when a peer starts downloading merkle blocks, the bloom filter of all
the other peers becomes invalid the moment a match is found by an actual
wallet.
This is Ok on one peer because the merkleblock automatically updates the
filter on match on the server side, but obviously not on the other peers
we have for that wallet.

The approach we follow is that as soon as a sync-run is done on a single
peer (we do a main and also a backup sync), we tell the wallet to re-
build its bloom filter for _all_ peers and if the sync that peer did
leads us to be at the chain-tip, we also send each peer the mempool
command.
2023-04-01 22:54:35 +02:00
tomFlowee 2c0e0bad75 Update SyncChainAction to present day concepts
When the SyncChainAction was written, various interactions we do
today in the ConnectionManager did not happen yet. Features in
Peer didn't exist yet.

This updates the SyncChainAction to take those items into account
and be more responsive and conclue we are 'up to date' faster,
while also leaving behind a better state.
2023-03-27 15:20:50 +02:00
tomFlowee 70e4f2292e Refactor the SPV merkleblock/mempool sending
Tuesdays idea of adding some code into the SyncSPVAction didn't feel
right.
A second look made clear that bloom filter updates make much more sense
to go hand in hand with sending a mempool message. Especially since they
depend on each other on the server side.

To-rehash:
the wallet may decide at any time that a new bloom filter is needed. It
then uses the superclass (code in p2plib) PrivacySegment, to build that
filter. As part of that we get a lock object which, when going out of
scope, makes the peers that are subscribed to the privacySegment send
out the filter.

This separation of concerns means that the subclass wallet in the app
doens't know about peers or messages, only its superclass PrivacySegment
does.

What we did in this change is make the PrivacySegment class decide to
combine a bloom update with a mempool call. Typicall only once per
connection.

This means I can remove hacks in the SyncSPVAction which forced the
sending of the mempool message separately.
2023-02-24 19:41:42 +01:00
tomFlowee 4f40e861f1 Remove not optional = nullptr. 2023-01-31 16:06:25 +01:00
tomFlowee c31ceb3c84 Add docs 2023-01-30 17:10:02 +01:00
tomFlowee 3ed5b1117f Fixlet in comment 2022-08-17 19:28:42 +02:00
tomFlowee c33d54ed7d Rename class CKeyID -> KeyId 2022-07-06 21:52:47 +02:00
tomFlowee e17ba3bc58 Add a property 'enabled' on PrivacySegment
A not-enabled PrivacySegment will not have its merkleblocks downloaded.
2022-06-23 23:17:05 +02:00
tomFlowee 512d49785a Pass enum by value 2022-04-05 22:13:55 +02:00
tomFlowee 0e6f2bec29 Add 'Last' priority. 2021-07-30 14:03:29 +02:00
tomFlowee ccb1016ac7 Avoid deep-copying a bloomfilter when possible. 2021-05-27 19:08:46 +02:00
tomFlowee adfe4081cb Update copyright notice and email address 2021-02-02 13:08:07 +01:00
TomZ 4b0bcf7bc9 Add priority to privacySegment
We connect to the "first" priority stated segments first, in order to
allow the UX to be made much better since it may take a bit of time to
find peers.
2020-10-19 14:04:57 +02:00
TomZ cf01da9164 API review: privacySegment
The uint256 and CKeyID classes are the same baseclass with template
differences only, which makes them fragile to use for overloading.

As such rename the convenience overload slightly.
2020-06-07 13:56:55 +02:00
TomZ cde1372b2e Make PrivacySegment emit signals
this adds a listener interface and a way to emit the callbacks on
changing of the filter.

This also adds a mutex since we expect the Peer to use the filter which
will likely live in its own thread.
This makes the class thread safe and re-entrant.

Notice that we use a recursive mutex to allow various usecase on
altering the bloom filter.
The most involved one is a complete replacement which calls clear and
then various calls to add() style methods.
Second is a single 'add' which can be done without the clear first.

The second needs an explicit lock in the add() methods, which would
deadlock in the first usecase if I didn't pick the recursive mutex.
2020-05-18 14:25:14 +02:00
TomZ 01e8bcfb09 Announce all transactions per block at once.
Instead of forwarding one transaction at a time as the peer sends them
to us, bundle them in a group of transactions known to be merkle-checked
and all belonging together in one block.

Since the peer has no obligation (and with CTOR even less) to send the
transactions in natural order, we should get them per block so we know
all transactions forwarded have parents.
2020-05-16 11:01:27 +02:00
TomZ c2d53d75e4 Add some extra methods on the privacySegment
this allows more mature usage of the bloom filter.
2020-05-15 17:18:42 +02:00
TomZ 25ffc84f80 Introduce new lib p2p
We reuse the NetworkManager lower level code in order to connect
to the Bitcoin P2P network.
This implements the basics for anyone wanting to be a player on
this network.
2020-04-20 21:49:03 +02:00