storagefsm: Change sector CreationTime to unix ts

This commit is contained in:
Łukasz Magiera 2021-01-20 14:49:31 +01:00
parent 9857ad8378
commit fd67a41c75
5 changed files with 36 additions and 15 deletions

View File

@ -543,7 +543,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
}
}
// t.CreationTime (time.Time) (struct)
// t.CreationTime (int64) (int64)
if len("CreationTime") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"CreationTime\" was too long")
}
@ -555,9 +555,15 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
if err := t.CreationTime.MarshalCBOR(w); err != nil {
if t.CreationTime >= 0 {
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.CreationTime)); err != nil {
return err
}
} else {
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.CreationTime-1)); err != nil {
return err
}
}
// t.Pieces ([]sealing.Piece) (slice)
if len("Pieces") > cbg.MaxLength {
@ -1149,15 +1155,31 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
t.SectorType = abi.RegisteredSealProof(extraI)
}
// t.CreationTime (time.Time) (struct)
// t.CreationTime (int64) (int64)
case "CreationTime":
{
if err := t.CreationTime.UnmarshalCBOR(br); err != nil {
return xerrors.Errorf("unmarshaling t.CreationTime: %w", err)
maj, extra, err := cbg.CborReadHeaderBuf(br, scratch)
var extraI int64
if err != nil {
return err
}
switch maj {
case cbg.MajUnsignedInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 positive overflow")
}
case cbg.MajNegativeInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 negative oveflow")
}
extraI = -1 - extraI
default:
return fmt.Errorf("wrong type for int64 field: %d", maj)
}
t.CreationTime = int64(extraI)
}
// t.Pieces ([]sealing.Piece) (slice)
case "Pieces":

View File

@ -84,8 +84,8 @@ type SectorAddPiece struct {
}
func (evt SectorAddPiece) apply(state *SectorInfo) {
if state.CreationTime.IsZero() {
state.CreationTime = time.Now()
if state.CreationTime == 0 {
state.CreationTime = time.Now().Unix()
}
state.PendingPieces = append(state.PendingPieces, evt.NewPiece)
}

View File

@ -35,14 +35,14 @@ func (m *Sealing) handleWaitDeals(ctx statemachine.Context, sector SectorInfo) e
}
}
if !sector.CreationTime.IsZero() {
if sector.CreationTime != 0 {
cfg, err := m.getConfig()
if err != nil {
m.inputLk.Unlock()
return xerrors.Errorf("getting storage config: %w", err)
}
sealTime := sector.CreationTime.Add(cfg.WaitDealsDelay)
sealTime := time.Unix(sector.CreationTime, 0).Add(cfg.WaitDealsDelay)
if now.After(sealTime) {
m.inputLk.Unlock()
return ctx.Send(SectorStartPacking{})

View File

@ -137,6 +137,7 @@ func New(api SealingAPI, fc FeeConfig, events Events, maddr address.Address, ds
pcp: pcp,
openSectors: map[abi.SectorID]*openSector{},
sectorTimers: map[abi.SectorID]*time.Timer{},
pendingPieces: map[cid.Cid]*pendingPiece{},
toUpgrade: map[abi.SectorNumber]struct{}{},

View File

@ -3,8 +3,6 @@ package sealing
import (
"bytes"
"context"
"time"
"github.com/ipfs/go-cid"
"github.com/filecoin-project/go-state-types/abi"
@ -71,7 +69,7 @@ type SectorInfo struct {
SectorType abi.RegisteredSealProof
// Packing
CreationTime time.Time
CreationTime int64 // unix seconds
Pieces []Piece
PendingPieces []cid.Cid