Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions dash-spv/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ mod tests {
use crate::storage::DiskStorageManager;
use crate::test_utils::MockNetworkManager;
use crate::Network;
use dashcore::bls_sig_utils::BLSSignature;
use dashcore::hash_types::{
MerkleRootAssetUnlocks, MerkleRootMasternodeList, MerkleRootQuorums,
};
use dashcore::hashes::Hash;
use dashcore::transaction::special_transaction::coinbase::CoinbasePayload;
use key_wallet::wallet::initialization::WalletAccountCreationOptions;
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
use key_wallet_manager::WalletManager;
Expand Down Expand Up @@ -137,4 +143,59 @@ mod tests {
let wallet_ref = client.wallet();
let _wallet_guard = wallet_ref.read().await;
}

/// The client reports the coinbase payload the masternode list engine
/// kept, and nothing while masternode sync is off.
#[tokio::test]
async fn latest_coinbase_reports_what_the_masternode_list_engine_kept() {
let make_client = |config: ClientConfig| async move {
let storage =
DiskStorageManager::with_temp_dir().await.expect("Failed to create tmp storage");
let wallet =
Arc::new(RwLock::new(WalletManager::<ManagedWalletInfo>::new(config.network)));
DashSpvClient::new(
config,
MockNetworkManager::new(),
storage,
wallet,
vec![Arc::new(())],
)
.await
.expect("client construction must succeed")
};
let storage_dir = TempDir::new().unwrap();

let without_masternodes = make_client(
ClientConfig::mainnet()
.without_filters()
.without_masternodes()
.with_storage_path(storage_dir.path()),
)
.await;
assert_eq!(without_masternodes.latest_coinbase().await, None);

let with_masternodes = make_client(
ClientConfig::mainnet().without_filters().with_storage_path(storage_dir.path()),
)
.await;
assert_eq!(with_masternodes.latest_coinbase().await, None);

let coinbase = CoinbasePayload {
version: 4,
height: 2_400_000,
merkle_root_masternode_list: MerkleRootMasternodeList::all_zeros(),
merkle_root_quorums: MerkleRootQuorums::all_zeros(),
best_cl_height: Some(0),
best_cl_signature: Some(BLSSignature::from([0; 96])),
asset_locked_amount: Some(0),
merkle_root_asset_unlocks: Some(MerkleRootAssetUnlocks::all_zeros()),
};
with_masternodes
.masternode_list_engine()
.expect("masternode sync is on")
.write()
.await
.latest_coinbase = Some(coinbase.clone());
assert_eq!(with_masternodes.latest_coinbase().await, Some(coinbase));
}
}
15 changes: 15 additions & 0 deletions dash-spv/src/client/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::storage::StorageManager;
use dashcore::sml::llmq_type::LLMQType;
use dashcore::sml::masternode_list_engine::MasternodeListEngine;
use dashcore::sml::quorum_entry::qualified_quorum_entry::QualifiedQuorumEntry;
use dashcore::transaction::special_transaction::coinbase::CoinbasePayload;
use dashcore::QuorumHash;
use key_wallet_manager::WalletInterface;
use std::sync::Arc;
Expand Down Expand Up @@ -43,6 +44,20 @@ impl<W: WalletInterface, N: NetworkManager, S: StorageManager> DashSpvClient<W,
}
}

/// **Not secure, and temporary:** the unverified coinbase payload of the
/// highest block an applied masternode list diff carried one for, replaced
/// on the `dev` branch by a version that keeps only coinbases verified
/// against their block (dashpay/rust-dashcore#1202).
///
/// Nothing authenticates the payload, so a single peer can serve one of its
/// choosing; see [`MasternodeListEngine::latest_coinbase`]. `None` while
/// masternode sync is off, and after a restart until a diff whose coinbase
/// carries one is applied.
pub async fn latest_coinbase(&self) -> Option<CoinbasePayload> {
let engine = self.masternode_engine.as_ref()?;
engine.read().await.latest_coinbase().cloned()
}

/// Get a quorum entry by type and hash at a specific block height.
/// Returns `SpvError::QuorumLookupError` if the quorum is not found.
pub async fn get_quorum_at_height(
Expand Down
Loading
Loading