From e8b20e6115587f10d11dbdc609ae541064e4d9e5 Mon Sep 17 00:00:00 2001 From: Boog900 Date: Fri, 24 May 2024 01:15:49 +0000 Subject: [PATCH 1/7] P2P: async buffer (#109) * impl async buffer * clippy * review comments --- p2p/async-buffer/Cargo.toml | 14 +++ p2p/async-buffer/src/lib.rs | 205 ++++++++++++++++++++++++++++++++ p2p/async-buffer/tests/basic.rs | 37 ++++++ 3 files changed, 256 insertions(+) create mode 100644 p2p/async-buffer/Cargo.toml create mode 100644 p2p/async-buffer/src/lib.rs create mode 100644 p2p/async-buffer/tests/basic.rs diff --git a/p2p/async-buffer/Cargo.toml b/p2p/async-buffer/Cargo.toml new file mode 100644 index 00000000..59f04301 --- /dev/null +++ b/p2p/async-buffer/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "async-buffer" +version = "0.1.0" +edition = "2021" +license = "MIT" +authors = ["Boog900"] + +[dependencies] +thiserror = { workspace = true } +futures = { workspace = true, features = ["std"] } +pin-project = { workspace = true } + +[dev-dependencies] +tokio = { workspace = true, features = ["full"] } \ No newline at end of file diff --git a/p2p/async-buffer/src/lib.rs b/p2p/async-buffer/src/lib.rs new file mode 100644 index 00000000..ded8c6a9 --- /dev/null +++ b/p2p/async-buffer/src/lib.rs @@ -0,0 +1,205 @@ +//! Async Buffer +//! +//! A bounded SPSC, FIFO, async buffer that supports arbitrary weights for values. +//! +//! Weight is used to bound the channel, on creation you specify a max weight and for each value you +//! specify a weight. +use std::{ + cmp::min, + future::Future, + pin::Pin, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + task::{Context, Poll}, +}; + +use futures::{ + channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender}, + ready, + task::AtomicWaker, + Stream, StreamExt, +}; + +#[derive(thiserror::Error, Debug, Copy, Clone, Eq, PartialEq)] +pub enum BufferError { + #[error("The buffer did not have enough capacity.")] + NotEnoughCapacity, + #[error("The other end of the buffer disconnected.")] + Disconnected, +} + +/// Initializes a new buffer with the provided capacity. +/// +/// The capacity inputted is not the max number of items, it is the max combined weight of all items +/// in the buffer. +/// +/// It should be noted that if there are no items in the buffer then a single item of any capacity is accepted. +/// i.e. if the capacity is 5 and there are no items in the buffer then any item even if it's weight is >5 will be +/// accepted. +pub fn new_buffer(max_item_weight: usize) -> (BufferAppender, BufferStream) { + let (tx, rx) = unbounded(); + let sink_waker = Arc::new(AtomicWaker::new()); + let capacity_atomic = Arc::new(AtomicUsize::new(max_item_weight)); + + ( + BufferAppender { + queue: tx, + sink_waker: sink_waker.clone(), + capacity: capacity_atomic.clone(), + max_item_weight: capacity, + }, + BufferStream { + queue: rx, + sink_waker, + capacity: capacity_atomic, + }, + ) +} + +/// The stream side of the buffer. +pub struct BufferStream { + /// The internal queue of items. + queue: UnboundedReceiver<(T, usize)>, + /// The waker for the [`BufferAppender`] + sink_waker: Arc, + /// The current capacity of the buffer. + capacity: Arc, +} + +impl Stream for BufferStream { + type Item = T; + + fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + let Some((item, size)) = ready!(self.queue.poll_next_unpin(cx)) else { + return Poll::Ready(None); + }; + + // add the capacity back to the buffer. + self.capacity.fetch_add(size, Ordering::AcqRel); + // wake the sink. + self.sink_waker.wake(); + + Poll::Ready(Some(item)) + } +} + +/// The appender/sink side of the buffer. +pub struct BufferAppender { + /// The internal queue of items. + queue: UnboundedSender<(T, usize)>, + /// Our waker. + sink_waker: Arc, + /// The current capacity of the buffer. + capacity: Arc, + /// The max weight of an item, equal to the total allowed weight of the buffer. + max_item_weight: usize, +} + +impl BufferAppender { + /// Returns a future that resolves when the channel has enough capacity for + /// a single message of `size_needed`. + /// + /// It should be noted that if there are no items in the buffer then a single item of any capacity is accepted. + /// i.e. if the capacity is 5 and there are no items in the buffer then any item even if it's weight is >5 will be + /// accepted. + pub fn ready(&mut self, size_needed: usize) -> BufferSinkReady<'_, T> { + let size_needed = min(self.max_item_weight, size_needed); + + BufferSinkReady { + sink: self, + size_needed, + } + } + + /// Attempts to add an item to the buffer. + /// + /// # Errors + /// Returns an error if there is not enough capacity or the [`BufferStream`] was dropped. + pub fn try_send(&mut self, item: T, size_needed: usize) -> Result<(), BufferError> { + let size_needed = min(self.max_item_weight, size_needed); + + if self.capacity.load(Ordering::Acquire) < size_needed { + return Err(BufferError::NotEnoughCapacity); + } + + let prev_size = self.capacity.fetch_sub(size_needed, Ordering::AcqRel); + + // make sure we haven't wrapped the capacity around. + assert!(prev_size >= size_needed); + + self.queue + .unbounded_send((item, size_needed)) + .map_err(|_| BufferError::Disconnected)?; + + Ok(()) + } + + /// Waits for capacity in the buffer and then sends the item. + pub fn send(&mut self, item: T, size_needed: usize) -> BufferSinkSend<'_, T> { + BufferSinkSend { + ready: self.ready(size_needed), + item: Some(item), + } + } +} + +/// A [`Future`] for adding an item to the buffer. +#[pin_project::pin_project] +pub struct BufferSinkSend<'a, T> { + /// A future that resolves when the channel has capacity. + #[pin] + ready: BufferSinkReady<'a, T>, + /// The item to send. + /// + /// This is [`take`](Option::take)n and added to the buffer when there is enough capacity. + item: Option, +} + +impl<'a, T> Future for BufferSinkSend<'a, T> { + type Output = Result<(), BufferError>; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + let mut this = self.project(); + + let size_needed = this.ready.size_needed; + + this.ready.as_mut().poll(cx).map(|_| { + this.ready + .sink + .try_send(this.item.take().unwrap(), size_needed) + }) + } +} + +/// A [`Future`] for waiting for capacity in the buffer. +pub struct BufferSinkReady<'a, T> { + /// The sink side of the buffer. + sink: &'a mut BufferAppender, + /// The capacity needed. + /// + /// This future will wait forever if this is higher than the total availability of the buffer. + size_needed: usize, +} + +impl<'a, T> Future for BufferSinkReady<'a, T> { + type Output = (); + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + // Check before setting the waker just in case it has capacity now, + if self.sink.capacity.load(Ordering::Acquire) >= self.size_needed { + return Poll::Ready(()); + } + + // set the waker + self.sink.sink_waker.register(cx.waker()); + + // check the capacity again to avoid a race condition that would result in lost notifications. + if self.sink.capacity.load(Ordering::Acquire) >= self.size_needed { + Poll::Ready(()) + } else { + Poll::Pending + } + } +} diff --git a/p2p/async-buffer/tests/basic.rs b/p2p/async-buffer/tests/basic.rs new file mode 100644 index 00000000..93717300 --- /dev/null +++ b/p2p/async-buffer/tests/basic.rs @@ -0,0 +1,37 @@ +use futures::{FutureExt, StreamExt}; + +use async_buffer::new_buffer; + +#[tokio::test] +async fn async_buffer_send_rec() { + let (mut tx, mut rx) = new_buffer(1000); + + tx.send(4, 5).await.unwrap(); + tx.send(8, 5).await.unwrap(); + + assert_eq!(rx.next().await.unwrap(), 4); + assert_eq!(rx.next().await.unwrap(), 8); +} + +#[tokio::test] +async fn capacity_reached() { + let (mut tx, mut rx) = new_buffer(1000); + + tx.send(4, 1000).await.unwrap(); + + assert!(tx.ready(1).now_or_never().is_none()); + + let fut = tx.ready(1); + + rx.next().await; + + assert!(fut.now_or_never().is_some()); +} + +#[tokio::test] +async fn single_item_over_capacity() { + let (mut tx, mut rx) = new_buffer(1000); + tx.send(4, 1_000_000).await.unwrap(); + + assert_eq!(rx.next().await.unwrap(), 4); +} From 1e857416c91bdcb819c5432c964cee32e2768801 Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Thu, 23 May 2024 21:16:39 -0400 Subject: [PATCH 2/7] database/helper: define `static`s within functions (#135) --- database/src/resize.rs | 4 ++-- helper/src/fs.rs | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/database/src/resize.rs b/database/src/resize.rs index cf185029..99d6d7e3 100644 --- a/database/src/resize.rs +++ b/database/src/resize.rs @@ -85,8 +85,6 @@ impl Default for ResizeAlgorithm { } //---------------------------------------------------------------------------------------------------- Free functions -/// Cached result of [`page_size()`]. -static PAGE_SIZE: OnceLock = OnceLock::new(); /// This function retrieves the system’s memory page size. /// /// It is just [`page_size::get`](https://docs.rs/page_size) internally. @@ -97,6 +95,8 @@ static PAGE_SIZE: OnceLock = OnceLock::new(); /// This function will panic if the OS returns of page size of `0` (impossible?). #[inline] pub fn page_size() -> NonZeroUsize { + /// Cached result of [`page_size()`]. + static PAGE_SIZE: OnceLock = OnceLock::new(); *PAGE_SIZE .get_or_init(|| NonZeroUsize::new(page_size::get()).expect("page_size::get() returned 0")) } diff --git a/helper/src/fs.rs b/helper/src/fs.rs index 2e859229..a6ece515 100644 --- a/helper/src/fs.rs +++ b/helper/src/fs.rs @@ -78,17 +78,16 @@ macro_rules! impl_path_oncelock_and_fn { $(#[$attr:meta])* // Documentation and any `derive`'s. $fn:ident, // Name of the corresponding access function. $dirs_fn:ident, // Name of the `dirs` function to use, the PATH prefix. - $once_lock:ident, // Name of the `OnceLock`. $sub_dirs:literal // Any sub-directories to add onto the PATH. ),* $(,)?) => {$( - /// Local `OnceLock` containing the Path. - static $once_lock: OnceLock = OnceLock::new(); - // Create the `OnceLock` if needed, append // the Cuprate directory string and return. $(#[$attr])* pub fn $fn() -> &'static Path { - $once_lock.get_or_init(|| { + /// Local `OnceLock` containing the Path. + static ONCE_LOCK: OnceLock = OnceLock::new(); + + ONCE_LOCK.get_or_init(|| { // There's nothing we can do but panic if // we cannot acquire critical system directories. // @@ -139,7 +138,6 @@ impl_path_oncelock_and_fn! { /// | Linux | `/home/alice/.cache/cuprate/` | cuprate_cache_dir, cache_dir, - __CUPRATE_CACHE_DIR, "", /// Cuprate's config directory. @@ -153,7 +151,6 @@ impl_path_oncelock_and_fn! { /// | Linux | `/home/alice/.config/cuprate/` | cuprate_config_dir, config_dir, - __CUPRATE_CONFIG_DIR, "", /// Cuprate's data directory. @@ -167,7 +164,6 @@ impl_path_oncelock_and_fn! { /// | Linux | `/home/alice/.local/share/cuprate/` | cuprate_data_dir, data_dir, - __CUPRATE_DATA_DIR, "", /// Cuprate's database directory. @@ -181,7 +177,6 @@ impl_path_oncelock_and_fn! { /// | Linux | `/home/alice/.local/share/cuprate/database/` | cuprate_database_dir, data_dir, - __CUPRATE_DATABASE_DIR, "database", } From 59a49b93ab57cdb7a2a12d774faef3d4d76adb25 Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Sun, 26 May 2024 19:39:32 -0400 Subject: [PATCH 3/7] repo: update license (#134) * add MIT license * update LICENSE.md * net: remove license files * fix LICENSE-MIT formatting use github formatting --- net/epee-encoding/LICENSE => LICENSE-MIT | 4 ++-- LICENSE.md | 7 +++---- net/levin/LICENSE | 9 --------- net/monero-wire/LICENSE | 9 --------- 4 files changed, 5 insertions(+), 24 deletions(-) rename net/epee-encoding/LICENSE => LICENSE-MIT (94%) delete mode 100644 net/levin/LICENSE delete mode 100644 net/monero-wire/LICENSE diff --git a/net/epee-encoding/LICENSE b/LICENSE-MIT similarity index 94% rename from net/epee-encoding/LICENSE rename to LICENSE-MIT index 0e5fe087..8d245289 100644 --- a/net/epee-encoding/LICENSE +++ b/LICENSE-MIT @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Boog900 +Copyright (c) 2023-2024 Cuprate Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md index 3e44fd15..002555e1 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,5 @@ Cuprate crates are licensed under one of two licenses, either MIT or AGPL-3.0, depending on the crate in question. Each crate declares their license in their -`Cargo.toml` and includes a `LICENSE` file detailing its status. Additionally, -a full copy of the AGPL-3.0 License is included in the root of this repository -as a reference text. This copy should be provided with any distribution of a -crate licensed under the AGPL-3.0, as per its terms. +`Cargo.toml`. Additionally, a full copy of both licenses are included in the +root of this repository for reference. These copies should be provided with +any distribution of a crate, as per the respective license's terms. diff --git a/net/levin/LICENSE b/net/levin/LICENSE deleted file mode 100644 index 01e72cc9..00000000 --- a/net/levin/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT license - -Copyright (C) 2023 Cuprate Contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/net/monero-wire/LICENSE b/net/monero-wire/LICENSE deleted file mode 100644 index 01e72cc9..00000000 --- a/net/monero-wire/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT license - -Copyright (C) 2023 Cuprate Contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file From 45656fe653de87bb92bc35cc1b38fe5a4d82f90e Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Sun, 26 May 2024 19:57:21 -0400 Subject: [PATCH 4/7] repo: adopt `rust-lang` label system (#136) * contributing: add `Keeping track of issues and PRs` section * add `labeler.yml` * more labels * update labels * update `.github/labeler.yml` * update `CONTRIBUTING.md` * doc `.github` files * wording fix * add `A-dependency` --- .github/labeler.yml | 80 +++++++++++++++++++++++++++++++++++ .github/workflows/labeler.yml | 25 +++++++++++ CONTRIBUTING.md | 28 ++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 .github/labeler.yml create mode 100644 .github/workflows/labeler.yml diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 00000000..1a71a240 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,80 @@ +# This file consists of rules determining which labels the +# `github-actions` bot should automatically label an issue/PR with. +# The CI that actually applies labels is in `.github/workflows/labeler.yml`. +# +# The main one used is the "if a file changed" rule. +# The format for this rule is: +# +# ``` +# $LABEL_NAME: +# - changed-files: +# - any-glob-to-any-file: $PATH +# ``` +# +# where $PATH can be: +# $DIRECTORY/* +# which means any file changed 1 level deep inside that directory or: +# $DIRECTORY/** +# which means any file changed within that directory or: +# $DIRECTORY/$FILE_NAME +# which means a specific file path or: +# $DIRECTORY/*.$FILE_EXTENSION +# which means any file 1 level deep in that directory with a certain file extension. +# +# For a detailed guide, see: . +# +# For a real example: +A-consensus: # This is the tag name +- changed-files: # Any changed file... + - any-glob-to-any-file: consensus/** # ...within the `consensus/` directory + # will cause the `github-actions` bot + # to add the `A-consensus` tag. + +A-cryptonight: +- changed-files: + - any-glob-to-any-file: cryptonight/** + +A-database: +- changed-files: + - any-glob-to-any-file: database/** + +A-helper: +- changed-files: + - any-glob-to-any-file: helper/** + +A-net: +- changed-files: + - any-glob-to-any-file: net/** + +A-p2p: +- changed-files: + - any-glob-to-any-file: p2p/** + +A-pruning: +- changed-files: + - any-glob-to-any-file: pruning/** + +A-test-utils: +- changed-files: + - any-glob-to-any-file: test-utils/** + +A-types: +- changed-files: + - any-glob-to-any-file: types/** + +A-ci: +- changed-files: + - any-glob-to-any-file: .github/** + +A-dependency: +- changed-files: + - any-glob-to-any-file: '**/Cargo.toml' # Any Cargo file in the entire repo + - any-glob-to-any-file: '**/Cargo.lock' + +A-workspace: +- changed-files: + - any-glob-to-any-file: '*' # Any root file change + +A-docs: +- changed-files: + - any-glob-to-any-file: '**/*.md' # Any file in the entire repo ending in `.md` diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 00000000..381b7dd0 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,25 @@ +# This action automatically applies GitHub labels +# based on the rules in the `.github/labeler.yml` file. +# +# For more info: +# - +# - + +name: "Labeler" +on: +- pull_request_target + +permissions: + contents: read + +jobs: + labeler: + permissions: + contents: read # for actions/labeler to determine modified files + pull-requests: write # for actions/labeler to add labels to PRs + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v5 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + sync-labels: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dc07f0c1..742ebaef 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,3 +38,31 @@ After that, ensure all lints, tests, and builds are successful by running: - Sort imports as core, std, third-party, Cuprate crates, current crate. - Follow the [Rust API Guidelines](https://rust-lang.github.io/api-guidelines) - Break the above rules when it makes sense + +## Keeping track of issues and PRs +The Cuprate GitHub repository has a lot of issues and PRs to keep track of. Cuprate makes use of generic labels and labels grouped by a prefixes to help with this. + +Some labels will be [automatically added/removed](https://github.com/Cuprate/cuprate/tree/main/.github/labeler.yml) if certain file paths have been changed in a PR. + +The following section explains the meaning of various labels used. +This section is primarily targeted at maintainers. Most contributors aren't able to set these labels. + +| Labels | Description | Example | +|--------------|-------------|---------| +| [A-] | The **area** of the project an issue relates to. | `A-database`, `A-rpc`, `A-docs` +| [C-] | The **category** of an issue. | `C-cleanup`, `C-optimization` +| [D-] | Issues for **diagnostics**. | `D-confusing`, `D-verbose` +| [E-] | The **experience** level necessary to fix an issue. | `E-easy`, `E-hard` +| [I-] | The **importance** of the issue. | `I-crash`, `I-memory` +| [O-] | The **operating system** or platform that the issue is specific to. | `O-windows`, `O-macos`, `O-linux` +| [P-] | The issue **priority**. These labels can be assigned by anyone that understand the issue and is able to prioritize it, and remove the [I-prioritize] label. | `P-high`, `P-low` +| [wontfix] | Indicates an issue will not be fixed. | | + +[A-]: https://github.com/Cuprate/cuprate/labels?q=A +[C-]: https://github.com/Cuprate/cuprate/labels?q=C +[D-]: https://github.com/Cuprate/cuprate/labels?q=D +[E-]: https://github.com/Cuprate/cuprate/labels?q=E +[I-]: https://github.com/Cuprate/cuprate/labels?q=I +[O-]: https://github.com/Cuprate/cuprate/labels?q=O +[P-]: https://github.com/Cuprate/cuprate/labels?q=P +[wontfix]: https://github.com/Cuprate/cuprate/labels?q=wontfix \ No newline at end of file From 4876e159e7ba4714b426ec92bdb5e904270058f6 Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Tue, 28 May 2024 21:18:30 -0400 Subject: [PATCH 5/7] repo: add skeleton directories, fix labels (#139) * `database/` -> `storage/`, create skeleton `storage/` crates * add skeleton root directories * books: add skeleton * ci: fix labeler.yml * fix CONTRIBUTING.md * fix workspace Cargo.toml * fix `storage/` * rename helper fs fn, `cuprate_database` -> `cuprate_blockchain` * fix Cargo.toml * cuprate-blockchain: revert find-and-replace Since it has to be ported to the book anyway, there's not much reason to update this and create review diffs. * labeler.yml: remove `A-docs` from `books/` changes Although books are documentation, the `A-books` label already exists for this --- .github/labeler.yml | 38 +++++++++- .github/workflows/ci.yml | 2 +- CONTRIBUTING.md | 4 +- Cargo.lock | 74 ++++++++++--------- Cargo.toml | 4 +- benches/README.md | 1 + binaries/README.md | 1 + books/README.md | 1 + books/architecture/README.md | 1 + books/protocol/README.md | 1 + helper/src/fs.rs | 40 +++++----- rpc/README.md | 1 + storage/README.md | 5 ++ .../cuprate-blockchain}/Cargo.toml | 20 ++--- .../cuprate-blockchain}/README.md | 6 +- .../src/backend/heed/database.rs | 0 .../src/backend/heed/env.rs | 2 +- .../src/backend/heed/error.rs | 4 +- .../src/backend/heed/mod.rs | 0 .../src/backend/heed/storable.rs | 4 +- .../src/backend/heed/transaction.rs | 0 .../src/backend/heed/types.rs | 0 .../cuprate-blockchain}/src/backend/mod.rs | 0 .../src/backend/redb/database.rs | 0 .../src/backend/redb/env.rs | 2 +- .../src/backend/redb/error.rs | 2 +- .../src/backend/redb/mod.rs | 0 .../src/backend/redb/storable.rs | 4 +- .../src/backend/redb/transaction.rs | 0 .../src/backend/redb/types.rs | 0 .../cuprate-blockchain}/src/backend/tests.rs | 2 +- .../cuprate-blockchain}/src/config/backend.rs | 2 +- .../cuprate-blockchain}/src/config/config.rs | 20 ++--- .../cuprate-blockchain}/src/config/mod.rs | 4 +- .../src/config/reader_threads.rs | 6 +- .../src/config/sync_mode.rs | 0 .../cuprate-blockchain}/src/constants.rs | 4 +- .../cuprate-blockchain}/src/database.rs | 0 .../cuprate-blockchain}/src/env.rs | 0 .../cuprate-blockchain}/src/error.rs | 2 +- .../cuprate-blockchain}/src/free.rs | 0 .../cuprate-blockchain}/src/key.rs | 2 +- .../cuprate-blockchain}/src/lib.rs | 10 +-- .../cuprate-blockchain}/src/ops/block.rs | 0 .../cuprate-blockchain}/src/ops/blockchain.rs | 0 .../cuprate-blockchain}/src/ops/key_image.rs | 0 .../cuprate-blockchain}/src/ops/macros.rs | 0 .../cuprate-blockchain}/src/ops/mod.rs | 2 +- .../cuprate-blockchain}/src/ops/output.rs | 0 .../cuprate-blockchain}/src/ops/property.rs | 4 +- .../cuprate-blockchain}/src/ops/tx.rs | 0 .../cuprate-blockchain}/src/resize.rs | 16 ++-- .../cuprate-blockchain}/src/service/free.rs | 2 +- .../cuprate-blockchain}/src/service/mod.rs | 4 +- .../cuprate-blockchain}/src/service/read.rs | 0 .../cuprate-blockchain}/src/service/tests.rs | 0 .../cuprate-blockchain}/src/service/types.rs | 0 .../cuprate-blockchain}/src/service/write.rs | 0 .../cuprate-blockchain}/src/storable.rs | 10 +-- .../cuprate-blockchain}/src/table.rs | 0 .../cuprate-blockchain}/src/tables.rs | 4 +- .../cuprate-blockchain}/src/tests.rs | 2 +- .../cuprate-blockchain}/src/transaction.rs | 0 .../cuprate-blockchain}/src/types.rs | 20 ++--- .../src/unsafe_sendable.rs | 0 storage/cuprate-txpool/Cargo.toml | 6 ++ storage/cuprate-txpool/src/lib.rs | 1 + storage/database/Cargo.toml | 6 ++ storage/database/src/lib.rs | 1 + zmq/README.md | 1 + 70 files changed, 209 insertions(+), 139 deletions(-) create mode 100644 benches/README.md create mode 100644 binaries/README.md create mode 100644 books/README.md create mode 100644 books/architecture/README.md create mode 100644 books/protocol/README.md create mode 100644 rpc/README.md create mode 100644 storage/README.md rename {database => storage/cuprate-blockchain}/Cargo.toml (78%) rename {database => storage/cuprate-blockchain}/README.md (99%) rename {database => storage/cuprate-blockchain}/src/backend/heed/database.rs (100%) rename {database => storage/cuprate-blockchain}/src/backend/heed/env.rs (99%) rename {database => storage/cuprate-blockchain}/src/backend/heed/error.rs (98%) rename {database => storage/cuprate-blockchain}/src/backend/heed/mod.rs (100%) rename {database => storage/cuprate-blockchain}/src/backend/heed/storable.rs (96%) rename {database => storage/cuprate-blockchain}/src/backend/heed/transaction.rs (100%) rename {database => storage/cuprate-blockchain}/src/backend/heed/types.rs (100%) rename {database => storage/cuprate-blockchain}/src/backend/mod.rs (100%) rename {database => storage/cuprate-blockchain}/src/backend/redb/database.rs (100%) rename {database => storage/cuprate-blockchain}/src/backend/redb/env.rs (99%) rename {database => storage/cuprate-blockchain}/src/backend/redb/error.rs (98%) rename {database => storage/cuprate-blockchain}/src/backend/redb/mod.rs (100%) rename {database => storage/cuprate-blockchain}/src/backend/redb/storable.rs (98%) rename {database => storage/cuprate-blockchain}/src/backend/redb/transaction.rs (100%) rename {database => storage/cuprate-blockchain}/src/backend/redb/types.rs (100%) rename {database => storage/cuprate-blockchain}/src/backend/tests.rs (99%) rename {database => storage/cuprate-blockchain}/src/config/backend.rs (94%) rename {database => storage/cuprate-blockchain}/src/config/config.rs (91%) rename {database => storage/cuprate-blockchain}/src/config/mod.rs (92%) rename {database => storage/cuprate-blockchain}/src/config/reader_threads.rs (97%) rename {database => storage/cuprate-blockchain}/src/config/sync_mode.rs (100%) rename {database => storage/cuprate-blockchain}/src/constants.rs (95%) rename {database => storage/cuprate-blockchain}/src/database.rs (100%) rename {database => storage/cuprate-blockchain}/src/env.rs (100%) rename {database => storage/cuprate-blockchain}/src/error.rs (98%) rename {database => storage/cuprate-blockchain}/src/free.rs (100%) rename {database => storage/cuprate-blockchain}/src/key.rs (97%) rename {database => storage/cuprate-blockchain}/src/lib.rs (97%) rename {database => storage/cuprate-blockchain}/src/ops/block.rs (100%) rename {database => storage/cuprate-blockchain}/src/ops/blockchain.rs (100%) rename {database => storage/cuprate-blockchain}/src/ops/key_image.rs (100%) rename {database => storage/cuprate-blockchain}/src/ops/macros.rs (100%) rename {database => storage/cuprate-blockchain}/src/ops/mod.rs (99%) rename {database => storage/cuprate-blockchain}/src/ops/output.rs (100%) rename {database => storage/cuprate-blockchain}/src/ops/property.rs (87%) rename {database => storage/cuprate-blockchain}/src/ops/tx.rs (100%) rename {database => storage/cuprate-blockchain}/src/resize.rs (96%) rename {database => storage/cuprate-blockchain}/src/service/free.rs (94%) rename {database => storage/cuprate-blockchain}/src/service/mod.rs (96%) rename {database => storage/cuprate-blockchain}/src/service/read.rs (100%) rename {database => storage/cuprate-blockchain}/src/service/tests.rs (100%) rename {database => storage/cuprate-blockchain}/src/service/types.rs (100%) rename {database => storage/cuprate-blockchain}/src/service/write.rs (100%) rename {database => storage/cuprate-blockchain}/src/storable.rs (97%) rename {database => storage/cuprate-blockchain}/src/table.rs (100%) rename {database => storage/cuprate-blockchain}/src/tables.rs (99%) rename {database => storage/cuprate-blockchain}/src/tests.rs (98%) rename {database => storage/cuprate-blockchain}/src/transaction.rs (100%) rename {database => storage/cuprate-blockchain}/src/types.rs (96%) rename {database => storage/cuprate-blockchain}/src/unsafe_sendable.rs (100%) create mode 100644 storage/cuprate-txpool/Cargo.toml create mode 100644 storage/cuprate-txpool/src/lib.rs create mode 100644 storage/database/Cargo.toml create mode 100644 storage/database/src/lib.rs create mode 100644 zmq/README.md diff --git a/.github/labeler.yml b/.github/labeler.yml index 1a71a240..6dea11cd 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -30,13 +30,31 @@ A-consensus: # This is the tag name # will cause the `github-actions` bot # to add the `A-consensus` tag. +# Cuprate's books. +A-books: +- changed-files: + - any-glob-to-any-file: books/** + +A-book-architecture: +- changed-files: + - any-glob-to-any-file: books/architecture/** + +A-book-protocol: +- changed-files: + - any-glob-to-any-file: books/protocol/** + +# Crate (sub-)directories. +A-binaries: +- changed-files: + - any-glob-to-any-file: binaries/** + A-cryptonight: - changed-files: - any-glob-to-any-file: cryptonight/** -A-database: +A-storage: - changed-files: - - any-glob-to-any-file: database/** + - any-glob-to-any-file: storage/** A-helper: - changed-files: @@ -62,10 +80,24 @@ A-types: - changed-files: - any-glob-to-any-file: types/** +A-rpc: +- changed-files: + - any-glob-to-any-file: rpc/** + +A-zmq: +- changed-files: + - any-glob-to-any-file: zmq/** + +# CI files. A-ci: - changed-files: - any-glob-to-any-file: .github/** +# Misc +A-benches: +- changed-files: + - any-glob-to-any-file: benches/** # Benchmarks + A-dependency: - changed-files: - any-glob-to-any-file: '**/Cargo.toml' # Any Cargo file in the entire repo @@ -74,7 +106,9 @@ A-dependency: A-workspace: - changed-files: - any-glob-to-any-file: '*' # Any root file change + - any-glob-to-any-file: misc/** A-docs: - changed-files: - any-glob-to-any-file: '**/*.md' # Any file in the entire repo ending in `.md` + # `A-books` label is used for book documentation. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b45a5431..7cee92a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -133,7 +133,7 @@ jobs: - name: Test run: | cargo test --all-features --workspace - cargo test --package cuprate-database --no-default-features --features redb --features service + cargo test --package cuprate-blockchain --no-default-features --features redb --features service # TODO: upload binaries with `actions/upload-artifact@v3` - name: Build diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 742ebaef..f27de2af 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,14 +49,13 @@ This section is primarily targeted at maintainers. Most contributors aren't able | Labels | Description | Example | |--------------|-------------|---------| -| [A-] | The **area** of the project an issue relates to. | `A-database`, `A-rpc`, `A-docs` +| [A-] | The **area** of the project an issue relates to. | `A-storage`, `A-rpc`, `A-docs` | [C-] | The **category** of an issue. | `C-cleanup`, `C-optimization` | [D-] | Issues for **diagnostics**. | `D-confusing`, `D-verbose` | [E-] | The **experience** level necessary to fix an issue. | `E-easy`, `E-hard` | [I-] | The **importance** of the issue. | `I-crash`, `I-memory` | [O-] | The **operating system** or platform that the issue is specific to. | `O-windows`, `O-macos`, `O-linux` | [P-] | The issue **priority**. These labels can be assigned by anyone that understand the issue and is able to prioritize it, and remove the [I-prioritize] label. | `P-high`, `P-low` -| [wontfix] | Indicates an issue will not be fixed. | | [A-]: https://github.com/Cuprate/cuprate/labels?q=A [C-]: https://github.com/Cuprate/cuprate/labels?q=C @@ -65,4 +64,3 @@ This section is primarily targeted at maintainers. Most contributors aren't able [I-]: https://github.com/Cuprate/cuprate/labels?q=I [O-]: https://github.com/Cuprate/cuprate/labels?q=O [P-]: https://github.com/Cuprate/cuprate/labels?q=P -[wontfix]: https://github.com/Cuprate/cuprate/labels?q=wontfix \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 6a081885..2855514f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -495,6 +495,39 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cuprate-blockchain" +version = "0.0.0" +dependencies = [ + "bitflags 2.5.0", + "bytemuck", + "bytes", + "cfg-if", + "crossbeam", + "cuprate-helper", + "cuprate-test-utils", + "cuprate-types", + "curve25519-dalek", + "futures", + "heed", + "hex", + "hex-literal", + "monero-pruning", + "monero-serai", + "page_size", + "paste", + "pretty_assertions", + "rayon", + "redb", + "serde", + "tempfile", + "thiserror", + "thread_local", + "tokio", + "tokio-util", + "tower", +] + [[package]] name = "cuprate-consensus" version = "0.1.0" @@ -528,39 +561,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "cuprate-database" -version = "0.0.0" -dependencies = [ - "bitflags 2.5.0", - "bytemuck", - "bytes", - "cfg-if", - "crossbeam", - "cuprate-helper", - "cuprate-test-utils", - "cuprate-types", - "curve25519-dalek", - "futures", - "heed", - "hex", - "hex-literal", - "monero-pruning", - "monero-serai", - "page_size", - "paste", - "pretty_assertions", - "rayon", - "redb", - "serde", - "tempfile", - "thiserror", - "thread_local", - "tokio", - "tokio-util", - "tower", -] - [[package]] name = "cuprate-helper" version = "0.1.0" @@ -628,6 +628,10 @@ dependencies = [ "tokio-util", ] +[[package]] +name = "cuprate-txpool" +version = "0.0.0" + [[package]] name = "cuprate-types" version = "0.0.0" @@ -713,6 +717,10 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "database" +version = "0.0.0" + [[package]] name = "diff" version = "0.1.13" diff --git a/Cargo.toml b/Cargo.toml index 987d93d3..c1ebaf20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,6 @@ members = [ "consensus", "consensus/rules", "cryptonight", - "database", "helper", "net/epee-encoding", "net/fixed-bytes", @@ -15,6 +14,9 @@ members = [ "p2p/dandelion", "p2p/monero-p2p", "p2p/address-book", + "storage/cuprate-blockchain", + "storage/cuprate-txpool", + "storage/database", "pruning", "test-utils", "types", diff --git a/benches/README.md b/benches/README.md new file mode 100644 index 00000000..46409041 --- /dev/null +++ b/benches/README.md @@ -0,0 +1 @@ +# TODO diff --git a/binaries/README.md b/binaries/README.md new file mode 100644 index 00000000..46409041 --- /dev/null +++ b/binaries/README.md @@ -0,0 +1 @@ +# TODO diff --git a/books/README.md b/books/README.md new file mode 100644 index 00000000..46409041 --- /dev/null +++ b/books/README.md @@ -0,0 +1 @@ +# TODO diff --git a/books/architecture/README.md b/books/architecture/README.md new file mode 100644 index 00000000..46409041 --- /dev/null +++ b/books/architecture/README.md @@ -0,0 +1 @@ +# TODO diff --git a/books/protocol/README.md b/books/protocol/README.md new file mode 100644 index 00000000..46409041 --- /dev/null +++ b/books/protocol/README.md @@ -0,0 +1 @@ +# TODO diff --git a/helper/src/fs.rs b/helper/src/fs.rs index a6ece515..1efb20cb 100644 --- a/helper/src/fs.rs +++ b/helper/src/fs.rs @@ -68,7 +68,7 @@ pub const CUPRATE_DIR: &str = { /// - [`cuprate_cache_dir()`] /// - [`cuprate_config_dir()`] /// - [`cuprate_data_dir()`] -/// - [`cuprate_database_dir()`] +/// - [`cuprate_blockchain_dir()`] /// /// FIXME: Use `LazyLock` when stabilized. /// . @@ -166,18 +166,18 @@ impl_path_oncelock_and_fn! { data_dir, "", - /// Cuprate's database directory. + /// Cuprate's blockchain directory. /// - /// This is the PATH used for any Cuprate database files. + /// This is the PATH used for any Cuprate blockchain files. /// - /// | OS | PATH | - /// |---------|--------------------------------------------------------------| - /// | Windows | `C:\Users\Alice\AppData\Roaming\Cuprate\database\` | - /// | macOS | `/Users/Alice/Library/Application Support/Cuprate/database/` | - /// | Linux | `/home/alice/.local/share/cuprate/database/` | - cuprate_database_dir, + /// | OS | PATH | + /// |---------|----------------------------------------------------------------| + /// | Windows | `C:\Users\Alice\AppData\Roaming\Cuprate\blockchain\` | + /// | macOS | `/Users/Alice/Library/Application Support/Cuprate/blockchain/` | + /// | Linux | `/home/alice/.local/share/cuprate/blockchain/` | + cuprate_blockchain_dir, data_dir, - "database", + "blockchain", } //---------------------------------------------------------------------------------------------------- Tests @@ -195,7 +195,7 @@ mod test { assert!(cuprate_cache_dir().is_absolute()); assert!(cuprate_config_dir().is_absolute()); assert!(cuprate_data_dir().is_absolute()); - assert!(cuprate_database_dir().is_absolute()); + assert!(cuprate_blockchain_dir().is_absolute()); if cfg!(target_os = "windows") { let dir = cuprate_cache_dir(); @@ -210,9 +210,9 @@ mod test { println!("cuprate_data_dir: {dir:?}"); assert!(dir.ends_with(r"AppData\Roaming\Cuprate")); - let dir = cuprate_database_dir(); - println!("cuprate_database_dir: {dir:?}"); - assert!(dir.ends_with(r"AppData\Roaming\Cuprate\database")); + let dir = cuprate_blockchain_dir(); + println!("cuprate_blockchain_dir: {dir:?}"); + assert!(dir.ends_with(r"AppData\Roaming\Cuprate\blockchain")); } else if cfg!(target_os = "macos") { let dir = cuprate_cache_dir(); println!("cuprate_cache_dir: {dir:?}"); @@ -226,9 +226,9 @@ mod test { println!("cuprate_data_dir: {dir:?}"); assert!(dir.ends_with("Library/Application Support/Cuprate")); - let dir = cuprate_database_dir(); - println!("cuprate_database_dir: {dir:?}"); - assert!(dir.ends_with("Library/Application Support/Cuprate/database")); + let dir = cuprate_blockchain_dir(); + println!("cuprate_blockchain_dir: {dir:?}"); + assert!(dir.ends_with("Library/Application Support/Cuprate/blockchain")); } else { // Assumes Linux. let dir = cuprate_cache_dir(); @@ -243,9 +243,9 @@ mod test { println!("cuprate_data_dir: {dir:?}"); assert!(dir.ends_with(".local/share/cuprate")); - let dir = cuprate_database_dir(); - println!("cuprate_database_dir: {dir:?}"); - assert!(dir.ends_with(".local/share/cuprate/database")); + let dir = cuprate_blockchain_dir(); + println!("cuprate_blockchain_dir: {dir:?}"); + assert!(dir.ends_with(".local/share/cuprate/blockchain")); } } } diff --git a/rpc/README.md b/rpc/README.md new file mode 100644 index 00000000..46409041 --- /dev/null +++ b/rpc/README.md @@ -0,0 +1 @@ +# TODO diff --git a/storage/README.md b/storage/README.md new file mode 100644 index 00000000..b04d8e78 --- /dev/null +++ b/storage/README.md @@ -0,0 +1,5 @@ +# storage + +TODO: This subdirectory used to be `database/` and is in the middle of being shifted around. + +The old `database/` design document is in `cuprate-blockchain/` which will eventually be ported Cuprate's architecture book. diff --git a/database/Cargo.toml b/storage/cuprate-blockchain/Cargo.toml similarity index 78% rename from database/Cargo.toml rename to storage/cuprate-blockchain/Cargo.toml index 712dbb16..bd61d595 100644 --- a/database/Cargo.toml +++ b/storage/cuprate-blockchain/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "cuprate-database" +name = "cuprate-blockchain" version = "0.0.0" edition = "2021" -description = "Cuprate's database abstraction" +description = "Cuprate's blockchain database" license = "MIT" authors = ["hinto-janai"] -repository = "https://github.com/Cuprate/cuprate/tree/main/database" -keywords = ["cuprate", "database"] +repository = "https://github.com/Cuprate/cuprate/tree/main/storage/cuprate-blockchain" +keywords = ["cuprate", "blockchain", "database"] [features] default = ["heed", "redb", "service"] @@ -25,10 +25,10 @@ cfg-if = { workspace = true } # FIXME: # We only need the `thread` feature if `service` is enabled. # Figure out how to enable features of an already pulled in dependency conditionally. -cuprate-helper = { path = "../helper", features = ["fs", "thread", "map"] } -cuprate-types = { path = "../types", features = ["service"] } +cuprate-helper = { path = "../../helper", features = ["fs", "thread", "map"] } +cuprate-types = { path = "../../types", features = ["service"] } curve25519-dalek = { workspace = true } -monero-pruning = { path = "../pruning" } +monero-pruning = { path = "../../pruning" } monero-serai = { workspace = true, features = ["std"] } paste = { workspace = true } page_size = { version = "0.6.0" } # Needed for database resizes, they must be a multiple of the OS page size. @@ -50,10 +50,10 @@ serde = { workspace = true, optional = true } [dev-dependencies] bytemuck = { version = "1.14.3", features = ["must_cast", "derive", "min_const_generics", "extern_crate_alloc"] } -cuprate-helper = { path = "../helper", features = ["thread"] } -cuprate-test-utils = { path = "../test-utils" } +cuprate-helper = { path = "../../helper", features = ["thread"] } +cuprate-test-utils = { path = "../../test-utils" } page_size = { version = "0.6.0" } tempfile = { version = "3.10.0" } pretty_assertions = { workspace = true } hex = { workspace = true } -hex-literal = { workspace = true } \ No newline at end of file +hex-literal = { workspace = true } diff --git a/database/README.md b/storage/cuprate-blockchain/README.md similarity index 99% rename from database/README.md rename to storage/cuprate-blockchain/README.md index 293413ac..22f729f0 100644 --- a/database/README.md +++ b/storage/cuprate-blockchain/README.md @@ -1,5 +1,7 @@ # Database -Cuprate's database implementation. +FIXME: This documentation must be updated and moved to the architecture book. + +Cuprate's blockchain implementation. - [1. Documentation](#1-documentation) - [2. File structure](#2-file-structure) @@ -595,4 +597,4 @@ struct PreRctOutputId { amount: 1, amount_index: 1 } This means `cuprated`'s database will be slightly larger than `monerod`'s. -The current method `cuprate_database` uses will be "good enough" until usage shows that it must be optimized as multimap tables are tricky to implement across all backends. \ No newline at end of file +The current method `cuprate_database` uses will be "good enough" until usage shows that it must be optimized as multimap tables are tricky to implement across all backends. diff --git a/database/src/backend/heed/database.rs b/storage/cuprate-blockchain/src/backend/heed/database.rs similarity index 100% rename from database/src/backend/heed/database.rs rename to storage/cuprate-blockchain/src/backend/heed/database.rs diff --git a/database/src/backend/heed/env.rs b/storage/cuprate-blockchain/src/backend/heed/env.rs similarity index 99% rename from database/src/backend/heed/env.rs rename to storage/cuprate-blockchain/src/backend/heed/env.rs index 56064849..703af4a8 100644 --- a/database/src/backend/heed/env.rs +++ b/storage/cuprate-blockchain/src/backend/heed/env.rs @@ -27,7 +27,7 @@ use crate::{ //---------------------------------------------------------------------------------------------------- Consts /// Panic message when there's a table missing. const PANIC_MSG_MISSING_TABLE: &str = - "cuprate_database::Env should uphold the invariant that all tables are already created"; + "cuprate_blockchain::Env should uphold the invariant that all tables are already created"; //---------------------------------------------------------------------------------------------------- ConcreteEnv /// A strongly typed, concrete database environment, backed by `heed`. diff --git a/database/src/backend/heed/error.rs b/storage/cuprate-blockchain/src/backend/heed/error.rs similarity index 98% rename from database/src/backend/heed/error.rs rename to storage/cuprate-blockchain/src/backend/heed/error.rs index c47bd908..c809e51c 100644 --- a/database/src/backend/heed/error.rs +++ b/storage/cuprate-blockchain/src/backend/heed/error.rs @@ -1,4 +1,4 @@ -//! Conversion from `heed::Error` -> `cuprate_database`'s errors. +//! Conversion from `heed::Error` -> `cuprate_blockchain`'s errors. //---------------------------------------------------------------------------------------------------- Use use crate::constants::DATABASE_CORRUPT_MSG; @@ -85,7 +85,7 @@ impl From for crate::RuntimeError { E2::Corrupted | E2::PageNotFound => panic!("{mdb_error:#?}\n{DATABASE_CORRUPT_MSG}"), // These errors should not occur, and if they do, - // the best thing `cuprate_database` can do for + // the best thing `cuprate_blockchain` can do for // safety is to panic right here. E2::Panic | E2::PageFull diff --git a/database/src/backend/heed/mod.rs b/storage/cuprate-blockchain/src/backend/heed/mod.rs similarity index 100% rename from database/src/backend/heed/mod.rs rename to storage/cuprate-blockchain/src/backend/heed/mod.rs diff --git a/database/src/backend/heed/storable.rs b/storage/cuprate-blockchain/src/backend/heed/storable.rs similarity index 96% rename from database/src/backend/heed/storable.rs rename to storage/cuprate-blockchain/src/backend/heed/storable.rs index 83442212..ebd8f6e6 100644 --- a/database/src/backend/heed/storable.rs +++ b/storage/cuprate-blockchain/src/backend/heed/storable.rs @@ -1,4 +1,4 @@ -//! `cuprate_database::Storable` <-> `heed` serde trait compatibility layer. +//! `cuprate_blockchain::Storable` <-> `heed` serde trait compatibility layer. //---------------------------------------------------------------------------------------------------- Use use std::{borrow::Cow, marker::PhantomData}; @@ -9,7 +9,7 @@ use crate::storable::Storable; //---------------------------------------------------------------------------------------------------- StorableHeed /// The glue struct that implements `heed`'s (de)serialization -/// traits on any type that implements `cuprate_database::Storable`. +/// traits on any type that implements `cuprate_blockchain::Storable`. /// /// Never actually gets constructed, just used for trait bound translations. pub(super) struct StorableHeed(PhantomData) diff --git a/database/src/backend/heed/transaction.rs b/storage/cuprate-blockchain/src/backend/heed/transaction.rs similarity index 100% rename from database/src/backend/heed/transaction.rs rename to storage/cuprate-blockchain/src/backend/heed/transaction.rs diff --git a/database/src/backend/heed/types.rs b/storage/cuprate-blockchain/src/backend/heed/types.rs similarity index 100% rename from database/src/backend/heed/types.rs rename to storage/cuprate-blockchain/src/backend/heed/types.rs diff --git a/database/src/backend/mod.rs b/storage/cuprate-blockchain/src/backend/mod.rs similarity index 100% rename from database/src/backend/mod.rs rename to storage/cuprate-blockchain/src/backend/mod.rs diff --git a/database/src/backend/redb/database.rs b/storage/cuprate-blockchain/src/backend/redb/database.rs similarity index 100% rename from database/src/backend/redb/database.rs rename to storage/cuprate-blockchain/src/backend/redb/database.rs diff --git a/database/src/backend/redb/env.rs b/storage/cuprate-blockchain/src/backend/redb/env.rs similarity index 99% rename from database/src/backend/redb/env.rs rename to storage/cuprate-blockchain/src/backend/redb/env.rs index e552d454..67e430f8 100644 --- a/database/src/backend/redb/env.rs +++ b/storage/cuprate-blockchain/src/backend/redb/env.rs @@ -22,7 +22,7 @@ pub struct ConcreteEnv { /// (and in current use). config: Config, - /// A cached, redb version of `cuprate_database::config::SyncMode`. + /// A cached, redb version of `cuprate_blockchain::config::SyncMode`. /// `redb` needs the sync mode to be set _per_ TX, so we /// will continue to use this value every `Env::tx_rw`. durability: redb::Durability, diff --git a/database/src/backend/redb/error.rs b/storage/cuprate-blockchain/src/backend/redb/error.rs similarity index 98% rename from database/src/backend/redb/error.rs rename to storage/cuprate-blockchain/src/backend/redb/error.rs index 4d40dbd9..1cc1456b 100644 --- a/database/src/backend/redb/error.rs +++ b/storage/cuprate-blockchain/src/backend/redb/error.rs @@ -1,4 +1,4 @@ -//! Conversion from `redb`'s errors -> `cuprate_database`'s errors. +//! Conversion from `redb`'s errors -> `cuprate_blockchain`'s errors. //! //! HACK: There's a lot of `_ =>` usage here because //! `redb`'s errors are `#[non_exhaustive]`... diff --git a/database/src/backend/redb/mod.rs b/storage/cuprate-blockchain/src/backend/redb/mod.rs similarity index 100% rename from database/src/backend/redb/mod.rs rename to storage/cuprate-blockchain/src/backend/redb/mod.rs diff --git a/database/src/backend/redb/storable.rs b/storage/cuprate-blockchain/src/backend/redb/storable.rs similarity index 98% rename from database/src/backend/redb/storable.rs rename to storage/cuprate-blockchain/src/backend/redb/storable.rs index 6735fec0..efe77dc5 100644 --- a/database/src/backend/redb/storable.rs +++ b/storage/cuprate-blockchain/src/backend/redb/storable.rs @@ -1,4 +1,4 @@ -//! `cuprate_database::Storable` <-> `redb` serde trait compatibility layer. +//! `cuprate_blockchain::Storable` <-> `redb` serde trait compatibility layer. //---------------------------------------------------------------------------------------------------- Use use std::{cmp::Ordering, fmt::Debug, marker::PhantomData}; @@ -9,7 +9,7 @@ use crate::{key::Key, storable::Storable}; //---------------------------------------------------------------------------------------------------- StorableRedb /// The glue structs that implements `redb`'s (de)serialization -/// traits on any type that implements `cuprate_database::Key`. +/// traits on any type that implements `cuprate_blockchain::Key`. /// /// Never actually get constructed, just used for trait bound translations. #[derive(Debug)] diff --git a/database/src/backend/redb/transaction.rs b/storage/cuprate-blockchain/src/backend/redb/transaction.rs similarity index 100% rename from database/src/backend/redb/transaction.rs rename to storage/cuprate-blockchain/src/backend/redb/transaction.rs diff --git a/database/src/backend/redb/types.rs b/storage/cuprate-blockchain/src/backend/redb/types.rs similarity index 100% rename from database/src/backend/redb/types.rs rename to storage/cuprate-blockchain/src/backend/redb/types.rs diff --git a/database/src/backend/tests.rs b/storage/cuprate-blockchain/src/backend/tests.rs similarity index 99% rename from database/src/backend/tests.rs rename to storage/cuprate-blockchain/src/backend/tests.rs index 03d06c69..3daec669 100644 --- a/database/src/backend/tests.rs +++ b/storage/cuprate-blockchain/src/backend/tests.rs @@ -1,4 +1,4 @@ -//! Tests for `cuprate_database`'s backends. +//! Tests for `cuprate_blockchain`'s backends. //! //! These tests are fully trait-based, meaning there //! is no reference to `backend/`-specific types. diff --git a/database/src/config/backend.rs b/storage/cuprate-blockchain/src/config/backend.rs similarity index 94% rename from database/src/config/backend.rs rename to storage/cuprate-blockchain/src/config/backend.rs index 4bbb12ca..ee72b3df 100644 --- a/database/src/config/backend.rs +++ b/storage/cuprate-blockchain/src/config/backend.rs @@ -10,7 +10,7 @@ use std::{ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use cuprate_helper::fs::cuprate_database_dir; +use cuprate_helper::fs::cuprate_blockchain_dir; use crate::{ config::{ReaderThreads, SyncMode}, diff --git a/database/src/config/config.rs b/storage/cuprate-blockchain/src/config/config.rs similarity index 91% rename from database/src/config/config.rs rename to storage/cuprate-blockchain/src/config/config.rs index d712cb69..9d932ab1 100644 --- a/database/src/config/config.rs +++ b/storage/cuprate-blockchain/src/config/config.rs @@ -9,7 +9,7 @@ use std::{ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use cuprate_helper::fs::cuprate_database_dir; +use cuprate_helper::fs::cuprate_blockchain_dir; use crate::{ config::{ReaderThreads, SyncMode}, @@ -55,7 +55,7 @@ impl ConfigBuilder { /// /// # Default values /// If [`ConfigBuilder::db_directory`] was not called, - /// the default [`cuprate_database_dir`] will be used. + /// the default [`cuprate_blockchain_dir`] will be used. /// /// For all other values, [`Default::default`] is used. pub fn build(self) -> Config { @@ -63,7 +63,7 @@ impl ConfigBuilder { // in `helper::fs`. No need to do them here. let db_directory = self .db_directory - .unwrap_or_else(|| Cow::Borrowed(cuprate_database_dir())); + .unwrap_or_else(|| Cow::Borrowed(cuprate_blockchain_dir())); // Add the database filename to the directory. let db_file = { @@ -137,7 +137,7 @@ impl ConfigBuilder { impl Default for ConfigBuilder { fn default() -> Self { Self { - db_directory: Some(Cow::Borrowed(cuprate_database_dir())), + db_directory: Some(Cow::Borrowed(cuprate_blockchain_dir())), sync_mode: Some(SyncMode::default()), reader_threads: Some(ReaderThreads::default()), resize_algorithm: Some(ResizeAlgorithm::default()), @@ -163,7 +163,7 @@ pub struct Config { /// The directory used to store all database files. /// /// By default, if no value is provided in the [`Config`] - /// constructor functions, this will be [`cuprate_database_dir`]. + /// constructor functions, this will be [`cuprate_blockchain_dir`]. /// // SOMEDAY: we should also support `/etc/cuprated.conf`. // This could be represented with an `enum DbPath { Default, Custom, Etc, }` @@ -190,20 +190,20 @@ pub struct Config { impl Config { /// Create a new [`Config`] with sane default settings. /// - /// The [`Config::db_directory`] will be [`cuprate_database_dir`]. + /// The [`Config::db_directory`] will be [`cuprate_blockchain_dir`]. /// /// All other values will be [`Default::default`]. /// /// Same as [`Config::default`]. /// /// ```rust - /// use cuprate_database::{config::*, resize::*, DATABASE_DATA_FILENAME}; + /// use cuprate_blockchain::{config::*, resize::*, DATABASE_DATA_FILENAME}; /// use cuprate_helper::fs::*; /// /// let config = Config::new(); /// - /// assert_eq!(config.db_directory(), cuprate_database_dir()); - /// assert!(config.db_file().starts_with(cuprate_database_dir())); + /// assert_eq!(config.db_directory(), cuprate_blockchain_dir()); + /// assert!(config.db_file().starts_with(cuprate_blockchain_dir())); /// assert!(config.db_file().ends_with(DATABASE_DATA_FILENAME)); /// assert_eq!(config.sync_mode, SyncMode::default()); /// assert_eq!(config.reader_threads, ReaderThreads::default()); @@ -228,7 +228,7 @@ impl Default for Config { /// Same as [`Config::new`]. /// /// ```rust - /// # use cuprate_database::config::*; + /// # use cuprate_blockchain::config::*; /// assert_eq!(Config::default(), Config::new()); /// ``` fn default() -> Self { diff --git a/database/src/config/mod.rs b/storage/cuprate-blockchain/src/config/mod.rs similarity index 92% rename from database/src/config/mod.rs rename to storage/cuprate-blockchain/src/config/mod.rs index dfa4f674..141790b4 100644 --- a/database/src/config/mod.rs +++ b/storage/cuprate-blockchain/src/config/mod.rs @@ -12,7 +12,7 @@ //! //! # Example //! ```rust -//! use cuprate_database::{ +//! use cuprate_blockchain::{ //! Env, //! config::{ConfigBuilder, ReaderThreads, SyncMode} //! }; @@ -31,7 +31,7 @@ //! .build(); //! //! // Start a database `service` using this configuration. -//! let (reader_handle, _) = cuprate_database::service::init(config.clone())?; +//! let (reader_handle, _) = cuprate_blockchain::service::init(config.clone())?; //! // It's using the config we provided. //! assert_eq!(reader_handle.env().config(), &config); //! # Ok(()) } diff --git a/database/src/config/reader_threads.rs b/storage/cuprate-blockchain/src/config/reader_threads.rs similarity index 97% rename from database/src/config/reader_threads.rs rename to storage/cuprate-blockchain/src/config/reader_threads.rs index 34b20a88..04216e3e 100644 --- a/database/src/config/reader_threads.rs +++ b/storage/cuprate-blockchain/src/config/reader_threads.rs @@ -49,7 +49,7 @@ pub enum ReaderThreads { /// as such, it is equal to [`ReaderThreads::OnePerThread`]. /// /// ```rust - /// # use cuprate_database::config::*; + /// # use cuprate_blockchain::config::*; /// let reader_threads = ReaderThreads::from(0_usize); /// assert!(matches!(reader_threads, ReaderThreads::OnePerThread)); /// ``` @@ -81,7 +81,7 @@ pub enum ReaderThreads { /// non-zero, but not 1 thread, the minimum value 1 will be returned. /// /// ```rust - /// # use cuprate_database::config::*; + /// # use cuprate_blockchain::config::*; /// assert_eq!(ReaderThreads::Percent(0.000000001).as_threads().get(), 1); /// ``` Percent(f32), @@ -97,7 +97,7 @@ impl ReaderThreads { /// /// # Example /// ```rust - /// use cuprate_database::config::ReaderThreads as Rt; + /// use cuprate_blockchain::config::ReaderThreads as Rt; /// /// let total_threads: std::num::NonZeroUsize = /// cuprate_helper::thread::threads(); diff --git a/database/src/config/sync_mode.rs b/storage/cuprate-blockchain/src/config/sync_mode.rs similarity index 100% rename from database/src/config/sync_mode.rs rename to storage/cuprate-blockchain/src/config/sync_mode.rs diff --git a/database/src/constants.rs b/storage/cuprate-blockchain/src/constants.rs similarity index 95% rename from database/src/constants.rs rename to storage/cuprate-blockchain/src/constants.rs index 667e36cb..25837c23 100644 --- a/database/src/constants.rs +++ b/storage/cuprate-blockchain/src/constants.rs @@ -1,4 +1,4 @@ -//! General constants used throughout `cuprate-database`. +//! General constants used throughout `cuprate-blockchain`. //---------------------------------------------------------------------------------------------------- Import use cfg_if::cfg_if; @@ -8,7 +8,7 @@ use cfg_if::cfg_if; /// /// Returned by [`crate::ops::property::db_version`]. /// -/// This is incremented by 1 when `cuprate_database`'s +/// This is incremented by 1 when `cuprate_blockchain`'s /// structure/schema/tables change. /// /// This is akin to `VERSION` in `monerod`: diff --git a/database/src/database.rs b/storage/cuprate-blockchain/src/database.rs similarity index 100% rename from database/src/database.rs rename to storage/cuprate-blockchain/src/database.rs diff --git a/database/src/env.rs b/storage/cuprate-blockchain/src/env.rs similarity index 100% rename from database/src/env.rs rename to storage/cuprate-blockchain/src/env.rs diff --git a/database/src/error.rs b/storage/cuprate-blockchain/src/error.rs similarity index 98% rename from database/src/error.rs rename to storage/cuprate-blockchain/src/error.rs index e47634f6..6112d92f 100644 --- a/database/src/error.rs +++ b/storage/cuprate-blockchain/src/error.rs @@ -66,7 +66,7 @@ pub enum InitError { /// 2. (De)serialization /// 3. Shutdown errors /// -/// as `cuprate_database` upholds the invariant that: +/// as `cuprate_blockchain` upholds the invariant that: /// /// 1. All tables exist /// 2. (De)serialization never fails diff --git a/database/src/free.rs b/storage/cuprate-blockchain/src/free.rs similarity index 100% rename from database/src/free.rs rename to storage/cuprate-blockchain/src/free.rs diff --git a/database/src/key.rs b/storage/cuprate-blockchain/src/key.rs similarity index 97% rename from database/src/key.rs rename to storage/cuprate-blockchain/src/key.rs index 13f7cede..daafc6bb 100644 --- a/database/src/key.rs +++ b/storage/cuprate-blockchain/src/key.rs @@ -23,7 +23,7 @@ pub trait Key: Storable + Sized { /// not a comparison of the key's value. /// /// ```rust - /// # use cuprate_database::*; + /// # use cuprate_blockchain::*; /// assert_eq!( /// ::compare([0].as_slice(), [1].as_slice()), /// std::cmp::Ordering::Less, diff --git a/database/src/lib.rs b/storage/cuprate-blockchain/src/lib.rs similarity index 97% rename from database/src/lib.rs rename to storage/cuprate-blockchain/src/lib.rs index f1d2b2eb..7e7970fe 100644 --- a/database/src/lib.rs +++ b/storage/cuprate-blockchain/src/lib.rs @@ -1,6 +1,6 @@ //! Cuprate's database abstraction. //! -//! This documentation is mostly for practical usage of `cuprate_database`. +//! This documentation is mostly for practical usage of `cuprate_blockchain`. //! //! For a high-level overview, //! see [`database/README.md`](https://github.com/Cuprate/cuprate/blob/main/database/README.md). @@ -13,7 +13,7 @@ //! //! Each layer builds on-top of the previous. //! -//! As a user of `cuprate_database`, consider using the higher-level [`service`] module, +//! As a user of `cuprate_blockchain`, consider using the higher-level [`service`] module, //! or at the very least the [`ops`] module instead of interacting with the database traits directly. //! //! With that said, many database traits and internals (like [`DatabaseRo::get`]) are exposed. @@ -82,7 +82,7 @@ //! //! //! # Invariants when not using `service` -//! `cuprate_database` can be used without the `service` feature enabled but +//! `cuprate_blockchain` can be used without the `service` feature enabled but //! there are some things that must be kept in mind when doing so. //! //! Failing to uphold these invariants may cause panics. @@ -92,7 +92,7 @@ //! 1. `LMDB` has [maximum key/value byte size](http://www.lmdb.tech/doc/group__internal.html#gac929399f5d93cef85f874b9e9b1d09e0) which must not be exceeded //! //! # Examples -//! The below is an example of using `cuprate_database`'s +//! The below is an example of using `cuprate_blockchain`'s //! lowest API, i.e. using the database directly. //! //! For examples of the higher-level APIs, see: @@ -100,7 +100,7 @@ //! - [`service`] //! //! ```rust -//! use cuprate_database::{ +//! use cuprate_blockchain::{ //! ConcreteEnv, //! config::ConfigBuilder, //! Env, EnvInner, diff --git a/database/src/ops/block.rs b/storage/cuprate-blockchain/src/ops/block.rs similarity index 100% rename from database/src/ops/block.rs rename to storage/cuprate-blockchain/src/ops/block.rs diff --git a/database/src/ops/blockchain.rs b/storage/cuprate-blockchain/src/ops/blockchain.rs similarity index 100% rename from database/src/ops/blockchain.rs rename to storage/cuprate-blockchain/src/ops/blockchain.rs diff --git a/database/src/ops/key_image.rs b/storage/cuprate-blockchain/src/ops/key_image.rs similarity index 100% rename from database/src/ops/key_image.rs rename to storage/cuprate-blockchain/src/ops/key_image.rs diff --git a/database/src/ops/macros.rs b/storage/cuprate-blockchain/src/ops/macros.rs similarity index 100% rename from database/src/ops/macros.rs rename to storage/cuprate-blockchain/src/ops/macros.rs diff --git a/database/src/ops/mod.rs b/storage/cuprate-blockchain/src/ops/mod.rs similarity index 99% rename from database/src/ops/mod.rs rename to storage/cuprate-blockchain/src/ops/mod.rs index 9f48bd65..a4f50dd0 100644 --- a/database/src/ops/mod.rs +++ b/storage/cuprate-blockchain/src/ops/mod.rs @@ -56,7 +56,7 @@ //! //! use cuprate_test_utils::data::block_v16_tx0; //! -//! use cuprate_database::{ +//! use cuprate_blockchain::{ //! ConcreteEnv, //! config::ConfigBuilder, //! Env, EnvInner, diff --git a/database/src/ops/output.rs b/storage/cuprate-blockchain/src/ops/output.rs similarity index 100% rename from database/src/ops/output.rs rename to storage/cuprate-blockchain/src/ops/output.rs diff --git a/database/src/ops/property.rs b/storage/cuprate-blockchain/src/ops/property.rs similarity index 87% rename from database/src/ops/property.rs rename to storage/cuprate-blockchain/src/ops/property.rs index 279c3552..2e584d87 100644 --- a/database/src/ops/property.rs +++ b/storage/cuprate-blockchain/src/ops/property.rs @@ -13,7 +13,7 @@ use crate::{error::RuntimeError, ops::macros::doc_error}; /// /// # Example /// ```rust -/// # use cuprate_database::{*, tables::*, ops::block::*, ops::tx::*}; +/// # use cuprate_blockchain::{*, tables::*, ops::block::*, ops::tx::*}; /// // SOMEDAY /// ``` #[inline] @@ -29,7 +29,7 @@ pub const fn get_blockchain_pruning_seed() -> Result /// /// # Example /// ```rust -/// # use cuprate_database::{*, tables::*, ops::block::*, ops::tx::*}; +/// # use cuprate_blockchain::{*, tables::*, ops::block::*, ops::tx::*}; /// // SOMEDAY /// ``` #[inline] diff --git a/database/src/ops/tx.rs b/storage/cuprate-blockchain/src/ops/tx.rs similarity index 100% rename from database/src/ops/tx.rs rename to storage/cuprate-blockchain/src/ops/tx.rs diff --git a/database/src/resize.rs b/storage/cuprate-blockchain/src/resize.rs similarity index 96% rename from database/src/resize.rs rename to storage/cuprate-blockchain/src/resize.rs index 99d6d7e3..488325be 100644 --- a/database/src/resize.rs +++ b/storage/cuprate-blockchain/src/resize.rs @@ -50,7 +50,7 @@ impl ResizeAlgorithm { /// Returns [`Self::Monero`]. /// /// ```rust - /// # use cuprate_database::resize::*; + /// # use cuprate_blockchain::resize::*; /// assert!(matches!(ResizeAlgorithm::new(), ResizeAlgorithm::Monero)); /// ``` #[inline] @@ -75,7 +75,7 @@ impl Default for ResizeAlgorithm { /// Calls [`Self::new`]. /// /// ```rust - /// # use cuprate_database::resize::*; + /// # use cuprate_blockchain::resize::*; /// assert_eq!(ResizeAlgorithm::new(), ResizeAlgorithm::default()); /// ``` #[inline] @@ -113,7 +113,7 @@ pub fn page_size() -> NonZeroUsize { /// [^2]: `1_073_745_920` /// /// ```rust -/// # use cuprate_database::resize::*; +/// # use cuprate_blockchain::resize::*; /// // The value this function will increment by /// // (assuming page multiple of 4096). /// const N: usize = 1_073_741_824; @@ -129,7 +129,7 @@ pub fn page_size() -> NonZeroUsize { /// This function will panic if adding onto `current_size_bytes` overflows [`usize::MAX`]. /// /// ```rust,should_panic -/// # use cuprate_database::resize::*; +/// # use cuprate_blockchain::resize::*; /// // Ridiculous large numbers panic. /// monero(usize::MAX); /// ``` @@ -166,7 +166,7 @@ pub fn monero(current_size_bytes: usize) -> NonZeroUsize { /// and then round up to nearest OS page size. /// /// ```rust -/// # use cuprate_database::resize::*; +/// # use cuprate_blockchain::resize::*; /// let page_size: usize = page_size().get(); /// /// // Anything below the page size will round up to the page size. @@ -185,7 +185,7 @@ pub fn monero(current_size_bytes: usize) -> NonZeroUsize { /// This function will panic if adding onto `current_size_bytes` overflows [`usize::MAX`]. /// /// ```rust,should_panic -/// # use cuprate_database::resize::*; +/// # use cuprate_blockchain::resize::*; /// // Ridiculous large numbers panic. /// fixed_bytes(1, usize::MAX); /// ``` @@ -221,7 +221,7 @@ pub fn fixed_bytes(current_size_bytes: usize, add_bytes: usize) -> NonZeroUsize /// (rounded up to the OS page size). /// /// ```rust -/// # use cuprate_database::resize::*; +/// # use cuprate_blockchain::resize::*; /// let page_size: usize = page_size().get(); /// /// // Anything below the page size will round up to the page size. @@ -247,7 +247,7 @@ pub fn fixed_bytes(current_size_bytes: usize, add_bytes: usize) -> NonZeroUsize /// is closer to [`usize::MAX`] than the OS page size. /// /// ```rust,should_panic -/// # use cuprate_database::resize::*; +/// # use cuprate_blockchain::resize::*; /// // Ridiculous large numbers panic. /// percent(usize::MAX, 1.001); /// ``` diff --git a/database/src/service/free.rs b/storage/cuprate-blockchain/src/service/free.rs similarity index 94% rename from database/src/service/free.rs rename to storage/cuprate-blockchain/src/service/free.rs index fb40a065..276ce6a8 100644 --- a/database/src/service/free.rs +++ b/storage/cuprate-blockchain/src/service/free.rs @@ -1,4 +1,4 @@ -//! General free functions used (related to `cuprate_database::service`). +//! General free functions used (related to `cuprate_blockchain::service`). //---------------------------------------------------------------------------------------------------- Import use std::sync::Arc; diff --git a/database/src/service/mod.rs b/storage/cuprate-blockchain/src/service/mod.rs similarity index 96% rename from database/src/service/mod.rs rename to storage/cuprate-blockchain/src/service/mod.rs index ca5c9e6f..a95276a7 100644 --- a/database/src/service/mod.rs +++ b/storage/cuprate-blockchain/src/service/mod.rs @@ -66,7 +66,7 @@ //! use cuprate_types::service::{ReadRequest, WriteRequest, Response}; //! use cuprate_test_utils::data::block_v16_tx0; //! -//! use cuprate_database::{ConcreteEnv, config::ConfigBuilder, Env}; +//! use cuprate_blockchain::{ConcreteEnv, config::ConfigBuilder, Env}; //! //! # #[tokio::main] //! # async fn main() -> Result<(), Box> { @@ -77,7 +77,7 @@ //! .build(); //! //! // Initialize the database thread-pool. -//! let (mut read_handle, mut write_handle) = cuprate_database::service::init(config)?; +//! let (mut read_handle, mut write_handle) = cuprate_blockchain::service::init(config)?; //! //! // Prepare a request to write block. //! let mut block = block_v16_tx0().clone(); diff --git a/database/src/service/read.rs b/storage/cuprate-blockchain/src/service/read.rs similarity index 100% rename from database/src/service/read.rs rename to storage/cuprate-blockchain/src/service/read.rs diff --git a/database/src/service/tests.rs b/storage/cuprate-blockchain/src/service/tests.rs similarity index 100% rename from database/src/service/tests.rs rename to storage/cuprate-blockchain/src/service/tests.rs diff --git a/database/src/service/types.rs b/storage/cuprate-blockchain/src/service/types.rs similarity index 100% rename from database/src/service/types.rs rename to storage/cuprate-blockchain/src/service/types.rs diff --git a/database/src/service/write.rs b/storage/cuprate-blockchain/src/service/write.rs similarity index 100% rename from database/src/service/write.rs rename to storage/cuprate-blockchain/src/service/write.rs diff --git a/database/src/storable.rs b/storage/cuprate-blockchain/src/storable.rs similarity index 97% rename from database/src/storable.rs rename to storage/cuprate-blockchain/src/storable.rs index f259523f..80d010c6 100644 --- a/database/src/storable.rs +++ b/storage/cuprate-blockchain/src/storable.rs @@ -29,7 +29,7 @@ use bytes::Bytes; /// See [`StorableVec`] & [`StorableBytes`] for storing slices of `T: Storable`. /// /// ```rust -/// # use cuprate_database::*; +/// # use cuprate_blockchain::*; /// # use std::borrow::*; /// let number: u64 = 0; /// @@ -77,7 +77,7 @@ pub trait Storable: Debug { /// /// # Examples /// ```rust - /// # use cuprate_database::*; + /// # use cuprate_blockchain::*; /// assert_eq!(<()>::BYTE_LENGTH, Some(0)); /// assert_eq!(u8::BYTE_LENGTH, Some(1)); /// assert_eq!(u16::BYTE_LENGTH, Some(2)); @@ -99,7 +99,7 @@ pub trait Storable: Debug { /// /// # Blanket implementation /// The blanket implementation that covers all types used - /// by `cuprate_database` will simply bitwise copy `bytes` + /// by `cuprate_blockchain` will simply bitwise copy `bytes` /// into `Self`. /// /// The bytes do not have be correctly aligned. @@ -136,7 +136,7 @@ where /// /// # Example /// ```rust -/// # use cuprate_database::*; +/// # use cuprate_blockchain::*; /// //---------------------------------------------------- u8 /// let vec: StorableVec = StorableVec(vec![0,1]); /// @@ -202,7 +202,7 @@ impl Borrow<[T]> for StorableVec { /// A [`Storable`] version of [`Bytes`]. /// /// ```rust -/// # use cuprate_database::*; +/// # use cuprate_blockchain::*; /// # use bytes::Bytes; /// let bytes: StorableBytes = StorableBytes(Bytes::from_static(&[0,1])); /// diff --git a/database/src/table.rs b/storage/cuprate-blockchain/src/table.rs similarity index 100% rename from database/src/table.rs rename to storage/cuprate-blockchain/src/table.rs diff --git a/database/src/tables.rs b/storage/cuprate-blockchain/src/tables.rs similarity index 99% rename from database/src/tables.rs rename to storage/cuprate-blockchain/src/tables.rs index 0056b0bd..3bdad943 100644 --- a/database/src/tables.rs +++ b/storage/cuprate-blockchain/src/tables.rs @@ -1,7 +1,7 @@ //! Database tables. //! //! # Table marker structs -//! This module contains all the table definitions used by `cuprate_database`. +//! This module contains all the table definitions used by `cuprate_blockchain`. //! //! The zero-sized structs here represents the table type; //! they all are essentially marker types that implement [`Table`]. @@ -331,7 +331,7 @@ macro_rules! tables { /// /// ## Table Name /// ```rust - /// # use cuprate_database::{*,tables::*}; + /// # use cuprate_blockchain::{*,tables::*}; #[doc = concat!( "assert_eq!(", stringify!([<$table:camel>]), diff --git a/database/src/tests.rs b/storage/cuprate-blockchain/src/tests.rs similarity index 98% rename from database/src/tests.rs rename to storage/cuprate-blockchain/src/tests.rs index ba5e8550..90a74137 100644 --- a/database/src/tests.rs +++ b/storage/cuprate-blockchain/src/tests.rs @@ -1,4 +1,4 @@ -//! Utilities for `cuprate_database` testing. +//! Utilities for `cuprate_blockchain` testing. //! //! These types/fn's are only: //! - enabled on #[cfg(test)] diff --git a/database/src/transaction.rs b/storage/cuprate-blockchain/src/transaction.rs similarity index 100% rename from database/src/transaction.rs rename to storage/cuprate-blockchain/src/transaction.rs diff --git a/database/src/types.rs b/storage/cuprate-blockchain/src/types.rs similarity index 96% rename from database/src/types.rs rename to storage/cuprate-blockchain/src/types.rs index 5d89d4c4..2bb9aa0e 100644 --- a/database/src/types.rs +++ b/storage/cuprate-blockchain/src/types.rs @@ -105,7 +105,7 @@ pub type UnlockTime = u64; /// /// ```rust /// # use std::borrow::*; -/// # use cuprate_database::{*, types::*}; +/// # use cuprate_blockchain::{*, types::*}; /// // Assert Storable is correct. /// let a = PreRctOutputId { /// amount: 1, @@ -118,7 +118,7 @@ pub type UnlockTime = u64; /// /// # Size & Alignment /// ```rust -/// # use cuprate_database::types::*; +/// # use cuprate_blockchain::types::*; /// # use std::mem::*; /// assert_eq!(size_of::(), 16); /// assert_eq!(align_of::(), 8); @@ -148,7 +148,7 @@ pub struct PreRctOutputId { /// /// ```rust /// # use std::borrow::*; -/// # use cuprate_database::{*, types::*}; +/// # use cuprate_blockchain::{*, types::*}; /// // Assert Storable is correct. /// let a = BlockInfo { /// timestamp: 1, @@ -167,7 +167,7 @@ pub struct PreRctOutputId { /// /// # Size & Alignment /// ```rust -/// # use cuprate_database::types::*; +/// # use cuprate_blockchain::types::*; /// # use std::mem::*; /// assert_eq!(size_of::(), 88); /// assert_eq!(align_of::(), 8); @@ -207,7 +207,7 @@ bitflags::bitflags! { /// /// ```rust /// # use std::borrow::*; - /// # use cuprate_database::{*, types::*}; + /// # use cuprate_blockchain::{*, types::*}; /// // Assert Storable is correct. /// let a = OutputFlags::NON_ZERO_UNLOCK_TIME; /// let b = Storable::as_bytes(&a); @@ -217,7 +217,7 @@ bitflags::bitflags! { /// /// # Size & Alignment /// ```rust - /// # use cuprate_database::types::*; + /// # use cuprate_blockchain::types::*; /// # use std::mem::*; /// assert_eq!(size_of::(), 4); /// assert_eq!(align_of::(), 4); @@ -236,7 +236,7 @@ bitflags::bitflags! { /// /// ```rust /// # use std::borrow::*; -/// # use cuprate_database::{*, types::*}; +/// # use cuprate_blockchain::{*, types::*}; /// // Assert Storable is correct. /// let a = Output { /// key: [1; 32], @@ -251,7 +251,7 @@ bitflags::bitflags! { /// /// # Size & Alignment /// ```rust -/// # use cuprate_database::types::*; +/// # use cuprate_blockchain::types::*; /// # use std::mem::*; /// assert_eq!(size_of::(), 48); /// assert_eq!(align_of::(), 8); @@ -277,7 +277,7 @@ pub struct Output { /// /// ```rust /// # use std::borrow::*; -/// # use cuprate_database::{*, types::*}; +/// # use cuprate_blockchain::{*, types::*}; /// // Assert Storable is correct. /// let a = RctOutput { /// key: [1; 32], @@ -293,7 +293,7 @@ pub struct Output { /// /// # Size & Alignment /// ```rust -/// # use cuprate_database::types::*; +/// # use cuprate_blockchain::types::*; /// # use std::mem::*; /// assert_eq!(size_of::(), 80); /// assert_eq!(align_of::(), 8); diff --git a/database/src/unsafe_sendable.rs b/storage/cuprate-blockchain/src/unsafe_sendable.rs similarity index 100% rename from database/src/unsafe_sendable.rs rename to storage/cuprate-blockchain/src/unsafe_sendable.rs diff --git a/storage/cuprate-txpool/Cargo.toml b/storage/cuprate-txpool/Cargo.toml new file mode 100644 index 00000000..d08b2290 --- /dev/null +++ b/storage/cuprate-txpool/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "cuprate-txpool" +version = "0.0.0" +edition = "2021" + +[dependencies] diff --git a/storage/cuprate-txpool/src/lib.rs b/storage/cuprate-txpool/src/lib.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/storage/cuprate-txpool/src/lib.rs @@ -0,0 +1 @@ + diff --git a/storage/database/Cargo.toml b/storage/database/Cargo.toml new file mode 100644 index 00000000..b0351d12 --- /dev/null +++ b/storage/database/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "database" +version = "0.0.0" +edition = "2021" + +[dependencies] diff --git a/storage/database/src/lib.rs b/storage/database/src/lib.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/storage/database/src/lib.rs @@ -0,0 +1 @@ + diff --git a/zmq/README.md b/zmq/README.md new file mode 100644 index 00000000..46409041 --- /dev/null +++ b/zmq/README.md @@ -0,0 +1 @@ +# TODO From d052fbedf1e8acce60f2a10733b7dd747077432c Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Wed, 29 May 2024 13:34:32 -0400 Subject: [PATCH 6/7] repo: add issue templates (#137) * add issue templates * add `question.md` * fix bug.md * fix feature.md * bug.md: fix spacing --- .github/ISSUE_TEMPLATE/bug.md | 45 ++++++++++++++++++++++++++++ .github/ISSUE_TEMPLATE/discussion.md | 18 +++++++++++ .github/ISSUE_TEMPLATE/feature.md | 21 +++++++++++++ .github/ISSUE_TEMPLATE/proposal.md | 24 +++++++++++++++ .github/ISSUE_TEMPLATE/question.md | 15 ++++++++++ 5 files changed, 123 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug.md create mode 100644 .github/ISSUE_TEMPLATE/discussion.md create mode 100644 .github/ISSUE_TEMPLATE/feature.md create mode 100644 .github/ISSUE_TEMPLATE/proposal.md create mode 100644 .github/ISSUE_TEMPLATE/question.md diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md new file mode 100644 index 00000000..404bd6ad --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -0,0 +1,45 @@ +--- +name: 🐞 Bug report +about: Create a bug report +title: '' +labels: ["C-bug"] +assignees: '' + +--- + + + +## Environment +Example: +- OS: Windows 11 +- CPU: AMD Ryzen 5 5600X +- Memory: 16GB +- Storage: SSD 500GB +- Cuprate: v1.0.0 + +## Bug +What is the bug? + +### Expected behavior +What correct beahvior was expected to happen? + +## Steps to reproduce +Example: +1. In this environment... +2. With this config... +3. Run '...' +4. See error... + +## Log +If possible, add any related logs to help explain the bug. + +Note: please remove any sensitive information from the logs (e.g. IP address). + +## Screenshots +If possible, add screenshots to help explain the bug. + +Note: please remove any sensitive information from the screenshot. diff --git a/.github/ISSUE_TEMPLATE/discussion.md b/.github/ISSUE_TEMPLATE/discussion.md new file mode 100644 index 00000000..60444617 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/discussion.md @@ -0,0 +1,18 @@ +--- +name: ⏳ Discussion +about: Start a discussion on a topic +title: '' +labels: ["C-discussion"] +assignees: '' + +--- + + + +## What +What would you would like to discuss? + +## Why +Why would you would like to discuss this? diff --git a/.github/ISSUE_TEMPLATE/feature.md b/.github/ISSUE_TEMPLATE/feature.md new file mode 100644 index 00000000..dab48112 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature.md @@ -0,0 +1,21 @@ +--- +name: ✨ Feature request +about: Request a feature +title: '' +labels: ["C-request"] +assignees: '' + +--- + + + +## Feature +What is the feature you're requesting? + +## Why +Why should your feature be added? + +## Additional context +Add any other context or screenshots about the feature request. diff --git a/.github/ISSUE_TEMPLATE/proposal.md b/.github/ISSUE_TEMPLATE/proposal.md new file mode 100644 index 00000000..132b2b07 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/proposal.md @@ -0,0 +1,24 @@ +--- +name: 📜 Proposal +about: Propose an idea and request for comments +title: '' +labels: ["C-proposal"] +assignees: '' + +--- + + + +## What +Describe your proposal. + +## Where +Describe where your proposal will cause changes to. + +## Why +Describe why the proposal is needed. + +## How +Describe how the proposal could be implemented. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100644 index 00000000..af426a2d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,15 @@ +--- +name: ❓ Question +about: Ask a question +title: '' +labels: ["C-question"] +assignees: '' + +--- + + + +## Question +What question would you like to ask? From c50d9642be99af829144dca3cb9f732c467d7d62 Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Wed, 29 May 2024 15:00:29 -0400 Subject: [PATCH 7/7] storage: create Cargo.toml for `{database, cuprate-txpool}` (#140) --- storage/cuprate-txpool/Cargo.toml | 15 ++++++++++++--- storage/database/Cargo.toml | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/storage/cuprate-txpool/Cargo.toml b/storage/cuprate-txpool/Cargo.toml index d08b2290..536d445a 100644 --- a/storage/cuprate-txpool/Cargo.toml +++ b/storage/cuprate-txpool/Cargo.toml @@ -1,6 +1,15 @@ [package] -name = "cuprate-txpool" -version = "0.0.0" -edition = "2021" +name = "cuprate-txpool" +version = "0.0.0" +edition = "2021" +description = "Cuprate's transaction pool database" +license = "MIT" +authors = ["hinto-janai"] +repository = "https://github.com/Cuprate/cuprate/tree/main/storage/cuprate-txpool" +keywords = ["cuprate", "txpool", "transaction", "pool", "database"] + +[features] [dependencies] + +[dev-dependencies] diff --git a/storage/database/Cargo.toml b/storage/database/Cargo.toml index b0351d12..50bf0f7e 100644 --- a/storage/database/Cargo.toml +++ b/storage/database/Cargo.toml @@ -1,6 +1,15 @@ [package] -name = "database" -version = "0.0.0" -edition = "2021" +name = "database" +version = "0.0.0" +edition = "2021" +description = "Cuprate's database abstraction" +license = "MIT" +authors = ["hinto-janai"] +repository = "https://github.com/Cuprate/cuprate/tree/main/storage/database" +keywords = ["cuprate", "database"] + +[features] [dependencies] + +[dev-dependencies]