From 8a081de17794845b6f054b656d9270c0f515b120 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Thu, 17 Oct 2024 23:46:30 +0700 Subject: [PATCH 1/4] fix: dpns name vote tallies were not refreshing properly --- .../contested_names/query_dpns_contested_resources.rs | 6 +++--- src/ui/identities/register_dpns_name_screen.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/platform/contested_names/query_dpns_contested_resources.rs b/src/platform/contested_names/query_dpns_contested_resources.rs index b00324ec3..0c85e9a18 100644 --- a/src/platform/contested_names/query_dpns_contested_resources.rs +++ b/src/platform/contested_names/query_dpns_contested_resources.rs @@ -55,7 +55,7 @@ impl AppContext { let names_to_be_updated = self .db - .insert_name_contests_as_normalized_names(contested_resources_as_strings, &self) + .insert_name_contests_as_normalized_names(contested_resources_as_strings.clone(), &self) .map_err(|e| e.to_string())?; sender @@ -63,7 +63,7 @@ impl AppContext { .await .expect("expected to send refresh"); - // Create a semaphore with 15 permits + // Create a semaphore with 24 permits let semaphore = Arc::new(Semaphore::new(24)); let mut handles = Vec::new(); @@ -99,7 +99,7 @@ impl AppContext { handles.push(handle); - for name in names_to_be_updated { + for name in contested_resources_as_strings { // Clone the semaphore, sdk, and sender for each task let semaphore = semaphore.clone(); let sdk = sdk.clone(); diff --git a/src/ui/identities/register_dpns_name_screen.rs b/src/ui/identities/register_dpns_name_screen.rs index 0a4f8ec3d..04d598b67 100644 --- a/src/ui/identities/register_dpns_name_screen.rs +++ b/src/ui/identities/register_dpns_name_screen.rs @@ -62,14 +62,14 @@ impl RegisterDpnsNameScreen { .show_ui(ui, |ui| { // Loop through the qualified identities and display each as selectable for qualified_identity in &self.qualified_identities { - let id = qualified_identity.identity.id(); // Extract the Identifier - // Display each QualifiedIdentity as a selectable item if ui .selectable_value( &mut self.selected_qualified_identity, Some(qualified_identity.clone()), - id.to_string(Encoding::Base58), + qualified_identity.alias.as_ref().unwrap_or( + &qualified_identity.identity.id().to_string(Encoding::Base58), + ), ) .clicked() { From eccaff07126b5ba1193d89a840816a1f26a9dc86 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Fri, 18 Oct 2024 00:13:21 +0700 Subject: [PATCH 2/4] fix: only update active votes --- src/database/contested_names.rs | 22 ++++++++++++------- .../query_dpns_contested_resources.rs | 4 +++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/database/contested_names.rs b/src/database/contested_names.rs index 3960fe63b..81c0b249b 100644 --- a/src/database/contested_names.rs +++ b/src/database/contested_names.rs @@ -1,15 +1,15 @@ use crate::context::AppContext; use crate::database::Database; use crate::model::contested_name::{Contestant, ContestedName}; +use dash_sdk::dpp::dashcore::Network; use dash_sdk::dpp::data_contract::document_type::DocumentTypeRef; use dash_sdk::dpp::document::DocumentV0Getters; use dash_sdk::dpp::identifier::Identifier; use dash_sdk::dpp::identity::TimestampMillis; use dash_sdk::dpp::prelude::{BlockHeight, CoreBlockHeight}; use dash_sdk::query_types::Contenders; -use rusqlite::{params, params_from_iter, OptionalExtension, Result}; +use rusqlite::{params, params_from_iter, Result}; use std::collections::{BTreeMap, HashMap, HashSet}; -use std::fmt::Debug; impl Database { pub fn get_contested_names(&self, app_context: &AppContext) -> Result> { @@ -388,11 +388,12 @@ impl Database { ) -> Result> { let network = app_context.network_string(); let conn = self.conn.lock().unwrap(); - let mut outdated_names: Vec<(String, Option)> = Vec::new(); + let mut names_to_be_updated: Vec<(String, Option)> = Vec::new(); let mut new_names: Vec = Vec::new(); // Define the time limit (one hour ago in Unix timestamp format) let one_hour_ago = chrono::Utc::now().timestamp() - 3600; + let two_weeks_ago = chrono::Utc::now().timestamp() - 1_209_600; // Chunk the name_contests into smaller groups due to SQL parameter limits let chunk_size = 900; // Use a safe limit to stay below SQLite's limit @@ -427,8 +428,13 @@ impl Database { for row in rows { if let Ok((name, last_updated)) = row { existing_names.insert(name.clone()); - if last_updated.is_none() || last_updated.unwrap() < one_hour_ago { - outdated_names.push((name, last_updated)); + if last_updated.is_none() + || (app_context.network == Network::Testnet + && last_updated.unwrap() > one_hour_ago) + || (app_context.network == Network::Dash + && last_updated.unwrap() > two_weeks_ago) + { + names_to_be_updated.push((name, last_updated)); } } } @@ -454,11 +460,11 @@ impl Database { } // Combine the new names and outdated names, sorted by last_updated (oldest first) - outdated_names.extend(new_names.into_iter().map(|name| (name, None))); - outdated_names.sort_by(|a, b| a.1.unwrap_or(0).cmp(&b.1.unwrap_or(0))); + names_to_be_updated.extend(new_names.into_iter().map(|name| (name, None))); + names_to_be_updated.sort_by(|a, b| a.1.unwrap_or(0).cmp(&b.1.unwrap_or(0))); // Extract the names into a Vec - let result_names = outdated_names + let result_names = names_to_be_updated .into_iter() .map(|(name, _)| name) .collect::>(); diff --git a/src/platform/contested_names/query_dpns_contested_resources.rs b/src/platform/contested_names/query_dpns_contested_resources.rs index 0c85e9a18..d3d394d98 100644 --- a/src/platform/contested_names/query_dpns_contested_resources.rs +++ b/src/platform/contested_names/query_dpns_contested_resources.rs @@ -58,6 +58,8 @@ impl AppContext { .insert_name_contests_as_normalized_names(contested_resources_as_strings.clone(), &self) .map_err(|e| e.to_string())?; + tracing::info!("N: {}", names_to_be_updated.len()); + sender .send(TaskResult::Refresh) .await @@ -99,7 +101,7 @@ impl AppContext { handles.push(handle); - for name in contested_resources_as_strings { + for name in names_to_be_updated { // Clone the semaphore, sdk, and sender for each task let semaphore = semaphore.clone(); let sdk = sdk.clone(); From dc23dabef77355594e7be7c6f41aa1fe305f453d Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Fri, 18 Oct 2024 00:15:38 +0700 Subject: [PATCH 3/4] fix: remove stuff from previous commit --- .../contested_names/query_dpns_contested_resources.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/platform/contested_names/query_dpns_contested_resources.rs b/src/platform/contested_names/query_dpns_contested_resources.rs index d3d394d98..b00324ec3 100644 --- a/src/platform/contested_names/query_dpns_contested_resources.rs +++ b/src/platform/contested_names/query_dpns_contested_resources.rs @@ -55,17 +55,15 @@ impl AppContext { let names_to_be_updated = self .db - .insert_name_contests_as_normalized_names(contested_resources_as_strings.clone(), &self) + .insert_name_contests_as_normalized_names(contested_resources_as_strings, &self) .map_err(|e| e.to_string())?; - tracing::info!("N: {}", names_to_be_updated.len()); - sender .send(TaskResult::Refresh) .await .expect("expected to send refresh"); - // Create a semaphore with 24 permits + // Create a semaphore with 15 permits let semaphore = Arc::new(Semaphore::new(24)); let mut handles = Vec::new(); From ebddbc96fb40b030f0eb96628974bd797b1fc29b Mon Sep 17 00:00:00 2001 From: QuantumExplorer Date: Sun, 20 Oct 2024 04:05:46 +0700 Subject: [PATCH 4/4] Update src/database/contested_names.rs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/database/contested_names.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/contested_names.rs b/src/database/contested_names.rs index 81c0b249b..7d8833868 100644 --- a/src/database/contested_names.rs +++ b/src/database/contested_names.rs @@ -430,9 +430,9 @@ impl Database { existing_names.insert(name.clone()); if last_updated.is_none() || (app_context.network == Network::Testnet - && last_updated.unwrap() > one_hour_ago) + && last_updated.unwrap() < one_hour_ago) || (app_context.network == Network::Dash - && last_updated.unwrap() > two_weeks_ago) + && last_updated.unwrap() < two_weeks_ago) { names_to_be_updated.push((name, last_updated)); }