997 Commits

Author SHA1 Message Date
Arnaud
c80d44ff93
fix: update discovery isStarted flag during the stop (#1347) 2025-11-14 04:19:18 +01:00
Arnaud
16d44d038a
fix: close the discovery store (#1346) 2025-11-14 04:07:24 +01:00
Arnaud
5a227dbb56
fix: parse config using int for NBytes instead of string (#1344) 2025-11-11 07:25:45 +01:00
Eric
4006b0024b
fix: undeclared identifier 2025-11-11 12:05:09 +11:00
Eric
e47186db90
fix: decrease block retry count when no peers found
There is a limitation in `downloadInternal` that infinitely loops for peers when attempting to download a block if the node does not have peers. Currently, the block retry counter is only decremented if there exists peers and a download attempt is made, otherwise the loop will continue until peers are found, ad infinium. This fix decrements the retry counter on each loop that no peers are found.
2025-11-11 12:04:50 +11:00
Eric
46413c8dff
catch CancelledError in BlockExchange 2025-11-10 21:03:24 +11:00
Eric
b701e08a56
Merge branch 'feat/simple-optimizations-rebase' into release/1.0.0-prototype.1 2025-11-07 14:42:41 +11:00
Chrysostomos Nanakos
8257406e82
refactor(blockexchange): extract batched want list sending to helper proc
Part of https://github.com/codex-storage/nim-codex/issues/974

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
2025-11-03 17:24:03 +02:00
Chrysostomos Nanakos
86ce276a90
fix(blockexchange): cleanup stale lastSentWants entries to prevent memory leak
Stale entries in peer.lastSentWants were not removed when blocks were
resolved or cancelled, causing unbounded memory growth. This adds
incremental cleanup during refreshBlockKnowledge, removing up to 2048
stale entries per refresh cycle with proper event loop yielding.

Part of https://github.com/codex-storage/nim-codex/issues/974

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
2025-11-03 16:49:31 +02:00
Chrysostomos Nanakos
ff7ac829c4
fix(blockexchange): handle evicted peer in download retry loop
Part of https://github.com/codex-storage/nim-codex/issues/974

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
2025-11-03 14:10:57 +02:00
Chrysostomos Nanakos
ad4d3b5d62
feat(node): implement sliding window for block prefetching
Now fetchBatched maintains a sliding window of batchSize blocks in-flight.
When 75% complete, adds next chunk to maintain constant window size.
This ensures blocks are already pending or have been fetched when
StoreStream needs them.

Part of https://github.com/codex-storage/nim-codex/issues/974

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
2025-11-03 14:10:55 +02:00
Chrysostomos Nanakos
aea9337ddc
feat(blockexchange): implement delta WantList updates with batching
Implements delta-based WantList updates to reduce network traffic during
block exchange. Only sends newly added blocks instead of resending the
entire WantList on every refresh.

Also some network related fixes:

- Add TCP_NODELAY flag to prevent Nagle's algorithm delays
- Clear sendConn on stream reset to allow garbage collection
- Improve error handling in NetworkPeer.send()

Part of https://github.com/codex-storage/nim-codex/issues/974

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
2025-11-03 14:10:55 +02:00
Chrysostomos Nanakos
6f378b3c46
perf: add time-based yielding to hot loops
Part of https://github.com/codex-storage/nim-codex/issues/974

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
2025-11-03 14:10:54 +02:00
Chrysostomos Nanakos
f7a3e90414
refactor: remove makeRandomDataset helper function
Remove makeRandomDataset in favor of direct composition with
makeRandomBlocks and makeDataset.

Part of https://github.com/codex-storage/nim-codex/issues/974

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
2025-11-03 14:10:53 +02:00
Chrysostomos Nanakos
8812d98271
fix: assign selectPeer field in BlockExcEngine ctor
Part of https://github.com/codex-storage/nim-codex/issues/974

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
2025-11-03 14:10:53 +02:00
Chrysostomos Nanakos
6efdd4a068
chore: apply nph formatting
Part of https://github.com/codex-storage/nim-codex/issues/974

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
2025-11-03 14:10:52 +02:00
Chrysostomos Nanakos
0636adf5e8
refactor: make markRequested idempotent
Returns false on duplicate marking attempts instead of logging errors,
eliminating duplicate marking loop in blockPresenceHandler and
preventing duplicate block requests across concurrent flows.

Part of https://github.com/codex-storage/nim-codex/issues/974
2025-11-03 14:10:51 +02:00
Chrysostomos Nanakos
dddf7424b4
fix: resolve stuck peer refresh state preventing block discovery
This prevents peers from becoming permanently invisible to block discovery when
they fail to respond to WantHave requests.

Part of https://github.com/codex-storage/nim-codex/issues/974
2025-11-03 14:10:50 +02:00
Chrysostomos Nanakos
4abe8c4d97
feat: add strategic runtime metrics for block exchange monitoring
- Add codex_block_exchange_discovery_requests_total counter to track peer
  discovery frequency
- Add codex_block_exchange_peer_timeouts_total counter to monitor peer
  reliability issues
- Add codex_block_exchange_requests_failed_total counter to track request
  failure rates

Part of https://github.com/codex-storage/nim-codex/issues/974
2025-11-03 14:10:49 +02:00
Chrysostomos Nanakos
9af510316a
perf: optimize block batch size from 500 to 50 blocks per message
Achieves significant memory reduction with equivalent network
performance. The reduced batch size prevents memory pressure
while preserving transfer efficiency, improving overall system
resource utilization.

Part of https://github.com/codex-storage/nim-codex/issues/974
2025-11-03 14:10:49 +02:00
Chrysostomos Nanakos
b9fe7dce58
feat: add peer count limits to discovery engine
This prevents unbounded peer accumulation while maintaining redundancy.
When peer count exceeds the maximum, the least active peers are removed from
tracking to free resources.

Part of https://github.com/codex-storage/nim-codex/issues/974
2025-11-03 14:10:48 +02:00
Chrysostomos Nanakos
2fdf234c9d
perf: optimize further fetchBatched
- Reduce DefaultFetchBatch to prevent blockData explosion
- Add chunked onBatch processing to prevent memory accumulation
- Implement memory buffer reuse to reduce GC allocation churn
- Fix short-circuit evaluation

Part of https://github.com/codex-storage/nim-codex/issues/974
2025-11-03 14:10:47 +02:00
Chrysostomos Nanakos
0fbca17269
feat: implement weighted random peer selection for load balancing
Use probabilistic distribution based on peer quality scores, giving all peers
opportunity while favoring better-performing ones. Selection probability is
inversely proportional to score.

Part of https://github.com/codex-storage/nim-codex/issues/974
2025-11-03 14:10:46 +02:00
gmega
8e8d9f8e60
fix: randomize block refresh time, optimize context store checks 2025-11-03 14:10:46 +02:00
gmega
1fdb14f092
feat: add block knowledge request mechanism, implement tests 2025-11-03 14:10:45 +02:00
gmega
9114a620a3
feat: add stopgap "adaptive" refresh 2025-11-03 14:10:44 +02:00
gmega
908d527dc9
fix: fix testdiscovery so it works with stricter block protocol 2025-11-03 14:10:44 +02:00
gmega
544ec123c7
fix: fix block exchange test to stricter protocol; minor refactor 2025-11-03 14:10:43 +02:00
gmega
50ab785662
feat: drop peer on activity timeout 2025-11-03 14:10:42 +02:00
gmega
d91fd053e7
feat: modify retry mechanism; add DHT guard rails; improve block cancellation handling 2025-11-03 14:10:42 +02:00
gmega
38a0656cab
chore: remove file committed by accident 2025-11-03 14:10:41 +02:00
gmega
d875022ec3
feat: allow futures to be returned out-of-order to decrease memory consumption 2025-11-03 14:10:40 +02:00
gmega
d0466ccf80
feat: remove quadratic joins in cancelBlocks; use SafeAsyncIterator for getBlocks; limit memory usage for fetchBatched when used as prefetcher 2025-11-03 14:10:39 +02:00
gmega
cc44052cf5
feat: add SafeAsyncIter chaining 2025-11-03 14:10:39 +02:00
gmega
b0b1c45376
fix: refresh timestamp before issuing request to prevent flood of knowledge updates 2025-11-03 14:10:38 +02:00
Giuliano Mega
b58a92d1f9
Update codex/stores/networkstore.nim
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: Giuliano Mega <giuliano.mega@gmail.com>
2025-11-03 14:10:37 +02:00
gmega
5a983347cb
adapt existing tests to new data structures, remove vestigial tests 2025-11-03 14:10:36 +02:00
gmega
3c43d57497
optimize remaining list joins so they're not quadratic 2025-11-03 14:10:36 +02:00
gmega
096eb118f9
replace list operations with sets 2025-11-03 14:10:35 +02:00
gmega
9088566632
update engine tests; add BlockAddress hashing tests 2025-11-03 14:10:34 +02:00
gmega
1135a513d4
feat: cap how many blocks we can pack in a single message 2025-11-03 14:10:33 +02:00
gmega
475d31bef2
feat: add dataset request batching 2025-11-03 14:10:31 +02:00
Arnaud
480bd3b659
Fix missing res 2025-11-03 23:06:58 +11:00
Arnaud
40d2715bac
Add comment 2025-11-03 23:06:58 +11:00
Arnaud
2277729bad
Add exists in lib 2025-11-03 23:06:57 +11:00
Arnaud
58d964bea6
Prevent double start issue 2025-11-03 23:06:57 +11:00
Arnaud
b79a844030
Prevent seg fault when trying to close the discovery while it was not started 2025-11-03 23:06:57 +11:00
Arnaud
58b8676d3e
Fix missing return statement 2025-11-03 23:06:57 +11:00
Arnaud
d9f53d0056
Prevent error when the error message is empty 2025-11-03 23:06:57 +11:00
Arnaud
fbd466b4cd
Do not wait the bridge when destroying the codex node 2025-11-03 23:06:57 +11:00