Skip to content

Commit

Permalink
fix(drive)!: non-deterministic extended quorum info (#1425)
Browse files Browse the repository at this point in the history
Co-authored-by: Quantum Explorer <quantum@dash.org>
  • Loading branch information
shumkov and QuantumExplorer authored Sep 28, 2023
1 parent 0e59eaf commit 2b522d2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/rs-drive-abci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bs58 = "0.4.0"
hex = "0.4.3"
indexmap = { version = "1.9.3", features = ["serde"] }
sha2 = "0.10.6"
dashcore-rpc = { git = "https://github.com/dashpay/rust-dashcore-rpc", branch = "master" }
dashcore-rpc = { git = "https://github.com/dashpay/rust-dashcore-rpc", tag = "v0.15.1" }
dpp = { path = "../rs-dpp", features = ["abci"] }
rust_decimal = "1.2.5"
rust_decimal_macros = "1.25.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::rpc::core::CoreRPCLike;

use dpp::dashcore::QuorumHash;
use std::cmp::Ordering;
use std::collections::BTreeMap;

Check warning on line 13 in packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `std::collections::BTreeMap`

warning: unused import: `std::collections::BTreeMap` --> packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_quorum_info/v0/mod.rs:13:5 | 13 | use std::collections::BTreeMap; | ^^^^^^^^^^^^^^^^^^^^^^^^^^

impl<C> Platform<C>
where
Expand Down Expand Up @@ -137,7 +138,18 @@ where
block_platform_state.validator_sets()
);

block_platform_state.set_quorums_extended_info(quorum_list.quorums_by_type);
let quorums_by_type = quorum_list
.quorums_by_type
.into_iter()
.map(|(quorum_type, quorum_list)| {
let sorted_quorum_list = quorum_list.into_iter().collect();

(quorum_type, sorted_quorum_list)
})
.collect();

block_platform_state.set_quorums_extended_info(quorums_by_type);

Ok(())
}
}
16 changes: 11 additions & 5 deletions packages/rs-drive-abci/src/platform_types/platform_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crate::platform_types::platform_state::v0::{
};

use crate::platform_types::validator_set::ValidatorSet;
use crate::rpc::core::QuorumListExtendedInfo;
use dashcore_rpc::dashcore_rpc_json::{MasternodeListItem, QuorumType};
use dashcore_rpc::dashcore_rpc_json::{ExtendedQuorumDetails, MasternodeListItem, QuorumType};
use derive_more::From;
use dpp::bincode::{config, Decode, Encode};
use dpp::block::epoch::Epoch;
Expand Down Expand Up @@ -304,7 +303,9 @@ impl PlatformStateV0Methods for PlatformState {
}
}

fn quorums_extended_info(&self) -> &HashMap<QuorumType, QuorumListExtendedInfo> {
fn quorums_extended_info(
&self,
) -> &BTreeMap<QuorumType, BTreeMap<QuorumHash, ExtendedQuorumDetails>> {
match self {
PlatformState::V0(v0) => &v0.quorums_extended_info,
}
Expand Down Expand Up @@ -364,7 +365,10 @@ impl PlatformStateV0Methods for PlatformState {
}
}

fn set_quorums_extended_info(&mut self, info: HashMap<QuorumType, QuorumListExtendedInfo>) {
fn set_quorums_extended_info(
&mut self,
info: BTreeMap<QuorumType, BTreeMap<QuorumHash, ExtendedQuorumDetails>>,
) {
match self {
PlatformState::V0(v0) => v0.set_quorums_extended_info(info),
}
Expand Down Expand Up @@ -424,7 +428,9 @@ impl PlatformStateV0Methods for PlatformState {
}
}

fn quorums_extended_info_mut(&mut self) -> &mut HashMap<QuorumType, QuorumListExtendedInfo> {
fn quorums_extended_info_mut(
&mut self,
) -> &mut BTreeMap<QuorumType, BTreeMap<QuorumHash, ExtendedQuorumDetails>> {
match self {
PlatformState::V0(v0) => v0.quorums_extended_info_mut(),
}
Expand Down
29 changes: 21 additions & 8 deletions packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::rpc::core::QuorumListExtendedInfo;
use dashcore_rpc::dashcore::{ProTxHash, QuorumHash};
use dashcore_rpc::dashcore_rpc_json::{ExtendedQuorumDetails, MasternodeListItem};
use dashcore_rpc::json::QuorumType;
Expand Down Expand Up @@ -31,7 +30,7 @@ pub struct PlatformStateV0 {
/// upcoming protocol version
pub next_epoch_protocol_version: ProtocolVersion,
/// current quorums
pub quorums_extended_info: HashMap<QuorumType, QuorumListExtendedInfo>,
pub quorums_extended_info: BTreeMap<QuorumType, BTreeMap<QuorumHash, ExtendedQuorumDetails>>,
/// current quorum
pub current_validator_set_quorum_hash: QuorumHash,
/// next quorum
Expand Down Expand Up @@ -251,7 +250,9 @@ pub trait PlatformStateV0Methods {
fn next_epoch_protocol_version(&self) -> ProtocolVersion;

/// Returns extended information about the current quorums.
fn quorums_extended_info(&self) -> &HashMap<QuorumType, QuorumListExtendedInfo>;
fn quorums_extended_info(
&self,
) -> &BTreeMap<QuorumType, BTreeMap<QuorumHash, ExtendedQuorumDetails>>;

/// Returns the quorum hash of the current validator set.
fn current_validator_set_quorum_hash(&self) -> QuorumHash;
Expand Down Expand Up @@ -284,7 +285,10 @@ pub trait PlatformStateV0Methods {
fn set_next_epoch_protocol_version(&mut self, version: ProtocolVersion);

/// Sets the extended info for the current quorums.
fn set_quorums_extended_info(&mut self, info: HashMap<QuorumType, QuorumListExtendedInfo>);
fn set_quorums_extended_info(
&mut self,
info: BTreeMap<QuorumType, BTreeMap<QuorumHash, ExtendedQuorumDetails>>,
);

/// Sets the current validator set quorum hash.
fn set_current_validator_set_quorum_hash(&mut self, hash: QuorumHash);
Expand Down Expand Up @@ -313,7 +317,9 @@ pub trait PlatformStateV0Methods {
fn next_epoch_protocol_version_mut(&mut self) -> &mut ProtocolVersion;

/// Returns a mutable reference to the extended info for the current quorums.
fn quorums_extended_info_mut(&mut self) -> &mut HashMap<QuorumType, QuorumListExtendedInfo>;
fn quorums_extended_info_mut(
&mut self,
) -> &mut BTreeMap<QuorumType, BTreeMap<QuorumHash, ExtendedQuorumDetails>>;

/// Returns a mutable reference to the current validator set quorum hash.
fn current_validator_set_quorum_hash_mut(&mut self) -> &mut QuorumHash;
Expand Down Expand Up @@ -484,7 +490,9 @@ impl PlatformStateV0Methods for PlatformStateV0 {
}

/// Returns extended information about the current quorums.
fn quorums_extended_info(&self) -> &HashMap<QuorumType, QuorumListExtendedInfo> {
fn quorums_extended_info(
&self,
) -> &BTreeMap<QuorumType, BTreeMap<QuorumHash, ExtendedQuorumDetails>> {
&self.quorums_extended_info
}

Expand Down Expand Up @@ -539,7 +547,10 @@ impl PlatformStateV0Methods for PlatformStateV0 {
}

/// Sets the extended info for the current quorums.
fn set_quorums_extended_info(&mut self, info: HashMap<QuorumType, QuorumListExtendedInfo>) {
fn set_quorums_extended_info(
&mut self,
info: BTreeMap<QuorumType, BTreeMap<QuorumHash, ExtendedQuorumDetails>>,
) {
self.quorums_extended_info = info;
}

Expand Down Expand Up @@ -585,7 +596,9 @@ impl PlatformStateV0Methods for PlatformStateV0 {
&mut self.next_epoch_protocol_version
}

fn quorums_extended_info_mut(&mut self) -> &mut HashMap<QuorumType, QuorumListExtendedInfo> {
fn quorums_extended_info_mut(
&mut self,
) -> &mut BTreeMap<QuorumType, BTreeMap<QuorumHash, ExtendedQuorumDetails>> {
&mut self.quorums_extended_info
}

Expand Down

0 comments on commit 2b522d2

Please sign in to comment.