From 7b9b0c8b5ed30c7d476c24860fe7d647aab826de Mon Sep 17 00:00:00 2001 From: Nathan F Yospe Date: Thu, 1 Feb 2024 13:13:06 -0500 Subject: [PATCH 1/6] Setting up tide-disco bindings --- Cargo.toml | 8 ++++ src/api.rs | 58 ++++++++++++++++++++++++ src/block_metadata.rs | 35 +++++++++++--- src/builder.rs | 103 ++++++++++++++++++++++++++++++++++++++++++ src/data_source.rs | 18 +++++--- src/lib.rs | 9 ++-- 6 files changed, 215 insertions(+), 16 deletions(-) create mode 100644 src/api.rs create mode 100644 src/builder.rs diff --git a/Cargo.toml b/Cargo.toml index 4e861bb..1df9730 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,15 @@ edition = "2021" [dependencies] async-trait = "0.1" +clap = { version = "4.4", features = ["derive", "env"] } +commit = { git = "https://github.com/EspressoSystems/commit.git" } +derive_more = "0.99" +futures = "0.3" hotshot-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.7.1" } serde = { version = "1.0", features = ["derive"] } sha2 = "0.10" +snafu = { version = "0.7", features = ["backtraces"] } +tagged-base64 = { git = "https://github.com/EspressoSystems/tagged-base64", tag = "0.3.4" } +tide-disco = { git = "https://github.com/EspressoSystems/tide-disco.git", tag = "v0.4.6" } +toml = "0.8" diff --git a/src/api.rs b/src/api.rs new file mode 100644 index 0000000..66058b2 --- /dev/null +++ b/src/api.rs @@ -0,0 +1,58 @@ +// Copyright (c) 2022 Espresso Systems (espressosys.com) +// This file is part of the HotShot Query Service library. +// +// This program is free software: you can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// You should have received a copy of the GNU General Public License along with this program. If not, +// see . + +use std::fs; +use std::path::Path; +use tide_disco::api::{Api, ApiError}; +use toml::{map::Entry, Value}; + +pub(crate) fn load_api( + path: Option>, + default: &str, + extensions: impl IntoIterator, +) -> Result, ApiError> { + let mut toml = match path { + Some(path) => load_toml(path.as_ref())?, + None => toml::from_str(default).map_err(|err| ApiError::CannotReadToml { + reason: err.to_string(), + })?, + }; + for extension in extensions { + merge_toml(&mut toml, extension); + } + Api::new(toml) +} + +fn merge_toml(into: &mut Value, from: Value) { + if let (Value::Table(into), Value::Table(from)) = (into, from) { + for (key, value) in from { + match into.entry(key) { + Entry::Occupied(mut entry) => merge_toml(entry.get_mut(), value), + Entry::Vacant(entry) => { + entry.insert(value); + } + } + } + } +} + +fn load_toml(path: &Path) -> Result { + let bytes = fs::read(path).map_err(|err| ApiError::CannotReadToml { + reason: err.to_string(), + })?; + let string = std::str::from_utf8(&bytes).map_err(|err| ApiError::CannotReadToml { + reason: err.to_string(), + })?; + toml::from_str(string).map_err(|err| ApiError::CannotReadToml { + reason: err.to_string(), + }) +} diff --git a/src/block_metadata.rs b/src/block_metadata.rs index ee335de..b081cb3 100644 --- a/src/block_metadata.rs +++ b/src/block_metadata.rs @@ -1,15 +1,38 @@ -use std::marker::PhantomData; +use std::{hash::Hash, marker::PhantomData}; -use hotshot_types::traits::node_implementation::NodeType; +use commit::{Commitment, Committable}; +use hotshot_types::traits::{node_implementation::NodeType, BlockPayload}; use serde::{Deserialize, Serialize}; -use sha2::digest::{generic_array::GenericArray, typenum}; +use sha2::{Digest, Sha256}; -pub type BlockHash = GenericArray; +pub struct HashableBlock(::BlockPayload, <::BlockPayload as BlockPayload>::Metadata); +pub type BlockHash = Commitment>; +impl Default for HashableBlock { + fn default() -> Self { + let (bp, bm) = ::BlockPayload::from_transactions(Vec::new()).unwrap_or_else(|_|::BlockPayload::genesis()); + Self(bp, bm) + } +} + +impl Committable for HashableBlock { + fn commit(&self) -> Commitment { + let builder = commit::RawCommitmentBuilder::new("Hashable Block Payload"); + let mut hasher = Sha256::new(); + let encoded = if let Ok(encoder) = self.0.encode() { + encoder.collect() + } else { + Vec::new() + }; + hasher.update(&encoded); + let generic_array = hasher.finalize(); + builder.generic_byte_array(&generic_array).finalize() + } +} -#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] #[serde(bound = "")] pub struct BlockMetadata { - block_hash: BlockHash, + block_hash: BlockHash, block_size: u64, offered_fee: u64, _phantom: PhantomData, diff --git a/src/builder.rs b/src/builder.rs new file mode 100644 index 0000000..bfc6ec9 --- /dev/null +++ b/src/builder.rs @@ -0,0 +1,103 @@ +use std::{fmt::Display, path::PathBuf}; + +use clap::Args; +use derive_more::From; +use futures::FutureExt; +use hotshot_types::{data::VidCommitment, traits::{node_implementation::NodeType, signature_key::SignatureKey}}; +use serde::{Deserialize, Serialize}; +use snafu::{OptionExt, ResultExt, Snafu}; +use tagged_base64::TaggedBase64; +use tide_disco::{api::ApiError, method::ReadState, Api, RequestError, StatusCode}; + +use crate::{api::load_api, block_metadata::BlockHash, data_source::{self, BuilderDataSource}}; + +#[derive(Args, Default)] +pub struct Options { + #[arg(long = "builder-api-path", env = "HOTSHOT_BUILDER_API_PATH")] + pub api_path: Option, + + /// Additional API specification files to merge with `builder-api-path`. + /// + /// These optional files may contain route definitions for application-specific routes that have + /// been added as extensions to the basic builder API. + #[arg( + long = "builder-extension", + env = "HOTSHOT_BUILDER_EXTENSIONS", + value_delimiter = ',' + )] + pub extensions: Vec, +} + +#[derive(Clone, Debug, Snafu, Deserialize, Serialize)] +#[snafu(visibility(pub))] +pub enum BuildError { + /// The requested resource does not exist or is not known to this builder service. + NotFound, + /// The requested resource exists but is not currently available. + Missing, + /// There was an error while trying to fetch the requested resource. + #[snafu(display("Failed to fetch requested resource: {message}"))] + Error { message: String }, +} + + +#[derive(Clone, Debug, From, Snafu, Deserialize, Serialize)] +#[snafu(visibility(pub))] +pub enum Error { + Request { + source: RequestError, + }, + #[snafu(display("error building block from {resource}: {source}"))] + #[from(ignore)] + BlockAvailable { + source: BuildError, + resource: String, + }, + #[snafu(display("error claiming block {resource}: {source}"))] + #[from(ignore)] + BlockClaim { + source: BuildError, + resource: String, + }, + Custom { + message: String, + status: StatusCode, + }, +} + + +pub fn define_api(options: &Options) -> Result, ApiError> +where + State: 'static + Send + Sync + ReadState, + ::State: Send + Sync + BuilderDataSource, + Types: NodeType, + <::SignatureKey as SignatureKey>::PureAssembledSignatureType: for<'a> TryFrom<&'a TaggedBase64> + Into + Display, + for<'a> <<::SignatureKey as SignatureKey>::PureAssembledSignatureType as TryFrom<&'a TaggedBase64>>::Error: Display, +{ + let mut api = load_api::( + options.api_path.as_ref(), + include_str!("../api/builder.toml"), + options.extensions.clone(), + )?; + api.with_version("0.0.1".parse().unwrap()) + .get("available_blocks", |req, state| { + async move { + let hash = req.blob_param("parent_hash")?; + state.get_available_blocks(&hash).await.context(BlockAvailableSnafu { + resource: hash.to_string(), + }) + } + .boxed() + })? + .get("claim_block", |req, state| { + async move { + let hash = req.blob_param("block_hash")?; + let signature = req.blob_param("signature")?; + state.claim_block(&hash, &signature).await.context(BlockClaimSnafu { + resource: hash.to_string(), + }) + } + .boxed() + })?; + Ok(api) +} \ No newline at end of file diff --git a/src/data_source.rs b/src/data_source.rs index 11f35ae..49d394e 100644 --- a/src/data_source.rs +++ b/src/data_source.rs @@ -1,13 +1,19 @@ use std::sync::Arc; use async_trait::async_trait; -use hotshot_types::{data::VidCommitment, traits::{node_implementation::NodeType, signature_key::SignatureKey}}; +use commit::Committable; +use hotshot_types::{data::VidCommitment, traits::{node_implementation::NodeType, signature_key::SignatureKey, BlockPayload}}; +use tagged_base64::TaggedBase64; -use crate::block_metadata::{BlockHash, BlockMetadata}; +use crate::{block_metadata::{BlockHash, BlockMetadata}, builder::BuildError}; #[async_trait] -pub trait BuilderDataSource { - async fn get_available_blocks(&self, for_parent: &VidCommitment) -> Vec>; - async fn claim_block(&self, block_hash: BlockHash, signature: <::SignatureKey as SignatureKey>::PureAssembledSignatureType) -> Arc>; - async fn submit_txn(&self, txn: ::Transaction); +pub trait BuilderDataSource +where I: NodeType, + <::SignatureKey as SignatureKey>::PureAssembledSignatureType: for<'a> TryFrom<&'a TaggedBase64> + Into + { + async fn get_available_blocks(&self, for_parent: &VidCommitment) -> Result>, BuildError>; + async fn claim_block(&self, block_hash: &BlockHash, signature: &<::SignatureKey as SignatureKey>::PureAssembledSignatureType) -> Result; + async fn submit_txn(&self, txn: ::Transaction) -> Result<(), BuildError>; } + diff --git a/src/lib.rs b/src/lib.rs index 737f7bf..2493f5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ -mod block_metadata; -mod data_source; -mod query_data; - +pub mod block_metadata; +pub mod builder; +pub mod data_source; +pub mod query_data; +mod api; From 212ec65525a4ce568f667d6ebc0437042eafaabb Mon Sep 17 00:00:00 2001 From: Nathan F Yospe Date: Fri, 2 Feb 2024 12:44:38 -0500 Subject: [PATCH 2/6] Cargo format --- src/block_metadata.rs | 9 ++++++--- src/builder.rs | 40 +++++++++++++++++++++++++++------------- src/data_source.rs | 30 ++++++++++++++++++++++-------- src/lib.rs | 2 +- src/query_data.rs | 1 - 5 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/block_metadata.rs b/src/block_metadata.rs index b081cb3..d6d6dae 100644 --- a/src/block_metadata.rs +++ b/src/block_metadata.rs @@ -5,11 +5,15 @@ use hotshot_types::traits::{node_implementation::NodeType, BlockPayload}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; -pub struct HashableBlock(::BlockPayload, <::BlockPayload as BlockPayload>::Metadata); +pub struct HashableBlock( + ::BlockPayload, + <::BlockPayload as BlockPayload>::Metadata, +); pub type BlockHash = Commitment>; impl Default for HashableBlock { fn default() -> Self { - let (bp, bm) = ::BlockPayload::from_transactions(Vec::new()).unwrap_or_else(|_|::BlockPayload::genesis()); + let (bp, bm) = ::BlockPayload::from_transactions(Vec::new()) + .unwrap_or_else(|_| ::BlockPayload::genesis()); Self(bp, bm) } } @@ -37,4 +41,3 @@ pub struct BlockMetadata { offered_fee: u64, _phantom: PhantomData, } - diff --git a/src/builder.rs b/src/builder.rs index bfc6ec9..020d922 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -3,13 +3,20 @@ use std::{fmt::Display, path::PathBuf}; use clap::Args; use derive_more::From; use futures::FutureExt; -use hotshot_types::{data::VidCommitment, traits::{node_implementation::NodeType, signature_key::SignatureKey}}; +use hotshot_types::{ + data::VidCommitment, + traits::{node_implementation::NodeType, signature_key::SignatureKey}, +}; use serde::{Deserialize, Serialize}; use snafu::{OptionExt, ResultExt, Snafu}; use tagged_base64::TaggedBase64; use tide_disco::{api::ApiError, method::ReadState, Api, RequestError, StatusCode}; -use crate::{api::load_api, block_metadata::BlockHash, data_source::{self, BuilderDataSource}}; +use crate::{ + api::load_api, + block_metadata::BlockHash, + data_source::{self, BuilderDataSource}, +}; #[derive(Args, Default)] pub struct Options { @@ -40,7 +47,6 @@ pub enum BuildError { Error { message: String }, } - #[derive(Clone, Debug, From, Snafu, Deserialize, Serialize)] #[snafu(visibility(pub))] pub enum Error { @@ -65,14 +71,16 @@ pub enum Error { }, } - pub fn define_api(options: &Options) -> Result, ApiError> where State: 'static + Send + Sync + ReadState, ::State: Send + Sync + BuilderDataSource, Types: NodeType, - <::SignatureKey as SignatureKey>::PureAssembledSignatureType: for<'a> TryFrom<&'a TaggedBase64> + Into + Display, - for<'a> <<::SignatureKey as SignatureKey>::PureAssembledSignatureType as TryFrom<&'a TaggedBase64>>::Error: Display, + <::SignatureKey as SignatureKey>::PureAssembledSignatureType: + for<'a> TryFrom<&'a TaggedBase64> + Into + Display, + for<'a> <<::SignatureKey as SignatureKey>::PureAssembledSignatureType as TryFrom< + &'a TaggedBase64, + >>::Error: Display, { let mut api = load_api::( options.api_path.as_ref(), @@ -83,9 +91,12 @@ where .get("available_blocks", |req, state| { async move { let hash = req.blob_param("parent_hash")?; - state.get_available_blocks(&hash).await.context(BlockAvailableSnafu { - resource: hash.to_string(), - }) + state + .get_available_blocks(&hash) + .await + .context(BlockAvailableSnafu { + resource: hash.to_string(), + }) } .boxed() })? @@ -93,11 +104,14 @@ where async move { let hash = req.blob_param("block_hash")?; let signature = req.blob_param("signature")?; - state.claim_block(&hash, &signature).await.context(BlockClaimSnafu { - resource: hash.to_string(), - }) + state + .claim_block(&hash, &signature) + .await + .context(BlockClaimSnafu { + resource: hash.to_string(), + }) } .boxed() })?; Ok(api) -} \ No newline at end of file +} diff --git a/src/data_source.rs b/src/data_source.rs index 49d394e..664f285 100644 --- a/src/data_source.rs +++ b/src/data_source.rs @@ -2,18 +2,32 @@ use std::sync::Arc; use async_trait::async_trait; use commit::Committable; -use hotshot_types::{data::VidCommitment, traits::{node_implementation::NodeType, signature_key::SignatureKey, BlockPayload}}; +use hotshot_types::{ + data::VidCommitment, + traits::{node_implementation::NodeType, signature_key::SignatureKey, BlockPayload}, +}; use tagged_base64::TaggedBase64; -use crate::{block_metadata::{BlockHash, BlockMetadata}, builder::BuildError}; +use crate::{ + block_metadata::{BlockHash, BlockMetadata}, + builder::BuildError, +}; #[async_trait] pub trait BuilderDataSource -where I: NodeType, - <::SignatureKey as SignatureKey>::PureAssembledSignatureType: for<'a> TryFrom<&'a TaggedBase64> + Into - { - async fn get_available_blocks(&self, for_parent: &VidCommitment) -> Result>, BuildError>; - async fn claim_block(&self, block_hash: &BlockHash, signature: &<::SignatureKey as SignatureKey>::PureAssembledSignatureType) -> Result; +where + I: NodeType, + <::SignatureKey as SignatureKey>::PureAssembledSignatureType: + for<'a> TryFrom<&'a TaggedBase64> + Into, +{ + async fn get_available_blocks( + &self, + for_parent: &VidCommitment, + ) -> Result>, BuildError>; + async fn claim_block( + &self, + block_hash: &BlockHash, + signature: &<::SignatureKey as SignatureKey>::PureAssembledSignatureType, + ) -> Result; async fn submit_txn(&self, txn: ::Transaction) -> Result<(), BuildError>; } - diff --git a/src/lib.rs b/src/lib.rs index 2493f5a..8a52c67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ +mod api; pub mod block_metadata; pub mod builder; pub mod data_source; pub mod query_data; -mod api; diff --git a/src/query_data.rs b/src/query_data.rs index b2bb9e9..602a329 100644 --- a/src/query_data.rs +++ b/src/query_data.rs @@ -3,7 +3,6 @@ // // TODO: License - use hotshot_types::traits::node_implementation::NodeType; use serde::{Deserialize, Serialize}; From d1b0cf58a99a7b686d2faddac691f3f1629ec799 Mon Sep 17 00:00:00 2001 From: Nathan F Yospe Date: Mon, 5 Feb 2024 10:05:51 -0500 Subject: [PATCH 3/6] Adding flake.nix --- flake.nix | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 flake.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..547c6b9 --- /dev/null +++ b/flake.nix @@ -0,0 +1,192 @@ +# Copyright (c) 2022 Espresso Systems (espressosys.com) +# This file is part of the HotShot Query Service library. +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU +# General Public License as published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# You should have received a copy of the GNU General Public License along with this program. If not, +# see . + +{ + description = "Generic query service for HotShot applications"; + + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + inputs.flake-utils.url = "github:numtide/flake-utils"; + + inputs.flake-compat.url = "github:edolstra/flake-compat"; + inputs.flake-compat.flake = false; + + inputs.rust-overlay.url = "github:oxalica/rust-overlay"; + + inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + inputs.pre-commit-hooks.inputs.flake-utils.follows = "flake-utils"; + inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; + + inputs.poetry2nixFlake = { + url = "github:nix-community/poetry2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, flake-utils, rust-overlay, pre-commit-hooks, poetry2nixFlake, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + poetry2nix = poetry2nixFlake.lib.mkPoetry2Nix { inherit pkgs; }; + rustToolchain = pkgs.rust-bin.stable.latest.minimal.override { + extensions = [ "rustfmt" "clippy" "llvm-tools-preview" "rust-src" ]; + }; + rustDeps = with pkgs; + [ + pkg-config + openssl + bash + + curl + docker + + cargo-audit + cargo-edit + cargo-udeps + cargo-sort + cmake + + # `postgresql` defaults to an older version (15), so we select the latest version (16) + # explicitly. + postgresql_16 + ] ++ lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Security + darwin.apple_sdk.frameworks.CoreFoundation + darwin.apple_sdk.frameworks.SystemConfiguration + + # https://github.com/NixOS/nixpkgs/issues/126182 + libiconv + ] ++ lib.optionals (!stdenv.isDarwin) [ + cargo-watch # broken: https://github.com/NixOS/nixpkgs/issues/146349 + ]; + # nixWithFlakes allows pre v2.4 nix installations to use + # flake commands (like `nix flake update`) + nixWithFlakes = pkgs.writeShellScriptBin "nix" '' + exec ${pkgs.nixFlakes}/bin/nix --experimental-features "nix-command flakes" "$@" + ''; + cargo-llvm-cov = pkgs.rustPlatform.buildRustPackage rec { + pname = "cargo-llvm-cov"; + version = "0.5.0"; + + doCheck = false; + + buildInputs = [ pkgs.libllvm ]; + + src = builtins.fetchTarball { + url = + "https://crates.io/api/v1/crates/${pname}/${version}/download"; + sha256 = + "sha256:1a0grmpcjnqrz5c9jjbk07705py4573pmq0jcgr9m7l5xf4g1yc9"; + }; + + cargoSha256 = "sha256-11xNgiOw0qysTWpoKAXQ5gx1uJSAsp+aDDir0zpkpeQ="; + meta = with pkgs.lib; { + description = "Cargo llvm cov generates code coverage via llvm."; + homepage = "https://github.com/taiki-e/cargo-llvm-cov"; + + license = with licenses; [ mit asl20 ]; + }; + }; + pythonEnv = poetry2nix.mkPoetryEnv { projectDir = ./.; }; + myPython = with pkgs; [ poetry pythonEnv ]; + shellHook = '' + # Prevent cargo aliases from using programs in `~/.cargo` to avoid conflicts with rustup + # installations. + export CARGO_HOME=$HOME/.cargo-nix + export PATH="$PWD/$CARGO_TARGET_DIR/release:$PATH" + ''; + + RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; + RUST_BACKTRACE = 1; + RUST_LOG = "info"; + RUSTFLAGS=" --cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\" --cfg hotshot_example"; + in { + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + cargo-fmt = { + enable = true; + description = "Enforce rustfmt"; + entry = "cargo fmt --all -- --check"; + pass_filenames = false; + }; + cargo-sort = { + enable = true; + description = "Ensure Cargo.toml are sorted"; + entry = "cargo sort -g -w"; + pass_filenames = false; + }; + cargo-clippy = { + enable = true; + description = "Run clippy"; + entry = "cargo clippy --workspace --all-features --all-targets -- -D clippy::dbg-macro"; + pass_filenames = false; + }; + license-header-c-style = { + enable = true; + description = + "Ensure files with c-style comments have license header"; + entry = '' + insert_license --license-filepath .license-header.txt --comment-style "//"''; + types_or = [ "rust" ]; + pass_filenames = true; + }; + license-header-hash = { + enable = true; + description = + "Ensure files with hash style comments have license header"; + entry = '' + insert_license --license-filepath .license-header.txt --comment-style "#"''; + types_or = [ "bash" "python" "toml" "nix" ]; + excludes = [ "poetry.lock" ]; + pass_filenames = true; + }; + license-header-html = { + enable = true; + description = "Ensure markdown files have license header"; + entry = '' + insert_license --license-filepath .license-header.txt --comment-style ""''; + types_or = [ "markdown" ]; + pass_filenames = true; + }; + }; + }; + }; + devShell = pkgs.mkShell { + shellHook = shellHook + # install pre-commit hooks + + self.checks.${system}.pre-commit-check.shellHook; + buildInputs = with pkgs; + [ + rust-bin.nightly.latest.rust-analyzer + nixWithFlakes + nixpkgs-fmt + git + mdbook # make-doc, documentation generation + protobuf + rustToolchain + ] ++ myPython ++ rustDeps; + + inherit RUST_SRC_PATH RUST_BACKTRACE RUST_LOG RUSTFLAGS; + }; + devShells = { + perfShell = pkgs.mkShell { + shellHook = shellHook; + buildInputs = with pkgs; + [ nixWithFlakes cargo-llvm-cov rustToolchain protobuf ] ++ rustDeps; + + inherit RUST_SRC_PATH RUST_BACKTRACE RUST_LOG RUSTFLAGS; + }; + }; + }); +} From 8e9a91e705bfbed9c9d873f7364a7d27e7b8f8b0 Mon Sep 17 00:00:00 2001 From: Nathan F Yospe Date: Mon, 5 Feb 2024 10:41:46 -0500 Subject: [PATCH 4/6] Removing unneeded dependencies --- src/block_metadata.rs | 2 +- src/builder.rs | 10 +++------- src/data_source.rs | 5 +---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/block_metadata.rs b/src/block_metadata.rs index d6d6dae..ff7784e 100644 --- a/src/block_metadata.rs +++ b/src/block_metadata.rs @@ -9,7 +9,7 @@ pub struct HashableBlock( ::BlockPayload, <::BlockPayload as BlockPayload>::Metadata, ); -pub type BlockHash = Commitment>; +pub type BlockHash = Commitment>; impl Default for HashableBlock { fn default() -> Self { let (bp, bm) = ::BlockPayload::from_transactions(Vec::new()) diff --git a/src/builder.rs b/src/builder.rs index 020d922..0478044 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -3,19 +3,15 @@ use std::{fmt::Display, path::PathBuf}; use clap::Args; use derive_more::From; use futures::FutureExt; -use hotshot_types::{ - data::VidCommitment, - traits::{node_implementation::NodeType, signature_key::SignatureKey}, -}; +use hotshot_types::traits::{node_implementation::NodeType, signature_key::SignatureKey}; use serde::{Deserialize, Serialize}; -use snafu::{OptionExt, ResultExt, Snafu}; +use snafu::{ResultExt, Snafu}; use tagged_base64::TaggedBase64; use tide_disco::{api::ApiError, method::ReadState, Api, RequestError, StatusCode}; use crate::{ api::load_api, - block_metadata::BlockHash, - data_source::{self, BuilderDataSource}, + data_source::BuilderDataSource, }; #[derive(Args, Default)] diff --git a/src/data_source.rs b/src/data_source.rs index 664f285..df207d5 100644 --- a/src/data_source.rs +++ b/src/data_source.rs @@ -1,10 +1,7 @@ -use std::sync::Arc; - use async_trait::async_trait; -use commit::Committable; use hotshot_types::{ data::VidCommitment, - traits::{node_implementation::NodeType, signature_key::SignatureKey, BlockPayload}, + traits::{node_implementation::NodeType, signature_key::SignatureKey}, }; use tagged_base64::TaggedBase64; From e8ff75e5deaf1784688bddb1e5ae865b7c3b4804 Mon Sep 17 00:00:00 2001 From: Nathan F Yospe Date: Mon, 5 Feb 2024 11:14:21 -0500 Subject: [PATCH 5/6] cargo fmt --- src/builder.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 0478044..bcda68e 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -9,10 +9,7 @@ use snafu::{ResultExt, Snafu}; use tagged_base64::TaggedBase64; use tide_disco::{api::ApiError, method::ReadState, Api, RequestError, StatusCode}; -use crate::{ - api::load_api, - data_source::BuilderDataSource, -}; +use crate::{api::load_api, data_source::BuilderDataSource}; #[derive(Args, Default)] pub struct Options { From 4d4bed92ffc74141730a6ab659d83059171b1386 Mon Sep 17 00:00:00 2001 From: Nathan F Yospe Date: Mon, 5 Feb 2024 11:24:29 -0500 Subject: [PATCH 6/6] removing incorrect copied feature flags --- .github/workflows/lint.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 27858f7..d0347d2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,12 +20,6 @@ jobs: features: # No optional features - '' - # Each optional feature on its own - - sql-data-source - - file-system-data-source - - metrics-data-source - # All optional features together - - sql-data-source,file-system-data-source,metrics-data-source env: RUSTFLAGS: "--cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\"" RUST_LOG: info