Skip to content

Commit

Permalink
Get all dead genesis objects
Browse files Browse the repository at this point in the history
  • Loading branch information
williampsmith committed Oct 28, 2024
1 parent 818b174 commit f5e2e2f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
16 changes: 13 additions & 3 deletions crates/sui-tool/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::{
check_completed_snapshot,
db_tool::{execute_db_tool_command, print_db_all_tables, DbToolCommand},
download_db_snapshot, download_formal_snapshot, dump_checkpoints_from_archive,
get_latest_available_epoch, get_object, get_transaction_block, make_clients,
restore_from_db_checkpoint, verify_archive, verify_archive_by_checksum, ConciseObjectOutput,
GroupedObjectOutput, SnapshotVerifyMode, VerboseObjectOutput,
get_dead_genesis_objects, get_latest_available_epoch, get_object, get_transaction_block,
make_clients, restore_from_db_checkpoint, verify_archive, verify_archive_by_checksum,
ConciseObjectOutput, GroupedObjectOutput, SnapshotVerifyMode, VerboseObjectOutput,
};
use anyhow::Result;
use futures::{future::join_all, StreamExt};
Expand Down Expand Up @@ -416,6 +416,13 @@ pub enum ToolCommand {
)]
sender_signed_data: String,
},
#[command(name = "get-dead-genesis-objects")]
GetDeadGenesisObjects {
#[arg(long = "db-path")]
db_path: PathBuf,
#[arg(long = "genesis")]
genesis: PathBuf,
},
}

async fn check_locked_object(
Expand Down Expand Up @@ -1091,6 +1098,9 @@ impl ToolCommand {
let result = agg.process_transaction(transaction, None).await;
println!("{:?}", result);
}
ToolCommand::GetDeadGenesisObjects { db_path, genesis } => {
get_dead_genesis_objects(&db_path, &genesis).await?;
}
};
Ok(())
}
Expand Down
30 changes: 30 additions & 0 deletions crates/sui-tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use futures::future::join_all;
use futures::future::AbortHandle;
use itertools::Itertools;
use std::collections::BTreeMap;
use std::collections::HashSet;
use std::fmt::Write;
use std::num::NonZeroUsize;
use std::ops::Range;
Expand Down Expand Up @@ -814,6 +815,35 @@ pub async fn check_completed_snapshot(
}
}

pub async fn get_dead_genesis_objects(db_path: &Path, genesis: &Path) -> Result<(), anyhow::Error> {
let mut genesis_object_ids: HashSet<ObjectID> = Genesis::load(genesis)?
.objects()
.iter()
.map(|obj| obj.id())
.collect();
let perpetual_db = Arc::new(AuthorityPerpetualTables::open(
&db_path.join("live").join("store"),
None,
));
let live_objects = perpetual_db.iter_live_object_set(false);
live_objects.for_each(|obj| {
let oid = obj.object_id();
if genesis_object_ids.contains(&oid) {
genesis_object_ids.remove(&oid);
}
});
println!(
"Found {} dead genesis objects: \n{}",
genesis_object_ids.len(),
genesis_object_ids
.iter()
.map(|oid| format!("{:?}", oid))
.collect::<Vec<_>>()
.join("\n")
);
Ok(())
}

pub async fn download_formal_snapshot(
path: &Path,
epoch: EpochId,
Expand Down

0 comments on commit f5e2e2f

Please sign in to comment.