Fix precommit deposit math
This commit is contained in:
parent
3030e3a74f
commit
495b4ba841
28
cbor_gen.go
28
cbor_gen.go
@ -383,7 +383,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
|
||||
_, err := w.Write(cbg.CborNull)
|
||||
return err
|
||||
}
|
||||
if _, err := w.Write([]byte{181}); err != nil {
|
||||
if _, err := w.Write([]byte{182}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -624,6 +624,22 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.PreCommitDeposit (big.Int) (struct)
|
||||
if len("PreCommitDeposit") > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field \"PreCommitDeposit\" was too long")
|
||||
}
|
||||
|
||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("PreCommitDeposit")))); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := w.Write([]byte("PreCommitDeposit")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := t.PreCommitDeposit.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")
|
||||
@ -1103,6 +1119,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// t.PreCommitDeposit (big.Int) (struct)
|
||||
case "PreCommitDeposit":
|
||||
|
||||
{
|
||||
|
||||
if err := t.PreCommitDeposit.UnmarshalCBOR(br); err != nil {
|
||||
return xerrors.Errorf("unmarshaling t.PreCommitDeposit: %w", err)
|
||||
}
|
||||
|
||||
}
|
||||
// t.PreCommitMessage (cid.Cid) (struct)
|
||||
case "PreCommitMessage":
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||
"github.com/filecoin-project/specs-storage/storage"
|
||||
)
|
||||
@ -154,11 +155,13 @@ func (evt SectorChainPreCommitFailed) apply(*SectorInfo)
|
||||
|
||||
type SectorPreCommitted struct {
|
||||
Message cid.Cid
|
||||
PreCommitDeposit big.Int
|
||||
PreCommitInfo miner.SectorPreCommitInfo
|
||||
}
|
||||
|
||||
func (evt SectorPreCommitted) apply(state *SectorInfo) {
|
||||
state.PreCommitMessage = &evt.Message
|
||||
state.PreCommitDeposit = evt.PreCommitDeposit
|
||||
state.PreCommitInfo = &evt.PreCommitInfo
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,8 @@ func New(api SealingAPI, events Events, maddr address.Address, ds datastore.Batc
|
||||
verif: verif,
|
||||
unsealedInfos: make(map[abi.SectorNumber]UnsealedSectorInfo),
|
||||
pcp: pcp,
|
||||
|
||||
toUpgrade: map[abi.SectorNumber]struct{}{},
|
||||
}
|
||||
|
||||
s.sectors = statemachine.New(namespace.Wrap(ds, datastore.NewKey(SectorStorePrefix)), s, SectorInfo{})
|
||||
|
@ -169,11 +169,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
||||
DealIDs: sector.dealIDs(),
|
||||
}
|
||||
|
||||
replace := m.maybeUpgradableSector()
|
||||
if replace != nil {
|
||||
params.ReplaceCapacity = true
|
||||
params.ReplaceSector = *replace
|
||||
}
|
||||
depositMinimum := m.tryUpgradeSector(params)
|
||||
|
||||
enc := new(bytes.Buffer)
|
||||
if err := params.MarshalCBOR(enc); err != nil {
|
||||
@ -185,13 +181,15 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
||||
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())
|
||||
deposit := big.Max(depositMinimum, collateral)
|
||||
|
||||
log.Infof("submitting precommit for sector (deposit: %s): ", sector.SectorNumber, deposit)
|
||||
mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.PreCommitSector, deposit, 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, PreCommitInfo: *params})
|
||||
return ctx.Send(SectorPreCommitted{Message: mcid, PreCommitDeposit: deposit, PreCommitInfo: *params})
|
||||
}
|
||||
|
||||
func (m *Sealing) handlePreCommitWait(ctx statemachine.Context, sector SectorInfo) error {
|
||||
|
2
types.go
2
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/abi/big"
|
||||
"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"
|
||||
@ -69,6 +70,7 @@ type SectorInfo struct {
|
||||
Proof []byte
|
||||
|
||||
PreCommitInfo *miner.SectorPreCommitInfo
|
||||
PreCommitDeposit big.Int
|
||||
PreCommitMessage *cid.Cid
|
||||
PreCommitTipSet TipSetToken
|
||||
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||
)
|
||||
|
||||
func (m *Sealing) MarkForUpgrade(id abi.SectorNumber) error {
|
||||
@ -39,6 +41,29 @@ func (m *Sealing) MarkForUpgrade(id abi.SectorNumber) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Sealing) tryUpgradeSector(params *miner.SectorPreCommitInfo) big.Int {
|
||||
replace := m.maybeUpgradableSector()
|
||||
if replace != nil {
|
||||
params.ReplaceCapacity = true
|
||||
params.ReplaceSector = *replace
|
||||
|
||||
ri, err := m.GetSectorInfo(*replace)
|
||||
if err != nil {
|
||||
log.Errorf("error calling GetSectorInfo for replaced sector: %+v", err)
|
||||
return big.Zero()
|
||||
}
|
||||
|
||||
if params.Expiration < ri.PreCommitInfo.Expiration {
|
||||
// TODO: Some limit on this
|
||||
params.Expiration = ri.PreCommitInfo.Expiration
|
||||
}
|
||||
|
||||
return ri.PreCommitDeposit
|
||||
}
|
||||
|
||||
return big.Zero()
|
||||
}
|
||||
|
||||
func (m *Sealing) maybeUpgradableSector() *abi.SectorNumber {
|
||||
m.upgradeLk.Lock()
|
||||
defer m.upgradeLk.Unlock()
|
||||
|
Loading…
Reference in New Issue
Block a user