Skip to content

Commit

Permalink
burn datacap in one go
Browse files Browse the repository at this point in the history
  • Loading branch information
alexytsu committed May 26, 2023
1 parent 2fd9e77 commit fa6ddc6
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions actors/verifreg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,13 @@ impl Actor {
}

let mut rets: Vec<ClaimAllocationsReturn> = Vec::new();
let mut total_datacap_claimed = DataCap::zero();

for p in params.claims {
let mut datacap_claimed = DataCap::zero();
let mut ret_gen = BatchReturnGen::new(p.sectors.len());
let all_or_nothing = p.all_or_nothing;
rt.transaction(|st: &mut State, rt| {
rt.transaction(|st: &mut State, rt| {
for p in params.claims {
let mut datacap_claimed = DataCap::zero();
let mut ret_gen = BatchReturnGen::new(p.sectors.len());
let all_or_nothing = p.all_or_nothing;
let mut claims = st.load_claims(rt.store())?;
let mut allocs = st.load_allocs(rt.store())?;

Expand Down Expand Up @@ -448,23 +449,25 @@ impl Actor {
}
st.save_allocs(&mut allocs)?;
st.save_claims(&mut claims)?;
Ok(())
})
.context("state transaction failed")?;
let batch_info = ret_gen.gen();
if all_or_nothing && !batch_info.all_ok() {
return Err(actor_error!(
illegal_argument,
"all or nothing call contained failures: {}",
batch_info.to_string()
));
}
let batch_info = ret_gen.gen();
if all_or_nothing && !batch_info.all_ok() {
return Err(actor_error!(
illegal_argument,
"all or nothing call contained failures: {}",
batch_info.to_string()
));
}

// Burn the datacap tokens from verified registry's own balance.
burn(rt, &datacap_claimed)?;
// accumulate burnt datacap
total_datacap_claimed += datacap_claimed.clone();
rets.push(ClaimAllocationsReturn { batch_info, claimed_space: datacap_claimed });
}
Ok(())
})
.context("state transaction failed")?;

rets.push(ClaimAllocationsReturn { batch_info, claimed_space: datacap_claimed });
}
// burn all the claimed datacap
burn(rt, &total_datacap_claimed)?;

Ok(ClaimAllocationsBatchReturn { claims: rets })
}
Expand Down

0 comments on commit fa6ddc6

Please sign in to comment.