Commit Graph

38 Commits

Author SHA1 Message Date
tomFlowee e4d6528428 Fix off by one. 2023-04-18 09:37:17 +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 5374a50712 Minor cleanups. 2023-03-27 15:16:54 +02: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 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 5f629a161e Let the actions do the assignments of segments.
This removes some code from the connectionmanager / blockchain classes
which assigned a random segment on a new peer.
2022-07-13 13:50:23 +02:00
tomFlowee 0f434e0425 Check file exists before using it. 2022-05-03 18:50:53 +02:00
tomFlowee 7e3e7c2fb7 Fix testing failure 2022-01-24 12:26:37 +01:00
tomFlowee 9c4984dcf7 [P2Plib] Make initial startup 70% faster
What we did previously is load a static chain which was to avoid lots of
work by simply memory-mapping the data instead of inserting it in a
vector.

This improves upon that by also having a metadata file which holds the
block-hashes directly readable. This avoids us having to iterate over
the blockheaders and hashing them.

Additionally we now have a single chain-work field that is the total
amount added work for the headers. This saves us from doing 256-bit
divisions and work for each blockheader as well.

Result is that we make the statup mostly about memory moving and remove
all CPU intensive stuff. Going from 1450ms to 400ms on desktop.
I expect an even greater gain on mobile CPUs.
2022-01-12 19:45:51 +01:00
tomFlowee d79ab0a301 Special case peers that are behind
A peer that is behind is marked as "on a different chain", which is
ultimately correct, but the response to punish or ban them is too much.
We could very well reconnect later when the situation is resolved.

So, detect when a peer is simply behind and respond by disconnecting
without punishment.
2021-11-01 17:19:00 +01:00
tomFlowee 3841257505 Fix possible deadlock.
The new iteration avoids having the blockchain mutex locked when it
calls up to the connection manager (which locks its own mutex).
2021-11-01 15:52:55 +01:00
tomFlowee a5c4a308f4 We reached 700K, pre-allocate more :) 2021-08-09 21:22:25 +02:00
tomFlowee c8a531e6f8 Comments and fix warning
Statics should be PODs.
2021-06-24 19:10:14 +02:00
tomFlowee 460d4be807 Add new method Blockchain::blockHeightAtTime() 2021-05-28 14:52:27 +02:00
tomFlowee c45e7d9c3e [P2P] Do not save blockchain data when not changed 2021-05-27 19:08:46 +02:00
tomFlowee d1fa3fa4a9 [P2P] Allow static loading of blockheaders
This adds a unit test for the Blockchain class in the p2p lib and this
introduces the functionality to have a blockchain pre-shipped with an
app.
2021-05-27 19:08:46 +02:00
tomFlowee ceb44cc3b5 Remove dead code. 2021-02-05 17:26:40 +01:00
tomFlowee 1f2f7c36d2 Port the boost container to the std one.
The unordered_map is now available in stl, and said to be better,
so lets slowly switch over
2021-02-03 16:31:46 +01:00
tomFlowee 5d6d09e4d6 Assign segments only to good peers
Instead of assigning a privacy segment at connect, wait until we have
determined if this peer is on the same chain as us before we allocate a
peer slot.

This also helps us limit the amount of peers we send our bloom filter to.
2021-02-03 14:41:51 +01:00
tomFlowee adfe4081cb Update copyright notice and email address 2021-02-02 13:08:07 +01:00
TomZ 93148976e9 add the checkpoint to p2pnet 2020-11-15 15:27:32 +01:00
TomZ 37e1f2fcd3 Fix bad usage of create_directories() 2020-11-14 23:59:01 +01:00
TomZ 301a4ca3ee Fix properly following the chain-tip
This is done in several steps:

1. Separate my height from the remote peer heights.
Instead of assuming we have one height, recognize that a peer may
not be at the tip at the same time we are. We monitor headers/invs
to update the 'peerHeight' variable.

2. Ask for merkle blocks from a peer to the maximum height of that
peer (but not later than what we validated to be true).
This avoids us asking past the remotes tip which they didn't like.

3. Redo the SyncSPVAction to use all this and make it much more
reliable in finding peers to download from and getting all the
changes as fast as possible.
2020-11-13 21:03:56 +01:00
TomZ 062f62af67 Bugfixes 2020-11-05 21:49:32 +01:00
TomZ e8a2996c84 Persist succesful 'headers' call.
This fixes the issue that a headers call did not get remembered when we
were up-to-date.
2020-11-05 21:48:57 +01:00
TomZ 3f5fe41534 P2PNet: Support multiple chains.
This adds support for the testnet4 chain.
2020-10-29 21:47:53 +01:00
TomZ b89d117475 Add checkpoints after latest protcol upgrade 2020-05-15 17:14:46 +02:00
TomZ ef69014fd2 Upgrade log line 2020-05-13 22:29:23 +02:00
TomZ 2341e4723e P2PNet Make logs easier to read 2020-05-11 20:01:07 +02:00
TomZ 7bfe5e0e2c Provide a getter for blockHeight on Blockchain 2020-05-11 18:07:10 +02:00
TomZ d0bc12ea2d API docs and minor fixes 2020-05-11 17:42:44 +02:00
TomZ 43d7626d46 P2PNet make the blockchain class save its state. 2020-05-11 15:16:59 +02:00
TomZ 010df674e4 P2PNet: Use exceptions and avoid deadlock.
This avoids still having the blockchain lock while calling into the
connectionmanager which may do the reverse, causing deadlock.
2020-05-10 16:02:14 +02:00
TomZ ebbbdcd3a2 P2PNet: log improvement.
Also fix cron disconnecting peers before they connect.
2020-05-10 16:02:14 +02:00
TomZ d49b1ae5e2 Make NetworkManager connections leaner
The NetworkManager usage was mostly for low connection counts and this
made defaults selection easy.
With more usages it is important to allow the NWM-connection to be more
configurable about memory usage and leaner in general.

This changes the headers-buffers (used to create envelopes) to not be per
connection anymore but per thread using the tread_local keyword.

This changes the ring-buffers to become configurable using
NetworkConnections::setMessageQueueSizes().

Also removing some include statements where they were not really needed
in the P2PNet lib.
2020-05-09 20:23:05 +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