1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#[cfg(any(test, feature = "fuzzing"))]
use crate::network_address::{
encrypted::{TEST_SHARED_VAL_NETADDR_KEY, TEST_SHARED_VAL_NETADDR_KEY_VERSION},
NetworkAddress,
};
use crate::{account_address::AccountAddress, validator_config::ValidatorConfig};
use diem_crypto::ed25519::Ed25519PublicKey;
#[cfg(any(test, feature = "fuzzing"))]
use proptest_derive::Arbitrary;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
pub struct ValidatorInfo {
account_address: AccountAddress,
consensus_voting_power: u64,
config: ValidatorConfig,
last_config_update_time: u64,
}
impl fmt::Display for ValidatorInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
write!(
f,
"account_address: {}",
self.account_address.short_str_lossless()
)
}
}
impl ValidatorInfo {
pub fn new(
account_address: AccountAddress,
consensus_voting_power: u64,
config: ValidatorConfig,
) -> Self {
ValidatorInfo {
account_address,
consensus_voting_power,
config,
last_config_update_time: 0,
}
}
#[cfg(any(test, feature = "fuzzing"))]
pub fn new_with_test_network_keys(
account_address: AccountAddress,
consensus_public_key: Ed25519PublicKey,
consensus_voting_power: u64,
) -> Self {
let addr = NetworkAddress::mock();
let enc_addr = addr.clone().encrypt(
&TEST_SHARED_VAL_NETADDR_KEY,
TEST_SHARED_VAL_NETADDR_KEY_VERSION,
&account_address,
0,
0,
);
let config = ValidatorConfig::new(
consensus_public_key,
bcs::to_bytes(&vec![enc_addr.unwrap()]).unwrap(),
bcs::to_bytes(&vec![addr]).unwrap(),
);
Self {
account_address,
consensus_voting_power,
config,
last_config_update_time: 0,
}
}
pub fn account_address(&self) -> &AccountAddress {
&self.account_address
}
pub fn consensus_public_key(&self) -> &Ed25519PublicKey {
&self.config.consensus_public_key
}
pub fn consensus_voting_power(&self) -> u64 {
self.consensus_voting_power
}
pub fn config(&self) -> &ValidatorConfig {
&self.config
}
pub fn into_config(self) -> ValidatorConfig {
self.config
}
}