When we receive info about a host from two nodes simulatenously it was
causing duplicate entries to enter the hostlist.
We fix this by introducing a new state, HostState::Insert, and checking
that hosts don't exist with this HostState before we accept them.
The usage of a second p2p network for miners was a premature optimization for faster block propagation between block producers, but in reality we don't know if its required yet, therefore we eliminate the extra complexity it introduces
HostContainer is an Array of 4 hostlists which are identified by
HostColor as Grey, White, Gold or Black.
Using this Container allows us to quickly replicate the same utilities
on all host functions while minimizing code reuse.
this would loop forever in the case that the manual connection has been
successfully established.
we don't need `continue`, we can safely execute the function since
HostState is protecting from any invalid state changes (such
as changing a host state from Connected to Pending)
also move the HostState reset remove() after the sleep.
We must stop tracking a peer if connecting to it has failed, i.e.
Pending peers must either transition to Connected or None, otherwise
they will be stuck in the Pending state forever.
This commit removes excessive use of RwLocks in the net code, replacing
them with a state machine that:
* Protects against race conditions where multiple threads are trying to
modify the same resource (i.e. the hostlists) by retricting state
transitions to a fixed set of safe steps.
* Minimizes risk of deadlocks by aggregating is_migrating(), is_pending(),
is_connected() etc checks to a single locked HashMap, `HostRegistry`.
This commit also simplifies the `p2p.rs` interface by migrating
connected channel utilities into `hosts/store.rs`.