Commit Graph

4359 Commits

Author SHA1 Message Date
skoupidi
85670eb1f6 src/rpc: server handle requests in the background 2024-07-02 17:17:34 +03:00
draoi
9033567f00 net: stabilize HostState.unregister() calls
We previously deleted the call to `unregister()` after the refinery is
successful on a16dd562d9.

It was considered redundant since the `unregister()` call happens in
`subscribe_on_stop()`, which for refine session is called directly after
the refinery process finishes (after `channel.stop()`).

However, in a highly async environment the `unregister()` call in
`subscribe_on_stop()` can be called before the call to `move_host()`, meaning
that the host would then be stuck in the `Moving` state.

We have fixed this by specifying that `unregister` should only be called
in `subscribe_on_stop()` to peers that are not part of a refine session.
We seperately call `unregister` after `move_host` in the refinery.

This commit also fixes some documentation.

Note: the call to `unregister()` is highly fragile and can lead to race
conditions. We are working to replace this with something more robust
(like `tombstone()`).
2024-07-02 13:57:02 +02:00
parazyd
e09f0b192d net/tor: Add a way to retrieve the running onion address 2024-07-02 13:05:43 +02:00
parazyd
ccc5d9cf30 net/tor: Use P2P datastore for Tor's state and cache dirs 2024-07-02 12:13:22 +02:00
parazyd
c6aa5c1544 net: Define a datastore path 2024-07-02 11:51:42 +02:00
parazyd
ba62cdf6e5 net/settings: Convert hostlist into an Option<String> 2024-07-02 11:45:06 +02:00
skoupidi
cb029adc4d contract/dao/lib: typo lol 2024-07-01 18:37:57 +03:00
skoupidi
7b92070c7c contract/dao/lib: fixed blockwindow 2024-07-01 18:33:31 +03:00
skoupidi
97f7a91879 drk: rpc cleanup and minor fix
- All rpc use same fn to perform requests towards darkfid\n- Moved all rpc related Drk fns to rpc.rs\n- Fixed subscribe where if darkfid went off, drk subscription errored and drk hanged
2024-07-01 16:36:29 +03:00
draoi
a16dd562d9 refine_session: remove redundant call to unregister()
unregister() will get called when the refine session channel disconnects
in session::remove_sub_on_stop(). Calling it here is actually dangerous
and creates rare race conditions.
2024-06-28 15:47:36 +02:00
draoi
39ce78632a hosts: create resize() and sort_by_last_seen() methods
We organize this functionality into distinct methods which get called
higher up, for example rather than manually resizing inside of store(),
we call resize() after we call store().

This is about reducing the "critical section" where locks are held and
using function scopes to ensure locks are released as quickly as possible.
2024-06-28 10:41:59 +02:00
draoi
2cd8b4dff7 net: use sync Mutex for HostContainer
Rationale: using a sync Mutex wherever possible is the recommended
method.

Additionally, using a sync Mutex here fixes some really weird fairness
behaviors we observed in the smol::lock::RwLock where writers in the
priority queue were occassionally ignored.
2024-06-27 15:03:22 +02:00
draoi
e7d8ba1864 refine_session: use remove_if_exists() method to delete entry when refinery fails
There's no need to acquire the write lock in the refinery when we can
just use one of the hosts methods.
2024-06-27 13:56:25 +02:00
draoi
958361c953 net: simplfy fetch_last() method and fix lilith's usage 2024-06-26 10:24:06 +02:00
draoi
6a0d4cfe7d net: simplify update_last_seen() method
Also fix its usage by Lilith
2024-06-26 10:01:42 +02:00
draoi
e2ba275cb9 session/mod: use !p2p.connected() instead of channels().is_empty() 2024-06-26 09:21:23 +02:00
draoi
0958e69b62 hosts: modify last_seen instead of entire entry on store_or_update() 2024-06-26 09:13:30 +02:00
draoi
55af782eb3 refine_session: use !p2p.connected() instead of channels.is_empty() 2024-06-26 09:01:33 +02:00
draoi
dbf5c6bc8f hosts: use sync Mutex for HostRegistry
We don't need to use an AsyncMutex here since we're not holding across .await points or for long periods of time.

Using a sync Mutex here also fixes some really weird fairness behaviors we observed in the smol::lock::Mutex where writers in the priority queue were occasionally getting ignored. This was apparently not a deadlock since subsequent and prior readers and writers were able to access the data with no problems.
2024-06-26 08:52:46 +02:00
draoi
958f02a3eb hosts: use sync Mutex for HostRegistry
We don't need to use an AsyncMutex here since we're not holding across .await points or for long periods of time.

Using a sync Mutex here also fixes some really weird fairness behaviors we observed in the smol::lock::Mutex where writers in the priority queue were occasionally getting ignored. This was apparently not a deadlock since subsequent and prior readers and writers were able to access the data with no problems.
2024-06-25 22:16:20 +02:00
skoupidi
235ba3f644 darkfid: purge current forks on network dc 2024-06-25 16:00:38 +03:00
draoi
787d9ac395 net: make disconnect_publisher notify with an Error instead of a bool 2024-06-25 09:12:12 +02:00
draoi
2badfbb141 net: create a disconnect_publisher that notifies when we have no connectons
We check whether there are any remaining channels when we remove a
channel in remove_sub_on_stop(). If the channel list is empty,
we call notify() on disconnect_pubisher and set its inner value to true.

Note that this only signals when we do not have any connections, and
does not update to false when new connections are formed.
2024-06-25 08:44:32 +02:00
dasman
c4ea68e474 event_graph: in dag_insert() continue instead of break when iterating over/cleaning unreferenced_tips 2024-06-25 03:18:54 +03:00
draoi
5d7632d79f hosts: use async mutex instead of async rwlock on HostRegistry
Mutex makes more sense here since there are orders of magnitude more call to write() than there are to read() (we counted) (trust me bro)
2024-06-24 18:00:37 +02:00
draoi
4abc12207a chore: cleanup hosts imports 2024-06-24 13:45:50 +02:00
draoi
43bad915a5 refinery: delete un-necessary and excessively long lock on greylist
Previously we were locking the greylist to prevent the index from changing
while performing a handshake. This isn't necessary. It is acceptable
for the greylist index to change while the handshake is ongoing.

The thing we don't want to happen is that the addr we are operating on
is somehow removed from the list- this should never happen since it has
been marked as "Refine" in the HostRegistry. Therefore, calling unwrap()
on get_index_at_addr() should pass 100% of the time (and if it doesn't,
that indicates a logic failure elsewhere in the code).
2024-06-24 13:34:34 +02:00
draoi
531e4b2f92 net: use sync Mutex for last_connection
RwLock is overkill in this case since there is only ever one reader and
one writer.

For more info why a sync Mutex is appropiate in this case, see commit 65a8e9a44fa3c835158550e7eb5b5e1946e3028f
2024-06-24 13:34:34 +02:00
draoi
76934ac216 net: use sync Mutex for ipv6_available
Locks should be sync for simple data operations and async if:

1. the lock must be held across an .await point
2. the new data being stored in the lock is calculated from data already inside the lock

Since ipv6_available is a fast and simple data operation it is more appropiate to use
a sync Mutex here.
2024-06-24 13:34:34 +02:00
draoi
aee1e571d4 error: fix wrong print on HostStateBlocked 2024-06-22 19:01:24 +02:00
draoi
348ed19a7d net/tests: ensure ports are unique 2024-06-21 19:43:02 +02:00
draoi
541166162e acceptor: return error instead of calling unwrap() on subscribe_stop
unwrap() can panic in the rare case that a node disconnects while we are
in the middle of accepting a connection from it.

In the case that this happens we should instead just exit with an error.
2024-06-21 12:01:55 +02:00
skoupidi
3f31e393e1 contract/money/client/pow_reward: minor cleanup 2024-06-20 14:18:27 +03:00
skoupidi
6e59afaee3 contract/money/client/genesis_mint: allow optional different recipient 2024-06-20 14:18:27 +03:00
skoupidi
8c33d59f40 chore: updated all repo references to codeberg 2024-06-19 20:51:25 +03:00
draoi
57499cff8b net/test: capture panics + select random ports to connect to
Selecting a random port allows us to run the test on the same machine
concurrently without conflicts.

Note that selecting a port for the seed node and seed sync session is
fairly safe, since we immediately start the node after the port is
selected, meaning most of the time the same port will not come up as
available if another test is being run concurrently.

However there is slightly less certainty with the manual session, since
we first generate a list of available ports, and then start them in a
loop, creating a slight delay and increasing the probability that
another test, run concurrently, could select one of those ports as
available.
2024-06-19 19:22:19 +02:00
skoupidi
5313217f9f contract/money/client/genesis_mint: minor cleanup 2024-06-19 20:07:25 +03:00
skoupidi
934d8f1a42 validator: check block timestamp is after genesis 2024-06-19 17:37:02 +03:00
skoupidi
82a56cd2c2 validator: properly handle gas limit checks 2024-06-19 12:00:21 +03:00
kalm
cff9d0e7f5 validator/consensus: gas-based limit for unproposed transactions retrieval
Gas-based limit implementation to retrieve unproposed transactions. The limit is maintained by the constant 'GAS_LIMIT_UNPROPOSED_TXS', currently calculated as the product of the average total gas used and a gas limit multiplier equivalent to the existing TX_CAP value (i.e, 50).

The average total gas was obtained through analysis of empirical transaction test data, using a gas analysis tool.

The aim of this approach is to allow a gradual and controlled transition towards an optimal gas-based system. This minimizes potential adverse effects brought by changes to TX_CAP's implementation and provides the benefits of using gas to limit the number of txs received. This implementation will be fine-tuned until the discovery of the most efficient formula for determining the unproposed transactions' gas limit.

Tests have been added to verify the implementation's correctness by running transactions against it. To run the tests, run the following command from the bin/darkfid directory:

cargo test --release --bin darkfid tests::unproposed_txs
2024-06-13 05:27:05 -07:00
draoi
c088ec5003 manual_session: reconnect when a manual connection disconnects 2024-06-10 17:22:18 +02:00
draoi
b0b192c3f2 system: rename Subscriber to Publisher + propagate change
We now subscribe to a Publisher which is clearer conceptually than
subscribing to a Subscriber.
2024-06-10 17:22:18 +02:00
foo
302d482475 money/client/transfer: Fix integer truncation issues when dividing for half-split
- Fix issue where `half` was calculated incorrectly for odd values of
  `value`
- Fix issue where sending a `value` of 1 and `half_split` of true would
  result in two empty value transfers

Note that this is only a client issue. The wasm back-end would cause the
invalid transfer to fail as the tx outputs from the client would not
match the inputs
2024-06-09 17:53:21 +03:00
foo
4eba00236d clippy: add suggested clippy lints to top-level Cargo.toml and enable
clippy linting at the workspace level for all crates

Configure all workspaces to use lints from the top-level Cargo.toml
  file
Add example lints that the project could configure to improve security
  and reliability.
Configure lints to warn level. Using deny level makes other binaries
fail to compile if even one of them has a failure.
No lints are added in this commit. Future changes can enable and fix
lints
2024-06-09 10:35:09 -04:00
dasman
cfe9f49de2 dakirc+tau: do not create_dir_all on replay path if not needed 2024-06-08 03:03:24 +03:00
dasman
3bbbaa6308 make clippy happy again 2024-06-06 13:32:40 +03:00
lunar-mining
63a91dde41 net: remove potential race conditions
1. Shutting down all channels in p2p.stop() is redundant since they will
   be cleaned up by the session shutdown.
2. subscribe_stop().expect(..) could panic in the case that the node we
   are connecting to disconnects at this exact moment (triggering a
   `ChannelStopped` error).
2024-06-06 08:33:10 +02:00
dasman
37f85f49cd event_graph: dag replay logs and db to be configurable, also user should choose to run in replay mode or not 2024-06-06 04:42:47 +03:00
skoupidi
a755c30b75 contract/dao: renamed all day references to blockwindow 2024-06-05 16:33:38 +03:00
skoupidi
b5cb5a55b7 contract/dao: use actual runtime block target time not hardcoded one in blockwindow() 2024-06-05 14:20:17 +03:00