Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions checkpoint/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ struct Args {
/// AWS CLI profile name
#[arg(long, requires = "upload")]
profile: Option<String>,

/// Path of a Rust source file to write the checkpoint constant to.
/// Skipped if not set. Typically `checkpoint/src/integrity.rs` from a
/// workspace checkout; irrelevant on servers.
#[arg(long)]
integrity_out: Option<PathBuf>,
}

fn main() -> anyhow::Result<()> {
Expand All @@ -78,8 +84,10 @@ fn main() -> anyhow::Result<()> {
);
eprintln!("SHA-256: {}", hex::encode(digest));

spaces_checkpoint::write_integrity(height, &block_hash, &digest)?;
eprintln!("Updated checkpoint/src/integrity.rs");
if let Some(path) = args.integrity_out.as_deref() {
spaces_checkpoint::write_integrity(path, height, &block_hash, &digest)?;
eprintln!("Updated {}", path.display());
}

if let Some(bucket) = &args.upload {
let bucket = bucket.trim_end_matches('/');
Expand Down
20 changes: 7 additions & 13 deletions checkpoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,14 @@ pub fn checkpoint() -> super::Checkpoint {{
)
}

/// Write the checkpoint constant to a Rust source file at `path`.
#[cfg(feature = "cli")]
const INTEGRITY_PATH: &str = "checkpoint/src/integrity.rs";

/// Write the checkpoint constant to integrity.rs.
/// Must be run from the workspace root.
#[cfg(feature = "cli")]
pub fn write_integrity(height: u32, block_hash: &str, digest: &[u8; 32]) -> anyhow::Result<()> {
let path = Path::new(INTEGRITY_PATH);
if !path.exists() {
anyhow::bail!(
"{} not found — run checkpoint-builder from the workspace root",
INTEGRITY_PATH
);
}
pub fn write_integrity(
path: &Path,
height: u32,
block_hash: &str,
digest: &[u8; 32],
) -> anyhow::Result<()> {
std::fs::write(path, format_integrity_file(height, block_hash, digest))?;
Ok(())
}
Expand Down
Loading