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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
different deposit or start a new one, instead of the generic rejection
message that suggested retrying the same one.

- **Shielded features now detect network support correctly**: the app's
live check of the connected network's protocol version — used to enable
shielded sending, receiving, and transfers — no longer gets stuck at its
startup default. It was silently keeping shielded operations unavailable
regardless of what the connected network actually supports, and also kept
the send-fee estimate from picking up the network's current rate. A
temporary workaround is in place while the underlying issue is fixed
upstream; the send-fee estimate will keep using its last known rate until
that lands.

### Changed

- **Upstream wallet backend updated (`platform-wallet` / `platform-wallet-storage`)**:
Expand Down
86 changes: 69 additions & 17 deletions src/backend_task/platform_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use dash_sdk::dpp::block::extended_epoch_info::{
use dash_sdk::dpp::core_types::validator_set::v0::ValidatorSetV0Getters;
use dash_sdk::dpp::dashcore::hashes::Hash;
use dash_sdk::dpp::dashcore::{Address, Network, ScriptBuf};
use dash_sdk::dpp::data_contract::accessors::v0::DataContractV0Getters;
use dash_sdk::dpp::data_contracts::SystemDataContract;
use dash_sdk::dpp::data_contracts::withdrawals_contract::WithdrawalStatus;
use dash_sdk::dpp::data_contracts::withdrawals_contract::v1::document_types::withdrawal::properties::{
Expand All @@ -28,7 +29,9 @@ use dash_sdk::drive::query::{SelectProjection, OrderClause, WhereClause, WhereOp
use dash_sdk::dpp::address_funds::PlatformAddress;
use dash_sdk::platform::fetch_current_no_parameters::FetchCurrent;
use dash_sdk::platform::proto::get_documents_request::get_documents_request_v0::Start;
use dash_sdk::platform::{DocumentQuery, FetchMany, FetchUnproved, Identifier};
use dash_sdk::platform::{
DataContract, DocumentQuery, Fetch, FetchMany, FetchUnproved, Identifier,
};
use dash_sdk::query_types::{
AddressInfo, CurrentQuorumsInfo, NoParamQuery, ProtocolVersionUpgrades, TotalCreditsInPlatform,
};
Expand Down Expand Up @@ -247,6 +250,16 @@ fn format_extended_epoch_info(
)
}

fn format_unavailable_current_epoch_info(protocol_version: u32) -> String {
format!(
"Current Epoch Information:\n\
• Protocol Version: {protocol_version}\n\
• Epoch details and fee multiplier are temporarily unavailable while \
dashpay/platform#4231 is unresolved.\n\n\
(The fee multiplier cache was not updated.)"
)
Comment thread
lklimek marked this conversation as resolved.
}

fn format_current_quorums_info(current_quorums_info: &CurrentQuorumsInfo) -> String {
let mut result = String::new();
result.push_str("Current Validator Set Information:\n\n");
Expand Down Expand Up @@ -457,6 +470,23 @@ fn withdrawal_status_str(status: WithdrawalStatus) -> &'static str {
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn epoch_workaround_reports_protocol_version_and_stale_fee_cache() {
assert_eq!(
format_unavailable_current_epoch_info(12),
"Current Epoch Information:\n\
• Protocol Version: 12\n\
• Epoch details and fee multiplier are temporarily unavailable while \
dashpay/platform#4231 is unresolved.\n\n\
(The fee multiplier cache was not updated.)"
);
}
}

/// Flatten one withdrawal [`Document`] into a [`WithdrawalRecord`].
fn extract_withdrawal_record(
document: &Document,
Expand Down Expand Up @@ -550,22 +580,44 @@ impl AppContext {
))
}
PlatformInfoTaskRequestType::CurrentEpochInfo => {
let epoch_info = ExtendedEpochInfo::fetch_current(sdk)
.await
.map_err(TaskError::from)?;

let fee_multiplier = epoch_info.fee_multiplier_permille();
self.set_fee_multiplier_permille(fee_multiplier);
self.set_platform_protocol_version(epoch_info.protocol_version());

let mut formatted = format_extended_epoch_info(epoch_info, self.network, true);
formatted.push_str(&format!(
"\n\n(Fee multiplier cache updated: {}x)",
fee_multiplier as f64 / 1000.0
));
Ok(BackendTaskSuccessResult::PlatformInfo(
PlatformInfoTaskResult::TextResult(formatted),
))
if let Err(error) = DataContract::fetch(sdk, self.dpns_contract.id()).await {
tracing::warn!(
%error,
"Protocol-version ratchet trigger (DPNS contract fetch) failed; \
keeping the SDK's previous protocol version"
);
}
let protocol_version = sdk.protocol_version_number();
self.set_platform_protocol_version(protocol_version);

match ExtendedEpochInfo::fetch_current(sdk).await {
Ok(epoch_info) => {
let fee_multiplier = epoch_info.fee_multiplier_permille();
self.set_fee_multiplier_permille(fee_multiplier);

let mut formatted =
format_extended_epoch_info(epoch_info, self.network, true);
formatted.push_str(&format!(
"\n\n(Fee multiplier cache updated: {}x)",
fee_multiplier as f64 / 1000.0
));
Ok(BackendTaskSuccessResult::PlatformInfo(
PlatformInfoTaskResult::TextResult(formatted),
))
}
Err(error) => {
tracing::warn!(
%error,
"Current epoch fetch is blocked by dashpay/platform#4231; \
keeping the cached fee multiplier"
);
Ok(BackendTaskSuccessResult::PlatformInfo(
PlatformInfoTaskResult::TextResult(
format_unavailable_current_epoch_info(protocol_version),
),
))
}
}
}
PlatformInfoTaskRequestType::TotalCreditsOnPlatform => {
let total_credits = TotalCreditsInPlatform::fetch_current(sdk)
Expand Down
27 changes: 23 additions & 4 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use dash_sdk::dpp::state_transition::StateTransitionSigningOptions;
use dash_sdk::dpp::state_transition::batch_transition::methods::StateTransitionCreationOptions;
use dash_sdk::dpp::system_data_contracts::{SystemDataContract, load_system_data_contract};
use dash_sdk::dpp::version::PlatformVersion;
use dash_sdk::dpp::version::v11::PLATFORM_V11;
use dash_sdk::dpp::version::v12::PLATFORM_V12;
use dash_sdk::platform::DataContract;
use dash_sdk::platform::Identifier;
use egui::Context;
Expand Down Expand Up @@ -1532,16 +1532,35 @@ impl AppContext {
}

/// Returns the default platform version for the given network.
// TODO: Ideally use sdk.load().version() but this is a free function with no sdk access.
// Every network currently pins the same version.
// TODO(platform#4231): Seeded at v12 (not pinned) so `Sdk`'s protocol-version
// ratchet stays active. See `PlatformInfoTaskRequestType::CurrentEpochInfo` for
// why `ExtendedEpochInfo::fetch_current` can't be used directly right now.
// Revert to `.with_version()` (a hard pin) or otherwise reconsider this once
// https://github.com/dashpay/platform/pull/4231 merges and this repo's platform
// pin advances past it.
pub(crate) const fn default_platform_version(_network: &Network) -> &'static PlatformVersion {
&PLATFORM_V11
&PLATFORM_V12
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn epoch_workaround_uses_v12_for_every_network() {
for network in [
Network::Mainnet,
Network::Testnet,
Network::Devnet,
Network::Regtest,
] {
assert_eq!(
default_platform_version(&network).protocol_version,
PLATFORM_V12.protocol_version
);
}
}

#[test]
fn install_secret_prompt_recovers_poisoned_slot() {
use crate::context::test_support::test_app_context;
Expand Down
2 changes: 1 addition & 1 deletion src/sdk_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn initialize_sdk<P: ContextProvider + 'static>(
let platform_version = default_platform_version(&network);

let sdk = SdkBuilder::new(address_list)
.with_version(platform_version)
.with_initial_version(platform_version)
.with_network(network)
.with_context_provider(context_provider)
.with_settings(request_settings)
Expand Down
Loading