Merge pull request #1223 from filecoin-project/fix/squash-forks
squash forks and use correct amt library everywhere
This commit is contained in:
commit
72c89ab89b
@ -1,3 +1,5 @@
|
|||||||
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
||||||
|
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -9,8 +11,6 @@ import (
|
|||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
var _ = xerrors.Errorf
|
var _ = xerrors.Errorf
|
||||||
|
|
||||||
func (t *PaymentInfo) MarshalCBOR(w io.Writer) error {
|
func (t *PaymentInfo) MarshalCBOR(w io.Writer) error {
|
||||||
|
@ -1,9 +1 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
const ForkBlizzardHeight = 6288
|
|
||||||
|
|
||||||
const ForkFrigidHeight = 7950
|
|
||||||
|
|
||||||
const ForkBootyBayHeight = 11000
|
|
||||||
|
|
||||||
const ForkMissingSnowballs = 34000
|
|
||||||
|
@ -7,23 +7,49 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
|
amt2 "github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-sectorbuilder"
|
"github.com/filecoin-project/go-sectorbuilder"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-amt-ipld"
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StorageMinerActor struct{}
|
type StorageMinerActor struct{}
|
||||||
|
|
||||||
|
func (sma StorageMinerActor) Exports() []interface{} {
|
||||||
|
return []interface{}{
|
||||||
|
1: sma.StorageMinerConstructor,
|
||||||
|
2: sma.PreCommitSector,
|
||||||
|
3: sma.ProveCommitSector,
|
||||||
|
4: sma.SubmitFallbackPoSt,
|
||||||
|
//5: sma.SlashStorageFault,
|
||||||
|
//6: sma.GetCurrentProvingSet,
|
||||||
|
//7: sma.ArbitrateDeal,
|
||||||
|
//8: sma.DePledge,
|
||||||
|
9: sma.GetOwner,
|
||||||
|
10: sma.GetWorkerAddr,
|
||||||
|
11: sma.GetPower,
|
||||||
|
12: sma.GetPeerID,
|
||||||
|
13: sma.GetSectorSize,
|
||||||
|
14: sma.UpdatePeerID,
|
||||||
|
//15: sma.ChangeWorker,
|
||||||
|
16: sma.IsSlashed,
|
||||||
|
17: sma.CheckMiner,
|
||||||
|
18: sma.DeclareFaults,
|
||||||
|
19: sma.SlashConsensusFault,
|
||||||
|
20: sma.SubmitElectionPoSt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type StorageMinerActorState struct {
|
type StorageMinerActorState struct {
|
||||||
// PreCommittedSectors is the set of sectors that have been committed to but not
|
// PreCommittedSectors is the set of sectors that have been committed to but not
|
||||||
// yet had their proofs submitted
|
// yet had their proofs submitted
|
||||||
@ -133,50 +159,6 @@ type maMethods struct {
|
|||||||
|
|
||||||
var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
|
var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
|
||||||
|
|
||||||
func (sma StorageMinerActor) Exports() []interface{} {
|
|
||||||
return []interface{}{
|
|
||||||
1: sma.StorageMinerConstructor,
|
|
||||||
2: sma.PreCommitSector,
|
|
||||||
3: sma.ProveCommitSector,
|
|
||||||
4: sma.SubmitFallbackPoSt,
|
|
||||||
//5: sma.SlashStorageFault,
|
|
||||||
//6: sma.GetCurrentProvingSet,
|
|
||||||
//7: sma.ArbitrateDeal,
|
|
||||||
//8: sma.DePledge,
|
|
||||||
9: sma.GetOwner,
|
|
||||||
10: sma.GetWorkerAddr,
|
|
||||||
11: sma.GetPower, // TODO: Remove
|
|
||||||
12: sma.GetPeerID,
|
|
||||||
13: sma.GetSectorSize,
|
|
||||||
14: sma.UpdatePeerID,
|
|
||||||
//15: sma.ChangeWorker,
|
|
||||||
16: sma.IsSlashed,
|
|
||||||
17: sma.CheckMiner,
|
|
||||||
18: sma.DeclareFaults,
|
|
||||||
19: sma.SlashConsensusFault,
|
|
||||||
20: sma.SubmitElectionPoSt,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadState(vmctx types.VMContext) (cid.Cid, *StorageMinerActorState, ActorError) {
|
|
||||||
var self StorageMinerActorState
|
|
||||||
oldstate := vmctx.Storage().GetHead()
|
|
||||||
if err := vmctx.Storage().Get(oldstate, &self); err != nil {
|
|
||||||
return cid.Undef, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return oldstate, &self, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadMinerInfo(vmctx types.VMContext, m *StorageMinerActorState) (*MinerInfo, ActorError) {
|
|
||||||
var mi MinerInfo
|
|
||||||
if err := vmctx.Storage().Get(m.Info, &mi); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &mi, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) ([]byte, ActorError) {
|
func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) ([]byte, ActorError) {
|
||||||
minerInfo := &MinerInfo{
|
minerInfo := &MinerInfo{
|
||||||
Owner: params.Owner,
|
Owner: params.Owner,
|
||||||
@ -191,8 +173,8 @@ func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
var self StorageMinerActorState
|
var self StorageMinerActorState
|
||||||
sectors := amt.NewAMT(types.WrapStorage(vmctx.Storage()))
|
sectors := amt2.NewAMT(vmctx.Ipld())
|
||||||
scid, serr := sectors.Flush()
|
scid, serr := sectors.Flush(context.TODO())
|
||||||
if serr != nil {
|
if serr != nil {
|
||||||
return nil, aerrors.HandleExternalError(serr, "initializing AMT")
|
return nil, aerrors.HandleExternalError(serr, "initializing AMT")
|
||||||
}
|
}
|
||||||
@ -215,6 +197,7 @@ func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMContext, params *SectorPreCommitInfo) ([]byte, ActorError) {
|
func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMContext, params *SectorPreCommitInfo) ([]byte, ActorError) {
|
||||||
|
|
||||||
ctx := vmctx.Context()
|
ctx := vmctx.Context()
|
||||||
oldstate, self, err := loadState(vmctx)
|
oldstate, self, err := loadState(vmctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -239,7 +222,7 @@ func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make sure the miner isnt trying to submit a pre-existing sector
|
// make sure the miner isnt trying to submit a pre-existing sector
|
||||||
unique, err := SectorIsUnique(ctx, vmctx.Storage(), self.Sectors, params.SectorNumber)
|
unique, err := SectorIsUnique(ctx, vmctx.Ipld(), self.Sectors, params.SectorNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -276,18 +259,6 @@ func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMCon
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func uintToStringKey(i uint64) string {
|
|
||||||
buf := make([]byte, 10)
|
|
||||||
n := binary.PutUvarint(buf, i)
|
|
||||||
return string(buf[:n])
|
|
||||||
}
|
|
||||||
|
|
||||||
type SectorProveCommitInfo struct {
|
|
||||||
Proof []byte
|
|
||||||
SectorID uint64
|
|
||||||
DealIDs []uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMContext, params *SectorProveCommitInfo) ([]byte, ActorError) {
|
func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMContext, params *SectorProveCommitInfo) ([]byte, ActorError) {
|
||||||
ctx := vmctx.Context()
|
ctx := vmctx.Context()
|
||||||
oldstate, self, err := loadState(vmctx)
|
oldstate, self, err := loadState(vmctx)
|
||||||
@ -358,7 +329,7 @@ func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMC
|
|||||||
// Note: There must exist a unique index in the miner's sector set for each
|
// Note: There must exist a unique index in the miner's sector set for each
|
||||||
// sector ID. The `faults`, `recovered`, and `done` parameters of the
|
// sector ID. The `faults`, `recovered`, and `done` parameters of the
|
||||||
// SubmitPoSt method express indices into this sector set.
|
// SubmitPoSt method express indices into this sector set.
|
||||||
nssroot, err := AddToSectorSet(ctx, types.WrapStorage(vmctx.Storage()), self.Sectors, params.SectorID, us.Info.CommR, commD)
|
nssroot, err := AddToSectorSet2(ctx, vmctx.Ipld(), self.Sectors, params.SectorID, us.Info.CommR, commD)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -372,7 +343,7 @@ func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMC
|
|||||||
//
|
//
|
||||||
// Note: Proving period is a function of sector size; small sectors take less
|
// Note: Proving period is a function of sector size; small sectors take less
|
||||||
// time to prove than large sectors do. Sector size is selected when pledging.
|
// time to prove than large sectors do. Sector size is selected when pledging.
|
||||||
pss, lerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
|
pss, lerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.ProvingSet)
|
||||||
if lerr != nil {
|
if lerr != nil {
|
||||||
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
||||||
}
|
}
|
||||||
@ -403,19 +374,6 @@ func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMC
|
|||||||
return nil, aerrors.Wrapf(err, "calling ActivateStorageDeals failed")
|
return nil, aerrors.Wrapf(err, "calling ActivateStorageDeals failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func truncateHexPrint(b []byte) string {
|
|
||||||
s := fmt.Sprintf("%x", b)
|
|
||||||
if len(s) > 60 {
|
|
||||||
return s[:20] + "..." + s[len(s)-20:]
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubmitFallbackPoStParams struct {
|
|
||||||
Proof []byte
|
|
||||||
Candidates []types.EPostTicket
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VMContext, params *SubmitFallbackPoStParams) ([]byte, ActorError) {
|
func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VMContext, params *SubmitFallbackPoStParams) ([]byte, ActorError) {
|
||||||
oldstate, self, err := loadState(vmctx)
|
oldstate, self, err := loadState(vmctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -467,12 +425,12 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM
|
|||||||
copy(seed[:], rand)
|
copy(seed[:], rand)
|
||||||
}
|
}
|
||||||
|
|
||||||
pss, lerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
|
pss, lerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.ProvingSet)
|
||||||
if lerr != nil {
|
if lerr != nil {
|
||||||
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
||||||
}
|
}
|
||||||
|
|
||||||
ss, lerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.Sectors)
|
ss, lerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.Sectors)
|
||||||
if lerr != nil {
|
if lerr != nil {
|
||||||
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
||||||
}
|
}
|
||||||
@ -484,7 +442,7 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM
|
|||||||
|
|
||||||
activeFaults := uint64(0)
|
activeFaults := uint64(0)
|
||||||
var sectorInfos []ffi.PublicSectorInfo
|
var sectorInfos []ffi.PublicSectorInfo
|
||||||
if err := pss.ForEach(func(id uint64, v *cbg.Deferred) error {
|
if err := pss.ForEach(vmctx.Context(), func(id uint64, v *cbg.Deferred) error {
|
||||||
if faults[id] {
|
if faults[id] {
|
||||||
activeFaults++
|
activeFaults++
|
||||||
return nil
|
return nil
|
||||||
@ -535,7 +493,7 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Post submission is successful!
|
// Post submission is successful!
|
||||||
if err := onSuccessfulPoSt(self, vmctx, activeFaults); err != nil {
|
if err := onSuccessfulPoSt2(self, vmctx, activeFaults); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,11 +514,16 @@ func (sma StorageMinerActor) GetPower(act *types.Actor, vmctx types.VMContext, p
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.SlashedAt != 0 {
|
||||||
|
return types.NewInt(0).Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
return self.Power.Bytes(), nil
|
return self.Power.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SectorIsUnique(ctx context.Context, s types.Storage, sroot cid.Cid, sid uint64) (bool, ActorError) {
|
func SectorIsUnique2(ctx context.Context, s cbor.IpldStore, sroot cid.Cid, sid uint64) (bool, ActorError) {
|
||||||
found, _, _, err := GetFromSectorSet(ctx, s, sroot, sid)
|
found, _, _, err := GetFromSectorSet2(ctx, s, sroot, sid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -568,22 +531,22 @@ func SectorIsUnique(ctx context.Context, s types.Storage, sroot cid.Cid, sid uin
|
|||||||
return !found, nil
|
return !found, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddToSectorSet(ctx context.Context, blks amt.Blocks, ss cid.Cid, sectorID uint64, commR, commD []byte) (cid.Cid, ActorError) {
|
func AddToSectorSet2(ctx context.Context, blks cbor.IpldStore, ss cid.Cid, sectorID uint64, commR, commD []byte) (cid.Cid, ActorError) {
|
||||||
if sectorID >= build.MinerMaxSectors {
|
if sectorID >= build.MinerMaxSectors {
|
||||||
return cid.Undef, aerrors.Newf(25, "sector ID out of range: %d", sectorID)
|
return cid.Undef, aerrors.Newf(25, "sector ID out of range: %d", sectorID)
|
||||||
}
|
}
|
||||||
ssr, err := amt.LoadAMT(blks, ss)
|
ssr, err := amt2.LoadAMT(ctx, blks, ss)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node")
|
return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Spec says to use SealCommitment, and construct commD from deals each time,
|
// TODO: Spec says to use SealCommitment, and construct commD from deals each time,
|
||||||
// but that would make SubmitPoSt way, way more expensive
|
// but that would make SubmitPoSt way, way more expensive
|
||||||
if err := ssr.Set(sectorID, [][]byte{commR, commD}); err != nil {
|
if err := ssr.Set(ctx, sectorID, [][]byte{commR, commD}); err != nil {
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "failed to set commitment in sector set")
|
return cid.Undef, aerrors.HandleExternalError(err, "failed to set commitment in sector set")
|
||||||
}
|
}
|
||||||
|
|
||||||
ncid, err := ssr.Flush()
|
ncid, err := ssr.Flush(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set")
|
return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set")
|
||||||
}
|
}
|
||||||
@ -591,20 +554,20 @@ func AddToSectorSet(ctx context.Context, blks amt.Blocks, ss cid.Cid, sectorID u
|
|||||||
return ncid, nil
|
return ncid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFromSectorSet(ctx context.Context, s types.Storage, ss cid.Cid, sectorID uint64) (bool, []byte, []byte, ActorError) {
|
func GetFromSectorSet2(ctx context.Context, cst cbor.IpldStore, ss cid.Cid, sectorID uint64) (bool, []byte, []byte, ActorError) {
|
||||||
if sectorID >= build.MinerMaxSectors {
|
if sectorID >= build.MinerMaxSectors {
|
||||||
return false, nil, nil, aerrors.Newf(25, "sector ID out of range: %d", sectorID)
|
return false, nil, nil, aerrors.Newf(25, "sector ID out of range: %d", sectorID)
|
||||||
}
|
}
|
||||||
|
|
||||||
ssr, err := amt.LoadAMT(types.WrapStorage(s), ss)
|
ssr, err := amt2.LoadAMT(ctx, cst, ss)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil, nil, aerrors.HandleExternalError(err, "could not load sector set node")
|
return false, nil, nil, aerrors.HandleExternalError(err, "could not load sector set node")
|
||||||
}
|
}
|
||||||
|
|
||||||
var comms [][]byte
|
var comms [][]byte
|
||||||
err = ssr.Get(sectorID, &comms)
|
err = ssr.Get(ctx, sectorID, &comms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(*amt.ErrNotFound); ok {
|
if _, ok := err.(*amt2.ErrNotFound); ok {
|
||||||
return false, nil, nil, nil
|
return false, nil, nil, nil
|
||||||
}
|
}
|
||||||
return false, nil, nil, aerrors.HandleExternalError(err, "failed to find sector in sector set")
|
return false, nil, nil, aerrors.HandleExternalError(err, "failed to find sector in sector set")
|
||||||
@ -617,20 +580,20 @@ func GetFromSectorSet(ctx context.Context, s types.Storage, ss cid.Cid, sectorID
|
|||||||
return true, comms[0], comms[1], nil
|
return true, comms[0], comms[1], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveFromSectorSet(ctx context.Context, s types.Storage, ss cid.Cid, ids []uint64) (cid.Cid, aerrors.ActorError) {
|
func RemoveFromSectorSet2(ctx context.Context, cst cbor.IpldStore, ss cid.Cid, ids []uint64) (cid.Cid, aerrors.ActorError) {
|
||||||
|
|
||||||
ssr, err := amt.LoadAMT(types.WrapStorage(s), ss)
|
ssr, err := amt2.LoadAMT(ctx, cst, ss)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node")
|
return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
if err := ssr.Delete(id); err != nil {
|
if err := ssr.Delete(ctx, id); err != nil {
|
||||||
log.Warnf("failed to delete sector %d from set: %s", id, err)
|
log.Warnf("failed to delete sector %d from set: %s", id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ncid, err := ssr.Flush()
|
ncid, err := ssr.Flush(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set")
|
return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set")
|
||||||
}
|
}
|
||||||
@ -638,19 +601,6 @@ func RemoveFromSectorSet(ctx context.Context, s types.Storage, ss cid.Cid, ids [
|
|||||||
return ncid, nil
|
return ncid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CollateralForPower(power types.BigInt) types.BigInt {
|
|
||||||
return types.BigMul(power, types.NewInt(10))
|
|
||||||
/* TODO: this
|
|
||||||
availableFil = FakeGlobalMethods.GetAvailableFil()
|
|
||||||
totalNetworkPower = StorageMinerActor.GetTotalStorage()
|
|
||||||
numMiners = StorageMarket.GetMinerCount()
|
|
||||||
powerCollateral = availableFil * NetworkConstants.POWER_COLLATERAL_PROPORTION * power / totalNetworkPower
|
|
||||||
perCapitaCollateral = availableFil * NetworkConstants.PER_CAPITA_COLLATERAL_PROPORTION / numMiners
|
|
||||||
collateralRequired = math.Ceil(minerPowerCollateral + minerPerCapitaCollateral)
|
|
||||||
return collateralRequired
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor) GetWorkerAddr(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
func (sma StorageMinerActor) GetWorkerAddr(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
||||||
_, self, err := loadState(vmctx)
|
_, self, err := loadState(vmctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -693,10 +643,6 @@ func (sma StorageMinerActor) GetPeerID(act *types.Actor, vmctx types.VMContext,
|
|||||||
return []byte(mi.PeerID), nil
|
return []byte(mi.PeerID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdatePeerIDParams struct {
|
|
||||||
PeerID peer.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor) UpdatePeerID(act *types.Actor, vmctx types.VMContext, params *UpdatePeerIDParams) ([]byte, ActorError) {
|
func (sma StorageMinerActor) UpdatePeerID(act *types.Actor, vmctx types.VMContext, params *UpdatePeerIDParams) ([]byte, ActorError) {
|
||||||
oldstate, self, err := loadState(vmctx)
|
oldstate, self, err := loadState(vmctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -747,10 +693,6 @@ func (sma StorageMinerActor) GetSectorSize(act *types.Actor, vmctx types.VMConte
|
|||||||
return types.NewInt(mi.SectorSize).Bytes(), nil
|
return types.NewInt(mi.SectorSize).Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isLate(height uint64, self *StorageMinerActorState) bool {
|
|
||||||
return self.ElectionPeriodStart > 0 && height >= self.ElectionPeriodStart+build.SlashablePowerDelay
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor) IsSlashed(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
func (sma StorageMinerActor) IsSlashed(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
||||||
_, self, err := loadState(vmctx)
|
_, self, err := loadState(vmctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -760,10 +702,6 @@ func (sma StorageMinerActor) IsSlashed(act *types.Actor, vmctx types.VMContext,
|
|||||||
return cbg.EncodeBool(self.SlashedAt != 0), nil
|
return cbg.EncodeBool(self.SlashedAt != 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type CheckMinerParams struct {
|
|
||||||
NetworkPower types.BigInt
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: better name
|
// TODO: better name
|
||||||
func (sma StorageMinerActor) CheckMiner(act *types.Actor, vmctx types.VMContext, params *CheckMinerParams) ([]byte, ActorError) {
|
func (sma StorageMinerActor) CheckMiner(act *types.Actor, vmctx types.VMContext, params *CheckMinerParams) ([]byte, ActorError) {
|
||||||
if vmctx.Message().From != StoragePowerAddress {
|
if vmctx.Message().From != StoragePowerAddress {
|
||||||
@ -795,6 +733,8 @@ func (sma StorageMinerActor) CheckMiner(act *types.Actor, vmctx types.VMContext,
|
|||||||
// Slash for being late
|
// Slash for being late
|
||||||
|
|
||||||
self.SlashedAt = vmctx.BlockHeight()
|
self.SlashedAt = vmctx.BlockHeight()
|
||||||
|
oldPower := self.Power
|
||||||
|
self.Power = types.NewInt(0)
|
||||||
|
|
||||||
nstate, err := vmctx.Storage().Put(self)
|
nstate, err := vmctx.Storage().Put(self)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -805,16 +745,12 @@ func (sma StorageMinerActor) CheckMiner(act *types.Actor, vmctx types.VMContext,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
if err := self.Power.MarshalCBOR(&out); err != nil {
|
if err := oldPower.MarshalCBOR(&out); err != nil {
|
||||||
return nil, aerrors.HandleExternalError(err, "marshaling return value")
|
return nil, aerrors.HandleExternalError(err, "marshaling return value")
|
||||||
}
|
}
|
||||||
return out.Bytes(), nil
|
return out.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeclareFaultsParams struct {
|
|
||||||
Faults types.BitField
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor) DeclareFaults(act *types.Actor, vmctx types.VMContext, params *DeclareFaultsParams) ([]byte, ActorError) {
|
func (sma StorageMinerActor) DeclareFaults(act *types.Actor, vmctx types.VMContext, params *DeclareFaultsParams) ([]byte, ActorError) {
|
||||||
oldstate, self, aerr := loadState(vmctx)
|
oldstate, self, aerr := loadState(vmctx)
|
||||||
if aerr != nil {
|
if aerr != nil {
|
||||||
@ -835,7 +771,7 @@ func (sma StorageMinerActor) DeclareFaults(act *types.Actor, vmctx types.VMConte
|
|||||||
return nil, aerrors.Absorb(err, 1, "failed to merge bitfields")
|
return nil, aerrors.Absorb(err, 1, "failed to merge bitfields")
|
||||||
}
|
}
|
||||||
|
|
||||||
ss, nerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.Sectors)
|
ss, nerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.Sectors)
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
return nil, aerrors.HandleExternalError(nerr, "failed to load sector set")
|
return nil, aerrors.HandleExternalError(nerr, "failed to load sector set")
|
||||||
}
|
}
|
||||||
@ -864,12 +800,6 @@ func (sma StorageMinerActor) DeclareFaults(act *types.Actor, vmctx types.VMConte
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type MinerSlashConsensusFault struct {
|
|
||||||
Slasher address.Address
|
|
||||||
AtHeight uint64
|
|
||||||
SlashedCollateral types.BigInt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor) SlashConsensusFault(act *types.Actor, vmctx types.VMContext, params *MinerSlashConsensusFault) ([]byte, ActorError) {
|
func (sma StorageMinerActor) SlashConsensusFault(act *types.Actor, vmctx types.VMContext, params *MinerSlashConsensusFault) ([]byte, ActorError) {
|
||||||
if vmctx.Message().From != StoragePowerAddress {
|
if vmctx.Message().From != StoragePowerAddress {
|
||||||
return nil, aerrors.New(1, "SlashConsensusFault may only be called by the storage market actor")
|
return nil, aerrors.New(1, "SlashConsensusFault may only be called by the storage market actor")
|
||||||
@ -900,6 +830,21 @@ func (sma StorageMinerActor) SlashConsensusFault(act *types.Actor, vmctx types.V
|
|||||||
return nil, aerrors.Wrap(err, "failed to burn funds")
|
return nil, aerrors.Wrap(err, "failed to burn funds")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldstate, self, err := loadState(vmctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, aerrors.Wrap(err, "failed to load state for slashing")
|
||||||
|
}
|
||||||
|
|
||||||
|
self.Power = types.NewInt(0)
|
||||||
|
|
||||||
|
ncid, err := vmctx.Storage().Put(self)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := vmctx.Storage().Commit(oldstate, ncid); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: this still allows the miner to commit sectors and submit posts,
|
// TODO: this still allows the miner to commit sectors and submit posts,
|
||||||
// their users could potentially be unaffected, but the miner will never be
|
// their users could potentially be unaffected, but the miner will never be
|
||||||
// able to mine a block again
|
// able to mine a block again
|
||||||
@ -911,6 +856,8 @@ func (sma StorageMinerActor) SlashConsensusFault(act *types.Actor, vmctx types.V
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sma StorageMinerActor) SubmitElectionPoSt(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) {
|
func (sma StorageMinerActor) SubmitElectionPoSt(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) {
|
||||||
|
ctx := vmctx.Context()
|
||||||
|
|
||||||
if vmctx.Message().From != NetworkAddress {
|
if vmctx.Message().From != NetworkAddress {
|
||||||
return nil, aerrors.Newf(1, "submit election post can only be called by the storage power actor")
|
return nil, aerrors.Newf(1, "submit election post can only be called by the storage power actor")
|
||||||
}
|
}
|
||||||
@ -924,12 +871,12 @@ func (sma StorageMinerActor) SubmitElectionPoSt(act *types.Actor, vmctx types.VM
|
|||||||
return nil, aerrors.New(1, "slashed miners can't perform election PoSt")
|
return nil, aerrors.New(1, "slashed miners can't perform election PoSt")
|
||||||
}
|
}
|
||||||
|
|
||||||
pss, nerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
|
pss, nerr := amt2.LoadAMT(ctx, vmctx.Ipld(), self.ProvingSet)
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
return nil, aerrors.HandleExternalError(nerr, "failed to load proving set")
|
return nil, aerrors.HandleExternalError(nerr, "failed to load proving set")
|
||||||
}
|
}
|
||||||
|
|
||||||
ss, nerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.Sectors)
|
ss, nerr := amt2.LoadAMT(ctx, vmctx.Ipld(), self.Sectors)
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
return nil, aerrors.HandleExternalError(nerr, "failed to load proving set")
|
return nil, aerrors.HandleExternalError(nerr, "failed to load proving set")
|
||||||
}
|
}
|
||||||
@ -941,14 +888,14 @@ func (sma StorageMinerActor) SubmitElectionPoSt(act *types.Actor, vmctx types.VM
|
|||||||
|
|
||||||
activeFaults := uint64(0)
|
activeFaults := uint64(0)
|
||||||
for f := range faults {
|
for f := range faults {
|
||||||
if f > amt.MaxIndex {
|
if f > amt2.MaxIndex {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var comms [][]byte
|
var comms [][]byte
|
||||||
err := pss.Get(f, &comms)
|
err := pss.Get(ctx, f, &comms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var notfound *amt.ErrNotFound
|
var notfound *amt2.ErrNotFound
|
||||||
if !xerrors.As(err, ¬found) {
|
if !xerrors.As(err, ¬found) {
|
||||||
return nil, aerrors.HandleExternalError(err, "failed to find sector in sector set")
|
return nil, aerrors.HandleExternalError(err, "failed to find sector in sector set")
|
||||||
}
|
}
|
||||||
@ -958,7 +905,7 @@ func (sma StorageMinerActor) SubmitElectionPoSt(act *types.Actor, vmctx types.VM
|
|||||||
activeFaults++
|
activeFaults++
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := onSuccessfulPoSt(self, vmctx, activeFaults); err != nil { // TODO
|
if err := onSuccessfulPoSt2(self, vmctx, activeFaults); err != nil { // TODO
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -973,20 +920,20 @@ func (sma StorageMinerActor) SubmitElectionPoSt(act *types.Actor, vmctx types.VM
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func onSuccessfulPoSt(self *StorageMinerActorState, vmctx types.VMContext, activeFaults uint64) aerrors.ActorError {
|
func onSuccessfulPoSt2(self *StorageMinerActorState, vmctx types.VMContext, activeFaults uint64) aerrors.ActorError {
|
||||||
// TODO: some sector upkeep stuff that is very haphazard and unclear in the spec
|
ctx := vmctx.Context()
|
||||||
|
|
||||||
var mi MinerInfo
|
var mi MinerInfo
|
||||||
if err := vmctx.Storage().Get(self.Info, &mi); err != nil {
|
if err := vmctx.Storage().Get(self.Info, &mi); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
pss, nerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
|
pss, nerr := amt2.LoadAMT(ctx, vmctx.Ipld(), self.ProvingSet)
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
return aerrors.HandleExternalError(nerr, "failed to load proving set")
|
return aerrors.HandleExternalError(nerr, "failed to load proving set")
|
||||||
}
|
}
|
||||||
|
|
||||||
ss, nerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.Sectors)
|
ss, nerr := amt2.LoadAMT(ctx, vmctx.Ipld(), self.Sectors)
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
return aerrors.HandleExternalError(nerr, "failed to load sector set")
|
return aerrors.HandleExternalError(nerr, "failed to load sector set")
|
||||||
}
|
}
|
||||||
@ -1038,7 +985,10 @@ func onSuccessfulPoSt(self *StorageMinerActorState, vmctx types.VMContext, activ
|
|||||||
self.ElectionPeriodStart = vmctx.BlockHeight()
|
self.ElectionPeriodStart = vmctx.BlockHeight()
|
||||||
}
|
}
|
||||||
|
|
||||||
ncid, err := RemoveFromSectorSet(vmctx.Context(), vmctx.Storage(), self.Sectors, faults)
|
var ncid cid.Cid
|
||||||
|
var err aerrors.ActorError
|
||||||
|
|
||||||
|
ncid, err = RemoveFromSectorSet2(ctx, vmctx.Ipld(), self.Sectors, faults)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1048,6 +998,143 @@ func onSuccessfulPoSt(self *StorageMinerActorState, vmctx types.VMContext, activ
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SectorIsUnique(ctx context.Context, cst cbor.IpldStore, sroot cid.Cid, sid uint64) (bool, ActorError) {
|
||||||
|
found, _, _, err := GetFromSectorSet(ctx, cst, sroot, sid)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return !found, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFromSectorSet(ctx context.Context, cst cbor.IpldStore, ss cid.Cid, sectorID uint64) (bool, []byte, []byte, ActorError) {
|
||||||
|
if sectorID >= build.MinerMaxSectors {
|
||||||
|
return false, nil, nil, aerrors.Newf(25, "sector ID out of range: %d", sectorID)
|
||||||
|
}
|
||||||
|
|
||||||
|
ssr, err := amt.LoadAMT(ctx, cst, ss)
|
||||||
|
if err != nil {
|
||||||
|
return false, nil, nil, aerrors.HandleExternalError(err, "could not load sector set node")
|
||||||
|
}
|
||||||
|
|
||||||
|
var comms [][]byte
|
||||||
|
err = ssr.Get(ctx, sectorID, &comms)
|
||||||
|
if err != nil {
|
||||||
|
if _, ok := err.(*amt.ErrNotFound); ok {
|
||||||
|
return false, nil, nil, nil
|
||||||
|
}
|
||||||
|
return false, nil, nil, aerrors.HandleExternalError(err, "failed to find sector in sector set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(comms) != 2 {
|
||||||
|
return false, nil, nil, aerrors.Newf(20, "sector set entry should only have 2 elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, comms[0], comms[1], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddToSectorSet(ctx context.Context, blks cbor.IpldStore, ss cid.Cid, sectorID uint64, commR, commD []byte) (cid.Cid, ActorError) {
|
||||||
|
if sectorID >= build.MinerMaxSectors {
|
||||||
|
return cid.Undef, aerrors.Newf(25, "sector ID out of range: %d", sectorID)
|
||||||
|
}
|
||||||
|
ssr, err := amt.LoadAMT(ctx, blks, ss)
|
||||||
|
if err != nil {
|
||||||
|
return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Spec says to use SealCommitment, and construct commD from deals each time,
|
||||||
|
// but that would make SubmitPoSt way, way more expensive
|
||||||
|
if err := ssr.Set(ctx, sectorID, [][]byte{commR, commD}); err != nil {
|
||||||
|
return cid.Undef, aerrors.HandleExternalError(err, "failed to set commitment in sector set")
|
||||||
|
}
|
||||||
|
|
||||||
|
ncid, err := ssr.Flush(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ncid, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadState(vmctx types.VMContext) (cid.Cid, *StorageMinerActorState, ActorError) {
|
||||||
|
var self StorageMinerActorState
|
||||||
|
oldstate := vmctx.Storage().GetHead()
|
||||||
|
if err := vmctx.Storage().Get(oldstate, &self); err != nil {
|
||||||
|
return cid.Undef, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return oldstate, &self, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadMinerInfo(vmctx types.VMContext, m *StorageMinerActorState) (*MinerInfo, ActorError) {
|
||||||
|
var mi MinerInfo
|
||||||
|
if err := vmctx.Storage().Get(m.Info, &mi); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &mi, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func uintToStringKey(i uint64) string {
|
||||||
|
buf := make([]byte, 10)
|
||||||
|
n := binary.PutUvarint(buf, i)
|
||||||
|
return string(buf[:n])
|
||||||
|
}
|
||||||
|
|
||||||
|
type SectorProveCommitInfo struct {
|
||||||
|
Proof []byte
|
||||||
|
SectorID uint64
|
||||||
|
DealIDs []uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func truncateHexPrint(b []byte) string {
|
||||||
|
s := fmt.Sprintf("%x", b)
|
||||||
|
if len(s) > 60 {
|
||||||
|
return s[:20] + "..." + s[len(s)-20:]
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubmitFallbackPoStParams struct {
|
||||||
|
Proof []byte
|
||||||
|
Candidates []types.EPostTicket
|
||||||
|
}
|
||||||
|
|
||||||
|
func CollateralForPower(power types.BigInt) types.BigInt {
|
||||||
|
return types.BigMul(power, types.NewInt(10))
|
||||||
|
/* TODO: this
|
||||||
|
availableFil = FakeGlobalMethods.GetAvailableFil()
|
||||||
|
totalNetworkPower = StorageMinerActor.GetTotalStorage()
|
||||||
|
numMiners = StorageMarket.GetMinerCount()
|
||||||
|
powerCollateral = availableFil * NetworkConstants.POWER_COLLATERAL_PROPORTION * power / totalNetworkPower
|
||||||
|
perCapitaCollateral = availableFil * NetworkConstants.PER_CAPITA_COLLATERAL_PROPORTION / numMiners
|
||||||
|
collateralRequired = math.Ceil(minerPowerCollateral + minerPerCapitaCollateral)
|
||||||
|
return collateralRequired
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdatePeerIDParams struct {
|
||||||
|
PeerID peer.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
func isLate(height uint64, self *StorageMinerActorState) bool {
|
||||||
|
return self.ElectionPeriodStart > 0 && height >= self.ElectionPeriodStart+build.SlashablePowerDelay
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckMinerParams struct {
|
||||||
|
NetworkPower types.BigInt
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeclareFaultsParams struct {
|
||||||
|
Faults types.BitField
|
||||||
|
}
|
||||||
|
|
||||||
|
type MinerSlashConsensusFault struct {
|
||||||
|
Slasher address.Address
|
||||||
|
AtHeight uint64
|
||||||
|
SlashedCollateral types.BigInt
|
||||||
|
}
|
||||||
|
|
||||||
func slasherShare(total types.BigInt, elapsed uint64) types.BigInt {
|
func slasherShare(total types.BigInt, elapsed uint64) types.BigInt {
|
||||||
// [int(pow(1.26, n) * 10) for n in range(30)]
|
// [int(pow(1.26, n) * 10) for n in range(30)]
|
||||||
fracs := []uint64{10, 12, 15, 20, 25, 31, 40, 50, 63, 80, 100, 127, 160, 201, 254, 320, 403, 508, 640, 807, 1017, 1281, 1614, 2034, 2563, 3230, 4070, 5128, 6462, 8142}
|
fracs := []uint64{10, 12, 15, 20, 25, 31, 40, 50, 63, 80, 100, 127, 160, 201, 254, 320, 403, 508, 640, 807, 1017, 1281, 1614, 2034, 2563, 3230, 4070, 5128, 6462, 8142}
|
||||||
|
@ -1,907 +0,0 @@
|
|||||||
package actors
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
|
||||||
amt2 "github.com/filecoin-project/go-amt-ipld/v2"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-sectorbuilder"
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
|
||||||
"golang.org/x/xerrors"
|
|
||||||
)
|
|
||||||
|
|
||||||
type StorageMinerActor2 struct{}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) Exports() []interface{} {
|
|
||||||
return []interface{}{
|
|
||||||
1: sma.StorageMinerConstructor,
|
|
||||||
2: sma.PreCommitSector,
|
|
||||||
3: sma.ProveCommitSector,
|
|
||||||
4: sma.SubmitFallbackPoSt,
|
|
||||||
//5: sma.SlashStorageFault,
|
|
||||||
//6: sma.GetCurrentProvingSet,
|
|
||||||
//7: sma.ArbitrateDeal,
|
|
||||||
//8: sma.DePledge,
|
|
||||||
9: sma.GetOwner,
|
|
||||||
10: sma.GetWorkerAddr,
|
|
||||||
11: withUpdates(
|
|
||||||
update{0, sma.GetPower},
|
|
||||||
update{build.ForkMissingSnowballs, sma.GetPower2},
|
|
||||||
), // FORK
|
|
||||||
12: sma.GetPeerID,
|
|
||||||
13: sma.GetSectorSize,
|
|
||||||
14: sma.UpdatePeerID,
|
|
||||||
//15: sma.ChangeWorker,
|
|
||||||
16: sma.IsSlashed,
|
|
||||||
17: sma.CheckMiner,
|
|
||||||
18: sma.DeclareFaults,
|
|
||||||
19: sma.SlashConsensusFault,
|
|
||||||
20: sma.SubmitElectionPoSt,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) StorageMinerConstructor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) ([]byte, ActorError) {
|
|
||||||
minerInfo := &MinerInfo{
|
|
||||||
Owner: params.Owner,
|
|
||||||
Worker: params.Worker,
|
|
||||||
PeerID: params.PeerID,
|
|
||||||
SectorSize: params.SectorSize,
|
|
||||||
}
|
|
||||||
|
|
||||||
minfocid, err := vmctx.Storage().Put(minerInfo)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var self StorageMinerActorState
|
|
||||||
sectors := amt2.NewAMT(vmctx.Ipld())
|
|
||||||
scid, serr := sectors.Flush(context.TODO())
|
|
||||||
if serr != nil {
|
|
||||||
return nil, aerrors.HandleExternalError(serr, "initializing AMT")
|
|
||||||
}
|
|
||||||
|
|
||||||
self.Sectors = scid
|
|
||||||
self.ProvingSet = scid
|
|
||||||
self.Info = minfocid
|
|
||||||
|
|
||||||
storage := vmctx.Storage()
|
|
||||||
c, err := storage.Put(&self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := storage.Commit(EmptyCBOR, c); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) PreCommitSector(act *types.Actor, vmctx types.VMContext, params *SectorPreCommitInfo) ([]byte, ActorError) {
|
|
||||||
|
|
||||||
ctx := vmctx.Context()
|
|
||||||
oldstate, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if params.SealEpoch >= vmctx.BlockHeight()+build.SealRandomnessLookback {
|
|
||||||
return nil, aerrors.Newf(1, "sector commitment must be based off past randomness (%d >= %d)", params.SealEpoch, vmctx.BlockHeight()+build.SealRandomnessLookback)
|
|
||||||
}
|
|
||||||
|
|
||||||
if vmctx.BlockHeight()-params.SealEpoch+build.SealRandomnessLookback > build.SealRandomnessLookbackLimit {
|
|
||||||
return nil, aerrors.Newf(2, "sector commitment must be recent enough (was %d)", vmctx.BlockHeight()-params.SealEpoch+build.SealRandomnessLookback)
|
|
||||||
}
|
|
||||||
|
|
||||||
mi, err := loadMinerInfo(vmctx, self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if vmctx.Message().From != mi.Worker {
|
|
||||||
return nil, aerrors.New(1, "not authorized to precommit sector for miner")
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure the miner isnt trying to submit a pre-existing sector
|
|
||||||
unique, err := SectorIsUnique(ctx, vmctx.Storage(), self.Sectors, params.SectorNumber)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if !unique {
|
|
||||||
return nil, aerrors.New(3, "sector already committed!")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Power of the miner after adding this sector
|
|
||||||
futurePower := types.BigAdd(self.Power, types.NewInt(mi.SectorSize))
|
|
||||||
collateralRequired := CollateralForPower(futurePower)
|
|
||||||
|
|
||||||
// TODO: grab from market?
|
|
||||||
if act.Balance.LessThan(collateralRequired) {
|
|
||||||
return nil, aerrors.New(4, "not enough collateral")
|
|
||||||
}
|
|
||||||
|
|
||||||
self.PreCommittedSectors[uintToStringKey(params.SectorNumber)] = &PreCommittedSector{
|
|
||||||
Info: *params,
|
|
||||||
ReceivedEpoch: vmctx.BlockHeight(),
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(self.PreCommittedSectors) > 4096 {
|
|
||||||
return nil, aerrors.New(5, "too many precommitted sectors")
|
|
||||||
}
|
|
||||||
|
|
||||||
nstate, err := vmctx.Storage().Put(self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := vmctx.Storage().Commit(oldstate, nstate); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) ProveCommitSector(act *types.Actor, vmctx types.VMContext, params *SectorProveCommitInfo) ([]byte, ActorError) {
|
|
||||||
ctx := vmctx.Context()
|
|
||||||
oldstate, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
mi, err := loadMinerInfo(vmctx, self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if vmctx.Message().From != mi.Worker {
|
|
||||||
return nil, aerrors.New(1, "not authorized to submit sector proof for miner")
|
|
||||||
}
|
|
||||||
|
|
||||||
us, ok := self.PreCommittedSectors[uintToStringKey(params.SectorID)]
|
|
||||||
if !ok {
|
|
||||||
return nil, aerrors.New(1, "no pre-commitment found for sector")
|
|
||||||
}
|
|
||||||
|
|
||||||
if us.ReceivedEpoch+build.InteractivePoRepDelay >= vmctx.BlockHeight() {
|
|
||||||
return nil, aerrors.New(2, "too early for proof submission")
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(self.PreCommittedSectors, uintToStringKey(params.SectorID))
|
|
||||||
|
|
||||||
// TODO: ensure normalization to ID address
|
|
||||||
maddr := vmctx.Message().To
|
|
||||||
|
|
||||||
if vmctx.BlockHeight()-us.Info.SealEpoch > build.MaxSealLookback {
|
|
||||||
return nil, aerrors.Newf(5, "source randomness for sector SealEpoch too far in past (epoch %d)", us.Info.SealEpoch)
|
|
||||||
}
|
|
||||||
|
|
||||||
if vmctx.BlockHeight()-us.ReceivedEpoch > build.MaxSealLookback {
|
|
||||||
return nil, aerrors.Newf(6, "source randomness for sector ReceivedEpoch too far in past (epoch %d)", us.ReceivedEpoch)
|
|
||||||
}
|
|
||||||
|
|
||||||
ticket, err := vmctx.GetRandomness(us.Info.SealEpoch - build.SealRandomnessLookback)
|
|
||||||
if err != nil {
|
|
||||||
return nil, aerrors.Wrap(err, "failed to get ticket randomness")
|
|
||||||
}
|
|
||||||
|
|
||||||
seed, err := vmctx.GetRandomness(us.ReceivedEpoch + build.InteractivePoRepDelay)
|
|
||||||
if err != nil {
|
|
||||||
return nil, aerrors.Wrap(err, "failed to get randomness for prove sector commitment")
|
|
||||||
}
|
|
||||||
|
|
||||||
enc, err := SerializeParams(&ComputeDataCommitmentParams{
|
|
||||||
DealIDs: params.DealIDs,
|
|
||||||
SectorSize: mi.SectorSize,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, aerrors.Wrap(err, "failed to serialize ComputeDataCommitmentParams")
|
|
||||||
}
|
|
||||||
|
|
||||||
commD, err := vmctx.Send(StorageMarketAddress, SMAMethods.ComputeDataCommitment, types.NewInt(0), enc)
|
|
||||||
if err != nil {
|
|
||||||
return nil, aerrors.Wrapf(err, "failed to compute data commitment (sector %d, deals: %v)", params.SectorID, params.DealIDs)
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok, err := vmctx.Sys().ValidatePoRep(ctx, maddr, mi.SectorSize, commD, us.Info.CommR, ticket, params.Proof, seed, params.SectorID); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else if !ok {
|
|
||||||
return nil, aerrors.Newf(2, "porep proof was invalid (t:%x; s:%x(%d); p:%s)", ticket, seed, us.ReceivedEpoch+build.InteractivePoRepDelay, truncateHexPrint(params.Proof))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: There must exist a unique index in the miner's sector set for each
|
|
||||||
// sector ID. The `faults`, `recovered`, and `done` parameters of the
|
|
||||||
// SubmitPoSt method express indices into this sector set.
|
|
||||||
nssroot, err := AddToSectorSet2(ctx, vmctx.Ipld(), self.Sectors, params.SectorID, us.Info.CommR, commD)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
self.Sectors = nssroot
|
|
||||||
|
|
||||||
// if miner is not mining, start their proving period now
|
|
||||||
// Note: As written here, every miners first PoSt will only be over one sector.
|
|
||||||
// We could set up a 'grace period' for starting mining that would allow miners
|
|
||||||
// to submit several sectors for their first proving period. Alternatively, we
|
|
||||||
// could simply make the 'PreCommitSector' call take multiple sectors at a time.
|
|
||||||
//
|
|
||||||
// Note: Proving period is a function of sector size; small sectors take less
|
|
||||||
// time to prove than large sectors do. Sector size is selected when pledging.
|
|
||||||
pss, lerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.ProvingSet)
|
|
||||||
if lerr != nil {
|
|
||||||
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
|
||||||
}
|
|
||||||
|
|
||||||
if pss.Count == 0 && !self.Active {
|
|
||||||
self.ProvingSet = self.Sectors
|
|
||||||
// TODO: probably want to wait until the miner is above a certain
|
|
||||||
// threshold before starting this
|
|
||||||
self.ElectionPeriodStart = vmctx.BlockHeight()
|
|
||||||
}
|
|
||||||
|
|
||||||
nstate, err := vmctx.Storage().Put(self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := vmctx.Storage().Commit(oldstate, nstate); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
activateParams, err := SerializeParams(&ActivateStorageDealsParams{
|
|
||||||
Deals: params.DealIDs,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = vmctx.Send(StorageMarketAddress, SMAMethods.ActivateStorageDeals, types.NewInt(0), activateParams)
|
|
||||||
return nil, aerrors.Wrapf(err, "calling ActivateStorageDeals failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) SubmitFallbackPoSt(act *types.Actor, vmctx types.VMContext, params *SubmitFallbackPoStParams) ([]byte, ActorError) {
|
|
||||||
oldstate, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
mi, err := loadMinerInfo(vmctx, self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if vmctx.Message().From != mi.Worker {
|
|
||||||
return nil, aerrors.New(1, "not authorized to submit post for miner")
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// TODO: handle fees
|
|
||||||
msgVal := vmctx.Message().Value
|
|
||||||
if msgVal.LessThan(feesRequired) {
|
|
||||||
return nil, aerrors.New(2, "not enough funds to pay post submission fees")
|
|
||||||
}
|
|
||||||
|
|
||||||
if msgVal.GreaterThan(feesRequired) {
|
|
||||||
_, err := vmctx.Send(vmctx.Message().From, 0,
|
|
||||||
types.BigSub(msgVal, feesRequired), nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, aerrors.Wrap(err, "could not refund excess fees")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
var seed [sectorbuilder.CommLen]byte
|
|
||||||
{
|
|
||||||
randHeight := self.ElectionPeriodStart + build.FallbackPoStDelay
|
|
||||||
if vmctx.BlockHeight() <= randHeight {
|
|
||||||
// TODO: spec, retcode
|
|
||||||
return nil, aerrors.Newf(1, "submit fallback PoSt called too early (%d < %d)", vmctx.BlockHeight(), randHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
rand, err := vmctx.GetRandomness(randHeight)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, aerrors.Wrap(err, "could not get randomness for PoST")
|
|
||||||
}
|
|
||||||
if len(rand) < len(seed) {
|
|
||||||
return nil, aerrors.Escalate(fmt.Errorf("randomness too small (%d < %d)",
|
|
||||||
len(rand), len(seed)), "improper randomness")
|
|
||||||
}
|
|
||||||
copy(seed[:], rand)
|
|
||||||
}
|
|
||||||
|
|
||||||
pss, lerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.ProvingSet)
|
|
||||||
if lerr != nil {
|
|
||||||
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
|
||||||
}
|
|
||||||
|
|
||||||
ss, lerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.Sectors)
|
|
||||||
if lerr != nil {
|
|
||||||
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
|
||||||
}
|
|
||||||
|
|
||||||
faults, nerr := self.FaultSet.AllMap(2 * ss.Count)
|
|
||||||
if nerr != nil {
|
|
||||||
return nil, aerrors.Absorb(err, 5, "RLE+ invalid")
|
|
||||||
}
|
|
||||||
|
|
||||||
activeFaults := uint64(0)
|
|
||||||
var sectorInfos []ffi.PublicSectorInfo
|
|
||||||
if err := pss.ForEach(vmctx.Context(), func(id uint64, v *cbg.Deferred) error {
|
|
||||||
if faults[id] {
|
|
||||||
activeFaults++
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var comms [][]byte
|
|
||||||
if err := cbor.DecodeInto(v.Raw, &comms); err != nil {
|
|
||||||
return xerrors.New("could not decode comms")
|
|
||||||
}
|
|
||||||
si := ffi.PublicSectorInfo{
|
|
||||||
SectorID: id,
|
|
||||||
}
|
|
||||||
commR := comms[0]
|
|
||||||
if len(commR) != len(si.CommR) {
|
|
||||||
return xerrors.Errorf("commR length is wrong: %d", len(commR))
|
|
||||||
}
|
|
||||||
copy(si.CommR[:], commR)
|
|
||||||
|
|
||||||
sectorInfos = append(sectorInfos, si)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}); err != nil {
|
|
||||||
return nil, aerrors.Absorb(err, 3, "could not decode sectorset")
|
|
||||||
}
|
|
||||||
|
|
||||||
proverID := vmctx.Message().To // TODO: normalize to ID address
|
|
||||||
|
|
||||||
var candidates []sectorbuilder.EPostCandidate
|
|
||||||
for _, t := range params.Candidates {
|
|
||||||
var partial [32]byte
|
|
||||||
copy(partial[:], t.Partial)
|
|
||||||
candidates = append(candidates, sectorbuilder.EPostCandidate{
|
|
||||||
PartialTicket: partial,
|
|
||||||
SectorID: t.SectorID,
|
|
||||||
SectorChallengeIndex: t.ChallengeIndex,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok, lerr := vmctx.Sys().VerifyFallbackPost(vmctx.Context(), mi.SectorSize,
|
|
||||||
sectorbuilder.NewSortedPublicSectorInfo(sectorInfos), seed[:], params.Proof, candidates, proverID, activeFaults); !ok || lerr != nil {
|
|
||||||
if lerr != nil {
|
|
||||||
// TODO: study PoST errors
|
|
||||||
return nil, aerrors.Absorb(lerr, 4, "PoST error")
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
return nil, aerrors.New(4, "PoST invalid")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Post submission is successful!
|
|
||||||
if err := onSuccessfulPoSt2(self, vmctx, activeFaults); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c, err := vmctx.Storage().Put(self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := vmctx.Storage().Commit(oldstate, c); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) GetPower(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
|
||||||
_, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.Power.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) GetPower2(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
|
||||||
_, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.SlashedAt != 0 {
|
|
||||||
return types.NewInt(0).Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.Power.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func SectorIsUnique2(ctx context.Context, s cbor.IpldStore, sroot cid.Cid, sid uint64) (bool, ActorError) {
|
|
||||||
found, _, _, err := GetFromSectorSet2(ctx, s, sroot, sid)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return !found, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddToSectorSet2(ctx context.Context, blks cbor.IpldStore, ss cid.Cid, sectorID uint64, commR, commD []byte) (cid.Cid, ActorError) {
|
|
||||||
if sectorID >= build.MinerMaxSectors {
|
|
||||||
return cid.Undef, aerrors.Newf(25, "sector ID out of range: %d", sectorID)
|
|
||||||
}
|
|
||||||
ssr, err := amt2.LoadAMT(ctx, blks, ss)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node")
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Spec says to use SealCommitment, and construct commD from deals each time,
|
|
||||||
// but that would make SubmitPoSt way, way more expensive
|
|
||||||
if err := ssr.Set(ctx, sectorID, [][]byte{commR, commD}); err != nil {
|
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "failed to set commitment in sector set")
|
|
||||||
}
|
|
||||||
|
|
||||||
ncid, err := ssr.Flush(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set")
|
|
||||||
}
|
|
||||||
|
|
||||||
return ncid, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetFromSectorSet2(ctx context.Context, cst cbor.IpldStore, ss cid.Cid, sectorID uint64) (bool, []byte, []byte, ActorError) {
|
|
||||||
if sectorID >= build.MinerMaxSectors {
|
|
||||||
return false, nil, nil, aerrors.Newf(25, "sector ID out of range: %d", sectorID)
|
|
||||||
}
|
|
||||||
|
|
||||||
ssr, err := amt2.LoadAMT(ctx, cst, ss)
|
|
||||||
if err != nil {
|
|
||||||
return false, nil, nil, aerrors.HandleExternalError(err, "could not load sector set node")
|
|
||||||
}
|
|
||||||
|
|
||||||
var comms [][]byte
|
|
||||||
err = ssr.Get(ctx, sectorID, &comms)
|
|
||||||
if err != nil {
|
|
||||||
if _, ok := err.(*amt2.ErrNotFound); ok {
|
|
||||||
return false, nil, nil, nil
|
|
||||||
}
|
|
||||||
return false, nil, nil, aerrors.HandleExternalError(err, "failed to find sector in sector set")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(comms) != 2 {
|
|
||||||
return false, nil, nil, aerrors.Newf(20, "sector set entry should only have 2 elements")
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, comms[0], comms[1], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func RemoveFromSectorSet2(ctx context.Context, cst cbor.IpldStore, ss cid.Cid, ids []uint64) (cid.Cid, aerrors.ActorError) {
|
|
||||||
|
|
||||||
ssr, err := amt2.LoadAMT(ctx, cst, ss)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, id := range ids {
|
|
||||||
if err := ssr.Delete(ctx, id); err != nil {
|
|
||||||
log.Warnf("failed to delete sector %d from set: %s", id, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ncid, err := ssr.Flush(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set")
|
|
||||||
}
|
|
||||||
|
|
||||||
return ncid, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) GetWorkerAddr(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
|
||||||
_, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
mi, err := loadMinerInfo(vmctx, self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return mi.Worker.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) GetOwner(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
|
||||||
_, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
mi, err := loadMinerInfo(vmctx, self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return mi.Owner.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) GetPeerID(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
|
||||||
_, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
mi, err := loadMinerInfo(vmctx, self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return []byte(mi.PeerID), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) UpdatePeerID(act *types.Actor, vmctx types.VMContext, params *UpdatePeerIDParams) ([]byte, ActorError) {
|
|
||||||
oldstate, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
mi, err := loadMinerInfo(vmctx, self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if vmctx.Message().From != mi.Worker {
|
|
||||||
return nil, aerrors.New(2, "only the mine worker may update the peer ID")
|
|
||||||
}
|
|
||||||
|
|
||||||
mi.PeerID = params.PeerID
|
|
||||||
|
|
||||||
mic, err := vmctx.Storage().Put(mi)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
self.Info = mic
|
|
||||||
|
|
||||||
c, err := vmctx.Storage().Put(self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := vmctx.Storage().Commit(oldstate, c); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) GetSectorSize(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
|
||||||
_, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
mi, err := loadMinerInfo(vmctx, self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return types.NewInt(mi.SectorSize).Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) IsSlashed(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
|
||||||
_, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return cbg.EncodeBool(self.SlashedAt != 0), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: better name
|
|
||||||
func (sma StorageMinerActor2) CheckMiner(act *types.Actor, vmctx types.VMContext, params *CheckMinerParams) ([]byte, ActorError) {
|
|
||||||
if vmctx.Message().From != StoragePowerAddress {
|
|
||||||
return nil, aerrors.New(2, "only the storage power actor can check miner")
|
|
||||||
}
|
|
||||||
|
|
||||||
oldstate, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isLate(vmctx.BlockHeight(), self) {
|
|
||||||
// Everything's fine
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.SlashedAt != 0 {
|
|
||||||
// Don't slash more than necessary
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if params.NetworkPower.Equals(self.Power) {
|
|
||||||
// Don't break the network when there's only one miner left
|
|
||||||
|
|
||||||
log.Warnf("can't slash miner %s for missed PoSt, no power would be left in the network", vmctx.Message().To)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Slash for being late
|
|
||||||
|
|
||||||
self.SlashedAt = vmctx.BlockHeight()
|
|
||||||
oldPower := self.Power
|
|
||||||
|
|
||||||
if vmctx.BlockHeight() > build.ForkMissingSnowballs {
|
|
||||||
self.Power = types.NewInt(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
nstate, err := vmctx.Storage().Put(self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := vmctx.Storage().Commit(oldstate, nstate); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var out bytes.Buffer
|
|
||||||
if err := oldPower.MarshalCBOR(&out); err != nil {
|
|
||||||
return nil, aerrors.HandleExternalError(err, "marshaling return value")
|
|
||||||
}
|
|
||||||
return out.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) DeclareFaults(act *types.Actor, vmctx types.VMContext, params *DeclareFaultsParams) ([]byte, ActorError) {
|
|
||||||
oldstate, self, aerr := loadState(vmctx)
|
|
||||||
if aerr != nil {
|
|
||||||
return nil, aerr
|
|
||||||
}
|
|
||||||
|
|
||||||
mi, aerr := loadMinerInfo(vmctx, self)
|
|
||||||
if aerr != nil {
|
|
||||||
return nil, aerr
|
|
||||||
}
|
|
||||||
|
|
||||||
if vmctx.Message().From != mi.Worker {
|
|
||||||
return nil, aerrors.New(1, "not authorized to declare faults for miner")
|
|
||||||
}
|
|
||||||
|
|
||||||
nfaults, err := types.MergeBitFields(params.Faults, self.FaultSet)
|
|
||||||
if err != nil {
|
|
||||||
return nil, aerrors.Absorb(err, 1, "failed to merge bitfields")
|
|
||||||
}
|
|
||||||
|
|
||||||
ss, nerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.Sectors)
|
|
||||||
if nerr != nil {
|
|
||||||
return nil, aerrors.HandleExternalError(nerr, "failed to load sector set")
|
|
||||||
}
|
|
||||||
|
|
||||||
cf, nerr := nfaults.Count()
|
|
||||||
if nerr != nil {
|
|
||||||
return nil, aerrors.Absorb(nerr, 2, "could not decode RLE+")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cf > 2*ss.Count {
|
|
||||||
return nil, aerrors.Newf(3, "too many declared faults: %d > %d", cf, 2*ss.Count)
|
|
||||||
}
|
|
||||||
|
|
||||||
self.FaultSet = nfaults
|
|
||||||
|
|
||||||
self.LastFaultSubmission = vmctx.BlockHeight()
|
|
||||||
|
|
||||||
nstate, aerr := vmctx.Storage().Put(self)
|
|
||||||
if aerr != nil {
|
|
||||||
return nil, aerr
|
|
||||||
}
|
|
||||||
if err := vmctx.Storage().Commit(oldstate, nstate); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) SlashConsensusFault(act *types.Actor, vmctx types.VMContext, params *MinerSlashConsensusFault) ([]byte, ActorError) {
|
|
||||||
if vmctx.Message().From != StoragePowerAddress {
|
|
||||||
return nil, aerrors.New(1, "SlashConsensusFault may only be called by the storage market actor")
|
|
||||||
}
|
|
||||||
|
|
||||||
slashedCollateral := params.SlashedCollateral
|
|
||||||
if slashedCollateral.LessThan(act.Balance) {
|
|
||||||
slashedCollateral = act.Balance
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some of the slashed collateral should be paid to the slasher
|
|
||||||
// GROWTH_RATE determines how fast the slasher share of slashed collateral will increase as block elapses
|
|
||||||
// current GROWTH_RATE results in SLASHER_SHARE reaches 1 after 30 blocks
|
|
||||||
// TODO: define arithmetic precision and rounding for this operation
|
|
||||||
blockElapsed := vmctx.BlockHeight() - params.AtHeight
|
|
||||||
|
|
||||||
slasherShare := slasherShare(params.SlashedCollateral, blockElapsed)
|
|
||||||
|
|
||||||
burnPortion := types.BigSub(slashedCollateral, slasherShare)
|
|
||||||
|
|
||||||
_, err := vmctx.Send(vmctx.Message().From, 0, slasherShare, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, aerrors.Wrap(err, "failed to pay slasher")
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = vmctx.Send(BurntFundsAddress, 0, burnPortion, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, aerrors.Wrap(err, "failed to burn funds")
|
|
||||||
}
|
|
||||||
|
|
||||||
if vmctx.BlockHeight() > build.ForkMissingSnowballs {
|
|
||||||
oldstate, self, err := loadState(vmctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, aerrors.Wrap(err, "failed to load state for slashing")
|
|
||||||
}
|
|
||||||
|
|
||||||
self.Power = types.NewInt(0)
|
|
||||||
|
|
||||||
ncid, err := vmctx.Storage().Put(self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := vmctx.Storage().Commit(oldstate, ncid); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: this still allows the miner to commit sectors and submit posts,
|
|
||||||
// their users could potentially be unaffected, but the miner will never be
|
|
||||||
// able to mine a block again
|
|
||||||
// One potential issue: the miner will have to pay back the slashed
|
|
||||||
// collateral to continue submitting PoSts, which includes pledge
|
|
||||||
// collateral that they no longer really 'need'
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor2) SubmitElectionPoSt(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) {
|
|
||||||
ctx := vmctx.Context()
|
|
||||||
|
|
||||||
if vmctx.Message().From != NetworkAddress {
|
|
||||||
return nil, aerrors.Newf(1, "submit election post can only be called by the storage power actor")
|
|
||||||
}
|
|
||||||
|
|
||||||
oldstate, self, aerr := loadState(vmctx)
|
|
||||||
if aerr != nil {
|
|
||||||
return nil, aerr
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.SlashedAt != 0 {
|
|
||||||
return nil, aerrors.New(1, "slashed miners can't perform election PoSt")
|
|
||||||
}
|
|
||||||
|
|
||||||
pss, nerr := amt2.LoadAMT(ctx, vmctx.Ipld(), self.ProvingSet)
|
|
||||||
if nerr != nil {
|
|
||||||
return nil, aerrors.HandleExternalError(nerr, "failed to load proving set")
|
|
||||||
}
|
|
||||||
|
|
||||||
ss, nerr := amt2.LoadAMT(ctx, vmctx.Ipld(), self.Sectors)
|
|
||||||
if nerr != nil {
|
|
||||||
return nil, aerrors.HandleExternalError(nerr, "failed to load proving set")
|
|
||||||
}
|
|
||||||
|
|
||||||
faults, nerr := self.FaultSet.AllMap(2 * ss.Count)
|
|
||||||
if nerr != nil {
|
|
||||||
return nil, aerrors.Absorb(nerr, 1, "invalid bitfield (fatal?)")
|
|
||||||
}
|
|
||||||
|
|
||||||
activeFaults := uint64(0)
|
|
||||||
for f := range faults {
|
|
||||||
if f > amt2.MaxIndex {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
var comms [][]byte
|
|
||||||
err := pss.Get(ctx, f, &comms)
|
|
||||||
if err != nil {
|
|
||||||
var notfound *amt2.ErrNotFound
|
|
||||||
if !xerrors.As(err, ¬found) {
|
|
||||||
return nil, aerrors.HandleExternalError(err, "failed to find sector in sector set")
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
activeFaults++
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := onSuccessfulPoSt2(self, vmctx, activeFaults); err != nil { // TODO
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ncid, err := vmctx.Storage().Put(self)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := vmctx.Storage().Commit(oldstate, ncid); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func onSuccessfulPoSt2(self *StorageMinerActorState, vmctx types.VMContext, activeFaults uint64) aerrors.ActorError {
|
|
||||||
ctx := vmctx.Context()
|
|
||||||
// FORK
|
|
||||||
if vmctx.BlockHeight() < build.ForkBootyBayHeight {
|
|
||||||
return onSuccessfulPoSt(self, vmctx, activeFaults)
|
|
||||||
}
|
|
||||||
|
|
||||||
var mi MinerInfo
|
|
||||||
if err := vmctx.Storage().Get(self.Info, &mi); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
pss, nerr := amt2.LoadAMT(ctx, vmctx.Ipld(), self.ProvingSet)
|
|
||||||
if nerr != nil {
|
|
||||||
return aerrors.HandleExternalError(nerr, "failed to load proving set")
|
|
||||||
}
|
|
||||||
|
|
||||||
ss, nerr := amt2.LoadAMT(ctx, vmctx.Ipld(), self.Sectors)
|
|
||||||
if nerr != nil {
|
|
||||||
return aerrors.HandleExternalError(nerr, "failed to load sector set")
|
|
||||||
}
|
|
||||||
|
|
||||||
faults, nerr := self.FaultSet.All(2 * ss.Count)
|
|
||||||
if nerr != nil {
|
|
||||||
return aerrors.Absorb(nerr, 1, "invalid bitfield (fatal?)")
|
|
||||||
}
|
|
||||||
|
|
||||||
self.FaultSet = types.NewBitField()
|
|
||||||
|
|
||||||
oldPower := self.Power
|
|
||||||
newPower := types.BigMul(types.NewInt(pss.Count-activeFaults), types.NewInt(mi.SectorSize))
|
|
||||||
|
|
||||||
// If below the minimum size requirement, miners have zero power
|
|
||||||
if newPower.LessThan(types.NewInt(build.MinimumMinerPower)) {
|
|
||||||
newPower = types.NewInt(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
self.Power = newPower
|
|
||||||
|
|
||||||
delta := types.BigSub(self.Power, oldPower)
|
|
||||||
if self.SlashedAt != 0 {
|
|
||||||
self.SlashedAt = 0
|
|
||||||
delta = self.Power
|
|
||||||
}
|
|
||||||
|
|
||||||
prevSlashingDeadline := self.ElectionPeriodStart + build.SlashablePowerDelay
|
|
||||||
if !self.Active && newPower.GreaterThan(types.NewInt(0)) {
|
|
||||||
self.Active = true
|
|
||||||
prevSlashingDeadline = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if !(oldPower.IsZero() && newPower.IsZero()) {
|
|
||||||
enc, err := SerializeParams(&UpdateStorageParams{
|
|
||||||
Delta: delta,
|
|
||||||
NextSlashDeadline: vmctx.BlockHeight() + build.SlashablePowerDelay,
|
|
||||||
PreviousSlashDeadline: prevSlashingDeadline,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = vmctx.Send(StoragePowerAddress, SPAMethods.UpdateStorage, types.NewInt(0), enc)
|
|
||||||
if err != nil {
|
|
||||||
return aerrors.Wrap(err, "updating storage failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
self.ElectionPeriodStart = vmctx.BlockHeight()
|
|
||||||
}
|
|
||||||
|
|
||||||
var ncid cid.Cid
|
|
||||||
var err aerrors.ActorError
|
|
||||||
|
|
||||||
ncid, err = RemoveFromSectorSet2(ctx, vmctx.Ipld(), self.Sectors, faults)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
self.Sectors = ncid
|
|
||||||
self.ProvingSet = ncid
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -8,7 +8,7 @@ import (
|
|||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-amt-ipld"
|
"github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-hamt-ipld"
|
"github.com/ipfs/go-hamt-ipld"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
@ -314,7 +314,7 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
deals, err := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.Deals)
|
deals, err := amt.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.Deals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, aerrors.HandleExternalError(err, "loading deals amt")
|
return nil, aerrors.HandleExternalError(err, "loading deals amt")
|
||||||
}
|
}
|
||||||
@ -345,7 +345,7 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := deals.Set(self.NextDealID, &OnChainDeal{
|
err := deals.Set(vmctx.Context(), self.NextDealID, &OnChainDeal{
|
||||||
PieceRef: deal.PieceRef,
|
PieceRef: deal.PieceRef,
|
||||||
PieceSize: deal.PieceSize,
|
PieceSize: deal.PieceSize,
|
||||||
|
|
||||||
@ -367,7 +367,7 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
|
|||||||
self.NextDealID++
|
self.NextDealID++
|
||||||
}
|
}
|
||||||
|
|
||||||
dealsCid, err := deals.Flush()
|
dealsCid, err := deals.Flush(vmctx.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, aerrors.HandleExternalError(err, "saving deals AMT")
|
return nil, aerrors.HandleExternalError(err, "saving deals AMT")
|
||||||
}
|
}
|
||||||
@ -451,20 +451,21 @@ type ActivateStorageDealsParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sma StorageMarketActor) ActivateStorageDeals(act *types.Actor, vmctx types.VMContext, params *ActivateStorageDealsParams) ([]byte, ActorError) {
|
func (sma StorageMarketActor) ActivateStorageDeals(act *types.Actor, vmctx types.VMContext, params *ActivateStorageDealsParams) ([]byte, ActorError) {
|
||||||
|
ctx := vmctx.Context()
|
||||||
var self StorageMarketState
|
var self StorageMarketState
|
||||||
old := vmctx.Storage().GetHead()
|
old := vmctx.Storage().GetHead()
|
||||||
if err := vmctx.Storage().Get(old, &self); err != nil {
|
if err := vmctx.Storage().Get(old, &self); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
deals, err := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.Deals)
|
deals, err := amt.LoadAMT(ctx, vmctx.Ipld(), self.Deals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, aerrors.HandleExternalError(err, "loading deals amt")
|
return nil, aerrors.HandleExternalError(err, "loading deals amt")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, deal := range params.Deals {
|
for _, deal := range params.Deals {
|
||||||
var dealInfo OnChainDeal
|
var dealInfo OnChainDeal
|
||||||
if err := deals.Get(deal, &dealInfo); err != nil {
|
if err := deals.Get(ctx, deal, &dealInfo); err != nil {
|
||||||
if _, is := err.(*amt.ErrNotFound); is {
|
if _, is := err.(*amt.ErrNotFound); is {
|
||||||
return nil, aerrors.New(3, "deal not found")
|
return nil, aerrors.New(3, "deal not found")
|
||||||
}
|
}
|
||||||
@ -486,12 +487,12 @@ func (sma StorageMarketActor) ActivateStorageDeals(act *types.Actor, vmctx types
|
|||||||
|
|
||||||
dealInfo.ActivationEpoch = vmctx.BlockHeight()
|
dealInfo.ActivationEpoch = vmctx.BlockHeight()
|
||||||
|
|
||||||
if err := deals.Set(deal, &dealInfo); err != nil {
|
if err := deals.Set(ctx, deal, &dealInfo); err != nil {
|
||||||
return nil, aerrors.HandleExternalError(err, "setting deal info in AMT failed")
|
return nil, aerrors.HandleExternalError(err, "setting deal info in AMT failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dealsCid, err := deals.Flush()
|
dealsCid, err := deals.Flush(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, aerrors.HandleExternalError(err, "saving deals AMT")
|
return nil, aerrors.HandleExternalError(err, "saving deals AMT")
|
||||||
}
|
}
|
||||||
@ -516,13 +517,14 @@ type ProcessStorageDealsPaymentParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx types.VMContext, params *ProcessStorageDealsPaymentParams) ([]byte, ActorError) {
|
func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx types.VMContext, params *ProcessStorageDealsPaymentParams) ([]byte, ActorError) {
|
||||||
|
ctx := vmctx.Context()
|
||||||
var self StorageMarketState
|
var self StorageMarketState
|
||||||
old := vmctx.Storage().GetHead()
|
old := vmctx.Storage().GetHead()
|
||||||
if err := vmctx.Storage().Get(old, &self); err != nil {
|
if err := vmctx.Storage().Get(old, &self); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
deals, err := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.Deals)
|
deals, err := amt.LoadAMT(ctx, vmctx.Ipld(), self.Deals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, aerrors.HandleExternalError(err, "loading deals amt")
|
return nil, aerrors.HandleExternalError(err, "loading deals amt")
|
||||||
}
|
}
|
||||||
@ -539,7 +541,7 @@ func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx
|
|||||||
|
|
||||||
for _, deal := range params.DealIDs {
|
for _, deal := range params.DealIDs {
|
||||||
var dealInfo OnChainDeal
|
var dealInfo OnChainDeal
|
||||||
if err := deals.Get(deal, &dealInfo); err != nil {
|
if err := deals.Get(ctx, deal, &dealInfo); err != nil {
|
||||||
if _, is := err.(*amt.ErrNotFound); is {
|
if _, is := err.(*amt.ErrNotFound); is {
|
||||||
return nil, aerrors.New(2, "deal not found")
|
return nil, aerrors.New(2, "deal not found")
|
||||||
}
|
}
|
||||||
@ -613,13 +615,14 @@ type ComputeDataCommitmentParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sma StorageMarketActor) ComputeDataCommitment(act *types.Actor, vmctx types.VMContext, params *ComputeDataCommitmentParams) ([]byte, ActorError) {
|
func (sma StorageMarketActor) ComputeDataCommitment(act *types.Actor, vmctx types.VMContext, params *ComputeDataCommitmentParams) ([]byte, ActorError) {
|
||||||
|
ctx := vmctx.Context()
|
||||||
var self StorageMarketState
|
var self StorageMarketState
|
||||||
old := vmctx.Storage().GetHead()
|
old := vmctx.Storage().GetHead()
|
||||||
if err := vmctx.Storage().Get(old, &self); err != nil {
|
if err := vmctx.Storage().Get(old, &self); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
deals, err := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.Deals)
|
deals, err := amt.LoadAMT(ctx, vmctx.Ipld(), self.Deals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, aerrors.HandleExternalError(err, "loading deals amt")
|
return nil, aerrors.HandleExternalError(err, "loading deals amt")
|
||||||
}
|
}
|
||||||
@ -631,7 +634,7 @@ func (sma StorageMarketActor) ComputeDataCommitment(act *types.Actor, vmctx type
|
|||||||
var pieces []sectorbuilder.PublicPieceInfo
|
var pieces []sectorbuilder.PublicPieceInfo
|
||||||
for _, deal := range params.DealIDs {
|
for _, deal := range params.DealIDs {
|
||||||
var dealInfo OnChainDeal
|
var dealInfo OnChainDeal
|
||||||
if err := deals.Get(deal, &dealInfo); err != nil {
|
if err := deals.Get(ctx, deal, &dealInfo); err != nil {
|
||||||
if _, is := err.(*amt.ErrNotFound); is {
|
if _, is := err.(*amt.ErrNotFound); is {
|
||||||
return nil, aerrors.New(4, "deal not found")
|
return nil, aerrors.New(4, "deal not found")
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-amt-ipld"
|
"github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
cid "github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
hamt "github.com/ipfs/go-hamt-ipld"
|
hamt "github.com/ipfs/go-hamt-ipld"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
@ -87,11 +87,7 @@ func (spa StoragePowerActor) CreateStorageMiner(act *types.Actor, vmctx types.VM
|
|||||||
return nil, aerrors.Newf(1, "not enough funds passed to cover required miner collateral (needed %s, got %s)", reqColl, vmctx.Message().Value)
|
return nil, aerrors.Newf(1, "not enough funds passed to cover required miner collateral (needed %s, got %s)", reqColl, vmctx.Message().Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FORK
|
|
||||||
minerCid := StorageMinerCodeCid
|
minerCid := StorageMinerCodeCid
|
||||||
if vmctx.BlockHeight() > build.ForkFrigidHeight {
|
|
||||||
minerCid = StorageMiner2CodeCid
|
|
||||||
}
|
|
||||||
|
|
||||||
encoded, err := CreateExecParams(minerCid, &StorageMinerConstructorParams{
|
encoded, err := CreateExecParams(minerCid, &StorageMinerConstructorParams{
|
||||||
Owner: params.Owner,
|
Owner: params.Owner,
|
||||||
@ -146,19 +142,8 @@ func (spa StoragePowerActor) ArbitrateConsensusFault(act *types.Actor, vmctx typ
|
|||||||
return nil, aerrors.New(2, "blocks must be from the same miner")
|
return nil, aerrors.New(2, "blocks must be from the same miner")
|
||||||
}
|
}
|
||||||
|
|
||||||
// FORK
|
if params.Block1.Cid() == params.Block2.Cid() {
|
||||||
if vmctx.BlockHeight() > build.ForkBlizzardHeight {
|
return nil, aerrors.New(3, "blocks must be different")
|
||||||
if params.Block1.Height <= build.ForkBlizzardHeight {
|
|
||||||
return nil, aerrors.New(10, "cannot slash miners with blocks from before blizzard")
|
|
||||||
}
|
|
||||||
|
|
||||||
if params.Block2.Height <= build.ForkBlizzardHeight {
|
|
||||||
return nil, aerrors.New(11, "cannot slash miners with blocks from before blizzard")
|
|
||||||
}
|
|
||||||
|
|
||||||
if params.Block1.Cid() == params.Block2.Cid() {
|
|
||||||
return nil, aerrors.New(3, "blocks must be different")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rval, err := vmctx.Send(params.Block1.Miner, MAMethods.GetWorkerAddr, types.NewInt(0), nil)
|
rval, err := vmctx.Send(params.Block1.Miner, MAMethods.GetWorkerAddr, types.NewInt(0), nil)
|
||||||
@ -300,6 +285,7 @@ type UpdateStorageParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (spa StoragePowerActor) UpdateStorage(act *types.Actor, vmctx types.VMContext, params *UpdateStorageParams) ([]byte, ActorError) {
|
func (spa StoragePowerActor) UpdateStorage(act *types.Actor, vmctx types.VMContext, params *UpdateStorageParams) ([]byte, ActorError) {
|
||||||
|
ctx := vmctx.Context()
|
||||||
var self StoragePowerState
|
var self StoragePowerState
|
||||||
old := vmctx.Storage().GetHead()
|
old := vmctx.Storage().GetHead()
|
||||||
if err := vmctx.Storage().Get(old, &self); err != nil {
|
if err := vmctx.Storage().Get(old, &self); err != nil {
|
||||||
@ -332,7 +318,7 @@ func (spa StoragePowerActor) UpdateStorage(act *types.Actor, vmctx types.VMConte
|
|||||||
return nil, nil // Nothing to do
|
return nil, nil // Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
buckets, eerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingBuckets)
|
buckets, eerr := amt.LoadAMT(ctx, vmctx.Ipld(), self.ProvingBuckets)
|
||||||
if eerr != nil {
|
if eerr != nil {
|
||||||
return nil, aerrors.HandleExternalError(eerr, "loading proving buckets amt")
|
return nil, aerrors.HandleExternalError(eerr, "loading proving buckets amt")
|
||||||
}
|
}
|
||||||
@ -349,7 +335,7 @@ func (spa StoragePowerActor) UpdateStorage(act *types.Actor, vmctx types.VMConte
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ProvingBuckets, eerr = buckets.Flush()
|
self.ProvingBuckets, eerr = buckets.Flush(ctx)
|
||||||
if eerr != nil {
|
if eerr != nil {
|
||||||
return nil, aerrors.HandleExternalError(eerr, "flushing proving buckets")
|
return nil, aerrors.HandleExternalError(eerr, "flushing proving buckets")
|
||||||
}
|
}
|
||||||
@ -367,8 +353,9 @@ func (spa StoragePowerActor) UpdateStorage(act *types.Actor, vmctx types.VMConte
|
|||||||
}
|
}
|
||||||
|
|
||||||
func deleteMinerFromBucket(vmctx types.VMContext, buckets *amt.Root, previousBucket uint64) aerrors.ActorError {
|
func deleteMinerFromBucket(vmctx types.VMContext, buckets *amt.Root, previousBucket uint64) aerrors.ActorError {
|
||||||
|
ctx := vmctx.Context()
|
||||||
var bucket cid.Cid
|
var bucket cid.Cid
|
||||||
err := buckets.Get(previousBucket, &bucket)
|
err := buckets.Get(ctx, previousBucket, &bucket)
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case *amt.ErrNotFound:
|
case *amt.ErrNotFound:
|
||||||
return aerrors.HandleExternalError(err, "proving bucket missing")
|
return aerrors.HandleExternalError(err, "proving bucket missing")
|
||||||
@ -396,7 +383,7 @@ func deleteMinerFromBucket(vmctx types.VMContext, buckets *amt.Root, previousBuc
|
|||||||
return aerrors.HandleExternalError(err, "putting previous proving bucket hamt")
|
return aerrors.HandleExternalError(err, "putting previous proving bucket hamt")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = buckets.Set(previousBucket, bucket)
|
err = buckets.Set(ctx, previousBucket, bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return aerrors.HandleExternalError(err, "setting previous proving bucket cid in amt")
|
return aerrors.HandleExternalError(err, "setting previous proving bucket cid in amt")
|
||||||
}
|
}
|
||||||
@ -405,9 +392,10 @@ func deleteMinerFromBucket(vmctx types.VMContext, buckets *amt.Root, previousBuc
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addMinerToBucket(vmctx types.VMContext, buckets *amt.Root, nextBucket uint64) aerrors.ActorError {
|
func addMinerToBucket(vmctx types.VMContext, buckets *amt.Root, nextBucket uint64) aerrors.ActorError {
|
||||||
|
ctx := vmctx.Context()
|
||||||
var bhamt *hamt.Node
|
var bhamt *hamt.Node
|
||||||
var bucket cid.Cid
|
var bucket cid.Cid
|
||||||
err := buckets.Get(nextBucket, &bucket)
|
err := buckets.Get(ctx, nextBucket, &bucket)
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case *amt.ErrNotFound:
|
case *amt.ErrNotFound:
|
||||||
bhamt = hamt.NewNode(vmctx.Ipld())
|
bhamt = hamt.NewNode(vmctx.Ipld())
|
||||||
@ -435,7 +423,7 @@ func addMinerToBucket(vmctx types.VMContext, buckets *amt.Root, nextBucket uint6
|
|||||||
return aerrors.HandleExternalError(err, "putting previous proving bucket hamt")
|
return aerrors.HandleExternalError(err, "putting previous proving bucket hamt")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = buckets.Set(nextBucket, bucket)
|
err = buckets.Set(ctx, nextBucket, bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return aerrors.HandleExternalError(err, "setting previous proving bucket cid in amt")
|
return aerrors.HandleExternalError(err, "setting previous proving bucket cid in amt")
|
||||||
}
|
}
|
||||||
@ -628,15 +616,16 @@ func (spa StoragePowerActor) CheckProofSubmissions(act *types.Actor, vmctx types
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkProofSubmissionsAtH(vmctx types.VMContext, self *StoragePowerState, height uint64) aerrors.ActorError {
|
func checkProofSubmissionsAtH(vmctx types.VMContext, self *StoragePowerState, height uint64) aerrors.ActorError {
|
||||||
|
ctx := vmctx.Context()
|
||||||
bucketID := height % build.SlashablePowerDelay
|
bucketID := height % build.SlashablePowerDelay
|
||||||
|
|
||||||
buckets, eerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingBuckets)
|
buckets, eerr := amt.LoadAMT(ctx, vmctx.Ipld(), self.ProvingBuckets)
|
||||||
if eerr != nil {
|
if eerr != nil {
|
||||||
return aerrors.HandleExternalError(eerr, "loading proving buckets amt")
|
return aerrors.HandleExternalError(eerr, "loading proving buckets amt")
|
||||||
}
|
}
|
||||||
|
|
||||||
var bucket cid.Cid
|
var bucket cid.Cid
|
||||||
err := buckets.Get(bucketID, &bucket)
|
err := buckets.Get(ctx, bucketID, &bucket)
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case *amt.ErrNotFound:
|
case *amt.ErrNotFound:
|
||||||
return nil // nothing to do
|
return nil // nothing to do
|
||||||
@ -661,16 +650,13 @@ func checkProofSubmissionsAtH(vmctx types.VMContext, self *StoragePowerState, he
|
|||||||
return aerrors.Escalate(err, "parsing miner address")
|
return aerrors.Escalate(err, "parsing miner address")
|
||||||
}
|
}
|
||||||
|
|
||||||
if vmctx.BlockHeight() > build.ForkMissingSnowballs {
|
has, aerr := MinerSetHas(vmctx, self.Miners, maddr)
|
||||||
has, aerr := MinerSetHas(vmctx, self.Miners, maddr)
|
if aerr != nil {
|
||||||
if aerr != nil {
|
return aerr
|
||||||
return aerr
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !has {
|
|
||||||
forRemoval = append(forRemoval, maddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if !has {
|
||||||
|
forRemoval = append(forRemoval, maddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
span.AddAttributes(trace.StringAttribute("miner", maddr.String()))
|
span.AddAttributes(trace.StringAttribute("miner", maddr.String()))
|
||||||
@ -706,18 +692,18 @@ func checkProofSubmissionsAtH(vmctx types.VMContext, self *StoragePowerState, he
|
|||||||
return aerrors.HandleExternalError(err, "iterating miners in proving bucket")
|
return aerrors.HandleExternalError(err, "iterating miners in proving bucket")
|
||||||
}
|
}
|
||||||
|
|
||||||
if vmctx.BlockHeight() > build.ForkMissingSnowballs && len(forRemoval) > 0 {
|
if len(forRemoval) > 0 {
|
||||||
nBucket, err := MinerSetRemove(vmctx.Context(), vmctx, bucket, forRemoval...)
|
nBucket, err := MinerSetRemove(vmctx.Context(), vmctx, bucket, forRemoval...)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return aerrors.Wrap(err, "could not remove miners from set")
|
return aerrors.Wrap(err, "could not remove miners from set")
|
||||||
}
|
}
|
||||||
|
|
||||||
eerr := buckets.Set(bucketID, nBucket)
|
eerr := buckets.Set(ctx, bucketID, nBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return aerrors.HandleExternalError(eerr, "could not set the bucket")
|
return aerrors.HandleExternalError(eerr, "could not set the bucket")
|
||||||
}
|
}
|
||||||
ncid, eerr := buckets.Flush()
|
ncid, eerr := buckets.Flush(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return aerrors.HandleExternalError(eerr, "could not flush buckets")
|
return aerrors.HandleExternalError(eerr, "could not flush buckets")
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,6 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) {
|
|||||||
signBlock(t, h.w, workerAddr, b1)
|
signBlock(t, h.w, workerAddr, b1)
|
||||||
signBlock(t, h.w, workerAddr, b2)
|
signBlock(t, h.w, workerAddr, b2)
|
||||||
|
|
||||||
h.BlockHeight = build.ForkBlizzardHeight + 1
|
|
||||||
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.ArbitrateConsensusFault,
|
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.ArbitrateConsensusFault,
|
||||||
&ArbitrateConsensusFaultParams{
|
&ArbitrateConsensusFaultParams{
|
||||||
Block1: b1,
|
Block1: b1,
|
||||||
|
@ -12,7 +12,6 @@ var CronCodeCid cid.Cid
|
|||||||
var StoragePowerCodeCid cid.Cid
|
var StoragePowerCodeCid cid.Cid
|
||||||
var StorageMarketCodeCid cid.Cid
|
var StorageMarketCodeCid cid.Cid
|
||||||
var StorageMinerCodeCid cid.Cid
|
var StorageMinerCodeCid cid.Cid
|
||||||
var StorageMiner2CodeCid cid.Cid
|
|
||||||
var MultisigCodeCid cid.Cid
|
var MultisigCodeCid cid.Cid
|
||||||
var InitCodeCid cid.Cid
|
var InitCodeCid cid.Cid
|
||||||
var PaymentChannelCodeCid cid.Cid
|
var PaymentChannelCodeCid cid.Cid
|
||||||
@ -51,7 +50,6 @@ func init() {
|
|||||||
StoragePowerCodeCid = mustSum("fil/1/power")
|
StoragePowerCodeCid = mustSum("fil/1/power")
|
||||||
StorageMarketCodeCid = mustSum("fil/1/market")
|
StorageMarketCodeCid = mustSum("fil/1/market")
|
||||||
StorageMinerCodeCid = mustSum("fil/1/miner")
|
StorageMinerCodeCid = mustSum("fil/1/miner")
|
||||||
StorageMiner2CodeCid = mustSum("fil/1/miner/2")
|
|
||||||
MultisigCodeCid = mustSum("fil/1/multisig")
|
MultisigCodeCid = mustSum("fil/1/multisig")
|
||||||
InitCodeCid = mustSum("fil/1/init")
|
InitCodeCid = mustSum("fil/1/init")
|
||||||
PaymentChannelCodeCid = mustSum("fil/1/paych")
|
PaymentChannelCodeCid = mustSum("fil/1/paych")
|
||||||
@ -60,7 +58,6 @@ func init() {
|
|||||||
StorageMarketCodeCid: true,
|
StorageMarketCodeCid: true,
|
||||||
StoragePowerCodeCid: true,
|
StoragePowerCodeCid: true,
|
||||||
StorageMinerCodeCid: true,
|
StorageMinerCodeCid: true,
|
||||||
StorageMiner2CodeCid: true,
|
|
||||||
AccountCodeCid: true,
|
AccountCodeCid: true,
|
||||||
InitCodeCid: true,
|
InitCodeCid: true,
|
||||||
MultisigCodeCid: true,
|
MultisigCodeCid: true,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
||||||
|
|
||||||
package actors
|
package actors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -11,8 +13,6 @@ import (
|
|||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
var _ = xerrors.Errorf
|
var _ = xerrors.Errorf
|
||||||
|
|
||||||
func (t *InitActorState) MarshalCBOR(w io.Writer) error {
|
func (t *InitActorState) MarshalCBOR(w io.Writer) error {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
||||||
|
|
||||||
package blocksync
|
package blocksync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -5,13 +7,11 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
cid "github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
var _ = xerrors.Errorf
|
var _ = xerrors.Errorf
|
||||||
|
|
||||||
func (t *BlockSyncRequest) MarshalCBOR(w io.Writer) error {
|
func (t *BlockSyncRequest) MarshalCBOR(w io.Writer) error {
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
bls "github.com/filecoin-project/filecoin-ffi"
|
bls "github.com/filecoin-project/filecoin-ffi"
|
||||||
amt "github.com/filecoin-project/go-amt-ipld"
|
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
cid "github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
@ -68,17 +68,17 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bs := amt.WrapBlockstore(sm.ChainStore().Blockstore())
|
bs := cbor.NewCborStore(sm.ChainStore().Blockstore())
|
||||||
blsmsgroot, err := amt.FromArray(bs, toIfArr(blsMsgCids))
|
blsmsgroot, err := amt.FromArray(ctx, bs, toIfArr(blsMsgCids))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("building bls amt: %w", err)
|
return nil, xerrors.Errorf("building bls amt: %w", err)
|
||||||
}
|
}
|
||||||
secpkmsgroot, err := amt.FromArray(bs, toIfArr(secpkMsgCids))
|
secpkmsgroot, err := amt.FromArray(ctx, bs, toIfArr(secpkMsgCids))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("building secpk amt: %w", err)
|
return nil, xerrors.Errorf("building secpk amt: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mmcid, err := bs.Put(&types.MsgMeta{
|
mmcid, err := bs.Put(ctx, &types.MsgMeta{
|
||||||
BlsMessages: blsmsgroot,
|
BlsMessages: blsmsgroot,
|
||||||
SecpkMessages: secpkmsgroot,
|
SecpkMessages: secpkmsgroot,
|
||||||
})
|
})
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
amt "github.com/filecoin-project/go-amt-ipld"
|
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
hamt "github.com/ipfs/go-hamt-ipld"
|
hamt "github.com/ipfs/go-hamt-ipld"
|
||||||
@ -166,15 +166,16 @@ func SetupCronActor(bs bstore.Blockstore) (*types.Actor, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
|
func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
|
||||||
|
ctx := context.TODO()
|
||||||
cst := cbor.NewCborStore(bs)
|
cst := cbor.NewCborStore(bs)
|
||||||
nd := hamt.NewNode(cst)
|
nd := hamt.NewNode(cst)
|
||||||
emptyhamt, err := cst.Put(context.TODO(), nd)
|
emptyhamt, err := cst.Put(ctx, nd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
blks := amt.WrapBlockstore(bs)
|
blks := cbor.NewCborStore(bs)
|
||||||
emptyamt, err := amt.FromArray(blks, nil)
|
emptyamt, err := amt.FromArray(ctx, blks, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("amt build failed: %w", err)
|
return nil, xerrors.Errorf("amt build failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -185,7 +186,7 @@ func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
|
|||||||
TotalStorage: types.NewInt(0),
|
TotalStorage: types.NewInt(0),
|
||||||
}
|
}
|
||||||
|
|
||||||
stcid, err := cst.Put(context.TODO(), sms)
|
stcid, err := cst.Put(ctx, sms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -199,15 +200,14 @@ func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors.StorageDealProposal) (cid.Cid, error) {
|
func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors.StorageDealProposal) (cid.Cid, error) {
|
||||||
|
ctx := context.TODO()
|
||||||
cst := cbor.NewCborStore(bs)
|
cst := cbor.NewCborStore(bs)
|
||||||
nd := hamt.NewNode(cst)
|
nd := hamt.NewNode(cst)
|
||||||
emptyHAMT, err := cst.Put(context.TODO(), nd)
|
emptyHAMT, err := cst.Put(ctx, nd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
blks := amt.WrapBlockstore(bs)
|
|
||||||
|
|
||||||
cdeals := make([]cbg.CBORMarshaler, len(deals))
|
cdeals := make([]cbg.CBORMarshaler, len(deals))
|
||||||
for i, deal := range deals {
|
for i, deal := range deals {
|
||||||
cdeals[i] = &actors.OnChainDeal{
|
cdeals[i] = &actors.OnChainDeal{
|
||||||
@ -223,7 +223,7 @@ func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dealAmt, err := amt.FromArray(blks, cdeals)
|
dealAmt, err := amt.FromArray(ctx, cst, cdeals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, xerrors.Errorf("amt build failed: %w", err)
|
return cid.Undef, xerrors.Errorf("amt build failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -354,10 +354,8 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
|||||||
}
|
}
|
||||||
mstate.Power = types.BigMul(types.NewInt(ps.SectorSize), types.NewInt(uint64(len(ps.Sectors))))
|
mstate.Power = types.BigMul(types.NewInt(ps.SectorSize), types.NewInt(uint64(len(ps.Sectors))))
|
||||||
|
|
||||||
blks := amt.WrapBlockstore(cs.Blockstore())
|
|
||||||
|
|
||||||
for _, s := range ps.Sectors {
|
for _, s := range ps.Sectors {
|
||||||
nssroot, err := actors.AddToSectorSet(ctx, blks, mstate.Sectors, s.SectorID, s.CommR[:], s.CommD[:])
|
nssroot, err := actors.AddToSectorSet(ctx, cst, mstate.Sectors, s.SectorID, s.CommR[:], s.CommD[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, nil, xerrors.Errorf("failed to add fake sector to sector set: %w", err)
|
return cid.Undef, nil, xerrors.Errorf("failed to add fake sector to sector set: %w", err)
|
||||||
}
|
}
|
||||||
@ -557,7 +555,7 @@ func doExecValue(ctx context.Context, vm *vm.VM, to, from address.Address, value
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MakeGenesisBlock(bs bstore.Blockstore, sys *types.VMSyscalls, balances map[address.Address]types.BigInt, gmcfg *GenMinerCfg, ts uint64) (*GenesisBootstrap, error) {
|
func MakeGenesisBlock(bs bstore.Blockstore, sys *types.VMSyscalls, balances map[address.Address]types.BigInt, gmcfg *GenMinerCfg, ts uint64) (*GenesisBootstrap, error) {
|
||||||
ctx := context.Background()
|
ctx := context.TODO()
|
||||||
|
|
||||||
state, err := MakeInitialStateTree(bs, balances)
|
state, err := MakeInitialStateTree(bs, balances)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -586,9 +584,9 @@ func MakeGenesisBlock(bs bstore.Blockstore, sys *types.VMSyscalls, balances map[
|
|||||||
return nil, xerrors.Errorf("failed to adjust init actor start ID: %w", err)
|
return nil, xerrors.Errorf("failed to adjust init actor start ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
blks := amt.WrapBlockstore(bs)
|
cst := cbor.NewCborStore(bs)
|
||||||
|
|
||||||
emptyroot, err := amt.FromArray(blks, nil)
|
emptyroot, err := amt.FromArray(ctx, cst, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("amt build failed: %w", err)
|
return nil, xerrors.Errorf("amt build failed: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -3,52 +3,10 @@ package stmgr
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
|
||||||
"github.com/filecoin-project/lotus/chain/state"
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
|
||||||
"golang.org/x/xerrors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ForksAtHeight = map[uint64]func(context.Context, *StateManager, cid.Cid) (cid.Cid, error){
|
var ForksAtHeight = map[uint64]func(context.Context, *StateManager, cid.Cid) (cid.Cid, error){}
|
||||||
build.ForkBlizzardHeight: func(ctx context.Context, sm *StateManager, pstate cid.Cid) (cid.Cid, error) {
|
|
||||||
log.Warnw("Executing blizzard fork logic")
|
|
||||||
nstate, err := fixBlizzardAMTBug(ctx, sm, pstate)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("blizzard bug fix failed: %w", err)
|
|
||||||
}
|
|
||||||
return nstate, nil
|
|
||||||
},
|
|
||||||
build.ForkFrigidHeight: func(ctx context.Context, sm *StateManager, pstate cid.Cid) (cid.Cid, error) {
|
|
||||||
log.Warnw("Executing frigid fork logic")
|
|
||||||
nstate, err := fixBlizzardAMTBug(ctx, sm, pstate)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("frigid bug fix failed: %w", err)
|
|
||||||
}
|
|
||||||
return nstate, nil
|
|
||||||
},
|
|
||||||
build.ForkBootyBayHeight: func(ctx context.Context, sm *StateManager, pstate cid.Cid) (cid.Cid, error) {
|
|
||||||
log.Warnw("Executing booty bay fork logic")
|
|
||||||
nstate, err := fixBlizzardAMTBug(ctx, sm, pstate)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("booty bay bug fix failed: %w", err)
|
|
||||||
}
|
|
||||||
return nstate, nil
|
|
||||||
},
|
|
||||||
build.ForkMissingSnowballs: func(ctx context.Context, sm *StateManager, pstate cid.Cid) (cid.Cid, error) {
|
|
||||||
log.Warnw("Adding more snow to the world")
|
|
||||||
nstate, err := fixTooFewSnowballs(ctx, sm, pstate)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("missing snowballs bug fix failed: %w", err)
|
|
||||||
}
|
|
||||||
return nstate, nil
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sm *StateManager) handleStateForks(ctx context.Context, pstate cid.Cid, height, parentH uint64) (_ cid.Cid, err error) {
|
func (sm *StateManager) handleStateForks(ctx context.Context, pstate cid.Cid, height, parentH uint64) (_ cid.Cid, err error) {
|
||||||
for i := parentH; i < height; i++ {
|
for i := parentH; i < height; i++ {
|
||||||
@ -64,162 +22,3 @@ func (sm *StateManager) handleStateForks(ctx context.Context, pstate cid.Cid, he
|
|||||||
|
|
||||||
return pstate, nil
|
return pstate, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fixTooFewSnowballs(ctx context.Context, sm *StateManager, pstate cid.Cid) (cid.Cid, error) {
|
|
||||||
cst := cbor.NewCborStore(sm.cs.Blockstore())
|
|
||||||
st, err := state.LoadStateTree(cst, pstate)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
|
|
||||||
spa, err := st.GetActor(actors.StoragePowerAddress)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("failed to get storage power actor: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var spast actors.StoragePowerState
|
|
||||||
if err := cst.Get(ctx, spa.Head, &spast); err != nil {
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
|
|
||||||
miners, err := actors.MinerSetList(ctx, cst, spast.Miners)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
|
|
||||||
sum := types.NewInt(0)
|
|
||||||
for _, m := range miners {
|
|
||||||
mact, err := st.GetActor(m)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("getting miner actor to fix: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var mstate actors.StorageMinerActorState
|
|
||||||
if err := cst.Get(ctx, mact.Head, &mstate); err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("failed to load miner actor state: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if mstate.SlashedAt != 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sum = types.BigAdd(sum, mstate.Power)
|
|
||||||
}
|
|
||||||
|
|
||||||
spast.TotalStorage = sum
|
|
||||||
nspahead, err := cst.Put(ctx, &spast)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
|
|
||||||
spa.Head = nspahead
|
|
||||||
|
|
||||||
return st.Flush(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
1) Iterate through each miner in the chain:
|
|
||||||
1.1) Fixup their sector set and proving set
|
|
||||||
1.2) Change their code cid to point to the new miner actor code
|
|
||||||
*/
|
|
||||||
func fixBlizzardAMTBug(ctx context.Context, sm *StateManager, pstate cid.Cid) (cid.Cid, error) {
|
|
||||||
cst := cbor.NewCborStore(sm.cs.Blockstore())
|
|
||||||
st, err := state.LoadStateTree(cst, pstate)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
|
|
||||||
spa, err := st.GetActor(actors.StoragePowerAddress)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("failed to get storage power actor: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var spast actors.StoragePowerState
|
|
||||||
if err := cst.Get(ctx, spa.Head, &spast); err != nil {
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
|
|
||||||
miners, err := actors.MinerSetList(ctx, cst, spast.Miners)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, m := range miners {
|
|
||||||
mact, err := st.GetActor(m)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("getting miner actor to fix: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
nhead, err := fixMiner(ctx, cst, sm.cs.Blockstore(), mact.Head)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("fixing miner: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if nhead != mact.Head {
|
|
||||||
log.Warnf("Miner %s had changes", m)
|
|
||||||
}
|
|
||||||
|
|
||||||
mact.Head = nhead
|
|
||||||
mact.Code = actors.StorageMiner2CodeCid
|
|
||||||
|
|
||||||
if err := st.SetActor(m, mact); err != nil {
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return st.Flush(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fixMiner(ctx context.Context, cst cbor.IpldStore, bs blockstore.Blockstore, mscid cid.Cid) (cid.Cid, error) {
|
|
||||||
var mstate actors.StorageMinerActorState
|
|
||||||
if err := cst.Get(ctx, mscid, &mstate); err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("failed to load miner actor state: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
nsectors, err := amtFsck(cst, mstate.Sectors)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("error fsck'ing sector set: %w", err)
|
|
||||||
}
|
|
||||||
mstate.Sectors = nsectors
|
|
||||||
|
|
||||||
nproving, err := amtFsck(cst, mstate.ProvingSet)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("error fsck'ing proving set: %w", err)
|
|
||||||
}
|
|
||||||
mstate.ProvingSet = nproving
|
|
||||||
|
|
||||||
nmcid, err := cst.Put(ctx, &mstate)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("failed to put modified miner state: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nmcid, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func amtFsck(cst cbor.IpldStore, ss cid.Cid) (cid.Cid, error) {
|
|
||||||
ctx := context.TODO()
|
|
||||||
a, err := amt.LoadAMT(ctx, cst, ss)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("could not load AMT: %w", a)
|
|
||||||
}
|
|
||||||
|
|
||||||
b := amt.NewAMT(cst)
|
|
||||||
|
|
||||||
err = a.ForEach(ctx, func(id uint64, data *cbg.Deferred) error {
|
|
||||||
err := b.Set(ctx, id, data)
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("could not copy at idx (%d): %w", id, err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("could not copy: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
nss, err := b.Flush(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("could not flush: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nss, nil
|
|
||||||
}
|
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
amt "github.com/filecoin-project/go-amt-ipld"
|
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/state"
|
"github.com/filecoin-project/lotus/chain/state"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
@ -281,8 +281,8 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
|
|||||||
return cid.Undef, cid.Undef, xerrors.Errorf("CheckProofSubmissions exit was non-zero: %d", ret.ExitCode)
|
return cid.Undef, cid.Undef, xerrors.Errorf("CheckProofSubmissions exit was non-zero: %d", ret.ExitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
bs := amt.WrapBlockstore(sm.cs.Blockstore())
|
bs := cbor.NewCborStore(sm.cs.Blockstore())
|
||||||
rectroot, err := amt.FromArray(bs, receipts)
|
rectroot, err := amt.FromArray(ctx, bs, receipts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, cid.Undef, xerrors.Errorf("failed to build receipts amt: %w", err)
|
return cid.Undef, cid.Undef, xerrors.Errorf("failed to build receipts amt: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@ package stmgr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
amt2 "github.com/filecoin-project/go-amt-ipld/v2"
|
|
||||||
|
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||||
|
|
||||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||||
@ -16,7 +17,6 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/vm"
|
"github.com/filecoin-project/lotus/chain/vm"
|
||||||
|
|
||||||
amt "github.com/filecoin-project/go-amt-ipld"
|
|
||||||
cid "github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
@ -171,13 +171,13 @@ func SectorSetSizes(ctx context.Context, sm *StateManager, maddr address.Address
|
|||||||
return api.MinerSectors{}, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err)
|
return api.MinerSectors{}, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
blks := amt.WrapBlockstore(sm.ChainStore().Blockstore())
|
blks := cbor.NewCborStore(sm.ChainStore().Blockstore())
|
||||||
ss, err := amt.LoadAMT(blks, mas.Sectors)
|
ss, err := amt.LoadAMT(ctx, blks, mas.Sectors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.MinerSectors{}, err
|
return api.MinerSectors{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ps, err := amt.LoadAMT(blks, mas.ProvingSet)
|
ps, err := amt.LoadAMT(ctx, blks, mas.ProvingSet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.MinerSectors{}, err
|
return api.MinerSectors{}, err
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ func GetMinerFaults(ctx context.Context, sm *StateManager, ts *types.TipSet, mad
|
|||||||
return nil, xerrors.Errorf("(get ssize) failed to load miner actor state: %w", err)
|
return nil, xerrors.Errorf("(get ssize) failed to load miner actor state: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ss, lerr := amt2.LoadAMT(amt.WrapBlockstore(sm.cs.Blockstore()), mas.Sectors)
|
ss, lerr := amt.LoadAMT(ctx, cbor.NewCborStore(sm.cs.Blockstore()), mas.Sectors)
|
||||||
if lerr != nil {
|
if lerr != nil {
|
||||||
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
|
||||||
}
|
}
|
||||||
@ -275,14 +275,13 @@ func GetStorageDeal(ctx context.Context, sm *StateManager, dealId uint64, ts *ty
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
blks := amt.WrapBlockstore(sm.ChainStore().Blockstore())
|
da, err := amt.LoadAMT(ctx, cbor.NewCborStore(sm.ChainStore().Blockstore()), state.Deals)
|
||||||
da, err := amt.LoadAMT(blks, state.Deals)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var ocd actors.OnChainDeal
|
var ocd actors.OnChainDeal
|
||||||
if err := da.Get(dealId, &ocd); err != nil {
|
if err := da.Get(ctx, dealId, &ocd); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,14 +304,13 @@ func ListMinerActors(ctx context.Context, sm *StateManager, ts *types.TipSet) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LoadSectorsFromSet(ctx context.Context, bs blockstore.Blockstore, ssc cid.Cid) ([]*api.ChainSectorInfo, error) {
|
func LoadSectorsFromSet(ctx context.Context, bs blockstore.Blockstore, ssc cid.Cid) ([]*api.ChainSectorInfo, error) {
|
||||||
blks := amt.WrapBlockstore(bs)
|
a, err := amt.LoadAMT(ctx, cbor.NewCborStore(bs), ssc)
|
||||||
a, err := amt.LoadAMT(blks, ssc)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var sset []*api.ChainSectorInfo
|
var sset []*api.ChainSectorInfo
|
||||||
if err := a.ForEach(func(i uint64, v *cbg.Deferred) error {
|
if err := a.ForEach(ctx, func(i uint64, v *cbg.Deferred) error {
|
||||||
var comms [][]byte
|
var comms [][]byte
|
||||||
if err := cbor.DecodeInto(v.Raw, &comms); err != nil {
|
if err := cbor.DecodeInto(v.Raw, &comms); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
"go.uber.org/multierr"
|
"go.uber.org/multierr"
|
||||||
|
|
||||||
amt "github.com/filecoin-project/go-amt-ipld"
|
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
@ -615,8 +615,9 @@ func (cs *ChainStore) GetSignedMessage(c cid.Cid) (*types.SignedMessage, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cs *ChainStore) readAMTCids(root cid.Cid) ([]cid.Cid, error) {
|
func (cs *ChainStore) readAMTCids(root cid.Cid) ([]cid.Cid, error) {
|
||||||
bs := amt.WrapBlockstore(cs.bs)
|
ctx := context.TODO()
|
||||||
a, err := amt.LoadAMT(bs, root)
|
bs := cbor.NewCborStore(cs.bs)
|
||||||
|
a, err := amt.LoadAMT(ctx, bs, root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("amt load: %w", err)
|
return nil, xerrors.Errorf("amt load: %w", err)
|
||||||
}
|
}
|
||||||
@ -624,7 +625,7 @@ func (cs *ChainStore) readAMTCids(root cid.Cid) ([]cid.Cid, error) {
|
|||||||
var cids []cid.Cid
|
var cids []cid.Cid
|
||||||
for i := uint64(0); i < a.Count; i++ {
|
for i := uint64(0); i < a.Count; i++ {
|
||||||
var c cbg.CborCid
|
var c cbg.CborCid
|
||||||
if err := a.Get(i, &c); err != nil {
|
if err := a.Get(ctx, i, &c); err != nil {
|
||||||
return nil, xerrors.Errorf("failed to load cid from amt: %w", err)
|
return nil, xerrors.Errorf("failed to load cid from amt: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -781,14 +782,15 @@ func (cs *ChainStore) MessagesForBlock(b *types.BlockHeader) ([]*types.Message,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cs *ChainStore) GetParentReceipt(b *types.BlockHeader, i int) (*types.MessageReceipt, error) {
|
func (cs *ChainStore) GetParentReceipt(b *types.BlockHeader, i int) (*types.MessageReceipt, error) {
|
||||||
bs := amt.WrapBlockstore(cs.bs)
|
ctx := context.TODO()
|
||||||
a, err := amt.LoadAMT(bs, b.ParentMessageReceipts)
|
bs := cbor.NewCborStore(cs.bs)
|
||||||
|
a, err := amt.LoadAMT(ctx, bs, b.ParentMessageReceipts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("amt load: %w", err)
|
return nil, xerrors.Errorf("amt load: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var r types.MessageReceipt
|
var r types.MessageReceipt
|
||||||
if err := a.Get(uint64(i), &r); err != nil {
|
if err := a.Get(ctx, uint64(i), &r); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/Gurpartap/async"
|
"github.com/Gurpartap/async"
|
||||||
bls "github.com/filecoin-project/filecoin-ffi"
|
bls "github.com/filecoin-project/filecoin-ffi"
|
||||||
amt "github.com/filecoin-project/go-amt-ipld"
|
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -210,7 +210,7 @@ func (syncer *Syncer) ValidateMsgMeta(fblk *types.FullBlock) error {
|
|||||||
// we implement that
|
// we implement that
|
||||||
blockstore := syncer.store.Blockstore()
|
blockstore := syncer.store.Blockstore()
|
||||||
|
|
||||||
bs := amt.WrapBlockstore(blockstore)
|
bs := cbor.NewCborStore(blockstore)
|
||||||
smroot, err := computeMsgMeta(bs, bcids, scids)
|
smroot, err := computeMsgMeta(bs, bcids, scids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("validating msgmeta, compute failed: %w", err)
|
return xerrors.Errorf("validating msgmeta, compute failed: %w", err)
|
||||||
@ -277,7 +277,7 @@ func copyBlockstore(from, to bstore.Blockstore) error {
|
|||||||
// either validate it here, or ensure that its validated elsewhere (maybe make
|
// either validate it here, or ensure that its validated elsewhere (maybe make
|
||||||
// sure the blocksync code checks it?)
|
// sure the blocksync code checks it?)
|
||||||
// maybe this code should actually live in blocksync??
|
// maybe this code should actually live in blocksync??
|
||||||
func zipTipSetAndMessages(bs amt.Blocks, ts *types.TipSet, allbmsgs []*types.Message, allsmsgs []*types.SignedMessage, bmi, smi [][]uint64) (*store.FullTipSet, error) {
|
func zipTipSetAndMessages(bs cbor.IpldStore, ts *types.TipSet, allbmsgs []*types.Message, allsmsgs []*types.SignedMessage, bmi, smi [][]uint64) (*store.FullTipSet, error) {
|
||||||
if len(ts.Blocks()) != len(smi) || len(ts.Blocks()) != len(bmi) {
|
if len(ts.Blocks()) != len(smi) || len(ts.Blocks()) != len(bmi) {
|
||||||
return nil, fmt.Errorf("msgincl length didnt match tipset size")
|
return nil, fmt.Errorf("msgincl length didnt match tipset size")
|
||||||
}
|
}
|
||||||
@ -325,18 +325,19 @@ func zipTipSetAndMessages(bs amt.Blocks, ts *types.TipSet, allbmsgs []*types.Mes
|
|||||||
return fts, nil
|
return fts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func computeMsgMeta(bs amt.Blocks, bmsgCids, smsgCids []cbg.CBORMarshaler) (cid.Cid, error) {
|
func computeMsgMeta(bs cbor.IpldStore, bmsgCids, smsgCids []cbg.CBORMarshaler) (cid.Cid, error) {
|
||||||
bmroot, err := amt.FromArray(bs, bmsgCids)
|
ctx := context.TODO()
|
||||||
|
bmroot, err := amt.FromArray(ctx, bs, bmsgCids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
smroot, err := amt.FromArray(bs, smsgCids)
|
smroot, err := amt.FromArray(ctx, bs, smsgCids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
mrcid, err := bs.Put(&types.MsgMeta{
|
mrcid, err := bs.Put(ctx, &types.MsgMeta{
|
||||||
BlsMessages: bmroot,
|
BlsMessages: bmroot,
|
||||||
SecpkMessages: smroot,
|
SecpkMessages: smroot,
|
||||||
})
|
})
|
||||||
@ -765,7 +766,6 @@ func (syncer *Syncer) checkBlockMessages(ctx context.Context, b *types.FullBlock
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
bs := amt.WrapBlockstore(syncer.store.Blockstore())
|
|
||||||
var blsCids []cbg.CBORMarshaler
|
var blsCids []cbg.CBORMarshaler
|
||||||
|
|
||||||
for i, m := range b.BlsMessages {
|
for i, m := range b.BlsMessages {
|
||||||
@ -796,17 +796,17 @@ func (syncer *Syncer) checkBlockMessages(ctx context.Context, b *types.FullBlock
|
|||||||
secpkCids = append(secpkCids, &c)
|
secpkCids = append(secpkCids, &c)
|
||||||
}
|
}
|
||||||
|
|
||||||
bmroot, err := amt.FromArray(bs, blsCids)
|
bmroot, err := amt.FromArray(ctx, cst, blsCids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to build amt from bls msg cids: %w", err)
|
return xerrors.Errorf("failed to build amt from bls msg cids: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
smroot, err := amt.FromArray(bs, secpkCids)
|
smroot, err := amt.FromArray(ctx, cst, secpkCids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to build amt from bls msg cids: %w", err)
|
return xerrors.Errorf("failed to build amt from bls msg cids: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mrcid, err := bs.Put(&types.MsgMeta{
|
mrcid, err := cst.Put(ctx, &types.MsgMeta{
|
||||||
BlsMessages: bmroot,
|
BlsMessages: bmroot,
|
||||||
SecpkMessages: smroot,
|
SecpkMessages: smroot,
|
||||||
})
|
})
|
||||||
@ -1076,7 +1076,7 @@ func (syncer *Syncer) iterFullTipsets(ctx context.Context, headers []*types.TipS
|
|||||||
// temp storage so we don't persist data we dont want to
|
// temp storage so we don't persist data we dont want to
|
||||||
ds := dstore.NewMapDatastore()
|
ds := dstore.NewMapDatastore()
|
||||||
bs := bstore.NewBlockstore(ds)
|
bs := bstore.NewBlockstore(ds)
|
||||||
blks := amt.WrapBlockstore(bs)
|
blks := cbor.NewCborStore(bs)
|
||||||
|
|
||||||
this := headers[i-bsi]
|
this := headers[i-bsi]
|
||||||
bstip := bstips[len(bstips)-(bsi+1)]
|
bstip := bstips[len(bstips)-(bsi+1)]
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -5,13 +7,11 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
cid "github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
var _ = xerrors.Errorf
|
var _ = xerrors.Errorf
|
||||||
|
|
||||||
func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
|
func (t *BlockHeader) MarshalCBOR(w io.Writer) error {
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/filecoin-project/go-sectorbuilder"
|
"github.com/filecoin-project/go-sectorbuilder"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-amt-ipld"
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||||
cid "github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
@ -79,7 +78,3 @@ func (sw *storageWrapper) Get(c cid.Cid, out cbg.CBORUnmarshaler) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WrapStorage(s Storage) amt.Blocks {
|
|
||||||
return &storageWrapper{s}
|
|
||||||
}
|
|
||||||
|
@ -38,7 +38,6 @@ func NewInvoker() *invoker {
|
|||||||
inv.Register(actors.StoragePowerCodeCid, actors.StoragePowerActor{}, actors.StoragePowerState{})
|
inv.Register(actors.StoragePowerCodeCid, actors.StoragePowerActor{}, actors.StoragePowerState{})
|
||||||
inv.Register(actors.StorageMarketCodeCid, actors.StorageMarketActor{}, actors.StorageMarketState{})
|
inv.Register(actors.StorageMarketCodeCid, actors.StorageMarketActor{}, actors.StorageMarketState{})
|
||||||
inv.Register(actors.StorageMinerCodeCid, actors.StorageMinerActor{}, actors.StorageMinerActorState{})
|
inv.Register(actors.StorageMinerCodeCid, actors.StorageMinerActor{}, actors.StorageMinerActorState{})
|
||||||
inv.Register(actors.StorageMiner2CodeCid, actors.StorageMinerActor2{}, actors.StorageMinerActorState{})
|
|
||||||
inv.Register(actors.MultisigCodeCid, multisig.MultiSigActor{}, multisig.MultiSigActorState{})
|
inv.Register(actors.MultisigCodeCid, multisig.MultiSigActor{}, multisig.MultiSigActorState{})
|
||||||
inv.Register(actors.PaymentChannelCodeCid, actors.PaymentChannelActor{}, actors.PaymentChannelActorState{})
|
inv.Register(actors.PaymentChannelCodeCid, actors.PaymentChannelActor{}, actors.PaymentChannelActorState{})
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipS
|
|||||||
|
|
||||||
for addr, m := range actors {
|
for addr, m := range actors {
|
||||||
for actor, c := range m {
|
for actor, c := range m {
|
||||||
if !(actor.Code == actors2.StorageMinerCodeCid || actor.Code == actors2.StorageMiner2CodeCid) {
|
if actor.Code != actors2.StorageMinerCodeCid {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,8 +297,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
|
|||||||
Ref: proposalCid, // TODO: This is super wrong, but there
|
Ref: proposalCid, // TODO: This is super wrong, but there
|
||||||
// are no params for CommP CIDs, we can't recover unixfs cid easily,
|
// are no params for CommP CIDs, we can't recover unixfs cid easily,
|
||||||
// and this isn't even used after the deal enters Complete state
|
// and this isn't even used after the deal enters Complete state
|
||||||
DealID: dealID,
|
DealID: dealID,
|
||||||
SectorID: sector.SectorID,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
go.mod
5
go.mod
@ -13,12 +13,11 @@ require (
|
|||||||
github.com/filecoin-project/chain-validation v0.0.3
|
github.com/filecoin-project/chain-validation v0.0.3
|
||||||
github.com/filecoin-project/filecoin-ffi v0.0.0-20191219131535-bb699517a590
|
github.com/filecoin-project/filecoin-ffi v0.0.0-20191219131535-bb699517a590
|
||||||
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5
|
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5
|
||||||
github.com/filecoin-project/go-amt-ipld v0.0.0-20191205011053-79efc22d6cdc
|
|
||||||
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e
|
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e
|
||||||
github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2
|
github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2
|
||||||
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
|
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
|
||||||
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce
|
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce
|
||||||
github.com/filecoin-project/go-fil-markets v0.0.0-20200124235616-d94a1cf0beaa
|
github.com/filecoin-project/go-fil-markets v0.0.0-20200206024724-973498b060e3
|
||||||
github.com/filecoin-project/go-paramfetch v0.0.1
|
github.com/filecoin-project/go-paramfetch v0.0.1
|
||||||
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200203173614-42d67726bb62
|
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200203173614-42d67726bb62
|
||||||
github.com/filecoin-project/go-statestore v0.1.0
|
github.com/filecoin-project/go-statestore v0.1.0
|
||||||
@ -33,7 +32,7 @@ require (
|
|||||||
github.com/ipfs/go-bitswap v0.1.8
|
github.com/ipfs/go-bitswap v0.1.8
|
||||||
github.com/ipfs/go-block-format v0.0.2
|
github.com/ipfs/go-block-format v0.0.2
|
||||||
github.com/ipfs/go-blockservice v0.1.3-0.20190908200855-f22eea50656c
|
github.com/ipfs/go-blockservice v0.1.3-0.20190908200855-f22eea50656c
|
||||||
github.com/ipfs/go-car v0.0.3-0.20200124090545-1a340009d896
|
github.com/ipfs/go-car v0.0.3-0.20200131220434-3f68f6ebd093
|
||||||
github.com/ipfs/go-cid v0.0.4
|
github.com/ipfs/go-cid v0.0.4
|
||||||
github.com/ipfs/go-datastore v0.3.1
|
github.com/ipfs/go-datastore v0.3.1
|
||||||
github.com/ipfs/go-ds-badger2 v0.0.0-20200123200730-d75eb2678a5d
|
github.com/ipfs/go-ds-badger2 v0.0.0-20200123200730-d75eb2678a5d
|
||||||
|
13
go.sum
13
go.sum
@ -103,8 +103,6 @@ github.com/filecoin-project/go-address v0.0.0-20191219011437-af739c490b4f h1:L2j
|
|||||||
github.com/filecoin-project/go-address v0.0.0-20191219011437-af739c490b4f/go.mod h1:rCbpXPva2NKF9/J4X6sr7hbKBgQCxyFtRj7KOZqoIms=
|
github.com/filecoin-project/go-address v0.0.0-20191219011437-af739c490b4f/go.mod h1:rCbpXPva2NKF9/J4X6sr7hbKBgQCxyFtRj7KOZqoIms=
|
||||||
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5 h1:/MmWluswvDIbuPvBct4q6HeQgVm62O2DzWYTB38kt4A=
|
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5 h1:/MmWluswvDIbuPvBct4q6HeQgVm62O2DzWYTB38kt4A=
|
||||||
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
|
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
|
||||||
github.com/filecoin-project/go-amt-ipld v0.0.0-20191205011053-79efc22d6cdc h1:cODZD2YzpTUtrOSxbEnWFcQHidNRZiRdvLxySjGvG/M=
|
|
||||||
github.com/filecoin-project/go-amt-ipld v0.0.0-20191205011053-79efc22d6cdc/go.mod h1:KsFPWjF+UUYl6n9A+qbg4bjFgAOneicFZtDH/LQEX2U=
|
|
||||||
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e h1:IOoff6yAZSJ5zHCPY2jzGNwQYQU6ygsRVe/cSnJrY+o=
|
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e h1:IOoff6yAZSJ5zHCPY2jzGNwQYQU6ygsRVe/cSnJrY+o=
|
||||||
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e/go.mod h1:boRtQhzmxNocrMxOXo1NYn4oUc1NGvR8tEa79wApNXg=
|
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e/go.mod h1:boRtQhzmxNocrMxOXo1NYn4oUc1NGvR8tEa79wApNXg=
|
||||||
github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2 h1:av5fw6wmm58FYMgJeoB/lK9XXrgdugYiTqkdxjTy9k8=
|
github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2 h1:av5fw6wmm58FYMgJeoB/lK9XXrgdugYiTqkdxjTy9k8=
|
||||||
@ -113,8 +111,10 @@ github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 h1:2pMX
|
|||||||
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ=
|
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ=
|
||||||
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce h1:Jdejrx6XVSTRy2PiX08HCU5y68p3wx2hNMJJc/J7kZY=
|
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce h1:Jdejrx6XVSTRy2PiX08HCU5y68p3wx2hNMJJc/J7kZY=
|
||||||
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce/go.mod h1:b14UWxhxVCAjrQUYvVGrQRRsjAh79wXYejw9RbUcAww=
|
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce/go.mod h1:b14UWxhxVCAjrQUYvVGrQRRsjAh79wXYejw9RbUcAww=
|
||||||
github.com/filecoin-project/go-fil-markets v0.0.0-20200124235616-d94a1cf0beaa h1:45LCzmHF2NZuYYFOmJ/MQ5SRDXw4QApQvT4BJzVysV8=
|
github.com/filecoin-project/go-fil-markets v0.0.0-20200206024724-973498b060e3 h1:fsHA5wFvO78+imT4VJiq2MLZGr8WmKVgjhnvVyqKOck=
|
||||||
github.com/filecoin-project/go-fil-markets v0.0.0-20200124235616-d94a1cf0beaa/go.mod h1:hbYlEmbOg9QwhZ71B724oAgXQ0wnoWHj8S+33q9lrm8=
|
github.com/filecoin-project/go-fil-markets v0.0.0-20200206024724-973498b060e3/go.mod h1:0d8NAXL4ecTLvxCpoc0cZd1XbRq9UtFT14BkITidVkc=
|
||||||
|
github.com/filecoin-project/go-padreader v0.0.0-20200130212543-892867c4edf9 h1:CQsjS+oWG96rk5YbeKpPw84fhbgc5H6/BGvrlPgd63A=
|
||||||
|
github.com/filecoin-project/go-padreader v0.0.0-20200130212543-892867c4edf9/go.mod h1:r0gyD7zvnqyRKSY8stil5G/LF0kXFgNzW/yR4vjga+Y=
|
||||||
github.com/filecoin-project/go-paramfetch v0.0.0-20200102181131-b20d579f2878/go.mod h1:40kI2Gv16mwcRsHptI3OAV4nlOEU7wVDc4RgMylNFjU=
|
github.com/filecoin-project/go-paramfetch v0.0.0-20200102181131-b20d579f2878/go.mod h1:40kI2Gv16mwcRsHptI3OAV4nlOEU7wVDc4RgMylNFjU=
|
||||||
github.com/filecoin-project/go-paramfetch v0.0.1 h1:gV7bs5YaqlgpGFMiLxInGK2L1FyCXUE0rimz4L7ghoE=
|
github.com/filecoin-project/go-paramfetch v0.0.1 h1:gV7bs5YaqlgpGFMiLxInGK2L1FyCXUE0rimz4L7ghoE=
|
||||||
github.com/filecoin-project/go-paramfetch v0.0.1/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc=
|
github.com/filecoin-project/go-paramfetch v0.0.1/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc=
|
||||||
@ -219,8 +219,8 @@ github.com/ipfs/go-blockservice v0.0.7/go.mod h1:EOfb9k/Y878ZTRY/CH0x5+ATtaipfbR
|
|||||||
github.com/ipfs/go-blockservice v0.1.0/go.mod h1:hzmMScl1kXHg3M2BjTymbVPjv627N7sYcvYaKbop39M=
|
github.com/ipfs/go-blockservice v0.1.0/go.mod h1:hzmMScl1kXHg3M2BjTymbVPjv627N7sYcvYaKbop39M=
|
||||||
github.com/ipfs/go-blockservice v0.1.3-0.20190908200855-f22eea50656c h1:lN5IQA07VtLiTLAp/Scezp1ljFhXErC6yq4O1cu+yJ0=
|
github.com/ipfs/go-blockservice v0.1.3-0.20190908200855-f22eea50656c h1:lN5IQA07VtLiTLAp/Scezp1ljFhXErC6yq4O1cu+yJ0=
|
||||||
github.com/ipfs/go-blockservice v0.1.3-0.20190908200855-f22eea50656c/go.mod h1:t+411r7psEUhLueM8C7aPA7cxCclv4O3VsUVxt9kz2I=
|
github.com/ipfs/go-blockservice v0.1.3-0.20190908200855-f22eea50656c/go.mod h1:t+411r7psEUhLueM8C7aPA7cxCclv4O3VsUVxt9kz2I=
|
||||||
github.com/ipfs/go-car v0.0.3-0.20200124090545-1a340009d896 h1:l8gnU1VBhftugMKzfh+n7nuDhOw3X1iqfrA33GVBMMY=
|
github.com/ipfs/go-car v0.0.3-0.20200131220434-3f68f6ebd093 h1:mYq7vJKGUzxIkkYfqXfO0uEO8gOmV9F38Tcpvi/p8P8=
|
||||||
github.com/ipfs/go-car v0.0.3-0.20200124090545-1a340009d896/go.mod h1:rmd887mJxQRDfndfDEY3Liyx8gQVyfFFRSHdsnDSAlk=
|
github.com/ipfs/go-car v0.0.3-0.20200131220434-3f68f6ebd093/go.mod h1:rEkw0S1sHd5kHL3rUSGEhwNanYqTwwNhjtpp0rwjrr4=
|
||||||
github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
|
github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
|
||||||
github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
|
github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
|
||||||
github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
|
github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
|
||||||
@ -740,7 +740,6 @@ github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc h1:BCPnHtcboa
|
|||||||
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc/go.mod h1:r45hJU7yEoA81k6MWNhpMj/kms0n14dkzkxYHoB96UM=
|
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc/go.mod h1:r45hJU7yEoA81k6MWNhpMj/kms0n14dkzkxYHoB96UM=
|
||||||
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba h1:X4n8JG2e2biEZZXdBKt9HX7DN3bYGFUqljqqy0DqgnY=
|
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba h1:X4n8JG2e2biEZZXdBKt9HX7DN3bYGFUqljqqy0DqgnY=
|
||||||
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba/go.mod h1:CHQnYnQUEPydYCwuy8lmTHfGmdw9TKrhWV0xLx8l0oM=
|
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba/go.mod h1:CHQnYnQUEPydYCwuy8lmTHfGmdw9TKrhWV0xLx8l0oM=
|
||||||
github.com/whyrusleeping/cbor-gen v0.0.0-20190917003517-d78d67427694/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
|
||||||
github.com/whyrusleeping/cbor-gen v0.0.0-20191116002219-891f55cd449d/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
github.com/whyrusleeping/cbor-gen v0.0.0-20191116002219-891f55cd449d/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
||||||
github.com/whyrusleeping/cbor-gen v0.0.0-20191212224538-d370462a7e8a/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
github.com/whyrusleeping/cbor-gen v0.0.0-20191212224538-d370462a7e8a/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
||||||
github.com/whyrusleeping/cbor-gen v0.0.0-20191216205031-b047b6acb3c0/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
github.com/whyrusleeping/cbor-gen v0.0.0-20191216205031-b047b6acb3c0/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
||||||
|
|
||||||
package statemachine
|
package statemachine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -8,8 +10,6 @@ import (
|
|||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
var _ = xerrors.Errorf
|
var _ = xerrors.Errorf
|
||||||
|
|
||||||
func (t *TestState) MarshalCBOR(w io.Writer) error {
|
func (t *TestState) MarshalCBOR(w io.Writer) error {
|
||||||
|
@ -221,7 +221,7 @@ func (c *ClientNodeAdapter) ValidatePublishedDeal(ctx context.Context, deal stor
|
|||||||
func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealId uint64, cb storagemarket.DealSectorCommittedCallback) error {
|
func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealId uint64, cb storagemarket.DealSectorCommittedCallback) error {
|
||||||
checkFunc := func(ts *types.TipSet) (done bool, more bool, err error) {
|
checkFunc := func(ts *types.TipSet) (done bool, more bool, err error) {
|
||||||
sd, err := stmgr.GetStorageDeal(ctx, c.StateManager, dealId, ts)
|
sd, err := stmgr.GetStorageDeal(ctx, c.StateManager, dealId, ts)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: This may be fine for some errors
|
// TODO: This may be fine for some errors
|
||||||
return false, false, xerrors.Errorf("failed to look up deal on chain: %w", err)
|
return false, false, xerrors.Errorf("failed to look up deal on chain: %w", err)
|
||||||
|
@ -98,15 +98,15 @@ func (n *ProviderNodeAdapter) PublishDeals(ctx context.Context, deal storagemark
|
|||||||
return storagemarket.DealID(resp.DealIDs[0]), smsg.Cid(), nil
|
return storagemarket.DealID(resp.DealIDs[0]), smsg.Cid(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagemarket.MinerDeal, pieceSize uint64, pieceData io.Reader) (uint64, error) {
|
func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagemarket.MinerDeal, pieceSize uint64, pieceData io.Reader) error {
|
||||||
|
|
||||||
sectorID, err := n.secb.AddPiece(ctx, pieceSize, pieceData, deal.DealID)
|
_, err := n.secb.AddPiece(ctx, pieceSize, pieceData, deal.DealID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, xerrors.Errorf("AddPiece failed: %s", err)
|
return xerrors.Errorf("AddPiece failed: %s", err)
|
||||||
}
|
}
|
||||||
log.Warnf("New Sector: %d (deal %d)", sectorID, deal.DealID)
|
log.Warnf("New Deal: deal %d", deal.DealID)
|
||||||
|
|
||||||
return sectorID, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ProviderNodeAdapter) ListProviderDeals(ctx context.Context, addr address.Address) ([]storagemarket.StorageDeal, error) {
|
func (n *ProviderNodeAdapter) ListProviderDeals(ctx context.Context, addr address.Address) ([]storagemarket.StorageDeal, error) {
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-amt-ipld"
|
"github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
"github.com/ipfs/go-blockservice"
|
"github.com/ipfs/go-blockservice"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-hamt-ipld"
|
"github.com/ipfs/go-hamt-ipld"
|
||||||
@ -241,7 +241,7 @@ func resolveOnce(bs blockstore.Blockstore) func(ctx context.Context, ds ipld.Nod
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(names[0], "@A:") {
|
if strings.HasPrefix(names[0], "@A:") {
|
||||||
a, err := amt.LoadAMT(amt.WrapBlockstore(bs), nd.Cid())
|
a, err := amt.LoadAMT(ctx, cbor.NewCborStore(bs), nd.Cid())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, xerrors.Errorf("load amt: %w", err)
|
return nil, nil, xerrors.Errorf("load amt: %w", err)
|
||||||
}
|
}
|
||||||
@ -252,7 +252,7 @@ func resolveOnce(bs blockstore.Blockstore) func(ctx context.Context, ds ipld.Nod
|
|||||||
}
|
}
|
||||||
|
|
||||||
var m interface{}
|
var m interface{}
|
||||||
if err := a.Get(idx, &m); err != nil {
|
if err := a.Get(ctx, idx, &m); err != nil {
|
||||||
return nil, nil, xerrors.Errorf("amt get: %w", err)
|
return nil, nil, xerrors.Errorf("amt get: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("AG %T %v\n", m, m)
|
fmt.Printf("AG %T %v\n", m, m)
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-amt-ipld"
|
"github.com/filecoin-project/go-amt-ipld/v2"
|
||||||
|
|
||||||
cid "github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-hamt-ipld"
|
"github.com/ipfs/go-hamt-ipld"
|
||||||
@ -280,13 +280,13 @@ func (a *StateAPI) StateMarketDeals(ctx context.Context, ts *types.TipSet) (map[
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
blks := amt.WrapBlockstore(a.StateManager.ChainStore().Blockstore())
|
blks := cbor.NewCborStore(a.StateManager.ChainStore().Blockstore())
|
||||||
da, err := amt.LoadAMT(blks, state.Deals)
|
da, err := amt.LoadAMT(ctx, blks, state.Deals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := da.ForEach(func(i uint64, v *cbg.Deferred) error {
|
if err := da.ForEach(ctx, func(i uint64, v *cbg.Deferred) error {
|
||||||
var d actors.OnChainDeal
|
var d actors.OnChainDeal
|
||||||
if err := d.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil {
|
if err := d.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
graphsyncimpl "github.com/filecoin-project/go-data-transfer/impl/graphsync"
|
graphsyncimpl "github.com/filecoin-project/go-data-transfer/impl/graphsync"
|
||||||
piecefilestore "github.com/filecoin-project/go-fil-markets/filestore"
|
|
||||||
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
||||||
"github.com/filecoin-project/go-fil-markets/retrievalmarket/discovery"
|
"github.com/filecoin-project/go-fil-markets/retrievalmarket/discovery"
|
||||||
retrievalimpl "github.com/filecoin-project/go-fil-markets/retrievalmarket/impl"
|
retrievalimpl "github.com/filecoin-project/go-fil-markets/retrievalmarket/impl"
|
||||||
@ -14,6 +13,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||||
deals "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
|
deals "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
|
||||||
storageimpl "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
|
storageimpl "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
|
||||||
|
smnet "github.com/filecoin-project/go-fil-markets/storagemarket/network"
|
||||||
"github.com/filecoin-project/go-statestore"
|
"github.com/filecoin-project/go-statestore"
|
||||||
"github.com/ipfs/go-bitswap"
|
"github.com/ipfs/go-bitswap"
|
||||||
"github.com/ipfs/go-bitswap/network"
|
"github.com/ipfs/go-bitswap/network"
|
||||||
@ -111,12 +111,9 @@ func NewClientRequestValidator(deals dtypes.ClientDealStore) *storageimpl.Client
|
|||||||
return storageimpl.NewClientRequestValidator(deals)
|
return storageimpl.NewClientRequestValidator(deals)
|
||||||
}
|
}
|
||||||
|
|
||||||
func StorageClient(h host.Host, ibs dtypes.ClientBlockstore, r repo.LockedRepo, dataTransfer dtypes.ClientDataTransfer, discovery *discovery.Local, deals dtypes.ClientDealStore, scn storagemarket.StorageClientNode) (storagemarket.StorageClient, error) {
|
func StorageClient(h host.Host, ibs dtypes.ClientBlockstore, r repo.LockedRepo, dataTransfer dtypes.ClientDataTransfer, discovery *discovery.Local, deals dtypes.ClientDealStore, scn storagemarket.StorageClientNode) storagemarket.StorageClient {
|
||||||
store, err := piecefilestore.NewLocalFileStore(piecefilestore.OsPath(r.Path()))
|
net := smnet.NewFromLibp2pHost(h)
|
||||||
if err != nil {
|
return storageimpl.NewClient(net, ibs, dataTransfer, discovery, deals, scn)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return storageimpl.NewClient(h, ibs, store, dataTransfer, discovery, deals, scn), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrievalClient creates a new retrieval client attached to the client blockstore
|
// RetrievalClient creates a new retrieval client attached to the client blockstore
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||||
deals "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
|
deals "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
|
||||||
storageimpl "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
|
storageimpl "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
|
||||||
|
smnet "github.com/filecoin-project/go-fil-markets/storagemarket/network"
|
||||||
paramfetch "github.com/filecoin-project/go-paramfetch"
|
paramfetch "github.com/filecoin-project/go-paramfetch"
|
||||||
"github.com/filecoin-project/go-sectorbuilder"
|
"github.com/filecoin-project/go-sectorbuilder"
|
||||||
"github.com/filecoin-project/go-sectorbuilder/fs"
|
"github.com/filecoin-project/go-sectorbuilder/fs"
|
||||||
@ -152,7 +153,7 @@ func HandleDeals(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, h sto
|
|||||||
|
|
||||||
lc.Append(fx.Hook{
|
lc.Append(fx.Hook{
|
||||||
OnStart: func(context.Context) error {
|
OnStart: func(context.Context) error {
|
||||||
h.Run(ctx, host)
|
h.Start(ctx)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
OnStop: func(context.Context) error {
|
OnStop: func(context.Context) error {
|
||||||
@ -292,12 +293,21 @@ func NewProviderRequestValidator(deals dtypes.ProviderDealStore) *storageimpl.Pr
|
|||||||
return storageimpl.NewProviderRequestValidator(deals)
|
return storageimpl.NewProviderRequestValidator(deals)
|
||||||
}
|
}
|
||||||
|
|
||||||
func StorageProvider(ds dtypes.MetadataDS, ibs dtypes.StagingBlockstore, r repo.LockedRepo, pieceStore dtypes.ProviderPieceStore, dataTransfer dtypes.ProviderDataTransfer, spn storagemarket.StorageProviderNode) (storagemarket.StorageProvider, error) {
|
func StorageProvider(h host.Host, ds dtypes.MetadataDS, ibs dtypes.StagingBlockstore, r repo.LockedRepo, pieceStore dtypes.ProviderPieceStore, dataTransfer dtypes.ProviderDataTransfer, spn storagemarket.StorageProviderNode) (storagemarket.StorageProvider, error) {
|
||||||
store, err := piecefilestore.NewLocalFileStore(piecefilestore.OsPath(r.Path()))
|
store, err := piecefilestore.NewLocalFileStore(piecefilestore.OsPath(r.Path()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return storageimpl.NewProvider(ds, ibs, store, pieceStore, dataTransfer, spn)
|
net := smnet.NewFromLibp2pHost(h)
|
||||||
|
addr, err := ds.Get(datastore.NewKey("miner-address"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
minerAddress, err := address.NewFromBytes(addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return storageimpl.NewProvider(net, ds, ibs, store, pieceStore, dataTransfer, spn, minerAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrievalProvider creates a new retrieval provider attached to the provider blockstore
|
// RetrievalProvider creates a new retrieval provider attached to the provider blockstore
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
||||||
|
|
||||||
package paych
|
package paych
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -9,8 +11,6 @@ import (
|
|||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
var _ = xerrors.Errorf
|
var _ = xerrors.Errorf
|
||||||
|
|
||||||
func (t *VoucherInfo) MarshalCBOR(w io.Writer) error {
|
func (t *VoucherInfo) MarshalCBOR(w io.Writer) error {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
||||||
|
|
||||||
package sealing
|
package sealing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -8,8 +10,6 @@ import (
|
|||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
var _ = xerrors.Errorf
|
var _ = xerrors.Errorf
|
||||||
|
|
||||||
func (t *SealTicket) MarshalCBOR(w io.Writer) error {
|
func (t *SealTicket) MarshalCBOR(w io.Writer) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user