Merge pull request #40 from filecoin-project/feat/specs-actors-v0.7.0

Specs actors v0.7.0
This commit is contained in:
Łukasz Magiera 2020-07-01 15:11:52 +02:00 committed by GitHub
commit dd6398dbcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 120 additions and 48 deletions

View File

@ -7,6 +7,7 @@ import (
"io" "io"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors" xerrors "golang.org/x/xerrors"
) )
@ -382,7 +383,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
return err return err
} }
if _, err := w.Write([]byte{180}); err != nil { if _, err := w.Write([]byte{181}); err != nil {
return err return err
} }
@ -607,6 +608,22 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err 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) // t.PreCommitMessage (cid.Cid) (struct)
if len("PreCommitMessage") > cbg.MaxLength { if len("PreCommitMessage") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"PreCommitMessage\" was too long") 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 { if _, err := io.ReadFull(br, t.Proof); err != nil {
return err 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) // t.PreCommitMessage (cid.Cid) (struct)
case "PreCommitMessage": case "PreCommitMessage":

View File

@ -6,7 +6,7 @@ import (
) )
// Epochs // Epochs
const SealRandomnessLookback = miner.ChainFinalityish const SealRandomnessLookback = miner.ChainFinality
// Epochs // Epochs
func SealRandomnessLookbackLimit(spt abi.RegisteredSealProof) abi.ChainEpoch { func SealRandomnessLookbackLimit(spt abi.RegisteredSealProof) abi.ChainEpoch {

81
fsm.go
View File

@ -166,49 +166,56 @@ func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(sta
/* /*
* Empty * Empty <- incoming deals
| | | |
| v | v
*<- Packing <- incoming *<- WaitDeals <- incoming deals
| | | |
| v | v
*<- PreCommit1 <--> SealPreCommit1Failed *<- Packing <- incoming committed capacity
| | ^ ^^ | |
| | *----------++----\ | v
| v v || | *<- PreCommit1 <--> SealPreCommit1Failed
*<- PreCommit2 --------++--> SealPreCommit2Failed | | ^ ^^
| | || | | *----------++----\
| v /-------/| | v v || |
* PreCommitting <-----+---> PreCommitFailed *<- PreCommit2 --------++--> SealPreCommit2Failed
| | | ^ | | ||
| v | | | v /-------/|
*<- WaitSeed -----------+-----/ * PreCommitting <-----+---> PreCommitFailed
| ||| ^ | | | | ^
| ||| \--------*-----/ | v | |
| ||| | *<- WaitSeed -----------+-----/
| vvv v----+----> ComputeProofFailed | ||| ^ |
*<- Committing | | ||| \--------*-----/
| | ^--> CommitFailed | ||| |
| v ^ | vvv v----+----> ComputeProofFailed
*<- CommitWait ---/ *<- Committing |
| | | | ^--> CommitFailed
| v | v ^
| FinalizeSector <--> FinalizeFailed *<- CommitWait ---/
| | | |
| v | v
*<- Proving | FinalizeSector <--> FinalizeFailed
| | |
v | v
FailedUnrecoverable *<- Proving
|
v
FailedUnrecoverable
UndefinedSectorState <- ¯\_()_/¯ UndefinedSectorState <- ¯\_()_/¯
| ^ | ^
*---------------------/ *---------------------/
*/ */
switch state.State { switch state.State {
// Happy path // Happy path
case Empty:
fallthrough
case WaitDeals:
log.Infof("Waiting for deals %d", state.SectorNumber)
case Packing: case Packing:
return m.handlePacking, nil return m.handlePacking, nil
case PreCommit1: case PreCommit1:

View File

@ -1,10 +1,12 @@
package sealing package sealing
import ( import (
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-storage/storage"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"golang.org/x/xerrors" "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 { type mutator interface {
@ -151,11 +153,13 @@ func (evt SectorChainPreCommitFailed) FormatError(xerrors.Printer) (next error)
func (evt SectorChainPreCommitFailed) apply(*SectorInfo) {} func (evt SectorChainPreCommitFailed) apply(*SectorInfo) {}
type SectorPreCommitted struct { type SectorPreCommitted struct {
Message cid.Cid Message cid.Cid
PreCommitInfo miner.SectorPreCommitInfo
} }
func (evt SectorPreCommitted) apply(state *SectorInfo) { func (evt SectorPreCommitted) apply(state *SectorInfo) {
state.PreCommitMessage = &evt.Message state.PreCommitMessage = &evt.Message
state.PreCommitInfo = &evt.PreCommitInfo
} }
type SectorSeedReady struct { type SectorSeedReady struct {

2
go.mod
View File

@ -10,7 +10,7 @@ require (
github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663 // indirect 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/go-statemachine v0.0.0-20200226041606-2074af6d51d9
github.com/filecoin-project/sector-storage v0.0.0-20200625154333-98ef8e4ef246 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/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea
github.com/ipfs/go-cid v0.0.5 github.com/ipfs/go-cid v0.0.5
github.com/ipfs/go-datastore v0.4.4 github.com/ipfs/go-datastore v0.4.4

2
go.sum
View File

@ -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.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 h1:IepUsmDGY60QliENVTkBTAkwqGWw9kNbbHOcU/9oiC0=
github.com/filecoin-project/specs-actors v0.6.0/go.mod h1:dRdy3cURykh2R8O/DKqy8olScl70rmIS7GrB4hB1IDY= 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 h1:iixjULRQFPn7Q9KlIqfwLJnlAXO10bbkI+xy5GKGdLY=
github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k= 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= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=

View File

@ -34,7 +34,7 @@ type SealingAPI interface {
StateMinerSectorSize(context.Context, address.Address, TipSetToken) (abi.SectorSize, error) StateMinerSectorSize(context.Context, address.Address, TipSetToken) (abi.SectorSize, error)
StateMinerWorkerAddress(ctx context.Context, maddr address.Address, tok TipSetToken) (address.Address, 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) 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) 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) 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) ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error)

View File

@ -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)}) return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("could not serialize pre-commit sector parameters: %w", err)})
} }
log.Info("submitting precommit for sector: ", sector.SectorNumber) collateral, err := m.api.StateMinerInitialPledgeCollateral(ctx.Context(), m.maddr, *params, tok)
mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.PreCommitSector, big.NewInt(0), big.NewInt(1), 1000000, enc.Bytes()) 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 { if err != nil {
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)}) 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 { 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 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 { if err != nil {
return xerrors.Errorf("getting initial pledge collateral: %w", err) 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 // 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()) mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.ProveCommitSector, collateral, big.NewInt(1), 1000000, enc.Bytes())
if err != nil { if err != nil {

View File

@ -8,6 +8,7 @@ import (
sectorstorage "github.com/filecoin-project/sector-storage" sectorstorage "github.com/filecoin-project/sector-storage"
"github.com/filecoin-project/specs-actors/actors/abi" "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-actors/actors/runtime/exitcode"
"github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/specs-storage/storage"
) )
@ -67,6 +68,7 @@ type SectorInfo struct {
CommR *cid.Cid CommR *cid.Cid
Proof []byte Proof []byte
PreCommitInfo *miner.SectorPreCommitInfo
PreCommitMessage *cid.Cid PreCommitMessage *cid.Cid
PreCommitTipSet TipSetToken PreCommitTipSet TipSetToken