Skip to content

Commit

Permalink
ledger-tool: add warn log if capitalization changes during create-sna…
Browse files Browse the repository at this point in the history
…pshot (#35155)

* Add warn log if capitalization changes during create-snapshot

* Add enable-capitalization-change flag

* Print capitalization message at end
  • Loading branch information
Tyera authored Feb 16, 2024
1 parent e212510 commit 9a69e3a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,12 @@ fn main() {
.takes_value(true)
.help("Snapshot archive format to use.")
.conflicts_with("no_snapshot"),
)
.arg(
Arg::with_name("enable_capitalization_change")
.long("enable-capitalization-change")
.takes_value(false)
.help("If snapshot creation should succeed with a capitalization delta."),
),
)
.subcommand(
Expand Down Expand Up @@ -1806,6 +1812,9 @@ fn main() {
None
};

let enable_capitalization_change =
arg_matches.is_present("enable_capitalization_change");

let snapshot_type_str = if is_incremental {
"incremental "
} else if is_minimized {
Expand Down Expand Up @@ -2047,8 +2056,31 @@ fn main() {
}
}

let pre_capitalization = bank.capitalization();

bank.set_capitalization();

let post_capitalization = bank.capitalization();

let capitalization_message = if pre_capitalization != post_capitalization {
let amount = if pre_capitalization > post_capitalization {
format!("-{}", pre_capitalization - post_capitalization)
} else {
(post_capitalization - pre_capitalization).to_string()
};
let msg = format!("Capitalization change: {amount} lamports");
warn!("{msg}");
if !enable_capitalization_change {
eprintln!(
"{msg}\nBut `--enable-capitalization-change flag not provided"
);
exit(1);
}
Some(msg)
} else {
None
};

let bank = if let Some(warp_slot) = warp_slot {
// need to flush the write cache in order to use Storages to calculate
// the accounts hash, and need to root `bank` before flushing the cache
Expand Down Expand Up @@ -2175,6 +2207,9 @@ fn main() {
}
}

if let Some(msg) = capitalization_message {
println!("{msg}");
}
println!(
"Shred version: {}",
compute_shred_version(&genesis_config.hash(), Some(&bank.hard_forks()))
Expand Down

0 comments on commit 9a69e3a

Please sign in to comment.