Skip to content

Commit

Permalink
Merge branch 'development' into schema-store
Browse files Browse the repository at this point in the history
* development:
  Make clippy happy
  We can't drop a reference
  Fix merge conflict
  Doc strings for entry and log store structs (#126)
  Improve CI, track test coverage (#139)
  Fix high CPU usage of idle workers (#136)
  • Loading branch information
adzialocha committed May 31, 2022
2 parents ae29cbb + 24c68a1 commit c7d6f5d
Show file tree
Hide file tree
Showing 22 changed files with 263 additions and 107 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.yml]
indent_size = 2
160 changes: 145 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,160 @@
name: tests
name: aquadoggo

on: push

env:
CARGO_TERM_COLOR: always
cache_path: |
target
~/.cargo
cargo_manifest: aquadoggo/Cargo.toml

jobs:
test:
name: build and test

rust-test-sqlite:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Cargo caching
uses: actions/cache@v2
- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
path: ${{ env.cache_path }}
key: ${{ runner.os }}-test-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build --verbose
- name: Build binary
uses: actions-rs/cargo@v1
with:
command: build
args: >-
--verbose
--manifest-path ${{ env.cargo_manifest }}
- name: Run tests
run: cargo test --verbose
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path ${{ env.cargo_manifest }}
# Ensure debug output is also tested
env:
RUST_LOG: debug

rust-check:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: ${{ env.cache_path }}
key: ${{ runner.os }}-check-${{ hashFiles('**/Cargo.lock') }}

- name: Check project and dependencies
uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path ${{ env.cargo_manifest }}

rust-fmt:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
override: true

- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: ${{ env.cache_path }}
key: ${{ runner.os }}-fmt-${{ hashFiles('**/Cargo.lock') }}

- name: Check formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --manifest-path ${{ env.cargo_manifest }} -- --check

rust-clippy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
override: true

- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: ${{ env.cache_path }}
key: ${{ runner.os }}-clippy-${{ hashFiles('**/Cargo.lock') }}

- name: Check code with clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --manifest-path ${{ env.cargo_manifest }} -- -D warnings --no-deps

rust-coverage:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: ${{ env.cache_path }}
key: ${{ runner.os }}-tarpaulin-${{ hashFiles('**/Cargo.lock') }}

- name: Run cargo-tarpaulin
uses: actions-rs/tarpaulin@v0.1
with:
# Force cleaning via `--force-clean` flag to prevent buggy code coverage
args: --manifest-path ${{ env.cargo_manifest }} --locked --force-clean
# Ensure debug output is also tested
env:
RUST_LOG: debug

- name: Upload to codecov.io
uses: codecov/codecov-action@v2
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Refactor module structure, propagate errors in worker to service manager [#97](https://github.com/p2panda/aquadoggo/pull/97)
- Restructure storage modules and remove JSON RPC [#101](https://github.com/p2panda/aquadoggo/pull/101)
- Implement new methods required for replication defined by `EntryStore` trait [#102](https://github.com/p2panda/aquadoggo/pull/102)
- Implement SQL `OperationStore` [103](https://github.com/p2panda/aquadoggo/pull/103)
- Implement SQL `OperationStore` [#103](https://github.com/p2panda/aquadoggo/pull/103)
- GraphQL client API with endpoint for retrieving next entry arguments [#119](https://github.com/p2panda/aquadoggo/pull/119)
- GraphQL endpoint for publishing entries [#123](https://github.com/p2panda/aquadoggo/pull/132)
- Implement SQL `DocumentStore` [#118](https://github.com/p2panda/aquadoggo/pull/118)
Expand All @@ -29,7 +29,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve `Signal` efficiency in `ServiceManager` [#95](https://github.com/p2panda/aquadoggo/pull/95)
- `EntryStore` improvements [#123](https://github.com/p2panda/aquadoggo/pull/123)
- Improvements for log and entry table layout [#124](https://github.com/p2panda/aquadoggo/issues/122)
- Update `StorageProvider` API after `p2panda-rs` changes [129](https://github.com/p2panda/aquadoggo/pull/129)
- Update `StorageProvider` API after `p2panda-rs` changes [#129](https://github.com/p2panda/aquadoggo/pull/129)

### Fixed

- Fix high CPU usage of idle workers [#136](https://github.com/p2panda/aquadoggo/pull/136)
- Improve CI, track test coverage [#139](https://github.com/p2panda/aquadoggo/pull/139)

## [0.2.0]

Expand Down
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<a href="https://github.com/p2panda/aquadoggo/actions">
<img src="https://img.shields.io/github/workflow/status/p2panda/aquadoggo/tests?style=flat-square" alt="CI Status" />
</a>
<!-- Codecov report -->
<a href="https://app.codecov.io/gh/p2panda/aquadoggo/">
<img src="https://img.shields.io/codecov/c/gh/p2panda/aquadoggo?style=flat-square" alt="Codecov Report" />
</a>
<!-- Crates version -->
<a href="https://crates.io/crates/aquadoggo">
<img src="https://img.shields.io/crates/v/aquadoggo.svg?style=flat-square" alt="Crates.io version" />
Expand Down
2 changes: 1 addition & 1 deletion aquadoggo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async-graphql = "3.0.35"
async-graphql-axum = "3.0.35"
axum = "0.5.1"
bamboo-rs-core-ed25519-yasmf = "0.1.1"
crossbeam-queue = "0.3.5"
deadqueue = { version = "0.2.2", default-features = false, features = ["unlimited"] }
directories = "3.0.2"
envy = "0.4.2"
futures = "0.3.17"
Expand Down
1 change: 1 addition & 0 deletions aquadoggo/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ pub type ServiceSender = Sender<ServiceMessage>;
#[derive(Clone)]
pub enum ServiceMessage {
/// New `Entry` with an `Operation` payload arrived at the node.
#[allow(dead_code)]
NewEntryAndOperation(Entry, Operation),
}
2 changes: 1 addition & 1 deletion aquadoggo/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ impl Deref for Context {
type Target = Data;

fn deref(&self) -> &Self::Target {
&self.0.as_ref()
self.0.as_ref()
}
}
3 changes: 2 additions & 1 deletion aquadoggo/src/db/models/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use serde::Serialize;
use sqlx::FromRow;

/// Struct representing the actual SQL row of `Entry`.
/// Representation of a row from the entries table as stored in the database. This is required
/// when coercing the returned results from a query with the `sqlx` library.
///
/// We store the u64 integer values of `log_id` and `seq_num` as strings since SQLite doesn't
/// support storing unsigned 64 bit integers.
Expand Down
6 changes: 2 additions & 4 deletions aquadoggo/src/db/models/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

use sqlx::FromRow;

/// Tracks the assigment of an author's logs to documents and records their schema.
///
/// This serves as an indexing layer on top of the lower-level bamboo entries. The node updates
/// this data according to what it sees in the newly incoming entries.
/// Representation of a row from the logs table as stored in the database. This is required
/// when coercing the returned results from a query with the `sqlx` library.
///
/// We store the u64 integer values of `log_id` as a string here since SQLite doesn't support
/// storing unsigned 64 bit integers.
Expand Down
21 changes: 18 additions & 3 deletions aquadoggo/src/db/stores/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

use async_trait::async_trait;
use lipmaa_link::get_lipmaa_links_back_to;
use p2panda_rs::storage_provider::ValidationError;
use p2panda_rs::Validate;
use sqlx::{query, query_as};

use p2panda_rs::entry::{decode_entry, Entry, EntrySigned, LogId, SeqNum};
Expand All @@ -13,10 +11,19 @@ use p2panda_rs::operation::{Operation, OperationEncoded};
use p2panda_rs::schema::SchemaId;
use p2panda_rs::storage_provider::errors::EntryStorageError;
use p2panda_rs::storage_provider::traits::{AsStorageEntry, EntryStore};
use p2panda_rs::storage_provider::ValidationError;
use p2panda_rs::Validate;

use crate::db::models::EntryRow;
use crate::db::provider::SqlStorage;

/// A signed entry and it's encoded operation. Entries are the lowest level data
/// type on the p2panda network, they are signed by authors and form bamboo append
/// only logs. The operation is an entries' payload, it contains the data mutations
/// which authors publish.
///
/// This struct implements the `AsStorageEntry` trait which is required when
/// constructing the `EntryStore`.
#[derive(Debug, Clone, PartialEq)]
pub struct StorageEntry {
entry_signed: EntrySigned,
Expand Down Expand Up @@ -51,6 +58,9 @@ impl Validate for StorageEntry {
}
}

/// `From` implementation for converting an `EntryRow` into a `StorageEntry`. This is useful
/// when retrieving entries from the database. The `sqlx` crate coerces returned entry rows
/// into `EntryRow` but we normally want them as `StorageEntry`.
impl From<EntryRow> for StorageEntry {
fn from(entry_row: EntryRow) -> Self {
// Unwrapping everything here as we assume values coming from the database are valid.
Expand Down Expand Up @@ -112,7 +122,12 @@ impl AsStorageEntry for StorageEntry {
}
}

/// Trait which handles all storage actions relating to `Entries`.
/// Implementation of `EntryStore` trait which is required when constructing a
/// `StorageProvider`.
///
/// Handles storage and retrieval of entries in the form of`StorageEntry` which
/// implements the required `AsStorageEntry` trait. An intermediary struct `EntryRow`
/// is also used when retrieving an entry from the database.
#[async_trait]
impl EntryStore<StorageEntry> for SqlStorage {
/// Insert an entry into storage.
Expand Down
26 changes: 17 additions & 9 deletions aquadoggo/src/db/stores/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ use p2panda_rs::storage_provider::traits::{AsStorageLog, LogStore};

use crate::db::provider::SqlStorage;

/// Tracks the assigment of an author's logs to documents and records their schema.
///
/// This serves as an indexing layer on top of the lower-level bamboo entries. The node updates
/// this data according to what it sees in the newly incoming entries.
///
/// `StorageLog` implements the trait `AsStorageLog` which is required when defining a `LogStore`.
pub struct StorageLog {
author: Author,
log_id: LogId,
Expand Down Expand Up @@ -51,7 +57,12 @@ impl AsStorageLog for StorageLog {
}
}

/// Trait which handles all storage actions relating to `StorageLog`s.
/// Implementation of `LogStore` trait which is required when constructing a
/// `StorageProvider`.
///
/// Handles storage and retrieval of logs in the form of `StorageLog` which
/// implements the required `AsStorageLog` trait. An intermediary struct `LogRow`
/// is also used when retrieving a log from the database.
#[async_trait]
impl LogStore<StorageLog> for SqlStorage {
/// Insert a log into storage.
Expand Down Expand Up @@ -106,10 +117,8 @@ impl LogStore<StorageLog> for SqlStorage {

// Wrap u64 inside of `P2PandaLog` instance
let log_id: Option<LogId> = result.map(|str| {
str.parse().expect(&format!(
"Corrupt u64 integer found in database: '{0}'",
&str
))
str.parse()
.unwrap_or_else(|_| panic!("Corrupt u64 integer found in database: '{0}'", &str))
});

Ok(log_id)
Expand Down Expand Up @@ -137,10 +146,9 @@ impl LogStore<StorageLog> for SqlStorage {
let mut log_ids: Vec<LogId> = result
.iter_mut()
.map(|str| {
str.parse().expect(&format!(
"Corrupt u64 integer found in database: '{0}'",
&str
))
str.parse().unwrap_or_else(|_| {
panic!("Corrupt u64 integer found in database: '{0}'", &str)
})
})
.collect();

Expand Down
Loading

0 comments on commit c7d6f5d

Please sign in to comment.