diff --git a/cbor_gen.go b/cbor_gen.go index ec4467edf..a5cf6273e 100644 --- a/cbor_gen.go +++ b/cbor_gen.go @@ -7,6 +7,7 @@ import ( "io" "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" ) @@ -382,7 +383,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{180}); err != nil { + if _, err := w.Write([]byte{181}); err != nil { return err } @@ -607,6 +608,22 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return err } + // t.PreCommitInfo (miner.SectorPreCommitInfo) (struct) + if len("PreCommitInfo") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PreCommitInfo\" was too long") + } + + if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("PreCommitInfo")))); err != nil { + return err + } + if _, err := w.Write([]byte("PreCommitInfo")); err != nil { + return err + } + + if err := t.PreCommitInfo.MarshalCBOR(w); err != nil { + return err + } + // t.PreCommitMessage (cid.Cid) (struct) if len("PreCommitMessage") > cbg.MaxLength { return xerrors.Errorf("Value in field \"PreCommitMessage\" was too long") @@ -1065,6 +1082,28 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { if _, err := io.ReadFull(br, t.Proof); err != nil { return err } + // t.PreCommitInfo (miner.SectorPreCommitInfo) (struct) + case "PreCommitInfo": + + { + + pb, err := br.PeekByte() + if err != nil { + return err + } + if pb == cbg.CborNull[0] { + var nbuf [1]byte + if _, err := br.Read(nbuf[:]); err != nil { + return err + } + } else { + t.PreCommitInfo = new(miner.SectorPreCommitInfo) + if err := t.PreCommitInfo.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.PreCommitInfo pointer: %w", err) + } + } + + } // t.PreCommitMessage (cid.Cid) (struct) case "PreCommitMessage": diff --git a/constants.go b/constants.go index cc035b094..565a38c8e 100644 --- a/constants.go +++ b/constants.go @@ -6,7 +6,7 @@ import ( ) // Epochs -const SealRandomnessLookback = miner.ChainFinalityish +const SealRandomnessLookback = miner.ChainFinality // Epochs func SealRandomnessLookbackLimit(spt abi.RegisteredSealProof) abi.ChainEpoch { diff --git a/fsm.go b/fsm.go index ff9ca4d9b..e0c53cfce 100644 --- a/fsm.go +++ b/fsm.go @@ -166,49 +166,56 @@ func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(sta /* - * Empty - | | - | v - *<- Packing <- incoming - | | - | v - *<- PreCommit1 <--> SealPreCommit1Failed - | | ^ ^^ - | | *----------++----\ - | v v || | - *<- PreCommit2 --------++--> SealPreCommit2Failed - | | || - | v /-------/| - * PreCommitting <-----+---> PreCommitFailed - | | | ^ - | v | | - *<- WaitSeed -----------+-----/ - | ||| ^ | - | ||| \--------*-----/ - | ||| | - | vvv v----+----> ComputeProofFailed - *<- Committing | - | | ^--> CommitFailed - | v ^ - *<- CommitWait ---/ - | | - | v - | FinalizeSector <--> FinalizeFailed - | | - | v - *<- Proving - | - v - FailedUnrecoverable + * Empty <- incoming deals + | | + | v + *<- WaitDeals <- incoming deals + | | + | v + *<- Packing <- incoming committed capacity + | | + | v + *<- PreCommit1 <--> SealPreCommit1Failed + | | ^ ^^ + | | *----------++----\ + | v v || | + *<- PreCommit2 --------++--> SealPreCommit2Failed + | | || + | v /-------/| + * PreCommitting <-----+---> PreCommitFailed + | | | ^ + | v | | + *<- WaitSeed -----------+-----/ + | ||| ^ | + | ||| \--------*-----/ + | ||| | + | vvv v----+----> ComputeProofFailed + *<- Committing | + | | ^--> CommitFailed + | v ^ + *<- CommitWait ---/ + | | + | v + | FinalizeSector <--> FinalizeFailed + | | + | v + *<- Proving + | + v + FailedUnrecoverable - UndefinedSectorState <- ¯\_(ツ)_/¯ - | ^ - *---------------------/ + UndefinedSectorState <- ¯\_(ツ)_/¯ + | ^ + *---------------------/ */ switch state.State { // Happy path + case Empty: + fallthrough + case WaitDeals: + log.Infof("Waiting for deals %d", state.SectorNumber) case Packing: return m.handlePacking, nil case PreCommit1: diff --git a/fsm_events.go b/fsm_events.go index a631ec08d..678d49ec6 100644 --- a/fsm_events.go +++ b/fsm_events.go @@ -1,10 +1,12 @@ package sealing import ( - "github.com/filecoin-project/specs-actors/actors/abi" - "github.com/filecoin-project/specs-storage/storage" "github.com/ipfs/go-cid" "golang.org/x/xerrors" + + "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/specs-storage/storage" ) type mutator interface { @@ -151,11 +153,13 @@ func (evt SectorChainPreCommitFailed) FormatError(xerrors.Printer) (next error) func (evt SectorChainPreCommitFailed) apply(*SectorInfo) {} type SectorPreCommitted struct { - Message cid.Cid + Message cid.Cid + PreCommitInfo miner.SectorPreCommitInfo } func (evt SectorPreCommitted) apply(state *SectorInfo) { state.PreCommitMessage = &evt.Message + state.PreCommitInfo = &evt.PreCommitInfo } type SectorSeedReady struct { diff --git a/go.mod b/go.mod index 18462d0f1..9a3138ec2 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663 // indirect github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9 github.com/filecoin-project/sector-storage v0.0.0-20200625154333-98ef8e4ef246 - github.com/filecoin-project/specs-actors v0.6.0 + github.com/filecoin-project/specs-actors v0.7.0 github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea github.com/ipfs/go-cid v0.0.5 github.com/ipfs/go-datastore v0.4.4 diff --git a/go.sum b/go.sum index c8c29adf2..4111d0e17 100644 --- a/go.sum +++ b/go.sum @@ -62,6 +62,8 @@ github.com/filecoin-project/specs-actors v0.3.0 h1:QxgAuTrZr5TPqjyprZk0nTYW5o0JW github.com/filecoin-project/specs-actors v0.3.0/go.mod h1:nQYnFbQ7Y0bHZyq6HDEuVlCPR+U3z5Q3wMOQ+2aiV+Y= github.com/filecoin-project/specs-actors v0.6.0 h1:IepUsmDGY60QliENVTkBTAkwqGWw9kNbbHOcU/9oiC0= github.com/filecoin-project/specs-actors v0.6.0/go.mod h1:dRdy3cURykh2R8O/DKqy8olScl70rmIS7GrB4hB1IDY= +github.com/filecoin-project/specs-actors v0.7.0 h1:tldjW8pFiJcMtyGPsXmPoFdbN/18mKW3BpEMlO4NJAc= +github.com/filecoin-project/specs-actors v0.7.0/go.mod h1:+z0htZu/wLBDbOLcQTKKUEC2rkUTFzL2KJ/bRAVWkws= github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea h1:iixjULRQFPn7Q9KlIqfwLJnlAXO10bbkI+xy5GKGdLY= github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= diff --git a/sealing.go b/sealing.go index 9eea593a2..e1d2d77c9 100644 --- a/sealing.go +++ b/sealing.go @@ -34,7 +34,7 @@ type SealingAPI interface { StateMinerSectorSize(context.Context, address.Address, TipSetToken) (abi.SectorSize, error) StateMinerWorkerAddress(ctx context.Context, maddr address.Address, tok TipSetToken) (address.Address, error) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok TipSetToken) (*miner.Deadlines, error) - StateMinerInitialPledgeCollateral(context.Context, address.Address, abi.SectorNumber, TipSetToken) (big.Int, error) + StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error) StateMarketStorageDeal(context.Context, abi.DealID, TipSetToken) (market.DealProposal, error) SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, gasPrice big.Int, gasLimit int64, params []byte) (cid.Cid, error) ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error) diff --git a/states_sealing.go b/states_sealing.go index 5a74a756b..e6d38bd7f 100644 --- a/states_sealing.go +++ b/states_sealing.go @@ -174,13 +174,18 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("could not serialize pre-commit sector parameters: %w", err)}) } - log.Info("submitting precommit for sector: ", sector.SectorNumber) - mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.PreCommitSector, big.NewInt(0), big.NewInt(1), 1000000, enc.Bytes()) + collateral, err := m.api.StateMinerInitialPledgeCollateral(ctx.Context(), m.maddr, *params, tok) + if err != nil { + return xerrors.Errorf("getting initial pledge collateral: %w", err) + } + + log.Infof("submitting precommit for sector (deposit: %s): ", sector.SectorNumber, collateral) + mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.PreCommitSector, collateral, big.NewInt(1), 1000000, enc.Bytes()) if err != nil { return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)}) } - return ctx.Send(SectorPreCommitted{Message: mcid}) + return ctx.Send(SectorPreCommitted{Message: mcid, PreCommitInfo: *params}) } func (m *Sealing) handlePreCommitWait(ctx statemachine.Context, sector SectorInfo) error { @@ -291,11 +296,24 @@ func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo) return nil } - collateral, err := m.api.StateMinerInitialPledgeCollateral(ctx.Context(), m.maddr, sector.SectorNumber, tok) + collateral, err := m.api.StateMinerInitialPledgeCollateral(ctx.Context(), m.maddr, *sector.PreCommitInfo, tok) if err != nil { return xerrors.Errorf("getting initial pledge collateral: %w", err) } + pci, err := m.api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, sector.PreCommitTipSet) + if err != nil { + return xerrors.Errorf("getting precommit info: %w", err) + } + if pci == nil { + return ctx.Send(SectorCommitFailed{error: xerrors.Errorf("precommit info not found on chain")}) + } + + collateral = big.Sub(collateral, pci.PreCommitDeposit) + if collateral.LessThan(big.Zero()) { + collateral = big.Zero() + } + // TODO: check seed / ticket are up to date mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.ProveCommitSector, collateral, big.NewInt(1), 1000000, enc.Bytes()) if err != nil { diff --git a/types.go b/types.go index c76a6c68d..de9fbc593 100644 --- a/types.go +++ b/types.go @@ -8,6 +8,7 @@ import ( sectorstorage "github.com/filecoin-project/sector-storage" "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" "github.com/filecoin-project/specs-storage/storage" ) @@ -67,6 +68,7 @@ type SectorInfo struct { CommR *cid.Cid Proof []byte + PreCommitInfo *miner.SectorPreCommitInfo PreCommitMessage *cid.Cid PreCommitTipSet TipSetToken