From 17bd7884ea2bad663f950b77598a071a804a2ceb Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 14 Jun 2023 16:01:39 -0300 Subject: [PATCH] fix(build): add elasticsearch feature to block serialize (#6709) * add elasticsearch feature to block serialize * fix for elastic feature * add zebra-chain elasticsearch dep to zebrad --- zebra-chain/Cargo.toml | 3 +++ zebra-chain/src/block.rs | 5 ++++- zebra-chain/src/transaction.rs | 5 ++++- zebra-chain/src/transparent.rs | 21 ++++++++++++++++----- zebra-state/Cargo.toml | 1 + zebrad/Cargo.toml | 1 + 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/zebra-chain/Cargo.toml b/zebra-chain/Cargo.toml index a3de60038..34f4dd57a 100644 --- a/zebra-chain/Cargo.toml +++ b/zebra-chain/Cargo.toml @@ -29,6 +29,9 @@ getblocktemplate-rpcs = [ "zcash_address", ] +# Experimental elasticsearch support +elasticsearch = [] + # Test-only features proptest-impl = [ diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 3ae098819..d472e930c 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -43,7 +43,10 @@ pub use arbitrary::LedgerState; /// A Zcash block, containing a header and a list of transactions. #[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr(any(test, feature = "proptest-impl"), derive(Serialize))] +#[cfg_attr( + any(test, feature = "proptest-impl", feature = "elasticsearch"), + derive(Serialize) +)] pub struct Block { /// The block header, containing block metadata. pub header: Arc
, diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs index 0b2c25583..583ca9681 100644 --- a/zebra-chain/src/transaction.rs +++ b/zebra-chain/src/transaction.rs @@ -63,7 +63,10 @@ use crate::{ /// internally by different enum variants. Because we checkpoint on Canopy /// activation, we do not validate any pre-Sapling transaction types. #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(any(test, feature = "proptest-impl"), derive(Serialize))] +#[cfg_attr( + any(test, feature = "proptest-impl", feature = "elasticsearch"), + derive(Serialize) +)] pub enum Transaction { /// A fully transparent transaction (`version = 1`). V1 { diff --git a/zebra-chain/src/transparent.rs b/zebra-chain/src/transparent.rs index afea036af..798246828 100644 --- a/zebra-chain/src/transparent.rs +++ b/zebra-chain/src/transparent.rs @@ -66,7 +66,10 @@ pub const EXTRA_ZEBRA_COINBASE_DATA: &str = "z\u{1F993}"; // // TODO: rename to ExtraCoinbaseData, because height is also part of the coinbase data? #[derive(Clone, Eq, PartialEq)] -#[cfg_attr(any(test, feature = "proptest-impl"), derive(Serialize))] +#[cfg_attr( + any(test, feature = "proptest-impl", feature = "elasticsearch"), + derive(Serialize) +)] pub struct CoinbaseData( /// Invariant: this vec, together with the coinbase height, must be less than /// 100 bytes. We enforce this by only constructing CoinbaseData fields by @@ -110,7 +113,11 @@ impl std::fmt::Debug for CoinbaseData { /// /// A particular transaction output reference. #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary, Serialize))] +#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))] +#[cfg_attr( + any(test, feature = "proptest-impl", feature = "elasticsearch"), + derive(Serialize) +)] pub struct OutPoint { /// References the transaction that contains the UTXO being spent. /// @@ -145,7 +152,10 @@ impl OutPoint { /// A transparent input to a transaction. #[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr(any(test, feature = "proptest-impl"), derive(Serialize))] +#[cfg_attr( + any(test, feature = "proptest-impl", feature = "elasticsearch"), + derive(Serialize) +)] pub enum Input { /// A reference to an output of a previous transaction. PrevOut { @@ -383,9 +393,10 @@ impl Input { /// that spends my UTXO and sends 1 ZEC to you and 1 ZEC back to me /// (just like receiving change). #[derive(Clone, Debug, Eq, PartialEq, Hash)] +#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary, Deserialize))] #[cfg_attr( - any(test, feature = "proptest-impl"), - derive(Arbitrary, Serialize, Deserialize) + any(test, feature = "proptest-impl", feature = "elasticsearch"), + derive(Serialize) )] pub struct Output { /// Transaction value. diff --git a/zebra-state/Cargo.toml b/zebra-state/Cargo.toml index 78c0c16d8..41c71c584 100644 --- a/zebra-state/Cargo.toml +++ b/zebra-state/Cargo.toml @@ -39,6 +39,7 @@ proptest-impl = [ elasticsearch = [ "dep:elasticsearch", "dep:serde_json", + "zebra-chain/elasticsearch", ] [dependencies] diff --git a/zebrad/Cargo.toml b/zebrad/Cargo.toml index 7eb30a2c7..bd00bb75d 100644 --- a/zebrad/Cargo.toml +++ b/zebrad/Cargo.toml @@ -44,6 +44,7 @@ getblocktemplate-rpcs = [ elasticsearch = [ "zebra-state/elasticsearch", + "zebra-chain/elasticsearch", ] sentry = ["dep:sentry"]