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 diem_crypto::{
9    bls::{BLSPrivateKey, BLSPublicKey, BLSSignature},
10    ec_vrf::{EcVrfPrivateKey, EcVrfProof, EcVrfPublicKey},
11    multi_bls::{MultiBLSPrivateKey, MultiBLSPublicKey, MultiBLSSignature},
12};
13#[cfg(any(test, feature = "fuzzing"))]
14use proptest_derive::Arbitrary;
15use serde::{Deserialize, Serialize};
16
17#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
18#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
19pub struct ValidatorConfig {
20    pub consensus_public_key: ConsensusPublicKey,
21    /// None if the leader election does not need VRF.
22    pub vrf_public_key: Option<ConsensusVRFPublicKey>,
23    // Both address fields are placeholders — always `vec![]`. Kept to
24    // preserve the BCS layout of the genesis `ValidatorSet` event (and
25    // thus the genesis transaction hash) for existing deployments.
26    // Historically held BCS-encoded validator network address stacks;
27    // Conflux-PoS never populated them.
28    pub validator_network_addresses: Vec<u8>,
29    pub fullnode_network_addresses: Vec<u8>,
30}
31
32impl ValidatorConfig {
33    pub fn new(
34        consensus_public_key: ConsensusPublicKey,
35        vrf_public_key: Option<ConsensusVRFPublicKey>,
36        validator_network_addresses: Vec<u8>,
37        fullnode_network_addresses: Vec<u8>,
38    ) -> Self {
39        ValidatorConfig {
40            consensus_public_key,
41            vrf_public_key,
42            validator_network_addresses,
43            fullnode_network_addresses,
44        }
45    }
46}
47
48// TODO(lpl): Put this in a proper place.
49pub type ConsensusPublicKey = BLSPublicKey;
50pub type ConsensusPrivateKey = BLSPrivateKey;
51pub type ConsensusSignature = BLSSignature;
52pub type ConsensusVRFPublicKey = EcVrfPublicKey;
53pub type ConsensusVRFPrivateKey = EcVrfPrivateKey;
54pub type ConsensusVRFProof = EcVrfProof;
55pub type MultiConsensusPublicKey = MultiBLSPublicKey;
56pub type MultiConsensusPrivateKey = MultiBLSPrivateKey;
57pub type MultiConsensusSignature = MultiBLSSignature;