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::network_address::{encrypted::EncNetworkAddress, NetworkAddress};
9use diem_crypto::{
10    bls::{BLSPrivateKey, BLSPublicKey, BLSSignature},
11    ec_vrf::{EcVrfPrivateKey, EcVrfProof, EcVrfPublicKey},
12    multi_bls::{MultiBLSPrivateKey, MultiBLSPublicKey, MultiBLSSignature},
13};
14#[cfg(any(test, feature = "fuzzing"))]
15use proptest_derive::Arbitrary;
16use serde::{Deserialize, Serialize};
17
18#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
19#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
20pub struct ValidatorConfig {
21    pub consensus_public_key: ConsensusPublicKey,
22    /// None if the leader election does not need VRF.
23    pub vrf_public_key: Option<ConsensusVRFPublicKey>,
24    /// This is an bcs serialized `Vec<EncNetworkAddress>`
25    pub validator_network_addresses: Vec<u8>,
26    /// This is an bcs serialized `Vec<NetworkAddress>`
27    pub fullnode_network_addresses: Vec<u8>,
28}
29
30impl ValidatorConfig {
31    pub fn new(
32        consensus_public_key: ConsensusPublicKey,
33        vrf_public_key: Option<ConsensusVRFPublicKey>,
34        validator_network_addresses: Vec<u8>,
35        fullnode_network_addresses: Vec<u8>,
36    ) -> Self {
37        ValidatorConfig {
38            consensus_public_key,
39            vrf_public_key,
40            validator_network_addresses,
41            fullnode_network_addresses,
42        }
43    }
44
45    pub fn fullnode_network_addresses(
46        &self,
47    ) -> Result<Vec<NetworkAddress>, bcs::Error> {
48        bcs::from_bytes(&self.fullnode_network_addresses)
49    }
50
51    pub fn validator_network_addresses(
52        &self,
53    ) -> Result<Vec<EncNetworkAddress>, bcs::Error> {
54        bcs::from_bytes(&self.validator_network_addresses)
55    }
56}
57
58// TODO(lpl): Put this in a proper place.
59pub type ConsensusPublicKey = BLSPublicKey;
60pub type ConsensusPrivateKey = BLSPrivateKey;
61pub type ConsensusSignature = BLSSignature;
62pub type ConsensusVRFPublicKey = EcVrfPublicKey;
63pub type ConsensusVRFPrivateKey = EcVrfPrivateKey;
64pub type ConsensusVRFProof = EcVrfProof;
65pub type MultiConsensusPublicKey = MultiBLSPublicKey;
66pub type MultiConsensusPrivateKey = MultiBLSPrivateKey;
67pub type MultiConsensusSignature = MultiBLSSignature;