-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic unit tests for ProveReplicaUpdate3
- Loading branch information
Showing
7 changed files
with
475 additions
and
215 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
use fil_actor_market::NO_ALLOCATION_ID; | ||
use fvm_ipld_blockstore::Blockstore; | ||
use fvm_shared::deal::DealID; | ||
use fvm_shared::piece::PaddedPieceSize; | ||
use fvm_shared::sector::SectorNumber; | ||
use fvm_shared::{bigint::Zero, clock::ChainEpoch, econ::TokenAmount, ActorID}; | ||
|
||
use fil_actor_miner::ext::verifreg::AllocationID; | ||
use fil_actor_miner::{ | ||
CompactCommD, PieceActivationManifest, SectorOnChainInfo, SectorPreCommitInfo, | ||
SectorPreCommitOnChainInfo, SectorUpdateManifest, State, VerifiedAllocationKey, | ||
}; | ||
use fil_actor_miner::{DataActivationNotification, ProveReplicaUpdates3Return}; | ||
use fil_actors_runtime::cbor::serialize; | ||
use fil_actors_runtime::test_utils::{make_piece_cid, make_sealed_cid, MockRuntime}; | ||
use fil_actors_runtime::{runtime::Runtime, BatchReturn, EPOCHS_IN_DAY, STORAGE_MARKET_ACTOR_ADDR}; | ||
use util::*; | ||
|
||
mod util; | ||
|
||
const DEFAULT_SECTOR_EXPIRATION_DAYS: ChainEpoch = 220; | ||
|
||
#[test] | ||
fn prove_single_sectorxxx() { | ||
let h = ActorHarness::new_with_options(HarnessOptions::default()); | ||
let rt = h.new_runtime(); | ||
rt.set_balance(BIG_BALANCE.clone()); | ||
let client_id: ActorID = 1000; | ||
|
||
h.construct_and_verify(&rt); | ||
|
||
// Onboard a batch of empty sectors. | ||
rt.set_epoch(1); | ||
let sector_expiry = *rt.epoch.borrow() + DEFAULT_SECTOR_EXPIRATION_DAYS * EPOCHS_IN_DAY; | ||
let first_sector_number = 100; | ||
let sector_count = 4; | ||
let sectors = onboard_empty_sectors(&rt, &h, sector_expiry, first_sector_number, sector_count); | ||
|
||
// Update them in batch, each with a single piece. | ||
let st: State = h.get_state(&rt); | ||
let store = rt.store(); | ||
let piece_size = h.sector_size as u64; | ||
let sector_updates = vec![ | ||
make_update_manifest(&st, store, §ors[0], &[(piece_size, 0, 0, 0)]), // No alloc or deal | ||
make_update_manifest(&st, store, §ors[1], &[(piece_size, client_id, 1000, 0)]), // Just an alloc | ||
make_update_manifest(&st, store, §ors[2], &[(piece_size, 0, 0, 2000)]), // Just a deal | ||
make_update_manifest(&st, store, §ors[3], &[(piece_size, client_id, 1001, 2001)]), // Alloc and deal | ||
]; | ||
|
||
let result = h.prove_replica_updates3_batch(&rt, §or_updates, true, true).unwrap(); | ||
assert_eq!( | ||
ProveReplicaUpdates3Return { activation_results: BatchReturn::ok(sectors.len() as u32) }, | ||
result | ||
); | ||
} | ||
|
||
fn onboard_empty_sectors( | ||
rt: &MockRuntime, | ||
h: &ActorHarness, | ||
expiration: ChainEpoch, | ||
first_sector_number: SectorNumber, | ||
count: usize, | ||
) -> Vec<SectorOnChainInfo> { | ||
let precommit_epoch = *rt.epoch.borrow(); | ||
|
||
// Precommit the sectors. | ||
let precommits = | ||
make_empty_precommits(h, first_sector_number, precommit_epoch - 1, expiration, count); | ||
h.pre_commit_sector_batch_v2(rt, &precommits, true, &TokenAmount::zero()).unwrap(); | ||
let precommits: Vec<SectorPreCommitOnChainInfo> = | ||
precommits.iter().map(|sector| h.get_precommit(rt, sector.sector_number)).collect(); | ||
|
||
// Prove the sectors. | ||
// Note: migrate this to ProveCommitSectors2 (batch) when the harness supports it. | ||
rt.set_epoch(precommit_epoch + rt.policy.pre_commit_challenge_delay + 1); | ||
let sectors: Vec<SectorOnChainInfo> = precommits | ||
.iter() | ||
.map(|pc| { | ||
h.prove_commit_sector_and_confirm( | ||
rt, | ||
pc, | ||
h.make_prove_commit_params(pc.info.sector_number), | ||
ProveCommitConfig::default(), | ||
) | ||
.unwrap() | ||
}) | ||
.collect(); | ||
|
||
// Window PoST to activate the sectors, a pre-requisite for upgrading. | ||
h.advance_and_submit_posts(rt, §ors); | ||
sectors | ||
} | ||
|
||
fn make_empty_precommits( | ||
h: &ActorHarness, | ||
first_sector_number: SectorNumber, | ||
challenge: ChainEpoch, | ||
expiration: ChainEpoch, | ||
count: usize, | ||
) -> Vec<SectorPreCommitInfo> { | ||
(0..count) | ||
.map(|i| { | ||
let sector_number = first_sector_number + i as u64; | ||
h.make_pre_commit_params_v2( | ||
sector_number, | ||
challenge, | ||
expiration, | ||
vec![], | ||
CompactCommD::empty(), | ||
) | ||
}) | ||
.collect() | ||
} | ||
|
||
fn make_update_manifest( | ||
st: &State, | ||
store: &impl Blockstore, | ||
sector: &SectorOnChainInfo, | ||
piece_specs: &[(u64, ActorID, AllocationID, DealID)], | ||
) -> SectorUpdateManifest { | ||
let (deadline, partition) = st.find_sector(store, sector.sector_number).unwrap(); | ||
let new_sealed_cid = make_sealed_cid(format!("sealed{}", sector.sector_number).as_bytes()); | ||
let pieces: Vec<PieceActivationManifest> = piece_specs | ||
.iter() | ||
.enumerate() | ||
.map(|(i, (sz, client, alloc, deal))| make_piece_manifest(i, *sz, *client, *alloc, *deal)) | ||
.collect(); | ||
SectorUpdateManifest { | ||
sector: sector.sector_number, | ||
deadline, | ||
partition, | ||
new_sealed_cid, | ||
pieces, | ||
} | ||
} | ||
|
||
fn make_piece_manifest( | ||
seq: usize, | ||
size: u64, | ||
alloc_client: ActorID, | ||
alloc_id: AllocationID, | ||
deal: DealID, | ||
) -> PieceActivationManifest { | ||
PieceActivationManifest { | ||
cid: make_piece_cid(format!("piece-{}", seq).as_bytes()), | ||
size: PaddedPieceSize(size), | ||
verified_allocation_key: if alloc_id != NO_ALLOCATION_ID { | ||
Some(VerifiedAllocationKey { client: alloc_client, id: alloc_id }) | ||
} else { | ||
None | ||
}, | ||
notify: if deal != 0 { | ||
vec![DataActivationNotification { | ||
address: STORAGE_MARKET_ACTOR_ADDR, | ||
payload: serialize(&deal, "deal id").unwrap(), | ||
}] | ||
} else { | ||
vec![] | ||
}, | ||
} | ||
} |
Oops, something went wrong.