1
0

12 Commits

Author SHA1 Message Date
SomberNight
c2e8188568 tests: test_network: add more header chain resolution test cases 2025-06-09 20:31:05 +00:00
SomberNight
eb69b6b516 interface: _search_headers_backwards: start at small delta
- interface.tip is the server's tip.
- consider scenario:
  - client has chain len 800_000, is up to date
  - client goes offline
  - suddenly there is a short reorg
      e.g. blocks 799_998, 799_999, 800_000 are reorged
  - client was offline for long time, finally comes back online again
  - server tip is 1_000_000, tip_header does not connect to client's local chain
  - PREVIOUSLY before commit, client would start backwards search
    - first it asks for header 800_001, which does not connect
    - then client asks for header ~600k, which checks
    - client will do long binary search to find the forkpoint
  - AFTER commit, client starts backwards search
    - first it asks for header 800_001, which does not connect
    - then client asks for header 799_999, etc
- that is, previously, on average, client did a short backwards search, followed by a long binary search
- now, on average, client does a longer backwards search, followed by a shorter binary search
  - this works much nicer with the headers_cache
  (- and thomasv said the old behaviour was not intentional)
2025-06-09 19:34:37 +00:00
SomberNight
02c6e118f0 tests: test_network: intro MockBlockchain. rewrite tests to use it.
interface.py no longer has knowledge about mocking! :P
2025-06-09 19:34:34 +00:00
SomberNight
cb1789a59c tests: test_network: try to explain test cases
no functional changes
2025-06-09 17:57:36 +00:00
SomberNight
09e412baf8 tests: enable verbose stderr logging
note: print() statements and stderr logging don't have a consistent printing order.
Either can buffer log lines and flush them later, and the buffers are independent.
2025-06-09 17:40:27 +00:00
SomberNight
ffb12b2833 tests: test_network: shorten lines 2025-06-09 17:22:49 +00:00
SomberNight
9016c36df0 tests: test_network.py: rm test_fork_conflict, no longer applicable
Just prior to this commit, test_fork_conflict and test_fork_noconflict were essentially identical copies.
The only diff was that test_fork_conflict set the global blockchain.blockchains,
but this was not even affecting its behaviour anymore.

Originally when this test was added, we had the concept of chain fork conflicting with each other:
we could not handle three-way chain-splits. As in, there could only be a single fork forking away
from the main chain at any given height.
see 7221fb3231

However, this restriction was removed and generalised later:
141ff99580
After which the "test_fork_conflict" test did not make sense anymore.
2025-06-09 15:46:02 +00:00
SomberNight
dbb9673139 interface: faster chain resolution: add headers_cache
We try to predict the next headers the interface will ask for,
and request them ahead of time, to be kept in the headers_cache.

This saves network latency/round-trips, for a bit more memory usage
and in some cases for more bandwidth.
Note that due to PaddedRSTransport.WAIT_FOR_BUFFER_GROWTH_SECONDS,
latency saved here can be longer than "real" network latency.

This speeds up
- binary search greatly,
- backwards search to a small degree
  (although not that much as its algorithm should be changed a bit to make it cache-friendly)
- catch-up greatly, if it's <10 blocks behind

What remains is to speed up catch-up in case we are behind by many thousands of block.
That behaviour is left unchanged here. The issue there is that we request chunks sequentially.
So e.g. 1 chunk (2016 blocks) per 1 second.
2025-06-09 15:36:04 +00:00
SomberNight
27599ac537 interface: small clean-up. intro ChainResolutionMode.
- type hints
- minor API changes
- no functional changes
2025-06-06 16:42:15 +00:00
Sander van Grieken
f4520b9e0d network: use TOR stream isolation
also refactor, for proxy instantiation, use Network instance, not a proxy dict.
2024-10-25 01:10:58 +02:00
SomberNight
1257f21b1b constants: rm set_testnet/set_mainnet fns with AbstractNet.set_as_network 2024-09-16 15:27:45 +00:00
Sander van Grieken
73fee69f5c tests: move /electrum/tests to /tests 2024-02-16 15:40:45 +01:00