Merge pull request #32 from filecoin-project/feat/cc-upgrade
CC upgrade
This commit is contained in:
commit
171e0d0e4b
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"
|
||||
)
|
||||
@ -153,12 +154,14 @@ func (evt SectorChainPreCommitFailed) FormatError(xerrors.Printer) (next error)
|
||||
func (evt SectorChainPreCommitFailed) apply(*SectorInfo) {}
|
||||
|
||||
type SectorPreCommitted struct {
|
||||
Message cid.Cid
|
||||
PreCommitInfo miner.SectorPreCommitInfo
|
||||
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
|
||||
}
|
||||
|
||||
|
2
go.mod
2
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.7.0
|
||||
github.com/filecoin-project/specs-actors v0.7.1
|
||||
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
|
||||
|
4
go.sum
4
go.sum
@ -62,8 +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-actors v0.7.1 h1:/zW++MN4gGIPvG+s0zmSI97k0Z/aaeiREjLC10gQbco=
|
||||
github.com/filecoin-project/specs-actors v0.7.1/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=
|
||||
|
@ -3,6 +3,7 @@ package sealing
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-datastore"
|
||||
@ -55,6 +56,9 @@ type Sealing struct {
|
||||
|
||||
unsealedInfos map[abi.SectorNumber]UnsealedSectorInfo
|
||||
pcp PreCommitPolicy
|
||||
|
||||
upgradeLk sync.Mutex
|
||||
toUpgrade map[abi.SectorNumber]struct{}
|
||||
}
|
||||
|
||||
type UnsealedSectorInfo struct {
|
||||
@ -74,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,6 +169,8 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
||||
DealIDs: sector.dealIDs(),
|
||||
}
|
||||
|
||||
depositMinimum := m.tryUpgradeSector(params)
|
||||
|
||||
enc := new(bytes.Buffer)
|
||||
if err := params.MarshalCBOR(enc); err != nil {
|
||||
return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("could not serialize pre-commit sector parameters: %w", err)})
|
||||
@ -179,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
|
||||
|
||||
|
82
upgrade_queue.go
Normal file
82
upgrade_queue.go
Normal file
@ -0,0 +1,82 @@
|
||||
package sealing
|
||||
|
||||
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 {
|
||||
m.upgradeLk.Lock()
|
||||
defer m.upgradeLk.Unlock()
|
||||
|
||||
_, found := m.toUpgrade[id]
|
||||
if found {
|
||||
return xerrors.Errorf("sector %d already marked for upgrade", id)
|
||||
}
|
||||
|
||||
si, err := m.GetSectorInfo(id)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("getting sector info: %w", err)
|
||||
}
|
||||
|
||||
if si.State != Proving {
|
||||
return xerrors.Errorf("can't mark sectors not in the 'Proving' state for upgrade")
|
||||
}
|
||||
|
||||
if len(si.Pieces) != 1 {
|
||||
return xerrors.Errorf("not a committed-capacity sector, expected 1 piece")
|
||||
}
|
||||
|
||||
if si.Pieces[0].DealInfo != nil {
|
||||
return xerrors.Errorf("not a committed-capacity sector, has deals")
|
||||
}
|
||||
|
||||
// TODO: more checks to match actor constraints
|
||||
|
||||
m.toUpgrade[id] = struct{}{}
|
||||
|
||||
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()
|
||||
for number := range m.toUpgrade {
|
||||
// TODO: checks to match actor constraints
|
||||
|
||||
// this one looks good
|
||||
/*if checks */
|
||||
{
|
||||
delete(m.toUpgrade, number)
|
||||
return &number
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user