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

v6: fix market and power actors to match go #1348

Merged
merged 8 commits into from
Jan 6, 2022
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
5 changes: 5 additions & 0 deletions utils/paramfetch/src/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,10 @@
"cid": "QmehSmC6BhrgRZakPDta2ewoH9nosNzdjCqQRXsNFNUkLN",
"digest": "a89884252c04c298d0b3c81bfd884164",
"sector_size": 68719476736
},
"v28-fil-inner-product-v1.srs": {
"cid": "Qmdq44DjcQnFfU3PJcdX7J49GCqcUYszr1TxMbHtAkvQ3g",
"digest": "ae20310138f5ba81451d723f858e3797",
"sector_size": 0
}
}
71 changes: 16 additions & 55 deletions vm/actor/src/builtin/market/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl Actor {
/// Publish a new set of storage deals (not yet included in a sector).
fn publish_storage_deals<BS, RT>(
rt: &mut RT,
mut params: PublishStorageDealsParams,
params: PublishStorageDealsParams,
) -> Result<PublishStorageDealsReturn, ActorError>
where
BS: BlockStore,
Expand Down Expand Up @@ -272,21 +272,9 @@ impl Actor {
.build()
.map_err(|e| e.downcast_default(ExitCode::ErrIllegalState, "failed to load msm"))?;

// the for loop too uses rt immutably and also needs to mutably access it.
// so we will need to isolate them.
struct Deal<'a> {
to: Address,
method: u64,
params: Serialized,
value: TokenAmount,
di: usize,
deal: &'a mut deal::ClientDealProposal,
}
let mut method_queue: Vec<Deal> = vec![];

for (di, deal) in params.deals.iter_mut().enumerate() {
for (di, mut deal) in params.deals.into_iter().enumerate() {
// drop malformed deals
if let Err(e) = validate_deal(rt, deal, &network_raw_power, &baseline_power) {
if let Err(e) = validate_deal(rt, &deal, &network_raw_power, &baseline_power) {
info!("invalid deal {}: {}", di, e);
continue;
}
Expand Down Expand Up @@ -388,50 +376,25 @@ impl Actor {
// check VerifiedClient allowed cap and deduct PieceSize from cap
// drop deals with a DealSize that cannot be fully covered by VerifiedClient's available DataCap
if deal.proposal.verified_deal {
// So instead of mutably calling, we queue the rt.send() params as a struct, see Deal struct
method_queue.push(Deal {
to: *VERIFIED_REGISTRY_ACTOR_ADDR,
method: crate::verifreg::Method::UseBytes as u64,
params: Serialized::serialize(UseBytesParams {
if let Err(e) = rt.send(
*VERIFIED_REGISTRY_ACTOR_ADDR,
crate::verifreg::Method::UseBytes as u64,
Serialized::serialize(UseBytesParams {
address: client,
deal_size: BigInt::from(deal.proposal.piece_size.0),
})?,
value: TokenAmount::zero(),
di,
deal,
});
TokenAmount::zero(),
) {
info!(
"invalid deal {}: failed to acquire datacap exitcode: {}",
di, e
)
}
}

proposal_cid_lookup.insert(pcid);
}

// we then loop over the method_queue and call rt.send()
for i in method_queue {
let Deal {
to,
method,
params,
value,
di,
deal,
} = i;
let ret = rt.send(to, method, params, value);

if let Err(e) = ret {
info!(
"invalid deal {}: failed to acquire datacap exitcode: {}",
di, e
);
continue;
}

let pcid = deal.proposal.cid().map_err(|e| {
ActorError::from(e).wrap(format!("failed to take cid of proposal {}", di))
})?;

// update valid deal state
valid_proposal_cids.push(pcid);
valid_deals.push(deal.clone());
valid_deals.push(deal);
valid_input_bf.set(di);
}

Expand Down Expand Up @@ -459,7 +422,7 @@ impl Actor {
));
}

let mut new_deal_ids = Vec::new();
let mut new_deal_ids = Vec::with_capacity(valid_deal_count);

rt.transaction(|st: &mut State, rt| {
let mut msm = st.mutator(rt.store());
Expand All @@ -475,8 +438,6 @@ impl Actor {

// All storage dealProposals will be added in an atomic transaction; this operation will be unrolled if any of them fails.
// This should only fail on programmer error because all expected invalid conditions should be filtered in the first set of checks.

// TODO: Check if we neeed to make the previous look non mut
for (vid, valid_deal) in valid_deals.iter().enumerate() {
msm.lock_client_and_provider_balances(&valid_deal.proposal)?;

Expand Down
3 changes: 1 addition & 2 deletions vm/actor/src/builtin/miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,8 +1248,7 @@ impl Actor {
rt.transaction(|state: &mut State, rt|{
// Aggregate fee applies only when batching.
if params.sectors.len() > 1 {
let aggregate_fee = aggregate_pre_commit_network_fee(params.sectors.len() as i64, rt.base_fee());
// AggregateFee applied to fee debt to consolidate burn with outstanding debts
let aggregate_fee = aggregate_pre_commit_network_fee(params.sectors.len() as i64, rt.base_fee()); // AggregateFee applied to fee debt to consolidate burn with outstanding debts
state.apply_penalty(&aggregate_fee)
.map_err(|e| {
actor_error!(
Expand Down
146 changes: 71 additions & 75 deletions vm/actor/src/builtin/power/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,90 +411,86 @@ impl Actor {
// on order iterated through multimap.
let mut verifies = IndexMap::new();
let mut st_err: Option<String> = None;
let state: State = rt.state().map_err(|e| {
format!(
"failed to load state in process batch proof verification: {}",
e
)
})?;
rt.transaction(|st: &mut State, rt| {
if st.proof_validation_batch.is_none() {
debug!("ProofValidationBatch was nil, quitting verification");
return Ok(());
}
let mmap = match Multimap::from_root(
rt.store(),
st.proof_validation_batch.as_ref().unwrap(),
HAMT_BIT_WIDTH,
PROOF_VALIDATION_BATCH_AMT_BITWIDTH,
) {
Ok(mmap) => mmap,
Err(e) => {
st_err = Some(format!("failed to load proofs validation batch {}", e));
return Ok(());
let this_epoch_qa_power_smoothed = rt
.transaction(|st: &mut State, rt| {
let result = Ok(st.this_epoch_qa_power_smoothed.clone());
if st.proof_validation_batch.is_none() {
debug!("ProofValidationBatch was nil, quitting verification");
return result;
}
};

let claims = match make_map_with_root_and_bitwidth::<_, Claim>(
&st.claims,
rt.store(),
HAMT_BIT_WIDTH,
) {
Ok(claims) => claims,
Err(e) => {
st_err = Some(format!("failed to load claims: {}", e));
return Ok(());
}
};

if let Err(e) = mmap.for_all::<_, SealVerifyInfo>(|k, arr| {
let addr = match Address::from_bytes(&k.0) {
Ok(addr) => addr,
let mmap = match Multimap::from_root(
rt.store(),
st.proof_validation_batch.as_ref().unwrap(),
HAMT_BIT_WIDTH,
PROOF_VALIDATION_BATCH_AMT_BITWIDTH,
) {
Ok(mmap) => mmap,
Err(e) => {
return Err(format!("failed to parse address key: {}", e).into());
st_err = Some(format!("failed to load proofs validation batch {}", e));
return result;
}
};

let contains_claim = match claims.contains_key(&addr.to_bytes()) {
Ok(contains_claim) => contains_claim,
Err(e) => return Err(format!("failed to look up claim: {}", e).into()),
let claims = match make_map_with_root_and_bitwidth::<_, Claim>(
&st.claims,
rt.store(),
HAMT_BIT_WIDTH,
) {
Ok(claims) => claims,
Err(e) => {
st_err = Some(format!("failed to load claims: {}", e));
return result;
}
};

if !contains_claim {
debug!("skipping batch verifies for unknown miner: {}", addr);
return Ok(());
}
if let Err(e) = mmap.for_all::<_, SealVerifyInfo>(|k, arr| {
let addr = match Address::from_bytes(&k.0) {
Ok(addr) => addr,
Err(e) => {
return Err(format!("failed to parse address key: {}", e).into());
}
};

let contains_claim = match claims.contains_key(&addr.to_bytes()) {
Ok(contains_claim) => contains_claim,
Err(e) => return Err(format!("failed to look up claim: {}", e).into()),
};

if !contains_claim {
debug!("skipping batch verifies for unknown miner: {}", addr);
return Ok(());
}

let mut infos = Vec::new();
arr.for_each(|_, svi| {
infos.push(svi.clone());
Ok(())
})
.map_err(|e| {
format!(
"failed to iterate over proof verify array for miner {}: {}",
addr, e
)
})?;
let mut infos = Vec::new();
arr.for_each(|_, svi| {
infos.push(svi.clone());
Ok(())
})
.map_err(|e| {
format!(
"failed to iterate over proof verify array for miner {}: {}",
addr, e
)
})?;

verifies.insert(addr, infos);
Ok(())
}) {
// Do not return immediately, all runs that get this far should wipe the ProofValidationBatchQueue.
// If we leave the validation batch then in the case of a repeating state error the queue
// will quickly fill up and repeated traversals will start ballooning cron execution time.
st_err = Some(format!("failed to iterate proof batch: {}", e));
}
verifies.insert(addr, infos);
Ok(())
}) {
// Do not return immediately, all runs that get this far should wipe the ProofValidationBatchQueue.
// If we leave the validation batch then in the case of a repeating state error the queue
// will quickly fill up and repeated traversals will start ballooning cron execution time.
st_err = Some(format!("failed to iterate proof batch: {}", e));
}

st.proof_validation_batch = None;
Ok(())
})
.map_err(|e| {
format!(
"failed to do transaction in process batch proof verifies: {}",
e
)
})?;
st.proof_validation_batch = None;
result
})
.map_err(|e| {
format!(
"failed to do transaction in process batch proof verifies: {}",
e
)
})?;
if let Some(st_err) = st_err {
return Err(st_err);
}
Expand Down Expand Up @@ -532,7 +528,7 @@ impl Actor {
sectors: successful,
reward_smoothed: rewret.this_epoch_reward_smoothed.clone(),
reward_baseline_power: rewret.this_epoch_baseline_power.clone(),
quality_adj_power_smoothed: state.this_epoch_qa_power_smoothed.clone(),
quality_adj_power_smoothed: this_epoch_qa_power_smoothed.clone(),
})
.map_err(|e| format!("failed to serialize ConfirmSectorProofsParams: {}", e))?,
Default::default(),
Expand Down
Loading