casper_types/chainspec/
upgrade_config.rs

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
use num_rational::Ratio;
use serde::Serialize;
use std::collections::BTreeMap;

use crate::{
    ChainspecRegistry, Digest, EraId, FeeHandling, HoldBalanceHandling, Key, ProtocolVersion,
    StoredValue,
};

/// Represents the configuration of a protocol upgrade.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ProtocolUpgradeConfig {
    pre_state_hash: Digest,
    current_protocol_version: ProtocolVersion,
    new_protocol_version: ProtocolVersion,
    activation_point: Option<EraId>,
    new_gas_hold_handling: Option<HoldBalanceHandling>,
    new_gas_hold_interval: Option<u64>,
    new_validator_slots: Option<u32>,
    new_auction_delay: Option<u64>,
    new_locked_funds_period_millis: Option<u64>,
    new_round_seigniorage_rate: Option<Ratio<u64>>,
    new_unbonding_delay: Option<u64>,
    global_state_update: BTreeMap<Key, StoredValue>,
    chainspec_registry: ChainspecRegistry,
    fee_handling: FeeHandling,
    migrate_legacy_accounts: bool,
    migrate_legacy_contracts: bool,
    maximum_delegation_amount: u64,
    minimum_delegation_amount: u64,
    enable_addressable_entity: bool,
}

impl ProtocolUpgradeConfig {
    /// Create new upgrade config.
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        pre_state_hash: Digest,
        current_protocol_version: ProtocolVersion,
        new_protocol_version: ProtocolVersion,
        activation_point: Option<EraId>,
        new_gas_hold_handling: Option<HoldBalanceHandling>,
        new_gas_hold_interval: Option<u64>,
        new_validator_slots: Option<u32>,
        new_auction_delay: Option<u64>,
        new_locked_funds_period_millis: Option<u64>,
        new_round_seigniorage_rate: Option<Ratio<u64>>,
        new_unbonding_delay: Option<u64>,
        global_state_update: BTreeMap<Key, StoredValue>,
        chainspec_registry: ChainspecRegistry,
        fee_handling: FeeHandling,
        migrate_legacy_accounts: bool,
        migrate_legacy_contracts: bool,
        maximum_delegation_amount: u64,
        minimum_delegation_amount: u64,
        enable_addressable_entity: bool,
    ) -> Self {
        ProtocolUpgradeConfig {
            pre_state_hash,
            current_protocol_version,
            new_protocol_version,
            activation_point,
            new_gas_hold_handling,
            new_gas_hold_interval,
            new_validator_slots,
            new_auction_delay,
            new_locked_funds_period_millis,
            new_round_seigniorage_rate,
            new_unbonding_delay,
            global_state_update,
            chainspec_registry,
            fee_handling,
            migrate_legacy_accounts,
            migrate_legacy_contracts,
            maximum_delegation_amount,
            minimum_delegation_amount,
            enable_addressable_entity,
        }
    }

    /// Returns the current state root state hash
    pub fn pre_state_hash(&self) -> Digest {
        self.pre_state_hash
    }

    /// Returns current protocol version of this upgrade.
    pub fn current_protocol_version(&self) -> ProtocolVersion {
        self.current_protocol_version
    }

    /// Returns new protocol version of this upgrade.
    pub fn new_protocol_version(&self) -> ProtocolVersion {
        self.new_protocol_version
    }

    /// Returns activation point in eras.
    pub fn activation_point(&self) -> Option<EraId> {
        self.activation_point
    }

    /// Returns new gas hold handling if specified.
    pub fn new_gas_hold_handling(&self) -> Option<HoldBalanceHandling> {
        self.new_gas_hold_handling
    }

    /// Returns new auction delay if specified.
    pub fn new_gas_hold_interval(&self) -> Option<u64> {
        self.new_gas_hold_interval
    }

    /// Returns new validator slots if specified.
    pub fn new_validator_slots(&self) -> Option<u32> {
        self.new_validator_slots
    }

    /// Returns new auction delay if specified.
    pub fn new_auction_delay(&self) -> Option<u64> {
        self.new_auction_delay
    }

    /// Returns new locked funds period if specified.
    pub fn new_locked_funds_period_millis(&self) -> Option<u64> {
        self.new_locked_funds_period_millis
    }

    /// Returns new round seigniorage rate if specified.
    pub fn new_round_seigniorage_rate(&self) -> Option<Ratio<u64>> {
        self.new_round_seigniorage_rate
    }

    /// Returns new unbonding delay if specified.
    pub fn new_unbonding_delay(&self) -> Option<u64> {
        self.new_unbonding_delay
    }

    /// Returns new map of emergency global state updates.
    pub fn global_state_update(&self) -> &BTreeMap<Key, StoredValue> {
        &self.global_state_update
    }

    /// Returns a reference to the chainspec registry.
    pub fn chainspec_registry(&self) -> &ChainspecRegistry {
        &self.chainspec_registry
    }

    /// Sets new pre state hash.
    pub fn with_pre_state_hash(&mut self, pre_state_hash: Digest) {
        self.pre_state_hash = pre_state_hash;
    }

    /// Fee handling setting.
    pub fn fee_handling(&self) -> FeeHandling {
        self.fee_handling
    }

    /// Migrate legacy accounts.
    pub fn migrate_legacy_accounts(&self) -> bool {
        self.migrate_legacy_accounts
    }

    /// Migrate legacy contracts.
    pub fn migrate_legacy_contracts(&self) -> bool {
        self.migrate_legacy_contracts
    }

    /// Maximum delegation amount for validator.
    pub fn maximum_delegation_amount(&self) -> u64 {
        self.maximum_delegation_amount
    }

    /// Minimum delegation amount for validator.
    pub fn minimum_delegation_amount(&self) -> u64 {
        self.minimum_delegation_amount
    }

    pub fn enable_addressable_entity(&self) -> bool {
        self.enable_addressable_entity
    }
}