Skip to content

Commit 729d5e1

Browse files
committed
Merge branch 'master' into feat/ferment
# Conflicts: # dash/src/sml/masternode_list_engine/mod.rs
2 parents 9cd29dd + a8b5d0b commit 729d5e1

File tree

8 files changed

+86
-56
lines changed

8 files changed

+86
-56
lines changed

dash/src/bip32.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ use serde;
3636

3737
use crate::base58;
3838
use crate::crypto::key::{self, Keypair, PrivateKey, PublicKey};
39-
use crate::dip9::{COINJOIN_PATH_MAINNET, COINJOIN_PATH_TESTNET, DASH_BIP44_PATH_MAINNET, DASH_BIP44_PATH_TESTNET, IDENTITY_AUTHENTICATION_PATH_MAINNET, IDENTITY_AUTHENTICATION_PATH_TESTNET, IDENTITY_INVITATION_PATH_MAINNET, IDENTITY_INVITATION_PATH_TESTNET, IDENTITY_REGISTRATION_PATH_MAINNET, IDENTITY_REGISTRATION_PATH_TESTNET, IDENTITY_TOPUP_PATH_MAINNET, IDENTITY_TOPUP_PATH_TESTNET};
39+
use crate::dip9::{
40+
COINJOIN_PATH_MAINNET, COINJOIN_PATH_TESTNET, DASH_BIP44_PATH_MAINNET, DASH_BIP44_PATH_TESTNET,
41+
IDENTITY_AUTHENTICATION_PATH_MAINNET, IDENTITY_AUTHENTICATION_PATH_TESTNET,
42+
IDENTITY_INVITATION_PATH_MAINNET, IDENTITY_INVITATION_PATH_TESTNET,
43+
IDENTITY_REGISTRATION_PATH_MAINNET, IDENTITY_REGISTRATION_PATH_TESTNET,
44+
IDENTITY_TOPUP_PATH_MAINNET, IDENTITY_TOPUP_PATH_TESTNET,
45+
};
4046
use crate::hash_types::XpubIdentifier;
4147
use crate::internal_macros::impl_bytes_newtype;
4248
use crate::io::Write;
@@ -489,16 +495,15 @@ impl DerivationPath {
489495
]);
490496
root_derivation_path
491497
}
492-
pub fn coinjoin_path(
493-
network: Network,
494-
account: u32,
495-
) -> Self {
498+
pub fn coinjoin_path(network: Network, account: u32) -> Self {
496499
let mut root_derivation_path: DerivationPath = match network {
497500
Network::Dash => COINJOIN_PATH_MAINNET,
498501
_ => COINJOIN_PATH_TESTNET,
499502
}
500503
.into();
501-
root_derivation_path.0.extend(&[ChildNumber::Hardened { index: account }]);
504+
root_derivation_path.0.extend(&[ChildNumber::Hardened {
505+
index: account,
506+
}]);
502507
root_derivation_path
503508
}
504509

dash/src/dip9.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,30 @@ pub const DASH_BIP44_PATH_TESTNET: IndexConstPath<2> = IndexConstPath {
155155

156156
pub const COINJOIN_PATH_MAINNET: IndexConstPath<3> = IndexConstPath {
157157
indexes: [
158-
ChildNumber::Hardened { index: FEATURE_PURPOSE },
159-
ChildNumber::Hardened { index: DASH_COIN_TYPE },
160-
ChildNumber::Hardened { index: FEATURE_PURPOSE_COINJOIN },
158+
ChildNumber::Hardened {
159+
index: FEATURE_PURPOSE,
160+
},
161+
ChildNumber::Hardened {
162+
index: DASH_COIN_TYPE,
163+
},
164+
ChildNumber::Hardened {
165+
index: FEATURE_PURPOSE_COINJOIN,
166+
},
161167
],
162168
reference: DerivationPathReference::CoinJoin,
163169
path_type: DerivationPathType::ANONYMOUS_FUNDS,
164170
};
165171
pub const COINJOIN_PATH_TESTNET: IndexConstPath<3> = IndexConstPath {
166172
indexes: [
167-
ChildNumber::Hardened { index: FEATURE_PURPOSE },
168-
ChildNumber::Hardened { index: DASH_TESTNET_COIN_TYPE },
169-
ChildNumber::Hardened { index: FEATURE_PURPOSE_COINJOIN },
173+
ChildNumber::Hardened {
174+
index: FEATURE_PURPOSE,
175+
},
176+
ChildNumber::Hardened {
177+
index: DASH_TESTNET_COIN_TYPE,
178+
},
179+
ChildNumber::Hardened {
180+
index: FEATURE_PURPOSE_COINJOIN,
181+
},
170182
],
171183
reference: DerivationPathReference::CoinJoin,
172184
path_type: DerivationPathType::ANONYMOUS_FUNDS,

dash/src/sml/masternode_list/from_diff.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::BTreeMap;
2-
31
use crate::bls_sig_utils::BLSSignature;
42
use crate::network::message_sml::MnListDiff;
53
use crate::sml::error::SmlError;
@@ -11,6 +9,8 @@ use crate::sml::quorum_entry::qualified_quorum_entry::{
119
QualifiedQuorumEntry, VerifyingChainLockSignaturesType,
1210
};
1311
use crate::{BlockHash, Network};
12+
use hashes::Hash;
13+
use std::collections::BTreeMap;
1414

1515
pub trait TryFromWithBlockHashLookup<T>: Sized {
1616
type Error;
@@ -67,7 +67,9 @@ impl TryFromWithBlockHashLookup<MnListDiff> for MasternodeList {
6767
{
6868
if let Some(genesis_block_hash) = network.known_genesis_block_hash() {
6969
// Check if the base block is the genesis block
70-
if diff.base_block_hash != genesis_block_hash {
70+
if diff.base_block_hash != genesis_block_hash
71+
&& diff.base_block_hash.as_byte_array() != &[0; 32]
72+
{
7173
return Err(SmlError::BaseBlockNotGenesis(diff.base_block_hash));
7274
}
7375
}

dash/src/sml/masternode_list_engine/mod.rs

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ mod validation;
88

99
use std::collections::{BTreeMap, BTreeSet};
1010

11-
#[cfg(feature = "bincode")]
12-
use bincode::{Decode, Encode};
13-
#[cfg(feature = "serde")]
14-
use serde::{Deserialize, Serialize};
15-
1611
use crate::bls_sig_utils::{BLSPublicKey, BLSSignature};
1712
use crate::network::message_qrinfo::{QRInfo, QuorumSnapshot};
1813
use crate::network::message_sml::MnListDiff;
@@ -28,6 +23,11 @@ use crate::sml::quorum_entry::qualified_quorum_entry::{
2823
use crate::sml::quorum_validation_error::{ClientDataRetrievalError, QuorumValidationError};
2924
use crate::blockdata::transaction::special_transaction::quorum_commitment::QuorumEntry;
3025
use crate::{BlockHash, Network, QuorumHash};
26+
#[cfg(feature = "bincode")]
27+
use bincode::{Decode, Encode};
28+
use hashes::Hash;
29+
#[cfg(feature = "serde")]
30+
use serde::{Deserialize, Serialize};
3131

3232
#[derive(Clone, Eq, PartialEq, Default)]
3333
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -71,10 +71,15 @@ impl From<MasternodeListEngineBTreeMapBlockContainer> for MasternodeListEngineBl
7171
}
7272

7373
impl MasternodeListEngineBlockContainer {
74-
pub fn get_height(&self, block: &BlockHash) -> Option<&CoreBlockHeight> {
75-
match self {
76-
MasternodeListEngineBlockContainer::BTreeMapContainer(map) => {
77-
map.block_heights.get(block)
74+
pub fn get_height(&self, block_hash: &BlockHash) -> Option<CoreBlockHeight> {
75+
if block_hash.as_byte_array() == &[0; 32] {
76+
// rep
77+
Some(0)
78+
} else {
79+
match self {
80+
MasternodeListEngineBlockContainer::BTreeMapContainer(map) => {
81+
map.block_heights.get(block_hash).copied()
82+
}
7883
}
7984
}
8085
}
@@ -222,7 +227,7 @@ impl MasternodeListEngine {
222227
else {
223228
return true;
224229
};
225-
!self.masternode_lists.contains_key(block_height)
230+
!self.masternode_lists.contains_key(&block_height)
226231
})
227232
.collect()
228233
} else {
@@ -249,7 +254,7 @@ impl MasternodeListEngine {
249254
else {
250255
return true;
251256
};
252-
!self.masternode_lists.contains_key(block_height)
257+
!self.masternode_lists.contains_key(&block_height)
253258
})
254259
.collect()
255260
} else {
@@ -274,7 +279,7 @@ impl MasternodeListEngine {
274279
) -> Option<&MasternodeList> {
275280
self.block_container
276281
.get_height(block_hash)
277-
.and_then(|height| self.masternode_lists.get(height))
282+
.and_then(|height| self.masternode_lists.get(&height))
278283
}
279284

280285
pub fn feed_block_height(&mut self, height: CoreBlockHeight, block_hash: BlockHash) {
@@ -415,15 +420,18 @@ impl MasternodeListEngine {
415420

416421
let can_verify_previous = quorum_snapshot_and_mn_list_diff_at_h_minus_4c.is_some();
417422

418-
let h_height = self
419-
.block_container
420-
.get_height(&mn_list_diff_h.block_hash)
421-
.copied()
422-
.ok_or(QuorumValidationError::RequiredBlockNotPresent(mn_list_diff_h.block_hash))?;
423-
let tip_height =
424-
self.block_container.get_height(&mn_list_diff_tip.block_hash).copied().ok_or(
425-
QuorumValidationError::RequiredBlockNotPresent(mn_list_diff_tip.block_hash),
426-
)?;
423+
let h_height = self.block_container.get_height(&mn_list_diff_h.block_hash).ok_or(
424+
QuorumValidationError::RequiredBlockNotPresent(
425+
mn_list_diff_h.block_hash,
426+
"getting height at diff h".to_string(),
427+
),
428+
)?;
429+
let tip_height = self.block_container.get_height(&mn_list_diff_tip.block_hash).ok_or(
430+
QuorumValidationError::RequiredBlockNotPresent(
431+
mn_list_diff_tip.block_hash,
432+
"getting height at diff tip".to_string(),
433+
),
434+
)?;
427435
let rotation_quorum_type = last_commitment_per_index
428436
.first()
429437
.map(|quorum_entry| quorum_entry.llmq_type)
@@ -677,21 +685,20 @@ impl MasternodeListEngine {
677685
.known_genesis_block_hash()
678686
.or_else(|| self.block_container.get_hash(&0).cloned())
679687
{
680-
if base_block_hash == known_genesis_block_hash {
688+
if base_block_hash == known_genesis_block_hash
689+
|| base_block_hash.as_byte_array() == &[0; 32]
690+
{
681691
// we are going from the start
682692
let masternode_list = masternode_list_diff.try_into_with_block_hash_lookup(
683-
|block_hash| {
684-
diff_end_height.or(self.block_container.get_height(block_hash).copied())
685-
},
693+
|block_hash| diff_end_height.or(self.block_container.get_height(block_hash)),
686694
self.network,
687695
)?;
688696

689697
let diff_end_height = match diff_end_height {
690698
None => self
691699
.block_container
692700
.get_height(&block_hash)
693-
.ok_or(SmlError::BlockHashLookupFailed(block_hash))
694-
.cloned()?,
701+
.ok_or(SmlError::BlockHashLookupFailed(block_hash))?,
695702
Some(diff_end_height) => {
696703
self.block_container.feed_block_height(diff_end_height, block_hash);
697704
diff_end_height
@@ -707,7 +714,7 @@ impl MasternodeListEngine {
707714
else {
708715
return Err(SmlError::BlockHashLookupFailed(masternode_list_diff.base_block_hash));
709716
};
710-
let Some(base_masternode_list) = self.masternode_lists.get(base_height) else {
717+
let Some(base_masternode_list) = self.masternode_lists.get(&base_height) else {
711718
return Err(SmlError::MissingStartMasternodeList(masternode_list_diff.base_block_hash));
712719
};
713720

@@ -717,8 +724,7 @@ impl MasternodeListEngine {
717724
None => self
718725
.block_container
719726
.get_height(&block_hash)
720-
.ok_or(SmlError::BlockHashLookupFailed(block_hash))
721-
.cloned()?,
727+
.ok_or(SmlError::BlockHashLookupFailed(block_hash))?,
722728
Some(diff_end_height) => diff_end_height,
723729
};
724730

@@ -1130,11 +1136,8 @@ mod tests {
11301136
}
11311137

11321138
masternode_list_engine
1133-
.feed_qr_info::<fn(&BlockHash) -> Result<u32, ClientDataRetrievalError>, fn(&BlockHash) -> Result<Option<BLSSignature>, ClientDataRetrievalError>>(
1134-
qr_info,
1135-
true,
1136-
true,
1137-
None,
1139+
.feed_qr_info::<fn(&BlockHash) -> Result<u32, ClientDataRetrievalError>>(
1140+
qr_info, true, true, None,
11381141
)
11391142
.expect("expected to feed_qr_info");
11401143

dash/src/sml/masternode_list_engine/non_rotated_quorum_construction.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ impl MasternodeListEngine {
2323
))
2424
}
2525
} else {
26-
Err(QuorumValidationError::RequiredBlockNotPresent(*block_hash))
26+
Err(QuorumValidationError::RequiredBlockNotPresent(
27+
*block_hash,
28+
"looking for masternode list and height for block hash 8 blocks ago".to_string(),
29+
))
2730
}
2831
}
2932

dash/src/sml/masternode_list_engine/rotated_quorum_construction.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl MasternodeListEngine {
3535
else {
3636
return Err(QuorumValidationError::RequiredBlockNotPresent(
3737
quorum.quorum_entry.quorum_hash,
38+
"getting height when finding rotated masternodes for quorum".to_string(),
3839
));
3940
};
4041
let llmq_type = quorum.quorum_entry.llmq_type;
@@ -82,7 +83,7 @@ impl MasternodeListEngine {
8283
self.block_container.get_height(&quorum.quorum_entry.quorum_hash)
8384
else {
8485
return Err(QuorumValidationError::RequiredBlockNotPresent(
85-
quorum.quorum_entry.quorum_hash,
86+
quorum.quorum_entry.quorum_hash, "getting height for a quorum hash when trying to find rotated masternodes for quorums".to_string()
8687
));
8788
};
8889
let llmq_type = quorum.quorum_entry.llmq_type;
@@ -145,7 +146,10 @@ impl MasternodeListEngine {
145146
for quorum in &qr_info.last_commitment_per_index {
146147
let Some(quorum_block_height) = self.block_container.get_height(&quorum.quorum_hash)
147148
else {
148-
return Err(QuorumValidationError::RequiredBlockNotPresent(quorum.quorum_hash));
149+
return Err(QuorumValidationError::RequiredBlockNotPresent(
150+
quorum.quorum_hash,
151+
"getting required cl_sig heights".to_string(),
152+
));
149153
};
150154
let llmq_params = quorum.llmq_type.params();
151155
let quorum_index = quorum_block_height % llmq_params.dkg_params.interval;
@@ -164,6 +168,7 @@ impl MasternodeListEngine {
164168
else {
165169
return Err(QuorumValidationError::RequiredBlockNotPresent(
166170
quorum.quorum_hash,
171+
"getting height for quorum hash for diff at h minus 4c".to_string(),
167172
));
168173
};
169174
let llmq_params = quorum.llmq_type.params();

dash/src/sml/quorum_entry/qualified_quorum_entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl QualifiedQuorumEntry {
7070
/// * `result` - A `Result` containing either success (`Ok`) or a `QuorumValidationError`.
7171
pub fn update_quorum_status(&mut self, result: Result<(), QuorumValidationError>) {
7272
match result {
73-
Err(QuorumValidationError::RequiredBlockNotPresent(block_hash)) => {
73+
Err(QuorumValidationError::RequiredBlockNotPresent(block_hash, _)) => {
7474
self.verified = LLMQEntryVerificationStatus::Skipped(
7575
LLMQEntryVerificationSkipStatus::UnknownBlock(block_hash),
7676
);

dash/src/sml/quorum_validation_error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub enum ClientDataRetrievalError {
2626
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
2727
#[cfg_attr(feature = "apple", ferment_macro::export)]
2828
pub enum QuorumValidationError {
29-
#[error("Required block not present: {0}")]
30-
RequiredBlockNotPresent(BlockHash),
29+
#[error("Required block not present: {0} ({1})")]
30+
RequiredBlockNotPresent(BlockHash, String),
3131

3232
#[error("Required block height not present: {0}")]
3333
RequiredBlockHeightNotPresent(CoreBlockHeight),

0 commit comments

Comments
 (0)