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(dfx-orbit): Check that there is a matching asset upload proposal #401

Merged
merged 3 commits into from
Oct 24, 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
13 changes: 12 additions & 1 deletion tools/dfx-orbit/src/asset/upload.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::DfxOrbit;
use anyhow::bail;
use anyhow::{bail, Context};
use candid::{Nat, Principal};
use clap::Parser;
use ic_certified_assets::types::{CommitProposedBatchArguments, DeleteBatchArguments};
Expand Down Expand Up @@ -75,6 +75,17 @@ impl VerifyAssetUploadArgs {

let evidence = asset_agent.compute_evidence(&paths).await?;

// Check that the expected batch ID and evidence are actually proposed
asset_agent
.validate_commit_proposed_batch(self.batch_id.clone(), evidence.clone())
.await
.with_context(|| {
format!(
"There is no proposal for batch ID {}, evidence {} on canister \"{}\"",
self.batch_id, evidence, self.canister,
)
})?;

println!("Computed evidence: 0x{evidence}");
DfxOrbit::check_evidence(request, canister_id, self.batch_id.clone(), evidence)?;

Expand Down
31 changes: 29 additions & 2 deletions tools/dfx-orbit/src/asset/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::DfxOrbit;
use anyhow::bail;
use anyhow::{anyhow, bail, Context};
use candid::{Nat, Principal};
use ic_utils::Canister;
use ic_certified_assets::types::CommitProposedBatchArguments;
use ic_utils::{call::AsyncCaller, Canister};
use serde_bytes::ByteBuf;
use slog::Logger;
use station_api::{GetRequestResponse, RequestOperationDTO};
Expand Down Expand Up @@ -62,4 +63,30 @@ impl AssetAgent<'_> {
pub(super) async fn compute_evidence(&self, sources: &[&Path]) -> anyhow::Result<String> {
Ok(ic_asset::compute_evidence(&self.canister_agent, sources, &self.logger).await?)
}

pub(super) async fn validate_commit_proposed_batch(
&self,
batch_id: Nat,
evidence: String,
) -> anyhow::Result<()> {
let evidence = hex::decode(evidence)?;
let arg = CommitProposedBatchArguments {
batch_id,
evidence: ByteBuf::from(evidence),
};

let method: AsyncCaller<'_, (Result<String, String>,)> = self
.canister_agent
.update("validate_commit_proposed_batch")
.with_arg(arg)
.build();

let result: Result<String, String> = method
.call_and_wait_one()
.await
.with_context(|| "Failed to fetch current upload proposal from asset canister")?;
result.map_err(|str| anyhow!(str))?;

Ok(())
}
}
Loading