Ledger-tool: add param to deactivate features in snapshot creation (#30755)

* Add separate parameter for deactivating features on snapshot creation

* Add debug logs for account/feature removals

* Add the word gate
This commit is contained in:
Tyera 2023-03-16 15:54:05 -06:00 committed by GitHub
parent d66d1f7a46
commit 9d792c1848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

View File

@ -2082,6 +2082,16 @@ fn main() {
.multiple(true)
.help("List of accounts to remove while creating the snapshot"),
)
.arg(
Arg::with_name("feature_gates_to_deactivate")
.required(false)
.long("deactivate-feature-gate")
.takes_value(true)
.value_name("PUBKEY")
.validator(is_pubkey)
.multiple(true)
.help("List of feature gates to deactivate while creating the snapshot")
)
.arg(
Arg::with_name("vote_accounts_to_destake")
.required(false)
@ -2963,6 +2973,8 @@ fn main() {
let bootstrap_validator_pubkeys = pubkeys_of(arg_matches, "bootstrap_validator");
let accounts_to_remove =
pubkeys_of(arg_matches, "accounts_to_remove").unwrap_or_default();
let feature_gates_to_deactivate =
pubkeys_of(arg_matches, "feature_gates_to_deactivate").unwrap_or_default();
let vote_accounts_to_destake: HashSet<_> =
pubkeys_of(arg_matches, "vote_accounts_to_destake")
.unwrap_or_default()
@ -3081,6 +3093,7 @@ fn main() {
|| hashes_per_tick.is_some()
|| remove_stake_accounts
|| !accounts_to_remove.is_empty()
|| !feature_gates_to_deactivate.is_empty()
|| !vote_accounts_to_destake.is_empty()
|| faucet_pubkey.is_some()
|| bootstrap_validator_pubkeys.is_some();
@ -3133,6 +3146,32 @@ fn main() {
account.set_lamports(0);
bank.store_account(&address, &account);
debug!("Account removed: {address}");
}
for address in feature_gates_to_deactivate {
let mut account = bank.get_account(&address).unwrap_or_else(|| {
eprintln!(
"Error: Feature-gate account does not exist, unable to deactivate it: {address}"
);
exit(1);
});
match feature::from_account(&account) {
Some(feature) => {
if feature.activated_at.is_none() {
warn!("Feature gate is not yet activated: {address}");
}
}
None => {
eprintln!("Error: Account is not a `Feature`: {address}");
exit(1);
}
}
account.set_lamports(0);
bank.store_account(&address, &account);
debug!("Feature gate deactivated: {address}");
}
if !vote_accounts_to_destake.is_empty() {