squash forks and use correct amt library everywhere

This commit is contained in:
whyrusleeping 2020-02-04 18:26:42 -08:00
parent c013ef3b30
commit faf05cafcf
29 changed files with 214 additions and 1250 deletions

View File

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

View File

@ -1,9 +1 @@
package build package build
const ForkBlizzardHeight = 6288
const ForkFrigidHeight = 7950
const ForkBootyBayHeight = 11000
const ForkMissingSnowballs = 34000

View File

@ -1,29 +1,17 @@
package actors package actors
import ( import (
"bytes"
"context"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"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/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"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
) )
type StorageMinerActor struct{}
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,31 +121,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) { func loadState(vmctx types.VMContext) (cid.Cid, *StorageMinerActorState, ActorError) {
var self StorageMinerActorState var self StorageMinerActorState
oldstate := vmctx.Storage().GetHead() oldstate := vmctx.Storage().GetHead()
@ -177,105 +140,6 @@ func loadMinerInfo(vmctx types.VMContext, m *StorageMinerActorState) (*MinerInfo
return &mi, nil return &mi, nil
} }
func (sma StorageMinerActor) 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 := amt.NewAMT(types.WrapStorage(vmctx.Storage()))
scid, serr := sectors.Flush()
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 StorageMinerActor) 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 uintToStringKey(i uint64) string { func uintToStringKey(i uint64) string {
buf := make([]byte, 10) buf := make([]byte, 10)
n := binary.PutUvarint(buf, i) n := binary.PutUvarint(buf, i)
@ -288,121 +152,6 @@ type SectorProveCommitInfo struct {
DealIDs []uint64 DealIDs []uint64
} }
func (sma StorageMinerActor) 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 := AddToSectorSet(ctx, types.WrapStorage(vmctx.Storage()), 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 := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), 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 truncateHexPrint(b []byte) string { func truncateHexPrint(b []byte) string {
s := fmt.Sprintf("%x", b) s := fmt.Sprintf("%x", b)
if len(s) > 60 { if len(s) > 60 {
@ -416,228 +165,6 @@ type SubmitFallbackPoStParams struct {
Candidates []types.EPostTicket Candidates []types.EPostTicket
} }
func (sma StorageMinerActor) 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 := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
if lerr != nil {
return nil, aerrors.HandleExternalError(lerr, "could not load proving set node")
}
ss, lerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), 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(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 := onSuccessfulPoSt(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 StorageMinerActor) 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 SectorIsUnique(ctx context.Context, s types.Storage, sroot cid.Cid, sid uint64) (bool, ActorError) {
found, _, _, err := GetFromSectorSet(ctx, s, sroot, sid)
if err != nil {
return false, err
}
return !found, nil
}
func AddToSectorSet(ctx context.Context, blks amt.Blocks, 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(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(sectorID, [][]byte{commR, commD}); err != nil {
return cid.Undef, aerrors.HandleExternalError(err, "failed to set commitment in sector set")
}
ncid, err := ssr.Flush()
if err != nil {
return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set")
}
return ncid, nil
}
func GetFromSectorSet(ctx context.Context, s types.Storage, 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(types.WrapStorage(s), ss)
if err != nil {
return false, nil, nil, aerrors.HandleExternalError(err, "could not load sector set node")
}
var comms [][]byte
err = ssr.Get(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 RemoveFromSectorSet(ctx context.Context, s types.Storage, ss cid.Cid, ids []uint64) (cid.Cid, aerrors.ActorError) {
ssr, err := amt.LoadAMT(types.WrapStorage(s), ss)
if err != nil {
return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node")
}
for _, id := range ids {
if err := ssr.Delete(id); err != nil {
log.Warnf("failed to delete sector %d from set: %s", id, err)
}
}
ncid, err := ssr.Flush()
if err != nil {
return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set")
}
return ncid, nil
}
func CollateralForPower(power types.BigInt) types.BigInt { func CollateralForPower(power types.BigInt) types.BigInt {
return types.BigMul(power, types.NewInt(10)) return types.BigMul(power, types.NewInt(10))
/* TODO: this /* TODO: this
@ -651,403 +178,28 @@ func CollateralForPower(power types.BigInt) types.BigInt {
*/ */
} }
func (sma StorageMinerActor) 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 StorageMinerActor) 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 StorageMinerActor) 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
}
type UpdatePeerIDParams struct { type UpdatePeerIDParams struct {
PeerID peer.ID PeerID peer.ID
} }
func (sma StorageMinerActor) 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 StorageMinerActor) 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 isLate(height uint64, self *StorageMinerActorState) bool { func isLate(height uint64, self *StorageMinerActorState) bool {
return self.ElectionPeriodStart > 0 && height >= self.ElectionPeriodStart+build.SlashablePowerDelay return self.ElectionPeriodStart > 0 && height >= self.ElectionPeriodStart+build.SlashablePowerDelay
} }
func (sma StorageMinerActor) 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
}
type CheckMinerParams struct { type CheckMinerParams struct {
NetworkPower types.BigInt NetworkPower types.BigInt
} }
// TODO: better name
func (sma StorageMinerActor) 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()
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 := self.Power.MarshalCBOR(&out); err != nil {
return nil, aerrors.HandleExternalError(err, "marshaling return value")
}
return out.Bytes(), nil
}
type DeclareFaultsParams struct { type DeclareFaultsParams struct {
Faults types.BitField Faults types.BitField
} }
func (sma StorageMinerActor) 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 := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), 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
}
type MinerSlashConsensusFault struct { type MinerSlashConsensusFault struct {
Slasher address.Address Slasher address.Address
AtHeight uint64 AtHeight uint64
SlashedCollateral types.BigInt SlashedCollateral types.BigInt
} }
func (sma StorageMinerActor) 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")
}
// 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 StorageMinerActor) SubmitElectionPoSt(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) {
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 := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
if nerr != nil {
return nil, aerrors.HandleExternalError(nerr, "failed to load proving set")
}
ss, nerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), 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 > amt.MaxIndex {
continue
}
var comms [][]byte
err := pss.Get(f, &comms)
if err != nil {
var notfound *amt.ErrNotFound
if !xerrors.As(err, &notfound) {
return nil, aerrors.HandleExternalError(err, "failed to find sector in sector set")
}
continue
}
activeFaults++
}
if err := onSuccessfulPoSt(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 onSuccessfulPoSt(self *StorageMinerActorState, vmctx types.VMContext, activeFaults uint64) aerrors.ActorError {
// TODO: some sector upkeep stuff that is very haphazard and unclear in the spec
var mi MinerInfo
if err := vmctx.Storage().Get(self.Info, &mi); err != nil {
return err
}
pss, nerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
if nerr != nil {
return aerrors.HandleExternalError(nerr, "failed to load proving set")
}
ss, nerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), 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()
}
ncid, err := RemoveFromSectorSet(vmctx.Context(), vmctx.Storage(), self.Sectors, faults)
if err != nil {
return err
}
self.Sectors = ncid
self.ProvingSet = ncid
return nil
}
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}

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
ffi "github.com/filecoin-project/filecoin-ffi" ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-amt-ipld/v2"
amt2 "github.com/filecoin-project/go-amt-ipld/v2" amt2 "github.com/filecoin-project/go-amt-ipld/v2"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
@ -19,9 +20,9 @@ import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
) )
type StorageMinerActor2 struct{} type StorageMinerActor struct{}
func (sma StorageMinerActor2) Exports() []interface{} { func (sma StorageMinerActor) Exports() []interface{} {
return []interface{}{ return []interface{}{
1: sma.StorageMinerConstructor, 1: sma.StorageMinerConstructor,
2: sma.PreCommitSector, 2: sma.PreCommitSector,
@ -33,10 +34,7 @@ func (sma StorageMinerActor2) Exports() []interface{} {
//8: sma.DePledge, //8: sma.DePledge,
9: sma.GetOwner, 9: sma.GetOwner,
10: sma.GetWorkerAddr, 10: sma.GetWorkerAddr,
11: withUpdates( 11: sma.GetPower,
update{0, sma.GetPower},
update{build.ForkMissingSnowballs, sma.GetPower2},
), // FORK
12: sma.GetPeerID, 12: sma.GetPeerID,
13: sma.GetSectorSize, 13: sma.GetSectorSize,
14: sma.UpdatePeerID, 14: sma.UpdatePeerID,
@ -49,7 +47,7 @@ func (sma StorageMinerActor2) Exports() []interface{} {
} }
} }
func (sma StorageMinerActor2) 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,
Worker: params.Worker, Worker: params.Worker,
@ -86,7 +84,7 @@ func (sma StorageMinerActor2) StorageMinerConstructor(act *types.Actor, vmctx ty
return nil, nil return nil, nil
} }
func (sma StorageMinerActor2) 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)
@ -112,7 +110,7 @@ func (sma StorageMinerActor2) PreCommitSector(act *types.Actor, vmctx types.VMCo
} }
// 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
} }
@ -149,7 +147,7 @@ func (sma StorageMinerActor2) PreCommitSector(act *types.Actor, vmctx types.VMCo
return nil, nil return nil, nil
} }
func (sma StorageMinerActor2) 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)
if err != nil { if err != nil {
@ -264,7 +262,7 @@ func (sma StorageMinerActor2) ProveCommitSector(act *types.Actor, vmctx types.VM
return nil, aerrors.Wrapf(err, "calling ActivateStorageDeals failed") return nil, aerrors.Wrapf(err, "calling ActivateStorageDeals failed")
} }
func (sma StorageMinerActor2) 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 {
return nil, err return nil, err
@ -399,16 +397,7 @@ func (sma StorageMinerActor2) SubmitFallbackPoSt(act *types.Actor, vmctx types.V
return nil, nil return nil, nil
} }
func (sma StorageMinerActor2) GetPower(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) { func (sma StorageMinerActor) 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) _, self, err := loadState(vmctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -500,7 +489,7 @@ func RemoveFromSectorSet2(ctx context.Context, cst cbor.IpldStore, ss cid.Cid, i
return ncid, nil return ncid, nil
} }
func (sma StorageMinerActor2) 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 {
return nil, err return nil, err
@ -514,7 +503,7 @@ func (sma StorageMinerActor2) GetWorkerAddr(act *types.Actor, vmctx types.VMCont
return mi.Worker.Bytes(), nil return mi.Worker.Bytes(), nil
} }
func (sma StorageMinerActor2) GetOwner(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) { func (sma StorageMinerActor) GetOwner(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
_, self, err := loadState(vmctx) _, self, err := loadState(vmctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -528,7 +517,7 @@ func (sma StorageMinerActor2) GetOwner(act *types.Actor, vmctx types.VMContext,
return mi.Owner.Bytes(), nil return mi.Owner.Bytes(), nil
} }
func (sma StorageMinerActor2) GetPeerID(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) { func (sma StorageMinerActor) GetPeerID(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
_, self, err := loadState(vmctx) _, self, err := loadState(vmctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -542,7 +531,7 @@ func (sma StorageMinerActor2) GetPeerID(act *types.Actor, vmctx types.VMContext,
return []byte(mi.PeerID), nil return []byte(mi.PeerID), nil
} }
func (sma StorageMinerActor2) 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 {
return nil, err return nil, err
@ -578,7 +567,7 @@ func (sma StorageMinerActor2) UpdatePeerID(act *types.Actor, vmctx types.VMConte
return nil, nil return nil, nil
} }
func (sma StorageMinerActor2) GetSectorSize(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) { func (sma StorageMinerActor) GetSectorSize(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
_, self, err := loadState(vmctx) _, self, err := loadState(vmctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -592,7 +581,7 @@ func (sma StorageMinerActor2) GetSectorSize(act *types.Actor, vmctx types.VMCont
return types.NewInt(mi.SectorSize).Bytes(), nil return types.NewInt(mi.SectorSize).Bytes(), nil
} }
func (sma StorageMinerActor2) 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 {
return nil, err return nil, err
@ -602,7 +591,7 @@ func (sma StorageMinerActor2) IsSlashed(act *types.Actor, vmctx types.VMContext,
} }
// TODO: better name // TODO: better name
func (sma StorageMinerActor2) 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 {
return nil, aerrors.New(2, "only the storage power actor can check miner") return nil, aerrors.New(2, "only the storage power actor can check miner")
} }
@ -633,10 +622,7 @@ func (sma StorageMinerActor2) CheckMiner(act *types.Actor, vmctx types.VMContext
self.SlashedAt = vmctx.BlockHeight() self.SlashedAt = vmctx.BlockHeight()
oldPower := self.Power oldPower := self.Power
self.Power = types.NewInt(0)
if vmctx.BlockHeight() > build.ForkMissingSnowballs {
self.Power = types.NewInt(0)
}
nstate, err := vmctx.Storage().Put(self) nstate, err := vmctx.Storage().Put(self)
if err != nil { if err != nil {
@ -653,7 +639,7 @@ func (sma StorageMinerActor2) CheckMiner(act *types.Actor, vmctx types.VMContext
return out.Bytes(), nil return out.Bytes(), nil
} }
func (sma StorageMinerActor2) 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 {
return nil, aerr return nil, aerr
@ -702,7 +688,7 @@ func (sma StorageMinerActor2) DeclareFaults(act *types.Actor, vmctx types.VMCont
return nil, nil return nil, nil
} }
func (sma StorageMinerActor2) 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")
} }
@ -732,21 +718,19 @@ func (sma StorageMinerActor2) SlashConsensusFault(act *types.Actor, vmctx types.
return nil, aerrors.Wrap(err, "failed to burn funds") return nil, aerrors.Wrap(err, "failed to burn funds")
} }
if vmctx.BlockHeight() > build.ForkMissingSnowballs { oldstate, self, err := loadState(vmctx)
oldstate, self, err := loadState(vmctx) if err != nil {
if err != nil { return nil, aerrors.Wrap(err, "failed to load state for slashing")
return nil, aerrors.Wrap(err, "failed to load state for slashing") }
}
self.Power = types.NewInt(0) self.Power = types.NewInt(0)
ncid, err := vmctx.Storage().Put(self) ncid, err := vmctx.Storage().Put(self)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := vmctx.Storage().Commit(oldstate, ncid); err != nil { if err := vmctx.Storage().Commit(oldstate, ncid); err != nil {
return nil, err 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,
@ -759,7 +743,7 @@ func (sma StorageMinerActor2) SlashConsensusFault(act *types.Actor, vmctx types.
return nil, nil return nil, nil
} }
func (sma StorageMinerActor2) 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() ctx := vmctx.Context()
if vmctx.Message().From != NetworkAddress { if vmctx.Message().From != NetworkAddress {
@ -826,10 +810,6 @@ func (sma StorageMinerActor2) SubmitElectionPoSt(act *types.Actor, vmctx types.V
func onSuccessfulPoSt2(self *StorageMinerActorState, vmctx types.VMContext, activeFaults uint64) aerrors.ActorError { func onSuccessfulPoSt2(self *StorageMinerActorState, vmctx types.VMContext, activeFaults uint64) aerrors.ActorError {
ctx := vmctx.Context() ctx := vmctx.Context()
// FORK
if vmctx.BlockHeight() < build.ForkBootyBayHeight {
return onSuccessfulPoSt(self, vmctx, activeFaults)
}
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 {
@ -905,3 +885,61 @@ func onSuccessfulPoSt2(self *StorageMinerActorState, vmctx types.VMContext, acti
self.ProvingSet = ncid self.ProvingSet = ncid
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
}

View File

@ -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"
@ -313,7 +313,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")
} }
@ -344,7 +344,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,
@ -366,7 +366,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")
} }
@ -450,20 +450,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")
} }
@ -485,12 +486,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")
} }
@ -515,13 +516,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")
} }
@ -538,7 +540,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")
} }
@ -612,13 +614,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")
} }
@ -630,7 +633,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")
} }

View File

@ -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"
@ -86,11 +86,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,
@ -145,19 +141,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)
@ -299,6 +284,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 {
@ -331,7 +317,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")
} }
@ -348,7 +334,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")
} }
@ -366,8 +352,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")
@ -395,7 +382,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")
} }
@ -404,9 +391,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())
@ -434,7 +422,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")
} }
@ -627,15 +615,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
@ -660,16 +649,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()))
@ -705,18 +691,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")
} }

View File

@ -92,7 +92,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,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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"
@ -209,7 +209,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)
@ -276,7 +276,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")
} }
@ -324,18 +324,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,
}) })
@ -764,7 +765,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 {
@ -795,17 +795,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,
}) })
@ -1075,7 +1075,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)]

View File

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

View File

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

View File

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

View File

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

4
go.mod
View File

@ -33,7 +33,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
@ -114,3 +114,5 @@ replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
replace github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 v22.0.0 replace github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 v22.0.0
replace github.com/filecoin-project/go-fil-markets => ../go-fil-markets

4
go.sum
View File

@ -115,6 +115,8 @@ github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce
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-20200124235616-d94a1cf0beaa h1:45LCzmHF2NZuYYFOmJ/MQ5SRDXw4QApQvT4BJzVysV8=
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-20200124235616-d94a1cf0beaa/go.mod h1:hbYlEmbOg9QwhZ71B724oAgXQ0wnoWHj8S+33q9lrm8=
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=
@ -221,6 +223,8 @@ github.com/ipfs/go-blockservice v0.1.3-0.20190908200855-f22eea50656c h1:lN5IQA07
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.20200124090545-1a340009d896 h1:l8gnU1VBhftugMKzfh+n7nuDhOw3X1iqfrA33GVBMMY=
github.com/ipfs/go-car v0.0.3-0.20200124090545-1a340009d896/go.mod h1:rmd887mJxQRDfndfDEY3Liyx8gQVyfFFRSHdsnDSAlk= 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 h1:mYq7vJKGUzxIkkYfqXfO0uEO8gOmV9F38Tcpvi/p8P8=
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=

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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