From 9e77a046a1f7ac4834c7a3fbd477f5199e13b880 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 27 Feb 2020 13:45:31 -0800 Subject: [PATCH] make it all build finally --- cbor_gen.go | 284 -------------------------------------------------- checks.go | 4 +- fsm_events.go | 4 +- fsm_test.go | 4 +- sealing.go | 2 +- states.go | 19 ++-- types.go | 18 +--- types_test.go | 9 +- 8 files changed, 24 insertions(+), 320 deletions(-) diff --git a/cbor_gen.go b/cbor_gen.go index d13847a99..e8cf29ec2 100644 --- a/cbor_gen.go +++ b/cbor_gen.go @@ -13,282 +13,6 @@ import ( var _ = xerrors.Errorf -func (t *SealTicket) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{162}); err != nil { - return err - } - - // t.BlockHeight (abi.ChainEpoch) (int64) - if len("BlockHeight") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"BlockHeight\" was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("BlockHeight")))); err != nil { - return err - } - if _, err := w.Write([]byte("BlockHeight")); err != nil { - return err - } - - if t.BlockHeight >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.BlockHeight))); err != nil { - return err - } - } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.BlockHeight)-1)); err != nil { - return err - } - } - - // t.TicketBytes ([]uint8) (slice) - if len("TicketBytes") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"TicketBytes\" was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("TicketBytes")))); err != nil { - return err - } - if _, err := w.Write([]byte("TicketBytes")); err != nil { - return err - } - - if len(t.TicketBytes) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.TicketBytes was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.TicketBytes)))); err != nil { - return err - } - if _, err := w.Write(t.TicketBytes); err != nil { - return err - } - return nil -} - -func (t *SealTicket) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajMap { - return fmt.Errorf("cbor input should be of type map") - } - - if extra > cbg.MaxLength { - return fmt.Errorf("SealTicket: map struct too large (%d)", extra) - } - - var name string - n := extra - - for i := uint64(0); i < n; i++ { - - { - sval, err := cbg.ReadString(br) - if err != nil { - return err - } - - name = string(sval) - } - - switch name { - // t.BlockHeight (abi.ChainEpoch) (int64) - case "BlockHeight": - { - maj, extra, err := cbg.CborReadHeader(br) - 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.BlockHeight = abi.ChainEpoch(extraI) - } - // t.TicketBytes ([]uint8) (slice) - case "TicketBytes": - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.TicketBytes: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - t.TicketBytes = make([]byte, extra) - if _, err := io.ReadFull(br, t.TicketBytes); err != nil { - return err - } - - default: - return fmt.Errorf("unknown struct field %d: '%s'", i, name) - } - } - - return nil -} -func (t *SealSeed) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{162}); err != nil { - return err - } - - // t.BlockHeight (abi.ChainEpoch) (int64) - if len("BlockHeight") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"BlockHeight\" was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("BlockHeight")))); err != nil { - return err - } - if _, err := w.Write([]byte("BlockHeight")); err != nil { - return err - } - - if t.BlockHeight >= 0 { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.BlockHeight))); err != nil { - return err - } - } else { - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.BlockHeight)-1)); err != nil { - return err - } - } - - // t.TicketBytes ([]uint8) (slice) - if len("TicketBytes") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"TicketBytes\" was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("TicketBytes")))); err != nil { - return err - } - if _, err := w.Write([]byte("TicketBytes")); err != nil { - return err - } - - if len(t.TicketBytes) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.TicketBytes was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.TicketBytes)))); err != nil { - return err - } - if _, err := w.Write(t.TicketBytes); err != nil { - return err - } - return nil -} - -func (t *SealSeed) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajMap { - return fmt.Errorf("cbor input should be of type map") - } - - if extra > cbg.MaxLength { - return fmt.Errorf("SealSeed: map struct too large (%d)", extra) - } - - var name string - n := extra - - for i := uint64(0); i < n; i++ { - - { - sval, err := cbg.ReadString(br) - if err != nil { - return err - } - - name = string(sval) - } - - switch name { - // t.BlockHeight (abi.ChainEpoch) (int64) - case "BlockHeight": - { - maj, extra, err := cbg.CborReadHeader(br) - 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.BlockHeight = abi.ChainEpoch(extraI) - } - // t.TicketBytes ([]uint8) (slice) - case "TicketBytes": - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.TicketBytes: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - t.TicketBytes = make([]byte, extra) - if _, err := io.ReadFull(br, t.TicketBytes); err != nil { - return err - } - - default: - return fmt.Errorf("unknown struct field %d: '%s'", i, name) - } - } - - return nil -} func (t *Piece) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) @@ -620,10 +344,6 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return err } - if err := t.Seed.MarshalCBOR(w); err != nil { - return err - } - // t.CommitMessage (cid.Cid) (struct) if len("CommitMessage") > cbg.MaxLength { return xerrors.Errorf("Value in field \"CommitMessage\" was too long") @@ -903,10 +623,6 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - if err := t.Seed.UnmarshalCBOR(br); err != nil { - return err - } - } // t.CommitMessage (cid.Cid) (struct) case "CommitMessage": diff --git a/checks.go b/checks.go index ff19afcb7..4fad2315b 100644 --- a/checks.go +++ b/checks.go @@ -111,8 +111,8 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %x != %x", r.Return, si.CommD)} } - if int64(head.Height())-int64(si.Ticket.BlockHeight+build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit { - return &ErrExpiredTicket{xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.Ticket.BlockHeight+build.SealRandomnessLookback, head.Height())} + if int64(head.Height())-int64(si.Ticket.Epoch+build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit { + return &ErrExpiredTicket{xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.Ticket.Epoch+build.SealRandomnessLookback, head.Height())} } return nil diff --git a/fsm_events.go b/fsm_events.go index 535f3fd86..dc773b966 100644 --- a/fsm_events.go +++ b/fsm_events.go @@ -68,7 +68,7 @@ func (evt SectorPackingFailed) apply(*SectorInfo) {} type SectorSealed struct { commR cid.Cid commD cid.Cid - ticket SealTicket + ticket api.SealTicket } func (evt SectorSealed) apply(state *SectorInfo) { @@ -96,7 +96,7 @@ func (evt SectorPreCommitted) apply(state *SectorInfo) { } type SectorSeedReady struct { - seed SealSeed + seed api.SealSeed } func (evt SectorSeedReady) apply(state *SectorInfo) { diff --git a/fsm_test.go b/fsm_test.go index 24145a2a1..a4d53d018 100644 --- a/fsm_test.go +++ b/fsm_test.go @@ -75,12 +75,12 @@ func TestSeedRevert(t *testing.T) { m.planSingle(SectorSeedReady{}) require.Equal(m.t, m.state.State, api.Committing) - _, err := m.s.plan([]statemachine.Event{{SectorSeedReady{seed: SealSeed{BlockHeight: 5}}}, {SectorCommitted{}}}, m.state) + _, err := m.s.plan([]statemachine.Event{{SectorSeedReady{seed: api.SealSeed{Epoch: 5}}}, {SectorCommitted{}}}, m.state) require.NoError(t, err) require.Equal(m.t, m.state.State, api.Committing) // not changing the seed this time - _, err = m.s.plan([]statemachine.Event{{SectorSeedReady{seed: SealSeed{BlockHeight: 5}}}, {SectorCommitted{}}}, m.state) + _, err = m.s.plan([]statemachine.Event{{SectorSeedReady{seed: api.SealSeed{Epoch: 5}}}, {SectorCommitted{}}}, m.state) require.Equal(m.t, m.state.State, api.CommitWait) m.planSingle(SectorProving{}) diff --git a/sealing.go b/sealing.go index 2e1e65ceb..8fd16cc17 100644 --- a/sealing.go +++ b/sealing.go @@ -28,7 +28,7 @@ const SectorStorePrefix = "/sectors" var log = logging.Logger("sectors") -type TicketFn func(context.Context) (SealTicket, error) +type TicketFn func(context.Context) (*api.SealTicket, error) type sealingApi interface { // TODO: trim down // Call a read only method on actors (no interaction with the chain required) diff --git a/states.go b/states.go index 9dae76694..426f028ad 100644 --- a/states.go +++ b/states.go @@ -11,6 +11,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/miner" "golang.org/x/xerrors" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" @@ -69,7 +70,7 @@ func (m *Sealing) handleUnsealed(ctx statemachine.Context, sector SectorInfo) er return ctx.Send(SectorSealFailed{xerrors.Errorf("getting ticket failed: %w", err)}) } - sealed, unsealed, err := m.sb.SealPreCommit(ctx.Context(), sector.SectorID, ticket.TicketBytes, sector.pieceInfos()) + sealed, unsealed, err := m.sb.SealPreCommit(ctx.Context(), sector.SectorID, ticket.Value, sector.pieceInfos()) if err != nil { return ctx.Send(SectorSealFailed{xerrors.Errorf("seal pre commit failed: %w", err)}) } @@ -77,7 +78,7 @@ func (m *Sealing) handleUnsealed(ctx statemachine.Context, sector SectorInfo) er return ctx.Send(SectorSealed{ commD: unsealed, commR: sealed, - ticket: ticket, + ticket: *ticket, }) } @@ -102,7 +103,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf RegisteredProof: abi.RegisteredProof_StackedDRG32GiBSeal, SealedCID: *sector.CommR, - SealRandEpoch: sector.Ticket.BlockHeight, + SealRandEpoch: sector.Ticket.Epoch, DealIDs: sector.deals(), } enc, aerr := actors.SerializeParams(params) @@ -156,9 +157,9 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er return err } - ctx.Send(SectorSeedReady{seed: SealSeed{ - BlockHeight: randHeight, - TicketBytes: abi.InteractiveSealRandomness(rand), + ctx.Send(SectorSeedReady{seed: api.SealSeed{ + Epoch: randHeight, + Value: abi.InteractiveSealRandomness(rand), }}) return nil @@ -177,9 +178,9 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo) error { log.Info("scheduling seal proof computation...") - log.Infof("KOMIT %d %x(%d); %x(%d); %v; r:%x; d:%x", sector.SectorID, sector.Ticket.TicketBytes, sector.Ticket.BlockHeight, sector.Seed.TicketBytes, sector.Seed.BlockHeight, sector.pieceInfos(), sector.CommR, sector.CommD) + log.Infof("KOMIT %d %x(%d); %x(%d); %v; r:%x; d:%x", sector.SectorID, sector.Ticket.Value, sector.Ticket.Epoch, sector.Seed.Value, sector.Seed.Epoch, sector.pieceInfos(), sector.CommR, sector.CommD) - proof, err := m.sb.SealCommit(ctx.Context(), sector.SectorID, sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.pieceInfos(), *sector.CommR, *sector.CommD) + proof, err := m.sb.SealCommit(ctx.Context(), sector.SectorID, sector.Ticket.Value, sector.Seed.Value, sector.pieceInfos(), *sector.CommR, *sector.CommD) if err != nil { return ctx.Send(SectorComputeProofFailed{xerrors.Errorf("computing seal proof failed: %w", err)}) } @@ -231,7 +232,7 @@ func (m *Sealing) handleCommitWait(ctx statemachine.Context, sector SectorInfo) } if mw.Receipt.ExitCode != 0 { - return ctx.Send(SectorCommitFailed{xerrors.Errorf("submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, sector.CommitMessage, sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.Seed.BlockHeight, sector.Proof)}) + return ctx.Send(SectorCommitFailed{xerrors.Errorf("submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, sector.CommitMessage, sector.Ticket.Value, sector.Seed.Value, sector.Seed.Epoch, sector.Proof)}) } return ctx.Send(SectorProving{}) diff --git a/types.go b/types.go index 3c181ef81..b25a43ef8 100644 --- a/types.go +++ b/types.go @@ -6,20 +6,6 @@ import ( "github.com/ipfs/go-cid" ) -type SealTicket struct { - BlockHeight abi.ChainEpoch - TicketBytes abi.SealRandomness -} - -type SealSeed struct { - BlockHeight abi.ChainEpoch - TicketBytes abi.InteractiveSealRandomness -} - -func (t *SealSeed) Equals(o *SealSeed) bool { - return string(t.TicketBytes) == string(o.TicketBytes) && t.BlockHeight == o.BlockHeight -} - type Piece struct { DealID *abi.DealID @@ -52,12 +38,12 @@ type SectorInfo struct { CommD *cid.Cid CommR *cid.Cid Proof []byte - Ticket SealTicket + Ticket api.SealTicket PreCommitMessage *cid.Cid // WaitSeed - Seed SealSeed + Seed api.SealSeed // Committing CommitMessage *cid.Cid diff --git a/types_test.go b/types_test.go index 32849e40c..f3ec17aa3 100644 --- a/types_test.go +++ b/types_test.go @@ -4,6 +4,7 @@ import ( "bytes" "testing" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/builtin" "gotest.tools/assert" @@ -28,12 +29,12 @@ func TestSectorInfoSelialization(t *testing.T) { CommD: &dummyCid, CommR: nil, Proof: nil, - Ticket: SealTicket{ - BlockHeight: 345, - TicketBytes: []byte{87, 78, 7, 87}, + Ticket: api.SealTicket{ + Epoch: 345, + Value: []byte{87, 78, 7, 87}, }, PreCommitMessage: nil, - Seed: SealSeed{}, + Seed: api.SealSeed{}, CommitMessage: nil, FaultReportMsg: nil, LastErr: "hi",