From f67e07c7f86c508c771aa284ab40d5aa878c0866 Mon Sep 17 00:00:00 2001 From: wenyuanhust <873741746@qq.com> Date: Wed, 8 Nov 2023 15:57:37 +0800 Subject: [PATCH] feat: add no-std version of axon-tools (#1532) * refactor: impl-serde & proof shouldn't be default features * feat: add no-std version of axon-tools --- devtools/axon-tools/Cargo.toml | 44 ++++--- devtools/axon-tools/src/error.rs | 61 +-------- devtools/axon-tools/src/hash.rs | 1 + devtools/axon-tools/src/lib.rs | 7 +- devtools/axon-tools/src/proof.rs | 10 +- devtools/axon-tools/src/rlp_codec.rs | 5 +- devtools/axon-tools/src/tests/verify_proof.rs | 9 ++ .../axon-tools/src/tests/verify_trie_proof.rs | 14 +- devtools/axon-tools/src/types.rs | 120 ++++++++++-------- 9 files changed, 137 insertions(+), 134 deletions(-) diff --git a/devtools/axon-tools/Cargo.toml b/devtools/axon-tools/Cargo.toml index 670171390..4e0c9abbb 100644 --- a/devtools/axon-tools/Cargo.toml +++ b/devtools/axon-tools/Cargo.toml @@ -18,13 +18,21 @@ eth_light_client_in_ckb-prover = { version = "0.3.0-alpha", git = "https://githu ethereum = "0.14" ethers-core = "2.0.10" hex = "0.4" +overlord = "0.4" rand = "0.8" -[dependencies] -derive_more = "0.99" -log = "0.4.19" -overlord = "0.4" -serde_json = "1.0" +[features] +default = [] +proof = ["blst", "bit-vec", "hash", "impl-rlp"] +hash = ["tiny-keccak"] +hex = ["faster-hex"] +impl-rlp = ["rlp", "rlp-derive", "ethereum-types/rlp"] +impl-serde = ["serde", "ethereum-types/serialize"] +std = ["cita_trie", "hex", "log", "derive_more", "serde_json"] + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "doc_cfg"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies.bit-vec] @@ -45,6 +53,10 @@ features = ["serde"] version = "4.0" optional = true +[dependencies.derive_more] +version = "0.99" +optional = true + [dependencies.ethereum-types] version = "0.14" default-features = false @@ -54,6 +66,11 @@ features = ["serialize"] version = "0.8" optional = true +[dependencies.log] +version = "0.4.19" +default_features = false +optional = true + [dependencies.rlp] version = "0.5" default-features = false @@ -69,19 +86,12 @@ default_features = false optional = true features = ["derive"] +[dependencies.serde_json] +version = "1.0" +default_features = false +optional = true + [dependencies.tiny-keccak] version = "2.0" optional = true features = ["keccak"] - -[features] -default = ["impl-serde", "proof"] -proof = ["blst", "bit-vec", "cita_trie", "hash", "impl-rlp"] -hash = ["tiny-keccak"] -hex = ["faster-hex"] -impl-rlp = ["rlp", "rlp-derive", "ethereum-types/rlp"] -impl-serde = ["serde", "ethereum-types/serialize", "hex"] - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--cfg", "doc_cfg"] diff --git a/devtools/axon-tools/src/error.rs b/devtools/axon-tools/src/error.rs index 53f8ee61f..5e521e4c3 100644 --- a/devtools/axon-tools/src/error.rs +++ b/devtools/axon-tools/src/error.rs @@ -1,5 +1,4 @@ -use derive_more::{Display, From}; -use ethereum_types::H256; +#[cfg(feature = "std")] use std::fmt::{self, Display}; #[allow(dead_code)] @@ -18,7 +17,7 @@ pub enum Error { #[cfg_attr(doc_cfg, doc(cfg(feature = "proof")))] Bls(blst::BLST_ERROR), - #[cfg(feature = "proof")] + #[cfg(all(feature = "proof", feature = "std"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "proof")))] Trie(cita_trie::TrieError), } @@ -39,7 +38,7 @@ impl From for Error { } } -#[cfg(feature = "proof")] +#[cfg(all(feature = "proof", feature = "std"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "proof")))] impl From for Error { fn from(e: cita_trie::TrieError) -> Self { @@ -47,6 +46,7 @@ impl From for Error { } } +#[cfg(feature = "std")] impl Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { @@ -64,58 +64,7 @@ impl Display for Error { } } -#[derive(Debug, Display, From)] +#[derive(Debug)] pub enum TypesError { - #[display(fmt = "Expect {:?}, get {:?}.", expect, real)] - LengthMismatch { expect: usize, real: usize }, - - #[display( - fmt = "Eip1559Transaction hash mismatch origin {:?}, computed {:?}", - origin, - calc - )] - TxHashMismatch { origin: H256, calc: H256 }, - - #[display(fmt = "{:?}", _0)] - FromHex(faster_hex::Error), - - #[display(fmt = "{:?} is an invalid address", _0)] - InvalidAddress(String), - - #[display(fmt = "Hex should start with 0x")] - HexPrefix, - - #[display(fmt = "Invalid public key")] - InvalidPublicKey, - - #[display(fmt = "Invalid check sum")] - InvalidCheckSum, - - #[display(fmt = "Unsigned")] - Unsigned, - - // #[display(fmt = "Crypto error {:?}", _0)] - // Crypto(CryptoError), - #[display(fmt = "Missing signature")] - MissingSignature, - - #[display(fmt = "Invalid crosschain direction")] - InvalidDirection, - - #[display(fmt = "Signature R is empty")] - SignatureRIsEmpty, - - #[display(fmt = "Invalid signature R type")] - InvalidSignatureRType, - - #[display(fmt = "Invalid address source type")] - InvalidAddressSourceType, - - #[display(fmt = "Missing interoperation sender")] - MissingInteroperationSender, - - #[display(fmt = "InvalidBlockVersion {:?}", _0)] InvalidBlockVersion(u8), } - -impl std::error::Error for TypesError {} diff --git a/devtools/axon-tools/src/hash.rs b/devtools/axon-tools/src/hash.rs index bc051bbe6..87f03149e 100644 --- a/devtools/axon-tools/src/hash.rs +++ b/devtools/axon-tools/src/hash.rs @@ -13,6 +13,7 @@ pub fn keccak_256(data: &[u8]) -> [u8; 32] { #[derive(Default)] pub(crate) struct InnerKeccak; +#[cfg(all(feature = "proof", feature = "std"))] impl cita_trie::Hasher for InnerKeccak { const LENGTH: usize = 32; diff --git a/devtools/axon-tools/src/lib.rs b/devtools/axon-tools/src/lib.rs index d10380c22..507d03fcf 100644 --- a/devtools/axon-tools/src/lib.rs +++ b/devtools/axon-tools/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(feature = "std"), no_std)] +// #![no_std] #![cfg_attr(doc_cfg, feature(doc_cfg))] extern crate alloc; @@ -17,7 +19,10 @@ pub use error::Error; #[cfg(feature = "proof")] #[cfg_attr(doc_cfg, doc(cfg(feature = "proof")))] -pub use proof::{verify_proof, verify_trie_proof}; +pub use proof::verify_proof; + +#[cfg(all(feature = "proof", feature = "std"))] +pub use proof::verify_trie_proof; #[cfg(feature = "hash")] #[cfg_attr(doc_cfg, doc(cfg(feature = "hash")))] diff --git a/devtools/axon-tools/src/proof.rs b/devtools/axon-tools/src/proof.rs index 9715d4426..1a93d499d 100644 --- a/devtools/axon-tools/src/proof.rs +++ b/devtools/axon-tools/src/proof.rs @@ -7,11 +7,14 @@ use bytes::Bytes; use ethereum_types::H256; use rlp::Encodable; +#[cfg(all(feature = "proof", feature = "std"))] +use crate::hash::InnerKeccak; use crate::types::{AxonBlock, Proof, Proposal, ValidatorExtend, Vote}; -use crate::{error::Error, hash::InnerKeccak, keccak_256}; +use crate::{error::Error, keccak_256}; const DST: &str = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RONUL"; +#[cfg(all(feature = "proof", feature = "std"))] pub fn verify_trie_proof( root: H256, key: &[u8], @@ -91,11 +94,6 @@ fn extract_pks( count += 1; } - log::debug!( - "extract_pks count: {}, validator len: {}", - count, - validator_list.len() - ); if count * 3 <= validator_list.len() * 2 { return Err(Error::NotEnoughSignatures); } diff --git a/devtools/axon-tools/src/rlp_codec.rs b/devtools/axon-tools/src/rlp_codec.rs index ba0778126..e72501b4a 100644 --- a/devtools/axon-tools/src/rlp_codec.rs +++ b/devtools/axon-tools/src/rlp_codec.rs @@ -1,4 +1,7 @@ -use crate::types::{BlockVersion, Proposal, Vote}; +#[cfg(feature = "impl-rlp")] +use crate::types::BlockVersion; +#[cfg(feature = "proof")] +use crate::types::{Proposal, Vote}; #[cfg(feature = "impl-rlp")] use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream}; diff --git a/devtools/axon-tools/src/tests/verify_proof.rs b/devtools/axon-tools/src/tests/verify_proof.rs index 726c866e7..4f3e348f1 100644 --- a/devtools/axon-tools/src/tests/verify_proof.rs +++ b/devtools/axon-tools/src/tests/verify_proof.rs @@ -1,16 +1,24 @@ +#[cfg(feature = "proof")] use crate::hash::keccak_256; +#[cfg(feature = "proof")] use crate::types::{AxonBlock, BlockVersion, Metadata, Proof, Proposal, ValidatorExtend}; +#[cfg(feature = "proof")] use bytes::Bytes; +#[cfg(feature = "proof")] use ethereum_types::{H160, H256, U256}; +#[cfg(feature = "proof")] use rlp::Encodable; +#[cfg(feature = "proof")] use serde::de::DeserializeOwned; +#[cfg(feature = "proof")] fn read_json(path: &str) -> T { let json = std::fs::read_to_string(path).unwrap(); serde_json::from_str(&json).unwrap() } #[test] +#[cfg(feature = "proof")] fn test_proposal() { let proposal = Proposal { version: BlockVersion::V0, @@ -46,6 +54,7 @@ fn test_proposal() { } #[test] +#[cfg(feature = "proof")] fn test_verify_proof() { let block: AxonBlock = read_json("src/tests/block.json"); let proof: Proof = read_json("src/tests/proof.json"); diff --git a/devtools/axon-tools/src/tests/verify_trie_proof.rs b/devtools/axon-tools/src/tests/verify_trie_proof.rs index 168be3701..6af4fdb84 100644 --- a/devtools/axon-tools/src/tests/verify_trie_proof.rs +++ b/devtools/axon-tools/src/tests/verify_trie_proof.rs @@ -1,12 +1,19 @@ +#[cfg(feature = "proof")] use crate::verify_trie_proof; +#[cfg(feature = "proof")] use eth_light_client_in_ckb_prover::{encode_receipt, Receipts}; -use ethereum_types::{Bloom, H256, U256}; +#[cfg(feature = "proof")] +use ethereum_types::U256; +use ethereum_types::{Bloom, H256}; +use ethers_core::{types::Log, utils::keccak256}; +#[cfg(feature = "proof")] use ethers_core::{ - types::{Log, TransactionReceipt, U64}, - utils::{keccak256, rlp}, + types::{TransactionReceipt, U64}, + utils::rlp, }; #[test] +#[cfg(feature = "std")] fn test_receipt() { let mut tx_receipts = Vec::::new(); @@ -52,6 +59,7 @@ fn test_receipt() { } #[test] +#[cfg(all(feature = "proof", feature = "std"))] fn test_verify_trie_proof() { let mut tx_receipts = Vec::::new(); diff --git a/devtools/axon-tools/src/types.rs b/devtools/axon-tools/src/types.rs index cc7e7c415..6890e1eb7 100644 --- a/devtools/axon-tools/src/types.rs +++ b/devtools/axon-tools/src/types.rs @@ -1,10 +1,9 @@ use crate::error::TypesError; +use alloc::vec; use alloc::vec::Vec; use bytes::{Bytes, BytesMut}; use core::cmp::Ordering; -use core::str::FromStr; use ethereum_types::{Bloom, H160, H256, U256}; -use faster_hex::withpfx_lowercase; #[cfg(feature = "impl-serde")] use serde::{Deserialize, Serialize}; @@ -16,12 +15,16 @@ use rlp_derive::{RlpDecodable, RlpEncodable}; use crate::hex::{hex_decode, hex_encode}; #[cfg(feature = "hex")] use crate::Error; +#[cfg(feature = "hex")] +use core::str::FromStr; +#[cfg(feature = "hex")] +use faster_hex::withpfx_lowercase; +#[cfg(feature = "std")] const HEX_PREFIX: &str = "0x"; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] -#[cfg(feature = "impl-rlp")] -#[derive(RlpEncodable, RlpDecodable)] +#[cfg_attr(feature = "impl-rlp", derive(RlpEncodable, RlpDecodable))] pub struct Hex(Bytes); impl Hex { @@ -41,10 +44,12 @@ impl Hex { Hex(BytesMut::from(src.as_ref()).freeze()) } + #[cfg(feature = "hex")] pub fn as_string(&self) -> String { HEX_PREFIX.to_string() + &hex_encode(self.0.as_ref()) } + #[cfg(feature = "hex")] pub fn as_string_trim0x(&self) -> String { hex_encode(self.0.as_ref()) } @@ -53,6 +58,7 @@ impl Hex { self.0.clone() } + #[cfg(feature = "hex")] fn is_prefixed(s: &str) -> bool { s.starts_with(HEX_PREFIX) } @@ -70,6 +76,14 @@ impl AsRef<[u8]> for Hex { } } +impl From> for Hex { + fn from(bytes: Vec) -> Self { + let bytes = Bytes::from(bytes); + Hex(bytes) + } +} + +#[cfg(feature = "hex")] impl FromStr for Hex { type Err = Error; @@ -88,6 +102,7 @@ impl From for Bytes { } } +#[cfg(all(feature = "impl-serde", feature = "std"))] impl Serialize for Hex { fn serialize(&self, serializer: S) -> Result where @@ -97,6 +112,7 @@ impl Serialize for Hex { } } +#[cfg(all(feature = "impl-serde", feature = "std"))] impl<'de> Deserialize<'de> for Hex { fn deserialize(deserializer: D) -> Result where @@ -108,8 +124,7 @@ impl<'de> Deserialize<'de> for Hex { } #[derive(Default, Copy, Clone, Debug, PartialEq, Eq)] -#[cfg(feature = "impl-serde")] -#[derive(Serialize, Deserialize)] +#[cfg_attr(feature = "impl-serde", derive(Serialize, Deserialize))] pub enum BlockVersion { #[default] V0, @@ -123,6 +138,7 @@ impl From for u8 { } } +// #[cfg(feature = "std")] impl TryFrom for BlockVersion { type Error = TypesError; @@ -146,7 +162,7 @@ pub type BlockNumber = u64; #[cfg_attr(feature = "impl-serde", derive(serde::Serialize, serde::Deserialize))] pub struct ExtraData { #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde( serialize_with = "withpfx_lowercase::serialize", deserialize_with = "withpfx_lowercase::deserialize" @@ -171,7 +187,7 @@ pub struct AxonHeader { pub receipts_root: MerkleRoot, pub log_bloom: Bloom, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde( serialize_with = "encode::serialize_uint", deserialize_with = "decode::deserialize_hex_u64" @@ -179,7 +195,7 @@ pub struct AxonHeader { )] pub timestamp: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde( serialize_with = "encode::serialize_uint", deserialize_with = "decode::deserialize_hex_u64" @@ -195,7 +211,7 @@ pub struct AxonHeader { pub base_fee_per_gas: U256, pub proof: Proof, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde( serialize_with = "encode::serialize_uint", deserialize_with = "decode::deserialize_hex_u32" @@ -203,7 +219,7 @@ pub struct AxonHeader { )] pub call_system_script_count: u32, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde( serialize_with = "encode::serialize_uint", deserialize_with = "decode::deserialize_hex_u64" @@ -235,12 +251,12 @@ pub struct Proposal { pub transactions_root: MerkleRoot, pub signed_txs_hash: Hash, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub timestamp: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub number: BlockNumber, @@ -249,12 +265,12 @@ pub struct Proposal { pub base_fee_per_gas: U256, pub proof: Proof, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub chain_id: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u32") )] pub call_system_script_count: u32, @@ -269,7 +285,7 @@ pub struct Proposal { #[cfg_attr(feature = "impl-serde", derive(serde::Serialize, serde::Deserialize))] pub struct Proof { #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde( serialize_with = "encode::serialize_uint", deserialize_with = "decode::deserialize_hex_u64" @@ -277,7 +293,7 @@ pub struct Proof { )] pub number: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde( serialize_with = "encode::serialize_uint", deserialize_with = "decode::deserialize_hex_u64" @@ -286,7 +302,7 @@ pub struct Proof { pub round: u64, pub block_hash: Hash, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde( serialize_with = "withpfx_lowercase::serialize", deserialize_with = "withpfx_lowercase::deserialize" @@ -294,7 +310,7 @@ pub struct Proof { )] pub signature: Bytes, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde( serialize_with = "withpfx_lowercase::serialize", deserialize_with = "withpfx_lowercase::deserialize" @@ -341,6 +357,7 @@ pub struct Vote { } #[cfg(test)] +#[cfg(feature = "proof")] impl Vote { fn random() -> Self { Self { @@ -360,12 +377,12 @@ impl Vote { #[cfg_attr(feature = "impl-serde", derive(serde::Serialize, serde::Deserialize))] pub struct MetadataVersion { #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub start: BlockNumber, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub end: BlockNumber, @@ -381,21 +398,28 @@ impl MetadataVersion { } } -#[derive(Default, Clone, Debug, PartialEq, Eq)] +#[derive(Default, Clone, PartialEq, Eq)] #[cfg_attr( feature = "impl-rlp", derive(rlp_derive::RlpEncodable, rlp_derive::RlpDecodable) )] -#[cfg_attr(feature = "impl-serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + all(feature = "impl-serde", feature = "std"), + derive(serde::Serialize, serde::Deserialize) +)] +#[cfg_attr(feature = "hex", derive(Debug))] pub struct Metadata { pub version: MetadataVersion, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub epoch: u64, pub verifier_list: Vec, - #[serde(skip_deserializing)] + #[cfg_attr( + all(feature = "impl-serde", feature = "std"), + serde(skip_deserializing) + )] pub propose_counter: Vec, pub consensus_config: ConsensusConfig, } @@ -408,53 +432,54 @@ pub struct Metadata { #[cfg_attr(feature = "impl-serde", derive(serde::Serialize, serde::Deserialize))] pub struct ConsensusConfig { #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub gas_limit: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub interval: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub propose_ratio: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub prevote_ratio: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub precommit_ratio: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub brake_ratio: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub tx_num_limit: u64, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub max_tx_size: u64, } -#[derive(rlp_derive::RlpEncodable, rlp_derive::RlpDecodable, Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "impl-rlp", derive(RlpEncodable, RlpDecodable))] #[cfg_attr(feature = "impl-serde", derive(serde::Serialize, serde::Deserialize))] pub struct ProposeCount { pub address: H160, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u64") )] pub count: u64, @@ -465,18 +490,21 @@ pub struct ProposeCount { feature = "impl-rlp", derive(rlp_derive::RlpEncodable, rlp_derive::RlpDecodable) )] -#[cfg_attr(feature = "impl-serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + all(feature = "impl-serde", feature = "std"), + derive(serde::Serialize, serde::Deserialize) +)] pub struct ValidatorExtend { pub bls_pub_key: Hex, pub pub_key: Hex, pub address: H160, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u32") )] pub propose_weight: u32, #[cfg_attr( - feature = "impl-serde", + all(feature = "impl-serde", feature = "std"), serde(deserialize_with = "decode::deserialize_hex_u32") )] pub vote_weight: u32, @@ -494,16 +522,7 @@ impl Ord for ValidatorExtend { } } -impl From for Validator { - fn from(ve: ValidatorExtend) -> Self { - Validator { - pub_key: ve.pub_key.as_bytes(), - propose_weight: ve.propose_weight, - vote_weight: ve.vote_weight, - } - } -} - +#[cfg(feature = "hex")] impl std::fmt::Debug for ValidatorExtend { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { let bls_pub_key = self.bls_pub_key.as_string_trim0x(); @@ -539,7 +558,7 @@ pub struct CkbRelatedInfo { pub reward_smt_type_id: H256, } -#[cfg(feature = "impl-serde")] +#[cfg(all(feature = "impl-serde", feature = "std"))] mod encode { use ethereum_types::U256; use serde::ser::Serializer; @@ -590,7 +609,7 @@ mod encode { } } -#[cfg(feature = "impl-serde")] +#[cfg(all(feature = "impl-serde", feature = "std"))] mod decode { use ethereum_types::U256; use serde::de::{Deserialize, Deserializer}; @@ -697,6 +716,7 @@ mod tests { } #[test] + #[cfg(feature = "proof")] fn test_vote_codec() { let vote = Vote::random(); let raw = rlp::encode(&vote);