Commit Graph

7640 Commits

Author SHA1 Message Date
lunar-mining
818ceaec4d store: don't remove from greylist or whitelist on anchorlist upgrade
because of the refinery running in the background, if we remove a peer
from the white or greylist on upgrade it can create an index error in
when seperate threads execute this code at the same time:

refinery:
    upgrades node to whitelist, removes from greylist

upgrade_host:
    upgrades node to anchorlist, removes from greylist

leaving a "safe" peer on the grey or whitelist is not a problem. the
only impact is that we risk selecting a peer from the whitelist that we
are already connected as an anchor, but p2p checks exist to protect
from this.

equally, if we remove from the greylist or whitelist on upgrade_host this can
happen:

upgrade_host:
    upgrades node to anchorlist, removes from greylist

protocol_addr:
    recv Addr
    do we have this node? no, add to greylist
    refinery: promotes to whitelist, etc

the above scenario makes removing the host in this case redundant.
2024-01-18 13:51:34 +01:00
lunar-mining
deb3ea5936 net: cleanup warnings + run make clippy 2024-01-18 13:17:51 +01:00
lunar-mining
fed0e582c1 net: bug fixes and cleanup
* move upgrade_host() and downgrade_host() to store.rs
* don't downgrade disconnected inbound connections
* fix logic error (missing else clause) on [hostlist]_store_or_update
* improve code comments
* make [hostlist]_remove a single-line function
2024-01-18 13:00:55 +01:00
lunar-mining
576afd574d store: create test_remove() unit test 2024-01-17 16:57:46 +01:00
lunar-mining
2674cfd32e store: do not shuffle hosts on fetch_address()
Previously we were shuffling hosts that we select to avoid trying to
connect to them in a deterministic order. However, this contradicts the
protocol of ordering hostlists by last_seen.

Instead, we should try to connect to addresses stored at the top of the
hostlists first, as they are most likely to be active.

The problem of multiple slots competing for the same peer should be
solved by the various locking checks in check_address_with_lock().
2024-01-17 15:13:54 +01:00
lunar-mining
f3361db4c4 lilith: change hostlist paths on default config 2024-01-17 14:31:38 +01:00
lunar-mining
eda5c69af4 lilith: add whitelist_refinery task
Lilith now periodically pings nodes on its whitelist, updating their
last_seen field if they are active, otherwise downgrading them to
greylist.

This is to prevent Lilith from sharing inactive peers with other hosts
when it shares its whitelist.
2024-01-17 14:27:51 +01:00
lunar-mining
3d5eabfe59 net: downgrade host if they disconnect or we can't connect to them.
This commit introduces a new Session method called downgrade_host().

It gets called on two occasions:

* if we receive a stop signal on a channel (Inbound, Outbound, Manual sessions)
* if we cannot establish a connection (Outbound and Manual session)

This commit deprecates the "rejected" vector inside Outbound session
that prevented us from instantly reconnecting to an inactive host.
2024-01-17 11:01:36 +01:00
lunar-mining
4ded978f06 chore: cargo fmt 2024-01-16 18:41:59 +01:00
lunar-mining
8d5963961b refinery: stop refinery process before saving the hostlist 2024-01-16 17:08:44 +01:00
lunar-mining
388a190d49 store: save whitelist entries on the greylist on stop (no locks)
a simplier way of saving whitelist entries on the greylist on stop
without acquiring any write locks.
2024-01-16 17:07:02 +01:00
lunar-mining
b5119dff94 Revert "net: downgrade whitelist to greylist on stop"
This reverts commit 4bf43ec521.
2024-01-16 16:59:22 +01:00
lunar-mining
99d0adc5bb settings: change default hostlist to .local/darkfi/CARGO_PKG_NAME
also update tests
2024-01-16 14:57:14 +01:00
lunar-mining
06ae4fd054 settings: change refinery interval default to 5 seconds
we reduce this in light of 4bf43ec521.
Hostlist sharing now works as follows:

* Start node
* wait 5 sec
* start greylist refinery
* send whitelisted entry to peers
2024-01-16 13:56:49 +01:00
lunar-mining
4bf43ec521 net: downgrade whitelist to greylist on stop
This commit forces all whitelisted peers through the greylist each time
we start a node, thus ensuring that whitelisted peers are in fact
reachable.

Otherwise, our whitelist risks getting polluted with unreachable
whitelisted peers. While the greylist has a refinery process to deal
with this, the whitelist has no such process.
2024-01-16 13:49:37 +01:00
lunar-mining
c0e23dca86 net: fix ports on test 2024-01-15 17:55:19 +01:00
lunar-mining
ec5abf9683 net: make clippy + fix test 2024-01-15 17:03:41 +01:00
lunar-mining
4f4e4fb5b3 net: small integration test tweaks 2024-01-15 16:05:38 +01:00
lunar-mining
5f83327aec chore: delete unused methods 2024-01-14 16:47:48 +01:00
lunar-mining
bd0c7684c8 outbound_session: replace downgrade_host() with rejected vector
downgrade_host() is costly (reads through many vectors) and redundant
because it repeats the behavior that should be handled by the greylist
refinery.

what we need is a way to avoid instantly reconnecting to hosts that we
have just failed to connect to.

this commit introduces a simple fix- we write to a vector called
`rejected` and avoid trying to reconnect to its entries once a
connection has failed.

however, this is not ideal as it means we will never connect to that
host- see TODO.
2024-01-14 16:00:54 +01:00
lunar-mining
fb4306e1e4 store: fix logic error in greylist_store_or_update
previously we were checking whether the entry is in any of the hostlists
(hostlist_contains) prior to storing entries in the greylist.

this creates a logic error which we have now fixed.

the impact is we will now likely have duplicate connections between the
greylist and other lists. however, it shouldn't be a problem.
2024-01-14 15:55:06 +01:00
lunar-mining
3abd2c62bb net: don't hide connection upgrade inside perform_handshake_protocols()
make a standalone function that removes the address from the white or
greylist and adds it to the anchorlist. call it inside outbound and
manual session.

this commit also removes a redundant Result<()> from
[hostlist]_store_or_upgrade() method and updates its usage.

We also add various debug statements and cleanup.
2024-01-14 11:42:01 +01:00
lunar-mining
f08ce9a4c8 chore: fix comment positionning on manual_session 2024-01-14 11:38:44 +01:00
lunar-mining
e40405a257 store: bug fix
fix accidental read from wrong hostlist
2024-01-14 09:54:44 +01:00
lunar-mining
b38a1267fb store: remove redundant else clauses 2024-01-14 09:14:51 +01:00
lunar-mining
3f51d80438 chore: fix test fixes 2024-01-13 13:32:35 +01:00
lunar-mining
765bd819b2 net: change unwrap() to expect() on hostlist queries 2024-01-13 12:25:04 +01:00
lunar-mining
40619581cd store: reduce LOC in hostlist queries and update usage.
also cleanup debug statements and warnings.
2024-01-13 11:34:38 +01:00
lunar-mining
639f1f72bf store: fix and simplify tests 2024-01-11 11:59:03 +01:00
lunar-mining
c7cf7d861d lilith: change no hostlist warning to fatal panic 2024-01-10 14:53:29 +01:00
lunar-mining
2dbaf413a0 protocol_seed: fix bool syntax 2024-01-10 09:44:27 +01:00
lunar-mining
736459aa51 chore: cleanup
fix warnings + debug statements
2024-01-10 08:49:29 +01:00
lunar-mining
96cad54d81 net: 99.9999% of the time it works 100% of the time
cleaned up refinery code and seem to have eliminated deadlocks...
2024-01-08 12:20:10 +01:00
lunar-mining
fcf5a87a28 net: fix deadlock (partial fix)
* don't fetch addresses with lock in a nested way- first fetch the
  address, then apply the locking checks

* delete blocking function get_active_connect_count. instead, just use
  slots rather that active connections to avoid deadlock on p2p channels.

TODO: there seems to be another deadlock that occurs more rarely. From
preliminary investigations, it doesn't seem to be related to p2p channels.
2024-01-07 12:50:04 +01:00
lunar-mining
4cde069c53 store: document and cleanup 2024-01-03 18:50:04 +01:00
lunar-mining
e472003b6d outbound_session: fetch_address() logic bug fix
we need to use else if rather than chaining if statements as it gets
confused and calls multiple fetch methods otherwise.
2024-01-03 18:00:23 +01:00
lunar-mining
0ac12ff19d store: add test_fetch_address() unit test 2024-01-03 17:59:56 +01:00
lunar-mining
79e9039b9b store: create test_fetch_anchorlist() unit test 2024-01-03 15:57:15 +01:00
lunar-mining
ad3675eb3c store: fix death loop
if we don't remove the greylist entry, keeps trying to connect to
it
2024-01-02 11:06:53 +01:00
lunar-mining
5f00598c12 outbound_session: remove peer from anchor or whitelist when try_connect fails 2024-01-01 13:47:03 +01:00
lunar-mining
27d1b3aa03 hosts: fix logic on anchorlist_fetch_with_schemes
if we don't have any hosts on the anchorlist, chose from the whitelist.
if we don't have any on the whitelist, chose from the greylist.

same principle for whitelist_fetch_with_schemes (each method has a
different selection priority)
2024-01-01 01:09:47 +01:00
lunar-mining
426efdf90b chore: cargo fmt 2023-12-31 11:49:55 +01:00
lunar-mining
18479be298 test: add seed node to net/test.rs 2023-12-31 11:48:48 +01:00
lunar-mining
1578138e8f outbound_session: move fetch_address logic into new function 2023-12-31 11:47:42 +01:00
lunar-mining
2696290aad store: fix logic on is_empty_hostlist()
anchorlist, greylist AND whitelist must be empty for this to return
true (previously OR)
2023-12-30 15:31:36 +01:00
lunar-mining
ca885a43ee store: improve error naming
Error::InvalidIndex -> Error::HostDoesNotExist
2023-12-30 12:05:47 +01:00
lunar-mining
07c2d667e1 session: remove redundant anchorlist write
We are already storing anchorlist entries in perform_handshake_protocols of session/mod.rs.
2023-12-30 11:58:26 +01:00
lunar-mining
4d4392f9e8 net: add test module to mod.rs 2023-12-30 11:45:27 +01:00
lunar-mining
873cd35e0e net: add hostlist documentation 2023-12-29 17:31:21 +01:00
lunar-mining
51b4263a93 net: remove connection from anchorlist when it disconnects and cleanup.
also remove perform_local_handshake function as it's made redudant by
the anchorlist removal change.
2023-12-29 17:31:03 +01:00