Set precommit deposit correctly

This commit is contained in:
Łukasz Magiera 2020-06-26 17:58:29 +02:00
parent 9aec1e9484
commit 408c9a7b33
5 changed files with 72 additions and 9 deletions

View File

@ -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":

View File

@ -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 {

View File

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

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

View File

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