Skip to content

Bootstore message handler implementation #1687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bootstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ uuid = { version = "1.1.0", features = [ "serde", "v4" ] }
vsss-rs = { version = "2.0.0", default-features = false, features = ["std"] }

[dev-dependencies]
assert_matches = "1.5.0"
bincode = "1.3.3"
omicron-test-utils = { path = "../test-utils" }
67 changes: 67 additions & 0 deletions bootstore/src/db/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! DB related errors

use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(thiserror::Error, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Error {
#[error("Failed to open db connection to {path}: {err}")]
DbOpen { path: String, err: String },

#[error("Diesel/sqlite error: {err}")]
Diesel { err: String },

#[error("BCS serialization error: {err}")]
Bcs { err: String },

#[error("Failed to parse string as UUID: {uuidstr} - {err}")]
ParseUuid { uuidstr: String, err: String },

// Temporary until the using code is written
#[allow(dead_code)]
#[error("Share commit for {epoch} does not match prepare")]
CommitHashMismatch { epoch: i32 },

#[error("No shares have been committed")]
NoSharesCommitted,

#[error("DB invariant violated: {0}")]
DbInvariant(String),

#[error("Already initialized with rack uuid: {0}")]
AlreadyInitialized(Uuid),

#[error(
"Tried to Prepare a KeyShare with epoch {epoch}, but found one \
with later epoch {stored_epoch}"
)]
OldKeySharePrepare { epoch: i32, stored_epoch: i32 },

#[error("A distinct key share already exists for epoch {epoch}")]
KeyShareAlreadyExists { epoch: i32 },

#[error("Rack UUID mismatch: Expected: {expected}, Actual: {actual:?}")]
RackUuidMismatch { expected: Uuid, actual: Option<Uuid> },

#[error("Rack not initialized")]
RackNotInitialized,

#[error("Key share for epoch {epoch} not committed")]
KeyShareNotCommitted { epoch: i32 },
}

impl From<diesel::result::Error> for Error {
fn from(err: diesel::result::Error) -> Self {
Error::Diesel { err: err.to_string() }
}
}

impl From<bcs::Error> for Error {
fn from(err: bcs::Error) -> Self {
Error::Bcs { err: err.to_string() }
}
}
8 changes: 6 additions & 2 deletions bootstore/src/db/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

//! Macros used to create ToSql and FromSql impls required by Diesel

/// Shamelessly stolen from buildomat/common/src/db.rs
/// Shamelessly cribbed and mutated from buildomat/common/src/db.rs
/// Thanks @jmc
macro_rules! bcs_new_type {
($name:ident, $mytype:ty) => {
#[derive(
Clone, Debug, FromSqlRow, diesel::expression::AsExpression,
Clone,
PartialEq,
Debug,
FromSqlRow,
diesel::expression::AsExpression,
)]
#[diesel(sql_type = diesel::sql_types::Binary)]
pub struct $name(pub $mytype);
Expand Down
Loading