Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/integration/direct-onboarding' i…
Browse files Browse the repository at this point in the history
…nto feat/ddo-actor-events
  • Loading branch information
aarshkshah1992 committed Jan 9, 2024
2 parents 693338f + aa0a168 commit 6f8be0d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 94 deletions.
8 changes: 7 additions & 1 deletion actors/miner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ impl Actor {
&proof_inputs,
miner_actor_id,
precommits[0].info.seal_proof,
RegisteredAggregateProof::SnarkPackV2,
&params.aggregate_proof,
)?;

Expand Down Expand Up @@ -1724,6 +1725,9 @@ impl Actor {
rt.validate_immediate_caller_is(
info.control_addresses.iter().chain(&[info.worker, info.owner]),
)?;
if params.aggregate_proof_type != RegisteredAggregateProof::SnarkPackV2 {
return Err(actor_error!(illegal_argument, "aggregate proof type must be SnarkPackV2"));
}

// Load pre-commits, failing if any don't exist.
let sector_numbers = params.sector_activations.iter().map(|sa| sa.sector_number);
Expand Down Expand Up @@ -1820,6 +1824,7 @@ impl Actor {
&proof_inputs,
miner_id,
precommits[0].info.seal_proof,
params.aggregate_proof_type,
&params.aggregate_proof,
)?;

Expand Down Expand Up @@ -4781,6 +4786,7 @@ fn verify_aggregate_seal(
proof_inputs: &[SectorSealProofInput],
miner_actor_id: ActorID,
seal_proof: RegisteredSealProof,
aggregate_proof: RegisteredAggregateProof,
proof_bytes: &RawBytes,
) -> Result<(), ActorError> {
let seal_verify_inputs =
Expand All @@ -4789,7 +4795,7 @@ fn verify_aggregate_seal(
rt.verify_aggregate_seals(&AggregateSealVerifyProofAndInfos {
miner: miner_actor_id,
seal_proof,
aggregate_proof: RegisteredAggregateProof::SnarkPackV2,
aggregate_proof,
proof: proof_bytes.clone().into(),
infos: seal_verify_inputs,
})
Expand Down
2 changes: 2 additions & 0 deletions actors/miner/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ pub struct ProveCommitSectors3Params {
// Aggregate proof for all sectors.
// Exactly one of sector_proofs or aggregate_proof must be non-empty.
pub aggregate_proof: RawBytes,
// The proof type for the aggregate proof (ignored if no aggregate proof).
pub aggregate_proof_type: RegisteredAggregateProof,
// Whether to abort if any sector activation fails.
pub require_activation_success: bool,
// Whether to abort if any notification returns a non-zero exit code.
Expand Down
1 change: 1 addition & 0 deletions actors/miner/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ impl ActorHarness {
} else {
vec![]
},
aggregate_proof_type: RegisteredAggregateProof::SnarkPackV2,
require_activation_success,
require_notification_success,
};
Expand Down
5 changes: 4 additions & 1 deletion integration_tests/src/tests/prove_commit2_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use fvm_shared::clock::ChainEpoch;
use fvm_shared::deal::DealID;
use fvm_shared::econ::TokenAmount;
use fvm_shared::piece::{PaddedPieceSize, PieceInfo};
use fvm_shared::sector::{RegisteredSealProof, SectorNumber, StoragePower};
use fvm_shared::sector::{
RegisteredAggregateProof, RegisteredSealProof, SectorNumber, StoragePower,
};
use integer_encoding::VarInt;
use num_traits::Zero;

Expand Down Expand Up @@ -205,6 +207,7 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) {
sector_activations: manifests.clone(),
sector_proofs: proofs,
aggregate_proof: RawBytes::default(),
aggregate_proof_type: RegisteredAggregateProof::SnarkPackV2,
require_activation_success: true,
require_notification_success: true,
};
Expand Down
152 changes: 60 additions & 92 deletions integration_tests/src/tests/replica_update2_test.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use cid::Cid;
use export_macro::vm_test;
use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::bigint::BigInt;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::deal::DealID;
use fvm_shared::econ::TokenAmount;
use fvm_shared::piece::{PaddedPieceSize, PieceInfo};
use fvm_shared::piece::PaddedPieceSize;
use fvm_shared::sector::{
RegisteredAggregateProof, RegisteredSealProof, SectorNumber, StoragePower,
};
use integer_encoding::VarInt;
use num_traits::Zero;

use fil_actor_market::Method as MarketMethod;
Expand All @@ -31,20 +29,22 @@ use fil_actors_runtime::test_utils::{make_piece_cid, make_sealed_cid};
use fil_actors_runtime::{
EPOCHS_IN_DAY, EPOCHS_IN_YEAR, STORAGE_MARKET_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR,
};
use vm_api::trace::{EmittedEvent, ExpectInvocation};
use vm_api::trace::ExpectInvocation;
use vm_api::util::apply_ok;
use vm_api::VM;

use crate::deals::{DealBatcher, DealOptions};
use crate::expects::Expect;
use crate::util::{advance_by_deadline_to_epoch, advance_by_deadline_to_index, advance_to_proving_deadline, create_accounts, create_miner, datacap_create_allocations, market_add_balance, market_list_deals, market_list_sectors_deals, precommit_sectors_v2, sector_info, submit_windowed_post, verifreg_add_client, verifreg_add_verifier, verifreg_list_claims, PrecommitMetadata, override_compute_unsealed_sector_cid};
use crate::util::{
advance_by_deadline_to_epoch, advance_by_deadline_to_index, advance_to_proving_deadline,
create_accounts, create_miner, datacap_create_allocations, market_add_balance,
market_list_deals, market_list_sectors_deals, precommit_sectors_v2, sector_info,
submit_windowed_post, verifreg_add_client, verifreg_add_verifier, verifreg_list_claims,
PrecommitMetadata,
};

#[vm_test]
pub fn prove_replica_update2_test(v: &dyn VM) {
// TODO: move this code somewhere more accessible.
// This change was made during a long rebase during which structural change was not practical.
override_compute_unsealed_sector_cid(v);

let policy = Policy::default();
let addrs = create_accounts(v, 3, &TokenAmount::from_whole(10_000));
let seal_proof = RegisteredSealProof::StackedDRG32GiBV1P1;
Expand Down Expand Up @@ -72,10 +72,56 @@ pub fn prove_replica_update2_test(v: &dyn VM) {
pieces: vec![],
})
.collect();
let first_sector_number: SectorNumber = 100;
let meta: Vec<PrecommitMetadata> = (0..activations.len())
.map(|_| PrecommitMetadata { deals: vec![], commd: CompactCommD::empty() })
.collect();
let sector_expiry = v.epoch() + claim_term_min + 60 * EPOCHS_IN_DAY;
precommit_sectors_v2(
v,
meta.len(),
meta.len(),
meta,
&worker,
&maddr,
seal_proof,
first_sector_number,
true,
Some(sector_expiry),
);

let activation_epoch = v.epoch() + policy.pre_commit_challenge_delay + 1;
advance_by_deadline_to_epoch(v, &maddr, activation_epoch);
let proofs = vec![RawBytes::new(vec![1, 2, 3, 4]); activations.len()];
let params = ProveCommitSectors3Params {
sector_activations: activations,
sector_proofs: proofs,
aggregate_proof: RawBytes::default(),
aggregate_proof_type: RegisteredAggregateProof::SnarkPackV2,
require_activation_success: true,
require_notification_success: true,
};
apply_ok(
v,
&worker,
&maddr,
&TokenAmount::zero(),
MinerMethod::ProveCommitSectors3 as u64,
Some(params),
);
// Advance to proving period and submit post for the partition
let (dlinfo, partition) = advance_to_proving_deadline(v, &maddr, first_sector_number);
let deadline = dlinfo.index;
submit_windowed_post(v, &worker, &maddr, dlinfo, partition, None);
advance_by_deadline_to_index(v, &maddr, dlinfo.index + 1);
let update_epoch = v.epoch();

// Note: the allocation and claim configuration here are duplicated from the prove_commit2 test.
// Register verifier and verified clients
let datacap = StoragePower::from(32_u128 << 40);
verifreg_add_verifier(v, &verifier, &datacap * 2);
verifreg_add_client(v, &verifier, &client, datacap);

// Publish two verified allocations for half a sector each.
let full_piece_size = PaddedPieceSize(sector_size as u64);
let half_piece_size = PaddedPieceSize(sector_size as u64 / 2);
let allocs = vec![
Expand All @@ -96,9 +142,7 @@ pub fn prove_replica_update2_test(v: &dyn VM) {
expiration: 30 * EPOCHS_IN_DAY,
},
];
// Publish two verified allocations for half a sector each.
let alloc_ids_s2 = datacap_create_allocations(v, &client, &allocs);
let alloc_ids_s4 = vec![alloc_ids_s2[alloc_ids_s2.len() - 1] + 1];

// Publish a full-size deal
let market_collateral = TokenAmount::from_whole(100);
Expand All @@ -122,7 +166,10 @@ pub fn prove_replica_update2_test(v: &dyn VM) {
let mut batcher = DealBatcher::new(v, opts);
batcher.stage_with_label(client, maddr, "s4p1".to_string());
let deal_ids_s4 = batcher.publish_ok(worker).ids;
let alloc_ids_s4 = vec![alloc_ids_s2[alloc_ids_s2.len() - 1] + 1];

// Update all sectors with a mix of data pieces, claims, and deals.
let first_sector_number: SectorNumber = 100;
let manifests = vec![
// Sector 0: no pieces (CC sector)
SectorUpdateManifest {
Expand Down Expand Up @@ -202,59 +249,6 @@ pub fn prove_replica_update2_test(v: &dyn VM) {
},
];

let meta: Vec<PrecommitMetadata> = manifests
.iter()
.map(|sector| {
let pis: Vec<PieceInfo> =
sector.pieces.iter().map(|p| PieceInfo { size: p.size, cid: p.cid }).collect();
let commd = v.primitives().compute_unsealed_sector_cid(seal_proof, &pis).unwrap();
PrecommitMetadata { deals: vec![], commd: CompactCommD::of(commd) }
})
.collect();

let sector_expiry = v.epoch() + claim_term_min + 60 * EPOCHS_IN_DAY;
precommit_sectors_v2(
v,
meta.len(),
meta.len(),
meta.clone(),
&worker,
&maddr,
seal_proof,
first_sector_number,
true,
Some(sector_expiry),
);

let activation_epoch = v.epoch() + policy.pre_commit_challenge_delay + 1;
advance_by_deadline_to_epoch(v, &maddr, activation_epoch);
let proofs = vec![RawBytes::new(vec![1, 2, 3, 4]); activations.len()];
let params = ProveCommitSectors3Params {
sector_activations: activations,
sector_proofs: proofs,
aggregate_proof: RawBytes::default(),
require_activation_success: true,
require_notification_success: true,
};
apply_ok(
v,
&worker,
&maddr,
&TokenAmount::zero(),
MinerMethod::ProveCommitSectors3 as u64,
Some(params),
);

submit_windowed_post(v, &worker, &maddr, dlinfo, partition, None);
advance_by_deadline_to_index(v, &maddr, dlinfo.index + 1);
let update_epoch = v.epoch();

// Note: the allocation and claim configuration here are duplicated from the prove_commit2 test.
// Register verifier and verified clients
let datacap = StoragePower::from(32_u128 << 40);
verifreg_add_verifier(v, &verifier, &datacap * 2);
verifreg_add_client(v, &verifier, &client, datacap);

// Replica update
let update_proof = seal_proof.registered_update_proof().unwrap();
let proofs = vec![RawBytes::new(vec![1, 2, 3, 4]); manifests.len()];
Expand All @@ -263,7 +257,7 @@ pub fn prove_replica_update2_test(v: &dyn VM) {
sector_proofs: proofs,
aggregate_proof: RawBytes::default(),
update_proofs_type: update_proof,
aggregate_proof_type: RegisteredAggregateProof::SnarkPackV1,
aggregate_proof_type: RegisteredAggregateProof::SnarkPackV2,
require_activation_success: true,
require_notification_success: true,
};
Expand All @@ -282,26 +276,6 @@ pub fn prove_replica_update2_test(v: &dyn VM) {
.map(|p| p.size.0 * 9)
.sum::<u64>(),
);

let events: Vec<EmittedEvent> = manifests
.iter()
.enumerate()
.map(|(i, sa)| {
let pieces: Vec<(Cid, PaddedPieceSize)> =
sa.pieces.iter().map(|p| (p.cid, p.size)).collect();

let unsealed_cid = meta.get(i).unwrap().commd.get_cid(seal_proof).unwrap();

Expect::build_sector_activation_event(
"sector-updated",
&miner_id,
&sa.sector,
&unsealed_cid,
&pieces,
)
})
.collect();

ExpectInvocation {
from: worker_id,
to: maddr,
Expand Down Expand Up @@ -352,11 +326,6 @@ pub fn prove_replica_update2_test(v: &dyn VM) {
})
.unwrap(),
),
events: vec![
Expect::build_verifreg_event("claim", &alloc_ids_s2[0], &client_id, &miner_id),
Expect::build_verifreg_event("claim", &alloc_ids_s2[1], &client_id, &miner_id),
Expect::build_verifreg_event("claim", &alloc_ids_s4[0], &client_id, &miner_id),
],
..Default::default()
},
Expect::reward_this_epoch(miner_id),
Expand Down Expand Up @@ -390,7 +359,6 @@ pub fn prove_replica_update2_test(v: &dyn VM) {
..Default::default()
},
]),
events,
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down

0 comments on commit 6f8be0d

Please sign in to comment.