Commit Graph

1412 Commits

Author SHA1 Message Date
tomFlowee e4d6528428 Fix off by one. 2023-04-18 09:37:17 +02:00
tomFlowee 153f72b5ac Debug output tweaks 2023-04-17 19:25:07 +02:00
tomFlowee a088a7867a Make GetHeaders replies more relevant
Lets avoid just getting empty answers when we are up-to-date.
2023-04-17 19:24:40 +02:00
tomFlowee dbeb0ff32d Wait longer for the 'getaddr'
Peers take a good amount of time to respond, so wait longer before
connecting to a different peer.
We now wait 60 seconds before creating more connections.
2023-04-17 19:22:05 +02:00
tomFlowee 3e2ab7ced7 Don't send notifications of new blocks until we synched 2023-04-17 11:56:50 +02:00
tomFlowee c6302bd7c0 Limit the amount of times we send mempool 2023-04-06 13:32:30 +02:00
tomFlowee 2545060a2f Tweaks some (debug level) logging. 2023-04-05 18:03:37 +02:00
tomFlowee 3becd7aa45 Remove unused log sections and code
Decentralized all things!

But, really, don't put the logging sections for external apps in the
library code.
2023-04-04 15:47:25 +02:00
tomFlowee 508a03139e Simplify the API
This removes a premature optimization where we avoid hashing the header
in the small case that the interface doesn't actually find any useful
transactions in the block.
It hurts others calling this API, though, as they suddenly need access
to the full header instead of just the blockId.
2023-04-04 13:38:51 +02:00
tomFlowee 91d6328eca Fix possibley sync issues. 2023-04-01 22:59:34 +02:00
tomFlowee 5517bb1c8b Add comment. 2023-04-01 22:58:41 +02:00
tomFlowee 805c2d9893 Split out the too-big logging section 'p2pnet'.
This introduces the spv-sync debug section as a child of the p2p lib
logging section.
2023-04-01 22:58:11 +02:00
tomFlowee 764a022b55 Swap debug output for more logical reading. 2023-04-01 22:54:43 +02:00
tomFlowee bff0b1df21 Fix in restart location.
Make sure we continue to the tip as fast as possible (no duplicates) on
sleep or otherwise losing a peer.
2023-04-01 22:54:43 +02:00
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 aa6f0676a3 Docs improvements. Mostly API docs 2023-03-27 15:19:05 +02:00
tomFlowee 2322456465 Add thread-safety for the deque too.
A list of weak-pointers itself is not directly thread-safe, the list
itself needs to be synched too.
2023-03-27 15:17:56 +02:00
tomFlowee 5374a50712 Minor cleanups. 2023-03-27 15:16:54 +02:00
tomFlowee 79ea54183e fixes in comments. 2023-03-25 17:26:24 +01:00
tomFlowee 038e7bc0a5 Add new CMake option 'build_apps'.
To enable this means the buildsystem will build all the applications
as well as the libraries.
Applications are 'hub' / 'txVulcano' / 'indexer' etc.
Default this one is turned off.
2023-03-20 19:50:32 +01:00
tomFlowee 6002803fa4 Add more bannable messages.
Alert:
This has been sunset so long ago, no complient BCH client will (/can) use it.

Protoconf:
This looks like its a BSV message.
2023-02-25 19:38:06 +01:00
tomFlowee 18fed67872 Use known not-bch p2p messages to disconnect
When we receive a known message (currently just avahello) we now
intantly ban and disconnect the peer, no need to
test compliance when they openly greet us saying they are not following
the same chain.
2023-02-25 12:02:19 +01:00
tomFlowee 3fd358be4d Don't ask for addresses from all peers
Make sure we only ask a peer that we know is on our chain.
2023-02-25 11:05:13 +01:00
tomFlowee c6d5bd6336 API Doc addition. 2023-02-25 11:04:19 +01: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 ca58fbad98 Change job-description: ensure connections are made
The job description of this component is to sync a wallet. Its means to
that end is to connect to peers.

Problem is that when we startup and the whole system is already in-sync,
then we forget to connect to peers. (that wasn't in the job description,
it just happened to be done as a sideeffect).

This changes the SyncSPVAction's job description to also make sure that
each wallet has the required number of peers.
2023-02-23 22:40:40 +01:00
tomFlowee af3618f473 Send 'mempool' to all peers
We send a 'mempool' p2p command to a peer after we did a series of
merkleblock downloads.
This code adds the mempool p2p command to be sent to peers that didn't
participate in the merkleblock download and thus get the best out of all
our connected peers.
2023-02-21 20:29:26 +01:00
tomFlowee d2fa084109 Add some comments. 2023-02-20 18:16:58 +01:00
tomFlowee 67e5aaee81 Count disabled peers on load. 2023-02-20 18:15:22 +01:00
tomFlowee 6951a9f13a Add missing reserve() call 2023-01-31 20:29:51 +01:00
tomFlowee 004f957540 Revisit listener interfaces.
Now we have 3 more logically divided interfaces for the listener
pattern (callbacks).

A P2PNetInterface for peers maintainance.
A DataListenerInterface for the sections getting new data.
And last the new  HeaderSyncInterface about the state of the
header-chain (application wide).
2023-01-31 20:29:51 +01:00
tomFlowee 25477cdfa1 Add API docs. 2023-01-31 16:35:29 +01:00
tomFlowee 4f40e861f1 Remove not optional = nullptr. 2023-01-31 16:06:25 +01:00
tomFlowee 1d75226cd6 Add comments 2023-01-30 17:10:12 +01:00
tomFlowee c31ceb3c84 Add docs 2023-01-30 17:10:02 +01:00
tomFlowee a711c38a77 Don't connect when the reconnect is underway
Avoid massive connect storm.
Using the network manager based logger we got into a fun situation where
logging to a remote host caused us to connect and fail, which caused us
to log this failed which made us try to connect and .. etc.
2022-12-20 15:32:58 +01:00
tomFlowee b5b493542b Rework base58 and tests
The unit tests testing base58 encoding were using univalue JSON
parsing, since we deprecatd univalue to be a hub-private lib
this has now been ported to Qts JSON parser.
Which also makes the clunky cmake hack nice to replace with the
QRC files concept.

As I was in there anyway, the base58 methods being global scope
C-style methods has now been fixed by putting them in a namespace.
2022-12-13 11:34:54 +01:00
tomFlowee c63519fa47 Move 3rdparty libraries around.
The leveldb and univalue 3rd party libraries are not installed and
not needed by anyone outside of the Hub.
So move them there, making it easier for 3rd party usage.
2022-12-13 11:34:54 +01:00
tomFlowee 7163605b00 Make sure login messages are sent first
When the client sent a message in the onConnected callback, it managed
to get in front of the login message. This fixes that.
2022-12-03 23:30:01 +01:00
tomFlowee 084aa4090f Cleanup and make nicer, cross-compile to Android.
This brings the developer experience in line with the one in Pay
and we avoid needing a path set to run the self-build executables
from.
2022-11-28 16:09:48 +01:00
tomFlowee 6de770466b Avoid possible references-of-deleted
This sanity check might avoid issues in future code by not assuming a
log channel (or anything it depends on) will avoid using logging at the
moment it is shutting down.
2022-11-25 14:01:05 +01:00
tomFlowee f3fb02a522 Make channel interface available
The manager now has an addChannel() method for anyone wanting to
implement a separate logging channel.
2022-11-24 18:14:14 +01:00
tomFlowee d8fa590547 Add useful overloads 2022-11-23 16:31:29 +01:00
Your Name 0ea51337d2 Minor fixes
Use a simple buffer on stack to read into, instead of a buffer pool.
Small fixes as well.
2022-11-14 13:15:08 +01:00
tomFlowee 4b358543c5 Add unit test for partial blockchain saving. 2022-11-13 15:53:51 +01:00
tomFlowee 46c6febfa1 Make compile on CLANG 2022-11-13 12:20:23 +01:00
tomFlowee 8780f16383 Implement the compressSaveFiles method
Makes the change from yesterday complete: we now
compress all the chunks into one periodically.

This, again, is done with a timeout instead of on-close.
We have 45 seconds as a timeout to balance between need to save and
waiting long enough to get additional headers should it
have been a while since last run.
2022-11-13 12:16:26 +01:00
tomFlowee 06b3d3d491 Save the downloaded block headers into multiple files
This change makes it so that we rely less on the downloaded
blockheader data being only in memory and us saving it when
the client shuts down.
Instead, we save more regularly and we save smaller files
instead of always overwriting the complete downloaded headers.

Having less to save at shutdown is then a happy side-effect.
2022-11-12 23:42:59 +01:00
tomFlowee 64d382b7c4 Add saveData() function to p2p net 2022-11-11 19:25:19 +01:00