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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/dapi-grpc/protos/platform/v0/platform.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ service Platform {
rpc getTotalCreditsInPlatform(GetTotalCreditsInPlatformRequest) returns (GetTotalCreditsInPlatformResponse);
rpc getPathElements(GetPathElementsRequest) returns (GetPathElementsResponse);
rpc getStatus(GetStatusRequest) returns (GetStatusResponse);
rpc getCurrentQuorumsInfo(GetCurrentQuorumsInfoRequest) returns (GetCurrentQuorumsInfoResponse);
}

// Proof message includes cryptographic proofs for validating responses
Expand Down Expand Up @@ -1184,3 +1185,33 @@ message GetStatusResponse {

oneof version { GetStatusResponseV0 v0 = 1; }
}

message GetCurrentQuorumsInfoRequest {
message GetCurrentQuorumsInfoRequestV0 {
}

oneof version { GetCurrentQuorumsInfoRequestV0 v0 = 1; }
}

message GetCurrentQuorumsInfoResponse {
message ValidatorV0 {
bytes pro_tx_hash = 1;
string node_ip = 2;
bool is_banned = 3;
}
message ValidatorSetV0 {
bytes quorum_hash = 1;
uint32 core_height = 2;
repeated ValidatorV0 members = 3;
bytes threshold_public_key = 4;
}

message GetCurrentQuorumsInfoResponseV0 {
repeated bytes quorum_hashes = 1;
bytes current_quorum_hash = 2;
repeated ValidatorSetV0 validator_sets = 3;
bytes last_block_proposer = 4;
ResponseMetadata metadata = 5;
}
oneof version { GetCurrentQuorumsInfoResponseV0 v0 = 1; }
}
9 changes: 9 additions & 0 deletions packages/rs-dapi-client/src/transport/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,15 @@ impl_transport_request_grpc!(
get_total_credits_in_platform
);

// rpc getCurrentQuorumsInfo(GetCurrentQuorumsInfoRequest) returns (GetCurrentQuorumsInfoResponse);
impl_transport_request_grpc!(
platform_proto::GetCurrentQuorumsInfoRequest,
platform_proto::GetCurrentQuorumsInfoResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_current_quorums_info
);

// Link to each core gRPC request what client and method to use:

impl_transport_request_grpc!(
Expand Down
15 changes: 15 additions & 0 deletions packages/rs-dpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ all_features = [
"identity-hashing",
"identity-serialization",
"ciborium",
"core-types",
"core-types-serialization",
"core-types-serde-conversion",
"document-serde-conversion",
"document-value-conversion",
"document-json-conversion",
Expand Down Expand Up @@ -131,6 +134,9 @@ dash-sdk-features = [
"document-value-conversion",
"data-contract-value-conversion",
"identity-value-conversion",
"core-types",
"core-types-serialization",
"core-types-serde-conversion",
"state-transition-serde-conversion",
"state-transition-value-conversion",
"state-transition-json-conversion",
Expand All @@ -152,6 +158,9 @@ all_features_without_client = [
"identity-hashing",
"identity-serialization",
"ciborium",
"core-types",
"core-types-serialization",
"core-types-serde-conversion",
"document-serde-conversion",
"document-value-conversion",
"document-json-conversion",
Expand Down Expand Up @@ -189,6 +198,9 @@ abci = [
"identity-serialization",
"vote-serialization",
"platform-value-cbor",
"core-types",
"core-types-serialization",
"core-types-serde-conversion",
]
cbor = ["ciborium"]
validation = [
Expand Down Expand Up @@ -261,6 +273,9 @@ state-transition-signing = [
]
vote-serialization = []
vote-serde-conversion = []
core-types = ["bls-signatures"]
core-types-serialization = ["core-types"]
core-types-serde-conversion = ["core-types"]
state-transitions = []
system_contracts = ["factories", "data-contracts", "platform-value-json"]
fixtures-and-mocks = ["system_contracts", "platform-value/json"]
Expand Down
2 changes: 2 additions & 0 deletions packages/rs-dpp/src/core_types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod validator;
pub mod validator_set;
119 changes: 119 additions & 0 deletions packages/rs-dpp/src/core_types/validator/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use crate::bls_signatures::PublicKey as BlsPublicKey;
use crate::core_types::validator::v0::{ValidatorV0, ValidatorV0Getters, ValidatorV0Setters};
use dashcore::{ProTxHash, PubkeyHash};
#[cfg(feature = "core-types-serde-conversion")]
use serde::{Deserialize, Serialize};

/// Version 0
pub mod v0;

/// A validator in the context of a quorum
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "core-types-serde-conversion",
derive(Serialize, Deserialize)
)]
pub enum Validator {
/// Version 0
V0(ValidatorV0),
}

impl ValidatorV0Getters for Validator {
fn pro_tx_hash(&self) -> &ProTxHash {
match self {
Validator::V0(v0) => v0.pro_tx_hash(),
}
}

fn public_key(&self) -> &Option<BlsPublicKey> {
match self {
Validator::V0(v0) => v0.public_key(),
}
}

fn node_ip(&self) -> &String {
match self {
Validator::V0(v0) => v0.node_ip(),
}
}

fn node_id(&self) -> &PubkeyHash {
match self {
Validator::V0(v0) => v0.node_id(),
}
}

fn core_port(&self) -> u16 {
match self {
Validator::V0(v0) => v0.core_port(),
}
}

fn platform_http_port(&self) -> u16 {
match self {
Validator::V0(v0) => v0.platform_http_port(),
}
}

fn platform_p2p_port(&self) -> u16 {
match self {
Validator::V0(v0) => v0.platform_p2p_port(),
}
}

fn is_banned(&self) -> bool {
match self {
Validator::V0(v0) => v0.is_banned(),
}
}
}
Comment on lines +21 to +69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor repetitive match statements in ValidatorV0Getters implementation

The implementation of ValidatorV0Getters for Validator contains repetitive match statements for each method. This repetition can be minimized to improve code readability and maintainability.

Consider implementing the trait methods using a macro or delegating directly to the inner ValidatorV0. Since Validator currently has only one variant (V0), you can simplify the code:

impl ValidatorV0Getters for Validator {
    fn pro_tx_hash(&self) -> &ProTxHash {
        &self.as_v0().pro_tx_hash
    }

    fn public_key(&self) -> &Option<BlsPublicKey> {
        &self.as_v0().public_key
    }

    // Implement other methods similarly...
}

impl Validator {
    fn as_v0(&self) -> &ValidatorV0 {
        match self {
            Validator::V0(v0) => v0,
        }
    }
}

This approach reduces the repetitive pattern matching in each method.


impl ValidatorV0Setters for Validator {
fn set_pro_tx_hash(&mut self, pro_tx_hash: ProTxHash) {
match self {
Validator::V0(v0) => v0.set_pro_tx_hash(pro_tx_hash),
}
}

fn set_public_key(&mut self, public_key: Option<BlsPublicKey>) {
match self {
Validator::V0(v0) => v0.set_public_key(public_key),
}
}

fn set_node_ip(&mut self, node_ip: String) {
match self {
Validator::V0(v0) => v0.set_node_ip(node_ip),
}
}

fn set_node_id(&mut self, node_id: PubkeyHash) {
match self {
Validator::V0(v0) => v0.set_node_id(node_id),
}
}

fn set_core_port(&mut self, core_port: u16) {
match self {
Validator::V0(v0) => v0.set_core_port(core_port),
}
}

fn set_platform_http_port(&mut self, platform_http_port: u16) {
match self {
Validator::V0(v0) => v0.set_platform_http_port(platform_http_port),
}
}

fn set_platform_p2p_port(&mut self, platform_p2p_port: u16) {
match self {
Validator::V0(v0) => v0.set_platform_p2p_port(platform_p2p_port),
}
}

fn set_is_banned(&mut self, is_banned: bool) {
match self {
Validator::V0(v0) => v0.set_is_banned(is_banned),
}
}
}
Comment on lines +71 to +119
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor repetitive match statements in ValidatorV0Setters implementation

Similarly, the ValidatorV0Setters implementation contains repetitive match statements for each setter method. Refactoring this can enhance maintainability.

You can apply the same strategy as with the getters by adding a mutable accessor for ValidatorV0:

impl ValidatorV0Setters for Validator {
    fn set_pro_tx_hash(&mut self, pro_tx_hash: ProTxHash) {
        self.as_mut_v0().pro_tx_hash = pro_tx_hash;
    }

    fn set_public_key(&mut self, public_key: Option<BlsPublicKey>) {
        self.as_mut_v0().public_key = public_key;
    }

    // Implement other methods similarly...
}

impl Validator {
    fn as_mut_v0(&mut self) -> &mut ValidatorV0 {
        match self {
            Validator::V0(v0) => v0,
        }
    }
}

This refactoring reduces redundancy and makes the code cleaner.

Loading
Loading