Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix block remove for latest aleohq commit, add faster release compile option #109

Merged
merged 5 commits into from
Apr 11, 2024
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
16 changes: 12 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ jobs:
- name: 📥 Checkout snarkOS
uses: actions/checkout@v4
with:
repository: AleoNet/snarkOS
repository: AleoHQ/snarkOS
fetch-depth: 0
ref: ec943b39968215e17f43b5f53fd73acba66e3a5f # latest canarynet
path: snarkos

- name: 📥 Checkout snarkVM
uses: actions/checkout@v4
with:
repository: AleoNet/snarkVM
repository: AleoHQ/snarkVM
fetch-depth: 0
ref: ed20562d6f97ef593f051ce3cc848644e785f817 # latest canarynet
path: snarkvm

- name: ☁️ Install Nightly
Expand All @@ -91,13 +95,17 @@ jobs:
- name: 📥 Checkout snarkOS
uses: actions/checkout@v4
with:
repository: AleoNet/snarkOS
repository: AleoHQ/snarkOS
fetch-depth: 0
ref: ec943b39968215e17f43b5f53fd73acba66e3a5f # latest canarynet
path: snarkos

- name: 📥 Checkout snarkVM
uses: actions/checkout@v4
with:
repository: AleoNet/snarkVM
repository: AleoHQ/snarkVM
fetch-depth: 0
ref: ed20562d6f97ef593f051ce3cc848644e785f817 # latest canarynet
path: snarkvm

- name: 🥬 Use Mold Linker
Expand Down
67 changes: 43 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ strip = false
inherits = "release"
opt-level = "z"

[profile.release-big]
inherits = "release"
codegen-units = 16
incremental = true
lto = "thin"
opt-level = 1
panic = "unwind"

[workspace.dependencies]
aleo-std = "=0.1.24"
axum = { version = "0.7", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/checkpoint/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Stores {

// Remove the block solution IDs.
for solution_id in solutions.solution_ids() {
db.puzzle_commitments_map().remove(solution_id)?;
db.solution_ids_map().remove(solution_id)?;
}

// Remove the aborted solution IDs.
Expand Down
50 changes: 42 additions & 8 deletions crates/snops-agent/src/reconcile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use snops_common::{
api::{CheckpointMeta, StorageInfo},
constant::{
LEDGER_BASE_DIR, LEDGER_PERSIST_DIR, LEDGER_STORAGE_FILE, SNARKOS_FILE,
SNARKOS_GENESIS_FILE,
SNARKOS_GENESIS_FILE, VERSION_FILE,
},
rpc::error::ReconcileError,
state::{EnvId, HeightRequest},
Expand Down Expand Up @@ -44,13 +44,31 @@ pub async fn check_files(
.await
.expect("failed to acquire snarkOS binary");

let version_file = storage_path.join(VERSION_FILE);

// wipe old storage when the version changes
if get_version_from_path(&version_file).await? != Some(info.version) && storage_path.exists() {
let _ = tokio::fs::remove_dir_all(&storage_path).await;
}

std::fs::create_dir_all(&storage_path).map_err(|e| {
error!("failed to create storage directory: {e}");
ReconcileError::StorageSetupError("create storage directory".to_string())
})?;

let genesis_path = storage_path.join(SNARKOS_GENESIS_FILE);
let genesis_url = format!(
"http://{}/content/storage/{storage_id}/{SNARKOS_GENESIS_FILE}",
&state.endpoint
);
let ledger_path = storage_path.join(LEDGER_STORAGE_FILE);
let ledger_url = format!(
"http://{}/content/storage/{storage_id}/{LEDGER_STORAGE_FILE}",
&state.endpoint
);

// download the genesis block
api::check_file(genesis_url, &storage_path.join(SNARKOS_GENESIS_FILE))
api::check_file(genesis_url, &genesis_path)
.await
.map_err(|e| {
error!("failed to download {SNARKOS_GENESIS_FILE} from the control plane: {e}");
Expand All @@ -63,19 +81,22 @@ pub async fn check_files(
return Ok(());
}

let ledger_url = format!(
"http://{}/content/storage/{storage_id}/{LEDGER_STORAGE_FILE}",
&state.endpoint
);

// download the ledger file
api::check_file(ledger_url, &storage_path.join(LEDGER_STORAGE_FILE))
api::check_file(ledger_url, &ledger_path)
.await
.map_err(|e| {
error!("failed to download {SNARKOS_GENESIS_FILE} from the control plane: {e}");
ReconcileError::StorageAcquireError(LEDGER_STORAGE_FILE.to_owned())
})?;

// write the regen version to a "version" file
tokio::fs::write(&version_file, info.version.to_string())
.await
.map_err(|e| {
error!("failed to write storage version: {e}");
ReconcileError::StorageSetupError("write storage version".to_string())
})?;

Ok(())
}

Expand Down Expand Up @@ -342,3 +363,16 @@ fn find_checkpoint_by_span<'a>(
.rev()
.find_map(|(t, c)| if t <= timestamp { Some(c) } else { None })
}

async fn get_version_from_path(path: &PathBuf) -> Result<Option<u16>, ReconcileError> {
if !path.exists() {
return Ok(None);
}

let data = tokio::fs::read_to_string(path).await.map_err(|e| {
error!("failed to read storage version: {e}");
ReconcileError::StorageSetupError("failed to read storage version".to_string())
})?;

Ok(data.parse().ok())
}
2 changes: 2 additions & 0 deletions crates/snops-common/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ pub struct StorageInfo {
pub checkpoints: Vec<CheckpointMeta>,
/// Whether to persist the ledger
pub persist: bool,
/// Version identifier for this ledger
pub version: u16,
}
2 changes: 2 additions & 0 deletions crates/snops-common/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ pub const LEDGER_BASE_DIR: &str = "ledger";
pub const LEDGER_PERSIST_DIR: &str = "persist";
/// Temporary storage archive file name.
pub const LEDGER_STORAGE_FILE: &str = "ledger.tar.gz";
/// File containing a version counter for a ledger
pub const VERSION_FILE: &str = "version";
6 changes: 6 additions & 0 deletions crates/snops/src/schema/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub enum StorageError {
Command(CommandError, String),
#[error("mkdirs for storage generation id: `{0}`: {1}")]
GenerateStorage(String, #[source] std::io::Error),
#[error("remove storage {0:#?}: {1}")]
RemoveStorage(PathBuf, #[source] std::io::Error),
#[error("generating genesis id: `{0}`: {1}")]
FailedToGenGenesis(String, #[source] std::io::Error),
#[error("fetching genesis block id: `{0}` url: `{1}`: {2}")]
Expand All @@ -27,6 +29,10 @@ pub enum StorageError {
NoGenerationParams(String),
#[error("reading balances {0:#?}: {1}")]
ReadBalances(PathBuf, #[source] std::io::Error),
#[error("reading version {0:#?}: {1}")]
ReadVersion(PathBuf, #[source] std::io::Error),
#[error("writing version {0:#?}: {1}")]
WriteVersion(PathBuf, #[source] std::io::Error),
#[error("parsing balances {0:#?}: {1}")]
ParseBalances(PathBuf, #[source] serde_json::Error),
#[error("error loading checkpoints: {0}")]
Expand Down
Loading