diem_types/
validator_config.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8use crate::{
9    account_address::AccountAddress,
10    network_address::{encrypted::EncNetworkAddress, NetworkAddress},
11};
12use diem_crypto::{
13    bls::{BLSPrivateKey, BLSPublicKey, BLSSignature},
14    ec_vrf::{EcVrfPrivateKey, EcVrfProof, EcVrfPublicKey},
15    multi_bls::{MultiBLSPrivateKey, MultiBLSPublicKey, MultiBLSSignature},
16};
17use move_core_types::move_resource::MoveResource;
18#[cfg(any(test, feature = "fuzzing"))]
19use proptest_derive::Arbitrary;
20use serde::{Deserialize, Serialize};
21
22#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq, Default)]
23pub struct ValidatorConfigResource {
24    pub validator_config: Option<ValidatorConfig>,
25    pub delegated_account: Option<AccountAddress>,
26    pub human_name: Vec<u8>,
27}
28
29impl MoveResource for ValidatorConfigResource {
30    const MODULE_NAME: &'static str = "ValidatorConfig";
31    const STRUCT_NAME: &'static str = "ValidatorConfig";
32}
33
34#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq, Default)]
35pub struct ValidatorOperatorConfigResource {
36    pub human_name: Vec<u8>,
37}
38
39impl MoveResource for ValidatorOperatorConfigResource {
40    const MODULE_NAME: &'static str = "ValidatorOperatorConfig";
41    const STRUCT_NAME: &'static str = "ValidatorOperatorConfig";
42}
43
44#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
45#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
46pub struct ValidatorConfig {
47    pub consensus_public_key: ConsensusPublicKey,
48    /// None if the leader election does not need VRF.
49    pub vrf_public_key: Option<ConsensusVRFPublicKey>,
50    /// This is an bcs serialized `Vec<EncNetworkAddress>`
51    pub validator_network_addresses: Vec<u8>,
52    /// This is an bcs serialized `Vec<NetworkAddress>`
53    pub fullnode_network_addresses: Vec<u8>,
54}
55
56impl ValidatorConfig {
57    pub fn new(
58        consensus_public_key: ConsensusPublicKey,
59        vrf_public_key: Option<ConsensusVRFPublicKey>,
60        validator_network_addresses: Vec<u8>,
61        fullnode_network_addresses: Vec<u8>,
62    ) -> Self {
63        ValidatorConfig {
64            consensus_public_key,
65            vrf_public_key,
66            validator_network_addresses,
67            fullnode_network_addresses,
68        }
69    }
70
71    pub fn fullnode_network_addresses(
72        &self,
73    ) -> Result<Vec<NetworkAddress>, bcs::Error> {
74        bcs::from_bytes(&self.fullnode_network_addresses)
75    }
76
77    pub fn validator_network_addresses(
78        &self,
79    ) -> Result<Vec<EncNetworkAddress>, bcs::Error> {
80        bcs::from_bytes(&self.validator_network_addresses)
81    }
82}
83
84// TODO(lpl): Put this in a proper place.
85pub type ConsensusPublicKey = BLSPublicKey;
86pub type ConsensusPrivateKey = BLSPrivateKey;
87pub type ConsensusSignature = BLSSignature;
88pub type ConsensusVRFPublicKey = EcVrfPublicKey;
89pub type ConsensusVRFPrivateKey = EcVrfPrivateKey;
90pub type ConsensusVRFProof = EcVrfProof;
91pub type MultiConsensusPublicKey = MultiBLSPublicKey;
92pub type MultiConsensusPrivateKey = MultiBLSPrivateKey;
93pub type MultiConsensusSignature = MultiBLSSignature;