Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
finish addressing feedback from @anorth
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed May 4, 2020
1 parent b2ccac0 commit 78d523d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
31 changes: 17 additions & 14 deletions actors/builtin/market/market_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,13 @@ func (a Actor) VerifyDealsOnSectorProveCommit(rt Runtime, params *VerifyDealsOnS
}

for _, dealID := range params.DealIDs {
deal, _, err := states.Get(dealID)
deal, found, err := states.Get(dealID)
if err != nil {
rt.Abortf(exitcode.ErrIllegalState, "get deal %v", err)
}
if !found {
rt.Abortf(exitcode.ErrIllegalArgument, "failed to find deal given in params: %d", dealID)
}
proposal, err := proposals.Get(dealID)
if err != nil {
rt.Abortf(exitcode.ErrIllegalState, "get deal %v", err)
Expand Down Expand Up @@ -385,10 +388,13 @@ func (a Actor) OnMinerSectorsTerminate(rt Runtime, params *OnMinerSectorsTermina
}
Assert(deal.Provider == minerAddr)

state, _, err := states.Get(dealID)
state, found, err := states.Get(dealID)
if err != nil {
rt.Abortf(exitcode.ErrIllegalState, "get deal: %v", err)
}
if !found {
rt.Abortf(exitcode.ErrIllegalState, "no state found for deal in sector being terminated")
}

// Note: we do not perform the balance transfers here, but rather simply record the flag
// to indicate that processDealSlashed should be called when the deferred state computation
Expand Down Expand Up @@ -455,19 +461,16 @@ func (a Actor) CronTick(rt Runtime, params *adt.EmptyValue) *adt.EmptyValue {

if state.SectorStartEpoch == epochUndefined {
// Not yet appeared in proven sector; check for timeout.
if rt.CurrEpoch() > deal.StartEpoch {
slashed := st.processDealInitTimedOut(rt, et, lt, dealID, deal, state)
if !slashed.IsZero() {
amountSlashed = big.Add(amountSlashed, slashed)
}
if deal.VerifiedDeal {
timedOutVerifiedDeals = append(timedOutVerifiedDeals, deal)
}
return nil
}
AssertMsg(rt.CurrEpoch() >= deal.StartEpoch, "if sector start is not set, we must be in a timed out state")

// This should not be able to happen
rt.Abortf(exitcode.ErrIllegalState, "invalid deal state, unstarted, not timed out")
slashed := st.processDealInitTimedOut(rt, et, lt, dealID, deal, state)
if !slashed.IsZero() {
amountSlashed = big.Add(amountSlashed, slashed)
}
if deal.VerifiedDeal {
timedOutVerifiedDeals = append(timedOutVerifiedDeals, deal)
}
return nil
}

slashAmount, nextEpoch := st.updatePendingDealState(rt, state, deal, dealID, et, lt, rt.CurrEpoch())
Expand Down
1 change: 1 addition & 0 deletions actors/builtin/market/market_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func ConstructState(emptyArrayCid, emptyMapCid, emptyMSetCid cid.Cid) *State {
LockedTable: emptyMapCid,
NextID: abi.DealID(0),
DealOpsByEpoch: emptyMSetCid,
LastCron: abi.ChainEpoch(-1),
}
}

Expand Down
1 change: 1 addition & 0 deletions actors/builtin/market/market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestMarketActor(t *testing.T) {
assert.Equal(t, emptyMap, state.LockedTable)
assert.Equal(t, abi.DealID(0), state.NextID)
assert.Equal(t, emptyMultiMap, state.DealOpsByEpoch)
assert.Equal(t, abi.ChainEpoch(-1), state.LastCron)
})

t.Run("AddBalance", func(t *testing.T) {
Expand Down

0 comments on commit 78d523d

Please sign in to comment.