Skip to content

Commit

Permalink
Update runtime transaction logic (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinabell authored Aug 31, 2020
1 parent d5ccf90 commit cd68b53
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 320 deletions.
2 changes: 1 addition & 1 deletion vm/actor/src/builtin/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Actor {
let id_address: Address = rt.transaction(|s: &mut State, rt| {
s.map_address_to_new_id(rt.store(), &robust_address)
.map_err(|e| actor_error!(ErrIllegalState; "failed to allocate ID address: {}", e))
})??;
})?;

// Create an empty actor
rt.create_actor(params.code_cid, &id_address)?;
Expand Down
67 changes: 33 additions & 34 deletions vm/actor/src/builtin/market/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Actor {

let (nominal, _, _) = escrow_address(rt, &provider_or_client)?;

rt.transaction::<State, Result<_, ActorError>, _>(|st, rt| {
rt.transaction(|st: &mut State, rt| {
let mut msm = st.mutator(rt.store());
msm.with_escrow_table(Permission::Write)
.with_locked_table(Permission::Write)
Expand All @@ -120,7 +120,7 @@ impl Actor {
.map_err(|e| actor_error!(ErrIllegalState; "failed to flush state: {}", e))?;

Ok(())
})??;
})?;

Ok(())
}
Expand All @@ -146,36 +146,35 @@ impl Actor {
// for clients -> only the client i.e the recipient can withdraw
rt.validate_immediate_caller_is(&approved)?;

let amount_extracted =
rt.transaction::<State, Result<TokenAmount, ActorError>, _>(|st, rt| {
let mut msm = st.mutator(rt.store());
msm.with_escrow_table(Permission::Write)
.with_locked_table(Permission::Write)
.build()
.map_err(|e| actor_error!(ErrIllegalState; "failed to load state: {}", e))?;

// The withdrawable amount might be slightly less than nominal
// depending on whether or not all relevant entries have been processed
// by cron
let min_balance = msm.locked_table.as_ref().unwrap().get(&nominal).map_err(
|e| actor_error!(ErrIllegalState; "failed to get locked balance: {}", e),
)?;
let amount_extracted = rt.transaction(|st: &mut State, rt| {
let mut msm = st.mutator(rt.store());
msm.with_escrow_table(Permission::Write)
.with_locked_table(Permission::Write)
.build()
.map_err(|e| actor_error!(ErrIllegalState; "failed to load state: {}", e))?;

let ex = msm
.escrow_table
.as_mut()
.unwrap()
.subtract_with_minimum(&nominal, &params.amount, &min_balance)
.map_err(|e| {
actor_error!(ErrIllegalState;
// The withdrawable amount might be slightly less than nominal
// depending on whether or not all relevant entries have been processed
// by cron
let min_balance = msm.locked_table.as_ref().unwrap().get(&nominal).map_err(
|e| actor_error!(ErrIllegalState; "failed to get locked balance: {}", e),
)?;

let ex = msm
.escrow_table
.as_mut()
.unwrap()
.subtract_with_minimum(&nominal, &params.amount, &min_balance)
.map_err(|e| {
actor_error!(ErrIllegalState;
"failed to subtract from escrow table: {}", e)
})?;
})?;

msm.commit_state()
.map_err(|e| actor_error!(ErrIllegalState; "failed to flush state: {}", e))?;
msm.commit_state()
.map_err(|e| actor_error!(ErrIllegalState; "failed to flush state: {}", e))?;

Ok(ex)
})??;
Ok(ex)
})?;

rt.send(
recipient,
Expand Down Expand Up @@ -313,7 +312,7 @@ impl Actor {
msm.commit_state()
.map_err(|e| actor_error!(ErrIllegalState; "failed to flush state: {}", e))?;
Ok(())
})??;
})?;

for deal in &params.deals {
// Check VerifiedClient allowed cap and deduct PieceSize from cap.
Expand Down Expand Up @@ -483,7 +482,7 @@ impl Actor {
msm.commit_state()
.map_err(|e| actor_error!(ErrIllegalState; "failed to flush state: {}", e))?;
Ok(())
})??;
})?;

Ok(())
}
Expand All @@ -502,7 +501,7 @@ impl Actor {
rt.validate_immediate_caller_type(std::iter::once(&*MINER_ACTOR_CODE_ID))?;
let miner_addr = *rt.message().caller();

rt.transaction::<State, Result<(), ActorError>, _>(|st, rt| {
rt.transaction(|st: &mut State, rt| {
let mut msm = st.mutator(rt.store());
msm.with_deal_states(Permission::Write)
.with_deal_proposals(Permission::ReadOnly)
Expand Down Expand Up @@ -555,7 +554,7 @@ impl Actor {
msm.commit_state()
.map_err(|e| actor_error!(ErrIllegalState; "failed to flush state: {}", e))?;
Ok(())
})??;
})?;
Ok(())
}

Expand Down Expand Up @@ -611,7 +610,7 @@ impl Actor {
let curr_epoch = rt.curr_epoch();
let mut timed_out_verified_deals: Vec<DealProposal> = Vec::new();

rt.transaction::<State, Result<(), ActorError>, _>(|st, rt| {
rt.transaction(|st: &mut State, rt| {
let last_cron = st.last_cron;
let mut updates_needed: AHashMap<ChainEpoch, Vec<DealID>> = AHashMap::new();
let mut msm = st.mutator(rt.store());
Expand Down Expand Up @@ -822,7 +821,7 @@ impl Actor {
msm.commit_state()
.map_err(|e| actor_error!(ErrIllegalState; "failed to flush state: {}", e))?;
Ok(())
})??;
})?;

for d in timed_out_verified_deals {
let res = rt.send(
Expand Down
Loading

0 comments on commit cd68b53

Please sign in to comment.