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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
use casper_types::bytesrepr::{self, FromBytes, ToBytes};
use datasize::DataSize;
use rand::{distributions::Standard, prelude::*, Rng};
use serde::{Deserialize, Serialize};
pub const DEFAULT_GET_ERA_VALIDATORS_COST: u32 = 10_000;
pub const DEFAULT_READ_SEIGNIORAGE_RECIPIENTS_COST: u32 = 10_000;
pub const DEFAULT_ADD_BID_COST: u32 = 10_000;
pub const DEFAULT_WITHDRAW_BID_COST: u32 = 10_000;
pub const DEFAULT_DELEGATE_COST: u32 = 10_000;
pub const DEFAULT_UNDELEGATE_COST: u32 = 10_000;
pub const DEFAULT_RUN_AUCTION_COST: u32 = 10_000;
pub const DEFAULT_SLASH_COST: u32 = 10_000;
pub const DEFAULT_DISTRIBUTE_COST: u32 = 10_000;
pub const DEFAULT_WITHDRAW_DELEGATOR_REWARD_COST: u32 = 10_000;
pub const DEFAULT_WITHDRAW_VALIDATOR_REWARD_COST: u32 = 10_000;
pub const DEFAULT_READ_ERA_ID_COST: u32 = 10_000;
pub const DEFAULT_ACTIVATE_BID_COST: u32 = 10_000;
#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Debug, DataSize)]
pub struct AuctionCosts {
pub get_era_validators: u32,
pub read_seigniorage_recipients: u32,
pub add_bid: u32,
pub withdraw_bid: u32,
pub delegate: u32,
pub undelegate: u32,
pub run_auction: u32,
pub slash: u32,
pub distribute: u32,
pub withdraw_delegator_reward: u32,
pub withdraw_validator_reward: u32,
pub read_era_id: u32,
pub activate_bid: u32,
}
impl Default for AuctionCosts {
fn default() -> Self {
Self {
get_era_validators: DEFAULT_GET_ERA_VALIDATORS_COST,
read_seigniorage_recipients: DEFAULT_READ_SEIGNIORAGE_RECIPIENTS_COST,
add_bid: DEFAULT_ADD_BID_COST,
withdraw_bid: DEFAULT_WITHDRAW_BID_COST,
delegate: DEFAULT_DELEGATE_COST,
undelegate: DEFAULT_UNDELEGATE_COST,
run_auction: DEFAULT_RUN_AUCTION_COST,
slash: DEFAULT_SLASH_COST,
distribute: DEFAULT_DISTRIBUTE_COST,
withdraw_delegator_reward: DEFAULT_WITHDRAW_DELEGATOR_REWARD_COST,
withdraw_validator_reward: DEFAULT_WITHDRAW_VALIDATOR_REWARD_COST,
read_era_id: DEFAULT_READ_ERA_ID_COST,
activate_bid: DEFAULT_ACTIVATE_BID_COST,
}
}
}
impl ToBytes for AuctionCosts {
fn to_bytes(&self) -> Result<Vec<u8>, casper_types::bytesrepr::Error> {
let mut ret = bytesrepr::unchecked_allocate_buffer(self);
ret.append(&mut self.get_era_validators.to_bytes()?);
ret.append(&mut self.read_seigniorage_recipients.to_bytes()?);
ret.append(&mut self.add_bid.to_bytes()?);
ret.append(&mut self.withdraw_bid.to_bytes()?);
ret.append(&mut self.delegate.to_bytes()?);
ret.append(&mut self.undelegate.to_bytes()?);
ret.append(&mut self.run_auction.to_bytes()?);
ret.append(&mut self.slash.to_bytes()?);
ret.append(&mut self.distribute.to_bytes()?);
ret.append(&mut self.withdraw_delegator_reward.to_bytes()?);
ret.append(&mut self.withdraw_validator_reward.to_bytes()?);
ret.append(&mut self.read_era_id.to_bytes()?);
ret.append(&mut self.activate_bid.to_bytes()?);
Ok(ret)
}
fn serialized_length(&self) -> usize {
self.get_era_validators.serialized_length()
+ self.read_seigniorage_recipients.serialized_length()
+ self.add_bid.serialized_length()
+ self.withdraw_bid.serialized_length()
+ self.delegate.serialized_length()
+ self.undelegate.serialized_length()
+ self.run_auction.serialized_length()
+ self.slash.serialized_length()
+ self.distribute.serialized_length()
+ self.withdraw_delegator_reward.serialized_length()
+ self.withdraw_validator_reward.serialized_length()
+ self.read_era_id.serialized_length()
+ self.activate_bid.serialized_length()
}
}
impl FromBytes for AuctionCosts {
fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), casper_types::bytesrepr::Error> {
let (get_era_validators, rem) = FromBytes::from_bytes(bytes)?;
let (read_seigniorage_recipients, rem) = FromBytes::from_bytes(rem)?;
let (add_bid, rem) = FromBytes::from_bytes(rem)?;
let (withdraw_bid, rem) = FromBytes::from_bytes(rem)?;
let (delegate, rem) = FromBytes::from_bytes(rem)?;
let (undelegate, rem) = FromBytes::from_bytes(rem)?;
let (run_auction, rem) = FromBytes::from_bytes(rem)?;
let (slash, rem) = FromBytes::from_bytes(rem)?;
let (distribute, rem) = FromBytes::from_bytes(rem)?;
let (withdraw_delegator_reward, rem) = FromBytes::from_bytes(rem)?;
let (withdraw_validator_reward, rem) = FromBytes::from_bytes(rem)?;
let (read_era_id, rem) = FromBytes::from_bytes(rem)?;
let (activate_bid, rem) = FromBytes::from_bytes(rem)?;
Ok((
Self {
get_era_validators,
read_seigniorage_recipients,
add_bid,
withdraw_bid,
delegate,
undelegate,
run_auction,
slash,
distribute,
withdraw_delegator_reward,
withdraw_validator_reward,
read_era_id,
activate_bid,
},
rem,
))
}
}
impl Distribution<AuctionCosts> for Standard {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> AuctionCosts {
AuctionCosts {
get_era_validators: rng.gen(),
read_seigniorage_recipients: rng.gen(),
add_bid: rng.gen(),
withdraw_bid: rng.gen(),
delegate: rng.gen(),
undelegate: rng.gen(),
run_auction: rng.gen(),
slash: rng.gen(),
distribute: rng.gen(),
withdraw_delegator_reward: rng.gen(),
withdraw_validator_reward: rng.gen(),
read_era_id: rng.gen(),
activate_bid: rng.gen(),
}
}
}
#[doc(hidden)]
#[cfg(any(feature = "gens", test))]
pub mod gens {
use proptest::{num, prop_compose};
use super::AuctionCosts;
prop_compose! {
pub fn auction_costs_arb()(
get_era_validators in num::u32::ANY,
read_seigniorage_recipients in num::u32::ANY,
add_bid in num::u32::ANY,
withdraw_bid in num::u32::ANY,
delegate in num::u32::ANY,
undelegate in num::u32::ANY,
run_auction in num::u32::ANY,
slash in num::u32::ANY,
distribute in num::u32::ANY,
withdraw_delegator_reward in num::u32::ANY,
withdraw_validator_reward in num::u32::ANY,
read_era_id in num::u32::ANY,
activate_bid in num::u32::ANY,
) -> AuctionCosts {
AuctionCosts {
get_era_validators,
read_seigniorage_recipients,
add_bid,
withdraw_bid,
delegate,
undelegate,
run_auction,
slash,
distribute,
withdraw_delegator_reward,
withdraw_validator_reward,
read_era_id,
activate_bid,
}
}
}
}