From 85f2233ef4ce1d41e35d3ee98901237b8f14e9d1 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 31 May 2024 13:00:03 +0700 Subject: [PATCH 01/48] refactor: encapsulate chain lock validation quorum logic to be reused --- .../update_quorum_info/v0/mod.rs | 57 ++--- .../verify_chain_lock_locally/v0/mod.rs | 66 ++---- .../rs-drive-abci/src/platform_types/mod.rs | 7 +- .../src/platform_types/platform_state/mod.rs | 65 +----- .../platform_types/platform_state/v0/mod.rs | 194 ++---------------- .../signature_verification_quorums/mod.rs | 89 ++++++++ .../signature_verification_quorums/v0/mod.rs | 193 +++++++++++++++++ 7 files changed, 356 insertions(+), 315 deletions(-) create mode 100644 packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs create mode 100644 packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index 323918cf39d..360bb43a126 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -3,6 +3,7 @@ use crate::error::Error; use crate::platform_types::platform::Platform; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; +use crate::platform_types::signature_verification_quorums::SignatureVerificationQuorumsV0Methods; use std::collections::BTreeMap; use crate::platform_types::validator_set::v0::{ValidatorSetV0, ValidatorSetV0Getters}; @@ -37,13 +38,15 @@ where ) -> Result<(), Error> { let _span = tracing::span!(Level::TRACE, "update_quorum_info", core_block_height).entered(); + let last_committed_core_height = block_platform_state.last_committed_core_height(); + if start_from_scratch { tracing::debug!("update quorum info from scratch up to {core_block_height}"); - } else if core_block_height != block_platform_state.last_committed_core_height() { + } else if core_block_height != last_committed_core_height { tracing::debug!( - previous_core_block_height = block_platform_state.last_committed_core_height(), + previous_core_block_height = last_committed_core_height, "update quorum info from {} to {}", - block_platform_state.last_committed_core_height(), + last_committed_core_height, core_block_height ); } else { @@ -173,26 +176,27 @@ where if validator_set_quorum_type == chain_lock_quorum_type { // Remove validator_sets entries that are no longer valid for the core block height if removed_a_validator_set || added_a_validator_set { - let chain_lock_validating_quorums = block_platform_state + let quorums = block_platform_state .validator_sets() .iter() .map(|(quorum_hash, validator_set)| { (*quorum_hash, validator_set.threshold_public_key().clone()) }) .collect(); - let previous_quorums = block_platform_state - .replace_chain_lock_validating_quorums(chain_lock_validating_quorums); - tracing::trace!("updated chain lock validating quorums to current validator set",); - // the only case where there will be no platform_state is init chain where we + + tracing::trace!("updated chain lock validating quorums to current validator set"); + if platform_state.is_some() { - block_platform_state.set_previous_chain_lock_validating_quorums( - block_platform_state.last_committed_core_height(), - core_block_height, - block_platform_state - .previous_height_chain_lock_validating_quorums() - .map(|(_, previous_change_height, _, _)| *previous_change_height), - previous_quorums, - ); + // we already have state, so we update last and previous quorums + block_platform_state + .chain_lock_validating_quorums_mut() + .rotate_quorums(quorums, last_committed_core_height, core_block_height); + } else { + // the only case where there will be no platform_state is init chain, + // so there is no previous quorums to update + block_platform_state + .chain_lock_validating_quorums_mut() + .set_last_quorums(quorums) } } } else { @@ -216,6 +220,7 @@ where // Remove chain_lock_validating_quorums entries that are no longer valid for the core block height block_platform_state .chain_lock_validating_quorums_mut() + .last_quorums_mut() .retain(|quorum_hash, _| { let retain = chain_lock_quorums_list.contains_key::(quorum_hash); if !retain { @@ -237,6 +242,7 @@ where .filter(|(key, _)| { !block_platform_state .chain_lock_validating_quorums() + .last_quorums() .contains_key::(key) }) .map(|(key, _)| { @@ -280,21 +286,22 @@ where // Add new validator_sets entries block_platform_state .chain_lock_validating_quorums_mut() + .last_quorums_mut() .extend(new_chain_lock_quorums); } if added_a_chain_lock_validating_quorum || removed_a_chain_lock_validating_quorum { if let Some(old_state) = platform_state { let previous_chain_lock_validating_quorums = - old_state.chain_lock_validating_quorums().clone(); - block_platform_state.set_previous_chain_lock_validating_quorums( - block_platform_state.last_committed_core_height(), - core_block_height, - block_platform_state - .previous_height_chain_lock_validating_quorums() - .map(|(_, previous_change_height, _, _)| *previous_change_height), - previous_chain_lock_validating_quorums, - ); + old_state.chain_lock_validating_quorums().last_quorums(); + + block_platform_state + .chain_lock_validating_quorums_mut() + .update_previous_quorums( + previous_chain_lock_validating_quorums.clone(), + last_committed_core_height, + core_block_height, + ); } } } diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs index 903617642ba..f52b15d2135 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs @@ -9,8 +9,10 @@ use crate::platform_types::platform::Platform; use crate::rpc::core::CoreRPCLike; +use crate::error::execution::ExecutionError; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; +use crate::platform_types::signature_verification_quorums::SignatureVerificationQuorumsV0Methods; use dpp::version::PlatformVersion; const CHAIN_LOCK_REQUEST_ID_PREFIX: &str = "clsig"; @@ -61,55 +63,9 @@ where return Ok(None); // the chain lock is too far in the future or the past to verify locally } - let (probable_quorums, second_to_check_quorums, should_be_verifiable) = if let Some(( - previous_quorum_height, - change_quorum_height, - previous_quorums_change_height, - previous_quorums, - )) = - platform_state.previous_height_chain_lock_validating_quorums() - { - if chain_lock_height > 8 && verification_height >= *change_quorum_height { - // in this case we are sure that we should be targeting the current quorum - // We updated core chain lock height from 100 to 105, new chain lock comes in for block 114 - // ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) ------ 106 (new chain lock verification height 114 - 8) - // We are sure that we should use current quorums - // If we have - // ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) ------ 105 (new chain lock verification height 113 - 8) - // We should also use current quorums, this is because at 105 we are sure new chain lock validating quorums are active - (platform_state.chain_lock_validating_quorums(), None, true) - } else if chain_lock_height > 8 && verification_height <= *previous_quorum_height { - let should_be_verifiable = previous_quorums_change_height - .map(|previous_quorums_change_height| { - verification_height > previous_quorums_change_height - }) - .unwrap_or(false); - // In this case the quorums were changed recently meaning that we should use the previous quorums to verify the chain lock - // We updated core chain lock height from 100 to 105, new chain lock comes in for block 106 - // -------- 98 (new chain lock verification height 106 - 8) ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) - // We are sure that we should use previous quorums - // If we have - // -------- 100 (new chain lock verification height 108 - 8) ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) - // We should also use previous quorums, this is because at 100 we are sure the old quorum set was active - (previous_quorums, None, should_be_verifiable) - } else { - let should_be_verifiable = previous_quorums_change_height - .map(|previous_quorums_change_height| { - verification_height > previous_quorums_change_height - }) - .unwrap_or(false); - // we are in between, so we don't actually know if it was the old one or the new one to be used. - // ------- 100 (previous_quorum_height) ------ 104 (new chain lock verification height 112 - 8) -------105 (change_quorum_height) - // we should just try both, starting with the current quorums - ( - platform_state.chain_lock_validating_quorums(), - Some(previous_quorums), - should_be_verifiable, - ) - } - } else { - (platform_state.chain_lock_validating_quorums(), None, false) - }; + let mut selected_quorum_sets = platform_state + .chain_lock_validating_quorums() + .select_quorums(chain_lock_height, verification_height); // From DIP 8: https://github.com/dashpay/dips/blob/master/dip-0008.md#finalization-of-signed-blocks // The request id is SHA256("clsig", blockHeight) and the message hash is the block hash of the previously successful attempt. @@ -130,6 +86,11 @@ where ); // Based on the deterministic masternode list at the given height, a quorum must be selected that was active at the time this block was mined + let probable_quorums = selected_quorum_sets.next().ok_or_else(|| { + Error::Execution(ExecutionError::CorruptedCodeExecution( + "at lest one set of quorums must be selected", + )) + })?; let quorum = Platform::::choose_quorum( self.config.chain_lock_quorum_type(), @@ -172,7 +133,7 @@ where if !chain_lock_verified { // We should also check the other quorum, as there could be the situation where the core height wasn't updated every block. - if let Some(second_to_check_quorums) = second_to_check_quorums { + if let Some(second_to_check_quorums) = selected_quorum_sets.next() { let quorum = Platform::::choose_quorum( self.config.chain_lock_quorum_type(), second_to_check_quorums, @@ -215,7 +176,8 @@ where ); } } else if platform_state - .previous_height_chain_lock_validating_quorums() + .chain_lock_validating_quorums() + .previous_quorums() .is_none() { // we don't have old quorums, this means our node is very new. @@ -223,7 +185,7 @@ where "we had no previous quorums locally, we should validate through core", ); return Ok(None); - } else if !should_be_verifiable { + } else if !selected_quorum_sets.should_be_verifiable { tracing::debug!( "we were in a situation where it would be possible we didn't have all quorums and we couldn't verify locally, we should validate through core", ); diff --git a/packages/rs-drive-abci/src/platform_types/mod.rs b/packages/rs-drive-abci/src/platform_types/mod.rs index 7602529bab6..66a86cbbee2 100644 --- a/packages/rs-drive-abci/src/platform_types/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/mod.rs @@ -47,6 +47,8 @@ pub mod platform; pub mod platform_state; /// Required identity public key set for system identities pub mod required_identity_public_key_set; +/// Signature verification quorums +pub mod signature_verification_quorums; /// The state transition execution result as part of the block execution outcome pub mod state_transitions_processing_result; /// System identity public keys @@ -56,8 +58,7 @@ pub mod system_identity_public_keys; pub mod validator; /// Quorum methods pub mod validator_set; -/// Withdrawal types -pub mod withdrawal; - /// Verify chain lock result pub mod verify_chain_lock_result; +/// Withdrawal types +pub mod withdrawal; diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs index b5d5b88ec7a..be67bdb11e4 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs @@ -21,8 +21,8 @@ use dpp::ProtocolError; use indexmap::IndexMap; use crate::error::execution::ExecutionError; +use crate::platform_types::signature_verification_quorums::SignatureVerificationQuorums; use dpp::block::block_info::BlockInfo; -use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; use dpp::util::hash::hash_double; use std::collections::BTreeMap; @@ -316,7 +316,7 @@ impl PlatformStateV0Methods for PlatformState { } } - fn chain_lock_validating_quorums(&self) -> &BTreeMap { + fn chain_lock_validating_quorums(&self) -> &SignatureVerificationQuorums { match self { PlatformState::V0(v0) => &v0.chain_lock_validating_quorums, } @@ -382,41 +382,12 @@ impl PlatformStateV0Methods for PlatformState { } } - fn set_chain_lock_validating_quorums( - &mut self, - quorums: BTreeMap, - ) { + fn set_chain_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorums) { match self { PlatformState::V0(v0) => v0.set_chain_lock_validating_quorums(quorums), } } - fn replace_chain_lock_validating_quorums( - &mut self, - quorums: BTreeMap, - ) -> BTreeMap { - match self { - PlatformState::V0(v0) => v0.replace_chain_lock_validating_quorums(quorums), - } - } - - fn set_previous_chain_lock_validating_quorums( - &mut self, - previous_core_height: u32, - change_core_height: u32, - previous_quorums_change_height: Option, - quorums: BTreeMap, - ) { - match self { - PlatformState::V0(v0) => v0.set_previous_chain_lock_validating_quorums( - previous_core_height, - change_core_height, - previous_quorums_change_height, - quorums, - ), - } - } - fn set_full_masternode_list(&mut self, list: BTreeMap) { match self { PlatformState::V0(v0) => v0.set_full_masternode_list(list), @@ -471,40 +442,12 @@ impl PlatformStateV0Methods for PlatformState { } } - fn chain_lock_validating_quorums_mut( - &mut self, - ) -> &mut BTreeMap { + fn chain_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorums { match self { PlatformState::V0(v0) => v0.chain_lock_validating_quorums_mut(), } } - fn previous_height_chain_lock_validating_quorums( - &self, - ) -> Option<&( - u32, - u32, - Option, - BTreeMap, - )> { - match self { - PlatformState::V0(v0) => v0.previous_height_chain_lock_validating_quorums(), - } - } - - fn previous_height_chain_lock_validating_quorums_mut( - &mut self, - ) -> &mut Option<( - u32, - u32, - Option, - BTreeMap, - )> { - match self { - PlatformState::V0(v0) => v0.previous_height_chain_lock_validating_quorums_mut(), - } - } - fn full_masternode_list_mut(&mut self) -> &mut BTreeMap { match self { PlatformState::V0(v0) => v0.full_masternode_list_mut(), diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs index 224bd39ecd0..4a9da76867f 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs @@ -17,9 +17,9 @@ use crate::platform_types::masternode::Masternode; use crate::platform_types::validator_set::ValidatorSet; use dpp::block::block_info::{BlockInfo, DEFAULT_BLOCK_INFO}; use dpp::block::extended_block_info::v0::ExtendedBlockInfoV0Getters; -use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; use dpp::version::{PlatformVersion, TryIntoPlatformVersioned}; +use crate::platform_types::signature_verification_quorums::SignatureVerificationQuorums; use itertools::Itertools; use std::collections::BTreeMap; use std::fmt::{Debug, Formatter}; @@ -45,23 +45,7 @@ pub struct PlatformStateV0 { pub validator_sets: IndexMap, /// The current quorums used for validating chain locks (400 60 for mainnet) - pub chain_lock_validating_quorums: BTreeMap, - - /// The slightly old quorums used for validating chain locks, it's important to keep - /// these because validation of signatures happens for the quorums that are 8 blocks before the - /// height written in the chain lock (400 60 for mainnet) - /// The first u32 is the core height at which these chain lock validating quorums were last active - /// The second u32 is the core height we are changing at. - /// The third u32 is the core height the previous chain lock validating quorums became active. - /// Keeping all three is important for verifying the chain locks, as we can detect edge cases where we - /// must check a chain lock with both the previous height chain lock validating quorums and the - /// current ones - pub previous_height_chain_lock_validating_quorums: Option<( - u32, - u32, - Option, - BTreeMap, - )>, + pub chain_lock_validating_quorums: SignatureVerificationQuorums, /// current full masternode list pub full_masternode_list: BTreeMap, @@ -101,6 +85,10 @@ impl Debug for PlatformStateV0 { .field("full_masternode_list", &self.full_masternode_list) .field("hpmn_masternode_list", &self.hpmn_masternode_list) .field("initialization_information", &self.genesis_block_info) + .field( + "chain_lock_validating_quorums", + &self.chain_lock_validating_quorums, + ) .finish() } } @@ -135,13 +123,7 @@ pub struct PlatformStateForSavingV0 { pub validator_sets: Vec<(Bytes32, ValidatorSet)>, /// The 400 60 quorums used for validating chain locks - #[bincode(with_serde)] - pub chain_lock_validating_quorums: Vec<(Bytes32, ThresholdBlsPublicKey)>, - - /// The quorums used for validating chain locks from a slightly previous height. - #[bincode(with_serde)] - pub previous_height_chain_lock_validating_quorums: - Option<(u32, u32, Option, Vec<(Bytes32, ThresholdBlsPublicKey)>)>, + pub chain_lock_validating_quorums: SignatureVerificationQuorums, /// current full masternode list pub full_masternode_list: BTreeMap, @@ -172,31 +154,7 @@ impl TryFrom for PlatformStateForSavingV0 { .into_iter() .map(|(k, v)| (k.to_byte_array().into(), v)) .collect(), - chain_lock_validating_quorums: value - .chain_lock_validating_quorums - .into_iter() - .map(|(k, v)| (k.to_byte_array().into(), v)) - .collect(), - previous_height_chain_lock_validating_quorums: value - .previous_height_chain_lock_validating_quorums - .map( - |( - previous_height, - change_height, - previous_quorums_change_height, - inner_value, - )| { - ( - previous_height, - change_height, - previous_quorums_change_height, - inner_value - .into_iter() - .map(|(k, v)| (k.to_byte_array().into(), v)) - .collect(), - ) - }, - ), + chain_lock_validating_quorums: value.chain_lock_validating_quorums, full_masternode_list: value .full_masternode_list .into_iter() @@ -239,31 +197,7 @@ impl From for PlatformStateV0 { .into_iter() .map(|(k, v)| (QuorumHash::from_byte_array(k.to_buffer()), v)) .collect(), - chain_lock_validating_quorums: value - .chain_lock_validating_quorums - .into_iter() - .map(|(k, v)| (QuorumHash::from_byte_array(k.to_buffer()), v)) - .collect(), - previous_height_chain_lock_validating_quorums: value - .previous_height_chain_lock_validating_quorums - .map( - |( - previous_height, - change_height, - previous_quorums_change_height, - inner_value, - )| { - ( - previous_height, - change_height, - previous_quorums_change_height, - inner_value - .into_iter() - .map(|(k, v)| (QuorumHash::from_byte_array(k.to_buffer()), v)) - .collect(), - ) - }, - ), + chain_lock_validating_quorums: value.chain_lock_validating_quorums, full_masternode_list: value .full_masternode_list .into_iter() @@ -284,6 +218,9 @@ impl PlatformStateV0 { current_protocol_version_in_consensus: ProtocolVersion, next_epoch_protocol_version: ProtocolVersion, ) -> PlatformStateV0 { + let platform_version = PlatformVersion::get(current_protocol_version_in_consensus) + .expect("invalid protocol version"); + PlatformStateV0 { last_committed_block_info: None, current_protocol_version_in_consensus, @@ -291,8 +228,8 @@ impl PlatformStateV0 { current_validator_set_quorum_hash: QuorumHash::all_zeros(), next_validator_set_quorum_hash: None, validator_sets: Default::default(), - chain_lock_validating_quorums: Default::default(), - previous_height_chain_lock_validating_quorums: None, + chain_lock_validating_quorums: + SignatureVerificationQuorums::default_for_platform_version(platform_version), full_masternode_list: Default::default(), hpmn_masternode_list: Default::default(), genesis_block_info: None, @@ -347,7 +284,7 @@ pub trait PlatformStateV0Methods { fn validator_sets(&self) -> &IndexMap; /// Returns the current 400 60 quorums used to validate chain locks. - fn chain_lock_validating_quorums(&self) -> &BTreeMap; + fn chain_lock_validating_quorums(&self) -> &SignatureVerificationQuorums; /// Returns the full list of masternodes. fn full_masternode_list(&self) -> &BTreeMap; @@ -380,25 +317,7 @@ pub trait PlatformStateV0Methods { fn set_validator_sets(&mut self, sets: IndexMap); /// Sets the current chain lock validating quorums. - fn set_chain_lock_validating_quorums( - &mut self, - quorums: BTreeMap, - ); - - /// Sets the current chain lock validating quorums and returns the old value. - fn replace_chain_lock_validating_quorums( - &mut self, - quorums: BTreeMap, - ) -> BTreeMap; - - /// Sets the previous chain lock validating quorums. - fn set_previous_chain_lock_validating_quorums( - &mut self, - previous_core_height: u32, - change_core_height: u32, - previous_quorums_change_height: Option, - quorums: BTreeMap, - ); + fn set_chain_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorums); /// Sets the full masternode list. fn set_full_masternode_list(&mut self, list: BTreeMap); @@ -427,19 +346,7 @@ pub trait PlatformStateV0Methods { fn validator_sets_mut(&mut self) -> &mut IndexMap; /// Returns a mutable reference to the current chain lock validating quorums. - fn chain_lock_validating_quorums_mut( - &mut self, - ) -> &mut BTreeMap; - - /// Returns a mutable reference to the previous chain lock validating quorums. - fn previous_height_chain_lock_validating_quorums_mut( - &mut self, - ) -> &mut Option<( - u32, - u32, - Option, - BTreeMap, - )>; + fn chain_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorums; /// Returns a mutable reference to the full masternode list. fn full_masternode_list_mut(&mut self) -> &mut BTreeMap; @@ -451,16 +358,6 @@ pub trait PlatformStateV0Methods { fn last_committed_block_epoch_ref(&self) -> &Epoch; /// The last block id hash fn last_committed_block_id_hash(&self) -> [u8; 32]; - - /// The previous height chain lock validating quorums - fn previous_height_chain_lock_validating_quorums( - &self, - ) -> Option<&( - u32, - u32, - Option, - BTreeMap, - )>; } impl PlatformStateV0Methods for PlatformStateV0 { @@ -603,7 +500,7 @@ impl PlatformStateV0Methods for PlatformStateV0 { } /// Returns the current 400 60 quorums used to validate chain locks. - fn chain_lock_validating_quorums(&self) -> &BTreeMap { + fn chain_lock_validating_quorums(&self) -> &SignatureVerificationQuorums { &self.chain_lock_validating_quorums } @@ -664,37 +561,10 @@ impl PlatformStateV0Methods for PlatformStateV0 { } /// Sets the current chain lock validating quorums. - fn set_chain_lock_validating_quorums( - &mut self, - quorums: BTreeMap, - ) { + fn set_chain_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorums) { self.chain_lock_validating_quorums = quorums; } - /// Swaps the current chain lock validating quorums and returns the old one - fn replace_chain_lock_validating_quorums( - &mut self, - quorums: BTreeMap, - ) -> BTreeMap { - std::mem::replace(&mut self.chain_lock_validating_quorums, quorums) - } - - /// Sets the previous chain lock validating quorums. - fn set_previous_chain_lock_validating_quorums( - &mut self, - previous_core_height: u32, - change_core_height: u32, - previous_quorums_change_height: Option, - quorums: BTreeMap, - ) { - self.previous_height_chain_lock_validating_quorums = Some(( - previous_core_height, - change_core_height, - previous_quorums_change_height, - quorums, - )); - } - /// Sets the full masternode list. fn set_full_masternode_list(&mut self, list: BTreeMap) { self.full_masternode_list = list; @@ -734,23 +604,10 @@ impl PlatformStateV0Methods for PlatformStateV0 { &mut self.validator_sets } - fn chain_lock_validating_quorums_mut( - &mut self, - ) -> &mut BTreeMap { + fn chain_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorums { &mut self.chain_lock_validating_quorums } - fn previous_height_chain_lock_validating_quorums_mut( - &mut self, - ) -> &mut Option<( - u32, - u32, - Option, - BTreeMap, - )> { - &mut self.previous_height_chain_lock_validating_quorums - } - fn full_masternode_list_mut(&mut self) -> &mut BTreeMap { &mut self.full_masternode_list } @@ -773,15 +630,4 @@ impl PlatformStateV0Methods for PlatformStateV0 { .map(|block_info| *block_info.block_id_hash()) .unwrap_or_default() } - - fn previous_height_chain_lock_validating_quorums( - &self, - ) -> Option<&( - u32, - u32, - Option, - BTreeMap, - )> { - self.previous_height_chain_lock_validating_quorums.as_ref() - } } diff --git a/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs b/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs new file mode 100644 index 00000000000..858486e8748 --- /dev/null +++ b/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs @@ -0,0 +1,89 @@ +mod v0; + +use crate::platform_types::signature_verification_quorums::v0::{ + PreviousQuorums, SelectedVerificationQuorumSets, +}; +use bincode::{Decode, Encode}; +use derive_more::From; +use dpp::version::PlatformVersion; +pub use v0::{QuorumKeys, SignatureVerificationQuorumsV0, SignatureVerificationQuorumsV0Methods}; + +/// Quorums with keys for signature verification +#[derive(Debug, Clone, Encode, Decode, From)] +pub enum SignatureVerificationQuorums { + /// Version 0 of the signature verification quorums + V0(SignatureVerificationQuorumsV0), +} + +impl SignatureVerificationQuorums { + /// Create a default SignatureVerificationQuorums + pub fn default_for_platform_version(platform_version: &PlatformVersion) -> Self { + // TODO: default for platform version + + SignatureVerificationQuorumsV0::default().into() + } +} + +impl SignatureVerificationQuorumsV0Methods for SignatureVerificationQuorums { + fn set_last_quorums(&mut self, quorums: QuorumKeys) { + match self { + Self::V0(v0) => v0.set_last_quorums(quorums), + } + } + + fn last_quorums(&self) -> &QuorumKeys { + match self { + Self::V0(v0) => v0.last_quorums(), + } + } + + fn last_quorums_mut(&mut self) -> &mut QuorumKeys { + match self { + Self::V0(v0) => v0.last_quorums_mut(), + } + } + + fn previous_quorums(&self) -> Option<&PreviousQuorums> { + match self { + Self::V0(v0) => v0.previous_quorums(), + } + } + + fn rotate_quorums( + &mut self, + quorums: QuorumKeys, + last_active_core_height: u32, + updated_at_core_height: u32, + ) { + match self { + Self::V0(v0) => { + v0.rotate_quorums(quorums, last_active_core_height, updated_at_core_height) + } + } + } + + fn update_previous_quorums( + &mut self, + previous_quorums: QuorumKeys, + last_active_core_height: u32, + updated_at_core_height: u32, + ) { + match self { + Self::V0(v0) => v0.update_previous_quorums( + previous_quorums, + last_active_core_height, + updated_at_core_height, + ), + } + } + + fn select_quorums( + &self, + signing_height: u32, + verification_height: u32, + ) -> SelectedVerificationQuorumSets { + match self { + Self::V0(v0) => v0.select_quorums(signing_height, verification_height), + } + } +} diff --git a/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs new file mode 100644 index 00000000000..2ce7f35c1e1 --- /dev/null +++ b/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs @@ -0,0 +1,193 @@ +use bincode::{Decode, Encode}; +use dpp::dashcore::QuorumHash; +use std::collections::BTreeMap; + +pub use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; + +/// Quorum key per hash +pub type QuorumKeys = BTreeMap; + +/// Previously obtained quorums and heights. Required for signature verification +#[derive(Debug, Clone, Encode, Decode, Default)] +pub struct PreviousQuorums { + #[bincode(with_serde)] + quorums: QuorumKeys, + + /// The core height at which these quorums were last active + active_core_height: u32, + + /// The core height when the quorums were changed + updated_at_core_height: u32, + + /// The core height the previous chain lock validating quorums became active + previous_change_height: Option, +} + +/// Quorums with keys for signature verification +#[derive(Debug, Clone, Encode, Decode, Default)] +pub struct SignatureVerificationQuorumsV0 { + /// Current quorums + #[bincode(with_serde)] + last_quorums: QuorumKeys, + + /// The slightly old quorums used for validating chain locks (or instant locks), it's important to keep + /// these because validation of signatures happens for the quorums that are 8 blocks before the + /// height written in the chain lock. The same for instant locks + previous: Option, +} + +/// The trait defines methods for the signature verification quorums structure v0 +pub trait SignatureVerificationQuorumsV0Methods { + /// Set last quorum keys + fn set_last_quorums(&mut self, quorums: QuorumKeys); + + /// Last quorum keys + fn last_quorums(&self) -> &QuorumKeys; + + /// Last quorum keys mutable + fn last_quorums_mut(&mut self) -> &mut QuorumKeys; + + /// Previous quorums + fn previous_quorums(&self) -> Option<&PreviousQuorums>; + + /// Set last quorums keys and update previous quorums + fn rotate_quorums( + &mut self, + quorums: QuorumKeys, + last_active_core_height: u32, + updated_at_core_height: u32, + ); + + /// Update previous quorums + fn update_previous_quorums( + &mut self, + previous_quorums: QuorumKeys, + last_active_core_height: u32, + updated_at_core_height: u32, + ); + + /// Select quorum sets for signature verification + fn select_quorums( + &self, + signing_height: u32, + verification_height: u32, + ) -> SelectedVerificationQuorumSets; +} + +pub struct SelectedVerificationQuorumSets<'q> { + pub quorum_sets: Vec<&'q QuorumKeys>, + pub should_be_verifiable: bool, +} + +impl<'q> Iterator for SelectedVerificationQuorumSets<'q> { + type Item = &'q QuorumKeys; + + fn next(&mut self) -> Option { + self.quorum_sets.pop() + } +} + +impl<'q> SignatureVerificationQuorumsV0Methods for SignatureVerificationQuorumsV0 { + fn set_last_quorums(&mut self, quorums: QuorumKeys) { + self.last_quorums = quorums; + } + + fn last_quorums(&self) -> &QuorumKeys { + &self.last_quorums + } + + fn last_quorums_mut(&mut self) -> &mut QuorumKeys { + &mut self.last_quorums + } + + fn previous_quorums(&self) -> Option<&PreviousQuorums> { + self.previous.as_ref() + } + + fn rotate_quorums( + &mut self, + quorums: QuorumKeys, + last_active_height: u32, + updated_at_core_height: u32, + ) { + let previous_quorums = std::mem::replace(&mut self.last_quorums, quorums); + + self.update_previous_quorums(previous_quorums, last_active_height, updated_at_core_height); + } + + fn update_previous_quorums( + &mut self, + previous_quorums: QuorumKeys, + last_active_core_height: u32, + updated_at_core_height: u32, + ) { + self.previous = Some(PreviousQuorums { + quorums: previous_quorums, + active_core_height: last_active_core_height, + updated_at_core_height, + previous_change_height: self + .previous + .as_ref() + .map(|previous| previous.updated_at_core_height), + }); + } + + fn select_quorums( + &self, + signing_height: u32, + verification_height: u32, + ) -> SelectedVerificationQuorumSets { + let mut quorums = Vec::new(); + let mut should_be_verifiable = false; + + if let Some(previous) = &self.previous { + let previous_quorum_height = previous.active_core_height; + let change_quorum_height = previous.updated_at_core_height; + let previous_quorums_change_height = previous.previous_change_height; + + if signing_height > 8 && verification_height >= change_quorum_height { + // in this case we are sure that we should be targeting the current quorum + // We updated core chain lock height from 100 to 105, new chain lock comes in for block 114 + // ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) ------ 106 (new chain lock verification height 114 - 8) + // We are sure that we should use current quorums + // If we have + // ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) ------ 105 (new chain lock verification height 113 - 8) + // We should also use current quorums, this is because at 105 we are sure new chain lock validating quorums are active + quorums.push(&self.last_quorums); + should_be_verifiable = true; + } else if signing_height > 8 && verification_height <= previous_quorum_height { + should_be_verifiable = previous_quorums_change_height + .map(|previous_quorums_change_height| { + verification_height > previous_quorums_change_height + }) + .unwrap_or(false); + // In this case the quorums were changed recently meaning that we should use the previous quorums to verify the chain lock + // We updated core chain lock height from 100 to 105, new chain lock comes in for block 106 + // -------- 98 (new chain lock verification height 106 - 8) ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) + // We are sure that we should use previous quorums + // If we have + // -------- 100 (new chain lock verification height 108 - 8) ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) + // We should also use previous quorums, this is because at 100 we are sure the old quorum set was active + quorums.push(&previous.quorums); + } else { + should_be_verifiable = previous_quorums_change_height + .map(|previous_quorums_change_height| { + verification_height > previous_quorums_change_height + }) + .unwrap_or(false); + // we are in between, so we don't actually know if it was the old one or the new one to be used. + // ------- 100 (previous_quorum_height) ------ 104 (new chain lock verification height 112 - 8) -------105 (change_quorum_height) + // we should just try both, starting with the current quorums + quorums.push(&self.last_quorums); + quorums.push(&previous.quorums); + } + } else { + quorums.push(&self.last_quorums); + } + + SelectedVerificationQuorumSets { + quorum_sets: quorums, + should_be_verifiable, + } + } +} From 731673aec507be1dfe251fc5b1a466915f3d6799 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 5 Jun 2024 18:13:41 +0700 Subject: [PATCH 02/48] feat: introduce `CoreQuorumSet` --- packages/rs-drive-abci/.env.local | 15 +- packages/rs-drive-abci/.env.mainnet | 12 + packages/rs-drive-abci/.env.testnet | 12 + packages/rs-drive-abci/src/config.rs | 438 +++++++++++++++--- .../engine/finalize_block_proposal/v0/mod.rs | 2 +- .../initialization/init_chain/v0/mod.rs | 1 + .../v0/mod.rs | 1 + .../process_block_fees/v0/mod.rs | 1 + .../update_quorum_info/v0/mod.rs | 50 +- .../core_chain_lock/choose_quorum/mod.rs | 2 +- .../verify_chain_lock_locally/v0/mod.rs | 56 +-- .../data_contract_update/mod.rs | 8 +- packages/rs-drive-abci/src/mimic/mod.rs | 2 +- .../src/platform_types/core_quorum_set/mod.rs | 124 +++++ .../core_quorum_set/v0/for_saving.rs | 165 +++++++ .../platform_types/core_quorum_set/v0/mod.rs | 3 + .../v0/quorum_set.rs} | 198 +++++--- .../core_quorum_set/v0/quorums.rs | 156 +++++++ .../rs-drive-abci/src/platform_types/mod.rs | 4 +- .../src/platform_types/platform/mod.rs | 1 + .../src/platform_types/platform_state/mod.rs | 23 +- .../platform_types/platform_state/v0/mod.rs | 68 ++- .../signature_verification_quorums/mod.rs | 89 ---- .../src/query/response_metadata/v0/mod.rs | 2 +- .../tests/strategy_tests/chain_lock_update.rs | 11 +- .../tests/strategy_tests/core_update_tests.rs | 28 +- .../tests/strategy_tests/execution.rs | 12 +- .../tests/strategy_tests/failures.rs | 20 +- .../tests/strategy_tests/main.rs | 271 ++++++----- .../tests/strategy_tests/query.rs | 19 +- .../strategy_tests/upgrade_fork_tests.rs | 46 +- 31 files changed, 1364 insertions(+), 476 deletions(-) create mode 100644 packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs create mode 100644 packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs create mode 100644 packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/mod.rs rename packages/rs-drive-abci/src/platform_types/{signature_verification_quorums/v0/mod.rs => core_quorum_set/v0/quorum_set.rs} (51%) create mode 100644 packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs delete mode 100644 packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs diff --git a/packages/rs-drive-abci/.env.local b/packages/rs-drive-abci/.env.local index 942707ab200..1c0ff965654 100644 --- a/packages/rs-drive-abci/.env.local +++ b/packages/rs-drive-abci/.env.local @@ -28,13 +28,24 @@ CORE_JSON_RPC_PASSWORD=password INITIAL_CORE_CHAINLOCKED_HEIGHT=1243 # https://github.com/dashevo/dashcore-lib/blob/286c33a9d29d33f05d874c47a9b33764a0be0cf1/lib/constants/index.js#L42-L57 -VALIDATOR_SET_QUORUM_TYPE=llmq_test +VALIDATOR_SET_QUORUM_TYPE=llmq_test_platform VALIDATOR_SET_QUORUM_SIZE=3 +VALIDATOR_SET_QUORUM_WINDOW=24 +VALIDATOR_SET_QUORUM_ACTIVE_SIGNERS=2 +VALIDATOR_SET_QUORUM_ROTATION=false VALIDATOR_SET_ROTATION_BLOCK_COUNT=64 CHAIN_LOCK_QUORUM_TYPE=llmq_test -CHAIN_LOCK_QUORUM_WINDOW=24 CHAIN_LOCK_QUORUM_SIZE=3 +CHAIN_LOCK_QUORUM_WINDOW=24 +CHAIN_LOCK_QUORUM_ACTIVE_SIGNERS=2 +CHAIN_LOCK_QUORUM_ROTATION=false + +INSTANT_LOCK_QUORUM_TYPE=llmq_test +INSTANT_LOCK_QUORUM_SIZE=3 +INSTANT_LOCK_QUORUM_WINDOW=24 +INSTANT_LOCK_QUORUM_ACTIVE_SIGNERS=2 +INSTANT_LOCK_QUORUM_ROTATION=false # DPNS Contract diff --git a/packages/rs-drive-abci/.env.mainnet b/packages/rs-drive-abci/.env.mainnet index a15602a413f..8e7f40cff51 100644 --- a/packages/rs-drive-abci/.env.mainnet +++ b/packages/rs-drive-abci/.env.mainnet @@ -30,10 +30,22 @@ INITIAL_CORE_CHAINLOCKED_HEIGHT=1243 # https://github.com/dashevo/dashcore-lib/blob/286c33a9d29d33f05d874c47a9b33764a0be0cf1/lib/constants/index.js#L42-L57 VALIDATOR_SET_QUORUM_TYPE=llmq_100_67 VALIDATOR_SET_QUORUM_SIZE=100 +VALIDATOR_SET_QUORUM_WINDOW=24 +VALIDATOR_SET_QUORUM_ACTIVE_SIGNERS=24 +VALIDATOR_SET_QUORUM_ROTATION=false VALIDATOR_SET_ROTATION_BLOCK_COUNT=64 CHAIN_LOCK_QUORUM_TYPE=llmq_400_60 +CHAIN_LOCK_QUORUM_SIZE=400 CHAIN_LOCK_QUORUM_WINDOW=288 +CHAIN_LOCK_QUORUM_ACTIVE_SIGNERS=4 +CHAIN_LOCK_QUORUM_ROTATION=false + +INSTANT_LOCK_QUORUM_TYPE=llmq_60_75 +INSTANT_LOCK_QUORUM_SIZE=60 +INSTANT_LOCK_QUORUM_WINDOW=288 +INSTANT_LOCK_QUORUM_ACTIVE_SIGNERS=32 +INSTANT_LOCK_QUORUM_ROTATION=true # DPNS Contract diff --git a/packages/rs-drive-abci/.env.testnet b/packages/rs-drive-abci/.env.testnet index e40ea7efc00..f0e6abf52ea 100644 --- a/packages/rs-drive-abci/.env.testnet +++ b/packages/rs-drive-abci/.env.testnet @@ -30,10 +30,22 @@ INITIAL_CORE_CHAINLOCKED_HEIGHT=1243 # https://github.com/dashevo/dashcore-lib/blob/286c33a9d29d33f05d874c47a9b33764a0be0cf1/lib/constants/index.js#L42-L57 VALIDATOR_SET_QUORUM_TYPE=llmq_25_67 VALIDATOR_SET_QUORUM_SIZE=25 +VALIDATOR_SET_QUORUM_WINDOW=24 +VALIDATOR_SET_QUORUM_ACTIVE_SIGNERS=24 +VALIDATOR_SET_QUORUM_ROTATION=false VALIDATOR_SET_ROTATION_BLOCK_COUNT=64 CHAIN_LOCK_QUORUM_TYPE=llmq_50_60 +CHAIN_LOCK_QUORUM_SIZE=50 CHAIN_LOCK_QUORUM_WINDOW=24 +CHAIN_LOCK_QUORUM_ACTIVE_SIGNERS=24 +CHAIN_LOCK_QUORUM_ROTATION=false + +INSTANT_LOCK_QUORUM_TYPE=llmq_60_75 +INSTANT_LOCK_QUORUM_SIZE=50 +INSTANT_LOCK_QUORUM_WINDOW=288 +INSTANT_LOCK_QUORUM_ACTIVE_SIGNERS=32 +INSTANT_LOCK_QUORUM_ROTATION=true # DPNS Contract diff --git a/packages/rs-drive-abci/src/config.rs b/packages/rs-drive-abci/src/config.rs index e3d043d479e..81e14b3b8b4 100644 --- a/packages/rs-drive-abci/src/config.rs +++ b/packages/rs-drive-abci/src/config.rs @@ -26,6 +26,7 @@ // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use bincode::{Decode, Encode}; use dashcore_rpc::json::QuorumType; use std::path::PathBuf; @@ -98,6 +99,7 @@ pub struct ExecutionConfig { #[serde(default = "ExecutionConfig::default_verify_sum_trees")] pub verify_sum_trees: bool, + // TODO: Move to ValidatorSetConfig /// How often should quorums change? #[serde( default = "ExecutionConfig::default_validator_set_rotation_block_count", @@ -175,21 +177,16 @@ pub struct PlatformConfig { pub execution: ExecutionConfig, /// The default quorum type - pub validator_set_quorum_type: String, - - /// The quorum type used for verifying chain locks - pub chain_lock_quorum_type: String, - - /// The validator set quorum size - pub validator_set_quorum_size: u16, + #[serde(flatten)] + pub validator_set: ValidatorSetConfig, - /// The chain lock quorum size - pub chain_lock_quorum_size: u16, + /// Chain lock configuration + #[serde(flatten)] + pub chain_lock: ChainLockConfig, - /// The window for chain locks - /// On Mainnet Chain Locks are signed using 400_60: One quorum in every 288 blocks and activeQuorumCount is 4. - /// On Testnet Chain Locks are signed using 50_60: One quorum in every 24 blocks and activeQuorumCount is 24. - pub chain_lock_quorum_window: u32, + /// Instant lock configuration + #[serde(flatten)] + pub instant_lock: InstantLockConfig, // todo: this should probably be coming from Tenderdash config. It's a test only param /// Approximately how often are blocks produced @@ -226,6 +223,304 @@ pub struct PlatformConfig { pub tokio_console_retention_secs: u64, } +/// A config suitable for a quorum configuration +pub trait QuorumLikeConfig: Sized { + /// Quorum type + fn quorum_type(&self) -> QuorumType; + + /// Quorum size + fn quorum_size(&self) -> u16; + + /// Quorum DKG interval + fn quorum_window(&self) -> u32; + + /// Quorum active signers count + fn quorum_active_signers(&self) -> u16; + + /// Quorum rotation (dip24) or classic + fn quorum_rotation(&self) -> bool; +} + +/// Chain Lock quorum configuration +#[derive(Clone, Debug, Serialize, Deserialize, Encode, Decode)] +pub struct ValidatorSetConfig { + /// The quorum type used for verifying chain locks + #[serde( + rename = "validator_set_quorum_type", + serialize_with = "serialize_quorum_type", + deserialize_with = "deserialize_quorum_type" + )] + pub quorum_type: QuorumType, + + /// The quorum size + #[serde( + rename = "validator_set_quorum_size", + deserialize_with = "from_str_or_number" + )] + pub quorum_size: u16, + + /// The quorum window (DKG interval) + /// On Mainnet Chain Locks are signed using 400_60: One quorum in every 288 blocks and activeQuorumCount is 4. + /// On Testnet Chain Locks are signed using 50_60: One quorum in every 24 blocks and activeQuorumCount is 24. + #[serde( + rename = "validator_set_quorum_window", + deserialize_with = "from_str_or_number" + )] + pub quorum_window: u32, + + /// The number of active signers + #[serde( + rename = "validator_set_quorum_active_signers", + deserialize_with = "from_str_or_number" + )] + pub quorum_active_signers: u16, + + /// Whether the quorum is rotated DIP24 or classic + #[serde( + rename = "validator_set_quorum_rotation", + deserialize_with = "from_str_or_number" + )] + pub quorum_rotation: bool, +} + +impl Default for ValidatorSetConfig { + fn default() -> Self { + // Mainnet + Self::default_100_67() + } +} + +impl ValidatorSetConfig { + /// Creates a default config for LLMQ 100 67 + pub fn default_100_67() -> Self { + Self { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 100, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + } + } +} + +impl QuorumLikeConfig for ValidatorSetConfig { + fn quorum_type(&self) -> QuorumType { + self.quorum_type + } + + fn quorum_size(&self) -> u16 { + self.quorum_size + } + + fn quorum_window(&self) -> u32 { + self.quorum_window + } + + fn quorum_active_signers(&self) -> u16 { + self.quorum_active_signers + } + + fn quorum_rotation(&self) -> bool { + self.quorum_rotation + } +} + +/// Chain Lock quorum configuration +#[derive(Clone, Debug, Serialize, Deserialize, Encode, Decode)] +pub struct ChainLockConfig { + /// The quorum type used for verifying chain locks + #[serde( + rename = "chain_lock_quorum_type", + serialize_with = "serialize_quorum_type", + deserialize_with = "deserialize_quorum_type" + )] + pub quorum_type: QuorumType, + + /// The quorum size + #[serde( + rename = "chain_lock_quorum_size", + deserialize_with = "from_str_or_number" + )] + pub quorum_size: u16, + + /// The quorum window (DKG interval) + /// On Mainnet Chain Locks are signed using 400_60: One quorum in every 288 blocks and activeQuorumCount is 4. + /// On Testnet Chain Locks are signed using 50_60: One quorum in every 24 blocks and activeQuorumCount is 24. + #[serde( + rename = "chain_lock_quorum_window", + deserialize_with = "from_str_or_number" + )] + pub quorum_window: u32, + + /// The number of active signers + #[serde( + rename = "chain_lock_quorum_active_signers", + deserialize_with = "from_str_or_number" + )] + pub quorum_active_signers: u16, + + /// Whether the quorum is rotated DIP24 or classic + #[serde( + rename = "chain_lock_quorum_rotation", + deserialize_with = "from_str_or_number" + )] + pub quorum_rotation: bool, +} + +impl Default for ChainLockConfig { + fn default() -> Self { + // Mainnet + Self { + quorum_type: QuorumType::Llmq400_60, + quorum_size: 400, + quorum_window: 24 * 12, + quorum_active_signers: 4, + quorum_rotation: false, + } + } +} + +impl QuorumLikeConfig for ChainLockConfig { + fn quorum_type(&self) -> QuorumType { + self.quorum_type + } + + fn quorum_size(&self) -> u16 { + self.quorum_size + } + + fn quorum_window(&self) -> u32 { + self.quorum_window + } + + fn quorum_active_signers(&self) -> u16 { + self.quorum_active_signers + } + + fn quorum_rotation(&self) -> bool { + self.quorum_rotation + } +} + +impl ChainLockConfig { + /// Creates a default config for LLMQ 100 67 + pub fn default_100_67() -> Self { + Self { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 100, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + } + } +} + +/// Chain Lock quorum configuration +#[derive(Clone, Debug, Serialize, Deserialize, Encode, Decode)] +pub struct InstantLockConfig { + /// The quorum type used for verifying chain locks + #[serde( + rename = "instant_lock_quorum_type", + serialize_with = "serialize_quorum_type", + deserialize_with = "deserialize_quorum_type" + )] + pub quorum_type: QuorumType, + + /// The quorum size + #[serde( + rename = "instant_lock_quorum_size", + deserialize_with = "from_str_or_number" + )] + pub quorum_size: u16, + + /// The quorum window (DKG interval) + /// On Mainnet Chain Locks are signed using 400_60: One quorum in every 288 blocks and activeQuorumCount is 4. + /// On Testnet Chain Locks are signed using 50_60: One quorum in every 24 blocks and activeQuorumCount is 24. + #[serde( + rename = "instant_lock_quorum_window", + deserialize_with = "from_str_or_number" + )] + pub quorum_window: u32, + + /// The number of active signers + #[serde( + rename = "instant_lock_quorum_active_signers", + deserialize_with = "from_str_or_number" + )] + pub quorum_active_signers: u16, + + /// Whether the quorum is rotated DIP24 or classic + #[serde( + rename = "instant_lock_quorum_rotation", + deserialize_with = "from_str_or_number" + )] + pub quorum_rotation: bool, +} + +impl Default for InstantLockConfig { + fn default() -> Self { + // Mainnet + Self { + quorum_type: QuorumType::Llmq60_75, + quorum_active_signers: 32, + quorum_size: 60, + quorum_window: 24 * 12, + quorum_rotation: true, + } + } +} + +impl QuorumLikeConfig for InstantLockConfig { + fn quorum_type(&self) -> QuorumType { + self.quorum_type + } + + fn quorum_size(&self) -> u16 { + self.quorum_size + } + + fn quorum_window(&self) -> u32 { + self.quorum_window + } + + fn quorum_active_signers(&self) -> u16 { + self.quorum_active_signers + } + + fn quorum_rotation(&self) -> bool { + self.quorum_rotation + } +} + +fn serialize_quorum_type(quorum_type: &QuorumType, serializer: S) -> Result +where + S: serde::Serializer, +{ + serializer.serialize_str(quorum_type.to_string().as_str()) +} + +fn deserialize_quorum_type<'de, D>(deserializer: D) -> Result +where + D: serde::Deserializer<'de>, +{ + let quorum_type_name = String::deserialize(deserializer)?; + + let quorum_type = if let Ok(t) = quorum_type_name.trim().parse::() { + QuorumType::from(t) + } else { + QuorumType::from(quorum_type_name.as_str()) + }; + + if quorum_type == QuorumType::UNKNOWN { + return Err(serde::de::Error::custom(format!( + "unsupported QUORUM_TYPE: {}", + quorum_type_name + ))); + }; + + Ok(quorum_type) +} + impl ExecutionConfig { fn default_verify_sum_trees() -> bool { true @@ -256,43 +551,8 @@ impl PlatformConfig { fn default_tokio_console_retention_secs() -> u64 { 60 * 3 } - - /// Return type of quorum - pub fn validator_set_quorum_type(&self) -> QuorumType { - let found = if let Ok(t) = self.validator_set_quorum_type.trim().parse::() { - QuorumType::from(t) - } else { - QuorumType::from(self.validator_set_quorum_type.as_str()) - }; - - if found == QuorumType::UNKNOWN { - panic!( - "config: unsupported QUORUM_TYPE: {}", - self.validator_set_quorum_type - ); - } - - found - } - - /// Return type of quorum for validating chain locks - pub fn chain_lock_quorum_type(&self) -> QuorumType { - let found = if let Ok(t) = self.chain_lock_quorum_type.trim().parse::() { - QuorumType::from(t) - } else { - QuorumType::from(self.chain_lock_quorum_type.as_str()) - }; - - if found == QuorumType::UNKNOWN { - panic!( - "config: unsupported QUORUM_TYPE: {}", - self.chain_lock_quorum_type - ); - } - - found - } } + /// create new object using values from environment variables pub trait FromEnv { /// create new object using values from environment variables @@ -338,11 +598,27 @@ impl Default for PlatformConfig { impl PlatformConfig { pub fn default_local() -> Self { Self { - validator_set_quorum_type: "llmq_test_platform".to_string(), - chain_lock_quorum_type: "llmq_test".to_string(), - validator_set_quorum_size: 3, - chain_lock_quorum_size: 3, - chain_lock_quorum_window: 24, + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::LlmqTestPlatform, + quorum_size: 3, + quorum_window: 24, + quorum_active_signers: 2, + quorum_rotation: false, + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::LlmqTest, + quorum_active_signers: 2, + quorum_size: 3, + quorum_window: 24, + quorum_rotation: false, + }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::LlmqTest, + quorum_active_signers: 2, + quorum_size: 3, + quorum_window: 24, + quorum_rotation: false, + }, block_spacing_ms: 5000, drive: Default::default(), abci: Default::default(), @@ -362,11 +638,27 @@ impl PlatformConfig { pub fn default_testnet() -> Self { Self { - validator_set_quorum_type: "llmq_25_67".to_string(), - chain_lock_quorum_type: "llmq_50_60".to_string(), - validator_set_quorum_size: 25, - chain_lock_quorum_size: 50, - chain_lock_quorum_window: 24, + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::Llmq25_67, + quorum_size: 25, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::Llmq50_60, + quorum_active_signers: 24, + quorum_size: 50, + quorum_window: 24, + quorum_rotation: false, + }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::Llmq60_75, + quorum_active_signers: 32, + quorum_size: 60, + quorum_window: 24 * 12, + quorum_rotation: true, + }, block_spacing_ms: 5000, drive: Default::default(), abci: Default::default(), @@ -386,11 +678,27 @@ impl PlatformConfig { pub fn default_mainnet() -> Self { Self { - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_400_60".to_string(), - validator_set_quorum_size: 100, - chain_lock_quorum_size: 400, - chain_lock_quorum_window: 288, + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 100, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::Llmq400_60, + quorum_active_signers: 4, + quorum_size: 400, + quorum_window: 24 * 12, + quorum_rotation: false, + }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::Llmq60_75, + quorum_active_signers: 32, + quorum_size: 60, + quorum_window: 24 * 12, + quorum_rotation: true, + }, block_spacing_ms: 5000, drive: Default::default(), abci: Default::default(), @@ -468,7 +776,7 @@ mod tests { let config = super::PlatformConfig::from_env().expect("expected config from env"); assert!(config.execution.verify_sum_trees); - assert_ne!(config.validator_set_quorum_type(), QuorumType::UNKNOWN); + assert_ne!(config.validator_set.quorum_type, QuorumType::UNKNOWN); for id in vectors { matches!(config.abci.log[id.0].destination, LogDestination::Bytes); } diff --git a/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs b/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs index ae78f603616..e6e91561b3a 100644 --- a/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs @@ -165,7 +165,7 @@ where let quorum_public_key = last_committed_state .current_validator_set()? .threshold_public_key(); - let quorum_type = self.config.validator_set_quorum_type(); + let quorum_type = self.config.validator_set.quorum_type; // TODO: We already had commit in the function above, why do we need to create it again with clone? let commit = Commit::new_from_cleaned( commit_info.clone(), diff --git a/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs b/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs index 29fba3c5148..200fa588a4f 100644 --- a/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs @@ -52,6 +52,7 @@ where let mut initial_platform_state = PlatformState::default_with_protocol_versions( request.initial_protocol_version, request.initial_protocol_version, + &self.config, ); let genesis_block_info = BlockInfo { diff --git a/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/add_process_epoch_change_operations/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/add_process_epoch_change_operations/v0/mod.rs index e705b047ba0..37da6433bd2 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/add_process_epoch_change_operations/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/add_process_epoch_change_operations/v0/mod.rs @@ -252,6 +252,7 @@ mod tests { let block_platform_state = PlatformState::default_with_protocol_versions( INITIAL_PROTOCOL_VERSION, INITIAL_PROTOCOL_VERSION, + &platform.config, ); let block_execution_context = BlockExecutionContextV0 { diff --git a/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/process_block_fees/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/process_block_fees/v0/mod.rs index 0b92b87f241..82deb3637f4 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/process_block_fees/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/process_block_fees/v0/mod.rs @@ -283,6 +283,7 @@ mod tests { let block_platform_state = PlatformState::default_with_protocol_versions( INITIAL_PROTOCOL_VERSION, INITIAL_PROTOCOL_VERSION, + &platform.config, ); let block_execution_context = BlockExecutionContextV0 { diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index 360bb43a126..cdc1d851566 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -3,13 +3,13 @@ use crate::error::Error; use crate::platform_types::platform::Platform; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; -use crate::platform_types::signature_verification_quorums::SignatureVerificationQuorumsV0Methods; use std::collections::BTreeMap; use crate::platform_types::validator_set::v0::{ValidatorSetV0, ValidatorSetV0Getters}; use crate::platform_types::validator_set::ValidatorSet; use crate::rpc::core::CoreRPCLike; +use crate::platform_types::core_quorum_set::{CoreQuorumSetV0Methods, Quorum, Quorums}; use dpp::bls_signatures::PublicKey as BlsPublicKey; use dpp::dashcore::QuorumHash; use tracing::Level; @@ -63,8 +63,8 @@ where .core_rpc .get_quorum_listextended(Some(core_block_height))?; - let validator_set_quorum_type = self.config.validator_set_quorum_type(); - let chain_lock_quorum_type = self.config.chain_lock_quorum_type(); + let validator_set_quorum_type = self.config.validator_set.quorum_type; + let chain_lock_quorum_type = self.config.chain_lock.quorum_type; let validator_quorums_list: BTreeMap<_, _> = extended_quorum_list .quorums_by_type @@ -72,7 +72,7 @@ where .ok_or(Error::Execution(ExecutionError::DashCoreBadResponseError( format!( "expected quorums of type {}, but did not receive any from Dash Core", - self.config.validator_set_quorum_type + self.config.validator_set.quorum_type ), )))? .into_iter() @@ -90,10 +90,10 @@ where if !retain { tracing::trace!( ?quorum_hash, - quorum_type = ?self.config.validator_set_quorum_type(), + quorum_type = ?self.config.validator_set.quorum_type, "removed validator set {} with quorum type {}", quorum_hash, - self.config.validator_set_quorum_type() + self.config.validator_set.quorum_type ) } @@ -110,7 +110,7 @@ where }) .map(|(key, _)| { let quorum_info_result = self.core_rpc.get_quorum_info( - self.config.validator_set_quorum_type(), + self.config.validator_set.quorum_type, key, None, )?; @@ -141,10 +141,10 @@ where tracing::trace!( ?validator_set, ?quorum_hash, - quorum_type = ?self.config.validator_set_quorum_type(), + quorum_type = ?self.config.validator_set.quorum_type, "add new validator set {} with quorum type {}", quorum_hash, - self.config.validator_set_quorum_type() + self.config.validator_set.quorum_type ); Ok((quorum_hash, validator_set)) @@ -186,17 +186,19 @@ where tracing::trace!("updated chain lock validating quorums to current validator set"); + let quorum_set = block_platform_state.chain_lock_validating_quorums_mut(); + if platform_state.is_some() { // we already have state, so we update last and previous quorums - block_platform_state - .chain_lock_validating_quorums_mut() - .rotate_quorums(quorums, last_committed_core_height, core_block_height); + quorum_set.replace_quorums( + quorums, + last_committed_core_height, + core_block_height, + ); } else { // the only case where there will be no platform_state is init chain, // so there is no previous quorums to update - block_platform_state - .chain_lock_validating_quorums_mut() - .set_last_quorums(quorums) + quorum_set.set_current_quorums(quorums) } } } else { @@ -206,7 +208,7 @@ where .ok_or(Error::Execution(ExecutionError::DashCoreBadResponseError( format!( "expected quorums of type {}, but did not receive any from Dash Core", - self.config.chain_lock_quorum_type + self.config.chain_lock.quorum_type ), )))? .into_iter() @@ -220,7 +222,7 @@ where // Remove chain_lock_validating_quorums entries that are no longer valid for the core block height block_platform_state .chain_lock_validating_quorums_mut() - .last_quorums_mut() + .current_quorums_mut() .retain(|quorum_hash, _| { let retain = chain_lock_quorums_list.contains_key::(quorum_hash); if !retain { @@ -242,7 +244,7 @@ where .filter(|(key, _)| { !block_platform_state .chain_lock_validating_quorums() - .last_quorums() + .current_quorums() .contains_key::(key) }) .map(|(key, _)| { @@ -279,21 +281,27 @@ where chain_lock_quorum_type ); - Ok((quorum_hash, public_key)) + Ok(( + quorum_hash, + Quorum { + public_key, + index: None, + }, + )) }) .collect::, Error>>()?; // Add new validator_sets entries block_platform_state .chain_lock_validating_quorums_mut() - .last_quorums_mut() + .current_quorums_mut() .extend(new_chain_lock_quorums); } if added_a_chain_lock_validating_quorum || removed_a_chain_lock_validating_quorum { if let Some(old_state) = platform_state { let previous_chain_lock_validating_quorums = - old_state.chain_lock_validating_quorums().last_quorums(); + old_state.chain_lock_validating_quorums().current_quorums(); block_platform_state .chain_lock_validating_quorums_mut() diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/choose_quorum/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/choose_quorum/mod.rs index 11d1b02f782..3af3b3fbd2d 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/choose_quorum/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/choose_quorum/mod.rs @@ -21,7 +21,7 @@ where C: CoreRPCLike, { /// Based on DIP8 deterministically chooses a pseudorandom quorum from the list of quorums - /// + // TODO: use CoreQuorumSet.select_quorums instead pub fn choose_quorum<'a>( llmq_quorum_type: QuorumType, quorums: &'a BTreeMap, diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs index f52b15d2135..fa068e11faf 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs @@ -9,10 +9,9 @@ use crate::platform_types::platform::Platform; use crate::rpc::core::CoreRPCLike; -use crate::error::execution::ExecutionError; +use crate::platform_types::core_quorum_set::CoreQuorumSetV0Methods; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; -use crate::platform_types::signature_verification_quorums::SignatureVerificationQuorumsV0Methods; use dpp::version::PlatformVersion; const CHAIN_LOCK_REQUEST_ID_PREFIX: &str = "clsig"; @@ -31,15 +30,18 @@ where round: u32, platform_state: &PlatformState, chain_lock: &ChainLock, - platform_version: &PlatformVersion, + _platform_version: &PlatformVersion, ) -> Result, Error> { + let quorum_set = platform_state.chain_lock_validating_quorums(); + let quorum_config = quorum_set.config(); + // First verify that the signature conforms to a signature let signature = G2Element::from_bytes(chain_lock.signature.as_bytes())?; // we attempt to verify the chain lock locally let chain_lock_height = chain_lock.block_height; - let window_width = self.config.chain_lock_quorum_window; + let window_width = quorum_config.window; // The last block in the window where the quorums would be the same let last_block_in_window = platform_state.last_committed_core_height() @@ -63,9 +65,7 @@ where return Ok(None); // the chain lock is too far in the future or the past to verify locally } - let mut selected_quorum_sets = platform_state - .chain_lock_validating_quorums() - .select_quorums(chain_lock_height, verification_height); + // TODO: We can use chain_lock.request_id() // From DIP 8: https://github.com/dashpay/dips/blob/master/dip-0008.md#finalization-of-signed-blocks // The request id is SHA256("clsig", blockHeight) and the message hash is the block hash of the previously successful attempt. @@ -86,20 +86,12 @@ where ); // Based on the deterministic masternode list at the given height, a quorum must be selected that was active at the time this block was mined - let probable_quorums = selected_quorum_sets.next().ok_or_else(|| { - Error::Execution(ExecutionError::CorruptedCodeExecution( - "at lest one set of quorums must be selected", - )) - })?; - - let quorum = Platform::::choose_quorum( - self.config.chain_lock_quorum_type(), - probable_quorums, - request_id.as_ref(), - platform_version, - )?; - - let Some((quorum_hash, public_key)) = quorum else { + + let mut selected_quorums = platform_state + .chain_lock_validating_quorums() + .select_quorums(chain_lock_height, verification_height, request_id); + + let Some((quorum_hash, public_key)) = selected_quorums.next() else { return Ok(None); }; @@ -107,7 +99,7 @@ where let mut engine = sha256d::Hash::engine(); - engine.input(&[self.config.chain_lock_quorum_type() as u8]); + engine.input(&[quorum_config.quorum_type as u8]); engine.input(quorum_hash.as_slice()); engine.input(request_id.as_byte_array()); engine.input(chain_lock.block_hash.as_byte_array()); @@ -133,15 +125,8 @@ where if !chain_lock_verified { // We should also check the other quorum, as there could be the situation where the core height wasn't updated every block. - if let Some(second_to_check_quorums) = selected_quorum_sets.next() { - let quorum = Platform::::choose_quorum( - self.config.chain_lock_quorum_type(), - second_to_check_quorums, - request_id.as_ref(), - platform_version, - )?; - - let Some((quorum_hash, public_key)) = quorum else { + if selected_quorums.len() == 2 { + let Some((quorum_hash, public_key)) = selected_quorums.next() else { // we return that we are not able to verify return Ok(None); }; @@ -150,7 +135,7 @@ where let mut engine = sha256d::Hash::engine(); - engine.input(&[self.config.chain_lock_quorum_type() as u8]); + engine.input(&[quorum_config.quorum_type as u8]); engine.input(quorum_hash.as_slice()); engine.input(request_id.as_byte_array()); engine.input(chain_lock.block_hash.as_byte_array()); @@ -175,17 +160,16 @@ where "chain lock was invalid for both recent and old chain lock quorums" ); } - } else if platform_state + } else if !platform_state .chain_lock_validating_quorums() - .previous_quorums() - .is_none() + .has_previous_quorums() { // we don't have old quorums, this means our node is very new. tracing::debug!( "we had no previous quorums locally, we should validate through core", ); return Ok(None); - } else if !selected_quorum_sets.should_be_verifiable { + } else if !selected_quorums.should_be_verifiable() { tracing::debug!( "we were in a situation where it would be possible we didn't have all quorums and we couldn't verify locally, we should validate through core", ); diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/mod.rs index dffa542954d..ae6e797a544 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/mod.rs @@ -52,12 +52,11 @@ impl StateTransitionActionTransformerV0 for DataContractUpdateTransition { #[cfg(test)] mod tests { - use crate::config::{ExecutionConfig, PlatformConfig, PlatformTestConfig}; + use crate::config::{ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig}; use crate::platform_types::platform::PlatformRef; use crate::rpc::core::MockCoreRPCLike; use crate::test::helpers::setup::{TempPlatform, TestPlatformBuilder}; use dpp::block::block_info::BlockInfo; - use dpp::consensus::basic::BasicError; use dpp::consensus::state::state_error::StateError; use dpp::consensus::ConsensusError; use dpp::dash_to_credits; @@ -174,7 +173,10 @@ mod tests { .data_contract_owned(); let config = PlatformConfig { - validator_set_quorum_size: 10, + validator_set: ValidatorSetConfig { + quorum_size: 10, + ..Default::default() + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, diff --git a/packages/rs-drive-abci/src/mimic/mod.rs b/packages/rs-drive-abci/src/mimic/mod.rs index d548590106a..4927771da21 100644 --- a/packages/rs-drive-abci/src/mimic/mod.rs +++ b/packages/rs-drive-abci/src/mimic/mod.rs @@ -457,7 +457,7 @@ impl<'a, C: CoreRPCLike> FullAbciApplication<'a, C> { // We need to sign the block - let quorum_type = self.platform.config.validator_set_quorum_type(); + let quorum_type = self.platform.config.validator_set.quorum_type; let state_id_hash = state_id .calculate_msg_hash(CHAIN_ID, height as i64, round as i32) .expect("cannot calculate state id hash"); diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs new file mode 100644 index 00000000000..4355d060c77 --- /dev/null +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs @@ -0,0 +1,124 @@ +mod v0; + +use crate::config::QuorumLikeConfig; +use crate::platform_types::core_quorum_set::v0::for_saving::CoreQuorumSetForSavingV0; +pub use crate::platform_types::core_quorum_set::v0::quorum_set::{ + CoreQuorumSetV0, CoreQuorumSetV0Methods, QuorumConfig, QuorumsVerificationDataIterator, +}; +pub use crate::platform_types::core_quorum_set::v0::quorums::{ + Quorum, QuorumVerificationData, Quorums, ReversedQuorumHashBytes, ThresholdBlsPublicKey, +}; +use bincode::{Decode, Encode}; +use derive_more::From; +use dpp::dashcore::QuorumSigningRequestId; +use dpp::version::PlatformVersion; + +/// Quorums with keys for signature verification +#[derive(Debug, Clone, From)] +pub enum CoreQuorumSet { + /// Version 0 of the signature verification quorums + V0(CoreQuorumSetV0), +} + +impl CoreQuorumSet { + /// Create a default SignatureVerificationQuorums + pub fn new(config: &impl QuorumLikeConfig, platform_version: &PlatformVersion) -> Self { + // TODO: default for platform version + + CoreQuorumSetV0::new(config).into() + } +} + +impl CoreQuorumSetV0Methods for CoreQuorumSet { + fn config(&self) -> &QuorumConfig { + match self { + Self::V0(v0) => v0.config(), + } + } + + fn set_current_quorums(&mut self, quorums: Quorums) { + match self { + Self::V0(v0) => v0.set_current_quorums(quorums), + } + } + + fn current_quorums(&self) -> &Quorums { + match self { + Self::V0(v0) => v0.current_quorums(), + } + } + + fn current_quorums_mut(&mut self) -> &mut Quorums { + match self { + Self::V0(v0) => v0.current_quorums_mut(), + } + } + + fn has_previous_quorums(&self) -> bool { + match self { + Self::V0(v0) => v0.has_previous_quorums(), + } + } + + fn replace_quorums( + &mut self, + quorums: Quorums, + last_active_core_height: u32, + updated_at_core_height: u32, + ) { + match self { + Self::V0(v0) => { + v0.replace_quorums(quorums, last_active_core_height, updated_at_core_height) + } + } + } + + fn update_previous_quorums( + &mut self, + previous_quorums: Quorums, + last_active_core_height: u32, + updated_at_core_height: u32, + ) { + match self { + Self::V0(v0) => v0.update_previous_quorums( + previous_quorums, + last_active_core_height, + updated_at_core_height, + ), + } + } + + fn select_quorums( + &self, + signing_height: u32, + verification_height: u32, + request_id: QuorumSigningRequestId, + ) -> QuorumsVerificationDataIterator { + match self { + Self::V0(v0) => v0.select_quorums(signing_height, verification_height, request_id), + } + } +} + +/// Core Quorum Set structure for saving to the database +#[derive(Debug, Clone, Encode, Decode)] +pub enum CoreQuorumSetForSaving { + /// Version 0 of the signature verification quorums + V0(CoreQuorumSetForSavingV0), +} + +impl From for CoreQuorumSetForSaving { + fn from(value: CoreQuorumSet) -> Self { + match value { + CoreQuorumSet::V0(v0) => CoreQuorumSetForSaving::V0(v0.into()), + } + } +} + +impl From for CoreQuorumSet { + fn from(value: CoreQuorumSetForSaving) -> Self { + match value { + CoreQuorumSetForSaving::V0(v0) => CoreQuorumSet::V0(v0.into()), + } + } +} diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs new file mode 100644 index 00000000000..dec457e86b8 --- /dev/null +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs @@ -0,0 +1,165 @@ +use crate::platform_types::core_quorum_set::v0::quorum_set::{PreviousQuorumsV0, QuorumConfig}; +use crate::platform_types::core_quorum_set::{ + CoreQuorumSetForSaving, CoreQuorumSetV0, Quorum, Quorums, ThresholdBlsPublicKey, +}; +use dashcore_rpc::dashcore::hashes::Hash; +use dashcore_rpc::dashcore::QuorumHash; +use dashcore_rpc::json::QuorumType; +use dpp::identity::state_transition::asset_lock_proof::Encode; +use dpp::platform_serialization::de::Decode; +use dpp::platform_value::Bytes32; + +#[derive(Debug, Clone, Encode, Decode)] +pub struct CoreQuorumSetForSavingV0 { + config: QuorumConfigForSavingV0, + + current_quorums: Vec, + + previous_quorums: Option, +} + +impl From for CoreQuorumSetForSaving { + fn from(value: CoreQuorumSetForSavingV0) -> Self { + CoreQuorumSetForSaving::V0(value) + } +} + +impl From for CoreQuorumSetForSavingV0 { + fn from(value: CoreQuorumSetV0) -> Self { + let CoreQuorumSetV0 { + config, + current_quorums, + previous, + } = value; + + Self { + config: config.into(), + current_quorums: current_quorums.into(), + previous_quorums: previous.map(|previous| previous.into()), + } + } +} + +impl From for CoreQuorumSetV0 { + fn from(value: CoreQuorumSetForSavingV0) -> Self { + let CoreQuorumSetForSavingV0 { + config, + current_quorums, + previous_quorums, + } = value; + + Self { + config: config.into(), + current_quorums: current_quorums.into(), + previous: previous_quorums.map(|previous| previous.into()), + } + } +} + +#[derive(Debug, Clone, Encode, Decode)] +pub struct QuorumConfigForSavingV0 { + quorum_type: QuorumType, + active_signers: u16, + rotation: bool, + window: u32, +} + +impl From for QuorumConfigForSavingV0 { + fn from(config: QuorumConfig) -> Self { + Self { + quorum_type: config.quorum_type, + active_signers: config.active_signers, + rotation: config.rotation, + window: config.window, + } + } +} + +impl From for QuorumConfig { + fn from(config: QuorumConfigForSavingV0) -> Self { + Self { + quorum_type: config.quorum_type, + active_signers: config.active_signers, + rotation: config.rotation, + window: config.window, + } + } +} + +#[derive(Debug, Clone, Encode, Decode)] +pub struct PreviousQuorumsForSavingV0 { + quorums: Vec, + active_core_height: u32, + updated_at_core_height: u32, + previous_change_height: Option, +} + +impl From for PreviousQuorumsForSavingV0 { + fn from(value: PreviousQuorumsV0) -> Self { + let PreviousQuorumsV0 { + quorums, + active_core_height, + updated_at_core_height, + previous_change_height, + } = value; + + Self { + quorums: quorums.into(), + active_core_height, + updated_at_core_height, + previous_change_height, + } + } +} + +impl From for PreviousQuorumsV0 { + fn from(value: PreviousQuorumsForSavingV0) -> Self { + let PreviousQuorumsForSavingV0 { + quorums, + active_core_height, + updated_at_core_height, + previous_change_height, + } = value; + + Self { + quorums: quorums.into(), + active_core_height, + updated_at_core_height, + previous_change_height, + } + } +} + +#[derive(Debug, Clone, Encode, Decode)] +pub struct QuorumForSavingV0 { + hash: Bytes32, + #[bincode(with_serde)] + public_key: ThresholdBlsPublicKey, + index: Option, +} + +impl From> for Quorums { + fn from(value: Vec) -> Self { + Quorums::from_iter(value.into_iter().map(|quorum| { + ( + QuorumHash::from_byte_array(quorum.hash.to_buffer()), + Quorum { + public_key: quorum.public_key, + index: quorum.index, + }, + ) + })) + } +} + +impl Into> for Quorums { + fn into(self) -> Vec { + self.into_iter() + .map(|(hash, quorum)| QuorumForSavingV0 { + hash: Bytes32::from(hash.as_byte_array()), + public_key: quorum.public_key, + index: quorum.index, + }) + .collect() + } +} diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/mod.rs new file mode 100644 index 00000000000..e78d6c1c7f4 --- /dev/null +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/mod.rs @@ -0,0 +1,3 @@ +pub mod for_saving; +pub mod quorum_set; +pub mod quorums; diff --git a/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs similarity index 51% rename from packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs rename to packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs index 2ce7f35c1e1..eb8b6e524a9 100644 --- a/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs @@ -1,59 +1,60 @@ -use bincode::{Decode, Encode}; -use dpp::dashcore::QuorumHash; -use std::collections::BTreeMap; - -pub use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; - -/// Quorum key per hash -pub type QuorumKeys = BTreeMap; +use crate::config::QuorumLikeConfig; +use crate::platform_types::core_quorum_set::v0::quorums::{QuorumVerificationData, Quorums}; +use dashcore_rpc::json::QuorumType; +use dpp::dashcore::QuorumSigningRequestId; +use std::vec::IntoIter; /// Previously obtained quorums and heights. Required for signature verification -#[derive(Debug, Clone, Encode, Decode, Default)] -pub struct PreviousQuorums { - #[bincode(with_serde)] - quorums: QuorumKeys, +#[derive(Debug, Clone)] +pub(super) struct PreviousQuorumsV0 { + pub(super) quorums: Quorums, /// The core height at which these quorums were last active - active_core_height: u32, + pub(super) active_core_height: u32, /// The core height when the quorums were changed - updated_at_core_height: u32, + pub(super) updated_at_core_height: u32, /// The core height the previous chain lock validating quorums became active - previous_change_height: Option, + pub(super) previous_change_height: Option, } /// Quorums with keys for signature verification -#[derive(Debug, Clone, Encode, Decode, Default)] -pub struct SignatureVerificationQuorumsV0 { +#[derive(Debug, Clone)] +pub struct CoreQuorumSetV0 { + /// Quorum configuration + pub(super) config: QuorumConfig, + /// Current quorums - #[bincode(with_serde)] - last_quorums: QuorumKeys, + pub(super) current_quorums: Quorums, - /// The slightly old quorums used for validating chain locks (or instant locks), it's important to keep + /// The slightly old quorums used for validating ch ain locks (or instant locks), it's important to keep /// these because validation of signatures happens for the quorums that are 8 blocks before the /// height written in the chain lock. The same for instant locks - previous: Option, + pub(super) previous: Option, } /// The trait defines methods for the signature verification quorums structure v0 -pub trait SignatureVerificationQuorumsV0Methods { - /// Set last quorum keys - fn set_last_quorums(&mut self, quorums: QuorumKeys); +pub trait CoreQuorumSetV0Methods { + /// Config + fn config(&self) -> &QuorumConfig; - /// Last quorum keys - fn last_quorums(&self) -> &QuorumKeys; + /// Set current quorum keys + fn set_current_quorums(&mut self, quorums: Quorums); + + /// Current quorum + fn current_quorums(&self) -> &Quorums; /// Last quorum keys mutable - fn last_quorums_mut(&mut self) -> &mut QuorumKeys; + fn current_quorums_mut(&mut self) -> &mut Quorums; - /// Previous quorums - fn previous_quorums(&self) -> Option<&PreviousQuorums>; + /// Has previous quorums? + fn has_previous_quorums(&self) -> bool; /// Set last quorums keys and update previous quorums - fn rotate_quorums( + fn replace_quorums( &mut self, - quorums: QuorumKeys, + quorums: Quorums, last_active_core_height: u32, updated_at_core_height: u32, ); @@ -61,67 +62,125 @@ pub trait SignatureVerificationQuorumsV0Methods { /// Update previous quorums fn update_previous_quorums( &mut self, - previous_quorums: QuorumKeys, + previous_quorums: Quorums, last_active_core_height: u32, updated_at_core_height: u32, ); - /// Select quorum sets for signature verification + /// Select quorums for signature verification fn select_quorums( &self, signing_height: u32, verification_height: u32, - ) -> SelectedVerificationQuorumSets; + request_id: QuorumSigningRequestId, + ) -> QuorumsVerificationDataIterator; } -pub struct SelectedVerificationQuorumSets<'q> { - pub quorum_sets: Vec<&'q QuorumKeys>, - pub should_be_verifiable: bool, +/// Iterator over selected quorum sets and specific quorums based on request_id and quorum configuration +pub struct QuorumsVerificationDataIterator<'q> { + /// Quorum configuration + config: &'q QuorumConfig, + /// Request ID to chose right quorum + request_id: QuorumSigningRequestId, + /// Appropriate quorum sets + quorum_sets: IntoIter<&'q Quorums>, + /// Should we expect signature verification to be successful + should_be_verifiable: bool, } -impl<'q> Iterator for SelectedVerificationQuorumSets<'q> { - type Item = &'q QuorumKeys; +impl<'p> Iterator for QuorumsVerificationDataIterator<'p> { + type Item = QuorumVerificationData<'p>; fn next(&mut self) -> Option { - self.quorum_sets.pop() + let quorum_set = self.quorum_sets.next(); + + let Some(quorum_set) = quorum_set else { + return None; + }; + + if self.config.rotation { + quorum_set.find_rotating_quorum_verification_data( + self.config.active_signers, + self.request_id.as_ref(), + ) + } else { + quorum_set.find_classic_quorum_verification_data( + self.config.quorum_type, + self.request_id.as_ref(), + ) + } } } -impl<'q> SignatureVerificationQuorumsV0Methods for SignatureVerificationQuorumsV0 { - fn set_last_quorums(&mut self, quorums: QuorumKeys) { - self.last_quorums = quorums; +impl<'q> QuorumsVerificationDataIterator<'q> { + /// Number of quorum sets + pub fn len(&self) -> usize { + self.quorum_sets.len() } - fn last_quorums(&self) -> &QuorumKeys { - &self.last_quorums + /// Does the iterator have any quorum sets + pub fn is_empty(&self) -> bool { + self.quorum_sets.len() == 0 } - fn last_quorums_mut(&mut self) -> &mut QuorumKeys { - &mut self.last_quorums + /// Should we expect signature verification to be successful + pub fn should_be_verifiable(&self) -> bool { + self.should_be_verifiable } +} - fn previous_quorums(&self) -> Option<&PreviousQuorums> { - self.previous.as_ref() +/// Quorum configuration +#[derive(Debug, Clone)] +pub struct QuorumConfig { + /// Type + pub quorum_type: QuorumType, + /// Active quorum signers count + pub active_signers: u16, + /// Is it a DIP24 rotating quorum or classic + pub rotation: bool, + /// DKG interval + pub window: u32, +} + +impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { + fn config(&self) -> &QuorumConfig { + &self.config } - fn rotate_quorums( + fn set_current_quorums(&mut self, quorums: Quorums) { + self.current_quorums = quorums; + } + + fn current_quorums(&self) -> &Quorums { + &self.current_quorums + } + + fn current_quorums_mut(&mut self) -> &mut Quorums { + &mut self.current_quorums + } + + fn has_previous_quorums(&self) -> bool { + self.previous.is_some() + } + + fn replace_quorums( &mut self, - quorums: QuorumKeys, + quorums: Quorums, last_active_height: u32, updated_at_core_height: u32, ) { - let previous_quorums = std::mem::replace(&mut self.last_quorums, quorums); + let previous_quorums = std::mem::replace(&mut self.current_quorums, quorums); self.update_previous_quorums(previous_quorums, last_active_height, updated_at_core_height); } fn update_previous_quorums( &mut self, - previous_quorums: QuorumKeys, + previous_quorums: Quorums, last_active_core_height: u32, updated_at_core_height: u32, ) { - self.previous = Some(PreviousQuorums { + self.previous = Some(PreviousQuorumsV0 { quorums: previous_quorums, active_core_height: last_active_core_height, updated_at_core_height, @@ -136,7 +195,8 @@ impl<'q> SignatureVerificationQuorumsV0Methods for SignatureVerificationQuorumsV &self, signing_height: u32, verification_height: u32, - ) -> SelectedVerificationQuorumSets { + request_id: QuorumSigningRequestId, + ) -> QuorumsVerificationDataIterator { let mut quorums = Vec::new(); let mut should_be_verifiable = false; @@ -153,7 +213,7 @@ impl<'q> SignatureVerificationQuorumsV0Methods for SignatureVerificationQuorumsV // If we have // ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) ------ 105 (new chain lock verification height 113 - 8) // We should also use current quorums, this is because at 105 we are sure new chain lock validating quorums are active - quorums.push(&self.last_quorums); + quorums.push(&self.current_quorums); should_be_verifiable = true; } else if signing_height > 8 && verification_height <= previous_quorum_height { should_be_verifiable = previous_quorums_change_height @@ -178,16 +238,34 @@ impl<'q> SignatureVerificationQuorumsV0Methods for SignatureVerificationQuorumsV // we are in between, so we don't actually know if it was the old one or the new one to be used. // ------- 100 (previous_quorum_height) ------ 104 (new chain lock verification height 112 - 8) -------105 (change_quorum_height) // we should just try both, starting with the current quorums - quorums.push(&self.last_quorums); + quorums.push(&self.current_quorums); quorums.push(&previous.quorums); } } else { - quorums.push(&self.last_quorums); + quorums.push(&self.current_quorums); } - SelectedVerificationQuorumSets { - quorum_sets: quorums, + QuorumsVerificationDataIterator { + config: &self.config, + request_id, + quorum_sets: quorums.into_iter(), should_be_verifiable, } } } + +impl CoreQuorumSetV0 { + /// New empty quorum set based on quorum configuration + pub fn new(config: &impl QuorumLikeConfig) -> Self { + CoreQuorumSetV0 { + config: QuorumConfig { + quorum_type: config.quorum_type(), + active_signers: config.quorum_active_signers(), + rotation: config.quorum_rotation(), + window: config.quorum_window(), + }, + current_quorums: Quorums::default(), + previous: None, + } + } +} diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs new file mode 100644 index 00000000000..ed6fdc9ccea --- /dev/null +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs @@ -0,0 +1,156 @@ +use dashcore_rpc::dashcore::hashes::Hash; +use dashcore_rpc::json::QuorumType; +use derive_more::{Deref, DerefMut, From}; +use dpp::dashcore::QuorumHash; +use std::collections::BTreeMap; +use std::convert::TryInto; + +pub use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; + +/// Reversed quorum hash bytes. Used for signature verification as part of the signature payload +pub type ReversedQuorumHashBytes = Vec; + +/// Quorum verification data for signature verification +pub type QuorumVerificationData<'p> = (ReversedQuorumHashBytes, &'p ThresholdBlsPublicKey); + +use dpp::dashcore::hashes::{sha256d, HashEngine}; + +type QuorumsInnerV0 = BTreeMap; + +/// Quorum per hash +#[derive(Debug, Clone, Deref, DerefMut, From, Default)] +pub struct Quorums(QuorumsInnerV0); + +impl FromIterator<(QuorumHash, ThresholdBlsPublicKey)> for Quorums { + fn from_iter>(iter: T) -> Self { + let mut quorums = Quorums::default(); + + for (hash, public_key) in iter { + quorums.0.insert( + hash, + Quorum { + index: None, + public_key, + }, + ); + } + + quorums + } +} + +impl FromIterator<(QuorumHash, ThresholdBlsPublicKey, Option)> for Quorums { + fn from_iter)>>( + iter: T, + ) -> Self { + let mut quorums = Quorums::default(); + + for (hash, public_key, index) in iter { + quorums.0.insert(hash, Quorum { index, public_key }); + } + + quorums + } +} + +impl FromIterator<(QuorumHash, Quorum)> for Quorums { + fn from_iter>(iter: T) -> Self { + let mut quorums = Quorums::default(); + + for (hash, quorum) in iter { + quorums.0.insert(hash, quorum); + } + + quorums + } +} + +impl IntoIterator for Quorums { + type Item = (QuorumHash, Quorum); + type IntoIter = std::collections::btree_map::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + +impl Quorums { + pub(super) fn find_classic_quorum_verification_data( + &self, + quorum_type: QuorumType, + request_id: &[u8; 32], + ) -> Option { + // Scoring system logic + let mut scores: Vec<(ReversedQuorumHashBytes, &ThresholdBlsPublicKey, [u8; 32])> = + Vec::new(); + + for (quorum_hash, quorum) in self.0.iter() { + let mut quorum_hash_bytes = quorum_hash.to_byte_array().to_vec(); + + // Only the quorum hash needs reversal. + quorum_hash_bytes.reverse(); + + let mut hasher = sha256d::Hash::engine(); + + // Serialize and hash the LLMQ type + hasher.input(&[quorum_type as u8]); + + // Serialize and add the quorum hash + hasher.input(quorum_hash_bytes.as_slice()); + + // Serialize and add the selection hash from the chain lock + hasher.input(request_id.as_slice()); + + // Finalize the hash + let hash_result = sha256d::Hash::from_engine(hasher); + scores.push((quorum_hash_bytes, &quorum.public_key, hash_result.into())); + } + + if scores.is_empty() { + return None; + } + + scores.sort_by_key(|k| k.2); + + let (quorum_reversed_hash, public_key, _) = scores.remove(0); + + Some((quorum_reversed_hash, public_key)) + } + + pub(super) fn find_rotating_quorum_verification_data( + &self, + quorums_signing_active_count: u16, + request_id: &[u8; 32], + ) -> Option { + let n = quorums_signing_active_count as u64; + + let b = u64::from_le_bytes(request_id[24..32].try_into().unwrap()); + + // Take last n bits of b + let mask = (1u64 << n) - 1; + let signer = mask & (b >> (64 - n)); + + self.0 + .iter() + .find(|(_, quorum)| quorum.index == Some(signer as u32)) + .map(|(hash, quorum)| { + let mut quorum_reversed_hash = hash.to_byte_array().to_vec(); + + // Only the quorum hash needs reversal. + quorum_reversed_hash.reverse(); + + (quorum_reversed_hash, &quorum.public_key) + }) + } +} + +/// Quorum for signature verification +#[derive(Debug, Clone)] +pub struct Quorum { + /// Index is present only for rotated quorums + pub index: Option, + + /// Quorum threshold public key is used to verify + /// signatures produced by corresponding quorum + pub public_key: ThresholdBlsPublicKey, +} diff --git a/packages/rs-drive-abci/src/platform_types/mod.rs b/packages/rs-drive-abci/src/platform_types/mod.rs index 66a86cbbee2..c48d9235bc7 100644 --- a/packages/rs-drive-abci/src/platform_types/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/mod.rs @@ -35,6 +35,8 @@ pub mod block_proposal; pub mod cleaned_abci_messages; /// The commit pub mod commit; +/// Signature verification quorums for Core +pub mod core_quorum_set; /// Epoch pub mod epoch_info; /// The execution event result @@ -47,8 +49,6 @@ pub mod platform; pub mod platform_state; /// Required identity public key set for system identities pub mod required_identity_public_key_set; -/// Signature verification quorums -pub mod signature_verification_quorums; /// The state transition execution result as part of the block execution outcome pub mod state_transitions_processing_result; /// System identity public keys diff --git a/packages/rs-drive-abci/src/platform_types/platform/mod.rs b/packages/rs-drive-abci/src/platform_types/platform/mod.rs index 3cab0f01fc8..cbf1a5685a8 100644 --- a/packages/rs-drive-abci/src/platform_types/platform/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform/mod.rs @@ -249,6 +249,7 @@ impl Platform { let platform_state = PlatformState::default_with_protocol_versions( current_protocol_version_in_consensus, next_epoch_protocol_version, + &config, ); let height = platform_state.last_committed_block_height(); diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs index be67bdb11e4..b92f24a9a74 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs @@ -20,8 +20,9 @@ use dpp::version::{PlatformVersion, TryFromPlatformVersioned, TryIntoPlatformVer use dpp::ProtocolError; use indexmap::IndexMap; +use crate::config::PlatformConfig; use crate::error::execution::ExecutionError; -use crate::platform_types::signature_verification_quorums::SignatureVerificationQuorums; +use crate::platform_types::core_quorum_set::CoreQuorumSet; use dpp::block::block_info::BlockInfo; use dpp::util::hash::hash_double; use std::collections::BTreeMap; @@ -119,11 +120,13 @@ impl PlatformState { pub fn default_with_protocol_versions( current_protocol_version_in_consensus: ProtocolVersion, next_epoch_protocol_version: ProtocolVersion, + config: &PlatformConfig, ) -> PlatformState { //todo find the current Platform state for the protocol version PlatformStateV0::default_with_protocol_versions( current_protocol_version_in_consensus, next_epoch_protocol_version, + config, ) .into() } @@ -316,7 +319,7 @@ impl PlatformStateV0Methods for PlatformState { } } - fn chain_lock_validating_quorums(&self) -> &SignatureVerificationQuorums { + fn chain_lock_validating_quorums(&self) -> &CoreQuorumSet { match self { PlatformState::V0(v0) => &v0.chain_lock_validating_quorums, } @@ -382,7 +385,7 @@ impl PlatformStateV0Methods for PlatformState { } } - fn set_chain_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorums) { + fn set_chain_lock_validating_quorums(&mut self, quorums: CoreQuorumSet) { match self { PlatformState::V0(v0) => v0.set_chain_lock_validating_quorums(quorums), } @@ -442,7 +445,7 @@ impl PlatformStateV0Methods for PlatformState { } } - fn chain_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorums { + fn chain_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet { match self { PlatformState::V0(v0) => v0.chain_lock_validating_quorums_mut(), } @@ -471,4 +474,16 @@ impl PlatformStateV0Methods for PlatformState { PlatformState::V0(v0) => v0.last_committed_block_id_hash(), } } + + fn instant_lock_validating_quorums(&self) -> &CoreQuorumSet { + match self { + PlatformState::V0(v0) => v0.instant_lock_validating_quorums(), + } + } + + fn instant_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet { + match self { + PlatformState::V0(v0) => v0.instant_lock_validating_quorums_mut(), + } + } } diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs index 4a9da76867f..ceaf5421e64 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs @@ -19,7 +19,8 @@ use dpp::block::block_info::{BlockInfo, DEFAULT_BLOCK_INFO}; use dpp::block::extended_block_info::v0::ExtendedBlockInfoV0Getters; use dpp::version::{PlatformVersion, TryIntoPlatformVersioned}; -use crate::platform_types::signature_verification_quorums::SignatureVerificationQuorums; +use crate::config::PlatformConfig; +use crate::platform_types::core_quorum_set::{CoreQuorumSet, CoreQuorumSetForSaving}; use itertools::Itertools; use std::collections::BTreeMap; use std::fmt::{Debug, Formatter}; @@ -44,8 +45,11 @@ pub struct PlatformStateV0 { /// all members pub validator_sets: IndexMap, - /// The current quorums used for validating chain locks (400 60 for mainnet) - pub chain_lock_validating_quorums: SignatureVerificationQuorums, + /// Quorums used for validating chain locks (400 60 for mainnet) + pub chain_lock_validating_quorums: CoreQuorumSet, + + /// Quorums used for validating instant locks + pub instant_lock_validating_quorums: CoreQuorumSet, /// current full masternode list pub full_masternode_list: BTreeMap, @@ -89,6 +93,10 @@ impl Debug for PlatformStateV0 { "chain_lock_validating_quorums", &self.chain_lock_validating_quorums, ) + .field( + "instant_lock_validating_quorums", + &self.instant_lock_validating_quorums, + ) .finish() } } @@ -122,8 +130,11 @@ pub struct PlatformStateForSavingV0 { #[bincode(with_serde)] pub validator_sets: Vec<(Bytes32, ValidatorSet)>, - /// The 400 60 quorums used for validating chain locks - pub chain_lock_validating_quorums: SignatureVerificationQuorums, + /// The quorums used for validating chain locks + pub chain_lock_validating_quorums: CoreQuorumSetForSaving, + + /// The quorums used for validating instant locks + pub instant_lock_validating_quorums: CoreQuorumSetForSaving, /// current full masternode list pub full_masternode_list: BTreeMap, @@ -154,7 +165,8 @@ impl TryFrom for PlatformStateForSavingV0 { .into_iter() .map(|(k, v)| (k.to_byte_array().into(), v)) .collect(), - chain_lock_validating_quorums: value.chain_lock_validating_quorums, + chain_lock_validating_quorums: value.chain_lock_validating_quorums.into(), + instant_lock_validating_quorums: value.instant_lock_validating_quorums.into(), full_masternode_list: value .full_masternode_list .into_iter() @@ -197,7 +209,8 @@ impl From for PlatformStateV0 { .into_iter() .map(|(k, v)| (QuorumHash::from_byte_array(k.to_buffer()), v)) .collect(), - chain_lock_validating_quorums: value.chain_lock_validating_quorums, + chain_lock_validating_quorums: value.chain_lock_validating_quorums.into(), + instant_lock_validating_quorums: value.instant_lock_validating_quorums.into(), full_masternode_list: value .full_masternode_list .into_iter() @@ -217,6 +230,7 @@ impl PlatformStateV0 { pub(super) fn default_with_protocol_versions( current_protocol_version_in_consensus: ProtocolVersion, next_epoch_protocol_version: ProtocolVersion, + config: &PlatformConfig, ) -> PlatformStateV0 { let platform_version = PlatformVersion::get(current_protocol_version_in_consensus) .expect("invalid protocol version"); @@ -228,8 +242,11 @@ impl PlatformStateV0 { current_validator_set_quorum_hash: QuorumHash::all_zeros(), next_validator_set_quorum_hash: None, validator_sets: Default::default(), - chain_lock_validating_quorums: - SignatureVerificationQuorums::default_for_platform_version(platform_version), + chain_lock_validating_quorums: CoreQuorumSet::new(&config.chain_lock, platform_version), + instant_lock_validating_quorums: CoreQuorumSet::new( + &config.instant_lock, + platform_version, + ), full_masternode_list: Default::default(), hpmn_masternode_list: Default::default(), genesis_block_info: None, @@ -283,8 +300,11 @@ pub trait PlatformStateV0Methods { /// Returns the current validator sets. fn validator_sets(&self) -> &IndexMap; - /// Returns the current 400 60 quorums used to validate chain locks. - fn chain_lock_validating_quorums(&self) -> &SignatureVerificationQuorums; + /// Returns the quorums used to validate chain locks. + fn chain_lock_validating_quorums(&self) -> &CoreQuorumSet; + + /// Returns quorums used to validate instant locks. + fn instant_lock_validating_quorums(&self) -> &CoreQuorumSet; /// Returns the full list of masternodes. fn full_masternode_list(&self) -> &BTreeMap; @@ -317,7 +337,7 @@ pub trait PlatformStateV0Methods { fn set_validator_sets(&mut self, sets: IndexMap); /// Sets the current chain lock validating quorums. - fn set_chain_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorums); + fn set_chain_lock_validating_quorums(&mut self, quorums: CoreQuorumSet); /// Sets the full masternode list. fn set_full_masternode_list(&mut self, list: BTreeMap); @@ -345,8 +365,11 @@ pub trait PlatformStateV0Methods { /// Returns a mutable reference to the current validator sets. fn validator_sets_mut(&mut self) -> &mut IndexMap; - /// Returns a mutable reference to the current chain lock validating quorums. - fn chain_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorums; + /// Returns a mutable reference to the chain lock validating quorums. + fn chain_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet; + + /// Returns a mutable reference to the instant lock validating quorums. + fn instant_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet; /// Returns a mutable reference to the full masternode list. fn full_masternode_list_mut(&mut self) -> &mut BTreeMap; @@ -499,11 +522,16 @@ impl PlatformStateV0Methods for PlatformStateV0 { &self.validator_sets } - /// Returns the current 400 60 quorums used to validate chain locks. - fn chain_lock_validating_quorums(&self) -> &SignatureVerificationQuorums { + /// Returns the quorums used to validate chain locks. + fn chain_lock_validating_quorums(&self) -> &CoreQuorumSet { &self.chain_lock_validating_quorums } + /// Returns the quorums used to validate instant locks. + fn instant_lock_validating_quorums(&self) -> &CoreQuorumSet { + &self.instant_lock_validating_quorums + } + /// Returns the full list of masternodes. fn full_masternode_list(&self) -> &BTreeMap { &self.full_masternode_list @@ -561,7 +589,7 @@ impl PlatformStateV0Methods for PlatformStateV0 { } /// Sets the current chain lock validating quorums. - fn set_chain_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorums) { + fn set_chain_lock_validating_quorums(&mut self, quorums: CoreQuorumSet) { self.chain_lock_validating_quorums = quorums; } @@ -604,10 +632,14 @@ impl PlatformStateV0Methods for PlatformStateV0 { &mut self.validator_sets } - fn chain_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorums { + fn chain_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet { &mut self.chain_lock_validating_quorums } + fn instant_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet { + &mut self.instant_lock_validating_quorums + } + fn full_masternode_list_mut(&mut self) -> &mut BTreeMap { &mut self.full_masternode_list } diff --git a/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs b/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs deleted file mode 100644 index 858486e8748..00000000000 --- a/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs +++ /dev/null @@ -1,89 +0,0 @@ -mod v0; - -use crate::platform_types::signature_verification_quorums::v0::{ - PreviousQuorums, SelectedVerificationQuorumSets, -}; -use bincode::{Decode, Encode}; -use derive_more::From; -use dpp::version::PlatformVersion; -pub use v0::{QuorumKeys, SignatureVerificationQuorumsV0, SignatureVerificationQuorumsV0Methods}; - -/// Quorums with keys for signature verification -#[derive(Debug, Clone, Encode, Decode, From)] -pub enum SignatureVerificationQuorums { - /// Version 0 of the signature verification quorums - V0(SignatureVerificationQuorumsV0), -} - -impl SignatureVerificationQuorums { - /// Create a default SignatureVerificationQuorums - pub fn default_for_platform_version(platform_version: &PlatformVersion) -> Self { - // TODO: default for platform version - - SignatureVerificationQuorumsV0::default().into() - } -} - -impl SignatureVerificationQuorumsV0Methods for SignatureVerificationQuorums { - fn set_last_quorums(&mut self, quorums: QuorumKeys) { - match self { - Self::V0(v0) => v0.set_last_quorums(quorums), - } - } - - fn last_quorums(&self) -> &QuorumKeys { - match self { - Self::V0(v0) => v0.last_quorums(), - } - } - - fn last_quorums_mut(&mut self) -> &mut QuorumKeys { - match self { - Self::V0(v0) => v0.last_quorums_mut(), - } - } - - fn previous_quorums(&self) -> Option<&PreviousQuorums> { - match self { - Self::V0(v0) => v0.previous_quorums(), - } - } - - fn rotate_quorums( - &mut self, - quorums: QuorumKeys, - last_active_core_height: u32, - updated_at_core_height: u32, - ) { - match self { - Self::V0(v0) => { - v0.rotate_quorums(quorums, last_active_core_height, updated_at_core_height) - } - } - } - - fn update_previous_quorums( - &mut self, - previous_quorums: QuorumKeys, - last_active_core_height: u32, - updated_at_core_height: u32, - ) { - match self { - Self::V0(v0) => v0.update_previous_quorums( - previous_quorums, - last_active_core_height, - updated_at_core_height, - ), - } - } - - fn select_quorums( - &self, - signing_height: u32, - verification_height: u32, - ) -> SelectedVerificationQuorumSets { - match self { - Self::V0(v0) => v0.select_quorums(signing_height, verification_height), - } - } -} diff --git a/packages/rs-drive-abci/src/query/response_metadata/v0/mod.rs b/packages/rs-drive-abci/src/query/response_metadata/v0/mod.rs index 12286271562..edd234ab2d4 100644 --- a/packages/rs-drive-abci/src/query/response_metadata/v0/mod.rs +++ b/packages/rs-drive-abci/src/query/response_metadata/v0/mod.rs @@ -28,7 +28,7 @@ impl Platform { Proof { grovedb_proof: proof, quorum_hash: platform_state.last_committed_quorum_hash().to_vec(), - quorum_type: self.config.validator_set_quorum_type() as u32, + quorum_type: self.config.validator_set.quorum_type as u32, block_id_hash: platform_state.last_committed_block_id_hash().to_vec(), signature: platform_state.last_committed_block_signature().to_vec(), round: platform_state.last_committed_block_round(), diff --git a/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs b/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs index f80ec3645de..7d141bfd735 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs @@ -4,7 +4,9 @@ mod tests { use crate::execution::run_chain_for_strategy; use crate::strategy::CoreHeightIncrease::RandomCoreHeightIncrease; use crate::strategy::{MasternodeListChangesStrategy, NetworkStrategy}; - use drive_abci::config::{ExecutionConfig, PlatformConfig, PlatformTestConfig}; + use drive_abci::config::{ + ChainLockConfig, ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig, + }; use drive_abci::test::helpers::setup::TestPlatformBuilder; use strategy_tests::frequency::Frequency; @@ -58,12 +60,9 @@ mod tests { ..Default::default() }; - let quorum_size = 100; - let config = PlatformConfig { - validator_set_quorum_size: quorum_size, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_400_60".to_string(), + validator_set: ValidatorSetConfig::default(), + chain_lock: ChainLockConfig::default(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, diff --git a/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs index 4c892673123..231d1626bd4 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs @@ -4,7 +4,9 @@ mod tests { use crate::execution::run_chain_for_strategy; use crate::strategy::CoreHeightIncrease::RandomCoreHeightIncrease; use crate::strategy::{MasternodeListChangesStrategy, NetworkStrategy}; - use drive_abci::config::{ExecutionConfig, PlatformConfig, PlatformTestConfig}; + use drive_abci::config::{ + ChainLockConfig, ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig, + }; use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods; use drive_abci::platform_types::validator_set::v0::ValidatorSetV0Getters; use drive_abci::test::helpers::setup::TestPlatformBuilder; @@ -61,9 +63,11 @@ mod tests { let quorum_size = 100; let config = PlatformConfig { - validator_set_quorum_size: quorum_size, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_size, + ..Default::default() + }, + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -159,9 +163,11 @@ mod tests { let quorum_size = 100; let config = PlatformConfig { - validator_set_quorum_size: quorum_size, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_size, + ..Default::default() + }, + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -246,9 +252,11 @@ mod tests { let quorum_size = 100; let config = PlatformConfig { - validator_set_quorum_size: quorum_size, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_size, + ..Default::default() + }, + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, diff --git a/packages/rs-drive-abci/tests/strategy_tests/execution.rs b/packages/rs-drive-abci/tests/strategy_tests/execution.rs index 3db5a245faa..07bf3e200cb 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/execution.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/execution.rs @@ -55,8 +55,8 @@ pub(crate) fn run_chain_for_strategy( ) -> ChainExecutionOutcome { let validator_quorum_count = strategy.validator_quorum_count; // In most tests 24 quorums let chain_lock_quorum_count = strategy.chain_lock_quorum_count; // In most tests 4 quorums when not the same as validator - let validator_set_quorum_size = config.validator_set_quorum_size; - let chain_lock_quorum_size = config.chain_lock_quorum_size; + let validator_set_quorum_size = config.validator_set.quorum_size; + let chain_lock_quorum_size = config.chain_lock.quorum_size; let mut rng = StdRng::seed_from_u64(seed); @@ -68,7 +68,7 @@ pub(crate) fn run_chain_for_strategy( let max_core_height = core_height_increase.max_core_height(block_count, strategy.initial_core_height); - let chain_lock_quorum_type = config.chain_lock_quorum_type(); + let chain_lock_quorum_type = config.chain_lock.quorum_type; let sign_chain_locks = strategy.sign_chain_locks; @@ -261,7 +261,7 @@ pub(crate) fn run_chain_for_strategy( quorums_details.shuffle(&mut rng); let (chain_lock_quorums, chain_lock_quorums_details) = - if config.validator_set_quorum_type != config.chain_lock_quorum_type { + if config.validator_set.quorum_type != config.chain_lock.quorum_type { let total_chain_lock_quorums = if strategy.rotate_quorums { chain_lock_quorum_count * 10 } else { @@ -806,7 +806,7 @@ pub(crate) fn continue_chain_for_strategy( StrategyRandomness::SeedEntropy(seed) => StdRng::seed_from_u64(seed), StrategyRandomness::RNGEntropy(rng) => rng, }; - let quorum_size = config.validator_set_quorum_size; + let quorum_size = config.validator_set.quorum_size; let first_block_time = start_time_ms; let mut current_identities = vec![]; let mut signer = strategy.strategy.signer.clone().unwrap_or_default(); @@ -1013,7 +1013,7 @@ pub(crate) fn continue_chain_for_strategy( query_strategy.query_chain_for_strategy( &ProofVerification { quorum_hash: ¤t_quorum_with_test_info.quorum_hash.into(), - quorum_type: config.validator_set_quorum_type(), + quorum_type: config.validator_set.quorum_type, app_version, chain_id: drive_abci::mimic::CHAIN_ID.to_string(), core_chain_locked_height: state_id.core_chain_locked_height, diff --git a/packages/rs-drive-abci/tests/strategy_tests/failures.rs b/packages/rs-drive-abci/tests/strategy_tests/failures.rs index c1fe8150951..167bbac8f53 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/failures.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/failures.rs @@ -7,7 +7,9 @@ mod tests { use crate::strategy::{FailureStrategy, NetworkStrategy}; use strategy_tests::{IdentityInsertInfo, StartIdentities, Strategy}; - use drive_abci::config::{ExecutionConfig, PlatformConfig, PlatformTestConfig}; + use drive_abci::config::{ + ChainLockConfig, ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig, + }; use dpp::dashcore::hashes::Hash; use dpp::dashcore::{BlockHash, ChainLock}; @@ -75,9 +77,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -150,9 +151,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -198,9 +198,9 @@ mod tests { // // We use the dpns contract and we insert two documents both with the same "name" // // This is a common scenario we should see quite often // let config = PlatformConfig { - // validator_set_quorum_size: 100, - // validator_set_quorum_type: "llmq_100_67".to_string(), - // chain_lock_quorum_type: "llmq_100_67".to_string(), + // validator_set_quorum_quorum_size: 100, + // validator_set_quorum_type: QuorumType::Llmq100_67, + // chain_lock_quorum_type: QuorumType::Llmq100_67, // execution: ExecutionConfig { // //we disable document triggers because we are using dpns and dpns needs a preorder // use_document_triggers: false, diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index 43ea171e360..79f2db20208 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -47,7 +47,7 @@ mod tests { use dashcore_rpc::dashcore::hashes::Hash; use dashcore_rpc::dashcore::BlockHash; use dashcore_rpc::dashcore_rpc_json::AssetUnlockStatus; - use dashcore_rpc::json::AssetUnlockStatusResult; + use dashcore_rpc::json::{AssetUnlockStatusResult, QuorumType}; use dpp::block::extended_block_info::v0::ExtendedBlockInfoV0Getters; use std::sync::{Arc, Mutex}; use strategy_tests::operations::DocumentAction::{ @@ -74,7 +74,9 @@ mod tests { use dpp::version::PlatformVersion; use drive::drive::config::DEFAULT_QUERY_LIMIT; use drive::drive::identity::withdrawals::WithdrawalTransactionIndex; - use drive_abci::config::{ExecutionConfig, PlatformTestConfig}; + use drive_abci::config::{ + ChainLockConfig, ExecutionConfig, PlatformTestConfig, ValidatorSetConfig, + }; use drive_abci::logging::LogLevel; use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods; @@ -113,9 +115,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -158,9 +159,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -203,9 +203,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -335,9 +334,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -468,9 +466,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -530,9 +527,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -579,9 +575,8 @@ mod tests { }; let hour_in_ms = 1000 * 60 * 60; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -636,9 +631,8 @@ mod tests { let hour_in_s = 60 * 60; let three_mins_in_ms = 1000 * 60 * 3; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -694,9 +688,18 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 10, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + ..Default::default() + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -774,9 +777,18 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 10, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + ..Default::default() + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -841,9 +853,18 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 10, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + ..Default::default() + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -903,9 +924,18 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 10, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + ..Default::default() + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -998,9 +1028,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1052,9 +1081,8 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -1133,9 +1161,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1252,9 +1279,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1339,9 +1365,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1443,9 +1468,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1524,9 +1548,8 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -1632,9 +1655,8 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -1740,9 +1762,8 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -1866,9 +1887,8 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -1991,9 +2011,8 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2105,9 +2124,8 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2219,9 +2237,8 @@ mod tests { let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2348,9 +2365,8 @@ mod tests { let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2493,9 +2509,8 @@ mod tests { let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2562,9 +2577,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -2642,9 +2656,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -2727,9 +2740,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -2824,9 +2836,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -3387,9 +3398,18 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 3, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + ..Default::default() + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 1, @@ -3552,9 +3572,18 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 3, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + ..Default::default() + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 1, @@ -3688,9 +3717,18 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 3, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + ..Default::default() + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 1, @@ -3814,9 +3852,18 @@ mod tests { }; let day_in_ms = 1000 * 60 * 60 * 24; let config = PlatformConfig { - validator_set_quorum_size: 3, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + ..Default::default() + }, + chain_lock: ChainLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 1, @@ -3958,9 +4005,8 @@ mod tests { }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -4014,9 +4060,8 @@ mod tests { ..Default::default() }; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, diff --git a/packages/rs-drive-abci/tests/strategy_tests/query.rs b/packages/rs-drive-abci/tests/strategy_tests/query.rs index c8825c7dfef..e0ba52316c4 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/query.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/query.rs @@ -306,7 +306,9 @@ mod tests { use dpp::block::extended_epoch_info::v0::ExtendedEpochInfoV0Getters; use dpp::version::PlatformVersion; - use drive_abci::config::{ExecutionConfig, PlatformConfig, PlatformTestConfig}; + use drive_abci::config::{ + ChainLockConfig, ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig, + }; use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods; use drive_abci::test::helpers::setup::TestPlatformBuilder; @@ -369,9 +371,8 @@ mod tests { }; let hour_in_ms = 1000 * 60 * 60; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -467,9 +468,8 @@ mod tests { }; let hour_in_ms = 1000 * 60 * 60; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -566,9 +566,8 @@ mod tests { }; let hour_in_ms = 1000 * 60 * 60; let config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, diff --git a/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs index 7b588734515..a707f407cc7 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs @@ -13,7 +13,9 @@ mod tests { ChainExecutionOutcome, ChainExecutionParameters, CoreHeightIncrease, MasternodeListChangesStrategy, NetworkStrategy, StrategyRandomness, UpgradingInfo, }; - use drive_abci::config::{ExecutionConfig, PlatformConfig, PlatformTestConfig}; + use drive_abci::config::{ + ChainLockConfig, ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig, + }; use drive_abci::mimic::MimicExecuteBlockOptions; use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods; use drive_abci::test::helpers::setup::TestPlatformBuilder; @@ -64,9 +66,8 @@ mod tests { }; let twenty_minutes_in_ms = 1000 * 60 * 20; let mut config = PlatformConfig { - validator_set_quorum_size: 100, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 125, @@ -307,9 +308,11 @@ mod tests { let one_hour_in_s = 60 * 60; let thirty_seconds_in_ms = 1000 * 30; let config = PlatformConfig { - validator_set_quorum_size: 30, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_size: 30, + ..Default::default() + }, + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 30, @@ -544,7 +547,10 @@ mod tests { let epoch_time_length_s = 60; let config = PlatformConfig { - validator_set_quorum_size: 30, + validator_set: ValidatorSetConfig { + quorum_size: 30, + ..Default::default() + }, execution: ExecutionConfig { epoch_time_length_s, ..Default::default() @@ -701,9 +707,11 @@ mod tests { }; let hour_in_ms = 1000 * 60 * 60; let config = PlatformConfig { - validator_set_quorum_size: 40, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_size: 40, + ..Default::default() + }, + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 80, @@ -934,9 +942,11 @@ mod tests { }; let hour_in_ms = 1000 * 60 * 60; let mut config = PlatformConfig { - validator_set_quorum_size: 50, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_size: 50, + ..Default::default() + }, + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 50, @@ -1263,9 +1273,11 @@ mod tests { }; let hour_in_ms = 1000 * 60 * 60; let config = PlatformConfig { - validator_set_quorum_size: 50, - validator_set_quorum_type: "llmq_100_67".to_string(), - chain_lock_quorum_type: "llmq_100_67".to_string(), + validator_set: ValidatorSetConfig { + quorum_size: 50, + ..Default::default() + }, + chain_lock: ChainLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 30, From 6289886a64d53fe94ebb02645cf88afdf5afb1cb Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 5 Jun 2024 19:17:44 +0700 Subject: [PATCH 03/48] feat: verify recent instant lock signatures locally --- packages/rs-drive-abci/src/config.rs | 6 +- .../src/execution/check_tx/v0/mod.rs | 257 ++++++++++-------- .../platform_events/core_instant_lock/mod.rs | 2 + .../verify_recent_signature_locally/mod.rs | 47 ++++ .../verify_recent_signature_locally/v0/mod.rs | 67 +++++ .../src/execution/platform_events/mod.rs | 3 + .../asset_lock/proof/validate/instant/mod.rs | 25 +- .../state_transitions/identity_create/mod.rs | 81 ++++-- .../state_transitions/identity_top_up/mod.rs | 17 +- .../tests/strategy_tests/execution.rs | 9 +- .../src/version/drive_abci_versions.rs | 6 + .../src/version/mocks/v2_test.rs | 9 +- .../src/version/mocks/v3_test.rs | 9 +- .../rs-platform-version/src/version/v1.rs | 9 +- 14 files changed, 383 insertions(+), 164 deletions(-) create mode 100644 packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/mod.rs create mode 100644 packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/mod.rs create mode 100644 packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs diff --git a/packages/rs-drive-abci/src/config.rs b/packages/rs-drive-abci/src/config.rs index 81e14b3b8b4..e523cd75581 100644 --- a/packages/rs-drive-abci/src/config.rs +++ b/packages/rs-drive-abci/src/config.rs @@ -718,12 +718,14 @@ impl PlatformConfig { } /// Configs that should only happen during testing -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug)] pub struct PlatformTestConfig { /// Block signing pub block_signing: bool, /// Block signature verification pub block_commit_signature_verification: bool, + /// Disable instant lock signature verification + pub disable_instant_lock_signature_verification: bool, } impl PlatformTestConfig { @@ -732,6 +734,7 @@ impl PlatformTestConfig { Self { block_signing: false, block_commit_signature_verification: false, + disable_instant_lock_signature_verification: false, } } } @@ -741,6 +744,7 @@ impl Default for PlatformTestConfig { Self { block_signing: true, block_commit_signature_verification: true, + disable_instant_lock_signature_verification: false, } } } diff --git a/packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs b/packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs index e6fa1e13e84..155cced9dad 100644 --- a/packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs @@ -205,7 +205,7 @@ where #[cfg(test)] mod tests { - use crate::config::PlatformConfig; + use crate::config::{PlatformConfig, PlatformTestConfig}; use crate::platform_types::event_execution_result::EventExecutionResult::{ SuccessfulPaidExecution, UnpaidConsensusExecutionError, UnsuccessfulPaidExecution, }; @@ -276,14 +276,17 @@ mod tests { #[test] #[ignore] fn verify_check_tx_on_data_contract_create() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let protocol_version = platform_state.current_protocol_version_in_consensus(); @@ -370,14 +373,17 @@ mod tests { #[test] fn data_contract_create_check_tx() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let protocol_version = platform_state.current_protocol_version_in_consensus(); @@ -501,14 +507,17 @@ mod tests { #[test] fn data_contract_create_check_tx_for_invalid_contract() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let protocol_version = platform_state.current_protocol_version_in_consensus(); @@ -693,14 +702,17 @@ mod tests { #[test] fn data_contract_create_check_tx_priority() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let protocol_version = platform_state.current_protocol_version_in_consensus(); @@ -838,14 +850,17 @@ mod tests { #[test] fn data_contract_create_check_tx_after_identity_balance_used_up() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let protocol_version = platform_state.current_protocol_version_in_consensus(); @@ -962,14 +977,17 @@ mod tests { #[test] fn data_contract_update_check_tx() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let protocol_version = platform_state.current_protocol_version_in_consensus(); @@ -1158,14 +1176,17 @@ mod tests { #[test] fn data_contract_update_check_tx_for_invalid_update() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let protocol_version = platform_state.current_protocol_version_in_consensus(); @@ -1389,16 +1410,19 @@ mod tests { #[test] fn document_update_check_tx() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; + + let platform = TestPlatformBuilder::new() + .with_config(platform_config) .build_with_mock_rpc() .set_genesis_state(); - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); - let platform_state = platform.state.load(); let platform_version = platform_state.current_platform_version().unwrap(); @@ -1577,14 +1601,17 @@ mod tests { #[test] fn identity_top_up_check_tx() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let platform_version = platform_state.current_platform_version().unwrap(); @@ -1716,14 +1743,17 @@ mod tests { #[test] fn identity_cant_double_top_up() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let platform_version = platform_state.current_platform_version().unwrap(); @@ -1887,14 +1917,17 @@ mod tests { #[test] fn identity_top_up_with_unknown_identity_doesnt_panic() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let platform_version = platform_state.current_platform_version().unwrap(); @@ -1981,14 +2014,17 @@ mod tests { #[test] fn identity_cant_create_with_used_outpoint() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let platform_version = platform_state.current_platform_version().unwrap(); @@ -2199,14 +2235,17 @@ mod tests { #[test] fn identity_can_create_with_semi_used_outpoint() { - let mut platform = TestPlatformBuilder::new() - .with_config(PlatformConfig::default()) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let platform_version = platform_state.current_platform_version().unwrap(); @@ -2513,14 +2552,17 @@ mod tests { config.abci.keys.dpns_second_public_key = high_public_key.serialize().to_vec(); - let mut platform = TestPlatformBuilder::new() - .with_config(config) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let platform_version = platform_state.current_platform_version().unwrap(); @@ -2627,14 +2669,17 @@ mod tests { config.abci.keys.dashpay_second_public_key = high_public_key.serialize().to_vec(); - let mut platform = TestPlatformBuilder::new() - .with_config(config) - .build_with_mock_rpc(); + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); + let platform = TestPlatformBuilder::new() + .with_config(platform_config) + .build_with_mock_rpc(); let platform_state = platform.state.load(); let platform_version = platform_state.current_platform_version().unwrap(); diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/mod.rs new file mode 100644 index 00000000000..87db2f8862d --- /dev/null +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/mod.rs @@ -0,0 +1,2 @@ +/// Instant Lock recent signature verification +pub mod verify_recent_signature_locally; diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/mod.rs new file mode 100644 index 00000000000..c0116febcdc --- /dev/null +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/mod.rs @@ -0,0 +1,47 @@ +mod v0; + +use crate::error::execution::ExecutionError; +use crate::error::Error; +use dpp::dashcore::InstantLock; + +use crate::platform_types::platform_state::PlatformState; +use dpp::version::PlatformVersion; + +/// Traits implements a method for signature verification using platform execution state +pub trait VerifyInstantLockSignature { + fn verify_recent_signature_locally( + &self, + platform_state: &PlatformState, + platform_version: &PlatformVersion, + ) -> Result; +} + +impl VerifyInstantLockSignature for InstantLock { + /// Verify instant lock signature with limited quorum set what we store in Platform state + /// + /// This is a limited verification and will work properly only for recently signed instant locks. + /// Even valid instant locks that was signed some time ago will be considered invalid due to limited + /// quorum information in the platform state. In turn, this verification doesn't use Core RPC or any other + /// IO. This is done to prevent DoS attacks on slow verify instant lock signature Core RPC method. + /// In case of failed signature verification (or any knowing the fact that signing quorum is old), + /// we expect clients to use ChainAssetLockProof. + fn verify_recent_signature_locally( + &self, + platform_state: &PlatformState, + platform_version: &PlatformVersion, + ) -> Result { + match platform_version + .drive_abci + .methods + .core_instant_lock + .verify_recent_signature_locally + { + 0 => v0::verify_recent_instant_lock_signature_locally_v0(self, platform_state), + version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { + method: "InstantLock.verify_recent_signature_locally".to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs new file mode 100644 index 00000000000..13ab09b1aec --- /dev/null +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs @@ -0,0 +1,67 @@ +use dpp::bls_signatures::G2Element; + +use dpp::dashcore::hashes::{sha256d, Hash, HashEngine}; +use dpp::dashcore::InstantLock; + +use crate::error::Error; + +use crate::error::serialization::SerializationError; +use crate::platform_types::core_quorum_set::CoreQuorumSetV0Methods; +use crate::platform_types::platform_state::v0::PlatformStateV0Methods; +use crate::platform_types::platform_state::PlatformState; + +const SIGN_OFFSET: u32 = 8; + +#[inline(always)] +pub(super) fn verify_recent_instant_lock_signature_locally_v0( + instant_lock: &InstantLock, + platform_state: &PlatformState, +) -> Result { + // First verify that the signature conforms to a signature + let signature = G2Element::from_bytes(instant_lock.signature.as_bytes())?; + + let instant_lock_height = platform_state.last_committed_core_height(); + + let verification_height = instant_lock_height.saturating_sub(SIGN_OFFSET); + + let request_id = instant_lock.request_id().map_err(|e| { + Error::Serialization(SerializationError::CorruptedSerialization(format!( + "can't hash instant lock request ID for signature verification: {e}" + ))) + })?; + + let quorum_set = platform_state.instant_lock_validating_quorums(); + + // Based on the deterministic masternode list at the given height, a quorum must be selected + // that was active at the time this block was mined + let selected_quorums = + quorum_set.select_quorums(instant_lock_height, verification_height, request_id); + + for (reversed_quorum_hash, public_key) in selected_quorums { + // The signature must verify against the quorum public key and SHA256(llmqType, quorumHash, SHA256(height), txId). + // llmqType and quorumHash must be taken from the quorum selected in 1. + let mut engine = sha256d::Hash::engine(); + + engine.input(&[quorum_set.config().quorum_type as u8]); + engine.input(reversed_quorum_hash.as_slice()); + engine.input(request_id.as_byte_array()); + engine.input(instant_lock.txid.as_byte_array()); + + let message_digest = sha256d::Hash::from_engine(engine); + + if public_key.verify(&signature, message_digest.as_ref()) { + return Ok(true); + } + } + + tracing::debug!( + ?instant_lock, + instant_lock_height, + verification_height, + "Instant Lock {} signature verification failed at height {}", + instant_lock.txid, + instant_lock_height, + ); + + Ok(false) +} diff --git a/packages/rs-drive-abci/src/execution/platform_events/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/mod.rs index 79821827bea..3d875663074 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/mod.rs @@ -26,3 +26,6 @@ pub(in crate::execution) mod block_start; /// Verify the chain lock pub(in crate::execution) mod core_chain_lock; + +/// Instant lock methods +pub(in crate::execution) mod core_instant_lock; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs index e9fb84b8f8d..79d4aacaa18 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs @@ -1,7 +1,6 @@ use crate::error::Error; use crate::platform_types::platform::PlatformRef; use crate::rpc::core::CoreRPCLike; -use crate::rpc::signature::CoreSignatureVerification; use dpp::asset_lock::reduced_asset_lock_value::AssetLockValue; use dpp::consensus::basic::identity::InvalidInstantAssetLockProofSignatureError; use dpp::fee::Credits; @@ -11,10 +10,10 @@ use dpp::state_transition::signable_bytes_hasher::SignableBytesHasher; use dpp::validation::ConsensusValidationResult; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; +use crate::execution::platform_events::core_instant_lock::verify_recent_signature_locally::VerifyInstantLockSignature; use crate::execution::validation::state_transition::common::asset_lock::proof::validate::AssetLockProofValidation; use crate::execution::validation::state_transition::common::asset_lock::proof::verify_is_not_spent::AssetLockProofVerifyIsNotSpent; use crate::execution::validation::state_transition::ValidationMode; -use crate::platform_types::platform_state::v0::PlatformStateV0Methods; // TODO: Versioning impl AssetLockProofValidation for InstantAssetLockProof { @@ -45,10 +44,24 @@ impl AssetLockProofValidation for InstantAssetLockProof { // As we know this outpoint was already considered final and locked. if validation_mode != ValidationMode::RecheckTx && !validation_result.has_data() { - let is_instant_lock_signature_valid = self.instant_lock().verify_signature( - platform_ref.core_rpc, - platform_ref.state.last_committed_core_height(), - )?; + // We should be able to disable instant lock versification for integration tests + if platform_ref + .config + .testing_configs + .disable_instant_lock_signature_verification + { + return Ok(validation_result); + } + + // This is a limited verification and will work properly only for recently signed instant locks. + // Even valid instant locks that was signed some time ago will be considered invalid due to limited + // quorum information in the platform state. In turn, this verification doesn't use Core RPC or any other + // IO. This is done to prevent DoS attacks on slow verify instant lock signature Core RPC method. + // In case of failed signature verification (or any knowing the fact that signing quorum is old), + // we expect clients to use ChainAssetLockProof. + let is_instant_lock_signature_valid = self + .instant_lock() + .verify_recent_signature_locally(platform_ref.state, platform_version)?; if !is_instant_lock_signature_valid { return Ok(ConsensusValidationResult::new_with_error( diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_create/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_create/mod.rs index f68781b6b13..a7db42dc744 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_create/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_create/mod.rs @@ -193,6 +193,7 @@ impl StateTransitionStateValidationForIdentityCreateTransitionV0 for IdentityCre #[cfg(test)] mod tests { + use crate::config::{PlatformConfig, PlatformTestConfig}; use crate::test::helpers::setup::TestPlatformBuilder; use dpp::block::block_info::BlockInfo; use dpp::dashcore::{Network, PrivateKey}; @@ -215,15 +216,19 @@ mod tests { #[test] fn test_identity_create_validation() { let platform_version = PlatformVersion::latest(); - let mut platform = TestPlatformBuilder::new() + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; + + let platform = TestPlatformBuilder::new() + .with_config(platform_config) .build_with_mock_rpc() .set_initial_state_structure(); - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); - let platform_state = platform.state.load(); let mut signer = SimpleSigner::default(); @@ -322,15 +327,19 @@ mod tests { #[test] fn test_identity_create_asset_lock_reuse_after_issue() { let platform_version = PlatformVersion::latest(); - let mut platform = TestPlatformBuilder::new() + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; + + let platform = TestPlatformBuilder::new() + .with_config(platform_config) .build_with_mock_rpc() .set_initial_state_structure(); - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); - let platform_state = platform.state.load(); let mut signer = SimpleSigner::default(); @@ -536,15 +545,19 @@ mod tests { #[test] fn test_identity_create_asset_lock_reuse_after_max_issues() { let platform_version = PlatformVersion::latest(); - let mut platform = TestPlatformBuilder::new() + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; + + let platform = TestPlatformBuilder::new() + .with_config(platform_config) .build_with_mock_rpc() .set_initial_state_structure(); - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); - let platform_state = platform.state.load(); let mut signer = SimpleSigner::default(); @@ -756,15 +769,19 @@ mod tests { #[test] fn test_identity_create_asset_lock_use_all_funds() { let platform_version = PlatformVersion::latest(); - let mut platform = TestPlatformBuilder::new() + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; + + let platform = TestPlatformBuilder::new() + .with_config(platform_config) .build_with_mock_rpc() .set_initial_state_structure(); - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); - let platform_state = platform.state.load(); let mut signer = SimpleSigner::default(); @@ -977,15 +994,19 @@ mod tests { #[test] fn test_identity_create_asset_lock_replay_attack() { let platform_version = PlatformVersion::latest(); - let mut platform = TestPlatformBuilder::new() + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; + + let platform = TestPlatformBuilder::new() + .with_config(platform_config) .build_with_mock_rpc() .set_initial_state_structure(); - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); - let platform_state = platform.state.load(); let mut signer = SimpleSigner::default(); diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_top_up/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_top_up/mod.rs index 670a1ac80cb..7bfa108e724 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_top_up/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_top_up/mod.rs @@ -100,6 +100,7 @@ impl StateTransitionBasicStructureValidationV0 for IdentityTopUpTransition { #[cfg(test)] mod tests { + use crate::config::{PlatformConfig, PlatformTestConfig}; use crate::test::helpers::setup::TestPlatformBuilder; use dpp::block::block_info::BlockInfo; use dpp::dashcore::{Network, PrivateKey}; @@ -121,15 +122,19 @@ mod tests { #[test] fn test_identity_top_up_validation() { let platform_version = PlatformVersion::latest(); - let mut platform = TestPlatformBuilder::new() + let platform_config = PlatformConfig { + testing_configs: PlatformTestConfig { + disable_instant_lock_signature_verification: true, + ..Default::default() + }, + ..Default::default() + }; + + let platform = TestPlatformBuilder::new() + .with_config(platform_config) .build_with_mock_rpc() .set_initial_state_structure(); - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); - let platform_state = platform.state.load(); let mut signer = SimpleSigner::default(); diff --git a/packages/rs-drive-abci/tests/strategy_tests/execution.rs b/packages/rs-drive-abci/tests/strategy_tests/execution.rs index 07bf3e200cb..fce4bd63fb3 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/execution.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/execution.rs @@ -50,9 +50,11 @@ pub(crate) fn run_chain_for_strategy( platform: &mut Platform, block_count: u64, strategy: NetworkStrategy, - config: PlatformConfig, + mut config: PlatformConfig, seed: u64, ) -> ChainExecutionOutcome { + // TODO: Do we want to sign instant locks or just disable verification? + let validator_quorum_count = strategy.validator_quorum_count; // In most tests 24 quorums let chain_lock_quorum_count = strategy.chain_lock_quorum_count; // In most tests 4 quorums when not the same as validator let validator_set_quorum_size = config.validator_set.quorum_size; @@ -330,11 +332,6 @@ pub(crate) fn run_chain_for_strategy( })) }); - platform - .core_rpc - .expect_verify_instant_lock() - .returning(|_, _| Ok(true)); - platform .core_rpc .expect_get_quorum_listextended() diff --git a/packages/rs-platform-version/src/version/drive_abci_versions.rs b/packages/rs-platform-version/src/version/drive_abci_versions.rs index 2439f050b17..e622ddded9a 100644 --- a/packages/rs-platform-version/src/version/drive_abci_versions.rs +++ b/packages/rs-platform-version/src/version/drive_abci_versions.rs @@ -64,6 +64,7 @@ pub struct DriveAbciMethodVersions { pub block_fee_processing: DriveAbciBlockFeeProcessingMethodVersions, pub core_subsidy: DriveAbciCoreSubsidyMethodVersions, pub core_chain_lock: DriveAbciCoreChainLockMethodVersionsAndConstants, + pub core_instant_lock: DriveAbciCoreInstantLockMethodVersions, pub fee_pool_inwards_distribution: DriveAbciFeePoolInwardsDistributionMethodVersions, pub fee_pool_outwards_distribution: DriveAbciFeePoolOutwardsDistributionMethodVersions, pub withdrawals: DriveAbciIdentityCreditWithdrawalMethodVersions, @@ -231,6 +232,11 @@ pub struct DriveAbciCoreSubsidyMethodVersions { pub epoch_core_reward_credits_for_distribution: FeatureVersion, } +#[derive(Clone, Debug, Default)] +pub struct DriveAbciCoreInstantLockMethodVersions { + pub verify_recent_signature_locally: FeatureVersion, +} + #[derive(Clone, Debug, Default)] pub struct DriveAbciCoreChainLockMethodVersionsAndConstants { pub choose_quorum: FeatureVersion, diff --git a/packages/rs-platform-version/src/version/mocks/v2_test.rs b/packages/rs-platform-version/src/version/mocks/v2_test.rs index d47370d65b7..3ee5e89dfab 100644 --- a/packages/rs-platform-version/src/version/mocks/v2_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v2_test.rs @@ -15,9 +15,9 @@ use crate::version::drive_abci_versions::{ DriveAbciAssetLockValidationVersions, DriveAbciBlockEndMethodVersions, DriveAbciBlockFeeProcessingMethodVersions, DriveAbciBlockStartMethodVersions, DriveAbciCoreBasedUpdatesMethodVersions, DriveAbciCoreChainLockMethodVersionsAndConstants, - DriveAbciCoreSubsidyMethodVersions, DriveAbciDocumentsStateTransitionValidationVersions, - DriveAbciEngineMethodVersions, DriveAbciEpochMethodVersions, - DriveAbciFeePoolInwardsDistributionMethodVersions, + DriveAbciCoreInstantLockMethodVersions, DriveAbciCoreSubsidyMethodVersions, + DriveAbciDocumentsStateTransitionValidationVersions, DriveAbciEngineMethodVersions, + DriveAbciEpochMethodVersions, DriveAbciFeePoolInwardsDistributionMethodVersions, DriveAbciFeePoolOutwardsDistributionMethodVersions, DriveAbciIdentityCreditWithdrawalMethodVersions, DriveAbciInitializationMethodVersions, DriveAbciMasternodeIdentitiesUpdatesMethodVersions, DriveAbciMethodVersions, @@ -555,6 +555,9 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { make_sure_core_is_synced_to_chain_lock: 0, recent_block_count_amount: 2, }, + core_instant_lock: DriveAbciCoreInstantLockMethodVersions { + verify_recent_signature_locally: 0, + }, fee_pool_inwards_distribution: DriveAbciFeePoolInwardsDistributionMethodVersions { add_distribute_block_fees_into_pools_operations: 0, add_distribute_storage_fee_to_epochs_operations: 0, diff --git a/packages/rs-platform-version/src/version/mocks/v3_test.rs b/packages/rs-platform-version/src/version/mocks/v3_test.rs index d603bf780e8..5e4025704fa 100644 --- a/packages/rs-platform-version/src/version/mocks/v3_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v3_test.rs @@ -15,9 +15,9 @@ use crate::version::drive_abci_versions::{ DriveAbciAssetLockValidationVersions, DriveAbciBlockEndMethodVersions, DriveAbciBlockFeeProcessingMethodVersions, DriveAbciBlockStartMethodVersions, DriveAbciCoreBasedUpdatesMethodVersions, DriveAbciCoreChainLockMethodVersionsAndConstants, - DriveAbciCoreSubsidyMethodVersions, DriveAbciDocumentsStateTransitionValidationVersions, - DriveAbciEngineMethodVersions, DriveAbciEpochMethodVersions, - DriveAbciFeePoolInwardsDistributionMethodVersions, + DriveAbciCoreInstantLockMethodVersions, DriveAbciCoreSubsidyMethodVersions, + DriveAbciDocumentsStateTransitionValidationVersions, DriveAbciEngineMethodVersions, + DriveAbciEpochMethodVersions, DriveAbciFeePoolInwardsDistributionMethodVersions, DriveAbciFeePoolOutwardsDistributionMethodVersions, DriveAbciIdentityCreditWithdrawalMethodVersions, DriveAbciInitializationMethodVersions, DriveAbciMasternodeIdentitiesUpdatesMethodVersions, DriveAbciMethodVersions, @@ -555,6 +555,9 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { make_sure_core_is_synced_to_chain_lock: 0, recent_block_count_amount: 2, }, + core_instant_lock: DriveAbciCoreInstantLockMethodVersions { + verify_recent_signature_locally: 0, + }, fee_pool_inwards_distribution: DriveAbciFeePoolInwardsDistributionMethodVersions { add_distribute_block_fees_into_pools_operations: 0, add_distribute_storage_fee_to_epochs_operations: 0, diff --git a/packages/rs-platform-version/src/version/v1.rs b/packages/rs-platform-version/src/version/v1.rs index 268ae2a7c57..ec0f8291f79 100644 --- a/packages/rs-platform-version/src/version/v1.rs +++ b/packages/rs-platform-version/src/version/v1.rs @@ -15,9 +15,9 @@ use crate::version::drive_abci_versions::{ DriveAbciAssetLockValidationVersions, DriveAbciBlockEndMethodVersions, DriveAbciBlockFeeProcessingMethodVersions, DriveAbciBlockStartMethodVersions, DriveAbciCoreBasedUpdatesMethodVersions, DriveAbciCoreChainLockMethodVersionsAndConstants, - DriveAbciCoreSubsidyMethodVersions, DriveAbciDocumentsStateTransitionValidationVersions, - DriveAbciEngineMethodVersions, DriveAbciEpochMethodVersions, - DriveAbciFeePoolInwardsDistributionMethodVersions, + DriveAbciCoreInstantLockMethodVersions, DriveAbciCoreSubsidyMethodVersions, + DriveAbciDocumentsStateTransitionValidationVersions, DriveAbciEngineMethodVersions, + DriveAbciEpochMethodVersions, DriveAbciFeePoolInwardsDistributionMethodVersions, DriveAbciFeePoolOutwardsDistributionMethodVersions, DriveAbciIdentityCreditWithdrawalMethodVersions, DriveAbciInitializationMethodVersions, DriveAbciMasternodeIdentitiesUpdatesMethodVersions, DriveAbciMethodVersions, @@ -554,6 +554,9 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { make_sure_core_is_synced_to_chain_lock: 0, recent_block_count_amount: 2, }, + core_instant_lock: DriveAbciCoreInstantLockMethodVersions { + verify_recent_signature_locally: 0, + }, fee_pool_inwards_distribution: DriveAbciFeePoolInwardsDistributionMethodVersions { add_distribute_block_fees_into_pools_operations: 0, add_distribute_storage_fee_to_epochs_operations: 0, From 10b982f1dae374ebb36d213ff53e9b3978fb3ccd Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 6 Jun 2024 00:16:49 +0700 Subject: [PATCH 04/48] feat: update instant lock quorums --- packages/rs-drive-abci/src/config.rs | 13 + .../update_quorum_info/v0/mod.rs | 307 +++++++++++------- .../rs-drive-abci/src/mimic/test_quorum.rs | 8 + .../core_quorum_set/v0/quorums.rs | 2 +- .../src/platform_types/validator_set/mod.rs | 12 + .../platform_types/validator_set/v0/mod.rs | 22 ++ .../tests/strategy_tests/chain_lock_update.rs | 2 - .../tests/strategy_tests/core_update_tests.rs | 8 +- .../tests/strategy_tests/failures.rs | 7 +- .../tests/strategy_tests/main.rs | 87 ++++- .../tests/strategy_tests/masternodes.rs | 1 + .../tests/strategy_tests/query.rs | 6 +- .../strategy_tests/upgrade_fork_tests.rs | 8 +- 13 files changed, 362 insertions(+), 121 deletions(-) diff --git a/packages/rs-drive-abci/src/config.rs b/packages/rs-drive-abci/src/config.rs index e523cd75581..fed79b3387b 100644 --- a/packages/rs-drive-abci/src/config.rs +++ b/packages/rs-drive-abci/src/config.rs @@ -470,6 +470,19 @@ impl Default for InstantLockConfig { } } +impl InstantLockConfig { + /// Creates a default config for LLMQ 100 67 + pub fn default_100_67() -> Self { + Self { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 100, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + } + } +} + impl QuorumLikeConfig for InstantLockConfig { fn quorum_type(&self) -> QuorumType { self.quorum_type diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index cdc1d851566..3401e6b1b7f 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -3,13 +3,16 @@ use crate::error::Error; use crate::platform_types::platform::Platform; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; +use dashcore_rpc::json::{ExtendedQuorumListResult, QuorumType}; use std::collections::BTreeMap; -use crate::platform_types::validator_set::v0::{ValidatorSetV0, ValidatorSetV0Getters}; +use crate::platform_types::validator_set::v0::{ + ValidatorSetV0, ValidatorSetV0Getters, ValidatorSetV0Setters, +}; use crate::platform_types::validator_set::ValidatorSet; use crate::rpc::core::CoreRPCLike; -use crate::platform_types::core_quorum_set::{CoreQuorumSetV0Methods, Quorum, Quorums}; +use crate::platform_types::core_quorum_set::{CoreQuorumSet, CoreQuorumSetV0Methods, Quorum}; use dpp::bls_signatures::PublicKey as BlsPublicKey; use dpp::dashcore::QuorumHash; use tracing::Level; @@ -65,6 +68,7 @@ where let validator_set_quorum_type = self.config.validator_set.quorum_type; let chain_lock_quorum_type = self.config.chain_lock.quorum_type; + let instant_lock_quorum_type = self.config.instant_lock.quorum_type; let validator_quorums_list: BTreeMap<_, _> = extended_quorum_list .quorums_by_type @@ -81,10 +85,18 @@ where let mut removed_a_validator_set = false; // Remove validator_sets entries that are no longer valid for the core block height + // and update quorum index for existing validator sets block_platform_state .validator_sets_mut() - .retain(|quorum_hash, _| { - let retain = validator_quorums_list.contains_key::(quorum_hash); + .retain(|quorum_hash, validator_set| { + let retain = match validator_quorums_list.get(quorum_hash) { + Some(quorum_details) => { + validator_set.set_quorum_index(quorum_details.quorum_index); + true + } + None => false, + }; + removed_a_validator_set |= !retain; if !retain { @@ -102,7 +114,7 @@ where // Fetch quorum info and their keys from the RPC for new quorums let mut quorum_infos = validator_quorums_list - .iter() + .into_iter() .filter(|(key, _)| { !block_platform_state .validator_sets() @@ -111,11 +123,11 @@ where .map(|(key, _)| { let quorum_info_result = self.core_rpc.get_quorum_info( self.config.validator_set.quorum_type, - key, + &key, None, )?; - Ok((*key, quorum_info_result)) + Ok((key, quorum_info_result)) }) .collect::, Error>>()?; @@ -151,7 +163,7 @@ where }) .collect::, Error>>()?; - let added_a_validator_set = !new_validator_sets.is_empty(); + let is_validator_set_updated = !new_validator_sets.is_empty() || removed_a_validator_set; // Add new validator_sets entries block_platform_state @@ -173,22 +185,77 @@ where } }); + // Update Chain Lock quorums + + // Use already updated validator sets if we use the same quorums if validator_set_quorum_type == chain_lock_quorum_type { - // Remove validator_sets entries that are no longer valid for the core block height - if removed_a_validator_set || added_a_validator_set { + // Update only in case if there are any changes + if is_validator_set_updated { let quorums = block_platform_state .validator_sets() .iter() .map(|(quorum_hash, validator_set)| { - (*quorum_hash, validator_set.threshold_public_key().clone()) + ( + *quorum_hash, + validator_set.threshold_public_key().clone(), + validator_set.quorum_index(), + ) }) .collect(); + let quorum_set = block_platform_state.chain_lock_validating_quorums_mut(); + tracing::trace!("updated chain lock validating quorums to current validator set"); - let quorum_set = block_platform_state.chain_lock_validating_quorums_mut(); + if !start_from_scratch { + // we already have state, so we update last and previous quorums + quorum_set.replace_quorums( + quorums, + last_committed_core_height, + core_block_height, + ); + } else { + // the only case where there will be no platform_state is init chain, + // so there is no previous quorums to update + quorum_set.set_current_quorums(quorums) + } + } + } else { + // Update quorums from the extended quorum list + self.update_quorums_from_quorum_list( + "chain lock", + chain_lock_quorum_type, + block_platform_state.chain_lock_validating_quorums_mut(), + platform_state, + &extended_quorum_list, + last_committed_core_height, + core_block_height, + )?; + } + + // Update Instant Lock quorums + + // Use already updated validator sets if we use the same quorums + if validator_set_quorum_type == instant_lock_quorum_type { + // Update only in case if there are any changes + if is_validator_set_updated { + let quorums = block_platform_state + .validator_sets() + .iter() + .map(|(quorum_hash, validator_set)| { + ( + *quorum_hash, + validator_set.threshold_public_key().clone(), + validator_set.quorum_index(), + ) + }) + .collect(); + + let quorum_set = block_platform_state.instant_lock_validating_quorums_mut(); - if platform_state.is_some() { + tracing::trace!("updated instant lock validating quorums to current validator set"); + + if !start_from_scratch { // we already have state, so we update last and previous quorums quorum_set.replace_quorums( quorums, @@ -202,115 +269,133 @@ where } } } else { - let chain_lock_quorums_list: BTreeMap<_, _> = extended_quorum_list - .quorums_by_type - .remove(&chain_lock_quorum_type) - .ok_or(Error::Execution(ExecutionError::DashCoreBadResponseError( - format!( - "expected quorums of type {}, but did not receive any from Dash Core", - self.config.chain_lock.quorum_type - ), - )))? - .into_iter() - .map(|(quorum_hash, extended_quorum_details)| { - (quorum_hash, extended_quorum_details.quorum_index) - }) - .collect(); - - let mut removed_a_chain_lock_validating_quorum = false; - - // Remove chain_lock_validating_quorums entries that are no longer valid for the core block height - block_platform_state - .chain_lock_validating_quorums_mut() - .current_quorums_mut() - .retain(|quorum_hash, _| { - let retain = chain_lock_quorums_list.contains_key::(quorum_hash); - if !retain { - tracing::trace!( - ?quorum_hash, - quorum_type = ?chain_lock_quorum_type, - "removed old chain lock quorum {} with quorum type {}", - quorum_hash, - chain_lock_quorum_type - ); + // Update quorums from the extended quorum list + self.update_quorums_from_quorum_list( + "instant lock", + instant_lock_quorum_type, + block_platform_state.instant_lock_validating_quorums_mut(), + platform_state, + &extended_quorum_list, + last_committed_core_height, + core_block_height, + )?; + } + + Ok(()) + } + + fn update_quorums_from_quorum_list( + &self, + name: &str, + quorum_type: QuorumType, + quorum_set: &mut CoreQuorumSet, + platform_state: Option<&PlatformState>, + full_quorum_list: &ExtendedQuorumListResult, + last_committed_core_height: u32, + next_core_height: u32, + ) -> Result<(), Error> { + let quorums_list: BTreeMap<_, _> = full_quorum_list + .quorums_by_type + .get(&quorum_type) + .ok_or(Error::Execution(ExecutionError::DashCoreBadResponseError( + format!( + "expected quorums of type {}, but did not receive any from Dash Core", + quorum_type + ), + )))? + .iter() + .map(|(quorum_hash, extended_quorum_details)| { + (quorum_hash, extended_quorum_details.quorum_index) + }) + .collect(); + + let mut removed_a_validating_quorum = false; + + // Remove validating_quorums entries that are no longer valid for the core block height + // and update quorum index for existing validator sets + quorum_set + .current_quorums_mut() + .retain(|quorum_hash, quorum| { + let retain = match quorums_list.get(quorum_hash) { + Some(index) => { + quorum.index = *index; + true } - removed_a_chain_lock_validating_quorum |= !retain; - retain - }); - - // Fetch quorum info and their keys from the RPC for new quorums - let quorum_infos = chain_lock_quorums_list - .iter() - .filter(|(key, _)| { - !block_platform_state - .chain_lock_validating_quorums() - .current_quorums() - .contains_key::(key) - }) - .map(|(key, _)| { - let quorum_info_result = - self.core_rpc - .get_quorum_info(chain_lock_quorum_type, key, None)?; + None => false, + }; - Ok((*key, quorum_info_result)) - }) - .collect::, Error>>()?; + if !retain { + tracing::trace!( + ?quorum_hash, + quorum_type = ?quorum_type, + "removed old {name} quorum {} with quorum type {}", + quorum_hash, + quorum_type + ); + } + removed_a_validating_quorum |= !retain; + retain + }); + + // Fetch quorum info and their keys from the RPC for new quorums + let quorum_infos = quorums_list + .into_iter() + .filter(|(key, _)| !quorum_set.current_quorums().contains_key::(key)) + .map(|(key, _)| { + let quorum_info_result = self.core_rpc.get_quorum_info(quorum_type, key, None)?; + + Ok((*key, quorum_info_result)) + }) + .collect::, Error>>()?; - let added_a_chain_lock_validating_quorum = !quorum_infos.is_empty(); + let added_a_validating_quorum = !quorum_infos.is_empty(); - if added_a_chain_lock_validating_quorum { - // Map to chain lock validating quorums - let new_chain_lock_quorums = quorum_infos - .into_iter() - .map(|(quorum_hash, info_result)| { - let public_key = match BlsPublicKey::from_bytes( - info_result.quorum_public_key.as_slice(), - ) - .map_err(ExecutionError::BlsErrorFromDashCoreResponse) + if added_a_validating_quorum { + // Map to validating quorums + let new_quorums = quorum_infos + .into_iter() + .map(|(quorum_hash, info_result)| { + let public_key = + match BlsPublicKey::from_bytes(info_result.quorum_public_key.as_slice()) + .map_err(ExecutionError::BlsErrorFromDashCoreResponse) { Ok(public_key) => public_key, Err(e) => return Err(e.into()), }; - tracing::trace!( - ?public_key, - ?quorum_hash, - quorum_type = ?chain_lock_quorum_type, - "add new chain lock quorum {} with quorum type {}", - quorum_hash, - chain_lock_quorum_type - ); - - Ok(( - quorum_hash, - Quorum { - public_key, - index: None, - }, - )) - }) - .collect::, Error>>()?; + tracing::trace!( + ?public_key, + ?quorum_hash, + quorum_type = ?quorum_type, + "add new {name} quorum {} with quorum type {}", + quorum_hash, + quorum_type + ); - // Add new validator_sets entries - block_platform_state - .chain_lock_validating_quorums_mut() - .current_quorums_mut() - .extend(new_chain_lock_quorums); - } + let index = if info_result.quorum_index == 0 { + None + } else { + Some(info_result.quorum_index) + }; - if added_a_chain_lock_validating_quorum || removed_a_chain_lock_validating_quorum { - if let Some(old_state) = platform_state { - let previous_chain_lock_validating_quorums = - old_state.chain_lock_validating_quorums().current_quorums(); - - block_platform_state - .chain_lock_validating_quorums_mut() - .update_previous_quorums( - previous_chain_lock_validating_quorums.clone(), - last_committed_core_height, - core_block_height, - ); - } + Ok((quorum_hash, Quorum { public_key, index })) + }) + .collect::, Error>>()?; + + // Add new validator_sets entries + quorum_set.current_quorums_mut().extend(new_quorums); + } + + if added_a_validating_quorum || removed_a_validating_quorum { + if let Some(old_state) = platform_state { + let previous_validating_quorums = + old_state.chain_lock_validating_quorums().current_quorums(); + + quorum_set.update_previous_quorums( + previous_validating_quorums.clone(), + last_committed_core_height, + next_core_height, + ); } } diff --git a/packages/rs-drive-abci/src/mimic/test_quorum.rs b/packages/rs-drive-abci/src/mimic/test_quorum.rs index e32888457bc..c1653183c6d 100644 --- a/packages/rs-drive-abci/src/mimic/test_quorum.rs +++ b/packages/rs-drive-abci/src/mimic/test_quorum.rs @@ -95,6 +95,8 @@ pub struct TestQuorumInfo { pub core_height: u32, /// The hash of the quorum. pub quorum_hash: QuorumHash, + /// The quorum index. Available only for DIP24 rotated quorums. + pub quorum_index: Option, /// The set of validators that belong to the quorum. pub validator_set: Vec, /// A map of validators indexed by their `ProTxHash` identifiers. @@ -129,6 +131,7 @@ impl TestQuorumInfo { pub fn from_quorum_hash_and_pro_tx_hashes( core_height: u32, quorum_hash: QuorumHash, + quorum_index: Option, pro_tx_hashes: Vec, rng: &mut StdRng, ) -> Self { @@ -172,6 +175,7 @@ impl TestQuorumInfo { TestQuorumInfo { core_height, quorum_hash, + quorum_index, validator_set, validator_map: map, private_key: recovered_private_key, @@ -185,6 +189,7 @@ impl From<&TestQuorumInfo> for ValidatorSetV0 { let TestQuorumInfo { core_height, quorum_hash, + quorum_index, validator_set, private_key: _, public_key, @@ -199,6 +204,7 @@ impl From<&TestQuorumInfo> for ValidatorSetV0 { .map(|v| (v.pro_tx_hash, v.into())) .collect(), threshold_public_key: public_key.clone(), + quorum_index: *quorum_index, } } } @@ -208,6 +214,7 @@ impl From for ValidatorSetV0 { let TestQuorumInfo { core_height, quorum_hash, + quorum_index, validator_set, private_key: _, public_key, @@ -216,6 +223,7 @@ impl From for ValidatorSetV0 { ValidatorSetV0 { quorum_hash, + quorum_index, core_height, members: validator_set .iter() diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs index ed6fdc9ccea..424010707ef 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs @@ -147,7 +147,7 @@ impl Quorums { /// Quorum for signature verification #[derive(Debug, Clone)] pub struct Quorum { - /// Index is present only for rotated quorums + /// Index is present only for rotated quorums (DIP24) pub index: Option, /// Quorum threshold public key is used to verify diff --git a/packages/rs-drive-abci/src/platform_types/validator_set/mod.rs b/packages/rs-drive-abci/src/platform_types/validator_set/mod.rs index 70fd7fe1067..5dd9adb1f83 100644 --- a/packages/rs-drive-abci/src/platform_types/validator_set/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/validator_set/mod.rs @@ -26,6 +26,12 @@ impl ValidatorSetV0Getters for ValidatorSet { } } + fn quorum_index(&self) -> Option { + match self { + ValidatorSet::V0(v0) => v0.quorum_index(), + } + } + fn core_height(&self) -> u32 { match self { ValidatorSet::V0(v0) => v0.core_height(), @@ -64,6 +70,12 @@ impl ValidatorSetV0Setters for ValidatorSet { } } + fn set_quorum_index(&mut self, index: Option) { + match self { + ValidatorSet::V0(v0) => v0.set_quorum_index(index), + } + } + fn set_core_height(&mut self, core_height: u32) { match self { ValidatorSet::V0(v0) => v0.set_core_height(core_height), diff --git a/packages/rs-drive-abci/src/platform_types/validator_set/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/validator_set/v0/mod.rs index 3adf9559b02..7574a5d31db 100644 --- a/packages/rs-drive-abci/src/platform_types/validator_set/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/validator_set/v0/mod.rs @@ -21,6 +21,8 @@ use tenderdash_abci::proto::{abci, crypto}; pub struct ValidatorSetV0 { /// The quorum hash pub quorum_hash: QuorumHash, + /// Rotation quorum index is available only for DIP24 quorums + pub quorum_index: Option, /// Active height pub core_height: u32, /// The list of masternodes @@ -297,6 +299,7 @@ impl ValidatorSetV0 { let QuorumInfoResult { height, quorum_hash, + quorum_index, quorum_public_key, members, .. @@ -332,8 +335,15 @@ impl ValidatorSetV0 { let threshold_public_key = BlsPublicKey::from_bytes(quorum_public_key.as_slice()) .map_err(ExecutionError::BlsErrorFromDashCoreResponse)?; + let optional_quorum_index = if quorum_index == 0 { + None + } else { + Some(quorum_index) + }; + Ok(ValidatorSetV0 { quorum_hash, + quorum_index: optional_quorum_index, core_height: height, members: validator_set, threshold_public_key, @@ -345,6 +355,8 @@ impl ValidatorSetV0 { pub trait ValidatorSetV0Getters { /// Returns the quorum hash of the validator set. fn quorum_hash(&self) -> &QuorumHash; + /// Returns rotation quorum index. It's available only for DIP24 quorums + fn quorum_index(&self) -> Option; /// Returns the active height of the validator set. fn core_height(&self) -> u32; /// Returns the members of the validator set. @@ -361,6 +373,8 @@ pub trait ValidatorSetV0Getters { pub trait ValidatorSetV0Setters { /// Sets the quorum hash of the validator set. fn set_quorum_hash(&mut self, quorum_hash: QuorumHash); + /// Sets the quorum index of the validator set. + fn set_quorum_index(&mut self, index: Option); /// Sets the active height of the validator set. fn set_core_height(&mut self, core_height: u32); /// Sets the members of the validator set. @@ -374,6 +388,10 @@ impl ValidatorSetV0Getters for ValidatorSetV0 { &self.quorum_hash } + fn quorum_index(&self) -> Option { + self.quorum_index + } + fn core_height(&self) -> u32 { self.core_height } @@ -400,6 +418,10 @@ impl ValidatorSetV0Setters for ValidatorSetV0 { self.quorum_hash = quorum_hash; } + fn set_quorum_index(&mut self, index: Option) { + self.quorum_index = index; + } + fn set_core_height(&mut self, core_height: u32) { self.core_height = core_height; } diff --git a/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs b/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs index 7d141bfd735..b913335bac0 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs @@ -61,8 +61,6 @@ mod tests { }; let config = PlatformConfig { - validator_set: ValidatorSetConfig::default(), - chain_lock: ChainLockConfig::default(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, diff --git a/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs index 231d1626bd4..5ec8b6b9d29 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs @@ -5,7 +5,8 @@ mod tests { use crate::strategy::CoreHeightIncrease::RandomCoreHeightIncrease; use crate::strategy::{MasternodeListChangesStrategy, NetworkStrategy}; use drive_abci::config::{ - ChainLockConfig, ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig, + ChainLockConfig, ExecutionConfig, InstantLockConfig, PlatformConfig, PlatformTestConfig, + ValidatorSetConfig, }; use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods; use drive_abci::platform_types::validator_set::v0::ValidatorSetV0Getters; @@ -67,7 +68,8 @@ mod tests { quorum_size, ..Default::default() }, - chain_lock: ChainLockConfig::default_100_67(), + + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -168,6 +170,7 @@ mod tests { ..Default::default() }, chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -257,6 +260,7 @@ mod tests { ..Default::default() }, chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, diff --git a/packages/rs-drive-abci/tests/strategy_tests/failures.rs b/packages/rs-drive-abci/tests/strategy_tests/failures.rs index 167bbac8f53..b99c22920d5 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/failures.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/failures.rs @@ -8,7 +8,8 @@ mod tests { use strategy_tests::{IdentityInsertInfo, StartIdentities, Strategy}; use drive_abci::config::{ - ChainLockConfig, ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig, + ChainLockConfig, ExecutionConfig, InstantLockConfig, PlatformConfig, PlatformTestConfig, + ValidatorSetConfig, }; use dpp::dashcore::hashes::Hash; @@ -78,7 +79,8 @@ mod tests { }; let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), - chain_lock: ChainLockConfig::default_100_67(), + + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -153,6 +155,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index 79f2db20208..1f42650f141 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -75,7 +75,7 @@ mod tests { use drive::drive::config::DEFAULT_QUERY_LIMIT; use drive::drive::identity::withdrawals::WithdrawalTransactionIndex; use drive_abci::config::{ - ChainLockConfig, ExecutionConfig, PlatformTestConfig, ValidatorSetConfig, + ChainLockConfig, ExecutionConfig, InstantLockConfig, PlatformTestConfig, ValidatorSetConfig, }; use drive_abci::logging::LogLevel; @@ -117,6 +117,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -161,6 +162,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -205,6 +207,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -336,6 +339,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -468,6 +472,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -529,6 +534,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -577,6 +583,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -633,6 +640,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -700,6 +708,13 @@ mod tests { quorum_active_signers: 24, quorum_rotation: false, }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -789,6 +804,13 @@ mod tests { quorum_active_signers: 24, quorum_rotation: false, }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -865,6 +887,13 @@ mod tests { quorum_active_signers: 24, quorum_rotation: false, }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -936,6 +965,13 @@ mod tests { quorum_active_signers: 24, quorum_rotation: false, }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 10, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1030,6 +1066,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1083,6 +1120,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -1163,6 +1201,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1281,6 +1320,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1367,6 +1407,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1470,6 +1511,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -1550,6 +1592,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -1657,6 +1700,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -1764,6 +1808,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -1889,6 +1934,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2013,6 +2059,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2126,6 +2173,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2239,6 +2287,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2367,6 +2416,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2511,6 +2561,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -2579,6 +2630,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -2658,6 +2710,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -2742,6 +2795,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -2838,6 +2892,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -3410,6 +3465,13 @@ mod tests { quorum_active_signers: 24, quorum_rotation: false, }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 1, @@ -3584,6 +3646,13 @@ mod tests { quorum_active_signers: 24, quorum_rotation: false, }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 1, @@ -3729,6 +3798,13 @@ mod tests { quorum_active_signers: 24, quorum_rotation: false, }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 1, @@ -3864,6 +3940,13 @@ mod tests { quorum_active_signers: 24, quorum_rotation: false, }, + instant_lock: InstantLockConfig { + quorum_type: QuorumType::Llmq100_67, + quorum_size: 3, + quorum_window: 24, + quorum_active_signers: 24, + quorum_rotation: false, + }, execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 1, @@ -4007,6 +4090,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -4062,6 +4146,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, diff --git a/packages/rs-drive-abci/tests/strategy_tests/masternodes.rs b/packages/rs-drive-abci/tests/strategy_tests/masternodes.rs index d240752a265..7dcde2d97af 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/masternodes.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/masternodes.rs @@ -537,6 +537,7 @@ where TestQuorumInfo::from_quorum_hash_and_pro_tx_hashes( index as u32 * 24, quorum_hash, + Some(index as u32 + 1), validator_pro_tx_hashes, rng, ), diff --git a/packages/rs-drive-abci/tests/strategy_tests/query.rs b/packages/rs-drive-abci/tests/strategy_tests/query.rs index e0ba52316c4..e7e4fd7ca9e 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/query.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/query.rs @@ -307,7 +307,8 @@ mod tests { use dpp::version::PlatformVersion; use drive_abci::config::{ - ChainLockConfig, ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig, + ChainLockConfig, ExecutionConfig, InstantLockConfig, PlatformConfig, PlatformTestConfig, + ValidatorSetConfig, }; use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods; @@ -373,6 +374,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -470,6 +472,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, @@ -568,6 +571,7 @@ mod tests { let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 100, diff --git a/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs index a707f407cc7..38fe85fd606 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs @@ -14,7 +14,8 @@ mod tests { MasternodeListChangesStrategy, NetworkStrategy, StrategyRandomness, UpgradingInfo, }; use drive_abci::config::{ - ChainLockConfig, ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig, + ChainLockConfig, ExecutionConfig, InstantLockConfig, PlatformConfig, PlatformTestConfig, + ValidatorSetConfig, }; use drive_abci::mimic::MimicExecuteBlockOptions; use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods; @@ -68,6 +69,7 @@ mod tests { let mut config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 125, @@ -313,6 +315,7 @@ mod tests { ..Default::default() }, chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 30, @@ -712,6 +715,7 @@ mod tests { ..Default::default() }, chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 80, @@ -947,6 +951,7 @@ mod tests { ..Default::default() }, chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 50, @@ -1278,6 +1283,7 @@ mod tests { ..Default::default() }, chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 30, From ec321d348a205cb2023f53e018bf2f4fccf72cee Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 6 Jun 2024 00:44:06 +0700 Subject: [PATCH 05/48] test: mock instant lock verification --- .../asset_lock/proof/validate/instant/mod.rs | 2 + .../tests/strategy_tests/chain_lock_update.rs | 10 +- .../tests/strategy_tests/failures.rs | 8 +- .../tests/strategy_tests/main.rs | 102 +++++++++++++++--- .../strategy_tests/upgrade_fork_tests.rs | 8 +- 5 files changed, 108 insertions(+), 22 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs index 79d4aacaa18..1e3362bd802 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs @@ -53,6 +53,8 @@ impl AssetLockProofValidation for InstantAssetLockProof { return Ok(validation_result); } + // TODO: Shouldn't we add an operation for fees? + // This is a limited verification and will work properly only for recently signed instant locks. // Even valid instant locks that was signed some time ago will be considered invalid due to limited // quorum information in the platform state. In turn, this verification doesn't use Core RPC or any other diff --git a/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs b/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs index b913335bac0..c406e2159d8 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs @@ -5,7 +5,8 @@ mod tests { use crate::strategy::CoreHeightIncrease::RandomCoreHeightIncrease; use crate::strategy::{MasternodeListChangesStrategy, NetworkStrategy}; use drive_abci::config::{ - ChainLockConfig, ExecutionConfig, PlatformConfig, PlatformTestConfig, ValidatorSetConfig, + ChainLockConfig, ExecutionConfig, InstantLockConfig, PlatformConfig, PlatformTestConfig, + ValidatorSetConfig, }; use drive_abci::test::helpers::setup::TestPlatformBuilder; @@ -61,13 +62,18 @@ mod tests { }; let config = PlatformConfig { + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, ..Default::default() }, block_spacing_ms: 3000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let mut platform = TestPlatformBuilder::new() diff --git a/packages/rs-drive-abci/tests/strategy_tests/failures.rs b/packages/rs-drive-abci/tests/strategy_tests/failures.rs index b99c22920d5..addb94cdbf7 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/failures.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/failures.rs @@ -79,7 +79,7 @@ mod tests { }; let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), - + chain_lock: ChainLockConfig::default_100_67(), instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { verify_sum_trees: true, @@ -87,7 +87,11 @@ mod tests { ..Default::default() }, block_spacing_ms: 3000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let mut platform = TestPlatformBuilder::new() diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index 1f42650f141..462e4ef4a04 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -479,7 +479,11 @@ mod tests { ..Default::default() }, block_spacing_ms: 3000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let mut platform = TestPlatformBuilder::new() @@ -1127,7 +1131,11 @@ mod tests { ..Default::default() }, block_spacing_ms: day_in_ms, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; @@ -1208,7 +1216,11 @@ mod tests { ..Default::default() }, block_spacing_ms: 3000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let mut platform = TestPlatformBuilder::new() @@ -1414,7 +1426,11 @@ mod tests { ..Default::default() }, block_spacing_ms: 3000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let mut platform = TestPlatformBuilder::new() @@ -1599,7 +1615,11 @@ mod tests { ..Default::default() }, block_spacing_ms: day_in_ms, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let block_count = 120; @@ -1707,7 +1727,11 @@ mod tests { ..Default::default() }, block_spacing_ms: day_in_ms, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let block_count = 120; @@ -1815,7 +1839,11 @@ mod tests { ..Default::default() }, block_spacing_ms: day_in_ms, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; @@ -1941,7 +1969,11 @@ mod tests { ..Default::default() }, block_spacing_ms: day_in_ms, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; @@ -2295,7 +2327,11 @@ mod tests { ..Default::default() }, block_spacing_ms: day_in_ms, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let block_count = 30; @@ -2424,7 +2460,11 @@ mod tests { ..Default::default() }, block_spacing_ms: day_in_ms, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let block_count = 30; @@ -2569,7 +2609,11 @@ mod tests { ..Default::default() }, block_spacing_ms: day_in_ms, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let block_count = 30; @@ -2717,7 +2761,11 @@ mod tests { ..Default::default() }, block_spacing_ms: 3000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let mut platform = TestPlatformBuilder::new() @@ -2802,7 +2850,11 @@ mod tests { ..Default::default() }, block_spacing_ms: 3000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let mut platform = TestPlatformBuilder::new() @@ -2899,7 +2951,11 @@ mod tests { ..Default::default() }, block_spacing_ms: 3000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; @@ -3811,7 +3867,11 @@ mod tests { ..Default::default() }, block_spacing_ms: day_in_ms, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let mut platform_a = TestPlatformBuilder::new() @@ -4097,7 +4157,11 @@ mod tests { ..Default::default() }, block_spacing_ms: 3000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; @@ -4153,7 +4217,11 @@ mod tests { ..Default::default() }, block_spacing_ms: 3000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; let mut platform = TestPlatformBuilder::new() diff --git a/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs index 38fe85fd606..304f8896f97 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs @@ -554,13 +554,19 @@ mod tests { quorum_size: 30, ..Default::default() }, + chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), execution: ExecutionConfig { epoch_time_length_s, ..Default::default() }, initial_protocol_version: TEST_PROTOCOL_VERSION_4_WITH_1_HPMN_UPGRADE, block_spacing_ms: epoch_time_length_s * 1000, - testing_configs: PlatformTestConfig::default_with_no_block_signing(), + testing_configs: PlatformTestConfig { + block_signing: false, + block_commit_signature_verification: false, + disable_instant_lock_signature_verification: true, + }, ..Default::default() }; From a3423f958910950b63a2fc6da3abfb78136ea99a Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 6 Jun 2024 20:15:48 +0700 Subject: [PATCH 06/48] test: implement instant lock signing --- .../update_quorum_info/v0/mod.rs | 231 ++++++++------- .../verify_chain_lock_locally/v0/mod.rs | 26 +- .../verify_recent_signature_locally/v0/mod.rs | 10 +- .../rs-drive-abci/src/mimic/test_quorum.rs | 7 + .../src/platform_types/core_quorum_set/mod.rs | 13 +- .../core_quorum_set/v0/for_saving.rs | 8 +- .../core_quorum_set/v0/quorum_set.rs | 66 +++-- .../core_quorum_set/v0/quorums.rs | 266 +++++++++++++----- .../tests/strategy_tests/execution.rs | 129 +++++++-- .../tests/strategy_tests/main.rs | 69 +++-- .../tests/strategy_tests/strategy.rs | 155 ++++++++-- .../strategy_tests/upgrade_fork_tests.rs | 104 ++++--- 12 files changed, 745 insertions(+), 339 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index 3401e6b1b7f..28ab6439042 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -5,6 +5,7 @@ use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; use dashcore_rpc::json::{ExtendedQuorumListResult, QuorumType}; use std::collections::BTreeMap; +use std::fmt::Display; use crate::platform_types::validator_set::v0::{ ValidatorSetV0, ValidatorSetV0Getters, ValidatorSetV0Setters, @@ -12,11 +13,36 @@ use crate::platform_types::validator_set::v0::{ use crate::platform_types::validator_set::ValidatorSet; use crate::rpc::core::CoreRPCLike; -use crate::platform_types::core_quorum_set::{CoreQuorumSet, CoreQuorumSetV0Methods, Quorum}; +use crate::platform_types::core_quorum_set::{ + CoreQuorumSet, CoreQuorumSetV0Methods, VerificationQuorum, +}; use dpp::bls_signatures::PublicKey as BlsPublicKey; use dpp::dashcore::QuorumHash; use tracing::Level; +enum QuorumSetType { + ChainLock(QuorumType), + InstantLock(QuorumType), +} + +impl QuorumSetType { + fn quorum_type(&self) -> QuorumType { + match self { + QuorumSetType::ChainLock(quorum_type) => *quorum_type, + QuorumSetType::InstantLock(quorum_type) => *quorum_type, + } + } +} + +impl Display for QuorumSetType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + QuorumSetType::ChainLock(quorum_type) => write!(f, "chain lock ({quorum_type})"), + QuorumSetType::InstantLock(quorum_type) => write!(f, "instant lock ({quorum_type})"), + } + } +} + impl Platform where C: CoreRPCLike, @@ -187,56 +213,42 @@ where // Update Chain Lock quorums - // Use already updated validator sets if we use the same quorums - if validator_set_quorum_type == chain_lock_quorum_type { - // Update only in case if there are any changes - if is_validator_set_updated { - let quorums = block_platform_state - .validator_sets() - .iter() - .map(|(quorum_hash, validator_set)| { - ( - *quorum_hash, - validator_set.threshold_public_key().clone(), - validator_set.quorum_index(), - ) - }) - .collect(); + self.update_quorums( + QuorumSetType::ChainLock(chain_lock_quorum_type), + block_platform_state, + platform_state, + &extended_quorum_list, + is_validator_set_updated, + core_block_height, + )?; - let quorum_set = block_platform_state.chain_lock_validating_quorums_mut(); + // Update Instant Lock quorums - tracing::trace!("updated chain lock validating quorums to current validator set"); + self.update_quorums( + QuorumSetType::InstantLock(instant_lock_quorum_type), + block_platform_state, + platform_state, + &extended_quorum_list, + is_validator_set_updated, + core_block_height, + )?; - if !start_from_scratch { - // we already have state, so we update last and previous quorums - quorum_set.replace_quorums( - quorums, - last_committed_core_height, - core_block_height, - ); - } else { - // the only case where there will be no platform_state is init chain, - // so there is no previous quorums to update - quorum_set.set_current_quorums(quorums) - } - } - } else { - // Update quorums from the extended quorum list - self.update_quorums_from_quorum_list( - "chain lock", - chain_lock_quorum_type, - block_platform_state.chain_lock_validating_quorums_mut(), - platform_state, - &extended_quorum_list, - last_committed_core_height, - core_block_height, - )?; - } + Ok(()) + } - // Update Instant Lock quorums + fn update_quorums( + &self, + quorum_set_type: QuorumSetType, + block_platform_state: &mut PlatformState, + platform_state: Option<&PlatformState>, + extended_quorum_list: &ExtendedQuorumListResult, + is_validator_set_updated: bool, + core_block_height: u32, + ) -> Result<(), Error> { + let last_committed_core_height = block_platform_state.last_committed_core_height(); // Use already updated validator sets if we use the same quorums - if validator_set_quorum_type == instant_lock_quorum_type { + if self.config.validator_set.quorum_type == quorum_set_type.quorum_type() { // Update only in case if there are any changes if is_validator_set_updated { let quorums = block_platform_state @@ -245,17 +257,22 @@ where .map(|(quorum_hash, validator_set)| { ( *quorum_hash, - validator_set.threshold_public_key().clone(), - validator_set.quorum_index(), + VerificationQuorum { + public_key: validator_set.threshold_public_key().clone(), + index: validator_set.quorum_index(), + }, ) }) .collect(); - let quorum_set = block_platform_state.instant_lock_validating_quorums_mut(); + tracing::trace!( + "updated {} validating quorums to current validator set", + quorum_set_type + ); - tracing::trace!("updated instant lock validating quorums to current validator set"); + let quorum_set = quorum_set_by_type_mut(block_platform_state, &quorum_set_type); - if !start_from_scratch { + if platform_state.is_some() { // we already have state, so we update last and previous quorums quorum_set.replace_quorums( quorums, @@ -269,13 +286,14 @@ where } } } else { + let quorum_set = quorum_set_by_type_mut(block_platform_state, &quorum_set_type); + // Update quorums from the extended quorum list self.update_quorums_from_quorum_list( - "instant lock", - instant_lock_quorum_type, - block_platform_state.instant_lock_validating_quorums_mut(), + &quorum_set_type, + quorum_set, platform_state, - &extended_quorum_list, + extended_quorum_list, last_committed_core_height, core_block_height, )?; @@ -286,8 +304,7 @@ where fn update_quorums_from_quorum_list( &self, - name: &str, - quorum_type: QuorumType, + quorum_set_type: &QuorumSetType, quorum_set: &mut CoreQuorumSet, platform_state: Option<&PlatformState>, full_quorum_list: &ExtendedQuorumListResult, @@ -296,11 +313,11 @@ where ) -> Result<(), Error> { let quorums_list: BTreeMap<_, _> = full_quorum_list .quorums_by_type - .get(&quorum_type) + .get(&quorum_set_type.quorum_type()) .ok_or(Error::Execution(ExecutionError::DashCoreBadResponseError( format!( - "expected quorums of type {}, but did not receive any from Dash Core", - quorum_type + "expected quorums {}, but did not receive any from Dash Core", + quorum_set_type ), )))? .iter() @@ -327,10 +344,10 @@ where if !retain { tracing::trace!( ?quorum_hash, - quorum_type = ?quorum_type, - "removed old {name} quorum {} with quorum type {}", + quorum_type = ?quorum_set_type.quorum_type(), + "removed old {} quorum {}", + quorum_set_type, quorum_hash, - quorum_type ); } removed_a_validating_quorum |= !retain; @@ -338,55 +355,53 @@ where }); // Fetch quorum info and their keys from the RPC for new quorums - let quorum_infos = quorums_list + // and then create VerificationQuorum instances + let new_quorums = quorums_list .into_iter() - .filter(|(key, _)| !quorum_set.current_quorums().contains_key::(key)) - .map(|(key, _)| { - let quorum_info_result = self.core_rpc.get_quorum_info(quorum_type, key, None)?; - - Ok((*key, quorum_info_result)) + .filter(|(quorum_hash, _)| { + !quorum_set + .current_quorums() + .contains_key::(quorum_hash) }) - .collect::, Error>>()?; + .map(|(quorum_hash, _)| { + let quorum_info = self.core_rpc.get_quorum_info( + quorum_set_type.quorum_type(), + quorum_hash, + None, + )?; - let added_a_validating_quorum = !quorum_infos.is_empty(); - - if added_a_validating_quorum { - // Map to validating quorums - let new_quorums = quorum_infos - .into_iter() - .map(|(quorum_hash, info_result)| { - let public_key = - match BlsPublicKey::from_bytes(info_result.quorum_public_key.as_slice()) - .map_err(ExecutionError::BlsErrorFromDashCoreResponse) - { - Ok(public_key) => public_key, - Err(e) => return Err(e.into()), - }; + let public_key = + match BlsPublicKey::from_bytes(quorum_info.quorum_public_key.as_slice()) + .map_err(ExecutionError::BlsErrorFromDashCoreResponse) + { + Ok(public_key) => public_key, + Err(e) => return Err(e.into()), + }; - tracing::trace!( - ?public_key, - ?quorum_hash, - quorum_type = ?quorum_type, - "add new {name} quorum {} with quorum type {}", - quorum_hash, - quorum_type - ); + tracing::trace!( + ?public_key, + ?quorum_hash, + quorum_type = ?quorum_set_type.quorum_type(), + "add new {} quorum {}", + quorum_set_type, + quorum_hash, + ); - let index = if info_result.quorum_index == 0 { - None - } else { - Some(info_result.quorum_index) - }; + let index = if quorum_info.quorum_index == 0 { + None + } else { + Some(quorum_info.quorum_index) + }; + + Ok((*quorum_hash, VerificationQuorum { public_key, index })) + }) + .collect::, Error>>()?; - Ok((quorum_hash, Quorum { public_key, index })) - }) - .collect::, Error>>()?; + let are_quorums_updated = !new_quorums.is_empty() || removed_a_validating_quorum; - // Add new validator_sets entries - quorum_set.current_quorums_mut().extend(new_quorums); - } + quorum_set.current_quorums_mut().extend(new_quorums); - if added_a_validating_quorum || removed_a_validating_quorum { + if are_quorums_updated { if let Some(old_state) = platform_state { let previous_validating_quorums = old_state.chain_lock_validating_quorums().current_quorums(); @@ -402,3 +417,13 @@ where Ok(()) } } + +fn quorum_set_by_type_mut<'p>( + block_platform_state: &'p mut PlatformState, + quorum_set_type: &QuorumSetType, +) -> &'p mut CoreQuorumSet { + match quorum_set_type { + QuorumSetType::ChainLock(_) => block_platform_state.chain_lock_validating_quorums_mut(), + QuorumSetType::InstantLock(_) => block_platform_state.instant_lock_validating_quorums_mut(), + } +} diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs index fa068e11faf..3c0b0ae4453 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs @@ -91,7 +91,7 @@ where .chain_lock_validating_quorums() .select_quorums(chain_lock_height, verification_height, request_id); - let Some((quorum_hash, public_key)) = selected_quorums.next() else { + let Some((quorum_hash, quorum)) = selected_quorums.next() else { return Ok(None); }; @@ -99,14 +99,19 @@ where let mut engine = sha256d::Hash::engine(); + let mut reversed_quorum_hash = quorum_hash.to_byte_array().to_vec(); + reversed_quorum_hash.reverse(); + engine.input(&[quorum_config.quorum_type as u8]); - engine.input(quorum_hash.as_slice()); + engine.input(reversed_quorum_hash.as_slice()); engine.input(request_id.as_byte_array()); engine.input(chain_lock.block_hash.as_byte_array()); let message_digest = sha256d::Hash::from_engine(engine); - let mut chain_lock_verified = public_key.verify(&signature, message_digest.as_ref()); + let mut chain_lock_verified = quorum + .public_key + .verify(&signature, message_digest.as_ref()); tracing::debug!( ?chain_lock, @@ -115,7 +120,7 @@ where round, chain_lock.block_height, hex::encode(message_digest.as_byte_array()), - hex::encode(quorum_hash.as_slice()), + hex::encode(reversed_quorum_hash.as_slice()), hex::encode(chain_lock.block_hash.as_byte_array()), if chain_lock_verified { "verified"} else {"not verified"}, platform_state.last_committed_core_height(), @@ -126,7 +131,7 @@ where if !chain_lock_verified { // We should also check the other quorum, as there could be the situation where the core height wasn't updated every block. if selected_quorums.len() == 2 { - let Some((quorum_hash, public_key)) = selected_quorums.next() else { + let Some((quorum_hash, quorum)) = selected_quorums.next() else { // we return that we are not able to verify return Ok(None); }; @@ -135,14 +140,19 @@ where let mut engine = sha256d::Hash::engine(); + let mut reversed_quorum_hash = quorum_hash.to_byte_array().to_vec(); + reversed_quorum_hash.reverse(); + engine.input(&[quorum_config.quorum_type as u8]); - engine.input(quorum_hash.as_slice()); + engine.input(reversed_quorum_hash.as_slice()); engine.input(request_id.as_byte_array()); engine.input(chain_lock.block_hash.as_byte_array()); let message_digest = sha256d::Hash::from_engine(engine); - chain_lock_verified = public_key.verify(&signature, message_digest.as_ref()); + chain_lock_verified = quorum + .public_key + .verify(&signature, message_digest.as_ref()); tracing::debug!( ?chain_lock, @@ -151,7 +161,7 @@ where round, chain_lock.block_height, hex::encode(message_digest.as_byte_array()), - hex::encode(quorum_hash.as_slice()), + hex::encode(reversed_quorum_hash.as_slice()), hex::encode(chain_lock.block_hash.as_byte_array()), if chain_lock_verified { "verified"} else {"not verified"} ); diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs index 13ab09b1aec..7afd3a8c0c8 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs @@ -37,11 +37,14 @@ pub(super) fn verify_recent_instant_lock_signature_locally_v0( let selected_quorums = quorum_set.select_quorums(instant_lock_height, verification_height, request_id); - for (reversed_quorum_hash, public_key) in selected_quorums { + for (quorum_hash, quorum) in selected_quorums { // The signature must verify against the quorum public key and SHA256(llmqType, quorumHash, SHA256(height), txId). // llmqType and quorumHash must be taken from the quorum selected in 1. let mut engine = sha256d::Hash::engine(); + let mut reversed_quorum_hash = quorum_hash.to_byte_array().to_vec(); + reversed_quorum_hash.reverse(); + engine.input(&[quorum_set.config().quorum_type as u8]); engine.input(reversed_quorum_hash.as_slice()); engine.input(request_id.as_byte_array()); @@ -49,7 +52,10 @@ pub(super) fn verify_recent_instant_lock_signature_locally_v0( let message_digest = sha256d::Hash::from_engine(engine); - if public_key.verify(&signature, message_digest.as_ref()) { + if quorum + .public_key + .verify(&signature, message_digest.as_ref()) + { return Ok(true); } } diff --git a/packages/rs-drive-abci/src/mimic/test_quorum.rs b/packages/rs-drive-abci/src/mimic/test_quorum.rs index c1653183c6d..e2a9e6c411e 100644 --- a/packages/rs-drive-abci/src/mimic/test_quorum.rs +++ b/packages/rs-drive-abci/src/mimic/test_quorum.rs @@ -1,3 +1,4 @@ +use crate::platform_types::core_quorum_set::Quorum; use crate::platform_types::validator::v0::ValidatorV0; use crate::platform_types::validator_set::v0::ValidatorSetV0; use dashcore_rpc::dashcore::hashes::Hash; @@ -271,3 +272,9 @@ impl From<&TestQuorumInfo> for QuorumInfoResult { } } } + +impl Quorum for TestQuorumInfo { + fn index(&self) -> Option { + self.quorum_index + } +} diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs index 4355d060c77..cfebe04fac6 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs @@ -6,7 +6,8 @@ pub use crate::platform_types::core_quorum_set::v0::quorum_set::{ CoreQuorumSetV0, CoreQuorumSetV0Methods, QuorumConfig, QuorumsVerificationDataIterator, }; pub use crate::platform_types::core_quorum_set::v0::quorums::{ - Quorum, QuorumVerificationData, Quorums, ReversedQuorumHashBytes, ThresholdBlsPublicKey, + Quorum, Quorums, ReversedQuorumHashBytes, SigningQuorum, ThresholdBlsPublicKey, + VerificationQuorum, }; use bincode::{Decode, Encode}; use derive_more::From; @@ -36,19 +37,19 @@ impl CoreQuorumSetV0Methods for CoreQuorumSet { } } - fn set_current_quorums(&mut self, quorums: Quorums) { + fn set_current_quorums(&mut self, quorums: Quorums) { match self { Self::V0(v0) => v0.set_current_quorums(quorums), } } - fn current_quorums(&self) -> &Quorums { + fn current_quorums(&self) -> &Quorums { match self { Self::V0(v0) => v0.current_quorums(), } } - fn current_quorums_mut(&mut self) -> &mut Quorums { + fn current_quorums_mut(&mut self) -> &mut Quorums { match self { Self::V0(v0) => v0.current_quorums_mut(), } @@ -62,7 +63,7 @@ impl CoreQuorumSetV0Methods for CoreQuorumSet { fn replace_quorums( &mut self, - quorums: Quorums, + quorums: Quorums, last_active_core_height: u32, updated_at_core_height: u32, ) { @@ -75,7 +76,7 @@ impl CoreQuorumSetV0Methods for CoreQuorumSet { fn update_previous_quorums( &mut self, - previous_quorums: Quorums, + previous_quorums: Quorums, last_active_core_height: u32, updated_at_core_height: u32, ) { diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs index dec457e86b8..7a018a01d8d 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs @@ -1,6 +1,6 @@ use crate::platform_types::core_quorum_set::v0::quorum_set::{PreviousQuorumsV0, QuorumConfig}; use crate::platform_types::core_quorum_set::{ - CoreQuorumSetForSaving, CoreQuorumSetV0, Quorum, Quorums, ThresholdBlsPublicKey, + CoreQuorumSetForSaving, CoreQuorumSetV0, Quorums, ThresholdBlsPublicKey, VerificationQuorum, }; use dashcore_rpc::dashcore::hashes::Hash; use dashcore_rpc::dashcore::QuorumHash; @@ -138,12 +138,12 @@ pub struct QuorumForSavingV0 { index: Option, } -impl From> for Quorums { +impl From> for Quorums { fn from(value: Vec) -> Self { Quorums::from_iter(value.into_iter().map(|quorum| { ( QuorumHash::from_byte_array(quorum.hash.to_buffer()), - Quorum { + VerificationQuorum { public_key: quorum.public_key, index: quorum.index, }, @@ -152,7 +152,7 @@ impl From> for Quorums { } } -impl Into> for Quorums { +impl Into> for Quorums { fn into(self) -> Vec { self.into_iter() .map(|(hash, quorum)| QuorumForSavingV0 { diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs index eb8b6e524a9..5a64628e41e 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs @@ -1,13 +1,16 @@ -use crate::config::QuorumLikeConfig; -use crate::platform_types::core_quorum_set::v0::quorums::{QuorumVerificationData, Quorums}; +use crate::config::{ChainLockConfig, QuorumLikeConfig}; +use crate::error::Error; +use crate::platform_types::core_quorum_set::v0::quorums::{Quorum, Quorums}; +use crate::platform_types::core_quorum_set::{ReversedQuorumHashBytes, VerificationQuorum}; +use dashcore_rpc::dashcore::ChainLock; use dashcore_rpc::json::QuorumType; -use dpp::dashcore::QuorumSigningRequestId; +use dpp::dashcore::{QuorumHash, QuorumSigningRequestId}; use std::vec::IntoIter; /// Previously obtained quorums and heights. Required for signature verification #[derive(Debug, Clone)] pub(super) struct PreviousQuorumsV0 { - pub(super) quorums: Quorums, + pub(super) quorums: Quorums, /// The core height at which these quorums were last active pub(super) active_core_height: u32, @@ -26,7 +29,7 @@ pub struct CoreQuorumSetV0 { pub(super) config: QuorumConfig, /// Current quorums - pub(super) current_quorums: Quorums, + pub(super) current_quorums: Quorums, /// The slightly old quorums used for validating ch ain locks (or instant locks), it's important to keep /// these because validation of signatures happens for the quorums that are 8 blocks before the @@ -40,13 +43,13 @@ pub trait CoreQuorumSetV0Methods { fn config(&self) -> &QuorumConfig; /// Set current quorum keys - fn set_current_quorums(&mut self, quorums: Quorums); + fn set_current_quorums(&mut self, quorums: Quorums); /// Current quorum - fn current_quorums(&self) -> &Quorums; + fn current_quorums(&self) -> &Quorums; /// Last quorum keys mutable - fn current_quorums_mut(&mut self) -> &mut Quorums; + fn current_quorums_mut(&mut self) -> &mut Quorums; /// Has previous quorums? fn has_previous_quorums(&self) -> bool; @@ -54,7 +57,7 @@ pub trait CoreQuorumSetV0Methods { /// Set last quorums keys and update previous quorums fn replace_quorums( &mut self, - quorums: Quorums, + quorums: Quorums, last_active_core_height: u32, updated_at_core_height: u32, ); @@ -62,7 +65,7 @@ pub trait CoreQuorumSetV0Methods { /// Update previous quorums fn update_previous_quorums( &mut self, - previous_quorums: Quorums, + previous_quorums: Quorums, last_active_core_height: u32, updated_at_core_height: u32, ); @@ -83,13 +86,13 @@ pub struct QuorumsVerificationDataIterator<'q> { /// Request ID to chose right quorum request_id: QuorumSigningRequestId, /// Appropriate quorum sets - quorum_sets: IntoIter<&'q Quorums>, + quorum_sets: IntoIter<&'q Quorums>, /// Should we expect signature verification to be successful should_be_verifiable: bool, } -impl<'p> Iterator for QuorumsVerificationDataIterator<'p> { - type Item = QuorumVerificationData<'p>; +impl<'q> Iterator for QuorumsVerificationDataIterator<'q> { + type Item = (QuorumHash, &'q VerificationQuorum); fn next(&mut self) -> Option { let quorum_set = self.quorum_sets.next(); @@ -98,17 +101,7 @@ impl<'p> Iterator for QuorumsVerificationDataIterator<'p> { return None; }; - if self.config.rotation { - quorum_set.find_rotating_quorum_verification_data( - self.config.active_signers, - self.request_id.as_ref(), - ) - } else { - quorum_set.find_classic_quorum_verification_data( - self.config.quorum_type, - self.request_id.as_ref(), - ) - } + quorum_set.choose_quorum(&self.config, self.request_id.as_ref()) } } @@ -147,15 +140,15 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { &self.config } - fn set_current_quorums(&mut self, quorums: Quorums) { + fn set_current_quorums(&mut self, quorums: Quorums) { self.current_quorums = quorums; } - fn current_quorums(&self) -> &Quorums { + fn current_quorums(&self) -> &Quorums { &self.current_quorums } - fn current_quorums_mut(&mut self) -> &mut Quorums { + fn current_quorums_mut(&mut self) -> &mut Quorums { &mut self.current_quorums } @@ -165,7 +158,7 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { fn replace_quorums( &mut self, - quorums: Quorums, + quorums: Quorums, last_active_height: u32, updated_at_core_height: u32, ) { @@ -176,7 +169,7 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { fn update_previous_quorums( &mut self, - previous_quorums: Quorums, + previous_quorums: Quorums, last_active_core_height: u32, updated_at_core_height: u32, ) { @@ -269,3 +262,18 @@ impl CoreQuorumSetV0 { } } } + +impl From for CoreQuorumSetV0 { + fn from(value: ChainLockConfig) -> Self { + CoreQuorumSetV0 { + config: QuorumConfig { + quorum_type: value.quorum_type, + active_signers: value.quorum_active_signers, + rotation: value.quorum_rotation, + window: value.quorum_window, + }, + current_quorums: Quorums::default(), + previous: None, + } + } +} diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs index 424010707ef..75cbf45b11d 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs @@ -1,7 +1,10 @@ -use dashcore_rpc::dashcore::hashes::Hash; use dashcore_rpc::json::QuorumType; use derive_more::{Deref, DerefMut, From}; -use dpp::dashcore::QuorumHash; +use dpp::bls_signatures::PrivateKey; +use dpp::dashcore::bls_sig_utils::BLSSignature; +use dpp::dashcore::consensus::Encodable; +use dpp::dashcore::{QuorumHash, QuorumSigningRequestId, Transaction, TxIn, Txid, VarInt}; +use dpp::{bls_signatures, ProtocolError}; use std::collections::BTreeMap; use std::convert::TryInto; @@ -10,79 +13,59 @@ pub use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; /// Reversed quorum hash bytes. Used for signature verification as part of the signature payload pub type ReversedQuorumHashBytes = Vec; -/// Quorum verification data for signature verification -pub type QuorumVerificationData<'p> = (ReversedQuorumHashBytes, &'p ThresholdBlsPublicKey); - -use dpp::dashcore::hashes::{sha256d, HashEngine}; - -type QuorumsInnerV0 = BTreeMap; +use crate::error::execution::ExecutionError; +use crate::error::Error; +use crate::platform_types::core_quorum_set::QuorumConfig; +use dpp::dashcore::hashes::{sha256d, Hash, HashEngine}; /// Quorum per hash -#[derive(Debug, Clone, Deref, DerefMut, From, Default)] -pub struct Quorums(QuorumsInnerV0); - -impl FromIterator<(QuorumHash, ThresholdBlsPublicKey)> for Quorums { - fn from_iter>(iter: T) -> Self { - let mut quorums = Quorums::default(); - - for (hash, public_key) in iter { - quorums.0.insert( - hash, - Quorum { - index: None, - public_key, - }, - ); - } - - quorums - } -} +#[derive(Debug, Clone, Deref, DerefMut, From)] +pub struct Quorums(BTreeMap); -impl FromIterator<(QuorumHash, ThresholdBlsPublicKey, Option)> for Quorums { - fn from_iter)>>( - iter: T, - ) -> Self { - let mut quorums = Quorums::default(); - - for (hash, public_key, index) in iter { - quorums.0.insert(hash, Quorum { index, public_key }); - } - - quorums +impl Default for Quorums { + fn default() -> Self { + Quorums::(BTreeMap::new()) } } -impl FromIterator<(QuorumHash, Quorum)> for Quorums { - fn from_iter>(iter: T) -> Self { - let mut quorums = Quorums::default(); - - for (hash, quorum) in iter { - quorums.0.insert(hash, quorum); - } - - quorums +impl FromIterator<(QuorumHash, Q)> for Quorums { + fn from_iter>(iter: T) -> Self { + Quorums::(BTreeMap::from_iter(iter)) } } -impl IntoIterator for Quorums { - type Item = (QuorumHash, Quorum); - type IntoIter = std::collections::btree_map::IntoIter; +impl IntoIterator for Quorums { + type Item = (QuorumHash, Q); + type IntoIter = std::collections::btree_map::IntoIter; fn into_iter(self) -> Self::IntoIter { self.0.into_iter() } } -impl Quorums { - pub(super) fn find_classic_quorum_verification_data( +impl Quorums { + /// Choose pseudorandom DIP8 or DIP24 quorum based on quorum config + /// and request_id + pub fn choose_quorum( &self, - quorum_type: QuorumType, + quorum_config: &QuorumConfig, request_id: &[u8; 32], - ) -> Option { + ) -> Option<(QuorumHash, &Q)> { + if quorum_config.rotation { + self.choose_rotating_quorum(quorum_config, request_id) + } else { + self.choose_classic_quorum(quorum_config, request_id) + } + } + + /// Based on DIP8 deterministically chooses a pseudorandom quorum from the list of quorums + fn choose_classic_quorum( + &self, + quorum_config: &QuorumConfig, + request_id: &[u8; 32], + ) -> Option<(QuorumHash, &Q)> { // Scoring system logic - let mut scores: Vec<(ReversedQuorumHashBytes, &ThresholdBlsPublicKey, [u8; 32])> = - Vec::new(); + let mut scores: Vec<(&QuorumHash, &Q, [u8; 32])> = Vec::new(); for (quorum_hash, quorum) in self.0.iter() { let mut quorum_hash_bytes = quorum_hash.to_byte_array().to_vec(); @@ -93,7 +76,7 @@ impl Quorums { let mut hasher = sha256d::Hash::engine(); // Serialize and hash the LLMQ type - hasher.input(&[quorum_type as u8]); + hasher.input(&[quorum_config.quorum_type as u8]); // Serialize and add the quorum hash hasher.input(quorum_hash_bytes.as_slice()); @@ -103,7 +86,7 @@ impl Quorums { // Finalize the hash let hash_result = sha256d::Hash::from_engine(hasher); - scores.push((quorum_hash_bytes, &quorum.public_key, hash_result.into())); + scores.push((quorum_hash, quorum, hash_result.into())); } if scores.is_empty() { @@ -112,17 +95,18 @@ impl Quorums { scores.sort_by_key(|k| k.2); - let (quorum_reversed_hash, public_key, _) = scores.remove(0); + let (quorum_hash, quorum, _) = scores.remove(0); - Some((quorum_reversed_hash, public_key)) + Some((*quorum_hash, quorum)) } - pub(super) fn find_rotating_quorum_verification_data( + /// Based on DIP24 deterministically chooses a pseudorandom quorum from the list of quorums + fn choose_rotating_quorum( &self, - quorums_signing_active_count: u16, + quorum_config: &QuorumConfig, request_id: &[u8; 32], - ) -> Option { - let n = quorums_signing_active_count as u64; + ) -> Option<(QuorumHash, &Q)> { + let n = quorum_config.active_signers as u64; let b = u64::from_le_bytes(request_id[24..32].try_into().unwrap()); @@ -132,21 +116,20 @@ impl Quorums { self.0 .iter() - .find(|(_, quorum)| quorum.index == Some(signer as u32)) - .map(|(hash, quorum)| { - let mut quorum_reversed_hash = hash.to_byte_array().to_vec(); - - // Only the quorum hash needs reversal. - quorum_reversed_hash.reverse(); - - (quorum_reversed_hash, &quorum.public_key) - }) + .find(|(hash, quorum)| quorum.index() == Some(signer as u32)) + .map(|(hash, quorum)| (*hash, quorum)) } } +/// Quorum trait for Quorums collection +pub trait Quorum { + /// Index is present only for rotated quorums (DIP24) + fn index(&self) -> Option; +} + /// Quorum for signature verification #[derive(Debug, Clone)] -pub struct Quorum { +pub struct VerificationQuorum { /// Index is present only for rotated quorums (DIP24) pub index: Option, @@ -154,3 +137,136 @@ pub struct Quorum { /// signatures produced by corresponding quorum pub public_key: ThresholdBlsPublicKey, } + +impl Quorum for VerificationQuorum { + fn index(&self) -> Option { + self.index + } +} + +/// Quorum for signature verification +#[derive(Debug, Clone)] +pub struct SigningQuorum { + /// Index is present only for rotated quorums (DIP24) + pub index: Option, + + /// Quorum private key for signing + pub private_key: [u8; 32], +} + +impl Quorum for SigningQuorum { + fn index(&self) -> Option { + self.index + } +} + +impl SigningQuorum { + /// Signs a transition for instant lock + pub fn sign_for_instant_lock( + &self, + quorum_config: &QuorumConfig, + quorum_hash: &QuorumHash, + request_id: &[u8; 32], + transaction_id: &Txid, + ) -> Result { + // The signature must verify against the quorum public key and SHA256(llmqType, quorumHash, SHA256(height), txId). + // llmqType and quorumHash must be taken from the quorum selected in 1. + let mut engine = sha256d::Hash::engine(); + + let mut reversed_quorum_hash = quorum_hash.to_byte_array().to_vec(); + reversed_quorum_hash.reverse(); + + engine.input(&[quorum_config.quorum_type as u8]); + engine.input(reversed_quorum_hash.as_slice()); + engine.input(request_id); + engine.input(transaction_id.as_byte_array()); + + let message_digest = sha256d::Hash::from_engine(engine); + + let private_key = + PrivateKey::from_bytes(&self.private_key, false).map_err(Error::BLSError)?; + + let g2element = private_key.sign(message_digest.as_ref()); + let g2element_bytes = *g2element.to_bytes(); + + Ok(BLSSignature::from(g2element_bytes)) + } +} + +// +// const IS_LOCK_REQUEST_ID_PREFIX: &str = "islock"; +// +// // TODO: Must be in dashcore lib +// +// pub struct InstantLockQuorumSigner { +// quorum_hash: QuorumHash, +// quorum_type: QuorumType, +// quorum_private_key: PrivateKey, +// } +// +// impl InstantLockQuorumSigner { +// pub fn new( +// quorum_hash: QuorumHash, +// quorum_type: QuorumType, +// quorum_private_key: PrivateKey, +// ) -> Self { +// Self { +// quorum_hash, +// quorum_type, +// quorum_private_key, +// } +// } +// +// pub fn sign( +// &self, +// request_id: &QuorumSigningRequestId, +// transaction: &Transaction, +// ) -> Result { +// // The signature must verify against the quorum public key and SHA256(llmqType, quorumHash, SHA256(height), txId). +// // llmqType and quorumHash must be taken from the quorum selected in 1. +// let mut engine = sha256d::Hash::engine(); +// +// let mut reversed_quorum_hash = self.quorum_hash.to_byte_array().to_vec(); +// reversed_quorum_hash.reverse(); +// +// engine.input(&[self.quorum_type as u8]); +// engine.input(reversed_quorum_hash.as_slice()); +// engine.input(request_id.as_byte_array()); +// engine.input(transaction.txid().as_byte_array()); +// +// let message_digest = sha256d::Hash::from_engine(engine); +// +// let g2element = self.quorum_private_key.sign(message_digest.as_ref()); +// let g2element_bytes = *g2element.to_bytes(); +// +// Ok(BLSSignature::from(g2element_bytes)) +// } +// } +// +// fn request_id_for_tx(tx: &Transaction) -> Result { +// let mut engine = QuorumSigningRequestId::engine(); +// +// // Prefix +// let prefix_len = VarInt(IS_LOCK_REQUEST_ID_PREFIX.len() as u64); +// prefix_len.consensus_encode(&mut engine).map_err(|e| { +// ProtocolError::CorruptedSerialization(format!("can't serialize varInt for request_id: {e}")) +// })?; +// +// engine.input(IS_LOCK_REQUEST_ID_PREFIX.as_bytes()); +// +// // Inputs +// let inputs_len = VarInt(tx.input.len() as u64); +// inputs_len.consensus_encode(&mut engine).map_err(|e| { +// ProtocolError::CorruptedSerialization(format!("can't serialize varInt for request_id: {e}")) +// })?; +// +// for TxIn { +// previous_output, .. +// } in &tx.input +// { +// engine.input(&previous_output.txid[..]); +// engine.input(&previous_output.vout.to_le_bytes()); +// } +// +// Ok(QuorumSigningRequestId::from_engine(engine)) +// } diff --git a/packages/rs-drive-abci/tests/strategy_tests/execution.rs b/packages/rs-drive-abci/tests/strategy_tests/execution.rs index fce4bd63fb3..fc1089406fb 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/execution.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/execution.rs @@ -28,6 +28,7 @@ use drive_abci::abci::app::FullAbciApplication; use drive_abci::config::PlatformConfig; use drive_abci::mimic::test_quorum::TestQuorumInfo; use drive_abci::mimic::{MimicExecuteBlockOptions, MimicExecuteBlockOutcome}; +use drive_abci::platform_types::core_quorum_set::{Quorums, SigningQuorum}; use drive_abci::platform_types::epoch_info::v0::EpochInfoV0; use drive_abci::platform_types::platform::Platform; use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods; @@ -57,6 +58,7 @@ pub(crate) fn run_chain_for_strategy( let validator_quorum_count = strategy.validator_quorum_count; // In most tests 24 quorums let chain_lock_quorum_count = strategy.chain_lock_quorum_count; // In most tests 4 quorums when not the same as validator + let instant_lock_quorum_count = strategy.instant_lock_quorum_count; // In most tests 24 quorums when not the same as validator let validator_set_quorum_size = config.validator_set.quorum_size; let chain_lock_quorum_size = config.chain_lock.quorum_size; @@ -244,7 +246,7 @@ pub(crate) fn run_chain_for_strategy( &mut rng, ); - let mut quorums_details: Vec<(QuorumHash, ExtendedQuorumDetails)> = validator_quorums + let mut validator_quorums_details: Vec<(QuorumHash, ExtendedQuorumDetails)> = validator_quorums .keys() .map(|quorum_hash| { ( @@ -260,7 +262,7 @@ pub(crate) fn run_chain_for_strategy( }) .collect(); - quorums_details.shuffle(&mut rng); + validator_quorums_details.shuffle(&mut rng); let (chain_lock_quorums, chain_lock_quorums_details) = if config.validator_set.quorum_type != config.chain_lock.quorum_type { @@ -303,6 +305,75 @@ pub(crate) fn run_chain_for_strategy( (BTreeMap::new(), vec![]) }; + let (instant_lock_quorum_infos, instant_lock_quorums_details, instant_lock_signing_quorums) = + if config.validator_set.quorum_type != config.instant_lock.quorum_type { + // TODO: Implement instant lock quorums rotation? + let total_instant_lock_quorums = if strategy.rotate_quorums { + instant_lock_quorum_count * 10 + } else { + instant_lock_quorum_count + }; + + let instant_lock_quorums_infos = masternodes::generate_test_quorums( + total_instant_lock_quorums as usize, + initial_all_masternodes + .iter() + .map(|masternode| &masternode.masternode), + config.instant_lock.quorum_size as usize, + &mut rng, + ); + + let mut instant_lock_quorums_details: Vec<(QuorumHash, ExtendedQuorumDetails)> = + instant_lock_quorums_infos + .iter() + .map(|(hash, quorum)| { + ( + *hash, + ExtendedQuorumDetails { + creation_height: 0, + quorum_index: quorum.quorum_index, + mined_block_hash: BlockHash::all_zeros(), + num_valid_members: 0, + health_ratio: 0.0, + }, + ) + }) + .collect(); + + instant_lock_quorums_details.shuffle(&mut rng); + + let instant_lock_signing_quorums: Quorums = + if strategy.sign_instant_locks { + instant_lock_quorums_infos + .iter() + .map(|(quorum_hash, info)| { + let bytes = info.private_key.to_bytes(); + let fixed_bytes: [u8; 32] = bytes + .as_slice() + .try_into() + .expect("Expected a byte array of length 32"); + ( + *quorum_hash, + SigningQuorum { + index: info.quorum_index, + private_key: fixed_bytes, + }, + ) + }) + .collect() + } else { + Default::default() + }; + + ( + instant_lock_quorums_infos, + instant_lock_quorums_details, + instant_lock_signing_quorums, + ) + } else { + Default::default() + }; + let start_core_height = platform.config.abci.genesis_core_height; platform @@ -337,7 +408,7 @@ pub(crate) fn run_chain_for_strategy( .expect_get_quorum_listextended() .returning(move |core_height: Option| { let validator_set_extended_info = if !strategy.rotate_quorums { - quorums_details.clone().into_iter().collect() + validator_quorums_details.clone().into_iter().collect() } else { let core_height = core_height.expect("expected a core height"); // if we rotate quorums we shouldn't give back the same ones every time @@ -347,18 +418,18 @@ pub(crate) fn run_chain_for_strategy( let end_range = end_range % total_validator_quorums as u32; if end_range > start_range { - quorums_details + validator_quorums_details .iter() .skip(start_range as usize) .take((end_range - start_range) as usize) .map(|(quorum_hash, quorum)| (*quorum_hash, quorum.clone())) .collect() } else { - let first_range = quorums_details + let first_range = validator_quorums_details .iter() .skip(start_range as usize) .take((total_validator_quorums as u32 - start_range) as usize); - let second_range = quorums_details.iter().take(end_range as usize); + let second_range = validator_quorums_details.iter().take(end_range as usize); first_range .chain(second_range) .map(|(quorum_hash, quorum)| (*quorum_hash, quorum.clone())) @@ -376,6 +447,13 @@ pub(crate) fn run_chain_for_strategy( ); } + if !instant_lock_quorums_details.is_empty() { + quorums_by_type.insert( + QuorumType::Llmq60_75, + instant_lock_quorums_details.clone().into_iter().collect(), + ); + } + let result = ExtendedQuorumListResult { quorums_by_type }; Ok(result) @@ -384,6 +462,7 @@ pub(crate) fn run_chain_for_strategy( let all_quorums_info: HashMap = validator_quorums .iter() .chain(chain_lock_quorums.iter()) + .chain(instant_lock_quorum_infos.iter()) .map(|(quorum_hash, test_quorum_info)| (*quorum_hash, test_quorum_info.into())) .collect(); @@ -658,6 +737,7 @@ pub(crate) fn run_chain_for_strategy( block_count, all_hpmns_with_updates, validator_quorums, + instant_lock_signing_quorums, strategy, config, rng, @@ -668,7 +748,8 @@ pub(crate) fn create_chain_for_strategy( platform: &Platform, block_count: u64, proposers_with_updates: Vec, - quorums: BTreeMap, + validator_quorums: BTreeMap, + instant_lock_quorums: Quorums, strategy: NetworkStrategy, config: PlatformConfig, rng: StdRng, @@ -685,7 +766,8 @@ pub(crate) fn create_chain_for_strategy( abci_application, block_count, proposers_with_updates, - quorums, + validator_quorums, + instant_lock_quorums, strategy, config, seed, @@ -696,7 +778,8 @@ pub(crate) fn start_chain_for_strategy( abci_application: FullAbciApplication, block_count: u64, proposers_with_updates: Vec, - quorums: BTreeMap, + validator_quorums: BTreeMap, + instant_lock_quorums: Quorums, strategy: NetworkStrategy, config: PlatformConfig, seed: StrategyRandomness, @@ -706,14 +789,14 @@ pub(crate) fn start_chain_for_strategy( StrategyRandomness::RNGEntropy(rng) => rng, }; - let quorum_hashes: Vec<&QuorumHash> = quorums.keys().collect(); + let quorum_hashes: Vec<&QuorumHash> = validator_quorums.keys().collect(); - let mut current_quorum_hash = **quorum_hashes + let mut current_validator_quorum_hash = **quorum_hashes .choose(&mut rng) .expect("expected quorums to be initialized"); - let current_quorum_with_test_info = quorums - .get::(¤t_quorum_hash) + let current_quorum_with_test_info = validator_quorums + .get::(¤t_validator_quorum_hash) .expect("expected a quorum to be found"); // init chain @@ -740,7 +823,7 @@ pub(crate) fn start_chain_for_strategy( current_quorum_with_test_info.public_key.to_bytes().to_vec(), )), }), - quorum_hash: current_quorum_hash.to_byte_array().to_vec(), + quorum_hash: current_validator_quorum_hash.to_byte_array().to_vec(), }); let ResponseInitChain { @@ -751,7 +834,7 @@ pub(crate) fn start_chain_for_strategy( .expect("should init chain"); // initialization will change the current quorum hash - current_quorum_hash = abci_application + current_validator_quorum_hash = abci_application .platform .state .load() @@ -764,8 +847,9 @@ pub(crate) fn start_chain_for_strategy( core_height_start: initial_core_height, block_count, proposers: proposers_with_updates, - quorums, - current_quorum_hash, + validator_quorums, + current_validator_quorum_hash, + instant_lock_quorums, current_proposer_versions: None, current_identity_nonce_counter: Default::default(), current_identity_contract_nonce_counter: Default::default(), @@ -791,13 +875,14 @@ pub(crate) fn continue_chain_for_strategy( core_height_start: _, block_count, proposers: proposers_with_updates, - quorums, - mut current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: mut current_quorum_hash, current_proposer_versions, mut current_identity_nonce_counter, mut current_identity_contract_nonce_counter, start_time_ms, mut current_time_ms, + instant_lock_quorums, } = chain_execution_parameters; let mut rng = match seed { StrategyRandomness::SeedEntropy(seed) => StdRng::seed_from_u64(seed), @@ -874,6 +959,7 @@ pub(crate) fn continue_chain_for_strategy( &mut current_identity_contract_nonce_counter, &mut signer, &mut rng, + &instant_lock_quorums, ); state_transitions_per_block.insert(block_height, state_transitions.clone()); @@ -1073,8 +1159,8 @@ pub(crate) fn continue_chain_for_strategy( masternode_identity_balances, identities: current_identities, proposers: proposers_with_updates, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: proposer_versions, identity_nonce_counter: current_identity_nonce_counter, identity_contract_nonce_counter: current_identity_contract_nonce_counter, @@ -1084,5 +1170,6 @@ pub(crate) fn continue_chain_for_strategy( withdrawals: total_withdrawals, validator_set_updates, state_transition_results_per_block, + instant_lock_quorums, } } diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index 462e4ef4a04..f3002d2fb3d 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -227,12 +227,13 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = run_chain_for_strategy(&mut platform, 15, strategy.clone(), config.clone(), 40); @@ -291,13 +292,14 @@ mod tests { core_height_start: 1, block_count: 30, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy, config, @@ -359,12 +361,13 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = run_chain_for_strategy(&mut platform, 15, strategy.clone(), config.clone(), 40); @@ -423,13 +426,14 @@ mod tests { core_height_start: 1, block_count: 30, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy, config, @@ -3023,12 +3027,13 @@ mod tests { ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. }, last_block_pooled_withdrawals_amount, @@ -3062,13 +3067,14 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, withdrawals: last_block_withdrawals, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = { let outcome = continue_chain_for_strategy( @@ -3078,13 +3084,14 @@ mod tests { core_height_start: 1, block_count: 1, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: GENESIS_TIME_MS, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy.clone(), config.clone(), @@ -3141,13 +3148,14 @@ mod tests { ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, withdrawals: last_block_withdrawals, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. }, last_block_broadcased_withdrawals_amount, @@ -3159,13 +3167,14 @@ mod tests { core_height_start: 1, block_count: 1, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: GENESIS_TIME_MS, current_time_ms: end_time_ms + 1000, + instant_lock_quorums, }, strategy.clone(), config.clone(), @@ -3253,13 +3262,14 @@ mod tests { ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, withdrawals: last_block_withdrawals, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. }, last_block_withdrawals_completed_amount, @@ -3271,13 +3281,14 @@ mod tests { core_height_start: 1, block_count: 1, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: GENESIS_TIME_MS, current_time_ms: end_time_ms + 1000, + instant_lock_quorums, }, strategy.clone(), config.clone(), @@ -3378,13 +3389,14 @@ mod tests { core_height_start: 1, block_count: 1, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: GENESIS_TIME_MS, current_time_ms: end_time_ms + 1000, + instant_lock_quorums, }, strategy.clone(), config.clone(), @@ -4027,8 +4039,8 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, identity_nonce_counter, @@ -4089,8 +4101,9 @@ mod tests { core_height_start: 10, block_count: 30, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, + instant_lock_quorums: Default::default(), current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, diff --git a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs index dae0d7acc8f..c984d3a2aa9 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs @@ -48,8 +48,9 @@ use tenderdash_abci::proto::abci::{ExecTxResult, ValidatorSetUpdate}; use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters; use dpp::data_contract::document_type::v0::DocumentTypeV0; use dpp::identity::accessors::IdentityGettersV0; +use dpp::identity::state_transition::asset_lock_proof::InstantAssetLockProof; use dpp::platform_value::{BinaryData, Value}; -use dpp::prelude::{Identifier, IdentityNonce}; +use dpp::prelude::{AssetLockProof, Identifier, IdentityNonce}; use dpp::state_transition::documents_batch_transition::document_base_transition::v0::DocumentBaseTransitionV0; use dpp::state_transition::documents_batch_transition::document_create_transition::{DocumentCreateTransition, DocumentCreateTransitionV0}; use dpp::state_transition::documents_batch_transition::document_transition::document_delete_transition::DocumentDeleteTransitionV0; @@ -59,7 +60,12 @@ use dpp::state_transition::documents_batch_transition::document_transition::{Doc use drive::drive::document::query::QueryDocumentsOutcomeV0Methods; use dpp::state_transition::data_contract_create_transition::methods::v0::DataContractCreateTransitionMethodsV0; use dpp::state_transition::documents_batch_transition::document_transition::document_transfer_transition::DocumentTransferTransitionV0; +use dpp::state_transition::identity_create_transition::IdentityCreateTransition; +use dpp::state_transition::identity_create_transition::v0::IdentityCreateTransitionV0; +use dpp::state_transition::identity_topup_transition::v0::IdentityTopUpTransitionV0; use drive_abci::abci::app::FullAbciApplication; +use drive_abci::config::PlatformConfig; +use drive_abci::platform_types::core_quorum_set::{QuorumConfig, Quorums, SigningQuorum}; use drive_abci::platform_types::withdrawal::unsigned_withdrawal_txs::v0::UnsignedWithdrawalTxs; use crate::strategy::CoreHeightIncrease::NoCoreHeightIncrease; @@ -240,6 +246,7 @@ pub struct NetworkStrategy { pub extra_normal_mns: u16, pub validator_quorum_count: u16, pub chain_lock_quorum_count: u16, + pub instant_lock_quorum_count: u16, pub initial_core_height: u32, pub upgrading_info: Option, pub core_height_increase: CoreHeightIncrease, @@ -251,6 +258,7 @@ pub struct NetworkStrategy { pub max_tx_bytes_per_block: u64, pub independent_process_proposal_verification: bool, pub sign_chain_locks: bool, + pub sign_instant_locks: bool, } impl Default for NetworkStrategy { @@ -261,6 +269,7 @@ impl Default for NetworkStrategy { extra_normal_mns: 0, validator_quorum_count: 24, chain_lock_quorum_count: 24, + instant_lock_quorum_count: 24, initial_core_height: 1, upgrading_info: None, core_height_increase: NoCoreHeightIncrease, @@ -272,6 +281,7 @@ impl Default for NetworkStrategy { max_tx_bytes_per_block: 44800, independent_process_proposal_verification: false, sign_chain_locks: false, + sign_instant_locks: false, } } } @@ -365,16 +375,18 @@ impl NetworkStrategy { block_info: &BlockInfo, signer: &mut SimpleSigner, rng: &mut StdRng, + instant_lock_quorums: &Quorums, + platform_config: &PlatformConfig, platform_version: &PlatformVersion, ) -> Result, ProtocolError> { let mut state_transitions = vec![]; if block_info.height == 1 && self.strategy.start_identities.number_of_identities > 0 { - let mut new_transitions = NetworkStrategy::create_identities_state_transitions( + let mut new_transitions = self.create_identities_state_transitions( self.strategy.start_identities.number_of_identities.into(), - self.strategy.identity_inserts.start_keys as KeyID, - &self.strategy.identity_inserts.extra_keys, signer, rng, + instant_lock_quorums, + platform_config, platform_version, ); state_transitions.append(&mut new_transitions); @@ -382,12 +394,12 @@ impl NetworkStrategy { let frequency = &self.strategy.identity_inserts.frequency; if frequency.check_hit(rng) { let count = frequency.events(rng); - let mut new_transitions = NetworkStrategy::create_identities_state_transitions( + let mut new_transitions = self.create_identities_state_transitions( count, - self.strategy.identity_inserts.start_keys as KeyID, - &self.strategy.identity_inserts.extra_keys, signer, rng, + instant_lock_quorums, + platform_config, platform_version, ); state_transitions.append(&mut new_transitions); @@ -522,6 +534,7 @@ impl NetworkStrategy { signer: &mut SimpleSigner, identity_nonce_counter: &mut BTreeMap, contract_nonce_counter: &mut BTreeMap<(Identifier, Identifier), u64>, + instant_lock_quorums: &Quorums, rng: &mut StdRng, platform_version: &PlatformVersion, ) -> (Vec, Vec) { @@ -1046,9 +1059,11 @@ impl NetworkStrategy { .collect(); for random_identity in random_identities { - operations.push(NetworkStrategy::create_identity_top_up_transition( + operations.push(self.create_identity_top_up_transition( rng, random_identity, + instant_lock_quorums, + &platform.config, platform_version, )); } @@ -1252,6 +1267,7 @@ impl NetworkStrategy { contract_nonce_counter: &mut BTreeMap<(Identifier, Identifier), u64>, signer: &mut SimpleSigner, rng: &mut StdRng, + instant_lock_quorums: &Quorums, ) -> (Vec, Vec) { let mut finalize_block_operations = vec![]; let platform_state = platform.state.load(); @@ -1259,8 +1275,14 @@ impl NetworkStrategy { .current_platform_version() .expect("expected platform version"); - let identity_state_transitions_result = - self.identity_state_transitions_for_block(block_info, signer, rng, platform_version); + let identity_state_transitions_result = self.identity_state_transitions_for_block( + block_info, + signer, + rng, + instant_lock_quorums, + &platform.config, + platform_version, + ); // Handle the Result returned by identity_state_transitions_for_block let (mut identities, mut state_transitions) = match identity_state_transitions_result { @@ -1293,6 +1315,7 @@ impl NetworkStrategy { signer, identity_nonce_counter, contract_nonce_counter, + instant_lock_quorums, rng, platform_version, ); @@ -1317,13 +1340,17 @@ impl NetworkStrategy { // add this because strategy tests library now requires a callback and uses the actual chain. fn create_identities_state_transitions( + &self, count: u16, - key_count: KeyID, - extra_keys: &KeyMaps, signer: &mut SimpleSigner, rng: &mut StdRng, + instant_lock_quorums: &Quorums, + platform_config: &PlatformConfig, platform_version: &PlatformVersion, ) -> Vec<(Identity, StateTransition)> { + let key_count = self.strategy.identity_inserts.start_keys as KeyID; + let extra_keys = &self.strategy.identity_inserts.extra_keys; + let (mut identities, mut keys) = Identity::random_identities_with_private_keys_with_rng::< Vec<_>, >(count, key_count, rng, platform_version) @@ -1352,13 +1379,58 @@ impl NetworkStrategy { } signer.add_keys(keys); - create_state_transitions_for_identities(identities, signer, rng, platform_version) + let mut state_transitions = + create_state_transitions_for_identities(identities, signer, rng, platform_version); + + if self.sign_instant_locks { + let quorum_config = QuorumConfig { + quorum_type: platform_config.instant_lock.quorum_type, + active_signers: platform_config.instant_lock.quorum_active_signers, + rotation: platform_config.instant_lock.quorum_rotation, + window: platform_config.instant_lock.quorum_window, + }; + + for (_, state_transition) in state_transitions.iter_mut() { + let StateTransition::IdentityCreate(IdentityCreateTransition::V0( + IdentityCreateTransitionV0 { + asset_lock_proof: + AssetLockProof::Instant(InstantAssetLockProof { instant_lock, .. }), + .. + }, + )) = state_transition + else { + panic!("must be identity create transition v0 with instant lock proof"); + }; + + let request_id = instant_lock + .request_id() + .expect("failed to build request id"); + + let (quorum_hash, quorum) = instant_lock_quorums + .choose_quorum(&quorum_config, request_id.as_ref()) + .expect("failed to choose quorum for instant lock transaction signing"); + + instant_lock.signature = quorum + .sign_for_instant_lock( + &quorum_config, + &quorum_hash, + request_id.as_ref(), + &instant_lock.txid, + ) + .expect("failed to sign transaction for instant lock"); + } + } + + state_transitions } // add this because strategy tests library now requires a callback and uses the actual chain. fn create_identity_top_up_transition( + &self, rng: &mut StdRng, identity: &Identity, + instant_lock_quorums: &Quorums, + platform_config: &PlatformConfig, platform_version: &PlatformVersion, ) -> StateTransition { let (_, pk) = ECDSA_SECP256K1 @@ -1369,7 +1441,7 @@ impl NetworkStrategy { let asset_lock_proof = instant_asset_lock_proof_fixture(PrivateKey::new(secret_key, Network::Dash)); - IdentityTopUpTransition::try_from_identity( + let mut state_transition = IdentityTopUpTransition::try_from_identity( identity, asset_lock_proof, secret_key.as_ref(), @@ -1377,7 +1449,46 @@ impl NetworkStrategy { platform_version, None, ) - .expect("expected to create top up transition") + .expect("expected to create top up transition"); + + if self.sign_instant_locks { + let quorum_config = QuorumConfig { + quorum_type: platform_config.instant_lock.quorum_type, + active_signers: platform_config.instant_lock.quorum_active_signers, + rotation: platform_config.instant_lock.quorum_rotation, + window: platform_config.instant_lock.quorum_window, + }; + + let StateTransition::IdentityTopUp(IdentityTopUpTransition::V0( + IdentityTopUpTransitionV0 { + asset_lock_proof: + AssetLockProof::Instant(InstantAssetLockProof { instant_lock, .. }), + .. + }, + )) = &mut state_transition + else { + panic!("must be identity topup transition v0 with instant lock proof"); + }; + + let request_id = instant_lock + .request_id() + .expect("failed to build request id"); + + let (quorum_hash, quorum) = instant_lock_quorums + .choose_quorum(&quorum_config, request_id.as_ref()) + .expect("failed to choose quorum for instant lock transaction signing"); + + instant_lock.signature = quorum + .sign_for_instant_lock( + &quorum_config, + &quorum_hash, + request_id.as_ref(), + &instant_lock.txid, + ) + .expect("failed to sign transaction for instant lock"); + } + + state_transition } } @@ -1399,9 +1510,10 @@ pub struct ChainExecutionOutcome<'a> { pub masternode_identity_balances: BTreeMap<[u8; 32], Credits>, pub identities: Vec, pub proposers: Vec, - pub quorums: BTreeMap, - pub current_quorum_hash: QuorumHash, + pub validator_quorums: BTreeMap, + pub current_validator_quorum_hash: QuorumHash, pub current_proposer_versions: Option>, + pub instant_lock_quorums: Quorums, /// Identity nonce counters pub identity_nonce_counter: BTreeMap, /// Identity Contract nonce counters @@ -1417,8 +1529,8 @@ pub struct ChainExecutionOutcome<'a> { impl<'a> ChainExecutionOutcome<'a> { pub fn current_quorum(&self) -> &TestQuorumInfo { - self.quorums - .get::(&self.current_quorum_hash) + self.validator_quorums + .get::(&self.current_validator_quorum_hash) .unwrap() } } @@ -1428,8 +1540,9 @@ pub struct ChainExecutionParameters { pub core_height_start: u32, pub block_count: u64, pub proposers: Vec, - pub quorums: BTreeMap, - pub current_quorum_hash: QuorumHash, + pub validator_quorums: BTreeMap, + pub current_validator_quorum_hash: QuorumHash, + pub instant_lock_quorums: Quorums, // the first option is if it is set // the second option is if we are even upgrading pub current_proposer_versions: Option>>, diff --git a/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs index 304f8896f97..0146fc16f7d 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs @@ -101,12 +101,13 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = run_chain_for_strategy( &mut platform, @@ -165,11 +166,12 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = continue_chain_for_strategy( abci_app, @@ -178,13 +180,14 @@ mod tests { core_height_start: 1, block_count: 200, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions.clone()), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy.clone(), config.clone(), @@ -228,13 +231,14 @@ mod tests { core_height_start: 1, block_count: 400, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy, config, @@ -343,12 +347,13 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = run_chain_for_strategy( &mut platform, @@ -404,11 +409,12 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = continue_chain_for_strategy( abci_app, @@ -417,13 +423,14 @@ mod tests { core_height_start: 1, block_count: 1, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions.clone()), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy.clone(), config.clone(), @@ -467,13 +474,14 @@ mod tests { core_height_start: 1, block_count: 120, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy, config, @@ -577,8 +585,8 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, end_time_ms, .. } = run_chain_for_strategy(&mut platform, 1, strategy.clone(), config.clone(), 13); @@ -754,12 +762,13 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = run_chain_for_strategy( &mut platform, @@ -807,12 +816,13 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = continue_chain_for_strategy( abci_app, @@ -821,13 +831,14 @@ mod tests { core_height_start: 1, block_count: 2500, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions.clone()), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy.clone(), config.clone(), @@ -874,13 +885,14 @@ mod tests { core_height_start: 1, block_count: 400, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy, config, @@ -989,12 +1001,13 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = run_chain_for_strategy( &mut platform, @@ -1034,12 +1047,13 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = continue_chain_for_strategy( abci_app, @@ -1048,13 +1062,14 @@ mod tests { core_height_start: 1, block_count: 3000, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy, config.clone(), @@ -1129,13 +1144,14 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = continue_chain_for_strategy( abci_app, @@ -1144,13 +1160,14 @@ mod tests { core_height_start: 1, block_count: 2000, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: None, //restart the proposer versions current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy.clone(), config.clone(), @@ -1199,13 +1216,14 @@ mod tests { core_height_start: 1, block_count: 100, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: Some(current_proposer_versions), current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy, config, @@ -1321,11 +1339,12 @@ mod tests { let ChainExecutionOutcome { abci_app, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, end_time_ms, identity_nonce_counter, identity_contract_nonce_counter, + instant_lock_quorums, .. } = run_chain_for_strategy(&mut platform, 1400, strategy, config.clone(), 15); let state = abci_app.platform.state.load(); @@ -1419,13 +1438,14 @@ mod tests { core_height_start: 1, block_count: 1100, proposers, - quorums, - current_quorum_hash, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, current_proposer_versions: None, current_identity_nonce_counter: identity_nonce_counter, current_identity_contract_nonce_counter: identity_contract_nonce_counter, start_time_ms: 1681094380000, current_time_ms: end_time_ms, + instant_lock_quorums, }, strategy, config, From dd3165eca5d5a56c2fcb815770535a4298ab5a55 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 00:13:10 +0700 Subject: [PATCH 07/48] fix: return error if signature is not valid --- .../core_chain_lock/verify_chain_lock_locally/v0/mod.rs | 4 +++- .../verify_recent_signature_locally/v0/mod.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs index 3c0b0ae4453..1e37d4a48c2 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs @@ -36,7 +36,9 @@ where let quorum_config = quorum_set.config(); // First verify that the signature conforms to a signature - let signature = G2Element::from_bytes(chain_lock.signature.as_bytes())?; + let Ok(signature) = G2Element::from_bytes(chain_lock.signature.as_bytes()) else { + return Ok(Some(false)); + }; // we attempt to verify the chain lock locally let chain_lock_height = chain_lock.block_height; diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs index 7afd3a8c0c8..e8800c2e9bb 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs @@ -18,7 +18,9 @@ pub(super) fn verify_recent_instant_lock_signature_locally_v0( platform_state: &PlatformState, ) -> Result { // First verify that the signature conforms to a signature - let signature = G2Element::from_bytes(instant_lock.signature.as_bytes())?; + let Ok(signature) = G2Element::from_bytes(instant_lock.signature.as_bytes()) else { + return Ok(false); + }; let instant_lock_height = platform_state.last_committed_core_height(); From 0c3425d70d7c77fb2464caacf4a0e06f8e6374ce Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 00:13:57 +0700 Subject: [PATCH 08/48] docs: add todo for non-determinism issue --- .../core_based_updates/update_quorum_info/v0/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index 28ab6439042..45b68f63a8b 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -171,6 +171,10 @@ where let new_validator_sets = quorum_infos .into_iter() .map(|(quorum_hash, info_result)| { + // TODO: There is a non-determinism here because quorum info is not based on core chain locked height + // so you will might get different members and tenderdash will fail when you will try to update + // validator set with different memebers. + let validator_set = ValidatorSet::V0(ValidatorSetV0::try_from_quorum_info_result( info_result, block_platform_state, From 98a9e608bee785c9fa4a258ed3fc5bd4301eb992 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 00:14:21 +0700 Subject: [PATCH 09/48] fix: non-deterministic quorum index is used --- .../core_based_updates/update_quorum_info/v0/mod.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index 45b68f63a8b..469dd2bd166 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -367,7 +367,7 @@ where .current_quorums() .contains_key::(quorum_hash) }) - .map(|(quorum_hash, _)| { + .map(|(quorum_hash, index)| { let quorum_info = self.core_rpc.get_quorum_info( quorum_set_type.quorum_type(), quorum_hash, @@ -385,18 +385,13 @@ where tracing::trace!( ?public_key, ?quorum_hash, + index, quorum_type = ?quorum_set_type.quorum_type(), "add new {} quorum {}", quorum_set_type, quorum_hash, ); - let index = if quorum_info.quorum_index == 0 { - None - } else { - Some(quorum_info.quorum_index) - }; - Ok((*quorum_hash, VerificationQuorum { public_key, index })) }) .collect::, Error>>()?; From eb43aa7f13416be415e2fe73c7ca2b3b3f953a7e Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 00:14:59 +0700 Subject: [PATCH 10/48] chore: log state transition validation result for asset lock based STs --- .../process_raw_state_transitions/v0/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/rs-drive-abci/src/execution/platform_events/state_transition_processing/process_raw_state_transitions/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/state_transition_processing/process_raw_state_transitions/v0/mod.rs index 29827900d00..a9ba48da712 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/state_transition_processing/process_raw_state_transitions/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/state_transition_processing/process_raw_state_transitions/v0/mod.rs @@ -214,6 +214,19 @@ where // the first error must be present for an invalid result .remove(0); + if tracing::enabled!(tracing::Level::DEBUG) { + let st_hash = hex::encode(hash_single(raw_state_transition)); + + tracing::debug!( + error = ?first_consensus_error, + st_hash, + "Invalid {} state transition without identity ({}): {}", + state_transition_name, + st_hash, + &first_consensus_error + ); + } + // We don't have execution event, so we can't pay for processing return Ok(StateTransitionExecutionResult::UnpaidConsensusError( first_consensus_error, From 9102d0f0d6c31901b454a5cb75f2a2aad768c586 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 00:15:22 +0700 Subject: [PATCH 11/48] docs: add todo to have more verbose error --- .../common/asset_lock/proof/validate/instant/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs index 1e3362bd802..5b599f9db1f 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs @@ -54,6 +54,7 @@ impl AssetLockProofValidation for InstantAssetLockProof { } // TODO: Shouldn't we add an operation for fees? + // TODO: The error should say that instant lock probably invalid and we should use ChainAssetLockProof // This is a limited verification and will work properly only for recently signed instant locks. // Even valid instant locks that was signed some time ago will be considered invalid due to limited From 0c6b1c6bb2b80fb95c45c47f4ffd7112cb380694 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 00:17:00 +0700 Subject: [PATCH 12/48] refactor: cleanup quorum set --- .../core_quorum_set/v0/quorum_set.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs index 5a64628e41e..702fe572e2d 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs @@ -1,8 +1,6 @@ use crate::config::{ChainLockConfig, QuorumLikeConfig}; -use crate::error::Error; -use crate::platform_types::core_quorum_set::v0::quorums::{Quorum, Quorums}; -use crate::platform_types::core_quorum_set::{ReversedQuorumHashBytes, VerificationQuorum}; -use dashcore_rpc::dashcore::ChainLock; +use crate::platform_types::core_quorum_set::v0::quorums::Quorums; +use crate::platform_types::core_quorum_set::VerificationQuorum; use dashcore_rpc::json::QuorumType; use dpp::dashcore::{QuorumHash, QuorumSigningRequestId}; use std::vec::IntoIter; @@ -95,13 +93,9 @@ impl<'q> Iterator for QuorumsVerificationDataIterator<'q> { type Item = (QuorumHash, &'q VerificationQuorum); fn next(&mut self) -> Option { - let quorum_set = self.quorum_sets.next(); + let quorum_set = self.quorum_sets.next()?; - let Some(quorum_set) = quorum_set else { - return None; - }; - - quorum_set.choose_quorum(&self.config, self.request_id.as_ref()) + quorum_set.choose_quorum(self.config, self.request_id.as_ref()) } } From ef8a001da3f079f810034fa141643f0c048f7638 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 00:18:36 +0700 Subject: [PATCH 13/48] fix: invalid selection logic for rotating quorums --- .../src/platform_types/core_quorum_set/mod.rs | 3 +- .../core_quorum_set/v0/quorums.rs | 105 +++--------------- 2 files changed, 15 insertions(+), 93 deletions(-) diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs index cfebe04fac6..b07f652e66a 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs @@ -6,8 +6,7 @@ pub use crate::platform_types::core_quorum_set::v0::quorum_set::{ CoreQuorumSetV0, CoreQuorumSetV0Methods, QuorumConfig, QuorumsVerificationDataIterator, }; pub use crate::platform_types::core_quorum_set::v0::quorums::{ - Quorum, Quorums, ReversedQuorumHashBytes, SigningQuorum, ThresholdBlsPublicKey, - VerificationQuorum, + Quorum, Quorums, SigningQuorum, ThresholdBlsPublicKey, VerificationQuorum, }; use bincode::{Decode, Encode}; use derive_more::From; diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs index 75cbf45b11d..5ff887cd64b 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs @@ -1,19 +1,12 @@ -use dashcore_rpc::json::QuorumType; use derive_more::{Deref, DerefMut, From}; use dpp::bls_signatures::PrivateKey; use dpp::dashcore::bls_sig_utils::BLSSignature; -use dpp::dashcore::consensus::Encodable; -use dpp::dashcore::{QuorumHash, QuorumSigningRequestId, Transaction, TxIn, Txid, VarInt}; -use dpp::{bls_signatures, ProtocolError}; +use dpp::dashcore::{QuorumHash, Txid}; use std::collections::BTreeMap; use std::convert::TryInto; pub use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; -/// Reversed quorum hash bytes. Used for signature verification as part of the signature payload -pub type ReversedQuorumHashBytes = Vec; - -use crate::error::execution::ExecutionError; use crate::error::Error; use crate::platform_types::core_quorum_set::QuorumConfig; use dpp::dashcore::hashes::{sha256d, Hash, HashEngine}; @@ -106,18 +99,26 @@ impl Quorums { quorum_config: &QuorumConfig, request_id: &[u8; 32], ) -> Option<(QuorumHash, &Q)> { - let n = quorum_config.active_signers as u64; + let active_signers = quorum_config.active_signers as u32; + + // binary (base-2) logarithm from active_signers + let n = 31 - active_signers.leading_zeros(); - let b = u64::from_le_bytes(request_id[24..32].try_into().unwrap()); + // Extract last 64 bits of request_id + let b = u64::from_le_bytes( + request_id[24..32] + .try_into() + .expect("request_id is [u8; 32]"), + ); // Take last n bits of b let mask = (1u64 << n) - 1; - let signer = mask & (b >> (64 - n)); + let signer = mask & (b >> (64 - n - 1)); self.0 .iter() - .find(|(hash, quorum)| quorum.index() == Some(signer as u32)) - .map(|(hash, quorum)| (*hash, quorum)) + .find(|(_, quorum)| quorum.index() == Some(signer as u32)) + .map(|(quorum_hash, quorum)| (*quorum_hash, quorum)) } } @@ -192,81 +193,3 @@ impl SigningQuorum { Ok(BLSSignature::from(g2element_bytes)) } } - -// -// const IS_LOCK_REQUEST_ID_PREFIX: &str = "islock"; -// -// // TODO: Must be in dashcore lib -// -// pub struct InstantLockQuorumSigner { -// quorum_hash: QuorumHash, -// quorum_type: QuorumType, -// quorum_private_key: PrivateKey, -// } -// -// impl InstantLockQuorumSigner { -// pub fn new( -// quorum_hash: QuorumHash, -// quorum_type: QuorumType, -// quorum_private_key: PrivateKey, -// ) -> Self { -// Self { -// quorum_hash, -// quorum_type, -// quorum_private_key, -// } -// } -// -// pub fn sign( -// &self, -// request_id: &QuorumSigningRequestId, -// transaction: &Transaction, -// ) -> Result { -// // The signature must verify against the quorum public key and SHA256(llmqType, quorumHash, SHA256(height), txId). -// // llmqType and quorumHash must be taken from the quorum selected in 1. -// let mut engine = sha256d::Hash::engine(); -// -// let mut reversed_quorum_hash = self.quorum_hash.to_byte_array().to_vec(); -// reversed_quorum_hash.reverse(); -// -// engine.input(&[self.quorum_type as u8]); -// engine.input(reversed_quorum_hash.as_slice()); -// engine.input(request_id.as_byte_array()); -// engine.input(transaction.txid().as_byte_array()); -// -// let message_digest = sha256d::Hash::from_engine(engine); -// -// let g2element = self.quorum_private_key.sign(message_digest.as_ref()); -// let g2element_bytes = *g2element.to_bytes(); -// -// Ok(BLSSignature::from(g2element_bytes)) -// } -// } -// -// fn request_id_for_tx(tx: &Transaction) -> Result { -// let mut engine = QuorumSigningRequestId::engine(); -// -// // Prefix -// let prefix_len = VarInt(IS_LOCK_REQUEST_ID_PREFIX.len() as u64); -// prefix_len.consensus_encode(&mut engine).map_err(|e| { -// ProtocolError::CorruptedSerialization(format!("can't serialize varInt for request_id: {e}")) -// })?; -// -// engine.input(IS_LOCK_REQUEST_ID_PREFIX.as_bytes()); -// -// // Inputs -// let inputs_len = VarInt(tx.input.len() as u64); -// inputs_len.consensus_encode(&mut engine).map_err(|e| { -// ProtocolError::CorruptedSerialization(format!("can't serialize varInt for request_id: {e}")) -// })?; -// -// for TxIn { -// previous_output, .. -// } in &tx.input -// { -// engine.input(&previous_output.txid[..]); -// engine.input(&previous_output.vout.to_le_bytes()); -// } -// -// Ok(QuorumSigningRequestId::from_engine(engine)) -// } From e14f9b74fa7adb9deabdd2d331f313bf9ddfbfe3 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 00:20:47 +0700 Subject: [PATCH 14/48] test: fix instant lock signing logic in strategy tests --- .../tests/strategy_tests/execution.rs | 20 +++ .../tests/strategy_tests/main.rs | 7 +- .../tests/strategy_tests/strategy.rs | 149 ++++++++++-------- packages/strategy-tests/src/transitions.rs | 30 +++- 4 files changed, 140 insertions(+), 66 deletions(-) diff --git a/packages/rs-drive-abci/tests/strategy_tests/execution.rs b/packages/rs-drive-abci/tests/strategy_tests/execution.rs index fc1089406fb..fa4c13ac779 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/execution.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/execution.rs @@ -370,6 +370,26 @@ pub(crate) fn run_chain_for_strategy( instant_lock_quorums_details, instant_lock_signing_quorums, ) + } else if strategy.sign_instant_locks { + let signing_quorums = validator_quorums + .iter() + .map(|(quorum_hash, info)| { + let bytes = info.private_key.to_bytes(); + let fixed_bytes: [u8; 32] = bytes + .as_slice() + .try_into() + .expect("Expected a byte array of length 32"); + ( + *quorum_hash, + SigningQuorum { + index: info.quorum_index, + private_key: fixed_bytes, + }, + ) + }) + .collect(); + + (Default::default(), Default::default(), signing_quorums) } else { Default::default() }; diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index f3002d2fb3d..bef89ceca8c 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -1036,7 +1036,8 @@ mod tests { #[test] fn run_chain_insert_one_new_identity_per_block_with_block_signing() { - // drive_abci::logging::Loggers::default().try_install().ok(); + drive_abci::logging::init_for_tests(LogLevel::Silent); + let strategy = NetworkStrategy { strategy: Strategy { start_contracts: vec![], @@ -1069,12 +1070,13 @@ mod tests { }, }), verify_state_transition_results: true, + sign_instant_locks: true, ..Default::default() }; let config = PlatformConfig { validator_set: ValidatorSetConfig::default_100_67(), chain_lock: ChainLockConfig::default_100_67(), - instant_lock: InstantLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default(), execution: ExecutionConfig { verify_sum_trees: true, validator_set_rotation_block_count: 25, @@ -2673,6 +2675,7 @@ mod tests { failure_testing: None, query_testing: None, verify_state_transition_results: true, + sign_instant_locks: true, ..Default::default() }; let config = PlatformConfig { diff --git a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs index c984d3a2aa9..b9e20d70bbd 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs @@ -40,7 +40,7 @@ use drive_abci::rpc::core::MockCoreRPCLike; use rand::prelude::{IteratorRandom, SliceRandom, StdRng}; use rand::Rng; use strategy_tests::{KeyMaps, Strategy}; -use strategy_tests::transitions::{create_state_transitions_for_identities, instant_asset_lock_proof_fixture}; +use strategy_tests::transitions::{create_state_transitions_for_identities, create_state_transitions_for_identities_and_proofs, instant_asset_lock_proof_fixture}; use std::borrow::Cow; use std::collections::{BTreeMap, HashMap, HashSet}; use std::str::FromStr; @@ -60,8 +60,6 @@ use dpp::state_transition::documents_batch_transition::document_transition::{Doc use drive::drive::document::query::QueryDocumentsOutcomeV0Methods; use dpp::state_transition::data_contract_create_transition::methods::v0::DataContractCreateTransitionMethodsV0; use dpp::state_transition::documents_batch_transition::document_transition::document_transfer_transition::DocumentTransferTransitionV0; -use dpp::state_transition::identity_create_transition::IdentityCreateTransition; -use dpp::state_transition::identity_create_transition::v0::IdentityCreateTransitionV0; use dpp::state_transition::identity_topup_transition::v0::IdentityTopUpTransitionV0; use drive_abci::abci::app::FullAbciApplication; use drive_abci::config::PlatformConfig; @@ -1379,49 +1377,24 @@ impl NetworkStrategy { } signer.add_keys(keys); - let mut state_transitions = - create_state_transitions_for_identities(identities, signer, rng, platform_version); if self.sign_instant_locks { - let quorum_config = QuorumConfig { - quorum_type: platform_config.instant_lock.quorum_type, - active_signers: platform_config.instant_lock.quorum_active_signers, - rotation: platform_config.instant_lock.quorum_rotation, - window: platform_config.instant_lock.quorum_window, - }; - - for (_, state_transition) in state_transitions.iter_mut() { - let StateTransition::IdentityCreate(IdentityCreateTransition::V0( - IdentityCreateTransitionV0 { - asset_lock_proof: - AssetLockProof::Instant(InstantAssetLockProof { instant_lock, .. }), - .. - }, - )) = state_transition - else { - panic!("must be identity create transition v0 with instant lock proof"); - }; - - let request_id = instant_lock - .request_id() - .expect("failed to build request id"); - - let (quorum_hash, quorum) = instant_lock_quorums - .choose_quorum(&quorum_config, request_id.as_ref()) - .expect("failed to choose quorum for instant lock transaction signing"); + let identities_with_proofs = create_signed_instant_asset_lock_proofs_for_identities( + identities, + rng, + instant_lock_quorums, + platform_config, + platform_version, + ); - instant_lock.signature = quorum - .sign_for_instant_lock( - &quorum_config, - &quorum_hash, - request_id.as_ref(), - &instant_lock.txid, - ) - .expect("failed to sign transaction for instant lock"); - } + create_state_transitions_for_identities_and_proofs( + identities_with_proofs, + signer, + platform_version, + ) + } else { + create_state_transitions_for_identities(identities, signer, rng, platform_version) } - - state_transitions } // add this because strategy tests library now requires a callback and uses the actual chain. @@ -1438,19 +1411,10 @@ impl NetworkStrategy { .unwrap(); let sk: [u8; 32] = pk.try_into().unwrap(); let secret_key = SecretKey::from_str(hex::encode(sk).as_str()).unwrap(); - let asset_lock_proof = + let mut asset_lock_proof = instant_asset_lock_proof_fixture(PrivateKey::new(secret_key, Network::Dash)); - let mut state_transition = IdentityTopUpTransition::try_from_identity( - identity, - asset_lock_proof, - secret_key.as_ref(), - 0, - platform_version, - None, - ) - .expect("expected to create top up transition"); - + // Sign transaction and update signature in instant lock proof if self.sign_instant_locks { let quorum_config = QuorumConfig { quorum_type: platform_config.instant_lock.quorum_type, @@ -1459,15 +1423,11 @@ impl NetworkStrategy { window: platform_config.instant_lock.quorum_window, }; - let StateTransition::IdentityTopUp(IdentityTopUpTransition::V0( - IdentityTopUpTransitionV0 { - asset_lock_proof: - AssetLockProof::Instant(InstantAssetLockProof { instant_lock, .. }), - .. - }, - )) = &mut state_transition + // Sign transaction and update instant lock + let AssetLockProof::Instant(InstantAssetLockProof { instant_lock, .. }) = + &mut asset_lock_proof else { - panic!("must be identity topup transition v0 with instant lock proof"); + panic!("must be instant lock proof"); }; let request_id = instant_lock @@ -1488,7 +1448,15 @@ impl NetworkStrategy { .expect("failed to sign transaction for instant lock"); } - state_transition + IdentityTopUpTransition::try_from_identity( + identity, + asset_lock_proof, + secret_key.as_ref(), + 0, + platform_version, + None, + ) + .expect("expected to create top up transition") } } @@ -1551,3 +1519,60 @@ pub struct ChainExecutionParameters { pub start_time_ms: u64, pub current_time_ms: u64, } + +fn create_signed_instant_asset_lock_proofs_for_identities( + identities: Vec, + rng: &mut StdRng, + instant_lock_quorums: &Quorums, + platform_config: &PlatformConfig, + platform_version: &PlatformVersion, +) -> Vec<(Identity, [u8; 32], AssetLockProof)> { + let quorum_config = QuorumConfig { + quorum_type: platform_config.instant_lock.quorum_type, + active_signers: platform_config.instant_lock.quorum_active_signers, + rotation: platform_config.instant_lock.quorum_rotation, + window: platform_config.instant_lock.quorum_window, + }; + + identities + .into_iter() + .map(|identity| { + // Create instant asset lock proof + let (_, pk) = ECDSA_SECP256K1 + .random_public_and_private_key_data(rng, platform_version) + .unwrap(); + + let pk_fixed: [u8; 32] = pk.try_into().unwrap(); + let secret_key = SecretKey::from_str(hex::encode(pk_fixed).as_str()).unwrap(); + let private_key = PrivateKey::new(secret_key, Network::Dash); + + let mut asset_lock_proof = instant_asset_lock_proof_fixture(private_key); + + // Sign transaction and update instant lock + let AssetLockProof::Instant(InstantAssetLockProof { instant_lock, .. }) = + &mut asset_lock_proof + else { + panic!("must be instant lock proof"); + }; + + let request_id = instant_lock + .request_id() + .expect("failed to build request id"); + + let (quorum_hash, quorum) = instant_lock_quorums + .choose_quorum(&quorum_config, request_id.as_ref()) + .expect("failed to choose quorum for instant lock transaction signing"); + + instant_lock.signature = quorum + .sign_for_instant_lock( + &quorum_config, + &quorum_hash, + request_id.as_ref(), + &instant_lock.txid, + ) + .expect("failed to sign transaction for instant lock"); + + (identity, pk_fixed, asset_lock_proof) + }) + .collect() +} diff --git a/packages/strategy-tests/src/transitions.rs b/packages/strategy-tests/src/transitions.rs index 0ef26db956b..0a9ef44be30 100644 --- a/packages/strategy-tests/src/transitions.rs +++ b/packages/strategy-tests/src/transitions.rs @@ -779,7 +779,7 @@ pub fn create_state_transitions_for_identities( let (_, pk) = ECDSA_SECP256K1 .random_public_and_private_key_data(rng, platform_version) .unwrap(); - let sk: [u8; 32] = pk.clone().try_into().unwrap(); + let sk: [u8; 32] = pk.try_into().unwrap(); let secret_key = SecretKey::from_str(hex::encode(sk).as_str()).unwrap(); let asset_lock_proof = instant_asset_lock_proof_fixture(PrivateKey::new(secret_key, Network::Dash)); @@ -787,7 +787,33 @@ pub fn create_state_transitions_for_identities( IdentityCreateTransition::try_from_identity_with_signer( &identity.clone(), asset_lock_proof, - pk.as_slice(), + &sk, + signer, + &NativeBlsModule, + 0, + platform_version, + ) + .expect("expected to transform identity into identity create transition"); + identity.set_id(identity_create_transition.owner_id()); + + (identity, identity_create_transition) + }) + .collect() +} + +pub fn create_state_transitions_for_identities_and_proofs( + identities_with_proofs: Vec<(Identity, [u8; 32], AssetLockProof)>, + signer: &mut SimpleSigner, + platform_version: &PlatformVersion, +) -> Vec<(Identity, StateTransition)> { + identities_with_proofs + .into_iter() + .map(|(mut identity, private_key, asset_lock_proof)| { + let identity_create_transition = + IdentityCreateTransition::try_from_identity_with_signer( + &identity.clone(), + asset_lock_proof, + &private_key, signer, &NativeBlsModule, 0, From 8842a22d8b6f19e95f96212130c795210992c079 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 01:57:31 +0700 Subject: [PATCH 15/48] chore(dashmate): update with new configuration --- .../configs/defaults/getBaseConfigFactory.js | 24 +++++++-- .../configs/defaults/getLocalConfigFactory.js | 21 ++++++-- .../defaults/getTestnetConfigFactory.js | 21 ++++++-- .../configs/getConfigFileMigrationsFactory.js | 51 +++++++++++++++++++ packages/dashmate/docker-compose.yml | 13 +++-- .../dashmate/src/config/configJsonSchema.js | 49 +++++++++++------- .../local/configureTenderdashTaskFactory.js | 2 +- .../local/enableCoreQuorumsTaskFactory.js | 2 +- .../test/unit/commands/config/set.spec.js | 8 +-- 9 files changed, 151 insertions(+), 40 deletions(-) diff --git a/packages/dashmate/configs/defaults/getBaseConfigFactory.js b/packages/dashmate/configs/defaults/getBaseConfigFactory.js index 9459d657db5..15ece4162ac 100644 --- a/packages/dashmate/configs/defaults/getBaseConfigFactory.js +++ b/packages/dashmate/configs/defaults/getBaseConfigFactory.js @@ -15,6 +15,7 @@ import semver from 'semver'; import fs from 'fs'; import { + NETWORK_MAINNET, NETWORK_TESTNET, PACKAGE_ROOT_DIR, } from '../../src/constants.js'; import Config from '../../src/config/Config.js'; @@ -245,12 +246,25 @@ export default function getBaseConfigFactory(homeDir) { retention: 60 * 3, }, validatorSet: { - llmqType: 4, + quorum: { + llmqType: 4, + dkgInterval: 24, + activeSigners: 24, + }, }, chainLock: { - llmqType: 2, - dkgInterval: 288, - llmqSize: 400, + quorum: { + llmqType: 2, + dkgInterval: 288, + activeSigners: 4, + }, + }, + instantLock: { + quorum: { + llmqType: 5, + dkgInterval: 288, + activeSigners: 32, + }, }, metrics: { enabled: false, @@ -425,7 +439,7 @@ export default function getBaseConfigFactory(homeDir) { }, }, externalIp: null, - network: NETWORK_TESTNET, + network: NETWORK_MAINNET, environment: 'production', }; diff --git a/packages/dashmate/configs/defaults/getLocalConfigFactory.js b/packages/dashmate/configs/defaults/getLocalConfigFactory.js index 33992ceceb7..c5c1047a7ab 100644 --- a/packages/dashmate/configs/defaults/getLocalConfigFactory.js +++ b/packages/dashmate/configs/defaults/getLocalConfigFactory.js @@ -70,12 +70,25 @@ export default function getLocalConfigFactory(getBaseConfig) { }, abci: { validatorSet: { - llmqType: 106, + quorum: { + llmqType: 106, + dkgInterval: 24, + activeSigners: 2, + }, }, chainLock: { - llmqType: 100, - dkgInterval: 24, - llmqSize: 3, + quorum: { + llmqType: 100, + dkgInterval: 24, + activeSigners: 2, + }, + }, + instantLock: { + quorum: { + llmqType: 100, + dkgInterval: 24, + activeSigners: 2, + }, }, }, }, diff --git a/packages/dashmate/configs/defaults/getTestnetConfigFactory.js b/packages/dashmate/configs/defaults/getTestnetConfigFactory.js index 323d63314bb..b5712bc1bba 100644 --- a/packages/dashmate/configs/defaults/getTestnetConfigFactory.js +++ b/packages/dashmate/configs/defaults/getTestnetConfigFactory.js @@ -55,12 +55,25 @@ export default function getTestnetConfigFactory(homeDir, getBaseConfig) { abci: { epochTime: 3600, validatorSet: { - llmqType: 6, + quorum: { + llmqType: 6, + dkgInterval: 24, + activeSigners: 24, + }, }, chainLock: { - llmqType: 1, - dkgInterval: 24, - llmqSize: 50, + quorum: { + llmqType: 1, + dkgInterval: 24, + activeSigners: 24, + }, + }, + instantLock: { + quorum: { + llmqType: 5, + dkgInterval: 288, + activeSigners: 32, + }, }, }, tenderdash: { diff --git a/packages/dashmate/configs/getConfigFileMigrationsFactory.js b/packages/dashmate/configs/getConfigFileMigrationsFactory.js index cdd3cd9405f..f328e259d9b 100644 --- a/packages/dashmate/configs/getConfigFileMigrationsFactory.js +++ b/packages/dashmate/configs/getConfigFileMigrationsFactory.js @@ -40,6 +40,20 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs) return defaultConfigs.get(baseConfigName); } + function getDefaultConfigByNetwork(network) { + if (network === NETWORK_MAINNET) { + return defaultConfigs.get('mainnet'); + } + if (network === NETWORK_TESTNET) { + return defaultConfigs.get('testnet'); + } + if (network === NETWORK_LOCAL) { + return defaultConfigs.get('local'); + } + + return defaultConfigs.get('base'); + } + return { '0.24.0': (configFile) => { Object.entries(configFile.configs) @@ -613,6 +627,43 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs) return configFile; }, + '1.0.0-dev.16': (configFile) => { + Object.entries(configFile.configs) + .forEach(([name, options]) => { + if (name === 'base') { + options.network = NETWORK_MAINNET; + } + + const networkConfig = getDefaultConfigByNetwork(options.network); + + options.platform.drive.abci.chainLock.quorum = { + llmqType: networkConfig.get('platform.drive.abci.chainLock.quorum.llmqType'), + dkgInterval: networkConfig.get('platform.drive.abci.chainLock.quorum.dkgInterval'), + activeSigners: networkConfig.get('platform.drive.abci.chainLock.quorum.activeSigners'), + }; + + delete options.platform.drive.abci.chainLock.llmqType; + delete options.platform.drive.abci.chainLock.llmqSize; + delete options.platform.drive.abci.chainLock.dkgInterval; + + options.platform.drive.abci.validatorSet.quorum = { + llmqType: networkConfig.get('platform.drive.abci.validatorSet.quorum.llmqType'), + dkgInterval: networkConfig.get('platform.drive.abci.validatorSet.quorum.dkgInterval'), + activeSigners: networkConfig.get('platform.drive.abci.validatorSet.quorum.activeSigners'), + }; + + delete options.platform.drive.abci.validatorSet.llmqType; + + options.platform.drive.abci.instantLock = { + quorum: { + llmqType: networkConfig.get('platform.drive.abci.instantLock.quorum.llmqType'), + dkgInterval: networkConfig.get('platform.drive.abci.instantLock.quorum.dkgInterval'), + activeSigners: networkConfig.get('platform.drive.abci.instantLock.quorum.activeSigners'), + }, + }; + }); + return configFile; + }, }; } diff --git a/packages/dashmate/docker-compose.yml b/packages/dashmate/docker-compose.yml index a2fad5c55ae..08cc8cfd0d6 100644 --- a/packages/dashmate/docker-compose.yml +++ b/packages/dashmate/docker-compose.yml @@ -65,10 +65,15 @@ services: - MASTERNODE_REWARD_SHARES_SECOND_PUBLIC_KEY=${PLATFORM_MASTERNODE_REWARD_SHARES_SECOND_PUBLIC_KEY} - WITHDRAWALS_MASTER_PUBLIC_KEY=${PLATFORM_WITHDRAWALS_MASTER_PUBLIC_KEY} - WITHDRAWALS_SECOND_PUBLIC_KEY=${PLATFORM_WITHDRAWALS_SECOND_PUBLIC_KEY} - - VALIDATOR_SET_QUORUM_TYPE=${PLATFORM_DRIVE_ABCI_VALIDATOR_SET_LLMQ_TYPE:?err} - - CHAIN_LOCK_QUORUM_TYPE=${PLATFORM_DRIVE_ABCI_CHAIN_LOCK_LLMQ_TYPE:?err} - - CHAIN_LOCK_QUORUM_WINDOW=${PLATFORM_DRIVE_ABCI_CHAIN_LOCK_DKG_INTERVAL:?err} - - CHAIN_LOCK_QUORUM_SIZE=${PLATFORM_DRIVE_ABCI_CHAIN_LOCK_LLMQ_SIZE:?err} + - VALIDATOR_SET_QUORUM_TYPE=${PLATFORM_DRIVE_ABCI_VALIDATOR_SET_QUORUM_LLMQ_TYPE:?err} + - VALIDATOR_SET_QUORUM_WINDOW=${PLATFORM_DRIVE_ABCI_VALIDATOR_SET_QUORUM_DKG_INTERVAL:?err} + - VALIDATOR_SET_QUORUM_ACTIVE_SIGNERS=${PLATFORM_DRIVE_ABCI_VALIDATOR_SET_QUORUM_ACTIVE_SIGNERS:?err} + - CHAIN_LOCK_QUORUM_TYPE=${PLATFORM_DRIVE_ABCI_CHAIN_LOCK_QUORUM_LLMQ_TYPE:?err} + - CHAIN_LOCK_QUORUM_WINDOW=${PLATFORM_DRIVE_ABCI_CHAIN_LOCK_QUORUM_DKG_INTERVAL:?err} + - CHAIN_LOCK_QUORUM_ACTIVE_SIGNERS=${PLATFORM_DRIVE_ABCI_CHAIN_LOCK_QUORUM_ACTIVE_SIGNERS:?err} + - INSTANT_LOCK_QUORUM_TYPE=${PLATFORM_DRIVE_ABCI_INSTANT_LOCK_QUORUM_LLMQ_TYPE:?err} + - INSTANT_LOCK_QUORUM_WINDOW=${PLATFORM_DRIVE_ABCI_INSTANT_LOCK_QUORUM_DKG_INTERVAL:?err} + - INSTANT_LOCK_QUORUM_ACTIVE_SIGNERS=${PLATFORM_DRIVE_ABCI_INSTANT_LOCK_QUORUM_ACTIVE_SIGNERS:?err} - DB_PATH=/var/lib/dash/rs-drive-abci/db - ABCI_CONSENSUS_BIND_ADDRESS=tcp://0.0.0.0:26658 - GRPC_BIND_ADDRESS=0.0.0.0:26670 diff --git a/packages/dashmate/src/config/configJsonSchema.js b/packages/dashmate/src/config/configJsonSchema.js index b003a4aded4..de5d403298b 100644 --- a/packages/dashmate/src/config/configJsonSchema.js +++ b/packages/dashmate/src/config/configJsonSchema.js @@ -105,6 +105,23 @@ export default { additionalProperties: false, required: ['enabled', 'host', 'port'], }, + quorum: { + type: 'object', + properties: { + llmqType: { + type: 'integer', + enum: [1, 2, 3, 4, 5, 6, 100, 101, 102, 103, 104, 105, 106, 107], + }, + dkgInterval: { + type: 'integer', + }, + activeSigners: { + type: 'integer', + }, + }, + required: ['llmqType', 'dkgInterval', 'activeSigners'], + additionalProperties: false, + }, }, properties: { description: { @@ -766,34 +783,32 @@ export default { validatorSet: { type: 'object', properties: { - llmqType: { - type: 'number', - // https://github.com/dashpay/dashcore-lib/blob/843176fed9fc81feae43ccf319d99e2dd942fe1f/lib/constants/index.js#L50-L99 - enum: [1, 2, 3, 4, 5, 6, 100, 101, 102, 103, 104, 105, 106, 107], + quorum: { + $ref: '#/definitions/quorum', }, }, additionalProperties: false, - required: ['llmqType'], + required: ['quorum'], }, chainLock: { type: 'object', properties: { - llmqType: { - type: 'number', - // https://github.com/dashpay/dashcore-lib/blob/843176fed9fc81feae43ccf319d99e2dd942fe1f/lib/constants/index.js#L50-L99 - enum: [1, 2, 3, 4, 5, 6, 100, 101, 102, 103, 104, 105, 106, 107], + quorum: { + $ref: '#/definitions/quorum', }, - llmqSize: { - type: 'integer', - minimum: 0, - }, - dkgInterval: { - type: 'integer', - minimum: 0, + }, + additionalProperties: false, + required: ['quorum'], + }, + instantLock: { + type: 'object', + properties: { + quorum: { + $ref: '#/definitions/quorum', }, }, additionalProperties: false, - required: ['llmqType', 'llmqSize', 'dkgInterval'], + required: ['quorum'], }, epochTime: { type: 'integer', diff --git a/packages/dashmate/src/listr/tasks/setup/local/configureTenderdashTaskFactory.js b/packages/dashmate/src/listr/tasks/setup/local/configureTenderdashTaskFactory.js index af533570888..da5e7e66fc0 100644 --- a/packages/dashmate/src/listr/tasks/setup/local/configureTenderdashTaskFactory.js +++ b/packages/dashmate/src/listr/tasks/setup/local/configureTenderdashTaskFactory.js @@ -50,7 +50,7 @@ export default function configureTenderdashTaskFactory() { config.set( 'platform.drive.tenderdash.genesis.validator_quorum_type', - config.get('platform.drive.abci.validatorSet.llmqType'), + config.get('platform.drive.abci.validatorSet.quorum.llmqType'), ); }); }, diff --git a/packages/dashmate/src/listr/tasks/setup/local/enableCoreQuorumsTaskFactory.js b/packages/dashmate/src/listr/tasks/setup/local/enableCoreQuorumsTaskFactory.js index 9dd3f68699a..49fbbd47379 100644 --- a/packages/dashmate/src/listr/tasks/setup/local/enableCoreQuorumsTaskFactory.js +++ b/packages/dashmate/src/listr/tasks/setup/local/enableCoreQuorumsTaskFactory.js @@ -268,7 +268,7 @@ export default function enableCoreQuorumsTaskFactory(generateBlocks) { // eslint-disable-next-line prefer-destructuring ctx.quorumHash = quorumList[LLMQ_TYPE_TEST_PLATFORM][0]; - const llmqType = ctx.masternodeCoreServices[0].getConfig().get('platform.drive.abci.validatorSet.llmqType'); + const llmqType = ctx.masternodeCoreServices[0].getConfig().get('platform.drive.abci.validatorSet.quorum.llmqType'); const { result: quorumInfo } = await ctx.seedRpcClient.quorum('info', llmqType, ctx.quorumHash); diff --git a/packages/dashmate/test/unit/commands/config/set.spec.js b/packages/dashmate/test/unit/commands/config/set.spec.js index 94089cb9a77..67b8bef75a3 100644 --- a/packages/dashmate/test/unit/commands/config/set.spec.js +++ b/packages/dashmate/test/unit/commands/config/set.spec.js @@ -42,18 +42,18 @@ describe('Config set command', () => { const command = new ConfigSetCommand(); await command.runWithDependencies({ - option: 'platform.drive.abci.validatorSet.llmqType', + option: 'platform.drive.abci.validatorSet.quorum.llmqType', value: 107, }, flags, config); - expect(config.get('platform.drive.abci.validatorSet.llmqType')).to.equal(107); + expect(config.get('platform.drive.abci.validatorSet.quorum.llmqType')).to.equal(107); await command.runWithDependencies({ - option: 'platform.drive.abci.validatorSet.llmqType', + option: 'platform.drive.abci.validatorSet.quorum.llmqType', value: '107', }, flags, config); - expect(config.get('platform.drive.abci.validatorSet.llmqType')).to.equal(107); + expect(config.get('platform.drive.abci.validatorSet.quorum.llmqType')).to.equal(107); }); it('should allow setting booleans', async () => { From 3260d804a51a9bbaffdc160ce413e5bf744557c9 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 14:16:50 +0700 Subject: [PATCH 16/48] chore(dashmate): add missing rotation option and correct llmq type --- packages/dashmate/configs/defaults/getBaseConfigFactory.js | 3 +++ packages/dashmate/configs/defaults/getLocalConfigFactory.js | 5 ++++- .../dashmate/configs/defaults/getTestnetConfigFactory.js | 3 +++ packages/dashmate/configs/getConfigFileMigrationsFactory.js | 3 +++ packages/dashmate/docker-compose.yml | 3 +++ packages/dashmate/src/config/configJsonSchema.js | 5 ++++- packages/rs-drive-abci/.env.local | 2 +- 7 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/dashmate/configs/defaults/getBaseConfigFactory.js b/packages/dashmate/configs/defaults/getBaseConfigFactory.js index 15ece4162ac..7a9b50caed4 100644 --- a/packages/dashmate/configs/defaults/getBaseConfigFactory.js +++ b/packages/dashmate/configs/defaults/getBaseConfigFactory.js @@ -250,6 +250,7 @@ export default function getBaseConfigFactory(homeDir) { llmqType: 4, dkgInterval: 24, activeSigners: 24, + rotation: false, }, }, chainLock: { @@ -257,6 +258,7 @@ export default function getBaseConfigFactory(homeDir) { llmqType: 2, dkgInterval: 288, activeSigners: 4, + rotation: false, }, }, instantLock: { @@ -264,6 +266,7 @@ export default function getBaseConfigFactory(homeDir) { llmqType: 5, dkgInterval: 288, activeSigners: 32, + rotation: true, }, }, metrics: { diff --git a/packages/dashmate/configs/defaults/getLocalConfigFactory.js b/packages/dashmate/configs/defaults/getLocalConfigFactory.js index c5c1047a7ab..6148abbf866 100644 --- a/packages/dashmate/configs/defaults/getLocalConfigFactory.js +++ b/packages/dashmate/configs/defaults/getLocalConfigFactory.js @@ -74,6 +74,7 @@ export default function getLocalConfigFactory(getBaseConfig) { llmqType: 106, dkgInterval: 24, activeSigners: 2, + rotation: false, }, }, chainLock: { @@ -81,13 +82,15 @@ export default function getLocalConfigFactory(getBaseConfig) { llmqType: 100, dkgInterval: 24, activeSigners: 2, + rotation: false, }, }, instantLock: { quorum: { - llmqType: 100, + llmqType: 104, dkgInterval: 24, activeSigners: 2, + rotation: false, }, }, }, diff --git a/packages/dashmate/configs/defaults/getTestnetConfigFactory.js b/packages/dashmate/configs/defaults/getTestnetConfigFactory.js index b5712bc1bba..59210678ce1 100644 --- a/packages/dashmate/configs/defaults/getTestnetConfigFactory.js +++ b/packages/dashmate/configs/defaults/getTestnetConfigFactory.js @@ -59,6 +59,7 @@ export default function getTestnetConfigFactory(homeDir, getBaseConfig) { llmqType: 6, dkgInterval: 24, activeSigners: 24, + rotation: false, }, }, chainLock: { @@ -66,6 +67,7 @@ export default function getTestnetConfigFactory(homeDir, getBaseConfig) { llmqType: 1, dkgInterval: 24, activeSigners: 24, + rotation: false, }, }, instantLock: { @@ -73,6 +75,7 @@ export default function getTestnetConfigFactory(homeDir, getBaseConfig) { llmqType: 5, dkgInterval: 288, activeSigners: 32, + rotation: true, }, }, }, diff --git a/packages/dashmate/configs/getConfigFileMigrationsFactory.js b/packages/dashmate/configs/getConfigFileMigrationsFactory.js index f328e259d9b..664f9bcf3d8 100644 --- a/packages/dashmate/configs/getConfigFileMigrationsFactory.js +++ b/packages/dashmate/configs/getConfigFileMigrationsFactory.js @@ -640,6 +640,7 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs) llmqType: networkConfig.get('platform.drive.abci.chainLock.quorum.llmqType'), dkgInterval: networkConfig.get('platform.drive.abci.chainLock.quorum.dkgInterval'), activeSigners: networkConfig.get('platform.drive.abci.chainLock.quorum.activeSigners'), + rotation: networkConfig.get('platform.drive.abci.chainLock.quorum.rotation'), }; delete options.platform.drive.abci.chainLock.llmqType; @@ -650,6 +651,7 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs) llmqType: networkConfig.get('platform.drive.abci.validatorSet.quorum.llmqType'), dkgInterval: networkConfig.get('platform.drive.abci.validatorSet.quorum.dkgInterval'), activeSigners: networkConfig.get('platform.drive.abci.validatorSet.quorum.activeSigners'), + rotation: networkConfig.get('platform.drive.abci.validatorSet.quorum.rotation'), }; delete options.platform.drive.abci.validatorSet.llmqType; @@ -659,6 +661,7 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs) llmqType: networkConfig.get('platform.drive.abci.instantLock.quorum.llmqType'), dkgInterval: networkConfig.get('platform.drive.abci.instantLock.quorum.dkgInterval'), activeSigners: networkConfig.get('platform.drive.abci.instantLock.quorum.activeSigners'), + rotation: networkConfig.get('platform.drive.abci.instantLock.quorum.rotation'), }, }; }); diff --git a/packages/dashmate/docker-compose.yml b/packages/dashmate/docker-compose.yml index 08cc8cfd0d6..5d706fea765 100644 --- a/packages/dashmate/docker-compose.yml +++ b/packages/dashmate/docker-compose.yml @@ -68,12 +68,15 @@ services: - VALIDATOR_SET_QUORUM_TYPE=${PLATFORM_DRIVE_ABCI_VALIDATOR_SET_QUORUM_LLMQ_TYPE:?err} - VALIDATOR_SET_QUORUM_WINDOW=${PLATFORM_DRIVE_ABCI_VALIDATOR_SET_QUORUM_DKG_INTERVAL:?err} - VALIDATOR_SET_QUORUM_ACTIVE_SIGNERS=${PLATFORM_DRIVE_ABCI_VALIDATOR_SET_QUORUM_ACTIVE_SIGNERS:?err} + - VALIDATOR_SET_QUORUM_ROTATION=${PLATFORM_DRIVE_ABCI_VALIDATOR_SET_QUORUM_ROTATION:?err} - CHAIN_LOCK_QUORUM_TYPE=${PLATFORM_DRIVE_ABCI_CHAIN_LOCK_QUORUM_LLMQ_TYPE:?err} - CHAIN_LOCK_QUORUM_WINDOW=${PLATFORM_DRIVE_ABCI_CHAIN_LOCK_QUORUM_DKG_INTERVAL:?err} - CHAIN_LOCK_QUORUM_ACTIVE_SIGNERS=${PLATFORM_DRIVE_ABCI_CHAIN_LOCK_QUORUM_ACTIVE_SIGNERS:?err} + - CHAIN_LOCK_QUORUM_ROTATION=${PLATFORM_DRIVE_ABCI_CHAIN_LOCK_QUORUM_ROTATION:?err} - INSTANT_LOCK_QUORUM_TYPE=${PLATFORM_DRIVE_ABCI_INSTANT_LOCK_QUORUM_LLMQ_TYPE:?err} - INSTANT_LOCK_QUORUM_WINDOW=${PLATFORM_DRIVE_ABCI_INSTANT_LOCK_QUORUM_DKG_INTERVAL:?err} - INSTANT_LOCK_QUORUM_ACTIVE_SIGNERS=${PLATFORM_DRIVE_ABCI_INSTANT_LOCK_QUORUM_ACTIVE_SIGNERS:?err} + - INSTANT_LOCK_QUORUM_ROTATION=${PLATFORM_DRIVE_ABCI_INSTANT_LOCK_QUORUM_ROTATION:?err} - DB_PATH=/var/lib/dash/rs-drive-abci/db - ABCI_CONSENSUS_BIND_ADDRESS=tcp://0.0.0.0:26658 - GRPC_BIND_ADDRESS=0.0.0.0:26670 diff --git a/packages/dashmate/src/config/configJsonSchema.js b/packages/dashmate/src/config/configJsonSchema.js index de5d403298b..ff0b84486c6 100644 --- a/packages/dashmate/src/config/configJsonSchema.js +++ b/packages/dashmate/src/config/configJsonSchema.js @@ -118,8 +118,11 @@ export default { activeSigners: { type: 'integer', }, + rotation: { + type: 'boolean', + }, }, - required: ['llmqType', 'dkgInterval', 'activeSigners'], + required: ['llmqType', 'dkgInterval', 'activeSigners', 'rotation'], additionalProperties: false, }, }, diff --git a/packages/rs-drive-abci/.env.local b/packages/rs-drive-abci/.env.local index 1c0ff965654..739b5b8d214 100644 --- a/packages/rs-drive-abci/.env.local +++ b/packages/rs-drive-abci/.env.local @@ -41,7 +41,7 @@ CHAIN_LOCK_QUORUM_WINDOW=24 CHAIN_LOCK_QUORUM_ACTIVE_SIGNERS=2 CHAIN_LOCK_QUORUM_ROTATION=false -INSTANT_LOCK_QUORUM_TYPE=llmq_test +INSTANT_LOCK_QUORUM_TYPE=llmq_test_instantsend INSTANT_LOCK_QUORUM_SIZE=3 INSTANT_LOCK_QUORUM_WINDOW=24 INSTANT_LOCK_QUORUM_ACTIVE_SIGNERS=2 From 3462a77ded55756e4be0e6c616ce1a91fb15d7b6 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 14:18:25 +0700 Subject: [PATCH 17/48] docs: add todo for a bug --- .../make_sure_core_is_synced_to_chain_lock/v0/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/make_sure_core_is_synced_to_chain_lock/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/make_sure_core_is_synced_to_chain_lock/v0/mod.rs index 4ca9f9705cb..f92183277b4 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/make_sure_core_is_synced_to_chain_lock/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/make_sure_core_is_synced_to_chain_lock/v0/mod.rs @@ -18,6 +18,8 @@ where ) -> Result { let given_chain_lock_height = chain_lock.block_height; // We need to make sure core is synced to the core height we see as valid for the state transitions + + // TODO: submit_chain_lock responds with invalid signature. We should handle it properly and return CoreSyncStatus let best_chain_locked_height = self.core_rpc.submit_chain_lock(chain_lock)?; Ok(if best_chain_locked_height >= given_chain_lock_height { CoreSyncStatus::Done From d88fda3a1a833b1b952423dce1d2cb2d8492036b Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 14:37:28 +0700 Subject: [PATCH 18/48] chore: enhance logging for IS lock signature verification --- .../verify_recent_signature_locally/v0/mod.rs | 146 +++++++++++++----- .../asset_lock/proof/validate/instant/mod.rs | 4 +- .../src/platform_types/core_quorum_set/mod.rs | 1 + .../core_quorum_set/v0/quorum_set.rs | 8 +- .../core_quorum_set/v0/quorums.rs | 33 +++- 5 files changed, 146 insertions(+), 46 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs index e8800c2e9bb..39c55543983 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs @@ -1,30 +1,40 @@ use dpp::bls_signatures::G2Element; +use std::fmt::{Debug, Formatter}; use dpp::dashcore::hashes::{sha256d, Hash, HashEngine}; use dpp::dashcore::InstantLock; +use crate::error::execution::ExecutionError; use crate::error::Error; use crate::error::serialization::SerializationError; -use crate::platform_types::core_quorum_set::CoreQuorumSetV0Methods; +use crate::platform_types::core_quorum_set::{CoreQuorumSetV0Methods, SIGN_OFFSET}; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; -const SIGN_OFFSET: u32 = 8; - #[inline(always)] pub(super) fn verify_recent_instant_lock_signature_locally_v0( instant_lock: &InstantLock, platform_state: &PlatformState, ) -> Result { // First verify that the signature conforms to a signature - let Ok(signature) = G2Element::from_bytes(instant_lock.signature.as_bytes()) else { - return Ok(false); + let signature = match G2Element::from_bytes(instant_lock.signature.as_bytes()) { + Ok(signature) => signature, + Err(e) => { + tracing::trace!( + instant_lock = ?InstantLockDebug(instant_lock), + "Invalid instant Lock {} signature format: {}", + instant_lock.txid, + e, + ); + + return Ok(false); + } }; - let instant_lock_height = platform_state.last_committed_core_height(); + let signing_height = platform_state.last_committed_core_height(); - let verification_height = instant_lock_height.saturating_sub(SIGN_OFFSET); + let verification_height = signing_height.saturating_sub(SIGN_OFFSET); let request_id = instant_lock.request_id().map_err(|e| { Error::Serialization(SerializationError::CorruptedSerialization(format!( @@ -37,39 +47,99 @@ pub(super) fn verify_recent_instant_lock_signature_locally_v0( // Based on the deterministic masternode list at the given height, a quorum must be selected // that was active at the time this block was mined let selected_quorums = - quorum_set.select_quorums(instant_lock_height, verification_height, request_id); - - for (quorum_hash, quorum) in selected_quorums { - // The signature must verify against the quorum public key and SHA256(llmqType, quorumHash, SHA256(height), txId). - // llmqType and quorumHash must be taken from the quorum selected in 1. - let mut engine = sha256d::Hash::engine(); + quorum_set.select_quorums(signing_height, verification_height, request_id); - let mut reversed_quorum_hash = quorum_hash.to_byte_array().to_vec(); - reversed_quorum_hash.reverse(); - - engine.input(&[quorum_set.config().quorum_type as u8]); - engine.input(reversed_quorum_hash.as_slice()); - engine.input(request_id.as_byte_array()); - engine.input(instant_lock.txid.as_byte_array()); + if selected_quorums.is_empty() { + return Err(Error::Execution(ExecutionError::CorruptedCodeExecution( + "No quorums selected for instant lock signature verification for specified height", + ))); + }; - let message_digest = sha256d::Hash::from_engine(engine); + let is_signature_valid = selected_quorums + .enumerate() + .find(|(i, (quorum_hash, quorum))| { + // The signature must verify against the quorum public key and SHA256(llmqType, quorumHash, SHA256(height), txId). + // llmqType and quorumHash must be taken from the quorum selected in 1. + let mut engine = sha256d::Hash::engine(); + + let mut reversed_quorum_hash = quorum_hash.to_byte_array().to_vec(); + reversed_quorum_hash.reverse(); + + engine.input(&[quorum_set.config().quorum_type as u8]); + engine.input(reversed_quorum_hash.as_slice()); + engine.input(request_id.as_byte_array()); + engine.input(instant_lock.txid.as_byte_array()); + + let message_digest = sha256d::Hash::from_engine(engine); + + if quorum + .public_key + .verify(&signature, message_digest.as_ref()) + { + return true; + } + + if tracing::enabled!(tracing::Level::TRACE) { + tracing::trace!( + quorums_iteration = i + 1, + instant_lock = ?InstantLockDebug(instant_lock), + quorum_hash = quorum_hash.to_string(), + quorum_config = ?quorum_set.config(), + quorum = ?quorum, + request_id = request_id.to_string(), + message_digest = message_digest.to_string(), + signing_height, + verification_height, + "Instant Lock {} signature verification failed", + instant_lock.txid, + ); + }; + + false + }) + .or_else(|| { + if tracing::enabled!(tracing::Level::TRACE) { + tracing::trace!( + instant_lock = ?InstantLockDebug(instant_lock), + request_id = request_id.to_string(), + quorum_set = ?quorum_set, + signing_height, + verification_height, + "No eligible quorums found for instant Lock {} signature", + instant_lock.txid, + ); + }; + + None + }) + .is_some(); + + Ok(is_signature_valid) +} - if quorum - .public_key - .verify(&signature, message_digest.as_ref()) - { - return Ok(true); - } +// TODO: The best way is to implement Value trait for InstantLock and hashes +// in dashcore + +/// An additional struct to implement Debug for InstantLock with hex strings +/// instead of byte arrays +struct InstantLockDebug<'a>(&'a InstantLock); + +impl<'a> Debug for InstantLockDebug<'a> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let instant_lock = &self.0; + f.debug_struct("InstantLock") + .field("version", &instant_lock.version) + .field( + "inputs", + &instant_lock + .inputs + .iter() + .map(|input| input.to_string()) + .collect::>(), + ) + .field("txid", &instant_lock.txid.to_string()) + .field("cyclehash", &instant_lock.cyclehash.to_string()) + .field("signature", &instant_lock.signature.to_string()) + .finish() } - - tracing::debug!( - ?instant_lock, - instant_lock_height, - verification_height, - "Instant Lock {} signature verification failed at height {}", - instant_lock.txid, - instant_lock_height, - ); - - Ok(false) } diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs index 5b599f9db1f..7cbd5bad4fa 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs @@ -62,11 +62,11 @@ impl AssetLockProofValidation for InstantAssetLockProof { // IO. This is done to prevent DoS attacks on slow verify instant lock signature Core RPC method. // In case of failed signature verification (or any knowing the fact that signing quorum is old), // we expect clients to use ChainAssetLockProof. - let is_instant_lock_signature_valid = self + let is_valid = self .instant_lock() .verify_recent_signature_locally(platform_ref.state, platform_version)?; - if !is_instant_lock_signature_valid { + if !is_valid { return Ok(ConsensusValidationResult::new_with_error( InvalidInstantAssetLockProofSignatureError::new().into(), )); diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs index b07f652e66a..41268b8a0c9 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs @@ -4,6 +4,7 @@ use crate::config::QuorumLikeConfig; use crate::platform_types::core_quorum_set::v0::for_saving::CoreQuorumSetForSavingV0; pub use crate::platform_types::core_quorum_set::v0::quorum_set::{ CoreQuorumSetV0, CoreQuorumSetV0Methods, QuorumConfig, QuorumsVerificationDataIterator, + SIGN_OFFSET, }; pub use crate::platform_types::core_quorum_set::v0::quorums::{ Quorum, Quorums, SigningQuorum, ThresholdBlsPublicKey, VerificationQuorum, diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs index 702fe572e2d..b5aefa49ba4 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs @@ -5,6 +5,9 @@ use dashcore_rpc::json::QuorumType; use dpp::dashcore::{QuorumHash, QuorumSigningRequestId}; use std::vec::IntoIter; +/// Offset for signature verification +pub const SIGN_OFFSET: u32 = 8; + /// Previously obtained quorums and heights. Required for signature verification #[derive(Debug, Clone)] pub(super) struct PreviousQuorumsV0 { @@ -192,7 +195,7 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { let change_quorum_height = previous.updated_at_core_height; let previous_quorums_change_height = previous.previous_change_height; - if signing_height > 8 && verification_height >= change_quorum_height { + if signing_height > SIGN_OFFSET && verification_height >= change_quorum_height { // in this case we are sure that we should be targeting the current quorum // We updated core chain lock height from 100 to 105, new chain lock comes in for block 114 // ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) ------ 106 (new chain lock verification height 114 - 8) @@ -202,7 +205,8 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { // We should also use current quorums, this is because at 105 we are sure new chain lock validating quorums are active quorums.push(&self.current_quorums); should_be_verifiable = true; - } else if signing_height > 8 && verification_height <= previous_quorum_height { + } else if signing_height > SIGN_OFFSET && verification_height <= previous_quorum_height + { should_be_verifiable = previous_quorums_change_height .map(|previous_quorums_change_height| { verification_height > previous_quorums_change_height diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs index 5ff887cd64b..9b30e90cc8f 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs @@ -4,6 +4,7 @@ use dpp::dashcore::bls_sig_utils::BLSSignature; use dpp::dashcore::{QuorumHash, Txid}; use std::collections::BTreeMap; use std::convert::TryInto; +use std::fmt::Debug; pub use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; @@ -12,7 +13,7 @@ use crate::platform_types::core_quorum_set::QuorumConfig; use dpp::dashcore::hashes::{sha256d, Hash, HashEngine}; /// Quorum per hash -#[derive(Debug, Clone, Deref, DerefMut, From)] +#[derive(Clone, Deref, DerefMut, From)] pub struct Quorums(BTreeMap); impl Default for Quorums { @@ -113,15 +114,27 @@ impl Quorums { // Take last n bits of b let mask = (1u64 << n) - 1; - let signer = mask & (b >> (64 - n - 1)); + let signer = (mask & (b >> (64 - n - 1))) as u32; self.0 .iter() - .find(|(_, quorum)| quorum.index() == Some(signer as u32)) + .find(|(_, quorum)| quorum.index() == Some(signer)) .map(|(quorum_hash, quorum)| (*quorum_hash, quorum)) } } +impl Debug for Quorums { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_map() + .entries( + self.0 + .iter() + .map(|(quorum_hash, quorum)| (quorum_hash.to_string(), quorum)), + ) + .finish() + } +} + /// Quorum trait for Quorums collection pub trait Quorum { /// Index is present only for rotated quorums (DIP24) @@ -129,7 +142,7 @@ pub trait Quorum { } /// Quorum for signature verification -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct VerificationQuorum { /// Index is present only for rotated quorums (DIP24) pub index: Option, @@ -139,6 +152,18 @@ pub struct VerificationQuorum { pub public_key: ThresholdBlsPublicKey, } +impl Debug for VerificationQuorum { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("VerificationQuorum") + .field("index", &self.index) + .field( + "public_key", + &hex::encode(*self.public_key.to_bytes()).to_string(), + ) + .finish() + } +} + impl Quorum for VerificationQuorum { fn index(&self) -> Option { self.index From 29b26428f6e6379e2c60bfd8f6cda6d55e7be6a9 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 14:42:51 +0700 Subject: [PATCH 19/48] chore: kick off CI From fc39b7209bf497b88de3d400d933b3241f5a204c Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 14:44:07 +0700 Subject: [PATCH 20/48] chore: kick off CI From dc27176f004104c667f997e89db18b28ecbe0119 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 14:58:12 +0700 Subject: [PATCH 21/48] style: remove unused import --- packages/dashmate/configs/defaults/getBaseConfigFactory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dashmate/configs/defaults/getBaseConfigFactory.js b/packages/dashmate/configs/defaults/getBaseConfigFactory.js index 7a9b50caed4..f52fa4ab2ed 100644 --- a/packages/dashmate/configs/defaults/getBaseConfigFactory.js +++ b/packages/dashmate/configs/defaults/getBaseConfigFactory.js @@ -16,7 +16,7 @@ import semver from 'semver'; import fs from 'fs'; import { NETWORK_MAINNET, - NETWORK_TESTNET, PACKAGE_ROOT_DIR, + PACKAGE_ROOT_DIR, } from '../../src/constants.js'; import Config from '../../src/config/Config.js'; From 7ddb81cfea56472ae13d7bd750c9463833e0c8c9 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 15:02:48 +0700 Subject: [PATCH 22/48] chore: rephrase invalid signature error --- .../invalid_instant_asset_lock_proof_signature_error.rs | 2 +- .../common/asset_lock/proof/validate/instant/mod.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/rs-dpp/src/errors/consensus/basic/identity/invalid_instant_asset_lock_proof_signature_error.rs b/packages/rs-dpp/src/errors/consensus/basic/identity/invalid_instant_asset_lock_proof_signature_error.rs index 130349d16a8..8d72de7772b 100644 --- a/packages/rs-dpp/src/errors/consensus/basic/identity/invalid_instant_asset_lock_proof_signature_error.rs +++ b/packages/rs-dpp/src/errors/consensus/basic/identity/invalid_instant_asset_lock_proof_signature_error.rs @@ -18,7 +18,7 @@ use bincode::{Decode, Encode}; PlatformSerialize, PlatformDeserialize, )] -#[error("Invalid instant lock proof signature")] +#[error("Instant lock proof signature is invalid or wasn't created recently. Pleases try chain asset lock proof instead.")] #[platform_serialize(unversioned)] pub struct InvalidInstantAssetLockProofSignatureError; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs index 7cbd5bad4fa..b6793cabfe4 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs @@ -54,7 +54,6 @@ impl AssetLockProofValidation for InstantAssetLockProof { } // TODO: Shouldn't we add an operation for fees? - // TODO: The error should say that instant lock probably invalid and we should use ChainAssetLockProof // This is a limited verification and will work properly only for recently signed instant locks. // Even valid instant locks that was signed some time ago will be considered invalid due to limited From fd1f994fb8f836daf0464ca33b72c4f532a21785 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 15:04:15 +0700 Subject: [PATCH 23/48] chore: remove unused trait implementation --- packages/rs-drive-abci/src/mimic/test_quorum.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/rs-drive-abci/src/mimic/test_quorum.rs b/packages/rs-drive-abci/src/mimic/test_quorum.rs index e2a9e6c411e..3cb6b50a740 100644 --- a/packages/rs-drive-abci/src/mimic/test_quorum.rs +++ b/packages/rs-drive-abci/src/mimic/test_quorum.rs @@ -272,9 +272,3 @@ impl From<&TestQuorumInfo> for QuorumInfoResult { } } } - -impl Quorum for TestQuorumInfo { - fn index(&self) -> Option { - self.quorum_index - } -} From 96360ff7d8cd9a37f48907314af3f2739185108c Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 15:28:41 +0700 Subject: [PATCH 24/48] chore: versioning for CoreQuorumSet --- .../engine/initialization/init_chain/v0/mod.rs | 2 +- .../v0/mod.rs | 3 ++- .../process_block_fees/v0/mod.rs | 3 ++- .../src/platform_types/core_quorum_set/mod.rs | 18 ++++++++++++++---- .../src/platform_types/platform/mod.rs | 2 +- .../src/platform_types/platform_state/mod.rs | 10 ++++++---- .../platform_types/platform_state/v0/mod.rs | 18 +++++++++++------- .../src/version/drive_abci_versions.rs | 1 + .../src/version/mocks/v2_test.rs | 1 + .../src/version/mocks/v3_test.rs | 1 + packages/rs-platform-version/src/version/v1.rs | 1 + 11 files changed, 41 insertions(+), 19 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs b/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs index 200fa588a4f..75bd88a55cf 100644 --- a/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs @@ -53,7 +53,7 @@ where request.initial_protocol_version, request.initial_protocol_version, &self.config, - ); + )?; let genesis_block_info = BlockInfo { height: request.initial_height, diff --git a/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/add_process_epoch_change_operations/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/add_process_epoch_change_operations/v0/mod.rs index 37da6433bd2..3e34b5c5822 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/add_process_epoch_change_operations/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/add_process_epoch_change_operations/v0/mod.rs @@ -253,7 +253,8 @@ mod tests { INITIAL_PROTOCOL_VERSION, INITIAL_PROTOCOL_VERSION, &platform.config, - ); + ) + .expect("failed to create platform state"); let block_execution_context = BlockExecutionContextV0 { block_state_info: block_info.clone().into(), diff --git a/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/process_block_fees/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/process_block_fees/v0/mod.rs index 82deb3637f4..d6df6c83012 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/process_block_fees/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/block_fee_processing/process_block_fees/v0/mod.rs @@ -284,7 +284,8 @@ mod tests { INITIAL_PROTOCOL_VERSION, INITIAL_PROTOCOL_VERSION, &platform.config, - ); + ) + .expect("failed to create default platform state"); let block_execution_context = BlockExecutionContextV0 { block_state_info: block_info.clone().into(), diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs index 41268b8a0c9..a71bdea531d 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs @@ -1,6 +1,8 @@ mod v0; use crate::config::QuorumLikeConfig; +use crate::error::execution::ExecutionError; +use crate::error::Error; use crate::platform_types::core_quorum_set::v0::for_saving::CoreQuorumSetForSavingV0; pub use crate::platform_types::core_quorum_set::v0::quorum_set::{ CoreQuorumSetV0, CoreQuorumSetV0Methods, QuorumConfig, QuorumsVerificationDataIterator, @@ -23,10 +25,18 @@ pub enum CoreQuorumSet { impl CoreQuorumSet { /// Create a default SignatureVerificationQuorums - pub fn new(config: &impl QuorumLikeConfig, platform_version: &PlatformVersion) -> Self { - // TODO: default for platform version - - CoreQuorumSetV0::new(config).into() + pub fn new( + config: &impl QuorumLikeConfig, + platform_version: &PlatformVersion, + ) -> Result { + match platform_version.drive_abci.structs.core_quorum_set { + 0 => Ok(CoreQuorumSetV0::new(config).into()), + version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { + method: "CoreQuorumSet.new".to_string(), + known_versions: vec![0], + received: version, + })), + } } } diff --git a/packages/rs-drive-abci/src/platform_types/platform/mod.rs b/packages/rs-drive-abci/src/platform_types/platform/mod.rs index cbf1a5685a8..24c2dba3df8 100644 --- a/packages/rs-drive-abci/src/platform_types/platform/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform/mod.rs @@ -250,7 +250,7 @@ impl Platform { current_protocol_version_in_consensus, next_epoch_protocol_version, &config, - ); + )?; let height = platform_state.last_committed_block_height(); diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs index b92f24a9a74..33b81684557 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs @@ -121,14 +121,16 @@ impl PlatformState { current_protocol_version_in_consensus: ProtocolVersion, next_epoch_protocol_version: ProtocolVersion, config: &PlatformConfig, - ) -> PlatformState { + ) -> Result { //todo find the current Platform state for the protocol version - PlatformStateV0::default_with_protocol_versions( + let state = PlatformStateV0::default_with_protocol_versions( current_protocol_version_in_consensus, next_epoch_protocol_version, config, - ) - .into() + )? + .into(); + + Ok(state) } /// Retrieve version 0, or an error if not currently on version 0 diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs index ceaf5421e64..4b29581d35f 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs @@ -231,26 +231,30 @@ impl PlatformStateV0 { current_protocol_version_in_consensus: ProtocolVersion, next_epoch_protocol_version: ProtocolVersion, config: &PlatformConfig, - ) -> PlatformStateV0 { - let platform_version = PlatformVersion::get(current_protocol_version_in_consensus) - .expect("invalid protocol version"); + ) -> Result { + let platform_version = PlatformVersion::get(current_protocol_version_in_consensus)?; - PlatformStateV0 { + let state = PlatformStateV0 { last_committed_block_info: None, current_protocol_version_in_consensus, next_epoch_protocol_version, current_validator_set_quorum_hash: QuorumHash::all_zeros(), next_validator_set_quorum_hash: None, validator_sets: Default::default(), - chain_lock_validating_quorums: CoreQuorumSet::new(&config.chain_lock, platform_version), + chain_lock_validating_quorums: CoreQuorumSet::new( + &config.chain_lock, + platform_version, + )?, instant_lock_validating_quorums: CoreQuorumSet::new( &config.instant_lock, platform_version, - ), + )?, full_masternode_list: Default::default(), hpmn_masternode_list: Default::default(), genesis_block_info: None, - } + }; + + Ok(state) } } diff --git a/packages/rs-platform-version/src/version/drive_abci_versions.rs b/packages/rs-platform-version/src/version/drive_abci_versions.rs index e622ddded9a..4d93d94b353 100644 --- a/packages/rs-platform-version/src/version/drive_abci_versions.rs +++ b/packages/rs-platform-version/src/version/drive_abci_versions.rs @@ -53,6 +53,7 @@ pub struct DriveAbciStructureVersions { pub state_transition_execution_context: FeatureVersion, pub commit: FeatureVersion, pub masternode: FeatureVersion, + pub core_quorum_set: FeatureVersion, } #[derive(Clone, Debug, Default)] diff --git a/packages/rs-platform-version/src/version/mocks/v2_test.rs b/packages/rs-platform-version/src/version/mocks/v2_test.rs index 3ee5e89dfab..d5cdc416ab9 100644 --- a/packages/rs-platform-version/src/version/mocks/v2_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v2_test.rs @@ -502,6 +502,7 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { state_transition_execution_context: 0, commit: 0, masternode: 0, + core_quorum_set: 0, }, methods: DriveAbciMethodVersions { engine: DriveAbciEngineMethodVersions { diff --git a/packages/rs-platform-version/src/version/mocks/v3_test.rs b/packages/rs-platform-version/src/version/mocks/v3_test.rs index 5e4025704fa..ca10d64fd0e 100644 --- a/packages/rs-platform-version/src/version/mocks/v3_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v3_test.rs @@ -502,6 +502,7 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { state_transition_execution_context: 0, commit: 0, masternode: 0, + core_quorum_set: 0, }, methods: DriveAbciMethodVersions { engine: DriveAbciEngineMethodVersions { diff --git a/packages/rs-platform-version/src/version/v1.rs b/packages/rs-platform-version/src/version/v1.rs index ec0f8291f79..ebaaa406aa0 100644 --- a/packages/rs-platform-version/src/version/v1.rs +++ b/packages/rs-platform-version/src/version/v1.rs @@ -501,6 +501,7 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { state_transition_execution_context: 0, commit: 0, masternode: 0, + core_quorum_set: 0, }, methods: DriveAbciMethodVersions { engine: DriveAbciEngineMethodVersions { From 93a604c1c659361e8d6bdb31d720d19bb3b02ff1 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 15:32:44 +0700 Subject: [PATCH 25/48] chore: bump version to 1.0.0-pr.1875.1 --- Cargo.lock | 46 +++++++++---------- package.json | 2 +- packages/bench-suite/package.json | 2 +- packages/dapi-grpc/Cargo.toml | 2 +- packages/dapi-grpc/package.json | 2 +- packages/dapi/package.json | 2 +- packages/dash-spv/package.json | 2 +- packages/dashmate/package.json | 2 +- packages/dashpay-contract/Cargo.toml | 2 +- packages/dashpay-contract/package.json | 2 +- packages/data-contracts/Cargo.toml | 2 +- packages/dpns-contract/Cargo.toml | 2 +- packages/dpns-contract/package.json | 2 +- packages/feature-flags-contract/Cargo.toml | 2 +- packages/feature-flags-contract/package.json | 2 +- packages/js-dapi-client/package.json | 2 +- packages/js-dash-sdk/package.json | 2 +- packages/js-grpc-common/package.json | 2 +- .../Cargo.toml | 2 +- .../package.json | 2 +- packages/platform-test-suite/package.json | 2 +- packages/rs-dapi-client/Cargo.toml | 2 +- packages/rs-dapi-grpc-macros/Cargo.toml | 2 +- packages/rs-dpp/Cargo.toml | 2 +- packages/rs-drive-abci/Cargo.toml | 2 +- packages/rs-drive-proof-verifier/Cargo.toml | 2 +- packages/rs-drive/Cargo.toml | 2 +- .../Cargo.toml | 2 +- packages/rs-platform-serialization/Cargo.toml | 2 +- .../rs-platform-value-convertible/Cargo.toml | 2 +- packages/rs-platform-value/Cargo.toml | 2 +- packages/rs-platform-version/Cargo.toml | 2 +- packages/rs-platform-versioning/Cargo.toml | 2 +- packages/rs-sdk/Cargo.toml | 2 +- packages/simple-signer/Cargo.toml | 2 +- packages/strategy-tests/Cargo.toml | 2 +- packages/wallet-lib/package.json | 2 +- packages/wasm-dpp/Cargo.toml | 2 +- packages/wasm-dpp/package.json | 2 +- packages/withdrawals-contract/Cargo.toml | 2 +- packages/withdrawals-contract/package.json | 2 +- 41 files changed, 63 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19c63f23809..ca5f0100e14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1244,7 +1244,7 @@ dependencies = [ [[package]] name = "dapi-grpc" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "dapi-grpc-macros", "futures-core", @@ -1260,7 +1260,7 @@ dependencies = [ [[package]] name = "dapi-grpc-macros" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "dapi-grpc", "heck 0.5.0", @@ -1305,7 +1305,7 @@ dependencies = [ [[package]] name = "dash-sdk" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "async-trait", "base64 0.22.0", @@ -1402,7 +1402,7 @@ dependencies = [ [[package]] name = "dashpay-contract" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "platform-value", "platform-version", @@ -1412,7 +1412,7 @@ dependencies = [ [[package]] name = "data-contracts" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "dashpay-contract", "dpns-contract", @@ -1536,7 +1536,7 @@ checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" [[package]] name = "dpns-contract" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "platform-value", "platform-version", @@ -1546,7 +1546,7 @@ dependencies = [ [[package]] name = "dpp" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "anyhow", "assert_matches", @@ -1598,7 +1598,7 @@ dependencies = [ [[package]] name = "drive" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "arc-swap", "base64 0.21.7", @@ -1634,7 +1634,7 @@ dependencies = [ [[package]] name = "drive-abci" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "arc-swap", "assert_matches", @@ -1690,7 +1690,7 @@ dependencies = [ [[package]] name = "drive-proof-verifier" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "dapi-grpc", "dpp", @@ -1908,7 +1908,7 @@ dependencies = [ [[package]] name = "feature-flags-contract" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "platform-value", "platform-version", @@ -2985,7 +2985,7 @@ dependencies = [ [[package]] name = "masternode-reward-shares-contract" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "platform-value", "platform-version", @@ -3546,7 +3546,7 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "platform-serialization" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "bincode 2.0.0-rc.3", "platform-version", @@ -3554,7 +3554,7 @@ dependencies = [ [[package]] name = "platform-serialization-derive" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "proc-macro2", "quote", @@ -3564,7 +3564,7 @@ dependencies = [ [[package]] name = "platform-value" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "base64 0.22.0", "bincode 2.0.0-rc.3", @@ -3585,7 +3585,7 @@ dependencies = [ [[package]] name = "platform-value-convertible" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "quote", "syn 2.0.60", @@ -3593,14 +3593,14 @@ dependencies = [ [[package]] name = "platform-version" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "thiserror", ] [[package]] name = "platform-versioning" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "proc-macro2", "quote", @@ -4199,7 +4199,7 @@ dependencies = [ [[package]] name = "rs-dapi-client" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "backon", "chrono", @@ -4668,7 +4668,7 @@ checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" [[package]] name = "simple-signer" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "bincode 2.0.0-rc.3", "dashcore-rpc", @@ -4776,7 +4776,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "strategy-tests" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "bincode 2.0.0-rc.3", "dpp", @@ -5791,7 +5791,7 @@ checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" [[package]] name = "wasm-dpp" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "anyhow", "async-trait", @@ -6341,7 +6341,7 @@ dependencies = [ [[package]] name = "withdrawals-contract" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" dependencies = [ "num_enum", "platform-value", diff --git a/package.json b/package.json index b37fc18a9dc..c4b361ad95d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/platform", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "private": true, "scripts": { "setup": "yarn install && yarn run build && yarn run configure", diff --git a/packages/bench-suite/package.json b/packages/bench-suite/package.json index 53c0e10d0cb..c44b36a5dde 100644 --- a/packages/bench-suite/package.json +++ b/packages/bench-suite/package.json @@ -1,7 +1,7 @@ { "name": "@dashevo/bench-suite", "private": true, - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "Dash Platform benchmark tool", "scripts": { "bench": "node ./bin/bench.js", diff --git a/packages/dapi-grpc/Cargo.toml b/packages/dapi-grpc/Cargo.toml index 21e63ea3e3e..a64ec3cb308 100644 --- a/packages/dapi-grpc/Cargo.toml +++ b/packages/dapi-grpc/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dapi-grpc" description = "GRPC client for Dash Platform" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" authors = [ "Samuel Westrich ", "Igor Markin ", diff --git a/packages/dapi-grpc/package.json b/packages/dapi-grpc/package.json index 511bd177a77..f2b370681c8 100644 --- a/packages/dapi-grpc/package.json +++ b/packages/dapi-grpc/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dapi-grpc", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "DAPI GRPC definition file and generated clients", "browser": "browser.js", "main": "node.js", diff --git a/packages/dapi/package.json b/packages/dapi/package.json index ab442480567..c649d395ea2 100644 --- a/packages/dapi/package.json +++ b/packages/dapi/package.json @@ -1,7 +1,7 @@ { "name": "@dashevo/dapi", "private": true, - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "A decentralized API for the Dash network", "scripts": { "api": "node scripts/api.js", diff --git a/packages/dash-spv/package.json b/packages/dash-spv/package.json index 35cac4b1fd6..2da45ae23b0 100644 --- a/packages/dash-spv/package.json +++ b/packages/dash-spv/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dash-spv", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "Repository containing SPV functions used by @dashevo", "main": "index.js", "scripts": { diff --git a/packages/dashmate/package.json b/packages/dashmate/package.json index ec527ce5054..6a32584c7e7 100644 --- a/packages/dashmate/package.json +++ b/packages/dashmate/package.json @@ -1,6 +1,6 @@ { "name": "dashmate", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "Distribution package for Dash node installation", "scripts": { "lint": "eslint .", diff --git a/packages/dashpay-contract/Cargo.toml b/packages/dashpay-contract/Cargo.toml index 115444dcd91..940605db1a2 100644 --- a/packages/dashpay-contract/Cargo.toml +++ b/packages/dashpay-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dashpay-contract" description = "DashPay data contract schema and tools" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/dashpay-contract/package.json b/packages/dashpay-contract/package.json index 7335e9a3c18..6177b8dcf18 100644 --- a/packages/dashpay-contract/package.json +++ b/packages/dashpay-contract/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dashpay-contract", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "Reference contract of the DashPay DPA on Dash Evolution", "scripts": { "lint": "eslint .", diff --git a/packages/data-contracts/Cargo.toml b/packages/data-contracts/Cargo.toml index 30e4c1ee003..ca5eb08c13d 100644 --- a/packages/data-contracts/Cargo.toml +++ b/packages/data-contracts/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "data-contracts" description = "Dash Platform system data contracts" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/dpns-contract/Cargo.toml b/packages/dpns-contract/Cargo.toml index 708bfc1885d..77b7dc8deef 100644 --- a/packages/dpns-contract/Cargo.toml +++ b/packages/dpns-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dpns-contract" description = "DPNS data contract schema and tools" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/dpns-contract/package.json b/packages/dpns-contract/package.json index 1cd50c4af76..52ecd54127d 100644 --- a/packages/dpns-contract/package.json +++ b/packages/dpns-contract/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dpns-contract", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "A contract and helper scripts for DPNS DApp", "scripts": { "lint": "eslint .", diff --git a/packages/feature-flags-contract/Cargo.toml b/packages/feature-flags-contract/Cargo.toml index 93416fb0369..444ede45c48 100644 --- a/packages/feature-flags-contract/Cargo.toml +++ b/packages/feature-flags-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "feature-flags-contract" description = "Feature flags data contract schema and tools" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/feature-flags-contract/package.json b/packages/feature-flags-contract/package.json index ae041474d6b..a4a54c87d89 100644 --- a/packages/feature-flags-contract/package.json +++ b/packages/feature-flags-contract/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/feature-flags-contract", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "Data Contract to store Dash Platform feature flags", "scripts": { "build": "", diff --git a/packages/js-dapi-client/package.json b/packages/js-dapi-client/package.json index 8f13a34a86b..f37ebc9c466 100644 --- a/packages/js-dapi-client/package.json +++ b/packages/js-dapi-client/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dapi-client", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "Client library used to access Dash DAPI endpoints", "main": "lib/index.js", "contributors": [ diff --git a/packages/js-dash-sdk/package.json b/packages/js-dash-sdk/package.json index 662bc45dd04..f199cabfd27 100644 --- a/packages/js-dash-sdk/package.json +++ b/packages/js-dash-sdk/package.json @@ -1,6 +1,6 @@ { "name": "dash", - "version": "4.0.0-dev.15", + "version": "4.0.0-pr.1875.1", "description": "Dash library for JavaScript/TypeScript ecosystem (Wallet, DAPI, Primitives, BLS, ...)", "main": "build/index.js", "unpkg": "dist/dash.min.js", diff --git a/packages/js-grpc-common/package.json b/packages/js-grpc-common/package.json index 36bf23b4606..069fcccef24 100644 --- a/packages/js-grpc-common/package.json +++ b/packages/js-grpc-common/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/grpc-common", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "Common GRPC library", "main": "index.js", "scripts": { diff --git a/packages/masternode-reward-shares-contract/Cargo.toml b/packages/masternode-reward-shares-contract/Cargo.toml index d5e3194eab4..09bce07535b 100644 --- a/packages/masternode-reward-shares-contract/Cargo.toml +++ b/packages/masternode-reward-shares-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "masternode-reward-shares-contract" description = "Masternode reward shares data contract schema and tools" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/masternode-reward-shares-contract/package.json b/packages/masternode-reward-shares-contract/package.json index a1a97d841a5..51ded6dc20b 100644 --- a/packages/masternode-reward-shares-contract/package.json +++ b/packages/masternode-reward-shares-contract/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/masternode-reward-shares-contract", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "A contract and helper scripts for reward sharing", "scripts": { "lint": "eslint .", diff --git a/packages/platform-test-suite/package.json b/packages/platform-test-suite/package.json index 75c8df73bed..99f708eb671 100644 --- a/packages/platform-test-suite/package.json +++ b/packages/platform-test-suite/package.json @@ -1,7 +1,7 @@ { "name": "@dashevo/platform-test-suite", "private": true, - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "Dash Network end-to-end tests", "scripts": { "test": "yarn exec bin/test.sh", diff --git a/packages/rs-dapi-client/Cargo.toml b/packages/rs-dapi-client/Cargo.toml index 56bd878d984..1d3a27c2d87 100644 --- a/packages/rs-dapi-client/Cargo.toml +++ b/packages/rs-dapi-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rs-dapi-client" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" [features] diff --git a/packages/rs-dapi-grpc-macros/Cargo.toml b/packages/rs-dapi-grpc-macros/Cargo.toml index c47067dab05..25506ee88ac 100644 --- a/packages/rs-dapi-grpc-macros/Cargo.toml +++ b/packages/rs-dapi-grpc-macros/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dapi-grpc-macros" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" description = "Macros used by dapi-grpc. Internal use only." diff --git a/packages/rs-dpp/Cargo.toml b/packages/rs-dpp/Cargo.toml index da94abc573d..9cb80630da9 100644 --- a/packages/rs-dpp/Cargo.toml +++ b/packages/rs-dpp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dpp" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" authors = [ diff --git a/packages/rs-drive-abci/Cargo.toml b/packages/rs-drive-abci/Cargo.toml index 8b1281b271e..c57f08ac1ed 100644 --- a/packages/rs-drive-abci/Cargo.toml +++ b/packages/rs-drive-abci/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "drive-abci" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" authors = [ "Samuel Westrich ", "Ivan Shumkov ", diff --git a/packages/rs-drive-proof-verifier/Cargo.toml b/packages/rs-drive-proof-verifier/Cargo.toml index 685f0727ba6..c2c210c1187 100644 --- a/packages/rs-drive-proof-verifier/Cargo.toml +++ b/packages/rs-drive-proof-verifier/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "drive-proof-verifier" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" diff --git a/packages/rs-drive/Cargo.toml b/packages/rs-drive/Cargo.toml index 013d70f8329..fc1224b77d6 100644 --- a/packages/rs-drive/Cargo.toml +++ b/packages/rs-drive/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "drive" description = "Dash drive built on top of GroveDB" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" authors = [ "Samuel Westrich ", "Ivan Shumkov ", diff --git a/packages/rs-platform-serialization-derive/Cargo.toml b/packages/rs-platform-serialization-derive/Cargo.toml index c93f55b9a0f..be8bbf6e531 100644 --- a/packages/rs-platform-serialization-derive/Cargo.toml +++ b/packages/rs-platform-serialization-derive/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-serialization-derive" authors = ["Samuel Westrich "] description = "Bincode serialization and deserialization derivations" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-platform-serialization/Cargo.toml b/packages/rs-platform-serialization/Cargo.toml index 223730e2010..a0ffcf71d37 100644 --- a/packages/rs-platform-serialization/Cargo.toml +++ b/packages/rs-platform-serialization/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-serialization" authors = ["Samuel Westrich "] description = "Bincode based serialization and deserialization" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-platform-value-convertible/Cargo.toml b/packages/rs-platform-value-convertible/Cargo.toml index 6fd648c51dd..7fbfb98ae26 100644 --- a/packages/rs-platform-value-convertible/Cargo.toml +++ b/packages/rs-platform-value-convertible/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-value-convertible" authors = ["Samuel Westrich "] description = "Convertion to and from platform values" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-platform-value/Cargo.toml b/packages/rs-platform-value/Cargo.toml index 4695510dbd1..136c19ba110 100644 --- a/packages/rs-platform-value/Cargo.toml +++ b/packages/rs-platform-value/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-value" authors = ["Samuel Westrich "] description = "A simple value module" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-platform-version/Cargo.toml b/packages/rs-platform-version/Cargo.toml index d4a13f7480b..218579b309c 100644 --- a/packages/rs-platform-version/Cargo.toml +++ b/packages/rs-platform-version/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-version" authors = ["Samuel Westrich "] description = "Bincode based serialization and deserialization" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-platform-versioning/Cargo.toml b/packages/rs-platform-versioning/Cargo.toml index fd0f3b25636..b7f99de757c 100644 --- a/packages/rs-platform-versioning/Cargo.toml +++ b/packages/rs-platform-versioning/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-versioning" authors = ["Samuel Westrich "] description = "Version derivation" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-sdk/Cargo.toml b/packages/rs-sdk/Cargo.toml index e514de10925..ac9e17b384d 100644 --- a/packages/rs-sdk/Cargo.toml +++ b/packages/rs-sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dash-sdk" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" [dependencies] diff --git a/packages/simple-signer/Cargo.toml b/packages/simple-signer/Cargo.toml index c326c3d63be..673af59fc65 100644 --- a/packages/simple-signer/Cargo.toml +++ b/packages/simple-signer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "simple-signer" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" diff --git a/packages/strategy-tests/Cargo.toml b/packages/strategy-tests/Cargo.toml index 7487c04c8bc..ba701d3de47 100644 --- a/packages/strategy-tests/Cargo.toml +++ b/packages/strategy-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strategy-tests" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" authors = [ "Samuel Westrich ", "Ivan Shumkov ", diff --git a/packages/wallet-lib/package.json b/packages/wallet-lib/package.json index 263c42579f0..bdd6e956fd4 100644 --- a/packages/wallet-lib/package.json +++ b/packages/wallet-lib/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/wallet-lib", - "version": "8.0.0-dev.15", + "version": "8.0.0-pr.1875.1", "description": "Light wallet library for Dash", "main": "src/index.js", "unpkg": "dist/wallet-lib.min.js", diff --git a/packages/wasm-dpp/Cargo.toml b/packages/wasm-dpp/Cargo.toml index b83aacf8d25..b26adf74597 100644 --- a/packages/wasm-dpp/Cargo.toml +++ b/packages/wasm-dpp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-dpp" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" authors = ["Anton Suprunchuk "] diff --git a/packages/wasm-dpp/package.json b/packages/wasm-dpp/package.json index ef9f8f09b3a..54e6181cb72 100644 --- a/packages/wasm-dpp/package.json +++ b/packages/wasm-dpp/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/wasm-dpp", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "The JavaScript implementation of the Dash Platform Protocol", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/withdrawals-contract/Cargo.toml b/packages/withdrawals-contract/Cargo.toml index d0910b65a87..57390a465bc 100644 --- a/packages/withdrawals-contract/Cargo.toml +++ b/packages/withdrawals-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "withdrawals-contract" description = "Witdrawals data contract schema and tools" -version = "1.0.0-dev.15" +version = "1.0.0-pr.1875.1" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/withdrawals-contract/package.json b/packages/withdrawals-contract/package.json index f047e25c929..e6a742f186c 100644 --- a/packages/withdrawals-contract/package.json +++ b/packages/withdrawals-contract/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/withdrawals-contract", - "version": "1.0.0-dev.15", + "version": "1.0.0-pr.1875.1", "description": "Data Contract to manipulate and track withdrawals", "scripts": { "build": "", From 617c0a2630ee0f975358c99199a41a0922eb6386 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 19:13:59 +0700 Subject: [PATCH 26/48] revert: bump version to 1.0.0-pr.1875.1 --- Cargo.lock | 46 +++++++++---------- package.json | 2 +- packages/bench-suite/package.json | 2 +- packages/dapi-grpc/Cargo.toml | 2 +- packages/dapi-grpc/package.json | 2 +- packages/dapi/package.json | 2 +- packages/dash-spv/package.json | 2 +- packages/dashmate/package.json | 2 +- packages/dashpay-contract/Cargo.toml | 2 +- packages/dashpay-contract/package.json | 2 +- packages/data-contracts/Cargo.toml | 2 +- packages/dpns-contract/Cargo.toml | 2 +- packages/dpns-contract/package.json | 2 +- packages/feature-flags-contract/Cargo.toml | 2 +- packages/feature-flags-contract/package.json | 2 +- packages/js-dapi-client/package.json | 2 +- packages/js-dash-sdk/package.json | 2 +- packages/js-grpc-common/package.json | 2 +- .../Cargo.toml | 2 +- .../package.json | 2 +- packages/platform-test-suite/package.json | 2 +- packages/rs-dapi-client/Cargo.toml | 2 +- packages/rs-dapi-grpc-macros/Cargo.toml | 2 +- packages/rs-dpp/Cargo.toml | 2 +- packages/rs-drive-abci/Cargo.toml | 2 +- packages/rs-drive-proof-verifier/Cargo.toml | 2 +- packages/rs-drive/Cargo.toml | 2 +- .../Cargo.toml | 2 +- packages/rs-platform-serialization/Cargo.toml | 2 +- .../rs-platform-value-convertible/Cargo.toml | 2 +- packages/rs-platform-value/Cargo.toml | 2 +- packages/rs-platform-version/Cargo.toml | 2 +- packages/rs-platform-versioning/Cargo.toml | 2 +- packages/rs-sdk/Cargo.toml | 2 +- packages/simple-signer/Cargo.toml | 2 +- packages/strategy-tests/Cargo.toml | 2 +- packages/wallet-lib/package.json | 2 +- packages/wasm-dpp/Cargo.toml | 2 +- packages/wasm-dpp/package.json | 2 +- packages/withdrawals-contract/Cargo.toml | 2 +- packages/withdrawals-contract/package.json | 2 +- 41 files changed, 63 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca5f0100e14..19c63f23809 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1244,7 +1244,7 @@ dependencies = [ [[package]] name = "dapi-grpc" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "dapi-grpc-macros", "futures-core", @@ -1260,7 +1260,7 @@ dependencies = [ [[package]] name = "dapi-grpc-macros" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "dapi-grpc", "heck 0.5.0", @@ -1305,7 +1305,7 @@ dependencies = [ [[package]] name = "dash-sdk" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "async-trait", "base64 0.22.0", @@ -1402,7 +1402,7 @@ dependencies = [ [[package]] name = "dashpay-contract" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "platform-value", "platform-version", @@ -1412,7 +1412,7 @@ dependencies = [ [[package]] name = "data-contracts" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "dashpay-contract", "dpns-contract", @@ -1536,7 +1536,7 @@ checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" [[package]] name = "dpns-contract" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "platform-value", "platform-version", @@ -1546,7 +1546,7 @@ dependencies = [ [[package]] name = "dpp" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "anyhow", "assert_matches", @@ -1598,7 +1598,7 @@ dependencies = [ [[package]] name = "drive" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "arc-swap", "base64 0.21.7", @@ -1634,7 +1634,7 @@ dependencies = [ [[package]] name = "drive-abci" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "arc-swap", "assert_matches", @@ -1690,7 +1690,7 @@ dependencies = [ [[package]] name = "drive-proof-verifier" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "dapi-grpc", "dpp", @@ -1908,7 +1908,7 @@ dependencies = [ [[package]] name = "feature-flags-contract" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "platform-value", "platform-version", @@ -2985,7 +2985,7 @@ dependencies = [ [[package]] name = "masternode-reward-shares-contract" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "platform-value", "platform-version", @@ -3546,7 +3546,7 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "platform-serialization" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "bincode 2.0.0-rc.3", "platform-version", @@ -3554,7 +3554,7 @@ dependencies = [ [[package]] name = "platform-serialization-derive" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "proc-macro2", "quote", @@ -3564,7 +3564,7 @@ dependencies = [ [[package]] name = "platform-value" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "base64 0.22.0", "bincode 2.0.0-rc.3", @@ -3585,7 +3585,7 @@ dependencies = [ [[package]] name = "platform-value-convertible" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "quote", "syn 2.0.60", @@ -3593,14 +3593,14 @@ dependencies = [ [[package]] name = "platform-version" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "thiserror", ] [[package]] name = "platform-versioning" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "proc-macro2", "quote", @@ -4199,7 +4199,7 @@ dependencies = [ [[package]] name = "rs-dapi-client" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "backon", "chrono", @@ -4668,7 +4668,7 @@ checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" [[package]] name = "simple-signer" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "bincode 2.0.0-rc.3", "dashcore-rpc", @@ -4776,7 +4776,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "strategy-tests" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "bincode 2.0.0-rc.3", "dpp", @@ -5791,7 +5791,7 @@ checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" [[package]] name = "wasm-dpp" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "anyhow", "async-trait", @@ -6341,7 +6341,7 @@ dependencies = [ [[package]] name = "withdrawals-contract" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" dependencies = [ "num_enum", "platform-value", diff --git a/package.json b/package.json index c4b361ad95d..b37fc18a9dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/platform", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "private": true, "scripts": { "setup": "yarn install && yarn run build && yarn run configure", diff --git a/packages/bench-suite/package.json b/packages/bench-suite/package.json index c44b36a5dde..53c0e10d0cb 100644 --- a/packages/bench-suite/package.json +++ b/packages/bench-suite/package.json @@ -1,7 +1,7 @@ { "name": "@dashevo/bench-suite", "private": true, - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "Dash Platform benchmark tool", "scripts": { "bench": "node ./bin/bench.js", diff --git a/packages/dapi-grpc/Cargo.toml b/packages/dapi-grpc/Cargo.toml index a64ec3cb308..21e63ea3e3e 100644 --- a/packages/dapi-grpc/Cargo.toml +++ b/packages/dapi-grpc/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dapi-grpc" description = "GRPC client for Dash Platform" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" authors = [ "Samuel Westrich ", "Igor Markin ", diff --git a/packages/dapi-grpc/package.json b/packages/dapi-grpc/package.json index f2b370681c8..511bd177a77 100644 --- a/packages/dapi-grpc/package.json +++ b/packages/dapi-grpc/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dapi-grpc", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "DAPI GRPC definition file and generated clients", "browser": "browser.js", "main": "node.js", diff --git a/packages/dapi/package.json b/packages/dapi/package.json index c649d395ea2..ab442480567 100644 --- a/packages/dapi/package.json +++ b/packages/dapi/package.json @@ -1,7 +1,7 @@ { "name": "@dashevo/dapi", "private": true, - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "A decentralized API for the Dash network", "scripts": { "api": "node scripts/api.js", diff --git a/packages/dash-spv/package.json b/packages/dash-spv/package.json index 2da45ae23b0..35cac4b1fd6 100644 --- a/packages/dash-spv/package.json +++ b/packages/dash-spv/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dash-spv", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "Repository containing SPV functions used by @dashevo", "main": "index.js", "scripts": { diff --git a/packages/dashmate/package.json b/packages/dashmate/package.json index 6a32584c7e7..ec527ce5054 100644 --- a/packages/dashmate/package.json +++ b/packages/dashmate/package.json @@ -1,6 +1,6 @@ { "name": "dashmate", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "Distribution package for Dash node installation", "scripts": { "lint": "eslint .", diff --git a/packages/dashpay-contract/Cargo.toml b/packages/dashpay-contract/Cargo.toml index 940605db1a2..115444dcd91 100644 --- a/packages/dashpay-contract/Cargo.toml +++ b/packages/dashpay-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dashpay-contract" description = "DashPay data contract schema and tools" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/dashpay-contract/package.json b/packages/dashpay-contract/package.json index 6177b8dcf18..7335e9a3c18 100644 --- a/packages/dashpay-contract/package.json +++ b/packages/dashpay-contract/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dashpay-contract", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "Reference contract of the DashPay DPA on Dash Evolution", "scripts": { "lint": "eslint .", diff --git a/packages/data-contracts/Cargo.toml b/packages/data-contracts/Cargo.toml index ca5eb08c13d..30e4c1ee003 100644 --- a/packages/data-contracts/Cargo.toml +++ b/packages/data-contracts/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "data-contracts" description = "Dash Platform system data contracts" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/dpns-contract/Cargo.toml b/packages/dpns-contract/Cargo.toml index 77b7dc8deef..708bfc1885d 100644 --- a/packages/dpns-contract/Cargo.toml +++ b/packages/dpns-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dpns-contract" description = "DPNS data contract schema and tools" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/dpns-contract/package.json b/packages/dpns-contract/package.json index 52ecd54127d..1cd50c4af76 100644 --- a/packages/dpns-contract/package.json +++ b/packages/dpns-contract/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dpns-contract", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "A contract and helper scripts for DPNS DApp", "scripts": { "lint": "eslint .", diff --git a/packages/feature-flags-contract/Cargo.toml b/packages/feature-flags-contract/Cargo.toml index 444ede45c48..93416fb0369 100644 --- a/packages/feature-flags-contract/Cargo.toml +++ b/packages/feature-flags-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "feature-flags-contract" description = "Feature flags data contract schema and tools" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/feature-flags-contract/package.json b/packages/feature-flags-contract/package.json index a4a54c87d89..ae041474d6b 100644 --- a/packages/feature-flags-contract/package.json +++ b/packages/feature-flags-contract/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/feature-flags-contract", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "Data Contract to store Dash Platform feature flags", "scripts": { "build": "", diff --git a/packages/js-dapi-client/package.json b/packages/js-dapi-client/package.json index f37ebc9c466..8f13a34a86b 100644 --- a/packages/js-dapi-client/package.json +++ b/packages/js-dapi-client/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/dapi-client", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "Client library used to access Dash DAPI endpoints", "main": "lib/index.js", "contributors": [ diff --git a/packages/js-dash-sdk/package.json b/packages/js-dash-sdk/package.json index f199cabfd27..662bc45dd04 100644 --- a/packages/js-dash-sdk/package.json +++ b/packages/js-dash-sdk/package.json @@ -1,6 +1,6 @@ { "name": "dash", - "version": "4.0.0-pr.1875.1", + "version": "4.0.0-dev.15", "description": "Dash library for JavaScript/TypeScript ecosystem (Wallet, DAPI, Primitives, BLS, ...)", "main": "build/index.js", "unpkg": "dist/dash.min.js", diff --git a/packages/js-grpc-common/package.json b/packages/js-grpc-common/package.json index 069fcccef24..36bf23b4606 100644 --- a/packages/js-grpc-common/package.json +++ b/packages/js-grpc-common/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/grpc-common", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "Common GRPC library", "main": "index.js", "scripts": { diff --git a/packages/masternode-reward-shares-contract/Cargo.toml b/packages/masternode-reward-shares-contract/Cargo.toml index 09bce07535b..d5e3194eab4 100644 --- a/packages/masternode-reward-shares-contract/Cargo.toml +++ b/packages/masternode-reward-shares-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "masternode-reward-shares-contract" description = "Masternode reward shares data contract schema and tools" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/masternode-reward-shares-contract/package.json b/packages/masternode-reward-shares-contract/package.json index 51ded6dc20b..a1a97d841a5 100644 --- a/packages/masternode-reward-shares-contract/package.json +++ b/packages/masternode-reward-shares-contract/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/masternode-reward-shares-contract", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "A contract and helper scripts for reward sharing", "scripts": { "lint": "eslint .", diff --git a/packages/platform-test-suite/package.json b/packages/platform-test-suite/package.json index 99f708eb671..75c8df73bed 100644 --- a/packages/platform-test-suite/package.json +++ b/packages/platform-test-suite/package.json @@ -1,7 +1,7 @@ { "name": "@dashevo/platform-test-suite", "private": true, - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "Dash Network end-to-end tests", "scripts": { "test": "yarn exec bin/test.sh", diff --git a/packages/rs-dapi-client/Cargo.toml b/packages/rs-dapi-client/Cargo.toml index 1d3a27c2d87..56bd878d984 100644 --- a/packages/rs-dapi-client/Cargo.toml +++ b/packages/rs-dapi-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rs-dapi-client" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" [features] diff --git a/packages/rs-dapi-grpc-macros/Cargo.toml b/packages/rs-dapi-grpc-macros/Cargo.toml index 25506ee88ac..c47067dab05 100644 --- a/packages/rs-dapi-grpc-macros/Cargo.toml +++ b/packages/rs-dapi-grpc-macros/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dapi-grpc-macros" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" description = "Macros used by dapi-grpc. Internal use only." diff --git a/packages/rs-dpp/Cargo.toml b/packages/rs-dpp/Cargo.toml index 9cb80630da9..da94abc573d 100644 --- a/packages/rs-dpp/Cargo.toml +++ b/packages/rs-dpp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dpp" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" authors = [ diff --git a/packages/rs-drive-abci/Cargo.toml b/packages/rs-drive-abci/Cargo.toml index c57f08ac1ed..8b1281b271e 100644 --- a/packages/rs-drive-abci/Cargo.toml +++ b/packages/rs-drive-abci/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "drive-abci" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" authors = [ "Samuel Westrich ", "Ivan Shumkov ", diff --git a/packages/rs-drive-proof-verifier/Cargo.toml b/packages/rs-drive-proof-verifier/Cargo.toml index c2c210c1187..685f0727ba6 100644 --- a/packages/rs-drive-proof-verifier/Cargo.toml +++ b/packages/rs-drive-proof-verifier/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "drive-proof-verifier" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" diff --git a/packages/rs-drive/Cargo.toml b/packages/rs-drive/Cargo.toml index fc1224b77d6..013d70f8329 100644 --- a/packages/rs-drive/Cargo.toml +++ b/packages/rs-drive/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "drive" description = "Dash drive built on top of GroveDB" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" authors = [ "Samuel Westrich ", "Ivan Shumkov ", diff --git a/packages/rs-platform-serialization-derive/Cargo.toml b/packages/rs-platform-serialization-derive/Cargo.toml index be8bbf6e531..c93f55b9a0f 100644 --- a/packages/rs-platform-serialization-derive/Cargo.toml +++ b/packages/rs-platform-serialization-derive/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-serialization-derive" authors = ["Samuel Westrich "] description = "Bincode serialization and deserialization derivations" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-platform-serialization/Cargo.toml b/packages/rs-platform-serialization/Cargo.toml index a0ffcf71d37..223730e2010 100644 --- a/packages/rs-platform-serialization/Cargo.toml +++ b/packages/rs-platform-serialization/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-serialization" authors = ["Samuel Westrich "] description = "Bincode based serialization and deserialization" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-platform-value-convertible/Cargo.toml b/packages/rs-platform-value-convertible/Cargo.toml index 7fbfb98ae26..6fd648c51dd 100644 --- a/packages/rs-platform-value-convertible/Cargo.toml +++ b/packages/rs-platform-value-convertible/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-value-convertible" authors = ["Samuel Westrich "] description = "Convertion to and from platform values" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-platform-value/Cargo.toml b/packages/rs-platform-value/Cargo.toml index 136c19ba110..4695510dbd1 100644 --- a/packages/rs-platform-value/Cargo.toml +++ b/packages/rs-platform-value/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-value" authors = ["Samuel Westrich "] description = "A simple value module" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-platform-version/Cargo.toml b/packages/rs-platform-version/Cargo.toml index 218579b309c..d4a13f7480b 100644 --- a/packages/rs-platform-version/Cargo.toml +++ b/packages/rs-platform-version/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-version" authors = ["Samuel Westrich "] description = "Bincode based serialization and deserialization" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-platform-versioning/Cargo.toml b/packages/rs-platform-versioning/Cargo.toml index b7f99de757c..fd0f3b25636 100644 --- a/packages/rs-platform-versioning/Cargo.toml +++ b/packages/rs-platform-versioning/Cargo.toml @@ -2,7 +2,7 @@ name = "platform-versioning" authors = ["Samuel Westrich "] description = "Version derivation" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/rs-sdk/Cargo.toml b/packages/rs-sdk/Cargo.toml index ac9e17b384d..e514de10925 100644 --- a/packages/rs-sdk/Cargo.toml +++ b/packages/rs-sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dash-sdk" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" [dependencies] diff --git a/packages/simple-signer/Cargo.toml b/packages/simple-signer/Cargo.toml index 673af59fc65..c326c3d63be 100644 --- a/packages/simple-signer/Cargo.toml +++ b/packages/simple-signer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "simple-signer" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" diff --git a/packages/strategy-tests/Cargo.toml b/packages/strategy-tests/Cargo.toml index ba701d3de47..7487c04c8bc 100644 --- a/packages/strategy-tests/Cargo.toml +++ b/packages/strategy-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "strategy-tests" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" authors = [ "Samuel Westrich ", "Ivan Shumkov ", diff --git a/packages/wallet-lib/package.json b/packages/wallet-lib/package.json index bdd6e956fd4..263c42579f0 100644 --- a/packages/wallet-lib/package.json +++ b/packages/wallet-lib/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/wallet-lib", - "version": "8.0.0-pr.1875.1", + "version": "8.0.0-dev.15", "description": "Light wallet library for Dash", "main": "src/index.js", "unpkg": "dist/wallet-lib.min.js", diff --git a/packages/wasm-dpp/Cargo.toml b/packages/wasm-dpp/Cargo.toml index b26adf74597..b83aacf8d25 100644 --- a/packages/wasm-dpp/Cargo.toml +++ b/packages/wasm-dpp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-dpp" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" authors = ["Anton Suprunchuk "] diff --git a/packages/wasm-dpp/package.json b/packages/wasm-dpp/package.json index 54e6181cb72..ef9f8f09b3a 100644 --- a/packages/wasm-dpp/package.json +++ b/packages/wasm-dpp/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/wasm-dpp", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "The JavaScript implementation of the Dash Platform Protocol", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/withdrawals-contract/Cargo.toml b/packages/withdrawals-contract/Cargo.toml index 57390a465bc..d0910b65a87 100644 --- a/packages/withdrawals-contract/Cargo.toml +++ b/packages/withdrawals-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "withdrawals-contract" description = "Witdrawals data contract schema and tools" -version = "1.0.0-pr.1875.1" +version = "1.0.0-dev.15" edition = "2021" rust-version = "1.76" license = "MIT" diff --git a/packages/withdrawals-contract/package.json b/packages/withdrawals-contract/package.json index e6a742f186c..f047e25c929 100644 --- a/packages/withdrawals-contract/package.json +++ b/packages/withdrawals-contract/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/withdrawals-contract", - "version": "1.0.0-pr.1875.1", + "version": "1.0.0-dev.15", "description": "Data Contract to manipulate and track withdrawals", "scripts": { "build": "", From d262ccabc672b823bc5a59370e12c3739118db69 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 7 Jun 2024 21:10:28 +0700 Subject: [PATCH 27/48] refactor: simplify/decompose quorum set iterator --- .../verify_chain_lock_locally/v0/mod.rs | 21 +++- .../verify_recent_signature_locally/v0/mod.rs | 106 +++++++++--------- .../src/platform_types/core_quorum_set/mod.rs | 12 +- .../core_quorum_set/v0/quorum_set.rs | 59 ++++++---- 4 files changed, 109 insertions(+), 89 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs index 1e37d4a48c2..4bf2ce7517d 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs @@ -9,6 +9,7 @@ use crate::platform_types::platform::Platform; use crate::rpc::core::CoreRPCLike; +use crate::error::execution::ExecutionError; use crate::platform_types::core_quorum_set::CoreQuorumSetV0Methods; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; @@ -67,6 +68,10 @@ where return Ok(None); // the chain lock is too far in the future or the past to verify locally } + let mut selected_quorums = platform_state + .chain_lock_validating_quorums() + .select_quorums_for_heights(chain_lock_height, verification_height); + // TODO: We can use chain_lock.request_id() // From DIP 8: https://github.com/dashpay/dips/blob/master/dip-0008.md#finalization-of-signed-blocks @@ -89,11 +94,13 @@ where // Based on the deterministic masternode list at the given height, a quorum must be selected that was active at the time this block was mined - let mut selected_quorums = platform_state - .chain_lock_validating_quorums() - .select_quorums(chain_lock_height, verification_height, request_id); + let quorums = selected_quorums.next().ok_or_else(|| { + Error::Execution(ExecutionError::CorruptedCodeExecution( + "No quorums selected for chain lock signature verification for specified height", + )) + })?; - let Some((quorum_hash, quorum)) = selected_quorums.next() else { + let Some((quorum_hash, quorum)) = quorums.choose_quorum(request_id.as_ref()) else { return Ok(None); }; @@ -132,8 +139,10 @@ where if !chain_lock_verified { // We should also check the other quorum, as there could be the situation where the core height wasn't updated every block. - if selected_quorums.len() == 2 { - let Some((quorum_hash, quorum)) = selected_quorums.next() else { + if let Some(second_to_check_quorums) = selected_quorums.next() { + let Some((quorum_hash, quorum)) = + second_to_check_quorums.choose_quorum(request_id.as_ref()) + else { // we return that we are not able to verify return Ok(None); }; diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs index 39c55543983..6ed41f2d902 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs @@ -33,21 +33,14 @@ pub(super) fn verify_recent_instant_lock_signature_locally_v0( }; let signing_height = platform_state.last_committed_core_height(); - let verification_height = signing_height.saturating_sub(SIGN_OFFSET); - let request_id = instant_lock.request_id().map_err(|e| { - Error::Serialization(SerializationError::CorruptedSerialization(format!( - "can't hash instant lock request ID for signature verification: {e}" - ))) - })?; - let quorum_set = platform_state.instant_lock_validating_quorums(); // Based on the deterministic masternode list at the given height, a quorum must be selected // that was active at the time this block was mined let selected_quorums = - quorum_set.select_quorums(signing_height, verification_height, request_id); + quorum_set.select_quorums_for_heights(signing_height, verification_height); if selected_quorums.is_empty() { return Err(Error::Execution(ExecutionError::CorruptedCodeExecution( @@ -55,66 +48,71 @@ pub(super) fn verify_recent_instant_lock_signature_locally_v0( ))); }; - let is_signature_valid = selected_quorums - .enumerate() - .find(|(i, (quorum_hash, quorum))| { - // The signature must verify against the quorum public key and SHA256(llmqType, quorumHash, SHA256(height), txId). - // llmqType and quorumHash must be taken from the quorum selected in 1. - let mut engine = sha256d::Hash::engine(); - - let mut reversed_quorum_hash = quorum_hash.to_byte_array().to_vec(); - reversed_quorum_hash.reverse(); - - engine.input(&[quorum_set.config().quorum_type as u8]); - engine.input(reversed_quorum_hash.as_slice()); - engine.input(request_id.as_byte_array()); - engine.input(instant_lock.txid.as_byte_array()); - - let message_digest = sha256d::Hash::from_engine(engine); - - if quorum - .public_key - .verify(&signature, message_digest.as_ref()) - { - return true; - } + let request_id = instant_lock.request_id().map_err(|e| { + Error::Serialization(SerializationError::CorruptedSerialization(format!( + "can't hash instant lock request ID for signature verification: {e}" + ))) + })?; + for (i, quorums) in selected_quorums.enumerate() { + let Some((quorum_hash, quorum)) = quorums.choose_quorum(request_id.as_ref()) else { if tracing::enabled!(tracing::Level::TRACE) { tracing::trace!( quorums_iteration = i + 1, instant_lock = ?InstantLockDebug(instant_lock), - quorum_hash = quorum_hash.to_string(), - quorum_config = ?quorum_set.config(), - quorum = ?quorum, request_id = request_id.to_string(), - message_digest = message_digest.to_string(), - signing_height, - verification_height, - "Instant Lock {} signature verification failed", - instant_lock.txid, - ); - }; - - false - }) - .or_else(|| { - if tracing::enabled!(tracing::Level::TRACE) { - tracing::trace!( - instant_lock = ?InstantLockDebug(instant_lock), + quorums = ?quorums.quorums, request_id = request_id.to_string(), - quorum_set = ?quorum_set, signing_height, verification_height, - "No eligible quorums found for instant Lock {} signature", + "No chosen for instant Lock {} request ID {}", instant_lock.txid, + request_id, ); }; - None - }) - .is_some(); + continue; + }; + + // The signature must verify against the quorum public key and SHA256(llmqType, quorumHash, SHA256(height), txId). + // llmqType and quorumHash must be taken from the quorum selected in 1. + let mut engine = sha256d::Hash::engine(); + + let mut reversed_quorum_hash = quorum_hash.to_byte_array().to_vec(); + reversed_quorum_hash.reverse(); + + engine.input(&[quorum_set.config().quorum_type as u8]); + engine.input(reversed_quorum_hash.as_slice()); + engine.input(request_id.as_byte_array()); + engine.input(instant_lock.txid.as_byte_array()); + + let message_digest = sha256d::Hash::from_engine(engine); + + if quorum + .public_key + .verify(&signature, message_digest.as_ref()) + { + return Ok(true); + } + + if tracing::enabled!(tracing::Level::TRACE) { + tracing::trace!( + quorums_iteration = i + 1, + instant_lock = ?InstantLockDebug(instant_lock), + quorum_hash = quorum_hash.to_string(), + quorum_config = ?quorum_set.config(), + quorum = ?quorum, + request_id = request_id.to_string(), + message_digest = message_digest.to_string(), + signing_height, + verification_height, + "Instant Lock {} signature verification failed", + instant_lock.txid, + ); + }; + } - Ok(is_signature_valid) + Ok(false) } // TODO: The best way is to implement Value trait for InstantLock and hashes diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs index a71bdea531d..226c7eefb59 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs @@ -5,15 +5,14 @@ use crate::error::execution::ExecutionError; use crate::error::Error; use crate::platform_types::core_quorum_set::v0::for_saving::CoreQuorumSetForSavingV0; pub use crate::platform_types::core_quorum_set::v0::quorum_set::{ - CoreQuorumSetV0, CoreQuorumSetV0Methods, QuorumConfig, QuorumsVerificationDataIterator, - SIGN_OFFSET, + CoreQuorumSetV0, CoreQuorumSetV0Methods, QuorumConfig, QuorumsWithConfig, + SelectedQuorumSetIterator, SIGN_OFFSET, }; pub use crate::platform_types::core_quorum_set::v0::quorums::{ Quorum, Quorums, SigningQuorum, ThresholdBlsPublicKey, VerificationQuorum, }; use bincode::{Decode, Encode}; use derive_more::From; -use dpp::dashcore::QuorumSigningRequestId; use dpp::version::PlatformVersion; /// Quorums with keys for signature verification @@ -99,14 +98,13 @@ impl CoreQuorumSetV0Methods for CoreQuorumSet { } } - fn select_quorums( + fn select_quorums_for_heights( &self, signing_height: u32, verification_height: u32, - request_id: QuorumSigningRequestId, - ) -> QuorumsVerificationDataIterator { + ) -> SelectedQuorumSetIterator { match self { - Self::V0(v0) => v0.select_quorums(signing_height, verification_height, request_id), + Self::V0(v0) => v0.select_quorums_for_heights(signing_height, verification_height), } } } diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs index b5aefa49ba4..ae2afb65815 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs @@ -2,7 +2,7 @@ use crate::config::{ChainLockConfig, QuorumLikeConfig}; use crate::platform_types::core_quorum_set::v0::quorums::Quorums; use crate::platform_types::core_quorum_set::VerificationQuorum; use dashcore_rpc::json::QuorumType; -use dpp::dashcore::{QuorumHash, QuorumSigningRequestId}; +use dpp::dashcore::QuorumHash; use std::vec::IntoIter; /// Offset for signature verification @@ -71,46 +71,63 @@ pub trait CoreQuorumSetV0Methods { updated_at_core_height: u32, ); - /// Select quorums for signature verification - fn select_quorums( + /// Select quorums for signature verification based on sign and verification heights + fn select_quorums_for_heights( &self, signing_height: u32, verification_height: u32, - request_id: QuorumSigningRequestId, - ) -> QuorumsVerificationDataIterator; + ) -> SelectedQuorumSetIterator; } /// Iterator over selected quorum sets and specific quorums based on request_id and quorum configuration -pub struct QuorumsVerificationDataIterator<'q> { +pub struct SelectedQuorumSetIterator<'q> { /// Quorum configuration config: &'q QuorumConfig, - /// Request ID to chose right quorum - request_id: QuorumSigningRequestId, /// Appropriate quorum sets - quorum_sets: IntoIter<&'q Quorums>, + quorum_set: IntoIter<&'q Quorums>, /// Should we expect signature verification to be successful should_be_verifiable: bool, } -impl<'q> Iterator for QuorumsVerificationDataIterator<'q> { - type Item = (QuorumHash, &'q VerificationQuorum); +impl<'q> Iterator for SelectedQuorumSetIterator<'q> { + type Item = QuorumsWithConfig<'q>; fn next(&mut self) -> Option { - let quorum_set = self.quorum_sets.next()?; + self.quorum_set.next().map(|quorums| QuorumsWithConfig { + quorums, + config: self.config, + }) + } +} + +/// Quorums with configuration +pub struct QuorumsWithConfig<'q> { + /// Quorums + pub quorums: &'q Quorums, + /// Config + pub config: &'q QuorumConfig, +} - quorum_set.choose_quorum(self.config, self.request_id.as_ref()) +impl<'q> QuorumsWithConfig<'q> { + /// Choose pseudorandom DIP8 or DIP24 quorum based on quorum config + /// and request_id + pub fn choose_quorum( + &self, + request_id: &[u8; 32], + ) -> Option<(QuorumHash, &VerificationQuorum)> { + self.quorums.choose_quorum(self.config, request_id) } } -impl<'q> QuorumsVerificationDataIterator<'q> { +impl<'q> SelectedQuorumSetIterator<'q> { /// Number of quorum sets pub fn len(&self) -> usize { - self.quorum_sets.len() + self.quorum_set.len() } /// Does the iterator have any quorum sets pub fn is_empty(&self) -> bool { - self.quorum_sets.len() == 0 + self.quorum_set.len() == 0 } /// Should we expect signature verification to be successful @@ -181,12 +198,11 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { }); } - fn select_quorums( + fn select_quorums_for_heights( &self, signing_height: u32, verification_height: u32, - request_id: QuorumSigningRequestId, - ) -> QuorumsVerificationDataIterator { + ) -> SelectedQuorumSetIterator { let mut quorums = Vec::new(); let mut should_be_verifiable = false; @@ -236,10 +252,9 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { quorums.push(&self.current_quorums); } - QuorumsVerificationDataIterator { + SelectedQuorumSetIterator { config: &self.config, - request_id, - quorum_sets: quorums.into_iter(), + quorum_set: quorums.into_iter(), should_be_verifiable, } } From 7355234433aad138cddc7d73effdc14e9d7a7da2 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 14 Jun 2024 13:17:53 +0700 Subject: [PATCH 28/48] refactor: renaming from Sam --- .../update_quorum_info/v0/mod.rs | 2 +- .../verify_chain_lock_locally/v0/mod.rs | 2 +- .../src/platform_types/core_quorum_set/mod.rs | 8 ++++---- .../core_quorum_set/v0/for_saving.rs | 19 +++++++++--------- .../core_quorum_set/v0/quorum_set.rs | 20 +++++++++++-------- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index 469dd2bd166..f1f74ec3391 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -405,7 +405,7 @@ where let previous_validating_quorums = old_state.chain_lock_validating_quorums().current_quorums(); - quorum_set.update_previous_quorums( + quorum_set.set_previous_past_quorums( previous_validating_quorums.clone(), last_committed_core_height, next_core_height, diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs index 4bf2ce7517d..fa66185b6c4 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs @@ -183,7 +183,7 @@ where } } else if !platform_state .chain_lock_validating_quorums() - .has_previous_quorums() + .has_previous_past_quorums() { // we don't have old quorums, this means our node is very new. tracing::debug!( diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs index 226c7eefb59..6f4727b20bd 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs @@ -64,9 +64,9 @@ impl CoreQuorumSetV0Methods for CoreQuorumSet { } } - fn has_previous_quorums(&self) -> bool { + fn has_previous_past_quorums(&self) -> bool { match self { - Self::V0(v0) => v0.has_previous_quorums(), + Self::V0(v0) => v0.has_previous_past_quorums(), } } @@ -83,14 +83,14 @@ impl CoreQuorumSetV0Methods for CoreQuorumSet { } } - fn update_previous_quorums( + fn set_previous_past_quorums( &mut self, previous_quorums: Quorums, last_active_core_height: u32, updated_at_core_height: u32, ) { match self { - Self::V0(v0) => v0.update_previous_quorums( + Self::V0(v0) => v0.set_previous_past_quorums( previous_quorums, last_active_core_height, updated_at_core_height, diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs index 7a018a01d8d..42138f3bab1 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs @@ -1,4 +1,4 @@ -use crate::platform_types::core_quorum_set::v0::quorum_set::{PreviousQuorumsV0, QuorumConfig}; +use crate::platform_types::core_quorum_set::v0::quorum_set::{PreviousPastQuorumsV0, QuorumConfig}; use crate::platform_types::core_quorum_set::{ CoreQuorumSetForSaving, CoreQuorumSetV0, Quorums, ThresholdBlsPublicKey, VerificationQuorum, }; @@ -15,7 +15,7 @@ pub struct CoreQuorumSetForSavingV0 { current_quorums: Vec, - previous_quorums: Option, + previous_quorums: Option, } impl From for CoreQuorumSetForSaving { @@ -87,16 +87,16 @@ impl From for QuorumConfig { } #[derive(Debug, Clone, Encode, Decode)] -pub struct PreviousQuorumsForSavingV0 { +pub struct PreviousPastQuorumsForSavingV0 { quorums: Vec, active_core_height: u32, updated_at_core_height: u32, previous_change_height: Option, } -impl From for PreviousQuorumsForSavingV0 { - fn from(value: PreviousQuorumsV0) -> Self { - let PreviousQuorumsV0 { +impl From for PreviousPastQuorumsForSavingV0 { + fn from(value: PreviousPastQuorumsV0) -> Self { + let PreviousPastQuorumsV0 { quorums, active_core_height, updated_at_core_height, @@ -112,9 +112,9 @@ impl From for PreviousQuorumsForSavingV0 { } } -impl From for PreviousQuorumsV0 { - fn from(value: PreviousQuorumsForSavingV0) -> Self { - let PreviousQuorumsForSavingV0 { +impl From for PreviousPastQuorumsV0 { + fn from(value: PreviousPastQuorumsForSavingV0) -> Self { + let PreviousPastQuorumsForSavingV0 { quorums, active_core_height, updated_at_core_height, @@ -152,6 +152,7 @@ impl From> for Quorums { } } +#[allow(clippy::from_over_into)] impl Into> for Quorums { fn into(self) -> Vec { self.into_iter() diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs index ae2afb65815..3d9d04cacef 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs @@ -10,7 +10,7 @@ pub const SIGN_OFFSET: u32 = 8; /// Previously obtained quorums and heights. Required for signature verification #[derive(Debug, Clone)] -pub(super) struct PreviousQuorumsV0 { +pub(super) struct PreviousPastQuorumsV0 { pub(super) quorums: Quorums, /// The core height at which these quorums were last active @@ -35,7 +35,7 @@ pub struct CoreQuorumSetV0 { /// The slightly old quorums used for validating ch ain locks (or instant locks), it's important to keep /// these because validation of signatures happens for the quorums that are 8 blocks before the /// height written in the chain lock. The same for instant locks - pub(super) previous: Option, + pub(super) previous: Option, } /// The trait defines methods for the signature verification quorums structure v0 @@ -53,7 +53,7 @@ pub trait CoreQuorumSetV0Methods { fn current_quorums_mut(&mut self) -> &mut Quorums; /// Has previous quorums? - fn has_previous_quorums(&self) -> bool; + fn has_previous_past_quorums(&self) -> bool; /// Set last quorums keys and update previous quorums fn replace_quorums( @@ -64,7 +64,7 @@ pub trait CoreQuorumSetV0Methods { ); /// Update previous quorums - fn update_previous_quorums( + fn set_previous_past_quorums( &mut self, previous_quorums: Quorums, last_active_core_height: u32, @@ -166,7 +166,7 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { &mut self.current_quorums } - fn has_previous_quorums(&self) -> bool { + fn has_previous_past_quorums(&self) -> bool { self.previous.is_some() } @@ -178,16 +178,20 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { ) { let previous_quorums = std::mem::replace(&mut self.current_quorums, quorums); - self.update_previous_quorums(previous_quorums, last_active_height, updated_at_core_height); + self.set_previous_past_quorums( + previous_quorums, + last_active_height, + updated_at_core_height, + ); } - fn update_previous_quorums( + fn set_previous_past_quorums( &mut self, previous_quorums: Quorums, last_active_core_height: u32, updated_at_core_height: u32, ) { - self.previous = Some(PreviousQuorumsV0 { + self.previous = Some(PreviousPastQuorumsV0 { quorums: previous_quorums, active_core_height: last_active_core_height, updated_at_core_height, From a2e26f74939331e208efb0dbbfa0e39ee2bbfe6f Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 14 Jun 2024 16:02:56 +0700 Subject: [PATCH 29/48] revert: variable name --- .../core_chain_lock/verify_chain_lock_locally/v0/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs index fa66185b6c4..4a96f90b002 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs @@ -94,13 +94,14 @@ where // Based on the deterministic masternode list at the given height, a quorum must be selected that was active at the time this block was mined - let quorums = selected_quorums.next().ok_or_else(|| { + let probable_quorums = selected_quorums.next().ok_or_else(|| { Error::Execution(ExecutionError::CorruptedCodeExecution( "No quorums selected for chain lock signature verification for specified height", )) })?; - let Some((quorum_hash, quorum)) = quorums.choose_quorum(request_id.as_ref()) else { + let Some((quorum_hash, quorum)) = probable_quorums.choose_quorum(request_id.as_ref()) + else { return Ok(None); }; From 998b963544f98f1d6e41bced47f7d494e3ae1b6b Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 14 Jun 2024 16:25:56 +0700 Subject: [PATCH 30/48] fix: non-deterministic quorum index --- .../update_quorum_info/v0/mod.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index f1f74ec3391..2b15382ae95 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -146,13 +146,19 @@ where .validator_sets() .contains_key::(key) }) - .map(|(key, _)| { - let quorum_info_result = self.core_rpc.get_quorum_info( + .map(|(key, details)| { + let mut quorum_info_result = self.core_rpc.get_quorum_info( self.config.validator_set.quorum_type, &key, None, )?; + // In case if current chain locked height so far in the past, + // long enough for a new quorum to be formed, quorum info (which is not + // based on chain locked height) will respond with altered quorum index, + // so we need to use quorum index from the deterministic `quorum listextended` response + quorum_info_result.quorum_index = details.quorum_index.unwrap_or(0); + Ok((key, quorum_info_result)) }) .collect::, Error>>()?; @@ -171,10 +177,6 @@ where let new_validator_sets = quorum_infos .into_iter() .map(|(quorum_hash, info_result)| { - // TODO: There is a non-determinism here because quorum info is not based on core chain locked height - // so you will might get different members and tenderdash will fail when you will try to update - // validator set with different memebers. - let validator_set = ValidatorSet::V0(ValidatorSetV0::try_from_quorum_info_result( info_result, block_platform_state, From 016afc30372222641e7d334783d0dc42f27adca2 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 18 Jun 2024 21:51:38 +0800 Subject: [PATCH 31/48] style: unused import --- packages/dashmate/src/config/configJsonSchema.js | 2 ++ packages/rs-drive-abci/src/mimic/test_quorum.rs | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/dashmate/src/config/configJsonSchema.js b/packages/dashmate/src/config/configJsonSchema.js index ff0b84486c6..d2633953cb2 100644 --- a/packages/dashmate/src/config/configJsonSchema.js +++ b/packages/dashmate/src/config/configJsonSchema.js @@ -114,9 +114,11 @@ export default { }, dkgInterval: { type: 'integer', + minimum: 1, }, activeSigners: { type: 'integer', + minimum: 1, }, rotation: { type: 'boolean', diff --git a/packages/rs-drive-abci/src/mimic/test_quorum.rs b/packages/rs-drive-abci/src/mimic/test_quorum.rs index 3cb6b50a740..c1653183c6d 100644 --- a/packages/rs-drive-abci/src/mimic/test_quorum.rs +++ b/packages/rs-drive-abci/src/mimic/test_quorum.rs @@ -1,4 +1,3 @@ -use crate::platform_types::core_quorum_set::Quorum; use crate::platform_types::validator::v0::ValidatorV0; use crate::platform_types::validator_set::v0::ValidatorSetV0; use dashcore_rpc::dashcore::hashes::Hash; From 3c71b37f9f3b764301a41be94995f1c6a3ac7637 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 18 Jun 2024 21:53:02 +0800 Subject: [PATCH 32/48] revert: remove non-determinism fix --- .../core_based_updates/update_quorum_info/v0/mod.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index 2b15382ae95..51126df9a1d 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -146,19 +146,13 @@ where .validator_sets() .contains_key::(key) }) - .map(|(key, details)| { - let mut quorum_info_result = self.core_rpc.get_quorum_info( + .map(|(key, _)| { + let quorum_info_result = self.core_rpc.get_quorum_info( self.config.validator_set.quorum_type, &key, None, )?; - // In case if current chain locked height so far in the past, - // long enough for a new quorum to be formed, quorum info (which is not - // based on chain locked height) will respond with altered quorum index, - // so we need to use quorum index from the deterministic `quorum listextended` response - quorum_info_result.quorum_index = details.quorum_index.unwrap_or(0); - Ok((key, quorum_info_result)) }) .collect::, Error>>()?; From fc51742a569c64bd70f17f63ecb51a07e56e3cf6 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 18 Jun 2024 21:53:53 +0800 Subject: [PATCH 33/48] refactor: rename `select_quorums` --- .../core_chain_lock/verify_chain_lock_locally/v0/mod.rs | 2 +- .../verify_recent_signature_locally/v0/mod.rs | 3 +-- .../rs-drive-abci/src/platform_types/core_quorum_set/mod.rs | 4 ++-- .../src/platform_types/core_quorum_set/v0/quorum_set.rs | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs index 4a96f90b002..3b4efdafa61 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs @@ -70,7 +70,7 @@ where let mut selected_quorums = platform_state .chain_lock_validating_quorums() - .select_quorums_for_heights(chain_lock_height, verification_height); + .select_quorums(chain_lock_height, verification_height); // TODO: We can use chain_lock.request_id() diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs index 6ed41f2d902..de89f35dd08 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs @@ -39,8 +39,7 @@ pub(super) fn verify_recent_instant_lock_signature_locally_v0( // Based on the deterministic masternode list at the given height, a quorum must be selected // that was active at the time this block was mined - let selected_quorums = - quorum_set.select_quorums_for_heights(signing_height, verification_height); + let selected_quorums = quorum_set.select_quorums(signing_height, verification_height); if selected_quorums.is_empty() { return Err(Error::Execution(ExecutionError::CorruptedCodeExecution( diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs index 6f4727b20bd..e3dc12ad2b0 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs @@ -98,13 +98,13 @@ impl CoreQuorumSetV0Methods for CoreQuorumSet { } } - fn select_quorums_for_heights( + fn select_quorums( &self, signing_height: u32, verification_height: u32, ) -> SelectedQuorumSetIterator { match self { - Self::V0(v0) => v0.select_quorums_for_heights(signing_height, verification_height), + Self::V0(v0) => v0.select_quorums(signing_height, verification_height), } } } diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs index 3d9d04cacef..c6da72ec868 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs +++ b/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs @@ -72,7 +72,7 @@ pub trait CoreQuorumSetV0Methods { ); /// Select quorums for signature verification based on sign and verification heights - fn select_quorums_for_heights( + fn select_quorums( &self, signing_height: u32, verification_height: u32, @@ -202,7 +202,7 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { }); } - fn select_quorums_for_heights( + fn select_quorums( &self, signing_height: u32, verification_height: u32, From 7b1c6e7872a60c7eaa8d9809987b9b3939377ab5 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 18 Jun 2024 21:54:36 +0800 Subject: [PATCH 34/48] refactor: `core_instant_lock` -> core_instant_send_lock --- .../{core_instant_lock => core_instant_send_lock}/mod.rs | 0 .../verify_recent_signature_locally/mod.rs | 0 .../verify_recent_signature_locally/v0/mod.rs | 0 packages/rs-drive-abci/src/execution/platform_events/mod.rs | 2 +- .../common/asset_lock/proof/validate/instant/mod.rs | 2 +- 5 files changed, 2 insertions(+), 2 deletions(-) rename packages/rs-drive-abci/src/execution/platform_events/{core_instant_lock => core_instant_send_lock}/mod.rs (100%) rename packages/rs-drive-abci/src/execution/platform_events/{core_instant_lock => core_instant_send_lock}/verify_recent_signature_locally/mod.rs (100%) rename packages/rs-drive-abci/src/execution/platform_events/{core_instant_lock => core_instant_send_lock}/verify_recent_signature_locally/v0/mod.rs (100%) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/mod.rs similarity index 100% rename from packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/mod.rs rename to packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/mod.rs diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/mod.rs similarity index 100% rename from packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/mod.rs rename to packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/mod.rs diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/v0/mod.rs similarity index 100% rename from packages/rs-drive-abci/src/execution/platform_events/core_instant_lock/verify_recent_signature_locally/v0/mod.rs rename to packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/v0/mod.rs diff --git a/packages/rs-drive-abci/src/execution/platform_events/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/mod.rs index 3d875663074..d63103d880d 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/mod.rs @@ -28,4 +28,4 @@ pub(in crate::execution) mod block_start; pub(in crate::execution) mod core_chain_lock; /// Instant lock methods -pub(in crate::execution) mod core_instant_lock; +pub(in crate::execution) mod core_instant_send_lock; diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs index b6793cabfe4..c2e4992197e 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs @@ -10,7 +10,7 @@ use dpp::state_transition::signable_bytes_hasher::SignableBytesHasher; use dpp::validation::ConsensusValidationResult; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; -use crate::execution::platform_events::core_instant_lock::verify_recent_signature_locally::VerifyInstantLockSignature; +use crate::execution::platform_events::core_instant_send_lock::verify_recent_signature_locally::VerifyInstantLockSignature; use crate::execution::validation::state_transition::common::asset_lock::proof::validate::AssetLockProofValidation; use crate::execution::validation::state_transition::common::asset_lock::proof::verify_is_not_spent::AssetLockProofVerifyIsNotSpent; use crate::execution::validation::state_transition::ValidationMode; From b9f765a005f1337c5700f61b7ba033c81dfa97c8 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 18 Jun 2024 22:41:34 +0800 Subject: [PATCH 35/48] chore: exclude the testing config for production --- Cargo.lock | 1 + packages/rs-drive-abci/Cargo.toml | 3 ++- packages/rs-drive-abci/src/config.rs | 8 +++++++- .../execution/engine/finalize_block_proposal/v0/mod.rs | 1 + .../common/asset_lock/proof/validate/instant/mod.rs | 1 + packages/rs-drive-abci/src/mimic/mod.rs | 1 + 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19c63f23809..f5e046b964f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1653,6 +1653,7 @@ dependencies = [ "dotenvy", "dpp", "drive", + "drive-abci", "envy", "file-rotate", "hex", diff --git a/packages/rs-drive-abci/Cargo.toml b/packages/rs-drive-abci/Cargo.toml index 8b1281b271e..eb01bfd39d8 100644 --- a/packages/rs-drive-abci/Cargo.toml +++ b/packages/rs-drive-abci/Cargo.toml @@ -99,6 +99,7 @@ dpp = { path = "../rs-dpp", features = [ drive = { path = "../rs-drive" } strategy-tests = { path = "../strategy-tests" } assert_matches = "1.5.0" +drive-abci = { path = ".", features = ["testing-config"]} # For tests of grovedb verify rocksdb = { version = "0.22.0" } @@ -109,7 +110,7 @@ integer-encoding = { version = "4.0.0" } default = ["mocks", "console"] mocks = ["mockall", "drive/fixtures-and-mocks"] console = ["console-subscriber", "tokio/tracing"] - +testing-config = [] [[bin]] name = "drive-abci" diff --git a/packages/rs-drive-abci/src/config.rs b/packages/rs-drive-abci/src/config.rs index fed79b3387b..23846e41e5c 100644 --- a/packages/rs-drive-abci/src/config.rs +++ b/packages/rs-drive-abci/src/config.rs @@ -206,7 +206,7 @@ pub struct PlatformConfig { #[serde(default)] pub rejections_path: Option, - // todo: put this in tests like #[cfg(test)] + #[cfg(feature = "testing-config")] /// This should be None, except in the case of Testing platform #[serde(skip)] pub testing_configs: PlatformTestConfig, @@ -639,6 +639,7 @@ impl PlatformConfig { execution: Default::default(), db_path: PathBuf::from("/var/lib/dash-platform/data"), rejections_path: Some(PathBuf::from("/var/log/dash/rejected")), + #[cfg(feature = "testing-config")] testing_configs: PlatformTestConfig::default(), tokio_console_enabled: false, tokio_console_address: PlatformConfig::default_tokio_console_address(), @@ -679,6 +680,7 @@ impl PlatformConfig { execution: Default::default(), db_path: PathBuf::from("/var/lib/dash-platform/data"), rejections_path: Some(PathBuf::from("/var/log/dash/rejected")), + #[cfg(feature = "testing-config")] testing_configs: PlatformTestConfig::default(), initial_protocol_version: Self::default_initial_protocol_version(), prometheus_bind_address: None, @@ -719,6 +721,7 @@ impl PlatformConfig { execution: Default::default(), db_path: PathBuf::from("/var/lib/dash-platform/data"), rejections_path: Some(PathBuf::from("/var/log/dash/rejected")), + #[cfg(feature = "testing-config")] testing_configs: PlatformTestConfig::default(), initial_protocol_version: Self::default_initial_protocol_version(), prometheus_bind_address: None, @@ -730,6 +733,7 @@ impl PlatformConfig { } } +#[cfg(feature = "testing-config")] /// Configs that should only happen during testing #[derive(Clone, Debug)] pub struct PlatformTestConfig { @@ -741,6 +745,7 @@ pub struct PlatformTestConfig { pub disable_instant_lock_signature_verification: bool, } +#[cfg(feature = "testing-config")] impl PlatformTestConfig { /// Much faster config for tests pub fn default_with_no_block_signing() -> Self { @@ -752,6 +757,7 @@ impl PlatformTestConfig { } } +#[cfg(feature = "testing-config")] impl Default for PlatformTestConfig { fn default() -> Self { Self { diff --git a/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs b/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs index e6e91561b3a..a958b6c46ae 100644 --- a/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs @@ -155,6 +155,7 @@ where } // In production this will always be true + #[cfg(feature = "testing-config")] if self .config .testing_configs diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs index c2e4992197e..a2500b06636 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/common/asset_lock/proof/validate/instant/mod.rs @@ -45,6 +45,7 @@ impl AssetLockProofValidation for InstantAssetLockProof { if validation_mode != ValidationMode::RecheckTx && !validation_result.has_data() { // We should be able to disable instant lock versification for integration tests + #[cfg(feature = "testing-config")] if platform_ref .config .testing_configs diff --git a/packages/rs-drive-abci/src/mimic/mod.rs b/packages/rs-drive-abci/src/mimic/mod.rs index 4927771da21..e766abc9a9d 100644 --- a/packages/rs-drive-abci/src/mimic/mod.rs +++ b/packages/rs-drive-abci/src/mimic/mod.rs @@ -480,6 +480,7 @@ impl<'a, C: CoreRPCLike> FullAbciApplication<'a, C> { threshold_vote_extensions: extensions, }; //if not in testing this will default to true + #[cfg(feature = "testing-config")] if self.platform.config.testing_configs.block_signing { let quorum_hash: [u8; 32] = quorum_hash.try_into().expect("wrong quorum hash len"); let digest = commit From 2a47154cd05949c2204292b6458fb02a4c40f395 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 18 Jun 2024 22:48:06 +0800 Subject: [PATCH 36/48] refactor: `CoreQuorumSet` to `VerificationQuorumSet` --- .../update_quorum_info/v0/mod.rs | 8 ++-- .../verify_chain_lock_locally/v0/mod.rs | 2 +- .../verify_recent_signature_locally/v0/mod.rs | 2 +- .../rs-drive-abci/src/platform_types/mod.rs | 4 +- .../src/platform_types/platform_state/mod.rs | 12 +++--- .../platform_types/platform_state/v0/mod.rs | 36 +++++++++-------- .../mod.rs | 40 +++++++++---------- .../v0/for_saving.rs | 29 ++++++++------ .../v0/mod.rs | 0 .../v0/quorum_set.rs | 18 ++++----- .../v0/quorums.rs | 2 +- .../tests/strategy_tests/execution.rs | 2 +- .../tests/strategy_tests/strategy.rs | 2 +- .../src/version/drive_abci_versions.rs | 2 +- .../src/version/mocks/v2_test.rs | 2 +- .../src/version/mocks/v3_test.rs | 2 +- .../rs-platform-version/src/version/v1.rs | 2 +- 17 files changed, 85 insertions(+), 80 deletions(-) rename packages/rs-drive-abci/src/platform_types/{core_quorum_set => verification_quorum_set}/mod.rs (69%) rename packages/rs-drive-abci/src/platform_types/{core_quorum_set => verification_quorum_set}/v0/for_saving.rs (82%) rename packages/rs-drive-abci/src/platform_types/{core_quorum_set => verification_quorum_set}/v0/mod.rs (100%) rename packages/rs-drive-abci/src/platform_types/{core_quorum_set => verification_quorum_set}/v0/quorum_set.rs (95%) rename packages/rs-drive-abci/src/platform_types/{core_quorum_set => verification_quorum_set}/v0/quorums.rs (99%) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index 51126df9a1d..082c14722e6 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -13,8 +13,8 @@ use crate::platform_types::validator_set::v0::{ use crate::platform_types::validator_set::ValidatorSet; use crate::rpc::core::CoreRPCLike; -use crate::platform_types::core_quorum_set::{ - CoreQuorumSet, CoreQuorumSetV0Methods, VerificationQuorum, +use crate::platform_types::verification_quorum_set::{ + VerificationQuorum, VerificationQuorumSet, VerificationQuorumSetV0Methods, }; use dpp::bls_signatures::PublicKey as BlsPublicKey; use dpp::dashcore::QuorumHash; @@ -305,7 +305,7 @@ where fn update_quorums_from_quorum_list( &self, quorum_set_type: &QuorumSetType, - quorum_set: &mut CoreQuorumSet, + quorum_set: &mut VerificationQuorumSet, platform_state: Option<&PlatformState>, full_quorum_list: &ExtendedQuorumListResult, last_committed_core_height: u32, @@ -416,7 +416,7 @@ where fn quorum_set_by_type_mut<'p>( block_platform_state: &'p mut PlatformState, quorum_set_type: &QuorumSetType, -) -> &'p mut CoreQuorumSet { +) -> &'p mut VerificationQuorumSet { match quorum_set_type { QuorumSetType::ChainLock(_) => block_platform_state.chain_lock_validating_quorums_mut(), QuorumSetType::InstantLock(_) => block_platform_state.instant_lock_validating_quorums_mut(), diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs index 3b4efdafa61..6433da149ae 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs @@ -10,9 +10,9 @@ use crate::platform_types::platform::Platform; use crate::rpc::core::CoreRPCLike; use crate::error::execution::ExecutionError; -use crate::platform_types::core_quorum_set::CoreQuorumSetV0Methods; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; +use crate::platform_types::verification_quorum_set::VerificationQuorumSetV0Methods; use dpp::version::PlatformVersion; const CHAIN_LOCK_REQUEST_ID_PREFIX: &str = "clsig"; diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/v0/mod.rs index de89f35dd08..2c3a3fc32b6 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/v0/mod.rs @@ -8,9 +8,9 @@ use crate::error::execution::ExecutionError; use crate::error::Error; use crate::error::serialization::SerializationError; -use crate::platform_types::core_quorum_set::{CoreQuorumSetV0Methods, SIGN_OFFSET}; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; +use crate::platform_types::verification_quorum_set::{VerificationQuorumSetV0Methods, SIGN_OFFSET}; #[inline(always)] pub(super) fn verify_recent_instant_lock_signature_locally_v0( diff --git a/packages/rs-drive-abci/src/platform_types/mod.rs b/packages/rs-drive-abci/src/platform_types/mod.rs index 514d07b363e..69cfe483ea7 100644 --- a/packages/rs-drive-abci/src/platform_types/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/mod.rs @@ -35,8 +35,6 @@ pub mod block_proposal; pub mod cleaned_abci_messages; /// The commit pub mod commit; -/// Signature verification quorums for Core -pub mod core_quorum_set; /// Epoch pub mod epoch_info; /// The execution event result @@ -60,6 +58,8 @@ pub mod system_identity_public_keys; pub mod validator; /// Quorum methods pub mod validator_set; +/// Signature verification quorums for Core +pub mod verification_quorum_set; /// Verify chain lock result pub mod verify_chain_lock_result; /// Withdrawal types diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs index 33b81684557..36650327698 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs @@ -22,7 +22,7 @@ use indexmap::IndexMap; use crate::config::PlatformConfig; use crate::error::execution::ExecutionError; -use crate::platform_types::core_quorum_set::CoreQuorumSet; +use crate::platform_types::verification_quorum_set::VerificationQuorumSet; use dpp::block::block_info::BlockInfo; use dpp::util::hash::hash_double; use std::collections::BTreeMap; @@ -321,7 +321,7 @@ impl PlatformStateV0Methods for PlatformState { } } - fn chain_lock_validating_quorums(&self) -> &CoreQuorumSet { + fn chain_lock_validating_quorums(&self) -> &VerificationQuorumSet { match self { PlatformState::V0(v0) => &v0.chain_lock_validating_quorums, } @@ -387,7 +387,7 @@ impl PlatformStateV0Methods for PlatformState { } } - fn set_chain_lock_validating_quorums(&mut self, quorums: CoreQuorumSet) { + fn set_chain_lock_validating_quorums(&mut self, quorums: VerificationQuorumSet) { match self { PlatformState::V0(v0) => v0.set_chain_lock_validating_quorums(quorums), } @@ -447,7 +447,7 @@ impl PlatformStateV0Methods for PlatformState { } } - fn chain_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet { + fn chain_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet { match self { PlatformState::V0(v0) => v0.chain_lock_validating_quorums_mut(), } @@ -477,13 +477,13 @@ impl PlatformStateV0Methods for PlatformState { } } - fn instant_lock_validating_quorums(&self) -> &CoreQuorumSet { + fn instant_lock_validating_quorums(&self) -> &VerificationQuorumSet { match self { PlatformState::V0(v0) => v0.instant_lock_validating_quorums(), } } - fn instant_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet { + fn instant_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet { match self { PlatformState::V0(v0) => v0.instant_lock_validating_quorums_mut(), } diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs index 4b29581d35f..77cbdb86f42 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs @@ -20,7 +20,9 @@ use dpp::block::extended_block_info::v0::ExtendedBlockInfoV0Getters; use dpp::version::{PlatformVersion, TryIntoPlatformVersioned}; use crate::config::PlatformConfig; -use crate::platform_types::core_quorum_set::{CoreQuorumSet, CoreQuorumSetForSaving}; +use crate::platform_types::verification_quorum_set::{ + VerificationQuorumSet, VerificationQuorumSetForSaving, +}; use itertools::Itertools; use std::collections::BTreeMap; use std::fmt::{Debug, Formatter}; @@ -46,10 +48,10 @@ pub struct PlatformStateV0 { pub validator_sets: IndexMap, /// Quorums used for validating chain locks (400 60 for mainnet) - pub chain_lock_validating_quorums: CoreQuorumSet, + pub chain_lock_validating_quorums: VerificationQuorumSet, /// Quorums used for validating instant locks - pub instant_lock_validating_quorums: CoreQuorumSet, + pub instant_lock_validating_quorums: VerificationQuorumSet, /// current full masternode list pub full_masternode_list: BTreeMap, @@ -131,10 +133,10 @@ pub struct PlatformStateForSavingV0 { pub validator_sets: Vec<(Bytes32, ValidatorSet)>, /// The quorums used for validating chain locks - pub chain_lock_validating_quorums: CoreQuorumSetForSaving, + pub chain_lock_validating_quorums: VerificationQuorumSetForSaving, /// The quorums used for validating instant locks - pub instant_lock_validating_quorums: CoreQuorumSetForSaving, + pub instant_lock_validating_quorums: VerificationQuorumSetForSaving, /// current full masternode list pub full_masternode_list: BTreeMap, @@ -241,11 +243,11 @@ impl PlatformStateV0 { current_validator_set_quorum_hash: QuorumHash::all_zeros(), next_validator_set_quorum_hash: None, validator_sets: Default::default(), - chain_lock_validating_quorums: CoreQuorumSet::new( + chain_lock_validating_quorums: VerificationQuorumSet::new( &config.chain_lock, platform_version, )?, - instant_lock_validating_quorums: CoreQuorumSet::new( + instant_lock_validating_quorums: VerificationQuorumSet::new( &config.instant_lock, platform_version, )?, @@ -305,10 +307,10 @@ pub trait PlatformStateV0Methods { fn validator_sets(&self) -> &IndexMap; /// Returns the quorums used to validate chain locks. - fn chain_lock_validating_quorums(&self) -> &CoreQuorumSet; + fn chain_lock_validating_quorums(&self) -> &VerificationQuorumSet; /// Returns quorums used to validate instant locks. - fn instant_lock_validating_quorums(&self) -> &CoreQuorumSet; + fn instant_lock_validating_quorums(&self) -> &VerificationQuorumSet; /// Returns the full list of masternodes. fn full_masternode_list(&self) -> &BTreeMap; @@ -341,7 +343,7 @@ pub trait PlatformStateV0Methods { fn set_validator_sets(&mut self, sets: IndexMap); /// Sets the current chain lock validating quorums. - fn set_chain_lock_validating_quorums(&mut self, quorums: CoreQuorumSet); + fn set_chain_lock_validating_quorums(&mut self, quorums: VerificationQuorumSet); /// Sets the full masternode list. fn set_full_masternode_list(&mut self, list: BTreeMap); @@ -370,10 +372,10 @@ pub trait PlatformStateV0Methods { fn validator_sets_mut(&mut self) -> &mut IndexMap; /// Returns a mutable reference to the chain lock validating quorums. - fn chain_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet; + fn chain_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet; /// Returns a mutable reference to the instant lock validating quorums. - fn instant_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet; + fn instant_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet; /// Returns a mutable reference to the full masternode list. fn full_masternode_list_mut(&mut self) -> &mut BTreeMap; @@ -527,12 +529,12 @@ impl PlatformStateV0Methods for PlatformStateV0 { } /// Returns the quorums used to validate chain locks. - fn chain_lock_validating_quorums(&self) -> &CoreQuorumSet { + fn chain_lock_validating_quorums(&self) -> &VerificationQuorumSet { &self.chain_lock_validating_quorums } /// Returns the quorums used to validate instant locks. - fn instant_lock_validating_quorums(&self) -> &CoreQuorumSet { + fn instant_lock_validating_quorums(&self) -> &VerificationQuorumSet { &self.instant_lock_validating_quorums } @@ -593,7 +595,7 @@ impl PlatformStateV0Methods for PlatformStateV0 { } /// Sets the current chain lock validating quorums. - fn set_chain_lock_validating_quorums(&mut self, quorums: CoreQuorumSet) { + fn set_chain_lock_validating_quorums(&mut self, quorums: VerificationQuorumSet) { self.chain_lock_validating_quorums = quorums; } @@ -636,11 +638,11 @@ impl PlatformStateV0Methods for PlatformStateV0 { &mut self.validator_sets } - fn chain_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet { + fn chain_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet { &mut self.chain_lock_validating_quorums } - fn instant_lock_validating_quorums_mut(&mut self) -> &mut CoreQuorumSet { + fn instant_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet { &mut self.instant_lock_validating_quorums } diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs b/packages/rs-drive-abci/src/platform_types/verification_quorum_set/mod.rs similarity index 69% rename from packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs rename to packages/rs-drive-abci/src/platform_types/verification_quorum_set/mod.rs index e3dc12ad2b0..806415503fe 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/verification_quorum_set/mod.rs @@ -3,12 +3,12 @@ mod v0; use crate::config::QuorumLikeConfig; use crate::error::execution::ExecutionError; use crate::error::Error; -use crate::platform_types::core_quorum_set::v0::for_saving::CoreQuorumSetForSavingV0; -pub use crate::platform_types::core_quorum_set::v0::quorum_set::{ - CoreQuorumSetV0, CoreQuorumSetV0Methods, QuorumConfig, QuorumsWithConfig, - SelectedQuorumSetIterator, SIGN_OFFSET, +use crate::platform_types::verification_quorum_set::v0::for_saving::VerificationQuorumSetForSavingV0; +pub use crate::platform_types::verification_quorum_set::v0::quorum_set::{ + QuorumConfig, QuorumsWithConfig, SelectedQuorumSetIterator, VerificationQuorumSetV0, + VerificationQuorumSetV0Methods, SIGN_OFFSET, }; -pub use crate::platform_types::core_quorum_set::v0::quorums::{ +pub use crate::platform_types::verification_quorum_set::v0::quorums::{ Quorum, Quorums, SigningQuorum, ThresholdBlsPublicKey, VerificationQuorum, }; use bincode::{Decode, Encode}; @@ -17,21 +17,21 @@ use dpp::version::PlatformVersion; /// Quorums with keys for signature verification #[derive(Debug, Clone, From)] -pub enum CoreQuorumSet { +pub enum VerificationQuorumSet { /// Version 0 of the signature verification quorums - V0(CoreQuorumSetV0), + V0(VerificationQuorumSetV0), } -impl CoreQuorumSet { +impl VerificationQuorumSet { /// Create a default SignatureVerificationQuorums pub fn new( config: &impl QuorumLikeConfig, platform_version: &PlatformVersion, ) -> Result { - match platform_version.drive_abci.structs.core_quorum_set { - 0 => Ok(CoreQuorumSetV0::new(config).into()), + match platform_version.drive_abci.structs.verification_quorum_set { + 0 => Ok(VerificationQuorumSetV0::new(config).into()), version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { - method: "CoreQuorumSet.new".to_string(), + method: "VerificationQuorumSet.new".to_string(), known_versions: vec![0], received: version, })), @@ -39,7 +39,7 @@ impl CoreQuorumSet { } } -impl CoreQuorumSetV0Methods for CoreQuorumSet { +impl VerificationQuorumSetV0Methods for VerificationQuorumSet { fn config(&self) -> &QuorumConfig { match self { Self::V0(v0) => v0.config(), @@ -111,23 +111,23 @@ impl CoreQuorumSetV0Methods for CoreQuorumSet { /// Core Quorum Set structure for saving to the database #[derive(Debug, Clone, Encode, Decode)] -pub enum CoreQuorumSetForSaving { +pub enum VerificationQuorumSetForSaving { /// Version 0 of the signature verification quorums - V0(CoreQuorumSetForSavingV0), + V0(VerificationQuorumSetForSavingV0), } -impl From for CoreQuorumSetForSaving { - fn from(value: CoreQuorumSet) -> Self { +impl From for VerificationQuorumSetForSaving { + fn from(value: VerificationQuorumSet) -> Self { match value { - CoreQuorumSet::V0(v0) => CoreQuorumSetForSaving::V0(v0.into()), + VerificationQuorumSet::V0(v0) => VerificationQuorumSetForSaving::V0(v0.into()), } } } -impl From for CoreQuorumSet { - fn from(value: CoreQuorumSetForSaving) -> Self { +impl From for VerificationQuorumSet { + fn from(value: VerificationQuorumSetForSaving) -> Self { match value { - CoreQuorumSetForSaving::V0(v0) => CoreQuorumSet::V0(v0.into()), + VerificationQuorumSetForSaving::V0(v0) => VerificationQuorumSet::V0(v0.into()), } } } diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs b/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/for_saving.rs similarity index 82% rename from packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs rename to packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/for_saving.rs index 42138f3bab1..61deceb9abe 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/for_saving.rs +++ b/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/for_saving.rs @@ -1,6 +1,9 @@ -use crate::platform_types::core_quorum_set::v0::quorum_set::{PreviousPastQuorumsV0, QuorumConfig}; -use crate::platform_types::core_quorum_set::{ - CoreQuorumSetForSaving, CoreQuorumSetV0, Quorums, ThresholdBlsPublicKey, VerificationQuorum, +use crate::platform_types::verification_quorum_set::v0::quorum_set::{ + PreviousPastQuorumsV0, QuorumConfig, +}; +use crate::platform_types::verification_quorum_set::{ + Quorums, ThresholdBlsPublicKey, VerificationQuorum, VerificationQuorumSetForSaving, + VerificationQuorumSetV0, }; use dashcore_rpc::dashcore::hashes::Hash; use dashcore_rpc::dashcore::QuorumHash; @@ -10,7 +13,7 @@ use dpp::platform_serialization::de::Decode; use dpp::platform_value::Bytes32; #[derive(Debug, Clone, Encode, Decode)] -pub struct CoreQuorumSetForSavingV0 { +pub struct VerificationQuorumSetForSavingV0 { config: QuorumConfigForSavingV0, current_quorums: Vec, @@ -18,15 +21,15 @@ pub struct CoreQuorumSetForSavingV0 { previous_quorums: Option, } -impl From for CoreQuorumSetForSaving { - fn from(value: CoreQuorumSetForSavingV0) -> Self { - CoreQuorumSetForSaving::V0(value) +impl From for VerificationQuorumSetForSaving { + fn from(value: VerificationQuorumSetForSavingV0) -> Self { + VerificationQuorumSetForSaving::V0(value) } } -impl From for CoreQuorumSetForSavingV0 { - fn from(value: CoreQuorumSetV0) -> Self { - let CoreQuorumSetV0 { +impl From for VerificationQuorumSetForSavingV0 { + fn from(value: VerificationQuorumSetV0) -> Self { + let VerificationQuorumSetV0 { config, current_quorums, previous, @@ -40,9 +43,9 @@ impl From for CoreQuorumSetForSavingV0 { } } -impl From for CoreQuorumSetV0 { - fn from(value: CoreQuorumSetForSavingV0) -> Self { - let CoreQuorumSetForSavingV0 { +impl From for VerificationQuorumSetV0 { + fn from(value: VerificationQuorumSetForSavingV0) -> Self { + let VerificationQuorumSetForSavingV0 { config, current_quorums, previous_quorums, diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/mod.rs similarity index 100% rename from packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/mod.rs rename to packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/mod.rs diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs b/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorum_set.rs similarity index 95% rename from packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs rename to packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorum_set.rs index c6da72ec868..3336108a9e6 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorum_set.rs +++ b/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorum_set.rs @@ -1,6 +1,6 @@ use crate::config::{ChainLockConfig, QuorumLikeConfig}; -use crate::platform_types::core_quorum_set::v0::quorums::Quorums; -use crate::platform_types::core_quorum_set::VerificationQuorum; +use crate::platform_types::verification_quorum_set::v0::quorums::Quorums; +use crate::platform_types::verification_quorum_set::VerificationQuorum; use dashcore_rpc::json::QuorumType; use dpp::dashcore::QuorumHash; use std::vec::IntoIter; @@ -25,7 +25,7 @@ pub(super) struct PreviousPastQuorumsV0 { /// Quorums with keys for signature verification #[derive(Debug, Clone)] -pub struct CoreQuorumSetV0 { +pub struct VerificationQuorumSetV0 { /// Quorum configuration pub(super) config: QuorumConfig, @@ -39,7 +39,7 @@ pub struct CoreQuorumSetV0 { } /// The trait defines methods for the signature verification quorums structure v0 -pub trait CoreQuorumSetV0Methods { +pub trait VerificationQuorumSetV0Methods { /// Config fn config(&self) -> &QuorumConfig; @@ -149,7 +149,7 @@ pub struct QuorumConfig { pub window: u32, } -impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { +impl VerificationQuorumSetV0Methods for VerificationQuorumSetV0 { fn config(&self) -> &QuorumConfig { &self.config } @@ -264,10 +264,10 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 { } } -impl CoreQuorumSetV0 { +impl VerificationQuorumSetV0 { /// New empty quorum set based on quorum configuration pub fn new(config: &impl QuorumLikeConfig) -> Self { - CoreQuorumSetV0 { + VerificationQuorumSetV0 { config: QuorumConfig { quorum_type: config.quorum_type(), active_signers: config.quorum_active_signers(), @@ -280,9 +280,9 @@ impl CoreQuorumSetV0 { } } -impl From for CoreQuorumSetV0 { +impl From for VerificationQuorumSetV0 { fn from(value: ChainLockConfig) -> Self { - CoreQuorumSetV0 { + VerificationQuorumSetV0 { config: QuorumConfig { quorum_type: value.quorum_type, active_signers: value.quorum_active_signers, diff --git a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs b/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorums.rs similarity index 99% rename from packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs rename to packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorums.rs index 9b30e90cc8f..4964e1cc411 100644 --- a/packages/rs-drive-abci/src/platform_types/core_quorum_set/v0/quorums.rs +++ b/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorums.rs @@ -9,7 +9,7 @@ use std::fmt::Debug; pub use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; use crate::error::Error; -use crate::platform_types::core_quorum_set::QuorumConfig; +use crate::platform_types::verification_quorum_set::QuorumConfig; use dpp::dashcore::hashes::{sha256d, Hash, HashEngine}; /// Quorum per hash diff --git a/packages/rs-drive-abci/tests/strategy_tests/execution.rs b/packages/rs-drive-abci/tests/strategy_tests/execution.rs index fa4c13ac779..879e74fc8da 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/execution.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/execution.rs @@ -28,10 +28,10 @@ use drive_abci::abci::app::FullAbciApplication; use drive_abci::config::PlatformConfig; use drive_abci::mimic::test_quorum::TestQuorumInfo; use drive_abci::mimic::{MimicExecuteBlockOptions, MimicExecuteBlockOutcome}; -use drive_abci::platform_types::core_quorum_set::{Quorums, SigningQuorum}; use drive_abci::platform_types::epoch_info::v0::EpochInfoV0; use drive_abci::platform_types::platform::Platform; use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods; +use drive_abci::platform_types::verification_quorum_set::{Quorums, SigningQuorum}; use drive_abci::platform_types::withdrawal::unsigned_withdrawal_txs::v0::UnsignedWithdrawalTxs; use drive_abci::rpc::core::MockCoreRPCLike; use drive_abci::test::fixture::abci::static_init_chain_request; diff --git a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs index b9e20d70bbd..eb21fc2f05c 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs @@ -63,7 +63,7 @@ use dpp::state_transition::documents_batch_transition::document_transition::docu use dpp::state_transition::identity_topup_transition::v0::IdentityTopUpTransitionV0; use drive_abci::abci::app::FullAbciApplication; use drive_abci::config::PlatformConfig; -use drive_abci::platform_types::core_quorum_set::{QuorumConfig, Quorums, SigningQuorum}; +use drive_abci::platform_types::verification_quorum_set::{QuorumConfig, Quorums, SigningQuorum}; use drive_abci::platform_types::withdrawal::unsigned_withdrawal_txs::v0::UnsignedWithdrawalTxs; use crate::strategy::CoreHeightIncrease::NoCoreHeightIncrease; diff --git a/packages/rs-platform-version/src/version/drive_abci_versions.rs b/packages/rs-platform-version/src/version/drive_abci_versions.rs index 4d93d94b353..70c76b46a6b 100644 --- a/packages/rs-platform-version/src/version/drive_abci_versions.rs +++ b/packages/rs-platform-version/src/version/drive_abci_versions.rs @@ -53,7 +53,7 @@ pub struct DriveAbciStructureVersions { pub state_transition_execution_context: FeatureVersion, pub commit: FeatureVersion, pub masternode: FeatureVersion, - pub core_quorum_set: FeatureVersion, + pub verification_quorum_set: FeatureVersion, } #[derive(Clone, Debug, Default)] diff --git a/packages/rs-platform-version/src/version/mocks/v2_test.rs b/packages/rs-platform-version/src/version/mocks/v2_test.rs index d5cdc416ab9..0e27d5b6d69 100644 --- a/packages/rs-platform-version/src/version/mocks/v2_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v2_test.rs @@ -502,7 +502,7 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { state_transition_execution_context: 0, commit: 0, masternode: 0, - core_quorum_set: 0, + verification_quorum_set: 0, }, methods: DriveAbciMethodVersions { engine: DriveAbciEngineMethodVersions { diff --git a/packages/rs-platform-version/src/version/mocks/v3_test.rs b/packages/rs-platform-version/src/version/mocks/v3_test.rs index ca10d64fd0e..592a436177e 100644 --- a/packages/rs-platform-version/src/version/mocks/v3_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v3_test.rs @@ -502,7 +502,7 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { state_transition_execution_context: 0, commit: 0, masternode: 0, - core_quorum_set: 0, + verification_quorum_set: 0, }, methods: DriveAbciMethodVersions { engine: DriveAbciEngineMethodVersions { diff --git a/packages/rs-platform-version/src/version/v1.rs b/packages/rs-platform-version/src/version/v1.rs index ebaaa406aa0..aea8e2349a3 100644 --- a/packages/rs-platform-version/src/version/v1.rs +++ b/packages/rs-platform-version/src/version/v1.rs @@ -501,7 +501,7 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { state_transition_execution_context: 0, commit: 0, masternode: 0, - core_quorum_set: 0, + verification_quorum_set: 0, }, methods: DriveAbciMethodVersions { engine: DriveAbciEngineMethodVersions { From e2b551f6a72741e11a76100ca2ce0af0dd66c0be Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 18 Jun 2024 23:04:44 +0800 Subject: [PATCH 37/48] refactoring: more renamings --- .../update_quorum_info/v0/mod.rs | 8 +- .../verify_chain_lock_locally/v0/mod.rs | 2 +- .../verify_recent_signature_locally/mod.rs | 2 +- .../verify_recent_signature_locally/v0/mod.rs | 4 +- .../rs-drive-abci/src/platform_types/mod.rs | 6 +- .../src/platform_types/platform_state/mod.rs | 12 +- .../platform_types/platform_state/v0/mod.rs | 36 ++-- .../mod.rs | 48 +++-- .../v0/for_saving.rs | 30 ++- .../v0/mod.rs | 0 .../v0/quorum_set.rs | 18 +- .../v0/quorums.rs | 2 +- .../signature_verification_quorums/mod.rs | 91 -------- .../signature_verification_quorums/v0/mod.rs | 198 ------------------ .../tests/strategy_tests/execution.rs | 2 +- .../tests/strategy_tests/strategy.rs | 2 +- .../src/version/drive_abci_versions.rs | 6 +- .../src/version/mocks/v2_test.rs | 4 +- .../src/version/mocks/v3_test.rs | 4 +- .../rs-platform-version/src/version/v1.rs | 4 +- 20 files changed, 98 insertions(+), 381 deletions(-) rename packages/rs-drive-abci/src/platform_types/{verification_quorum_set => signature_verification_quorum_set}/mod.rs (65%) rename packages/rs-drive-abci/src/platform_types/{verification_quorum_set => signature_verification_quorum_set}/v0/for_saving.rs (80%) rename packages/rs-drive-abci/src/platform_types/{verification_quorum_set => signature_verification_quorum_set}/v0/mod.rs (100%) rename packages/rs-drive-abci/src/platform_types/{verification_quorum_set => signature_verification_quorum_set}/v0/quorum_set.rs (95%) rename packages/rs-drive-abci/src/platform_types/{verification_quorum_set => signature_verification_quorum_set}/v0/quorums.rs (98%) delete mode 100644 packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs delete mode 100644 packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index 082c14722e6..b84db9975b5 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -13,8 +13,8 @@ use crate::platform_types::validator_set::v0::{ use crate::platform_types::validator_set::ValidatorSet; use crate::rpc::core::CoreRPCLike; -use crate::platform_types::verification_quorum_set::{ - VerificationQuorum, VerificationQuorumSet, VerificationQuorumSetV0Methods, +use crate::platform_types::signature_verification_quorum_set::{ + SignatureVerificationQuorumSet, SignatureVerificationQuorumSetV0Methods, VerificationQuorum, }; use dpp::bls_signatures::PublicKey as BlsPublicKey; use dpp::dashcore::QuorumHash; @@ -305,7 +305,7 @@ where fn update_quorums_from_quorum_list( &self, quorum_set_type: &QuorumSetType, - quorum_set: &mut VerificationQuorumSet, + quorum_set: &mut SignatureVerificationQuorumSet, platform_state: Option<&PlatformState>, full_quorum_list: &ExtendedQuorumListResult, last_committed_core_height: u32, @@ -416,7 +416,7 @@ where fn quorum_set_by_type_mut<'p>( block_platform_state: &'p mut PlatformState, quorum_set_type: &QuorumSetType, -) -> &'p mut VerificationQuorumSet { +) -> &'p mut SignatureVerificationQuorumSet { match quorum_set_type { QuorumSetType::ChainLock(_) => block_platform_state.chain_lock_validating_quorums_mut(), QuorumSetType::InstantLock(_) => block_platform_state.instant_lock_validating_quorums_mut(), diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs index 6433da149ae..a48fc30c670 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/verify_chain_lock_locally/v0/mod.rs @@ -12,7 +12,7 @@ use crate::rpc::core::CoreRPCLike; use crate::error::execution::ExecutionError; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; -use crate::platform_types::verification_quorum_set::VerificationQuorumSetV0Methods; +use crate::platform_types::signature_verification_quorum_set::SignatureVerificationQuorumSetV0Methods; use dpp::version::PlatformVersion; const CHAIN_LOCK_REQUEST_ID_PREFIX: &str = "clsig"; diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/mod.rs index c0116febcdc..e804ad228ef 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/mod.rs @@ -33,7 +33,7 @@ impl VerifyInstantLockSignature for InstantLock { match platform_version .drive_abci .methods - .core_instant_lock + .core_instant_send_lock .verify_recent_signature_locally { 0 => v0::verify_recent_instant_lock_signature_locally_v0(self, platform_state), diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/v0/mod.rs index 2c3a3fc32b6..b7fb76a10c0 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_instant_send_lock/verify_recent_signature_locally/v0/mod.rs @@ -10,7 +10,9 @@ use crate::error::Error; use crate::error::serialization::SerializationError; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; -use crate::platform_types::verification_quorum_set::{VerificationQuorumSetV0Methods, SIGN_OFFSET}; +use crate::platform_types::signature_verification_quorum_set::{ + SignatureVerificationQuorumSetV0Methods, SIGN_OFFSET, +}; #[inline(always)] pub(super) fn verify_recent_instant_lock_signature_locally_v0( diff --git a/packages/rs-drive-abci/src/platform_types/mod.rs b/packages/rs-drive-abci/src/platform_types/mod.rs index 69cfe483ea7..f6e9b3f838e 100644 --- a/packages/rs-drive-abci/src/platform_types/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/mod.rs @@ -47,8 +47,8 @@ pub mod platform; pub mod platform_state; /// Required identity public key set for system identities pub mod required_identity_public_key_set; -/// Signature verification quorums -pub mod signature_verification_quorums; +/// Signature verification quorums for Core +pub mod signature_verification_quorum_set; /// The state transition execution result as part of the block execution outcome pub mod state_transitions_processing_result; /// System identity public keys @@ -58,8 +58,6 @@ pub mod system_identity_public_keys; pub mod validator; /// Quorum methods pub mod validator_set; -/// Signature verification quorums for Core -pub mod verification_quorum_set; /// Verify chain lock result pub mod verify_chain_lock_result; /// Withdrawal types diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs index 36650327698..7276e2b94f0 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs @@ -22,7 +22,7 @@ use indexmap::IndexMap; use crate::config::PlatformConfig; use crate::error::execution::ExecutionError; -use crate::platform_types::verification_quorum_set::VerificationQuorumSet; +use crate::platform_types::signature_verification_quorum_set::SignatureVerificationQuorumSet; use dpp::block::block_info::BlockInfo; use dpp::util::hash::hash_double; use std::collections::BTreeMap; @@ -321,7 +321,7 @@ impl PlatformStateV0Methods for PlatformState { } } - fn chain_lock_validating_quorums(&self) -> &VerificationQuorumSet { + fn chain_lock_validating_quorums(&self) -> &SignatureVerificationQuorumSet { match self { PlatformState::V0(v0) => &v0.chain_lock_validating_quorums, } @@ -387,7 +387,7 @@ impl PlatformStateV0Methods for PlatformState { } } - fn set_chain_lock_validating_quorums(&mut self, quorums: VerificationQuorumSet) { + fn set_chain_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorumSet) { match self { PlatformState::V0(v0) => v0.set_chain_lock_validating_quorums(quorums), } @@ -447,7 +447,7 @@ impl PlatformStateV0Methods for PlatformState { } } - fn chain_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet { + fn chain_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorumSet { match self { PlatformState::V0(v0) => v0.chain_lock_validating_quorums_mut(), } @@ -477,13 +477,13 @@ impl PlatformStateV0Methods for PlatformState { } } - fn instant_lock_validating_quorums(&self) -> &VerificationQuorumSet { + fn instant_lock_validating_quorums(&self) -> &SignatureVerificationQuorumSet { match self { PlatformState::V0(v0) => v0.instant_lock_validating_quorums(), } } - fn instant_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet { + fn instant_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorumSet { match self { PlatformState::V0(v0) => v0.instant_lock_validating_quorums_mut(), } diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs index 77cbdb86f42..9b0fb3963e7 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs @@ -20,8 +20,8 @@ use dpp::block::extended_block_info::v0::ExtendedBlockInfoV0Getters; use dpp::version::{PlatformVersion, TryIntoPlatformVersioned}; use crate::config::PlatformConfig; -use crate::platform_types::verification_quorum_set::{ - VerificationQuorumSet, VerificationQuorumSetForSaving, +use crate::platform_types::signature_verification_quorum_set::{ + SignatureVerificationQuorumSet, SignatureVerificationQuorumSetForSaving, }; use itertools::Itertools; use std::collections::BTreeMap; @@ -48,10 +48,10 @@ pub struct PlatformStateV0 { pub validator_sets: IndexMap, /// Quorums used for validating chain locks (400 60 for mainnet) - pub chain_lock_validating_quorums: VerificationQuorumSet, + pub chain_lock_validating_quorums: SignatureVerificationQuorumSet, /// Quorums used for validating instant locks - pub instant_lock_validating_quorums: VerificationQuorumSet, + pub instant_lock_validating_quorums: SignatureVerificationQuorumSet, /// current full masternode list pub full_masternode_list: BTreeMap, @@ -133,10 +133,10 @@ pub struct PlatformStateForSavingV0 { pub validator_sets: Vec<(Bytes32, ValidatorSet)>, /// The quorums used for validating chain locks - pub chain_lock_validating_quorums: VerificationQuorumSetForSaving, + pub chain_lock_validating_quorums: SignatureVerificationQuorumSetForSaving, /// The quorums used for validating instant locks - pub instant_lock_validating_quorums: VerificationQuorumSetForSaving, + pub instant_lock_validating_quorums: SignatureVerificationQuorumSetForSaving, /// current full masternode list pub full_masternode_list: BTreeMap, @@ -243,11 +243,11 @@ impl PlatformStateV0 { current_validator_set_quorum_hash: QuorumHash::all_zeros(), next_validator_set_quorum_hash: None, validator_sets: Default::default(), - chain_lock_validating_quorums: VerificationQuorumSet::new( + chain_lock_validating_quorums: SignatureVerificationQuorumSet::new( &config.chain_lock, platform_version, )?, - instant_lock_validating_quorums: VerificationQuorumSet::new( + instant_lock_validating_quorums: SignatureVerificationQuorumSet::new( &config.instant_lock, platform_version, )?, @@ -307,10 +307,10 @@ pub trait PlatformStateV0Methods { fn validator_sets(&self) -> &IndexMap; /// Returns the quorums used to validate chain locks. - fn chain_lock_validating_quorums(&self) -> &VerificationQuorumSet; + fn chain_lock_validating_quorums(&self) -> &SignatureVerificationQuorumSet; /// Returns quorums used to validate instant locks. - fn instant_lock_validating_quorums(&self) -> &VerificationQuorumSet; + fn instant_lock_validating_quorums(&self) -> &SignatureVerificationQuorumSet; /// Returns the full list of masternodes. fn full_masternode_list(&self) -> &BTreeMap; @@ -343,7 +343,7 @@ pub trait PlatformStateV0Methods { fn set_validator_sets(&mut self, sets: IndexMap); /// Sets the current chain lock validating quorums. - fn set_chain_lock_validating_quorums(&mut self, quorums: VerificationQuorumSet); + fn set_chain_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorumSet); /// Sets the full masternode list. fn set_full_masternode_list(&mut self, list: BTreeMap); @@ -372,10 +372,10 @@ pub trait PlatformStateV0Methods { fn validator_sets_mut(&mut self) -> &mut IndexMap; /// Returns a mutable reference to the chain lock validating quorums. - fn chain_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet; + fn chain_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorumSet; /// Returns a mutable reference to the instant lock validating quorums. - fn instant_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet; + fn instant_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorumSet; /// Returns a mutable reference to the full masternode list. fn full_masternode_list_mut(&mut self) -> &mut BTreeMap; @@ -529,12 +529,12 @@ impl PlatformStateV0Methods for PlatformStateV0 { } /// Returns the quorums used to validate chain locks. - fn chain_lock_validating_quorums(&self) -> &VerificationQuorumSet { + fn chain_lock_validating_quorums(&self) -> &SignatureVerificationQuorumSet { &self.chain_lock_validating_quorums } /// Returns the quorums used to validate instant locks. - fn instant_lock_validating_quorums(&self) -> &VerificationQuorumSet { + fn instant_lock_validating_quorums(&self) -> &SignatureVerificationQuorumSet { &self.instant_lock_validating_quorums } @@ -595,7 +595,7 @@ impl PlatformStateV0Methods for PlatformStateV0 { } /// Sets the current chain lock validating quorums. - fn set_chain_lock_validating_quorums(&mut self, quorums: VerificationQuorumSet) { + fn set_chain_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorumSet) { self.chain_lock_validating_quorums = quorums; } @@ -638,11 +638,11 @@ impl PlatformStateV0Methods for PlatformStateV0 { &mut self.validator_sets } - fn chain_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet { + fn chain_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorumSet { &mut self.chain_lock_validating_quorums } - fn instant_lock_validating_quorums_mut(&mut self) -> &mut VerificationQuorumSet { + fn instant_lock_validating_quorums_mut(&mut self) -> &mut SignatureVerificationQuorumSet { &mut self.instant_lock_validating_quorums } diff --git a/packages/rs-drive-abci/src/platform_types/verification_quorum_set/mod.rs b/packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/mod.rs similarity index 65% rename from packages/rs-drive-abci/src/platform_types/verification_quorum_set/mod.rs rename to packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/mod.rs index 806415503fe..8d0eac3c0a3 100644 --- a/packages/rs-drive-abci/src/platform_types/verification_quorum_set/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/mod.rs @@ -3,12 +3,12 @@ mod v0; use crate::config::QuorumLikeConfig; use crate::error::execution::ExecutionError; use crate::error::Error; -use crate::platform_types::verification_quorum_set::v0::for_saving::VerificationQuorumSetForSavingV0; -pub use crate::platform_types::verification_quorum_set::v0::quorum_set::{ - QuorumConfig, QuorumsWithConfig, SelectedQuorumSetIterator, VerificationQuorumSetV0, - VerificationQuorumSetV0Methods, SIGN_OFFSET, +use crate::platform_types::signature_verification_quorum_set::v0::for_saving::SignatureVerificationQuorumSetForSavingV0; +pub use crate::platform_types::signature_verification_quorum_set::v0::quorum_set::{ + QuorumConfig, QuorumsWithConfig, SelectedQuorumSetIterator, SignatureVerificationQuorumSetV0, + SignatureVerificationQuorumSetV0Methods, SIGN_OFFSET, }; -pub use crate::platform_types::verification_quorum_set::v0::quorums::{ +pub use crate::platform_types::signature_verification_quorum_set::v0::quorums::{ Quorum, Quorums, SigningQuorum, ThresholdBlsPublicKey, VerificationQuorum, }; use bincode::{Decode, Encode}; @@ -17,21 +17,25 @@ use dpp::version::PlatformVersion; /// Quorums with keys for signature verification #[derive(Debug, Clone, From)] -pub enum VerificationQuorumSet { +pub enum SignatureVerificationQuorumSet { /// Version 0 of the signature verification quorums - V0(VerificationQuorumSetV0), + V0(SignatureVerificationQuorumSetV0), } -impl VerificationQuorumSet { +impl SignatureVerificationQuorumSet { /// Create a default SignatureVerificationQuorums pub fn new( config: &impl QuorumLikeConfig, platform_version: &PlatformVersion, ) -> Result { - match platform_version.drive_abci.structs.verification_quorum_set { - 0 => Ok(VerificationQuorumSetV0::new(config).into()), + match platform_version + .drive_abci + .structs + .signature_verification_quorum_set + { + 0 => Ok(SignatureVerificationQuorumSetV0::new(config).into()), version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { - method: "VerificationQuorumSet.new".to_string(), + method: "SignatureVerificationQuorumSet.new".to_string(), known_versions: vec![0], received: version, })), @@ -39,7 +43,7 @@ impl VerificationQuorumSet { } } -impl VerificationQuorumSetV0Methods for VerificationQuorumSet { +impl SignatureVerificationQuorumSetV0Methods for SignatureVerificationQuorumSet { fn config(&self) -> &QuorumConfig { match self { Self::V0(v0) => v0.config(), @@ -111,23 +115,27 @@ impl VerificationQuorumSetV0Methods for VerificationQuorumSet { /// Core Quorum Set structure for saving to the database #[derive(Debug, Clone, Encode, Decode)] -pub enum VerificationQuorumSetForSaving { +pub enum SignatureVerificationQuorumSetForSaving { /// Version 0 of the signature verification quorums - V0(VerificationQuorumSetForSavingV0), + V0(SignatureVerificationQuorumSetForSavingV0), } -impl From for VerificationQuorumSetForSaving { - fn from(value: VerificationQuorumSet) -> Self { +impl From for SignatureVerificationQuorumSetForSaving { + fn from(value: SignatureVerificationQuorumSet) -> Self { match value { - VerificationQuorumSet::V0(v0) => VerificationQuorumSetForSaving::V0(v0.into()), + SignatureVerificationQuorumSet::V0(v0) => { + SignatureVerificationQuorumSetForSaving::V0(v0.into()) + } } } } -impl From for VerificationQuorumSet { - fn from(value: VerificationQuorumSetForSaving) -> Self { +impl From for SignatureVerificationQuorumSet { + fn from(value: SignatureVerificationQuorumSetForSaving) -> Self { match value { - VerificationQuorumSetForSaving::V0(v0) => VerificationQuorumSet::V0(v0.into()), + SignatureVerificationQuorumSetForSaving::V0(v0) => { + SignatureVerificationQuorumSet::V0(v0.into()) + } } } } diff --git a/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/for_saving.rs b/packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/for_saving.rs similarity index 80% rename from packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/for_saving.rs rename to packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/for_saving.rs index 61deceb9abe..5e254e62023 100644 --- a/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/for_saving.rs +++ b/packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/for_saving.rs @@ -1,9 +1,9 @@ -use crate::platform_types::verification_quorum_set::v0::quorum_set::{ +use crate::platform_types::signature_verification_quorum_set::v0::quorum_set::{ PreviousPastQuorumsV0, QuorumConfig, }; -use crate::platform_types::verification_quorum_set::{ - Quorums, ThresholdBlsPublicKey, VerificationQuorum, VerificationQuorumSetForSaving, - VerificationQuorumSetV0, +use crate::platform_types::signature_verification_quorum_set::{ + Quorums, SignatureVerificationQuorumSetForSaving, SignatureVerificationQuorumSetV0, + ThresholdBlsPublicKey, VerificationQuorum, }; use dashcore_rpc::dashcore::hashes::Hash; use dashcore_rpc::dashcore::QuorumHash; @@ -13,23 +13,21 @@ use dpp::platform_serialization::de::Decode; use dpp::platform_value::Bytes32; #[derive(Debug, Clone, Encode, Decode)] -pub struct VerificationQuorumSetForSavingV0 { +pub struct SignatureVerificationQuorumSetForSavingV0 { config: QuorumConfigForSavingV0, - current_quorums: Vec, - previous_quorums: Option, } -impl From for VerificationQuorumSetForSaving { - fn from(value: VerificationQuorumSetForSavingV0) -> Self { - VerificationQuorumSetForSaving::V0(value) +impl From for SignatureVerificationQuorumSetForSaving { + fn from(value: SignatureVerificationQuorumSetForSavingV0) -> Self { + SignatureVerificationQuorumSetForSaving::V0(value) } } -impl From for VerificationQuorumSetForSavingV0 { - fn from(value: VerificationQuorumSetV0) -> Self { - let VerificationQuorumSetV0 { +impl From for SignatureVerificationQuorumSetForSavingV0 { + fn from(value: SignatureVerificationQuorumSetV0) -> Self { + let SignatureVerificationQuorumSetV0 { config, current_quorums, previous, @@ -43,9 +41,9 @@ impl From for VerificationQuorumSetForSavingV0 { } } -impl From for VerificationQuorumSetV0 { - fn from(value: VerificationQuorumSetForSavingV0) -> Self { - let VerificationQuorumSetForSavingV0 { +impl From for SignatureVerificationQuorumSetV0 { + fn from(value: SignatureVerificationQuorumSetForSavingV0) -> Self { + let SignatureVerificationQuorumSetForSavingV0 { config, current_quorums, previous_quorums, diff --git a/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/mod.rs similarity index 100% rename from packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/mod.rs rename to packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/mod.rs diff --git a/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorum_set.rs b/packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/quorum_set.rs similarity index 95% rename from packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorum_set.rs rename to packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/quorum_set.rs index 3336108a9e6..9225ced3164 100644 --- a/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorum_set.rs +++ b/packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/quorum_set.rs @@ -1,6 +1,6 @@ use crate::config::{ChainLockConfig, QuorumLikeConfig}; -use crate::platform_types::verification_quorum_set::v0::quorums::Quorums; -use crate::platform_types::verification_quorum_set::VerificationQuorum; +use crate::platform_types::signature_verification_quorum_set::v0::quorums::Quorums; +use crate::platform_types::signature_verification_quorum_set::VerificationQuorum; use dashcore_rpc::json::QuorumType; use dpp::dashcore::QuorumHash; use std::vec::IntoIter; @@ -25,7 +25,7 @@ pub(super) struct PreviousPastQuorumsV0 { /// Quorums with keys for signature verification #[derive(Debug, Clone)] -pub struct VerificationQuorumSetV0 { +pub struct SignatureVerificationQuorumSetV0 { /// Quorum configuration pub(super) config: QuorumConfig, @@ -39,7 +39,7 @@ pub struct VerificationQuorumSetV0 { } /// The trait defines methods for the signature verification quorums structure v0 -pub trait VerificationQuorumSetV0Methods { +pub trait SignatureVerificationQuorumSetV0Methods { /// Config fn config(&self) -> &QuorumConfig; @@ -149,7 +149,7 @@ pub struct QuorumConfig { pub window: u32, } -impl VerificationQuorumSetV0Methods for VerificationQuorumSetV0 { +impl SignatureVerificationQuorumSetV0Methods for SignatureVerificationQuorumSetV0 { fn config(&self) -> &QuorumConfig { &self.config } @@ -264,10 +264,10 @@ impl VerificationQuorumSetV0Methods for VerificationQuorumSetV0 { } } -impl VerificationQuorumSetV0 { +impl SignatureVerificationQuorumSetV0 { /// New empty quorum set based on quorum configuration pub fn new(config: &impl QuorumLikeConfig) -> Self { - VerificationQuorumSetV0 { + SignatureVerificationQuorumSetV0 { config: QuorumConfig { quorum_type: config.quorum_type(), active_signers: config.quorum_active_signers(), @@ -280,9 +280,9 @@ impl VerificationQuorumSetV0 { } } -impl From for VerificationQuorumSetV0 { +impl From for SignatureVerificationQuorumSetV0 { fn from(value: ChainLockConfig) -> Self { - VerificationQuorumSetV0 { + SignatureVerificationQuorumSetV0 { config: QuorumConfig { quorum_type: value.quorum_type, active_signers: value.quorum_active_signers, diff --git a/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorums.rs b/packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/quorums.rs similarity index 98% rename from packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorums.rs rename to packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/quorums.rs index 4964e1cc411..112b877a9b8 100644 --- a/packages/rs-drive-abci/src/platform_types/verification_quorum_set/v0/quorums.rs +++ b/packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/v0/quorums.rs @@ -9,7 +9,7 @@ use std::fmt::Debug; pub use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; use crate::error::Error; -use crate::platform_types::verification_quorum_set::QuorumConfig; +use crate::platform_types::signature_verification_quorum_set::QuorumConfig; use dpp::dashcore::hashes::{sha256d, Hash, HashEngine}; /// Quorum per hash diff --git a/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs b/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs deleted file mode 100644 index 4ad03aebc33..00000000000 --- a/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/mod.rs +++ /dev/null @@ -1,91 +0,0 @@ -mod v0; - -use crate::platform_types::signature_verification_quorums::v0::{ - PreviousPastQuorums, SelectedVerificationQuorumSets, -}; -use bincode::{Decode, Encode}; -use derive_more::From; -use dpp::version::PlatformVersion; -pub use v0::{ - QuorumKeysByQuorumHash, SignatureVerificationQuorumsV0, SignatureVerificationQuorumsV0Methods, -}; - -/// Quorums with keys for signature verification -#[derive(Debug, Clone, Encode, Decode, From)] -pub enum SignatureVerificationQuorums { - /// Version 0 of the signature verification quorums - V0(SignatureVerificationQuorumsV0), -} - -impl SignatureVerificationQuorums { - /// Create a default SignatureVerificationQuorums - pub fn default_for_platform_version(platform_version: &PlatformVersion) -> Self { - // TODO: default for platform version - - SignatureVerificationQuorumsV0::default().into() - } -} - -impl SignatureVerificationQuorumsV0Methods for SignatureVerificationQuorums { - fn set_current_quorums(&mut self, quorums: QuorumKeysByQuorumHash) { - match self { - Self::V0(v0) => v0.set_current_quorums(quorums), - } - } - - fn current_quorums(&self) -> &QuorumKeysByQuorumHash { - match self { - Self::V0(v0) => v0.current_quorums(), - } - } - - fn current_quorums_mut(&mut self) -> &mut QuorumKeysByQuorumHash { - match self { - Self::V0(v0) => v0.current_quorums_mut(), - } - } - - fn previous_past_quorums(&self) -> Option<&PreviousPastQuorums> { - match self { - Self::V0(v0) => v0.previous_past_quorums(), - } - } - - fn rotate_quorums( - &mut self, - quorums: QuorumKeysByQuorumHash, - last_active_core_height: u32, - updated_at_core_height: u32, - ) { - match self { - Self::V0(v0) => { - v0.rotate_quorums(quorums, last_active_core_height, updated_at_core_height) - } - } - } - - fn set_previous_past_quorums( - &mut self, - previous_quorums: QuorumKeysByQuorumHash, - last_active_core_height: u32, - updated_at_core_height: u32, - ) { - match self { - Self::V0(v0) => v0.set_previous_past_quorums( - previous_quorums, - last_active_core_height, - updated_at_core_height, - ), - } - } - - fn select_quorums( - &self, - signing_height: u32, - verification_height: u32, - ) -> SelectedVerificationQuorumSets { - match self { - Self::V0(v0) => v0.select_quorums(signing_height, verification_height), - } - } -} diff --git a/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs deleted file mode 100644 index 6ab87f6f6b0..00000000000 --- a/packages/rs-drive-abci/src/platform_types/signature_verification_quorums/v0/mod.rs +++ /dev/null @@ -1,198 +0,0 @@ -use bincode::{Decode, Encode}; -use dpp::dashcore::QuorumHash; -use std::collections::{BTreeMap, VecDeque}; - -pub use dpp::bls_signatures::PublicKey as ThresholdBlsPublicKey; - -/// Quorum key per hash -pub type QuorumKeysByQuorumHash = BTreeMap; - -/// Previously obtained quorums and heights. Required for signature verification -#[derive(Debug, Clone, Encode, Decode, Default)] -pub struct PreviousPastQuorums { - /// The quorum keys by quorum hash - #[bincode(with_serde)] - quorums: QuorumKeysByQuorumHash, - - /// The core height at which these quorums were last active - active_core_height: u32, - - /// The core height when the quorums were changed - updated_at_core_height: u32, - - /// The core height the previous chain lock validating quorums became active - previous_change_height: Option, -} - -/// Quorums with keys for signature verification -#[derive(Debug, Clone, Encode, Decode, Default)] -pub struct SignatureVerificationQuorumsV0 { - /// Current quorums - #[bincode(with_serde)] - current_quorums: QuorumKeysByQuorumHash, - - /// The slightly old quorums used for validating chain locks (or instant locks), it's important to keep - /// these because validation of signatures happens for the quorums that are 8 blocks before the - /// height written in the chain lock. The same for instant locks - previous: Option, -} - -/// The trait defines methods for the signature verification quorums structure v0 -pub trait SignatureVerificationQuorumsV0Methods { - /// Set last quorum keys - fn set_current_quorums(&mut self, quorums: QuorumKeysByQuorumHash); - - /// Current quorum keys by quorum hash - fn current_quorums(&self) -> &QuorumKeysByQuorumHash; - - /// The current quorums keys mutable - fn current_quorums_mut(&mut self) -> &mut QuorumKeysByQuorumHash; - - /// Previous quorums - fn previous_past_quorums(&self) -> Option<&PreviousPastQuorums>; - - /// Set last quorums keys and update previous quorums - fn rotate_quorums( - &mut self, - quorums: QuorumKeysByQuorumHash, - last_active_core_height: u32, - updated_at_core_height: u32, - ); - - /// Set previous quorums - fn set_previous_past_quorums( - &mut self, - previous_quorums: QuorumKeysByQuorumHash, - last_active_core_height: u32, - updated_at_core_height: u32, - ); - - /// Select quorum sets for signature verification - fn select_quorums( - &self, - signing_height: u32, - verification_height: u32, - ) -> SelectedVerificationQuorumSets; -} - -pub struct SelectedVerificationQuorumSets<'q> { - pub quorum_sets: VecDeque<&'q QuorumKeysByQuorumHash>, - pub should_be_verifiable: bool, -} - -impl<'q> Iterator for SelectedVerificationQuorumSets<'q> { - type Item = &'q QuorumKeysByQuorumHash; - - fn next(&mut self) -> Option { - self.quorum_sets.pop_front() - } -} - -impl SignatureVerificationQuorumsV0Methods for SignatureVerificationQuorumsV0 { - fn set_current_quorums(&mut self, quorums: QuorumKeysByQuorumHash) { - self.current_quorums = quorums; - } - - fn current_quorums(&self) -> &QuorumKeysByQuorumHash { - &self.current_quorums - } - - fn current_quorums_mut(&mut self) -> &mut QuorumKeysByQuorumHash { - &mut self.current_quorums - } - - fn previous_past_quorums(&self) -> Option<&PreviousPastQuorums> { - self.previous.as_ref() - } - - fn rotate_quorums( - &mut self, - quorums: QuorumKeysByQuorumHash, - last_active_height: u32, - updated_at_core_height: u32, - ) { - let previous_quorums = std::mem::replace(&mut self.current_quorums, quorums); - - self.set_previous_past_quorums( - previous_quorums, - last_active_height, - updated_at_core_height, - ); - } - - fn set_previous_past_quorums( - &mut self, - previous_quorums: QuorumKeysByQuorumHash, - last_active_core_height: u32, - updated_at_core_height: u32, - ) { - self.previous = Some(PreviousPastQuorums { - quorums: previous_quorums, - active_core_height: last_active_core_height, - updated_at_core_height, - previous_change_height: self - .previous - .as_ref() - .map(|previous| previous.updated_at_core_height), - }); - } - - fn select_quorums( - &self, - signing_height: u32, - verification_height: u32, - ) -> SelectedVerificationQuorumSets { - let mut quorums = VecDeque::new(); - let mut should_be_verifiable = false; - - if let Some(previous) = &self.previous { - let previous_quorum_height = previous.active_core_height; - let change_quorum_height = previous.updated_at_core_height; - let previous_quorums_change_height = previous.previous_change_height; - - if signing_height > 8 && verification_height >= change_quorum_height { - // in this case we are sure that we should be targeting the current quorum - // We updated core chain lock height from 100 to 105, new chain lock comes in for block 114 - // ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) ------ 106 (new chain lock verification height 114 - 8) - // We are sure that we should use current quorums - // If we have - // ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) ------ 105 (new chain lock verification height 113 - 8) - // We should also use current quorums, this is because at 105 we are sure new chain lock validating quorums are active - quorums.push_back(&self.current_quorums); - should_be_verifiable = true; - } else if signing_height > 8 && verification_height <= previous_quorum_height { - should_be_verifiable = previous_quorums_change_height - .map(|previous_quorums_change_height| { - verification_height > previous_quorums_change_height - }) - .unwrap_or(false); - // In this case the quorums were changed recently meaning that we should use the previous quorums to verify the chain lock - // We updated core chain lock height from 100 to 105, new chain lock comes in for block 106 - // -------- 98 (new chain lock verification height 106 - 8) ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) - // We are sure that we should use previous quorums - // If we have - // -------- 100 (new chain lock verification height 108 - 8) ------- 100 (previous_quorum_height) ------ 105 (change_quorum_height) - // We should also use previous quorums, this is because at 100 we are sure the old quorum set was active - quorums.push_back(&previous.quorums); - } else { - should_be_verifiable = previous_quorums_change_height - .map(|previous_quorums_change_height| { - verification_height > previous_quorums_change_height - }) - .unwrap_or(false); - // we are in between, so we don't actually know if it was the old one or the new one to be used. - // ------- 100 (previous_quorum_height) ------ 104 (new chain lock verification height 112 - 8) -------105 (change_quorum_height) - // we should just try both, starting with the current quorums - quorums.push_back(&self.current_quorums); - quorums.push_back(&previous.quorums); - } - } else { - quorums.push_back(&self.current_quorums); - } - - SelectedVerificationQuorumSets { - quorum_sets: quorums, - should_be_verifiable, - } - } -} diff --git a/packages/rs-drive-abci/tests/strategy_tests/execution.rs b/packages/rs-drive-abci/tests/strategy_tests/execution.rs index 879e74fc8da..08728958757 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/execution.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/execution.rs @@ -31,7 +31,7 @@ use drive_abci::mimic::{MimicExecuteBlockOptions, MimicExecuteBlockOutcome}; use drive_abci::platform_types::epoch_info::v0::EpochInfoV0; use drive_abci::platform_types::platform::Platform; use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods; -use drive_abci::platform_types::verification_quorum_set::{Quorums, SigningQuorum}; +use drive_abci::platform_types::signature_verification_quorum_set::{Quorums, SigningQuorum}; use drive_abci::platform_types::withdrawal::unsigned_withdrawal_txs::v0::UnsignedWithdrawalTxs; use drive_abci::rpc::core::MockCoreRPCLike; use drive_abci::test::fixture::abci::static_init_chain_request; diff --git a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs index eb21fc2f05c..43fba42224d 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs @@ -63,7 +63,7 @@ use dpp::state_transition::documents_batch_transition::document_transition::docu use dpp::state_transition::identity_topup_transition::v0::IdentityTopUpTransitionV0; use drive_abci::abci::app::FullAbciApplication; use drive_abci::config::PlatformConfig; -use drive_abci::platform_types::verification_quorum_set::{QuorumConfig, Quorums, SigningQuorum}; +use drive_abci::platform_types::signature_verification_quorum_set::{QuorumConfig, Quorums, SigningQuorum}; use drive_abci::platform_types::withdrawal::unsigned_withdrawal_txs::v0::UnsignedWithdrawalTxs; use crate::strategy::CoreHeightIncrease::NoCoreHeightIncrease; diff --git a/packages/rs-platform-version/src/version/drive_abci_versions.rs b/packages/rs-platform-version/src/version/drive_abci_versions.rs index 70c76b46a6b..5953f56e91c 100644 --- a/packages/rs-platform-version/src/version/drive_abci_versions.rs +++ b/packages/rs-platform-version/src/version/drive_abci_versions.rs @@ -53,7 +53,7 @@ pub struct DriveAbciStructureVersions { pub state_transition_execution_context: FeatureVersion, pub commit: FeatureVersion, pub masternode: FeatureVersion, - pub verification_quorum_set: FeatureVersion, + pub signature_verification_quorum_set: FeatureVersion, } #[derive(Clone, Debug, Default)] @@ -65,7 +65,7 @@ pub struct DriveAbciMethodVersions { pub block_fee_processing: DriveAbciBlockFeeProcessingMethodVersions, pub core_subsidy: DriveAbciCoreSubsidyMethodVersions, pub core_chain_lock: DriveAbciCoreChainLockMethodVersionsAndConstants, - pub core_instant_lock: DriveAbciCoreInstantLockMethodVersions, + pub core_instant_send_lock: DriveAbciCoreInstantSendLockMethodVersions, pub fee_pool_inwards_distribution: DriveAbciFeePoolInwardsDistributionMethodVersions, pub fee_pool_outwards_distribution: DriveAbciFeePoolOutwardsDistributionMethodVersions, pub withdrawals: DriveAbciIdentityCreditWithdrawalMethodVersions, @@ -234,7 +234,7 @@ pub struct DriveAbciCoreSubsidyMethodVersions { } #[derive(Clone, Debug, Default)] -pub struct DriveAbciCoreInstantLockMethodVersions { +pub struct DriveAbciCoreInstantSendLockMethodVersions { pub verify_recent_signature_locally: FeatureVersion, } diff --git a/packages/rs-platform-version/src/version/mocks/v2_test.rs b/packages/rs-platform-version/src/version/mocks/v2_test.rs index 0e27d5b6d69..ebd80929f0d 100644 --- a/packages/rs-platform-version/src/version/mocks/v2_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v2_test.rs @@ -15,7 +15,7 @@ use crate::version::drive_abci_versions::{ DriveAbciAssetLockValidationVersions, DriveAbciBlockEndMethodVersions, DriveAbciBlockFeeProcessingMethodVersions, DriveAbciBlockStartMethodVersions, DriveAbciCoreBasedUpdatesMethodVersions, DriveAbciCoreChainLockMethodVersionsAndConstants, - DriveAbciCoreInstantLockMethodVersions, DriveAbciCoreSubsidyMethodVersions, + DriveAbciCoreInstantSendLockMethodVersions, DriveAbciCoreSubsidyMethodVersions, DriveAbciDocumentsStateTransitionValidationVersions, DriveAbciEngineMethodVersions, DriveAbciEpochMethodVersions, DriveAbciFeePoolInwardsDistributionMethodVersions, DriveAbciFeePoolOutwardsDistributionMethodVersions, @@ -556,7 +556,7 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { make_sure_core_is_synced_to_chain_lock: 0, recent_block_count_amount: 2, }, - core_instant_lock: DriveAbciCoreInstantLockMethodVersions { + core_instant_send_lock: DriveAbciCoreInstantSendLockMethodVersions { verify_recent_signature_locally: 0, }, fee_pool_inwards_distribution: DriveAbciFeePoolInwardsDistributionMethodVersions { diff --git a/packages/rs-platform-version/src/version/mocks/v3_test.rs b/packages/rs-platform-version/src/version/mocks/v3_test.rs index 592a436177e..06f48f1973d 100644 --- a/packages/rs-platform-version/src/version/mocks/v3_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v3_test.rs @@ -15,7 +15,7 @@ use crate::version::drive_abci_versions::{ DriveAbciAssetLockValidationVersions, DriveAbciBlockEndMethodVersions, DriveAbciBlockFeeProcessingMethodVersions, DriveAbciBlockStartMethodVersions, DriveAbciCoreBasedUpdatesMethodVersions, DriveAbciCoreChainLockMethodVersionsAndConstants, - DriveAbciCoreInstantLockMethodVersions, DriveAbciCoreSubsidyMethodVersions, + DriveAbciCoreInstantSendLockMethodVersions, DriveAbciCoreSubsidyMethodVersions, DriveAbciDocumentsStateTransitionValidationVersions, DriveAbciEngineMethodVersions, DriveAbciEpochMethodVersions, DriveAbciFeePoolInwardsDistributionMethodVersions, DriveAbciFeePoolOutwardsDistributionMethodVersions, @@ -556,7 +556,7 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { make_sure_core_is_synced_to_chain_lock: 0, recent_block_count_amount: 2, }, - core_instant_lock: DriveAbciCoreInstantLockMethodVersions { + core_instant_send_lock: DriveAbciCoreInstantSendLockMethodVersions { verify_recent_signature_locally: 0, }, fee_pool_inwards_distribution: DriveAbciFeePoolInwardsDistributionMethodVersions { diff --git a/packages/rs-platform-version/src/version/v1.rs b/packages/rs-platform-version/src/version/v1.rs index aea8e2349a3..b9121cc2fac 100644 --- a/packages/rs-platform-version/src/version/v1.rs +++ b/packages/rs-platform-version/src/version/v1.rs @@ -15,7 +15,7 @@ use crate::version::drive_abci_versions::{ DriveAbciAssetLockValidationVersions, DriveAbciBlockEndMethodVersions, DriveAbciBlockFeeProcessingMethodVersions, DriveAbciBlockStartMethodVersions, DriveAbciCoreBasedUpdatesMethodVersions, DriveAbciCoreChainLockMethodVersionsAndConstants, - DriveAbciCoreInstantLockMethodVersions, DriveAbciCoreSubsidyMethodVersions, + DriveAbciCoreInstantSendLockMethodVersions, DriveAbciCoreSubsidyMethodVersions, DriveAbciDocumentsStateTransitionValidationVersions, DriveAbciEngineMethodVersions, DriveAbciEpochMethodVersions, DriveAbciFeePoolInwardsDistributionMethodVersions, DriveAbciFeePoolOutwardsDistributionMethodVersions, @@ -555,7 +555,7 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { make_sure_core_is_synced_to_chain_lock: 0, recent_block_count_amount: 2, }, - core_instant_lock: DriveAbciCoreInstantLockMethodVersions { + core_instant_send_lock: DriveAbciCoreInstantSendLockMethodVersions { verify_recent_signature_locally: 0, }, fee_pool_inwards_distribution: DriveAbciFeePoolInwardsDistributionMethodVersions { From 654b67e1b830a42351e4f80f11aec0322ba73820 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 19 Jun 2024 11:58:11 +0800 Subject: [PATCH 38/48] fix: outdated name --- packages/rs-platform-version/src/version/mocks/v2_test.rs | 2 +- packages/rs-platform-version/src/version/mocks/v3_test.rs | 2 +- packages/rs-platform-version/src/version/v1.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/rs-platform-version/src/version/mocks/v2_test.rs b/packages/rs-platform-version/src/version/mocks/v2_test.rs index ebd80929f0d..41e1a4f381b 100644 --- a/packages/rs-platform-version/src/version/mocks/v2_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v2_test.rs @@ -502,7 +502,7 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { state_transition_execution_context: 0, commit: 0, masternode: 0, - verification_quorum_set: 0, + signature_verification_quorum_set: 0, }, methods: DriveAbciMethodVersions { engine: DriveAbciEngineMethodVersions { diff --git a/packages/rs-platform-version/src/version/mocks/v3_test.rs b/packages/rs-platform-version/src/version/mocks/v3_test.rs index 06f48f1973d..c027f7886fc 100644 --- a/packages/rs-platform-version/src/version/mocks/v3_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v3_test.rs @@ -502,7 +502,7 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { state_transition_execution_context: 0, commit: 0, masternode: 0, - verification_quorum_set: 0, + signature_verification_quorum_set: 0, }, methods: DriveAbciMethodVersions { engine: DriveAbciEngineMethodVersions { diff --git a/packages/rs-platform-version/src/version/v1.rs b/packages/rs-platform-version/src/version/v1.rs index b9121cc2fac..a539e8bc29e 100644 --- a/packages/rs-platform-version/src/version/v1.rs +++ b/packages/rs-platform-version/src/version/v1.rs @@ -501,7 +501,7 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { state_transition_execution_context: 0, commit: 0, masternode: 0, - verification_quorum_set: 0, + signature_verification_quorum_set: 0, }, methods: DriveAbciMethodVersions { engine: DriveAbciEngineMethodVersions { From e5a11147e0082ddcc8d6a498d957146a2bd9fbde Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 19 Jun 2024 13:49:01 +0800 Subject: [PATCH 39/48] fix: commit signature verification is disabled by default --- .../engine/finalize_block_proposal/v0/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs b/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs index a958b6c46ae..4dbfe81b3ac 100644 --- a/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs @@ -154,15 +154,20 @@ where return Ok(validation_result.into()); } + // Verify commit + // In production this will always be true + #[cfg(not(feature = "testing-config"))] + let verify_commit_signature = true; + #[cfg(feature = "testing-config")] - if self + let verify_commit_signature = self .config .testing_configs - .block_commit_signature_verification - { - // Verify commit + .block_commit_signature_verification; + if verify_commit_signature + { let quorum_public_key = last_committed_state .current_validator_set()? .threshold_public_key(); From 828bf7ed3c2bab3954b248c22bfbd56c607793fe Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 19 Jun 2024 14:06:32 +0800 Subject: [PATCH 40/48] revert: quorum index update --- .../core_based_updates/update_quorum_info/v0/mod.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index b84db9975b5..90d4933824d 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -111,18 +111,10 @@ where let mut removed_a_validator_set = false; // Remove validator_sets entries that are no longer valid for the core block height - // and update quorum index for existing validator sets block_platform_state .validator_sets_mut() - .retain(|quorum_hash, validator_set| { - let retain = match validator_quorums_list.get(quorum_hash) { - Some(quorum_details) => { - validator_set.set_quorum_index(quorum_details.quorum_index); - true - } - None => false, - }; - + .retain(|quorum_hash, _| { + let retain = validator_quorums_list.contains_key::(quorum_hash); removed_a_validator_set |= !retain; if !retain { From 0684d6c8f34793950a67964f9bea822fe0b713bf Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 19 Jun 2024 14:34:54 +0800 Subject: [PATCH 41/48] fix: block is not signing by default --- packages/rs-drive-abci/src/mimic/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/rs-drive-abci/src/mimic/mod.rs b/packages/rs-drive-abci/src/mimic/mod.rs index e766abc9a9d..a691cd47724 100644 --- a/packages/rs-drive-abci/src/mimic/mod.rs +++ b/packages/rs-drive-abci/src/mimic/mod.rs @@ -480,8 +480,13 @@ impl<'a, C: CoreRPCLike> FullAbciApplication<'a, C> { threshold_vote_extensions: extensions, }; //if not in testing this will default to true + #[cfg(not(feature = "testing-config"))] + let sign_block = true; + #[cfg(feature = "testing-config")] - if self.platform.config.testing_configs.block_signing { + let sign_block = self.platform.config.testing_configs.block_signing; + + if sign_block { let quorum_hash: [u8; 32] = quorum_hash.try_into().expect("wrong quorum hash len"); let digest = commit .calculate_sign_hash( From 53e84c66e7d5ecabac67145fde2e21912fb2760d Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sat, 22 Jun 2024 22:45:30 +0700 Subject: [PATCH 42/48] chore: kick off CI From 58566740df19968a9f0bbce926b04d7ba664f23b Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sun, 23 Jun 2024 00:15:14 +0700 Subject: [PATCH 43/48] ci: show Rust formatting output --- .github/workflows/tests-rs-package.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests-rs-package.yml b/.github/workflows/tests-rs-package.yml index 77e28b2232f..ea58345f2dc 100644 --- a/.github/workflows/tests-rs-package.yml +++ b/.github/workflows/tests-rs-package.yml @@ -73,7 +73,12 @@ jobs: cache: false - name: Check formatting - run: exit `cargo fmt --check --package=${{ inputs.package }} | wc -l` + run: | + OUTPUT=$(cargo fmt --check --package=${{ inputs.package }}) + echo "$OUTPUT" + if [ -n "$OUTPUT" ]; then + exit 1 + fi unused_deps: name: Unused dependencies From 7dc94a64f0c02505243cd70517f34080ff077370 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sun, 23 Jun 2024 00:32:21 +0700 Subject: [PATCH 44/48] ci: improve formatting output --- .github/workflows/tests-rs-package.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests-rs-package.yml b/.github/workflows/tests-rs-package.yml index ea58345f2dc..92047b15177 100644 --- a/.github/workflows/tests-rs-package.yml +++ b/.github/workflows/tests-rs-package.yml @@ -74,9 +74,10 @@ jobs: - name: Check formatting run: | - OUTPUT=$(cargo fmt --check --package=${{ inputs.package }}) + OUTPUT=$(cargo fmt --check --package=${{ inputs.package }} 2>&1) || true echo "$OUTPUT" if [ -n "$OUTPUT" ]; then + echo "Formatting issues detected." exit 1 fi From 7378e31a522003900df5ebc159e252addae417b8 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sun, 23 Jun 2024 00:43:40 +0700 Subject: [PATCH 45/48] ci: fix formatting task --- .github/workflows/tests-rs-package.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/tests-rs-package.yml b/.github/workflows/tests-rs-package.yml index 92047b15177..2cf0b636d12 100644 --- a/.github/workflows/tests-rs-package.yml +++ b/.github/workflows/tests-rs-package.yml @@ -73,13 +73,7 @@ jobs: cache: false - name: Check formatting - run: | - OUTPUT=$(cargo fmt --check --package=${{ inputs.package }} 2>&1) || true - echo "$OUTPUT" - if [ -n "$OUTPUT" ]; then - echo "Formatting issues detected." - exit 1 - fi + run: cargo fmt --check --package=${{ inputs.package }} unused_deps: name: Unused dependencies From a328355ceb03f42a06900afd8fd06d20c0b80ceb Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sun, 23 Jun 2024 00:54:06 +0700 Subject: [PATCH 46/48] style: fix formatting --- .../src/execution/engine/finalize_block_proposal/v0/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs b/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs index 4dbfe81b3ac..68b226873b1 100644 --- a/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/engine/finalize_block_proposal/v0/mod.rs @@ -166,8 +166,7 @@ where .testing_configs .block_commit_signature_verification; - if verify_commit_signature - { + if verify_commit_signature { let quorum_public_key = last_committed_state .current_validator_set()? .threshold_public_key(); From 4f8f94a095918a3c37af69c72ca61c8b45dd7ac7 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sun, 23 Jun 2024 17:58:57 +0700 Subject: [PATCH 47/48] perf: reuse chain lock quorums for instant lock if they are the same type --- .../update_quorum_info/v0/mod.rs | 164 ++++++++++-------- .../src/platform_types/platform_state/mod.rs | 6 + .../platform_types/platform_state/v0/mod.rs | 8 + 3 files changed, 102 insertions(+), 76 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs index 90d4933824d..55c4b053321 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs @@ -7,9 +7,7 @@ use dashcore_rpc::json::{ExtendedQuorumListResult, QuorumType}; use std::collections::BTreeMap; use std::fmt::Display; -use crate::platform_types::validator_set::v0::{ - ValidatorSetV0, ValidatorSetV0Getters, ValidatorSetV0Setters, -}; +use crate::platform_types::validator_set::v0::{ValidatorSetV0, ValidatorSetV0Getters}; use crate::platform_types::validator_set::ValidatorSet; use crate::rpc::core::CoreRPCLike; @@ -20,6 +18,7 @@ use dpp::bls_signatures::PublicKey as BlsPublicKey; use dpp::dashcore::QuorumHash; use tracing::Level; +#[derive(Copy, Clone)] enum QuorumSetType { ChainLock(QuorumType), InstantLock(QuorumType), @@ -205,87 +204,61 @@ where // Update Chain Lock quorums - self.update_quorums( - QuorumSetType::ChainLock(chain_lock_quorum_type), - block_platform_state, - platform_state, - &extended_quorum_list, - is_validator_set_updated, - core_block_height, - )?; - - // Update Instant Lock quorums - - self.update_quorums( - QuorumSetType::InstantLock(instant_lock_quorum_type), - block_platform_state, - platform_state, - &extended_quorum_list, - is_validator_set_updated, - core_block_height, - )?; - - Ok(()) - } - - fn update_quorums( - &self, - quorum_set_type: QuorumSetType, - block_platform_state: &mut PlatformState, - platform_state: Option<&PlatformState>, - extended_quorum_list: &ExtendedQuorumListResult, - is_validator_set_updated: bool, - core_block_height: u32, - ) -> Result<(), Error> { - let last_committed_core_height = block_platform_state.last_committed_core_height(); - // Use already updated validator sets if we use the same quorums - if self.config.validator_set.quorum_type == quorum_set_type.quorum_type() { + let quorum_set_type = QuorumSetType::ChainLock(chain_lock_quorum_type); + let are_chainlock_quorum_updated = if chain_lock_quorum_type == validator_set_quorum_type { // Update only in case if there are any changes if is_validator_set_updated { - let quorums = block_platform_state - .validator_sets() - .iter() - .map(|(quorum_hash, validator_set)| { - ( - *quorum_hash, - VerificationQuorum { - public_key: validator_set.threshold_public_key().clone(), - index: validator_set.quorum_index(), - }, - ) - }) - .collect(); + Self::update_quorums_from_validator_set( + quorum_set_type, + platform_state, + block_platform_state, + core_block_height, + ); + } + is_validator_set_updated + } else { + self.update_quorums_from_quorum_list( + quorum_set_type, + block_platform_state.chain_lock_validating_quorums_mut(), + platform_state, + &extended_quorum_list, + last_committed_core_height, + core_block_height, + )? + }; + + // Update Instant Lock quorums + + // Use already updated chainlock quorums if we use the same quorum type + let quorum_set_type = QuorumSetType::InstantLock(instant_lock_quorum_type); + if instant_lock_quorum_type == chain_lock_quorum_type { + if are_chainlock_quorum_updated { tracing::trace!( - "updated {} validating quorums to current validator set", - quorum_set_type + "updated instant lock validating quorums to chain lock validating quorums", ); - let quorum_set = quorum_set_by_type_mut(block_platform_state, &quorum_set_type); - - if platform_state.is_some() { - // we already have state, so we update last and previous quorums - quorum_set.replace_quorums( - quorums, - last_committed_core_height, - core_block_height, - ); - } else { - // the only case where there will be no platform_state is init chain, - // so there is no previous quorums to update - quorum_set.set_current_quorums(quorums) - } + block_platform_state.set_instant_lock_validating_quorums( + block_platform_state.chain_lock_validating_quorums().clone(), + ); + } + // The same for validator set quorum type + } else if instant_lock_quorum_type == validator_set_quorum_type { + if is_validator_set_updated { + Self::update_quorums_from_validator_set( + quorum_set_type, + platform_state, + block_platform_state, + core_block_height, + ); } } else { - let quorum_set = quorum_set_by_type_mut(block_platform_state, &quorum_set_type); - - // Update quorums from the extended quorum list self.update_quorums_from_quorum_list( - &quorum_set_type, - quorum_set, + quorum_set_type, + block_platform_state.instant_lock_validating_quorums_mut(), platform_state, - extended_quorum_list, + &extended_quorum_list, last_committed_core_height, core_block_height, )?; @@ -294,15 +267,54 @@ where Ok(()) } + fn update_quorums_from_validator_set( + quorum_set_type: QuorumSetType, + platform_state: Option<&PlatformState>, + block_platform_state: &mut PlatformState, + core_block_height: u32, + ) { + let quorums = block_platform_state + .validator_sets() + .iter() + .map(|(quorum_hash, validator_set)| { + ( + *quorum_hash, + VerificationQuorum { + public_key: validator_set.threshold_public_key().clone(), + index: validator_set.quorum_index(), + }, + ) + }) + .collect(); + + tracing::trace!( + "updated {} validating quorums to current validator set", + quorum_set_type + ); + + let last_committed_core_height = block_platform_state.last_committed_core_height(); + + let quorum_set = quorum_set_by_type_mut(block_platform_state, &quorum_set_type); + + if platform_state.is_some() { + // we already have state, so we update last and previous quorums + quorum_set.replace_quorums(quorums, last_committed_core_height, core_block_height); + } else { + // the only case where there will be no platform_state is init chain, + // so there is no previous quorums to update + quorum_set.set_current_quorums(quorums) + } + } + fn update_quorums_from_quorum_list( &self, - quorum_set_type: &QuorumSetType, + quorum_set_type: QuorumSetType, quorum_set: &mut SignatureVerificationQuorumSet, platform_state: Option<&PlatformState>, full_quorum_list: &ExtendedQuorumListResult, last_committed_core_height: u32, next_core_height: u32, - ) -> Result<(), Error> { + ) -> Result { let quorums_list: BTreeMap<_, _> = full_quorum_list .quorums_by_type .get(&quorum_set_type.quorum_type()) @@ -401,7 +413,7 @@ where } } - Ok(()) + Ok(are_quorums_updated) } } diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs index 7276e2b94f0..d92a5a00c88 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs @@ -393,6 +393,12 @@ impl PlatformStateV0Methods for PlatformState { } } + fn set_instant_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorumSet) { + match self { + PlatformState::V0(v0) => v0.set_instant_lock_validating_quorums(quorums), + } + } + fn set_full_masternode_list(&mut self, list: BTreeMap) { match self { PlatformState::V0(v0) => v0.set_full_masternode_list(list), diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs index 9b0fb3963e7..2c22025628b 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs @@ -345,6 +345,9 @@ pub trait PlatformStateV0Methods { /// Sets the current chain lock validating quorums. fn set_chain_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorumSet); + /// Sets the current instant lock validating quorums. + fn set_instant_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorumSet); + /// Sets the full masternode list. fn set_full_masternode_list(&mut self, list: BTreeMap); @@ -599,6 +602,11 @@ impl PlatformStateV0Methods for PlatformStateV0 { self.chain_lock_validating_quorums = quorums; } + /// Sets the current instant lock validating quorums. + fn set_instant_lock_validating_quorums(&mut self, quorums: SignatureVerificationQuorumSet) { + self.instant_lock_validating_quorums = quorums; + } + /// Sets the full masternode list. fn set_full_masternode_list(&mut self, list: BTreeMap) { self.full_masternode_list = list; From 29fb68b4e730f632637f01628b6b1d73e9a6f647 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sun, 23 Jun 2024 18:51:39 +0700 Subject: [PATCH 48/48] ci: install Rust 1.76 as default toolchain --- .github/actions/rust/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/rust/action.yaml b/.github/actions/rust/action.yaml index a6aa86446e0..4965f7721a9 100644 --- a/.github/actions/rust/action.yaml +++ b/.github/actions/rust/action.yaml @@ -5,7 +5,7 @@ inputs: toolchain: description: Rust toolchain to use, stable / nightly / beta, or exact version # The same as in /README.md - default: "stable" + default: "1.76" target: description: Target Rust platform required: false