Commit graph

20 commits

Author SHA1 Message Date
Boog900
b510739701
P2P: Network init (#130)
* p2p changes

* clippy

* a few more docs

* init cuprate-p2p

* remove some unrelated code and add some docs

* start documenting client_pool.rs

* add more docs

* typo

* fix docs

* use JoinSet in connection maintainer

* small changes

* add peer sync state svc

* add broadcast svc

* add more docs

* add some tests

* add a test

* fix merge

* add another test

* unify PeerDisconnectFut and add more docs

* start network init

* add an inbound connection server

* remove crate doc for now

* fix address book docs

* fix leak in client pool

* correct comment

* fix merge + add some docs

* fix doc

* dandelion_tower -> dandelion-tower

* fix async-buffer builds

* check if incoming peers are banned

* add interface methods

* update docs

* use a JoinSet for background network tasks

* Apply suggestions from code review

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>

* Update p2p/monero-p2p/src/services.rs

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>

---------

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>
2024-06-04 18:19:25 +01:00
Boog900
00c3692eac
P2p changes (#118)
* p2p changes

* clippy

* a few more docs

* review comments

* fix peer list bug
2024-05-02 22:58:22 +00:00
Boog900
88f7d1f212
download monerod in CI (#123)
* download monerod in CI

* move action file

* add macOS arm support

* remove reqwest from workspace

* undo whitespace changes

* fix indentation

* update comments

* add monerod to .gitignore

* Apply suggestions from code review

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>

* add back spacing

---------

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>
2024-05-01 01:21:08 +01:00
hinto-janai
2ac90420c6
ci: fix windows/macos (#116)
* cryptonight: include homebrew directories

* test-utils: add arm macos to `monerod` downloader

* ci: install windows-gnu
2024-04-27 00:49:55 +01:00
hinto-janai
32a44a2503
test-utils: compare data against RPC (#115)
* cargo: add `pretty_assertions`

* test-utils: add tests to compare data against RPC data, and fix

* small fixes

* database: fix `cumulative_generated_coins` from test data

block had wrong data which offset all of the asserts
2024-04-25 19:58:45 +01:00
hinto-janai
c65eb0a3ca
database: implement ops/ (#102)
* ops: add `trait MoneroR{o,w}`

* update `trait MoneroR{o,w}` bounds

* types: add `BlockInfoLatest` type alias

* block: impl most core functions

* types: fix https://github.com/Cuprate/cuprate/pull/91#discussion_r1527668916

* fix table type test

* cargo.toml: add `{cuprate-types, monero-serai}`

* add_block: add all other block data

* ops: remove unneeded `block` functions

* env: add `EnvInner::open_db_rw_all()`

* types: fix test

* block: `&mut TxRw` -> `&TxRw`, use `open_db_rw_all()`

* add `trait Tables[Mut]` and use it in `EnvInner`

* block: use `TablesMut`

* tables: replace manual impl with `define_trait_tables!()`

* tables: docs for `trait Tables[Mut]`

* tables: doc functions

* create `call_fn_on_all_tables_or_early_return!()` macro

* block: cleanup signatures + bodies

* block: more fn's, docs

* block: add `doc_{error,single,bulk}!()`

* remove `ops/monero.rs`

* move `height()` to `ops/blockchain.rs`

* add `ops/macros.rs`

* tx: add fn signatures

* output: fix fn signatures

* ops: expose `_inner()` functions

* block: add `add_block_header{_bulk, _inner}()`

* ops: remove doc_{fn,inner}!()`

* ops: remove `_{inner,bulk}()`, lifetime + generics

* update lib/mod docs

* ops: add and use `doc_add_block_inner_invariant!()`

* ops: add docs/return to inner `add_block()` functions

* add_block(): extract and use fn for {key_image, output}

* ops: more fn body impl + `add_block()`

* cargo: add `monero-pruning`

* ops: extract out `tx` functions from `add_block()`

* property: add `db_version()`

* ops: `pop_block()` body, remove other `pop_block` fn's

* types: add `block_blob: Vec<u8>` to `VerifiedBlockInformation`

* block: put `block_blob`, pass `Tables` to sub-functions

`impl TablesMut` can't mutably pass multiple tables since
it takes `&mut self`, so all functions unfortunately have to
take a full `&mut impl TablesMut` even though they only need
a few tables.

* database: add `DatabaseRw::take()`

useful for `pop_block()` where we need the value afterwards

* block: deserialize tx's from `block_blobs` in `pop_block()`

* blockchain: `height()` -> `chain_height()`

* output: fix `amount_index`

* ops: fix unlock_time, chain_height

* `BlockInfoV{1,2,3}` -> `BlockInfo`

* constants: add `DATABASE_VERSION`

* database: add `DatabaseRw::update()`

* output: use `DatabaseRw::update()` in `remove_output()`

* add `TxBlobs` table, ignore pruning tables

* block: mostly impl `add_block()` body

* ops: comments

* add_block: miner v2 tx commitment, height cast

* block: impl `pop_block()`

* block: mostly impl `get_block()`

* block: impl `get_block_{from_height,header,header_from_height}`

* add `OutputFlags` bitflags

* add_block: u32::try_into(height: u32), use `OutputFlags`

* tx: impl `get_{tx,tx_from_id}()`

* tx: move docs tests to `#[test]`

testing everything in 1 go is more natural since e.g:
`add_tx()` is followed by `get_tx()`

* tables: add `trait TablesIter`, `all_tables_empty()`

This allows `TablesMut` to be a superset of `Tables`
and use all its accessor functions.

* use cuprate-test-utils, fix tx tests

* block: `add_block()` take block by ref

* tx: use all txs in tests

* output: add `all_tx_functions()` test

* add_block: check current height against input

* block: map more fields in `get_block()`

* block: remove `get_block()`, doc tests, fix `get_block_header()`

* block: dummy values in test

* heed: use `last/first()` instead of `unsafe` cursors

We no longer have DUP semantics and also hard to debug errors
were popping up on `del_current()`...

* heed: fix `DatabaseRw::delete`

Ok(true) means the key did not exist, so we must return
Err(RuntimeError::KeyNotFound)

* block: `add_block()` (dummy value) test

* ops: `key_image` tests

* cleanup, docs, tests

* backend: test `take()` & `update()`

* docs

* remove `OutputFlags::NONE`

* add_block(): add asserts, panic docs, `should_panic` tests

* backend: remove `Ok(())` in `Database::delete` if already deleted

redb already does this, so heed so match

* block: move block operations after tx/outputs

* `amount == 0` -> `amount == 1`

* Nit: StorableVec::wrap_ref

* `saturating_sub(1)` -> `- 1`

* add `TxOutputs` table

* add_block(): add to `tx_outputs` table

* fix `DatabaseRo::update`

* add_tx(): take `block_height` as input

* tx: add/remove from `TxOutputs` table

* output: remove if `amount == 1` -> `amount_index == 0`

* output: fix `add_output()`'s `amount_index` calculation

* output: fix `add_output()`'s `amount_index` calculation again

* output: tests for `amount_index/num_outputs`

* block: `num_outputs - 1` and `take()` -> `get()`

We don't need to `take()` since the call afterwards to
`remove_output()` removes the entry

* block: swap `get_block_extended_header[_from_height]()`

* move `{key_image,output}` handling `add_block()` -> `add_tx()`

* blockchain: add doc to `top_block_height()`

* block: manual panic -> `assert_eq!()`

* test-utils: add `block_blob` to `VerifiedBlockInformation`

field introduced in this PR

* ops: use real block/tx data in tests

* block: `total_generated_coins` -> `cumulative_generated_coins`

* fix clippy, docs, TODOs

* `cumulative_generated_coins()`: `block/` -> `blockchain/`

* blockchain: add `cumulative_generated_coins()` tests

* Update database/src/ops/block.rs

Co-authored-by: Boog900 <boog900@tutanota.com>

* `cumulative_generated_coins()` docs for pre-block-0 special case

---------

Co-authored-by: Boog900 <boog900@tutanota.com>
2024-04-23 02:53:29 +01:00
hinto-janai
ee22e81c7e
test-utils: add rpc module (#110)
* test-utils: impl `rpc` module

* client: use `spawn_blocking`

* client: add tests

* ignore test for now

* add example and `get_transaction_verification_data()`

* client: calculate proper `generated_coins`

* data: fix `generated_coins/reward` references

* data: fix height
2024-04-21 17:11:23 +01:00
hinto-janai
fe2366c5df
test-utils: return &'static verified superset types (#108)
* data: return `&'static` verified superset types

* docs

* fix VerifiedBlockMap, use manual input, add block 5da0a3d

* free: use macros to generate accessor functions

* constants: use macro

* docs

* `tx_data` -> `tx_blob`
2024-04-21 01:34:04 +01:00
hinto-janai
e6465ec613
test-utils: add data/ (#107)
* test-utils: add `data/` + add lints + `clippy --fix`

* data: assert tx_hash is correct

* data: add `BLOCK_202612` doctest

* lib.rs: remove lints

* data: add more tx data, fix names

* revert `Cargo.toml` formatting

* data: add more block data

* free: add serialization tests

* remove clippy allows
2024-04-13 02:13:46 +01:00
Boog900
93372fa4b5
P2P Address book & Handshake changes (#89)
* use tokio's delay queue for bans

* document handles

* remove peers from address book when retrieving

* ping inbound peers during handshakes

* support receiving pings during handshakes

* add peer to anchor before reducing whit list

* clippy

* comment handshakes

* typos

* sort `use`

* use `rand::prelude::*`

* review comments

* update macro
2024-03-20 20:58:12 +00:00
Boog900
159c8a3b48
levin: fragmented messages (#84)
* levin: fix fragmented messages & use bitflags

* levin: add a method to fragment a message

* levin: add tests for fragmented messages and fix issues

* fix docs

* tests: don't include bytes length

* levin: add support for sending fragmented
/ dummy messages

* fmt

* add fragmented handshake tests.

* fix handshake detection when fragmented
and alt (non-monero) protocol info

* add tracing logs

* remove `already_built`, this was an old way I was thinking of sending raw buckets

* clippy

* clippy 2

* Update net/levin/src/message.rs

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>

* review comments

* add timeout to tests

* Update net/levin/src/header.rs

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>

---------

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>
2024-03-05 01:29:57 +00:00
Boog900
28aa0b5552
CI: fix deny (#83) 2024-02-29 20:29:11 +00:00
Boog900
e560ecc2ee
Add a test for an inbound handshake from monerod (#75)
* monerod: set a random DB and remove dir when done

* add a test for an inbound monerod handshake

* don't fail if can't remove dir on windows

* Update test-utils/src/monerod.rs

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>

* use `temp_dir`

* use `tempfile`

---------

Co-authored-by: hinto-janai <hinto.janai@protonmail.com>
2024-02-25 21:21:25 +00:00
Boog900
475c8c5ac0
imporove Monerod spawn stability (#66)
* output monerod logs when a thread panics

* always spawn a monerod don't attempt to re-use

* set zmq port and `non-interactive`

* check monerod has started before test

* remove test panic

* review changes
2024-02-16 22:47:50 +00:00
hinto-janai
354ac9c2f6
Add typos + cargo doc CI (#32)
* ci: add separate `typo` job

* add `typos.toml` for false positives

* fix all typos

* ci: add `cargo doc` step

* fix doc errors

* contributing.md: update passing CI steps

* fix more typos, add exception to `cryptonight/`

* ci: move `cargo doc` step within `ci` job

It needs dependencies.

* ci: add https://github.com/Cuprate/cuprate/pull/63

* test-utils: fix typo

* ci: switch `rustup update` and switch order

* ci: only update rust on unix

* ci: set `RUSTDOCFLAGS` env earlier

* ci: only run `cargo doc` on linux

* ci: remove `bash` on `cargo doc`

* ci: remove `--all-targets`

We now have the target OS's in CI, no need to compile for each.

* contributing.md: update ci steps

* ci: add `--all-targets` back to clippy, build

* update contributing.md
2024-02-15 16:03:04 +00:00
hinto-janai
630faed263
ci: include macos + windows (#52)
* ci: install boost, include macos + windows

* cryptonight: fix `MSVC`

* cryptonight: use `flag_if_supported()`

* fix cryptonight builds

* update randomX

* fix rx builds

* add memwipe

* include memwipe.c in build

* spawn monerod in msys2 for windows

* fix last commit

* install dependencies before spawning monerod

* remove --detach

* try another way of spawning monerod

* add /I

* download and spawn monerod as a part of tests

* add download.rs

* extend time for monerod spawn

* move sleep and show monerod output

* fix clippy

* change stdin to pipped

* #[cfg(unix)] on bytes::Buf

* fix macos capitalisation

* remove tar.bz2 on macos expected dir

* remove zip on windows expected dir

* fix todo

* add docs

* fix a couple typos

---------

Co-authored-by: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com>
Co-authored-by: Boog900 <boog900@tutanota.com>
2024-02-12 13:39:15 +00:00
Boog900
f894ff6f1b
p2p: add handshake timeouts 2024-01-22 18:18:15 +00:00
Boog900
b9334b6a90
clean up dependencies 2024-01-21 14:46:03 +00:00
Boog900
2c4cc1fb93
move address book to separate crate.
Also changes the address book to use the network zone trait
2023-12-08 15:03:01 +00:00
Boog900
8557073c15
p2p changes (#38)
* start re-working p2p to work with change monero-wire

* start re-working p2p to work with change monero-wire

adds back some changes from #22

* change the peer module to use the new API + fix a couple bugs

* remove peer set for now

* add try_from/from conversion between `Message` and
`Request`/`Response`

* Allow specifying other parameters in levin-cuprate

* add new `LevinCommand` enum and clean up monero-wire message de/encoding

* fix issues with merge

* start splitting up p2p crate into smaller crates.

* add monerod action from serai to test network code

* remove tracing in tests
2023-11-30 18:09:05 +00:00