Skip to content

Commit fe3e331

Browse files
FIP-0106: Remove of the ProveReplicaUpdates method from the miner actor (#1688)
* Remove deprecated method and start porting an integration test * Add equivalent assert * Make expected subcalls check pass * Refactor function to util * Refactor * Refactor * Add back replica_update_simple_path_success test * Refactor * Add more tests * Add failure case * Add another failure case * Add back tests * Add two failure cases * Add two more failure cases * Add another failure case * Add another failure case * Add failure case * Add last failure case * Remove member * Cleanup * Refactor * Refactor * Refactor * Restore original comments * Refactor * Remove deals member in ReplicaUpdateInner * Remove require_deals argument * Remove method comment part * Remove market_activate_deals function * Fix lint errors * Apply rvagg test rework suggestion * Add assert * Remove old method type and params * Move tests and remove old module --------- Co-authored-by: Shashank <99187193+sudo-shashank@users.noreply.github.com>
1 parent d61ec1b commit fe3e331

File tree

10 files changed

+1509
-1579
lines changed

10 files changed

+1509
-1579
lines changed

actors/miner/src/lib.rs

Lines changed: 2 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub enum Method {
131131
DisputeWindowedPoSt = 24,
132132
//PreCommitSectorBatch = 25, // Deprecated
133133
// ProveCommitAggregate = 26, // Deprecated
134-
ProveReplicaUpdates = 27,
134+
// ProveReplicaUpdates = 27, // Deprecated
135135
PreCommitSectorBatch2 = 28,
136136
//ProveReplicaUpdates2 = 29, // Deprecated
137137
ChangeBeneficiary = 30,
@@ -763,163 +763,6 @@ impl Actor {
763763
Ok(())
764764
}
765765

766-
fn prove_replica_updates<RT>(
767-
rt: &RT,
768-
params: ProveReplicaUpdatesParams,
769-
) -> Result<BitField, ActorError>
770-
where
771-
// + Clone because we messed up and need to keep a copy around between transactions.
772-
// https://github.com/filecoin-project/builtin-actors/issues/133
773-
RT::Blockstore: Clone,
774-
RT: Runtime,
775-
{
776-
// In this entry point, the unsealed CID is computed from deals via the market actor.
777-
// A future entry point will take the unsealed CID as parameter
778-
let updates = params
779-
.updates
780-
.into_iter()
781-
.map(|ru| ReplicaUpdateInner {
782-
sector_number: ru.sector_number,
783-
deadline: ru.deadline,
784-
partition: ru.partition,
785-
new_sealed_cid: ru.new_sealed_cid,
786-
deals: ru.deals,
787-
update_proof_type: ru.update_proof_type,
788-
replica_proof: ru.replica_proof,
789-
})
790-
.collect();
791-
Self::prove_replica_updates_inner(rt, updates)
792-
}
793-
794-
fn prove_replica_updates_inner<RT>(
795-
rt: &RT,
796-
updates: Vec<ReplicaUpdateInner>,
797-
) -> Result<BitField, ActorError>
798-
where
799-
RT::Blockstore: Blockstore,
800-
RT: Runtime,
801-
{
802-
let state: State = rt.state()?;
803-
let store = rt.store();
804-
let info = get_miner_info(store, &state)?;
805-
806-
rt.validate_immediate_caller_is(
807-
info.control_addresses.iter().chain(&[info.owner, info.worker]),
808-
)?;
809-
810-
let mut sectors = Sectors::load(&store, &state.sectors)
811-
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to load sectors array")?;
812-
let mut sector_infos = Vec::with_capacity(updates.len());
813-
for update in &updates {
814-
sector_infos.push(sectors.must_get(update.sector_number)?);
815-
}
816-
817-
// Validate inputs
818-
let require_deals = true; // Legacy PRU requires deals to be specified in the update.
819-
let all_or_nothing = false; // Skip invalid updates.
820-
let (batch_return, update_sector_infos) = validate_replica_updates(
821-
&updates,
822-
&sector_infos,
823-
&state,
824-
info.sector_size,
825-
rt.policy(),
826-
rt.curr_epoch(),
827-
store,
828-
require_deals,
829-
all_or_nothing,
830-
)?;
831-
// Drop invalid inputs.
832-
let update_sector_infos: Vec<UpdateAndSectorInfo> =
833-
batch_return.successes(&update_sector_infos).into_iter().cloned().collect();
834-
835-
let data_activation_inputs: Vec<DealsActivationInput> =
836-
update_sector_infos.iter().map_into().collect();
837-
838-
/*
839-
- no CommD was specified on input so it must be computed for the first time here
840-
*/
841-
let compute_commd = true;
842-
let (batch_return, data_activations) =
843-
activate_sectors_deals(rt, &data_activation_inputs, compute_commd)?;
844-
845-
// associate the successfully activated sectors with the ReplicaUpdateInner and SectorOnChainInfo
846-
let validated_updates: Vec<(&UpdateAndSectorInfo, DataActivationOutput)> = batch_return
847-
.successes(&update_sector_infos)
848-
.into_iter()
849-
.zip(data_activations)
850-
.collect();
851-
852-
if validated_updates.is_empty() {
853-
return Err(actor_error!(illegal_argument, "no valid updates"));
854-
}
855-
856-
// Errors past this point cause the prove_replica_updates call to fail (no more skipping sectors)
857-
// Group inputs by deadline
858-
let mut updated_sectors: Vec<SectorNumber> = Vec::new();
859-
let mut decls_by_deadline = BTreeMap::<u64, Vec<ReplicaUpdateStateInputs>>::new();
860-
let mut deadlines_to_load = Vec::<u64>::new();
861-
for (usi, data_activation) in &validated_updates {
862-
updated_sectors.push(usi.update.sector_number);
863-
let dl = usi.update.deadline;
864-
if !decls_by_deadline.contains_key(&dl) {
865-
deadlines_to_load.push(dl);
866-
}
867-
868-
let computed_commd = CompactCommD::new(data_activation.unsealed_cid)
869-
.get_cid(usi.sector_info.seal_proof)?;
870-
let proof_inputs = ReplicaUpdateInfo {
871-
update_proof_type: usi.update.update_proof_type,
872-
new_sealed_cid: usi.update.new_sealed_cid,
873-
old_sealed_cid: usi.sector_info.sealed_cid,
874-
new_unsealed_cid: computed_commd,
875-
proof: usi.update.replica_proof.clone().into(),
876-
};
877-
rt.verify_replica_update(&proof_inputs).with_context_code(
878-
ExitCode::USR_ILLEGAL_ARGUMENT,
879-
|| {
880-
format!(
881-
"failed to verify replica proof for sector {}",
882-
usi.sector_info.sector_number
883-
)
884-
},
885-
)?;
886-
887-
let activated_data = ReplicaUpdateActivatedData {
888-
seal_cid: usi.update.new_sealed_cid,
889-
unverified_space: data_activation.unverified_space.clone(),
890-
verified_space: data_activation.verified_space.clone(),
891-
};
892-
decls_by_deadline.entry(dl).or_default().push(ReplicaUpdateStateInputs {
893-
deadline: usi.update.deadline,
894-
partition: usi.update.partition,
895-
sector_info: usi.sector_info,
896-
activated_data,
897-
});
898-
899-
emit::sector_updated(
900-
rt,
901-
usi.update.sector_number,
902-
data_activation.unsealed_cid,
903-
&data_activation.pieces,
904-
)?;
905-
}
906-
907-
let (power_delta, pledge_delta) = update_replica_states(
908-
rt,
909-
&decls_by_deadline,
910-
validated_updates.len(),
911-
&mut sectors,
912-
info.sector_size,
913-
)?;
914-
915-
notify_pledge_changed(rt, &pledge_delta)?;
916-
request_update_power(rt, power_delta)?;
917-
918-
let updated_bitfield = BitField::try_from_bits(updated_sectors)
919-
.context_code(ExitCode::USR_ILLEGAL_ARGUMENT, "invalid sector number")?;
920-
Ok(updated_bitfield)
921-
}
922-
923766
fn prove_replica_updates3(
924767
rt: &impl Runtime,
925768
params: ProveReplicaUpdates3Params,
@@ -980,7 +823,6 @@ impl Actor {
980823
deadline: update.deadline,
981824
partition: update.partition,
982825
new_sealed_cid: update.new_sealed_cid,
983-
deals: vec![],
984826
update_proof_type: params.update_proofs_type,
985827
// Replica proof may be empty if an aggregate is being proven.
986828
// Validation needs to accept this empty proof.
@@ -989,16 +831,13 @@ impl Actor {
989831
}
990832

991833
// Validate inputs.
992-
let require_deals = false; // No deals can be specified in new replica update.
993834
let (validation_batch, update_sector_infos) = validate_replica_updates(
994835
&updates,
995836
&sector_infos,
996837
&state,
997-
info.sector_size,
998838
rt.policy(),
999839
rt.curr_epoch(),
1000840
store,
1001-
require_deals,
1002841
params.require_activation_success,
1003842
)?;
1004843
let valid_unproven_usis = validation_batch.successes(&update_sector_infos);
@@ -3443,7 +3282,6 @@ pub struct ReplicaUpdateInner {
34433282
pub deadline: u64,
34443283
pub partition: u64,
34453284
pub new_sealed_cid: Cid,
3446-
pub deals: Vec<DealID>,
34473285
pub update_proof_type: RegisteredUpdateProof,
34483286
pub replica_proof: RawBytes,
34493287
}
@@ -3759,11 +3597,9 @@ fn validate_replica_updates<'a, BS>(
37593597
updates: &'a [ReplicaUpdateInner],
37603598
sector_infos: &'a [SectorOnChainInfo],
37613599
state: &State,
3762-
sector_size: SectorSize,
37633600
policy: &Policy,
37643601
curr_epoch: ChainEpoch,
37653602
store: BS,
3766-
require_deals: bool,
37673603
all_or_nothing: bool,
37683604
) -> Result<(BatchReturn, Vec<UpdateAndSectorInfo<'a>>), ActorError>
37693605
where
@@ -3790,22 +3626,6 @@ where
37903626
));
37913627
}
37923628

3793-
if require_deals && update.deals.is_empty() {
3794-
return Err(actor_error!(
3795-
illegal_argument,
3796-
"must have deals to update, skipping sector {}",
3797-
update.sector_number
3798-
));
3799-
}
3800-
3801-
if update.deals.len() as u64 > sector_deals_max(policy, sector_size) {
3802-
return Err(actor_error!(
3803-
illegal_argument,
3804-
"more deals than policy allows, skipping sector {}",
3805-
update.sector_number
3806-
));
3807-
}
3808-
38093629
if update.deadline >= policy.wpost_period_deadlines {
38103630
return Err(actor_error!(
38113631
illegal_argument,
@@ -5461,7 +5281,7 @@ impl From<&UpdateAndSectorInfo<'_>> for DealsActivationInput {
54615281
DealsActivationInput {
54625282
sector_number: usi.sector_info.sector_number,
54635283
sector_expiry: usi.sector_info.expiration,
5464-
deal_ids: usi.update.deals.clone(),
5284+
deal_ids: vec![],
54655285
sector_type: usi.sector_info.seal_proof,
54665286
}
54675287
}
@@ -5472,8 +5292,6 @@ impl From<&UpdateAndSectorInfo<'_>> for DealsActivationInput {
54725292
struct DataActivationOutput {
54735293
pub unverified_space: BigInt,
54745294
pub verified_space: BigInt,
5475-
// None indicates either no deals or computation was not requested.
5476-
pub unsealed_cid: Option<Cid>,
54775295
pub pieces: Vec<(Cid, u64)>,
54785296
}
54795297

@@ -5503,8 +5321,6 @@ struct ReplicaUpdateActivatedData {
55035321
// Pieces are grouped by sector and succeed or fail in sector groups.
55045322
// If an activation input specifies an expected CommD for the sector, a CommD
55055323
// is calculated from the pieces and must match.
5506-
// This method never returns CommDs in the output type; either the caller provided
5507-
// them and they are correct, or the caller did not provide anything that needs checking.
55085324
fn activate_sectors_pieces(
55095325
rt: &impl Runtime,
55105326
activation_inputs: Vec<SectorPiecesActivationInput>,
@@ -5580,7 +5396,6 @@ fn activate_sectors_pieces(
55805396
DataActivationOutput {
55815397
unverified_space: unverified_space.clone(),
55825398
verified_space: sector_claim.claimed_space.clone(),
5583-
unsealed_cid: None,
55845399
pieces,
55855400
}
55865401
})
@@ -5691,7 +5506,6 @@ fn activate_sectors_deals(
56915506
DataActivationOutput {
56925507
unverified_space: unverified_deal_space,
56935508
verified_space: sector_claim.claimed_space,
5694-
unsealed_cid: sector_deals.unsealed_cid,
56955509
pieces: sector_pieces,
56965510
}
56975511
})
@@ -5801,7 +5615,6 @@ impl ActorCode for Actor {
58015615
RepayDebt|RepayDebtExported => repay_debt,
58025616
ChangeOwnerAddress|ChangeOwnerAddressExported => change_owner_address,
58035617
DisputeWindowedPoSt => dispute_windowed_post,
5804-
ProveReplicaUpdates => prove_replica_updates,
58055618
PreCommitSectorBatch2 => pre_commit_sector_batch2,
58065619
ChangeBeneficiary|ChangeBeneficiaryExported => change_beneficiary,
58075620
GetBeneficiary|GetBeneficiaryExported => get_beneficiary,

actors/miner/src/types.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -475,22 +475,6 @@ pub struct DisputeWindowedPoStParams {
475475
pub post_index: u64, // only one is allowed at a time to avoid loading too many sector infos.
476476
}
477477

478-
#[derive(Debug, Clone, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
479-
pub struct ReplicaUpdate {
480-
pub sector_number: SectorNumber,
481-
pub deadline: u64,
482-
pub partition: u64,
483-
pub new_sealed_cid: Cid,
484-
pub deals: Vec<DealID>,
485-
pub update_proof_type: RegisteredUpdateProof,
486-
pub replica_proof: RawBytes,
487-
}
488-
489-
#[derive(Debug, Clone, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
490-
pub struct ProveReplicaUpdatesParams {
491-
pub updates: Vec<ReplicaUpdate>,
492-
}
493-
494478
#[derive(Debug, Clone, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
495479
pub struct ProveReplicaUpdates3Params {
496480
pub sector_updates: Vec<SectorUpdateManifest>,

integration_tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ publish = false
1212

1313
[dependencies]
1414
fil_builtin_actors_state = { workspace = true }
15-
fil_actors_runtime = { workspace = true, features = [ "test_utils" ] }
15+
fil_actors_runtime = { workspace = true, features = ["test_utils"] }
1616
fil_actor_init = { workspace = true }
1717
fil_actor_cron = { workspace = true }
1818
fil_actor_system = { workspace = true }

integration_tests/src/expects.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ use fvm_shared::address::Address;
99
use fvm_shared::clock::ChainEpoch;
1010
use fvm_shared::deal::DealID;
1111
use fvm_shared::econ::TokenAmount;
12-
use fvm_shared::sector::{RegisteredSealProof, SectorNumber};
12+
use fvm_shared::sector::SectorNumber;
1313
use fvm_shared::{ActorID, METHOD_SEND};
1414
use num_traits::Zero;
1515

1616
use fil_actor_account::types::AuthenticateMessageParams;
1717
use fil_actor_datacap::BalanceParams;
1818
use fil_actor_market::{
19-
BatchActivateDealsParams, OnMinerSectorsTerminateParams, SectorDeals,
20-
VerifyDealsForActivationParams,
19+
OnMinerSectorsTerminateParams, SectorDeals, VerifyDealsForActivationParams,
2120
};
2221
use fil_actor_miner::ext::verifreg::ClaimID;
2322
use fil_actor_miner::{IsControllingAddressParam, PowerPair};
23+
use fil_actor_miner::{PieceChange, SectorChanges, SectorContentChangedParams};
2424
use fil_actor_power::{UpdateClaimedPowerParams, UpdatePledgeTotalParams};
2525
use fil_actor_verifreg::GetClaimsParams;
2626
use fil_actors_runtime::{
@@ -42,23 +42,20 @@ impl Expect {
4242
pub fn burn(from: ActorID, v: Option<TokenAmount>) -> ExpectInvocation {
4343
Self::send(from, BURNT_FUNDS_ACTOR_ADDR, v)
4444
}
45-
pub fn market_activate_deals(
45+
pub fn market_content_changed(
4646
from: ActorID,
4747
deals: Vec<DealID>,
4848
client_id: ActorID,
4949
sector_number: SectorNumber,
5050
sector_expiry: ChainEpoch,
51-
sector_type: RegisteredSealProof,
52-
compute_cid: bool,
51+
pieces_changes: Vec<PieceChange>,
5352
) -> ExpectInvocation {
54-
let params = IpldBlock::serialize_cbor(&BatchActivateDealsParams {
55-
sectors: vec![SectorDeals {
56-
sector_number,
57-
deal_ids: deals.clone(),
58-
sector_expiry,
59-
sector_type,
53+
let params = IpldBlock::serialize_cbor(&SectorContentChangedParams {
54+
sectors: vec![SectorChanges {
55+
sector: sector_number,
56+
minimum_commitment_epoch: sector_expiry,
57+
added: pieces_changes,
6058
}],
61-
compute_cid,
6259
})
6360
.unwrap();
6461

@@ -70,7 +67,7 @@ impl Expect {
7067
ExpectInvocation {
7168
from,
7269
to: STORAGE_MARKET_ACTOR_ADDR,
73-
method: fil_actor_market::Method::BatchActivateDeals as u64,
70+
method: fil_actor_market::Method::SectorContentChangedExported as u64,
7471
params: Some(params),
7572
value: Some(TokenAmount::zero()),
7673
subinvocs: Some(vec![]),

0 commit comments

Comments
 (0)