Skip to content

Commit a1dd13c

Browse files
bincode serialization
1 parent a0dde41 commit a1dd13c

File tree

15 files changed

+80
-115
lines changed

15 files changed

+80
-115
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22
members = ["dash", "hashes", "internals", "fuzz"]
3+
resolver = "2"
34

45
[patch.crates-io.dashcore_hashes]
56
path = "hashes"

dash/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ lazy_static = "1.5.0"
7070
ed25519-dalek = { version = "2.1", features = ["rand_core"], optional = true }
7171
blake3 = "1.5"
7272
thiserror = "1"
73+
bls-signatures = { git = "https://github.com/dashpay/bls-signatures", branch = "develop" }
7374

7475
[dev-dependencies]
7576
serde_json = "1.0.96"

dash/src/hash_types.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,30 +147,30 @@ use hashes::{sha256, sha256d, hash160, hash_newtype, Hash, hash_newtype_no_ord};
147147
pub struct QuorumCommitmentHash(sha256d::Hash);
148148

149149
pub struct Sha256dHash(sha256d::Hash);
150-
pub struct ScoreHash(sha256::Hash);
150+
151151
}
152152

153-
// hash_newtype_no_ord! {
154-
//
155-
// }
153+
hash_newtype_no_ord! {
154+
pub struct ScoreHash(sha256::Hash);
155+
}
156156

157-
// impl Ord for ScoreHash {
158-
// fn cmp(&self, other: &Self) -> Ordering {
159-
// let mut self_bytes = self.0.to_byte_array();
160-
// let mut other_bytes = other.0.to_byte_array();
161-
//
162-
// self_bytes.reverse();
163-
// other_bytes.reverse();
164-
//
165-
// self_bytes.cmp(&other_bytes)
166-
// }
167-
// }
168-
//
169-
// impl PartialOrd for ScoreHash {
170-
// fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
171-
// Some(self.cmp(other))
172-
// }
173-
// }
157+
impl Ord for ScoreHash {
158+
fn cmp(&self, other: &Self) -> Ordering {
159+
let mut self_bytes = self.0.to_byte_array();
160+
let mut other_bytes = other.0.to_byte_array();
161+
162+
self_bytes.reverse();
163+
other_bytes.reverse();
164+
165+
self_bytes.cmp(&other_bytes)
166+
}
167+
}
168+
169+
impl PartialOrd for ScoreHash {
170+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
171+
Some(self.cmp(other))
172+
}
173+
}
174174

175175

176176
/// A hash used to identify a quorum

dash/src/sml/masternode_list/scores_for_quorum.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use std::collections::BTreeMap;
2-
use hashes::Hash;
32
use crate::hash_types::{QuorumModifierHash, ScoreHash};
43
use crate::Network;
54
use crate::sml::masternode_list::MasternodeList;
65
use crate::sml::masternode_list_entry::MasternodeType;
76
use crate::sml::masternode_list_entry::qualified_masternode_list_entry::QualifiedMasternodeListEntry;
8-
use crate::sml::order_option::LLMQOrderOption;
97
use crate::sml::quorum_entry::qualified_quorum_entry::QualifiedQuorumEntry;
108
use crate::sml::quorum_entry::quorum_modifier_type::LLMQModifierType;
119

@@ -15,46 +13,13 @@ impl MasternodeList {
1513
quorum: &QualifiedQuorumEntry,
1614
quorum_modifier: LLMQModifierType,
1715
network: Network,
18-
order_option: &LLMQOrderOption,
1916
) -> T
2017
where T: FromIterator<QualifiedMasternodeListEntry> {
2118
let llmq_type = quorum.quorum_entry.llmq_type;
2219
let hpmn_only = llmq_type == network.platform_type();
2320
let quorum_modifier = quorum_modifier.build_llmq_hash();
2421
let score_dictionary = self.scores_for_quorum(quorum_modifier, hpmn_only);
25-
// if quorum.quorum_entry.quorum_hash.to_string() == "0000000000000010d1f1ab756f1f3223485fdc7bce1cbb0e7437383bf7600b06".to_string() {
26-
27-
// } else {
28-
// println!("trying {}", quorum.quorum_entry.quorum_hash)
29-
// }
30-
println!("quorum modifier {}", quorum_modifier.reverse());
31-
if order_option.reverse_sort_scores {
32-
let mut score_dictionary: Vec<_> = score_dictionary.into_iter().collect();
33-
score_dictionary.sort_by(|(s1, _), (s2, _)| {
34-
35-
if order_option.reverse_sort_order {
36-
s2.reverse().cmp(&s1.reverse())
37-
} else {
38-
s1.reverse().cmp(&s2.reverse())
39-
}
40-
});
41-
for (score, list_entry) in score_dictionary.iter().take(5) {
42-
println!("score_hash {} {} -> {}", if order_option.reverse_sort_order { 1 } else { 2}, score, list_entry.masternode_list_entry.pro_reg_tx_hash);
43-
}
44-
score_dictionary.into_iter().take(llmq_type.size() as usize).map(|(a, b)| b).collect()
45-
} else {
46-
if order_option.reverse_sort_order {
47-
for (score, list_entry) in score_dictionary.iter().rev().take(5) {
48-
println!("3 score_hash {} -> {}", score, list_entry.masternode_list_entry.pro_reg_tx_hash);
49-
}
50-
score_dictionary.into_values().rev().take(llmq_type.size() as usize).collect()
51-
} else {
52-
for (score, list_entry) in score_dictionary.iter().take(5) {
53-
println!("4 score_hash {} -> {}", score, list_entry.masternode_list_entry.pro_reg_tx_hash);
54-
}
55-
score_dictionary.into_values().take(llmq_type.size() as usize).collect()
56-
}
57-
}
22+
score_dictionary.into_values().rev().take(llmq_type.size() as usize).collect()
5823
}
5924

6025
pub fn scores_for_quorum(

dash/src/sml/masternode_list_engine/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::sml::error::SmlError::CorruptedCodeExecution;
1515
use crate::sml::llmq_type::LLMQType;
1616
use crate::sml::masternode_list::from_diff::TryIntoWithBlockHashLookup;
1717
use crate::sml::masternode_list::MasternodeList;
18-
use crate::sml::order_option::LLMQOrderOption;
1918
use crate::sml::quorum_validation_error::QuorumValidationError;
2019

2120
#[derive(Clone, Eq, PartialEq)]
@@ -145,7 +144,7 @@ impl MasternodeListEngine {
145144
let mut inner = BTreeMap::new();
146145

147146
for (quorum_hash, quorum_entry) in hash_to_quorum_entries.iter() {
148-
inner.insert(*quorum_hash, self.validate_quorum(quorum_entry, &LLMQOrderOption::default()));
147+
inner.insert(*quorum_hash, self.validate_quorum(quorum_entry));
149148
}
150149
results.insert(*quorum_type, inner);
151150
}
@@ -170,11 +169,10 @@ mod tests {
170169
use crate::sml::llmq_type::LLMQType::{Llmqtype100_67, Llmqtype400_60, Llmqtype400_85, Llmqtype50_60};
171170
use crate::sml::masternode_list_engine::MasternodeListEngine;
172171
use std::str::FromStr;
173-
use crate::sml::order_option::LLMQOrderOption;
174172

175173
#[test]
176174
fn deserialize_mn_list_engine_and_validate_quorums() {
177-
let block_hex = include_str!("../../../tests/data/test_DML_diffs/masternode_list_engine.hex");
175+
let block_hex = include_str!("../../../tests/data/test_DML_diffs/masternode_list_engine3.hex");
178176
let data = hex::decode(block_hex).expect("decode hex");
179177
let mut mn_list_engine: MasternodeListEngine = bincode::decode_from_slice(&data, bincode::config::standard()).expect("expected to decode").0;
180178

@@ -199,7 +197,7 @@ mod tests {
199197

200198
#[test]
201199
fn deserialize_mn_list_engine_and_validate_single_quorum() {
202-
let block_hex = include_str!("../../../tests/data/test_DML_diffs/masternode_list_engine2.hex");
200+
let block_hex = include_str!("../../../tests/data/test_DML_diffs/masternode_list_engine3.hex");
203201
let data = hex::decode(block_hex).expect("decode hex");
204202
let mn_list_engine: MasternodeListEngine = bincode::decode_from_slice(&data, bincode::config::standard()).expect("expected to decode").0;
205203

@@ -211,8 +209,6 @@ mod tests {
211209

212210
let quorum = last_masternode_list.quorum_entry_of_type_for_quorum_hash(Llmqtype100_67, QuorumHash::from_str("000000000000001d4ebc43dbf9b25d2af6421641a84a1e04dd58f65d07b7ecf7").expect("expected to get quorum hash")).expect("expected to find quorum");
213211

214-
for option in LLMQOrderOption::all_combinations() {
215-
println!("using {:?} {:?}", option, mn_list_engine.validate_quorum(quorum, &option))
216-
}
212+
println!("using {:?}", mn_list_engine.validate_quorum(quorum))
217213
}
218214
}

dash/src/sml/masternode_list_engine/validation.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::sml::llmq_entry_verification::{LLMQEntryVerificationSkipStatus, LLMQE
66
use crate::sml::masternode_list_engine::MasternodeListEngine;
77
use crate::sml::masternode_list_entry::MasternodeListEntry;
88
use crate::sml::masternode_list_entry::qualified_masternode_list_entry::QualifiedMasternodeListEntry;
9-
use crate::sml::order_option::LLMQOrderOption;
109
use crate::sml::quorum_entry::qualified_quorum_entry::QualifiedQuorumEntry;
1110
use crate::sml::quorum_entry::quorum_modifier_type::LLMQModifierType;
1211
use crate::sml::quorum_validation_error::QuorumValidationError;
@@ -53,18 +52,17 @@ impl MasternodeListEngine {
5352
// }
5453
// }
5554
pub fn validate_and_update_quorum_status(&self, quorum: &mut QualifiedQuorumEntry) {
56-
quorum.update_quorum_status(self.validate_quorum(quorum, &LLMQOrderOption::default()));
55+
quorum.update_quorum_status(self.validate_quorum(quorum));
5756
}
5857

59-
pub fn validate_quorum(&self, quorum: &QualifiedQuorumEntry, order_option: &LLMQOrderOption) -> Result<(), QuorumValidationError> {
58+
pub fn validate_quorum(&self, quorum: &QualifiedQuorumEntry) -> Result<(), QuorumValidationError> {
6059
// first let's do basic structure validation
6160
quorum.quorum_entry.validate_structure()?;
6261

6362
let llmq_block_hash = quorum.quorum_entry.quorum_hash;
6463
let (masternode_list, known_block_height) = self.masternode_list_and_height_for_block_hash_8_blocks_ago(&llmq_block_hash)?;
6564
let quorum_modifier_type = LLMQModifierType::new_quorum_modifier_type(quorum.quorum_entry.llmq_type, masternode_list.block_hash, known_block_height, &self.known_chain_locks, self.network)?;
66-
// println!("quorum modifier is {} giving {}", quorum_modifier_type, quorum_modifier_type.build_llmq_hash(order_option));
67-
let masternodes : Vec<_> = masternode_list.valid_masternodes_for_quorum(quorum, quorum_modifier_type, self.network, order_option);
65+
let masternodes : Vec<_> = masternode_list.valid_masternodes_for_quorum(quorum, quorum_modifier_type, self.network);
6866
quorum.validate(masternodes.iter().map(|qualified_masternode_list_entry| &qualified_masternode_list_entry.masternode_list_entry))
6967
}
7068
}

dash/src/sml/masternode_list_entry/score.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ impl QualifiedMasternodeListEntry {
77
self.confirmed_hash_hashed_with_pro_reg_tx.is_none() {
88
return None;
99
}
10-
println!("creating score for {}({})\nconfirmed_hash_hashed_with_pro_reg_tx: {}({})\nmodifier {}({})", self.masternode_list_entry.pro_reg_tx_hash, self.masternode_list_entry.pro_reg_tx_hash.reverse(), if let Some(confirmed_hash_hashed_with_pro_reg_tx) = self.confirmed_hash_hashed_with_pro_reg_tx { confirmed_hash_hashed_with_pro_reg_tx.to_string() } else {
11-
"None".to_string()
12-
}, if let Some(confirmed_hash_hashed_with_pro_reg_tx) = self.confirmed_hash_hashed_with_pro_reg_tx { confirmed_hash_hashed_with_pro_reg_tx.reverse().to_string() } else {
13-
"None".to_string()
14-
}, modifier, modifier.reverse());
1510
let score = ScoreHash::create_score(self.confirmed_hash_hashed_with_pro_reg_tx, modifier);
16-
println!("score is {}",score);
1711
Some(score)
1812
}
1913
}

dash/src/sml/order_option.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +0,0 @@
1-
#[derive(Debug, PartialEq, Eq, Clone, Default)]
2-
pub struct LLMQOrderOption {
3-
pub reverse_sort_scores: bool,
4-
pub reverse_sort_order: bool,
5-
}
6-
7-
impl LLMQOrderOption {
8-
pub fn all_combinations() -> Vec<LLMQOrderOption> {
9-
let mut combinations = Vec::with_capacity(8);
10-
11-
for reverse_sort_scores in [false, true] {
12-
for reverse_sort_order in [false, true] {
13-
combinations.push(LLMQOrderOption {
14-
reverse_sort_scores,
15-
reverse_sort_order,
16-
});
17-
}
18-
}
19-
20-
combinations
21-
}
22-
}

dash/src/sml/quorum_entry/quorum_modifier_type.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::{BlockHash, Network};
99
use crate::bls_sig_utils::BLSSignature;
1010
use crate::prelude::CoreBlockHeight;
1111
use crate::sml::llmq_type::LLMQType;
12-
use crate::sml::order_option::LLMQOrderOption;
1312
use crate::sml::quorum_validation_error::QuorumValidationError;
1413

1514
pub enum LLMQModifierType {

0 commit comments

Comments
 (0)