Skip to content

Commit

Permalink
Merge pull request #6304 from yaohcn/fix-ticket
Browse files Browse the repository at this point in the history
fix ticket expired
  • Loading branch information
magik6k authored May 21, 2021
2 parents 2e279b2 + 00a1e2c commit 5820355
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
40 changes: 40 additions & 0 deletions extern/storage-sealing/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,43 @@ func TestBrokenState(t *testing.T) {
}
}
}

func TestTicketExpired(t *testing.T) {
var notif []struct{ before, after SectorInfo }
ma, _ := address.NewIDAddress(55151)
m := test{
s: &Sealing{
maddr: ma,
stats: SectorStats{
bySector: map[abi.SectorID]statSectorState{},
},
notifee: func(before, after SectorInfo) {
notif = append(notif, struct{ before, after SectorInfo }{before, after})
},
},
t: t,
state: &SectorInfo{State: Packing},
}

m.planSingle(SectorPacked{})
require.Equal(m.t, m.state.State, GetTicket)

m.planSingle(SectorTicket{})
require.Equal(m.t, m.state.State, PreCommit1)

expired := checkTicketExpired(0, MaxTicketAge+1)
require.True(t, expired)

m.planSingle(SectorOldTicket{})
require.Equal(m.t, m.state.State, GetTicket)

expected := []SectorState{Packing, GetTicket, PreCommit1, GetTicket}
for i, n := range notif {
if n.before.State != expected[i] {
t.Fatalf("expected before state: %s, got: %s", expected[i], n.before.State)
}
if n.after.State != expected[i+1] {
t.Fatalf("expected after state: %s, got: %s", expected[i+1], n.after.State)
}
}
}
8 changes: 4 additions & 4 deletions extern/storage-sealing/states_sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func (m *Sealing) padSector(ctx context.Context, sectorID storage.SectorRef, exi
return out, nil
}

func checkTicketExpired(sector SectorInfo, epoch abi.ChainEpoch) bool {
return epoch-sector.TicketEpoch > MaxTicketAge // TODO: allow configuring expected seal durations
func checkTicketExpired(ticket, head abi.ChainEpoch) bool {
return head-ticket > MaxTicketAge // TODO: allow configuring expected seal durations
}

func (m *Sealing) getTicket(ctx statemachine.Context, sector SectorInfo) (abi.SealRandomness, abi.ChainEpoch, error) {
Expand All @@ -124,7 +124,7 @@ func (m *Sealing) getTicket(ctx statemachine.Context, sector SectorInfo) (abi.Se
if pci != nil {
ticketEpoch = pci.Info.SealRandEpoch

if checkTicketExpired(sector, ticketEpoch) {
if checkTicketExpired(ticketEpoch, epoch) {
return nil, 0, xerrors.Errorf("ticket expired for precommitted sector")
}
}
Expand Down Expand Up @@ -186,7 +186,7 @@ func (m *Sealing) handlePreCommit1(ctx statemachine.Context, sector SectorInfo)
return nil
}

if checkTicketExpired(sector, height) {
if checkTicketExpired(sector.TicketEpoch, height) {
return ctx.Send(SectorOldTicket{}) // go get new ticket
}

Expand Down

0 comments on commit 5820355

Please sign in to comment.