casper_types/chainspec/
upgrade_config.rs

1use num_rational::Ratio;
2use serde::Serialize;
3use std::collections::BTreeMap;
4
5use crate::{
6    ChainspecRegistry, Digest, EraId, FeeHandling, HoldBalanceHandling, Key, ProtocolVersion,
7    StoredValue,
8};
9
10/// Represents the configuration of a protocol upgrade.
11#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
12pub struct ProtocolUpgradeConfig {
13    pre_state_hash: Digest,
14    current_protocol_version: ProtocolVersion,
15    new_protocol_version: ProtocolVersion,
16    activation_point: Option<EraId>,
17    new_gas_hold_handling: Option<HoldBalanceHandling>,
18    new_gas_hold_interval: Option<u64>,
19    new_validator_slots: Option<u32>,
20    new_auction_delay: Option<u64>,
21    new_locked_funds_period_millis: Option<u64>,
22    new_round_seigniorage_rate: Option<Ratio<u64>>,
23    new_unbonding_delay: Option<u64>,
24    global_state_update: BTreeMap<Key, StoredValue>,
25    chainspec_registry: ChainspecRegistry,
26    fee_handling: FeeHandling,
27    validator_minimum_bid_amount: u64,
28    maximum_delegation_amount: u64,
29    minimum_delegation_amount: u64,
30    enable_addressable_entity: bool,
31}
32
33impl ProtocolUpgradeConfig {
34    /// Create new upgrade config.
35    #[allow(clippy::too_many_arguments)]
36    pub fn new(
37        pre_state_hash: Digest,
38        current_protocol_version: ProtocolVersion,
39        new_protocol_version: ProtocolVersion,
40        activation_point: Option<EraId>,
41        new_gas_hold_handling: Option<HoldBalanceHandling>,
42        new_gas_hold_interval: Option<u64>,
43        new_validator_slots: Option<u32>,
44        new_auction_delay: Option<u64>,
45        new_locked_funds_period_millis: Option<u64>,
46        new_round_seigniorage_rate: Option<Ratio<u64>>,
47        new_unbonding_delay: Option<u64>,
48        global_state_update: BTreeMap<Key, StoredValue>,
49        chainspec_registry: ChainspecRegistry,
50        fee_handling: FeeHandling,
51        validator_minimum_bid_amount: u64,
52        maximum_delegation_amount: u64,
53        minimum_delegation_amount: u64,
54        enable_addressable_entity: bool,
55    ) -> Self {
56        ProtocolUpgradeConfig {
57            pre_state_hash,
58            current_protocol_version,
59            new_protocol_version,
60            activation_point,
61            new_gas_hold_handling,
62            new_gas_hold_interval,
63            new_validator_slots,
64            new_auction_delay,
65            new_locked_funds_period_millis,
66            new_round_seigniorage_rate,
67            new_unbonding_delay,
68            global_state_update,
69            chainspec_registry,
70            fee_handling,
71            validator_minimum_bid_amount,
72            maximum_delegation_amount,
73            minimum_delegation_amount,
74            enable_addressable_entity,
75        }
76    }
77
78    /// Returns the current state root state hash
79    pub fn pre_state_hash(&self) -> Digest {
80        self.pre_state_hash
81    }
82
83    /// Returns current protocol version of this upgrade.
84    pub fn current_protocol_version(&self) -> ProtocolVersion {
85        self.current_protocol_version
86    }
87
88    /// Returns new protocol version of this upgrade.
89    pub fn new_protocol_version(&self) -> ProtocolVersion {
90        self.new_protocol_version
91    }
92
93    /// Returns activation point in eras.
94    pub fn activation_point(&self) -> Option<EraId> {
95        self.activation_point
96    }
97
98    /// Returns new gas hold handling if specified.
99    pub fn new_gas_hold_handling(&self) -> Option<HoldBalanceHandling> {
100        self.new_gas_hold_handling
101    }
102
103    /// Returns new auction delay if specified.
104    pub fn new_gas_hold_interval(&self) -> Option<u64> {
105        self.new_gas_hold_interval
106    }
107
108    /// Returns new validator slots if specified.
109    pub fn new_validator_slots(&self) -> Option<u32> {
110        self.new_validator_slots
111    }
112
113    /// Returns new auction delay if specified.
114    pub fn new_auction_delay(&self) -> Option<u64> {
115        self.new_auction_delay
116    }
117
118    /// Returns new locked funds period if specified.
119    pub fn new_locked_funds_period_millis(&self) -> Option<u64> {
120        self.new_locked_funds_period_millis
121    }
122
123    /// Returns new round seigniorage rate if specified.
124    pub fn new_round_seigniorage_rate(&self) -> Option<Ratio<u64>> {
125        self.new_round_seigniorage_rate
126    }
127
128    /// Returns new unbonding delay if specified.
129    pub fn new_unbonding_delay(&self) -> Option<u64> {
130        self.new_unbonding_delay
131    }
132
133    /// Returns new map of emergency global state updates.
134    pub fn global_state_update(&self) -> &BTreeMap<Key, StoredValue> {
135        &self.global_state_update
136    }
137
138    /// Returns a reference to the chainspec registry.
139    pub fn chainspec_registry(&self) -> &ChainspecRegistry {
140        &self.chainspec_registry
141    }
142
143    /// Sets new pre state hash.
144    pub fn with_pre_state_hash(&mut self, pre_state_hash: Digest) {
145        self.pre_state_hash = pre_state_hash;
146    }
147
148    /// Fee handling setting.
149    pub fn fee_handling(&self) -> FeeHandling {
150        self.fee_handling
151    }
152
153    /// Validator minimum bid amount
154    pub fn validator_minimum_bid_amount(&self) -> u64 {
155        self.validator_minimum_bid_amount
156    }
157
158    /// Maximum delegation amount for validator.
159    pub fn maximum_delegation_amount(&self) -> u64 {
160        self.maximum_delegation_amount
161    }
162
163    /// Minimum delegation amount for validator.
164    pub fn minimum_delegation_amount(&self) -> u64 {
165        self.minimum_delegation_amount
166    }
167
168    pub fn enable_addressable_entity(&self) -> bool {
169        self.enable_addressable_entity
170    }
171}