Skip to content

Commit a6f83a1

Browse files
bincode serialization
1 parent 01292ba commit a6f83a1

File tree

18 files changed

+126
-2
lines changed

18 files changed

+126
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ edition = "2021"
1919

2020
# Please don't forget to add relevant features to docs.rs below
2121
[features]
22-
default = [ "std", "secp-recovery", "core-block-hash-use-x11", "quorum_validation" ]
22+
default = [ "std", "secp-recovery", "core-block-hash-use-x11", "quorum_validation", "bincode" ]
2323
base64 = [ "base64-compat" ]
2424
rand-std = ["secp256k1/rand"]
2525
rand = ["secp256k1/rand"]
@@ -31,6 +31,7 @@ core-block-hash-use-x11 = ["dashcore_hashes/x11"]
3131
bls = ["blsful"]
3232
eddsa = ["ed25519-dalek"]
3333
quorum_validation = ["bls"]
34+
bincode = [ "dep:bincode", "dashcore_hashes/bincode" ]
3435

3536
# At least one of std, no-std must be enabled.
3637
#

dash/src/blockdata/transaction/special_transaction/quorum_commitment.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
//!
1919
2020
use std::io::{Read, Write};
21-
21+
#[cfg(feature = "bincode")]
22+
use bincode::{Decode, Encode};
2223
use crate::bls_sig_utils::{BLSPublicKey, BLSSignature};
2324
use crate::consensus::encode::{
2425
compact_size_len, fixed_bitset_len, read_compact_size, read_fixed_bitset, write_compact_size,
@@ -37,6 +38,7 @@ use crate::sml::quorum_validation_error::QuorumValidationError;
3738
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
3839
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3940
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
41+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
4042
pub struct QuorumEntry {
4143
pub version: u16,
4244
pub llmq_type: LLMQType,

dash/src/bls_sig_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//! and signature.
1818
//!
1919
20+
#[cfg(feature = "bincode")]
21+
use bincode::{Decode, Encode};
2022
#[cfg(feature = "bls")]
2123
use blsful::{Bls12381G2Impl, Pairing};
2224
use hex::{FromHexError, ToHex};
@@ -29,6 +31,7 @@ use crate::sml::quorum_validation_error::QuorumValidationError;
2931
/// A BLS Public key is 48 bytes in the scheme used for Dash Core
3032
#[rustversion::attr(since(1.48), derive(PartialEq, Eq, Ord, PartialOrd, Hash))]
3133
#[derive(Clone, Copy, Debug)]
34+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
3235
pub struct BLSPublicKey([u8; 48]);
3336

3437
impl BLSPublicKey {
@@ -86,6 +89,7 @@ impl fmt::Display for BLSPublicKey {
8689
/// A BLS Signature is 96 bytes in the scheme used for Dash Core
8790
#[rustversion::attr(since(1.48), derive(PartialEq, Eq, Ord, PartialOrd, Hash))]
8891
#[derive(Clone, Copy)]
92+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
8993
pub struct BLSSignature([u8; 96]);
9094

9195
impl BLSSignature {

dash/src/network/constants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ use core::convert::From;
4444
use core::fmt::Display;
4545
use core::str::FromStr;
4646
use core::{fmt, ops};
47+
#[cfg(feature = "bincode")]
48+
use bincode::{Decode, Encode};
4749
use hashes::Hash;
4850
use internals::write_err;
4951

@@ -76,6 +78,7 @@ pub const PROTOCOL_VERSION: u32 = 70220;
7678
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
7779
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
7880
#[non_exhaustive]
81+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
7982
pub enum Network {
8083
/// Classic Dash Core Payment Chain
8184
Dash,

dash/src/sml/llmq_entry_verification.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use core::fmt::{Display, Formatter};
2+
#[cfg(feature = "bincode")]
3+
use bincode::{Decode, Encode};
24
use crate::prelude::CoreBlockHeight;
35
use crate::sml::quorum_validation_error::QuorumValidationError;
46

57
#[derive(Clone, Ord, PartialOrd, PartialEq, Eq, Hash, Debug)]
8+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
69
pub enum LLMQEntryVerificationSkipStatus {
710
NotMarkedForVerification,
811
MissedList(CoreBlockHeight),
@@ -22,6 +25,7 @@ impl Display for LLMQEntryVerificationSkipStatus {
2225
}
2326

2427
#[derive(Clone, Ord, PartialOrd, PartialEq, Eq, Hash, Debug)]
28+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
2529
pub enum LLMQEntryVerificationStatus {
2630
Unknown,
2731
Verified,

dash/src/sml/llmq_type/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ mod network;
55

66
use std::fmt::{Display, Formatter};
77
use std::io;
8+
#[cfg(feature = "bincode")]
9+
use bincode::{Decode, Encode};
810
use crate::bip152::BlockTransactionsRequest;
911
use crate::consensus::{Decodable, Encodable, encode};
1012
use crate::Network;
@@ -290,6 +292,7 @@ pub const LLMQ_DEV_PLATFORM: LLMQParams = LLMQParams {
290292
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Hash, Ord)]
291293
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
292294
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
295+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
293296
pub enum LLMQType {
294297
LlmqtypeUnknown = 0, // other kind of
295298
Llmqtype50_60 = 1, // 50 members, 30 (60%) threshold, 24 / day

dash/src/sml/masternode_list/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ mod scores_for_quorum;
1111
// mod rotation;
1212

1313
use std::collections::BTreeMap;
14+
#[cfg(feature = "bincode")]
15+
use bincode::{Decode, Encode};
1416
use crate::hash_types::{MerkleRootMasternodeList, MerkleRootQuorums};
1517
use crate::sml::llmq_type::LLMQType;
1618
use crate::{BlockHash, ProTxHash, QuorumHash};
1719
use crate::sml::masternode_list_entry::qualified_masternode_list_entry::QualifiedMasternodeListEntry;
1820
use crate::sml::quorum_entry::qualified_quorum_entry::QualifiedQuorumEntry;
1921

2022
#[derive(Clone, Eq, PartialEq)]
23+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
2124
pub struct MasternodeList {
2225
pub block_hash: BlockHash,
2326
pub known_height: u32,

dash/src/sml/masternode_list_engine/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
mod validation;
33

44
use std::collections::{BTreeMap, BTreeSet};
5+
#[cfg(feature = "bincode")]
6+
use bincode::{Decode, Encode};
7+
#[cfg(feature = "serde")]
8+
use serde::{Deserialize, Serialize};
59
use crate::{BlockHash, Network, QuorumHash};
610
use crate::bls_sig_utils::BLSSignature;
711
use crate::network::message_sml::MnListDiff;
@@ -14,6 +18,9 @@ use crate::sml::masternode_list::MasternodeList;
1418
use crate::sml::quorum_validation_error::QuorumValidationError;
1519

1620
#[derive(Clone, Eq, PartialEq)]
21+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
22+
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
23+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
1724
pub struct MasternodeListEngine {
1825
pub block_hashes : BTreeMap<CoreBlockHeight, BlockHash>,
1926
pub block_heights : BTreeMap<BlockHash, CoreBlockHeight>,

dash/src/sml/masternode_list_entry/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::internal_macros::impl_consensus_encoding;
1717
use crate::{ProTxHash, PubkeyHash};
1818

1919
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
20+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
2021
pub enum MasternodeType {
2122
Regular,
2223
HighPerformance { platform_http_port: u16, platform_node_id: PubkeyHash },
@@ -72,6 +73,7 @@ pub struct OperatorPublicKey {
7273
impl_consensus_encoding!(OperatorPublicKey, data, version);
7374

7475
#[derive(Clone, Eq, PartialEq, Debug)]
76+
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
7577
pub struct MasternodeListEntry {
7678
pub version: u16,
7779
pub pro_reg_tx_hash: ProTxHash,
@@ -84,6 +86,8 @@ pub struct MasternodeListEntry {
8486
}
8587

8688
use std::cmp::Ordering;
89+
#[cfg(feature = "bincode")]
90+
use bincode::{Decode, Encode};
8791
use hashes::Hash;
8892

8993
impl Ord for MasternodeListEntry {

0 commit comments

Comments
 (0)