Merge pull request #6304 from yaohcn/fix-ticket

fix ticket expired
This commit is contained in:
Łukasz Magiera 2021-05-21 16:07:28 +02:00 committed by GitHub
commit 58203559e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 4 deletions

View File

@ -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)
}
}
}

View File

@ -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) {
@ -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")
}
}
@ -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
}