diff --git a/chain/actors/actor_cron.go b/chain/actors/actor_cron.go index f0be6a439..39190e42d 100644 --- a/chain/actors/actor_cron.go +++ b/chain/actors/actor_cron.go @@ -1,48 +1,9 @@ package actors import ( - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/lotus/chain/actors/aerrors" - "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/specs-actors/actors/builtin/cron" ) -type CronActor struct{} +type CronActor = cron.Actor -type callTuple struct { - addr address.Address - method uint64 -} - -var CronActors = []callTuple{ - {StoragePowerAddress, SPAMethods.CheckProofSubmissions}, -} - -type CronActorState struct{} - -type cAMethods struct { - EpochTick uint64 -} - -var CAMethods = cAMethods{2} - -func (ca CronActor) Exports() []interface{} { - return []interface{}{ - 1: nil, - 2: ca.EpochTick, - } -} - -func (ca CronActor) EpochTick(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) { - if vmctx.Message().From != CronAddress { - return nil, aerrors.New(1, "EpochTick is only callable as a part of tipset state computation") - } - - for _, call := range CronActors { - _, err := vmctx.Send(call.addr, call.method, types.NewInt(0), nil) - if err != nil { - return nil, err // todo: this very bad? - } - } - - return nil, nil -} +type CronActorState = cron.State diff --git a/chain/actors/actor_miner.go b/chain/actors/actor_miner.go index 284aa3c6c..28a60d99f 100644 --- a/chain/actors/actor_miner.go +++ b/chain/actors/actor_miner.go @@ -1,1062 +1,9 @@ package actors import ( - "bytes" - "context" - "encoding/binary" - "fmt" - - ffi "github.com/filecoin-project/filecoin-ffi" - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-amt-ipld/v2" - amt2 "github.com/filecoin-project/go-amt-ipld/v2" - "github.com/filecoin-project/specs-actors/actors/abi" - "github.com/libp2p/go-libp2p-core/peer" - - "github.com/filecoin-project/go-sectorbuilder" - "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/actors/aerrors" - "github.com/filecoin-project/lotus/chain/types" - - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - cbg "github.com/whyrusleeping/cbor-gen" - "golang.org/x/xerrors" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) -type StorageMinerActor struct{} +type StorageMinerActor = miner.Actor -func (sma StorageMinerActor) Exports() []interface{} { - return []interface{}{ - 1: sma.StorageMinerConstructor, - 2: sma.PreCommitSector, - 3: sma.ProveCommitSector, - 4: sma.SubmitFallbackPoSt, - //5: sma.SlashStorageFault, - //6: sma.GetCurrentProvingSet, - //7: sma.ArbitrateDeal, - //8: sma.DePledge, - 9: sma.GetOwner, - 10: sma.GetWorkerAddr, - 11: sma.GetPower, - 12: sma.GetPeerID, - 13: sma.GetSectorSize, - 14: sma.UpdatePeerID, - //15: sma.ChangeWorker, - 16: sma.IsSlashed, - 17: sma.CheckMiner, - 18: sma.DeclareFaults, - 19: sma.SlashConsensusFault, - 20: sma.SubmitElectionPoSt, - } -} - -type StorageMinerActorState struct { - // PreCommittedSectors is the set of sectors that have been committed to but not - // yet had their proofs submitted - PreCommittedSectors map[string]*PreCommittedSector - - // All sectors this miner has committed. - // - // AMT[sectorID]ffi.PublicSectorInfo - Sectors cid.Cid - - // TODO: Spec says 'StagedCommittedSectors', which one is it? - - // Sectors this miner is currently mining. It is only updated - // when a PoSt is submitted (not as each new sector commitment is added). - // - // AMT[sectorID]ffi.PublicSectorInfo - ProvingSet cid.Cid - - // TODO: these: - // SectorTable - // SectorExpirationQueue - // ChallengeStatus - - // Contains mostly static info about this miner - Info cid.Cid - - // Faulty sectors reported since last SubmitPost - FaultSet types.BitField - - LastFaultSubmission uint64 - - // Amount of power this miner has. - Power types.BigInt - - // Active is set to true after the miner has submitted their first PoSt - Active bool - - // The height at which this miner was slashed at. - SlashedAt uint64 - - ElectionPeriodStart abi.ChainEpoch -} - -// 46356: - -type MinerInfo struct { - // Account that owns this miner. - // - Income and returned collateral are paid to this address. - // - This address is also allowed to change the worker address for the miner. - Owner address.Address - - // Worker account for this miner. - // This will be the key that is used to sign blocks created by this miner, and - // sign messages sent on behalf of this miner to commit sectors, submit PoSts, and - // other day to day miner activities. - Worker address.Address - - // Libp2p identity that should be used when connecting to this miner. - PeerID peer.ID - - // Amount of space in each sector committed to the network by this miner. - SectorSize abi.SectorSize - - // SubsectorCount -} - -type PreCommittedSector struct { - Info SectorPreCommitInfo - ReceivedEpoch uint64 -} - -type StorageMinerConstructorParams struct { - Owner address.Address - Worker address.Address - SectorSize abi.SectorSize - PeerID peer.ID -} - -type SectorPreCommitInfo struct { - SectorNumber abi.SectorNumber - - CommR []byte // TODO: Spec says CID - SealEpoch uint64 - DealIDs []uint64 -} - -type maMethods struct { - Constructor uint64 - PreCommitSector uint64 - ProveCommitSector uint64 - SubmitFallbackPoSt uint64 - SlashStorageFault uint64 - GetCurrentProvingSet uint64 - ArbitrateDeal uint64 - DePledge uint64 - GetOwner uint64 - GetWorkerAddr uint64 - GetPower uint64 - GetPeerID uint64 - GetSectorSize uint64 - UpdatePeerID uint64 - ChangeWorker uint64 - IsSlashed uint64 - CheckMiner uint64 - DeclareFaults uint64 - SlashConsensusFault uint64 - SubmitElectionPoSt uint64 -} - -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) StorageMinerConstructor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) ([]byte, ActorError) { - minerInfo := &MinerInfo{ - Owner: params.Owner, - Worker: params.Worker, - PeerID: params.PeerID, - SectorSize: params.SectorSize, - } - - minfocid, err := vmctx.Storage().Put(minerInfo) - if err != nil { - return nil, err - } - - var self StorageMinerActorState - sectors := amt2.NewAMT(vmctx.Ipld()) - scid, serr := sectors.Flush(context.TODO()) - if serr != nil { - return nil, aerrors.HandleExternalError(serr, "initializing AMT") - } - - self.Sectors = scid - self.ProvingSet = scid - self.Info = minfocid - - storage := vmctx.Storage() - c, err := storage.Put(&self) - if err != nil { - return nil, err - } - - if err := storage.Commit(EmptyCBOR, c); err != nil { - return nil, err - } - - return nil, nil -} - -func (sma 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 >= uint64(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 uint64(vmctx.BlockHeight())-params.SealEpoch+build.SealRandomnessLookback > build.SealRandomnessLookbackLimit { - return nil, aerrors.Newf(2, "sector commitment must be recent enough (was %d)", uint64(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.Ipld(), self.Sectors, uint64(params.SectorNumber)) - if err != nil { - return nil, err - } - if !unique { - return nil, aerrors.New(3, "sector already committed!") - } - - - self.PreCommittedSectors[uintToStringKey(uint64(params.SectorNumber))] = &PreCommittedSector{ - Info: *params, - ReceivedEpoch: uint64(vmctx.BlockHeight()), - } - - if len(self.PreCommittedSectors) > 4096 { - return nil, aerrors.New(5, "too many precommitted sectors") - } - - nstate, err := vmctx.Storage().Put(self) - if err != nil { - return nil, err - } - if err := vmctx.Storage().Commit(oldstate, nstate); err != nil { - return nil, err - } - - return nil, nil -} - -func (sma 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(uint64(params.SectorID))] - if !ok { - return nil, aerrors.New(1, "no pre-commitment found for sector") - } - - if us.ReceivedEpoch+build.InteractivePoRepDelay >= uint64(vmctx.BlockHeight()) { - return nil, aerrors.New(2, "too early for proof submission") - } - - delete(self.PreCommittedSectors, uintToStringKey(uint64(params.SectorID))) - - // TODO: ensure normalization to ID address - maddr := vmctx.Message().To - - if uint64(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 uint64(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(abi.ChainEpoch(0)) - if err != nil { - return nil, aerrors.Wrap(err, "failed to get ticket randomness") - } - - seed, err := vmctx.GetRandomness(abi.ChainEpoch(0)) - if err != nil { - return nil, aerrors.Wrap(err, "failed to get randomness for prove sector commitment") - } - - enc, err := SerializeParams(&ComputeDataCommitmentParams{ - DealIDs: params.DealIDs, - SectorSize: abi.SectorSize(mi.SectorSize), - }) - if err != nil { - return nil, aerrors.Wrap(err, "failed to serialize ComputeDataCommitmentParams") - } - - commD, err := vmctx.Send(StorageMarketAddress, SMAMethods.ComputeDataCommitment, types.NewInt(0), enc) - if err != nil { - return nil, aerrors.Wrapf(err, "failed to compute data commitment (sector %d, deals: %v)", params.SectorID, params.DealIDs) - } - - if ok, err := vmctx.Sys().ValidatePoRep(ctx, maddr, mi.SectorSize, commD, us.Info.CommR, ticket, params.Proof, seed, params.SectorID); err != nil { - return nil, err - } else if !ok { - return nil, aerrors.Newf(2, "porep proof was invalid (t:%x; s:%x(%d); p:%s)", ticket, seed, us.ReceivedEpoch+build.InteractivePoRepDelay, truncateHexPrint(params.Proof)) - } - - // Note: There must exist a unique index in the miner's sector set for each - // sector ID. The `faults`, `recovered`, and `done` parameters of the - // SubmitPoSt method express indices into this sector set. - nssroot, err := AddToSectorSet2(ctx, vmctx.Ipld(), self.Sectors, uint64(params.SectorID), us.Info.CommR, commD) - if err != nil { - return nil, err - } - self.Sectors = nssroot - - // if miner is not mining, start their proving period now - // Note: As written here, every miners first PoSt will only be over one sector. - // We could set up a 'grace period' for starting mining that would allow miners - // to submit several sectors for their first proving period. Alternatively, we - // could simply make the 'PreCommitSector' call take multiple sectors at a time. - // - // Note: Proving period is a function of sector size; small sectors take less - // time to prove than large sectors do. Sector size is selected when pledging. - pss, lerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.ProvingSet) - if lerr != nil { - return nil, aerrors.HandleExternalError(lerr, "could not load proving set node") - } - - if pss.Count == 0 && !self.Active { - self.ProvingSet = self.Sectors - // TODO: probably want to wait until the miner is above a certain - // threshold before starting this - self.ElectionPeriodStart = (vmctx.BlockHeight()) - } - - nstate, err := vmctx.Storage().Put(self) - if err != nil { - return nil, err - } - if err := vmctx.Storage().Commit(oldstate, nstate); err != nil { - return nil, err - } - - activateParams, err := SerializeParams(&ActivateStorageDealsParams{ - DealIDs: params.DealIDs, - }) - if err != nil { - return nil, err - } - - _, err = vmctx.Send(StorageMarketAddress, SMAMethods.ActivateStorageDeals, types.NewInt(0), activateParams) - return nil, aerrors.Wrapf(err, "calling ActivateStorageDeals failed") -} - -func (sma 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(0) - - if err != nil { - return nil, aerrors.Wrap(err, "could not get randomness for PoST") - } - if len(rand) < len(seed) { - return nil, aerrors.Escalate(fmt.Errorf("randomness too small (%d < %d)", - len(rand), len(seed)), "improper randomness") - } - copy(seed[:], rand) - } - - pss, lerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.ProvingSet) - if lerr != nil { - return nil, aerrors.HandleExternalError(lerr, "could not load proving set node") - } - - ss, lerr := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.Sectors) - if lerr != nil { - return nil, aerrors.HandleExternalError(lerr, "could not load proving set node") - } - - faults, nerr := self.FaultSet.AllMap(2 * ss.Count) - if nerr != nil { - return nil, aerrors.Absorb(err, 5, "RLE+ invalid") - } - - activeFaults := uint64(0) - var sectorInfos []ffi.PublicSectorInfo - if err := pss.ForEach(vmctx.Context(), func(id uint64, v *cbg.Deferred) error { - if faults[id] { - activeFaults++ - return nil - } - - var comms [][]byte - if err := cbor.DecodeInto(v.Raw, &comms); err != nil { - return xerrors.New("could not decode comms") - } - si := ffi.PublicSectorInfo{ - SectorNum: abi.SectorNumber(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, - SectorNum: t.SectorID, - SectorChallengeIndex: t.ChallengeIndex, - }) - } - - if ok, lerr := vmctx.Sys().VerifyFallbackPost(vmctx.Context(), mi.SectorSize, - sectorbuilder.NewSortedPublicSectorInfo(sectorInfos), seed[:], params.Proof, candidates, proverID, activeFaults); !ok || lerr != nil { - if lerr != nil { - // TODO: study PoST errors - return nil, aerrors.Absorb(lerr, 4, "PoST error") - } - if !ok { - return nil, aerrors.New(4, "PoST invalid") - } - } - - // Post submission is successful! - if err := onSuccessfulPoSt2(self, vmctx, activeFaults); err != nil { - return nil, err - } - - c, err := vmctx.Storage().Put(self) - if err != nil { - return nil, err - } - - if err := vmctx.Storage().Commit(oldstate, c); err != nil { - return nil, err - } - - return nil, nil -} - -func (sma StorageMinerActor) GetPower(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) { - _, self, err := loadState(vmctx) - if err != nil { - return nil, err - } - - if self.SlashedAt != 0 { - return nil, nil - } - - return nil, nil -} - -func SectorIsUnique2(ctx context.Context, s cbor.IpldStore, sroot cid.Cid, sid uint64) (bool, ActorError) { - found, _, _, err := GetFromSectorSet2(ctx, s, sroot, sid) - if err != nil { - return false, err - } - - return !found, nil -} - -func AddToSectorSet2(ctx context.Context, blks cbor.IpldStore, ss cid.Cid, sectorID uint64, commR, commD []byte) (cid.Cid, ActorError) { - if sectorID >= build.MinerMaxSectors { - return cid.Undef, aerrors.Newf(25, "sector ID out of range: %d", sectorID) - } - ssr, err := amt2.LoadAMT(ctx, blks, ss) - if err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node") - } - - // TODO: Spec says to use SealCommitment, and construct commD from deals each time, - // but that would make SubmitPoSt way, way more expensive - if err := ssr.Set(ctx, sectorID, [][]byte{commR, commD}); err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to set commitment in sector set") - } - - ncid, err := ssr.Flush(ctx) - if err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set") - } - - return ncid, nil -} - -func GetFromSectorSet2(ctx context.Context, cst cbor.IpldStore, ss cid.Cid, sectorID uint64) (bool, []byte, []byte, ActorError) { - if sectorID >= build.MinerMaxSectors { - return false, nil, nil, aerrors.Newf(25, "sector ID out of range: %d", sectorID) - } - - ssr, err := amt2.LoadAMT(ctx, cst, ss) - if err != nil { - return false, nil, nil, aerrors.HandleExternalError(err, "could not load sector set node") - } - - var comms [][]byte - err = ssr.Get(ctx, sectorID, &comms) - if err != nil { - if _, ok := err.(*amt2.ErrNotFound); ok { - return false, nil, nil, nil - } - return false, nil, nil, aerrors.HandleExternalError(err, "failed to find sector in sector set") - } - - if len(comms) != 2 { - return false, nil, nil, aerrors.Newf(20, "sector set entry should only have 2 elements") - } - - return true, comms[0], comms[1], nil -} - -func RemoveFromSectorSet2(ctx context.Context, cst cbor.IpldStore, ss cid.Cid, ids []uint64) (cid.Cid, aerrors.ActorError) { - - ssr, err := amt2.LoadAMT(ctx, cst, ss) - if err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node") - } - - for _, id := range ids { - if err := ssr.Delete(ctx, id); err != nil { - log.Warnf("failed to delete sector %d from set: %s", id, err) - } - } - - ncid, err := ssr.Flush(ctx) - if err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set") - } - - return ncid, nil -} - -func (sma 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 -} - -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) { - - - return nil, nil -} - -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 -} - -// 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(uint64(vmctx.BlockHeight()), self) { - // Everything's fine - return nil, nil - } - - if self.SlashedAt != 0 { - // Don't slash more than necessary - return nil, nil - } - - // Slash for being late - - self.SlashedAt = uint64(vmctx.BlockHeight()) - oldPower := self.Power - self.Power = types.NewInt(0) - - nstate, err := vmctx.Storage().Put(self) - if err != nil { - return nil, err - } - if err := vmctx.Storage().Commit(oldstate, nstate); err != nil { - return nil, err - } - - var out bytes.Buffer - if err := oldPower.MarshalCBOR(&out); err != nil { - return nil, aerrors.HandleExternalError(err, "marshaling return value") - } - return out.Bytes(), nil -} - -func (sma 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 := amt2.LoadAMT(vmctx.Context(), vmctx.Ipld(), self.Sectors) - if nerr != nil { - return nil, aerrors.HandleExternalError(nerr, "failed to load sector set") - } - - cf, nerr := nfaults.Count() - if nerr != nil { - return nil, aerrors.Absorb(nerr, 2, "could not decode RLE+") - } - - if cf > 2*ss.Count { - return nil, aerrors.Newf(3, "too many declared faults: %d > %d", cf, 2*ss.Count) - } - - self.FaultSet = nfaults - - self.LastFaultSubmission = uint64(vmctx.BlockHeight()) - - nstate, aerr := vmctx.Storage().Put(self) - if aerr != nil { - return nil, aerr - } - if err := vmctx.Storage().Commit(oldstate, nstate); err != nil { - return nil, err - } - - return nil, nil -} - -func (sma 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 - - // 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 := uint64(vmctx.BlockHeight()) - uint64(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") - } - - oldstate, self, err := loadState(vmctx) - if err != nil { - return nil, aerrors.Wrap(err, "failed to load state for slashing") - } - - self.Power = types.NewInt(0) - - ncid, err := vmctx.Storage().Put(self) - if err != nil { - return nil, err - } - if err := vmctx.Storage().Commit(oldstate, ncid); err != nil { - return nil, err - } - - // TODO: this still allows the miner to commit sectors and submit posts, - // their users could potentially be unaffected, but the miner will never be - // able to mine a block again - // One potential issue: the miner will have to pay back the slashed - // collateral to continue submitting PoSts, which includes pledge - // collateral that they no longer really 'need' - - return nil, nil -} - -func (sma StorageMinerActor) SubmitElectionPoSt(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) { - ctx := vmctx.Context() - - if vmctx.Message().From != NetworkAddress { - return nil, aerrors.Newf(1, "submit election post can only be called by the storage power actor") - } - - oldstate, self, aerr := loadState(vmctx) - if aerr != nil { - return nil, aerr - } - - if self.SlashedAt != 0 { - return nil, aerrors.New(1, "slashed miners can't perform election PoSt") - } - - pss, nerr := amt2.LoadAMT(ctx, vmctx.Ipld(), self.ProvingSet) - if nerr != nil { - return nil, aerrors.HandleExternalError(nerr, "failed to load proving set") - } - - ss, nerr := amt2.LoadAMT(ctx, vmctx.Ipld(), self.Sectors) - if nerr != nil { - return nil, aerrors.HandleExternalError(nerr, "failed to load proving set") - } - - faults, nerr := self.FaultSet.AllMap(2 * ss.Count) - if nerr != nil { - return nil, aerrors.Absorb(nerr, 1, "invalid bitfield (fatal?)") - } - - activeFaults := uint64(0) - for f := range faults { - if f > amt2.MaxIndex { - continue - } - - var comms [][]byte - err := pss.Get(ctx, f, &comms) - if err != nil { - var notfound *amt2.ErrNotFound - if !xerrors.As(err, ¬found) { - return nil, aerrors.HandleExternalError(err, "failed to find sector in sector set") - } - continue - } - - activeFaults++ - } - - if err := onSuccessfulPoSt2(self, vmctx, activeFaults); err != nil { // TODO - return nil, err - } - - ncid, err := vmctx.Storage().Put(self) - if err != nil { - return nil, err - } - if err := vmctx.Storage().Commit(oldstate, ncid); err != nil { - return nil, err - } - - return nil, nil -} - -func onSuccessfulPoSt2(self *StorageMinerActorState, vmctx types.VMContext, activeFaults uint64) aerrors.ActorError { - - - 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 abi.SectorNumber, 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, uint64(sectorID), [][]byte{commR, commD}); err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to set commitment in sector set") - } - - ncid, err := ssr.Flush(ctx) - if err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to flush sector set") - } - - return ncid, nil -} - -func loadState(vmctx types.VMContext) (cid.Cid, *StorageMinerActorState, ActorError) { - var self StorageMinerActorState - oldstate := vmctx.Storage().GetHead() - if err := vmctx.Storage().Get(oldstate, &self); err != nil { - return cid.Undef, nil, err - } - - return oldstate, &self, nil -} - -func loadMinerInfo(vmctx types.VMContext, m *StorageMinerActorState) (*MinerInfo, ActorError) { - var mi MinerInfo - if err := vmctx.Storage().Get(m.Info, &mi); err != nil { - return nil, err - } - - return &mi, nil -} - -func uintToStringKey(i uint64) string { - buf := make([]byte, 10) - n := binary.PutUvarint(buf, i) - return string(buf[:n]) -} - -type SectorProveCommitInfo struct { - Proof []byte - SectorID abi.SectorNumber - DealIDs []abi.DealID -} - -func truncateHexPrint(b []byte) string { - s := fmt.Sprintf("%x", b) - if len(s) > 60 { - return s[:20] + "..." + s[len(s)-20:] - } - return s -} - -type SubmitFallbackPoStParams struct { - Proof []byte - Candidates []types.EPostTicket -} - -func CollateralForPower(power types.BigInt) types.BigInt { - return types.BigMul(power, types.NewInt(10)) - /* TODO: this - availableFil = FakeGlobalMethods.GetAvailableFil() - totalNetworkPower = StorageMinerActor.GetTotalStorage() - numMiners = StorageMarket.GetMinerCount() - powerCollateral = availableFil * NetworkConstants.POWER_COLLATERAL_PROPORTION * power / totalNetworkPower - perCapitaCollateral = availableFil * NetworkConstants.PER_CAPITA_COLLATERAL_PROPORTION / numMiners - collateralRequired = math.Ceil(minerPowerCollateral + minerPerCapitaCollateral) - return collateralRequired - */ -} - -type UpdatePeerIDParams struct { - PeerID peer.ID -} - -func isLate(height uint64, self *StorageMinerActorState) bool { - return self.ElectionPeriodStart > 0 && height >= uint64(self.ElectionPeriodStart+build.SlashablePowerDelay) -} - -type CheckMinerParams struct { - NetworkPower types.BigInt -} - -type DeclareFaultsParams struct { - Faults types.BitField -} - -type MinerSlashConsensusFault struct { - Slasher address.Address - AtHeight abi.ChainEpoch - SlashedCollateral types.BigInt -} - -func slasherShare(total types.BigInt, elapsed uint64) types.BigInt { - // [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} - const precision = 10000 - - var frac uint64 - if elapsed >= uint64(len(fracs)) { - return total - } else { - frac = fracs[elapsed] - } - - return types.BigDiv( - types.BigMul( - types.NewInt(frac), - total, - ), - types.NewInt(precision), - ) -} +type StorageMinerActorState = miner.State diff --git a/chain/actors/actor_paych.go b/chain/actors/actor_paych.go index 532843b95..17fc787f2 100644 --- a/chain/actors/actor_paych.go +++ b/chain/actors/actor_paych.go @@ -1,302 +1,9 @@ package actors import ( - "bytes" - "fmt" - - "github.com/ipfs/go-cid" - "github.com/minio/blake2b-simd" - - "github.com/filecoin-project/go-address" - "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/specs-actors/actors/builtin/paych" ) -type PaymentChannelActor struct{} +type PaymentChannelActor = paych.Actor -type PaymentInfo struct { - PayChActor address.Address - Payer address.Address - ChannelMessage *cid.Cid - - Vouchers []*types.SignedVoucher -} - -type LaneState struct { - Closed bool - Redeemed types.BigInt - Nonce uint64 -} - -type PaymentChannelActorState struct { - From address.Address - To address.Address - - ToSend types.BigInt - - ClosingAt uint64 - MinCloseHeight uint64 - - // TODO: needs to be map[uint64]*laneState - // waiting on refmt#35 to be fixed - LaneStates map[string]*LaneState -} - -func (pca PaymentChannelActor) Exports() []interface{} { - return []interface{}{ - 1: pca.Constructor, - 2: pca.UpdateChannelState, - 3: pca.Close, - 4: pca.Collect, - 5: pca.GetOwner, - 6: pca.GetToSend, - } -} - -type pcaMethods struct { - Constructor uint64 - UpdateChannelState uint64 - Close uint64 - Collect uint64 - GetOwner uint64 - GetToSend uint64 -} - -var PCAMethods = pcaMethods{1, 2, 3, 4, 5, 6} - -type PCAConstructorParams struct { - To address.Address -} - -func (pca PaymentChannelActor) Constructor(act *types.Actor, vmctx types.VMContext, params *PCAConstructorParams) ([]byte, ActorError) { - var self PaymentChannelActorState - self.From = vmctx.Origin() - self.To = params.To - self.LaneStates = make(map[string]*LaneState) - - 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 -} - -type PCAUpdateChannelStateParams struct { - Sv types.SignedVoucher - Secret []byte - Proof []byte -} - -func hash(b []byte) []byte { - s := blake2b.Sum256(b) - return s[:] -} - -type PaymentVerifyParams struct { - Extra []byte - Proof []byte -} - -func (pca PaymentChannelActor) UpdateChannelState(act *types.Actor, vmctx types.VMContext, params *PCAUpdateChannelStateParams) ([]byte, ActorError) { - var self PaymentChannelActorState - oldstate := vmctx.Storage().GetHead() - storage := vmctx.Storage() - if err := storage.Get(oldstate, &self); err != nil { - return nil, err - } - - sv := params.Sv - - vb, nerr := sv.SigningBytes() - if nerr != nil { - return nil, aerrors.Absorb(nerr, 1, "failed to serialize signedvoucher") - } - - if err := vmctx.VerifySignature(sv.Signature, self.From, vb); err != nil { - return nil, err - } - - if uint64(vmctx.BlockHeight()) < sv.TimeLock { - return nil, aerrors.New(2, "cannot use this voucher yet!") - } - - if len(sv.SecretPreimage) > 0 { - if !bytes.Equal(hash(params.Secret), sv.SecretPreimage) { - return nil, aerrors.New(3, "incorrect secret!") - } - } - - if sv.Extra != nil { - encoded, err := SerializeParams(&PaymentVerifyParams{sv.Extra.Data, params.Proof}) - if err != nil { - return nil, err - } - - _, err = vmctx.Send(sv.Extra.Actor, sv.Extra.Method, types.NewInt(0), encoded) - if err != nil { - return nil, aerrors.Newf(4, "spend voucher verification failed: %s", err) - } - } - - ls, ok := self.LaneStates[fmt.Sprint(sv.Lane)] - if !ok { - ls = new(LaneState) - ls.Redeemed = types.NewInt(0) // TODO: kinda annoying that this doesnt default to a usable value - self.LaneStates[fmt.Sprint(sv.Lane)] = ls - } - if ls.Closed { - return nil, aerrors.New(5, "cannot redeem a voucher on a closed lane") - } - - if ls.Nonce > sv.Nonce { - return nil, aerrors.New(6, "voucher has an outdated nonce, cannot redeem") - } - - mergeValue := types.NewInt(0) - for _, merge := range sv.Merges { - if merge.Lane == sv.Lane { - return nil, aerrors.New(7, "voucher cannot merge its own lane") - } - - ols := self.LaneStates[fmt.Sprint(merge.Lane)] - - if ols.Nonce >= merge.Nonce { - return nil, aerrors.New(8, "merge in voucher has outdated nonce, cannot redeem") - } - - mergeValue = types.BigAdd(mergeValue, ols.Redeemed) - ols.Nonce = merge.Nonce - } - - ls.Nonce = sv.Nonce - balanceDelta := types.BigSub(sv.Amount, types.BigAdd(mergeValue, ls.Redeemed)) - ls.Redeemed = sv.Amount - - newSendBalance := types.BigAdd(self.ToSend, balanceDelta) - if newSendBalance.LessThan(types.NewInt(0)) { - // TODO: is this impossible? - return nil, aerrors.New(9, "voucher would leave channel balance negative") - } - - if newSendBalance.GreaterThan(act.Balance) { - return nil, aerrors.New(10, "not enough funds in channel to cover voucher") - } - - log.Info("vals: ", newSendBalance, sv.Amount, balanceDelta, mergeValue, ls.Redeemed) - self.ToSend = newSendBalance - - if sv.MinCloseHeight != 0 { - if self.ClosingAt != 0 && self.ClosingAt < sv.MinCloseHeight { - self.ClosingAt = sv.MinCloseHeight - } - if self.MinCloseHeight < sv.MinCloseHeight { - self.MinCloseHeight = sv.MinCloseHeight - } - } - - ncid, err := storage.Put(&self) - if err != nil { - return nil, err - } - if err := storage.Commit(oldstate, ncid); err != nil { - return nil, err - } - - return nil, nil -} - -func (pca PaymentChannelActor) Close(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) { - var self PaymentChannelActorState - storage := vmctx.Storage() - oldstate := storage.GetHead() - if err := storage.Get(oldstate, &self); err != nil { - return nil, err - } - - if vmctx.Message().From != self.From && vmctx.Message().From != self.To { - return nil, aerrors.New(1, "not authorized to close channel") - } - - if self.ClosingAt != 0 { - return nil, aerrors.New(2, "channel already closing") - } - - self.ClosingAt = uint64(vmctx.BlockHeight()) + build.PaymentChannelClosingDelay - if self.ClosingAt < self.MinCloseHeight { - self.ClosingAt = self.MinCloseHeight - } - - ncid, err := storage.Put(&self) - if err != nil { - return nil, err - } - if err := storage.Commit(oldstate, ncid); err != nil { - return nil, err - } - - return nil, nil -} - -func (pca PaymentChannelActor) Collect(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) { - var self PaymentChannelActorState - storage := vmctx.Storage() - oldstate := storage.GetHead() - if err := storage.Get(oldstate, &self); err != nil { - return nil, err - } - - if self.ClosingAt == 0 { - return nil, aerrors.New(1, "payment channel not closing or closed") - } - - if uint64(vmctx.BlockHeight()) < self.ClosingAt { - return nil, aerrors.New(2, "payment channel not closed yet") - } - _, err := vmctx.Send(self.From, 0, types.BigSub(act.Balance, self.ToSend), nil) - if err != nil { - return nil, err - } - _, err = vmctx.Send(self.To, 0, self.ToSend, nil) - if err != nil { - return nil, err - } - - self.ToSend = types.NewInt(0) - - ncid, err := storage.Put(&self) - if err != nil { - return nil, err - } - if err := storage.Commit(oldstate, ncid); err != nil { - return nil, err - } - - return nil, nil -} - -func (pca PaymentChannelActor) GetOwner(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) { - var self PaymentChannelActorState - storage := vmctx.Storage() - if err := storage.Get(storage.GetHead(), &self); err != nil { - return nil, err - } - - return self.From.Bytes(), nil -} - -func (pca PaymentChannelActor) GetToSend(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) { - var self PaymentChannelActorState - storage := vmctx.Storage() - if err := storage.Get(storage.GetHead(), &self); err != nil { - return nil, err - } - - return nil, nil -} +type PaymentChannelActorState = paych.State diff --git a/chain/actors/actor_storagepower.go b/chain/actors/actor_storagepower.go index e4c3117e7..4fd7c0604 100644 --- a/chain/actors/actor_storagepower.go +++ b/chain/actors/actor_storagepower.go @@ -1,832 +1,12 @@ package actors import ( - "bytes" - "context" - "io" - - "github.com/filecoin-project/go-amt-ipld/v2" - "github.com/filecoin-project/specs-actors/actors/abi" - cid "github.com/ipfs/go-cid" - hamt "github.com/ipfs/go-hamt-ipld" - cbor "github.com/ipfs/go-ipld-cbor" - "github.com/libp2p/go-libp2p-core/peer" - cbg "github.com/whyrusleeping/cbor-gen" - "go.opencensus.io/trace" - xerrors "golang.org/x/xerrors" - - "github.com/filecoin-project/go-address" - "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/lib/sigs" + "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/filecoin-project/specs-actors/actors/builtin/power" ) -type StoragePowerActor struct{} +type StoragePowerActor = power.Actor -type spaMethods struct { - Constructor uint64 - CreateStorageMiner uint64 - ArbitrateConsensusFault uint64 - UpdateStorage uint64 - GetTotalStorage uint64 - PowerLookup uint64 - IsValidMiner uint64 - PledgeCollateralForSize uint64 - CheckProofSubmissions uint64 -} +var SPAMethods = builtin.MethodsPower -var SPAMethods = spaMethods{1, 2, 3, 4, 5, 6, 7, 8, 9} - -func (spa StoragePowerActor) Exports() []interface{} { - return []interface{}{ - //1: spa.StoragePowerConstructor, - 2: spa.CreateStorageMiner, - 3: spa.ArbitrateConsensusFault, - 4: spa.UpdateStorage, - 5: spa.GetTotalStorage, - 6: spa.PowerLookup, - 7: spa.IsValidMiner, - 8: spa.PledgeCollateralForSize, - 9: spa.CheckProofSubmissions, - } -} - -type StoragePowerState struct { - Miners cid.Cid - ProvingBuckets cid.Cid // amt[ProvingPeriodBucket]hamt[minerAddress]struct{} - MinerCount uint64 - LastMinerCheck uint64 - - TotalStorage types.BigInt -} - -type CreateStorageMinerParams struct { - Owner address.Address - Worker address.Address - SectorSize abi.SectorSize - PeerID peer.ID -} - -func (spa StoragePowerActor) CreateStorageMiner(act *types.Actor, vmctx types.VMContext, params *CreateStorageMinerParams) ([]byte, ActorError) { - if !build.SupportedSectorSize(params.SectorSize) { - return nil, aerrors.Newf(1, "Unsupported sector size: %d", params.SectorSize) - } - - var self StoragePowerState - old := vmctx.Storage().GetHead() - if err := vmctx.Storage().Get(old, &self); err != nil { - return nil, err - } - - reqColl, err := pledgeCollateralForSize(vmctx, types.NewInt(0), self.TotalStorage, self.MinerCount+1) - if err != nil { - return nil, err - } - - if vmctx.Message().Value.LessThan(reqColl) { - return nil, aerrors.Newf(1, "not enough funds passed to cover required miner collateral (needed %s, got %s)", reqColl, vmctx.Message().Value) - } - - minerCid := StorageMinerCodeCid - - encoded, err := CreateExecParams(minerCid, &StorageMinerConstructorParams{ - Owner: params.Owner, - Worker: params.Worker, - SectorSize: params.SectorSize, - PeerID: params.PeerID, - }) - if err != nil { - return nil, err - } - - ret, err := vmctx.Send(InitAddress, IAMethods.Exec, vmctx.Message().Value, encoded) - if err != nil { - return nil, err - } - - naddr, nerr := address.NewFromBytes(ret) - if nerr != nil { - return nil, aerrors.Absorb(nerr, 2, "could not read address of new actor") - } - - ncid, err := MinerSetAdd(context.TODO(), vmctx, self.Miners, naddr) - if err != nil { - return nil, err - } - self.Miners = ncid - self.MinerCount++ - - nroot, err := vmctx.Storage().Put(&self) - if err != nil { - return nil, err - } - - if err := vmctx.Storage().Commit(old, nroot); err != nil { - return nil, err - } - - return naddr.Bytes(), nil -} - -type ArbitrateConsensusFaultParams struct { - Block1 *types.BlockHeader - Block2 *types.BlockHeader -} - -func (spa StoragePowerActor) ArbitrateConsensusFault(act *types.Actor, vmctx types.VMContext, params *ArbitrateConsensusFaultParams) ([]byte, ActorError) { - if params == nil || params.Block1 == nil || params.Block2 == nil { - return nil, aerrors.New(1, "failed to parse params") - } - - if params.Block1.Miner != params.Block2.Miner { - return nil, aerrors.New(2, "blocks must be from the same miner") - } - - 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) - if err != nil { - return nil, aerrors.Wrap(err, "failed to get miner worker") - } - - worker, oerr := address.NewFromBytes(rval) - if oerr != nil { - // REVIEW: should this be fatal? i can't think of a real situation that would get us here - return nil, aerrors.Absorb(oerr, 3, "response from 'GetWorkerAddr' was not a valid address") - } - - if err := sigs.CheckBlockSignature(params.Block1, vmctx.Context(), worker); err != nil { - return nil, aerrors.Absorb(err, 4, "block1 did not have valid signature") - } - - if err := sigs.CheckBlockSignature(params.Block2, vmctx.Context(), worker); err != nil { - return nil, aerrors.Absorb(err, 5, "block2 did not have valid signature") - } - - // see the "Consensus Faults" section of the faults spec (faults.md) - // for details on these slashing conditions. - if !shouldSlash(params.Block1, params.Block2) { - return nil, aerrors.New(6, "blocks do not prove a slashable offense") - } - - var self StoragePowerState - old := vmctx.Storage().GetHead() - if err := vmctx.Storage().Get(old, &self); err != nil { - return nil, err - } - - if types.BigCmp(self.TotalStorage, types.NewInt(0)) == 0 { - return nil, aerrors.Fatal("invalid state, storage power actor has zero total storage") - } - - miner := params.Block1.Miner - if has, err := MinerSetHas(vmctx, self.Miners, miner); err != nil { - return nil, aerrors.Wrapf(err, "failed to check miner in set") - } else if !has { - return nil, aerrors.New(7, "either already slashed or not a miner") - } - - minerPower, err := powerLookup(context.TODO(), vmctx, &self, miner) - if err != nil { - return nil, err - } - - slashedCollateral, err := pledgeCollateralForSize(vmctx, minerPower, self.TotalStorage, self.MinerCount) - if err != nil { - return nil, err - } - - enc, err := SerializeParams(&MinerSlashConsensusFault{ - Slasher: vmctx.Message().From, - AtHeight: params.Block1.Height, - SlashedCollateral: slashedCollateral, - }) - if err != nil { - return nil, err - } - - _, err = vmctx.Send(miner, MAMethods.SlashConsensusFault, types.NewInt(0), enc) - if err != nil { - return nil, err - } - - // Remove the miner from the list of network miners - ncid, err := MinerSetRemove(context.TODO(), vmctx, self.Miners, miner) - if err != nil { - return nil, err - } - self.Miners = ncid - self.MinerCount-- - - self.TotalStorage = types.BigSub(self.TotalStorage, minerPower) - - nroot, err := vmctx.Storage().Put(&self) - if err != nil { - return nil, err - } - - if err := vmctx.Storage().Commit(old, nroot); err != nil { - return nil, err - } - - return nil, nil -} - -func cidArrContains(a []cid.Cid, b cid.Cid) bool { - for _, c := range a { - if b == c { - return true - } - } - - return false -} - -func shouldSlash(block1, block2 *types.BlockHeader) bool { - // First slashing condition, blocks have the same ticket round - if block1.Height == block2.Height { - return true - } - - /* Second slashing condition requires having access to the parent tipset blocks - // This might not always be available, needs some thought on the best way to deal with this - - - // Second slashing condition, miner ignored own block when mining - // Case A: block2 could have been in block1's parent set but is not - b1ParentHeight := block1.Height - len(block1.Tickets) - - block1ParentTipSet := block1.Parents - if !cidArrContains(block1.Parents, block2.Cid()) && - b1ParentHeight == block2.Height && - block1ParentTipSet.ParentCids == block2.ParentCids { - return true - } - - // Case B: block1 could have been in block2's parent set but is not - block2ParentTipSet := parentOf(block2) - if !block2Parent.contains(block1) && - block2ParentTipSet.Height == block1.Height && - block2ParentTipSet.ParentCids == block1.ParentCids { - return true - } - - */ - - return false -} - -type UpdateStorageParams struct { - Delta types.BigInt - NextSlashDeadline uint64 - PreviousSlashDeadline uint64 -} - -func (spa StoragePowerActor) UpdateStorage(act *types.Actor, vmctx types.VMContext, params *UpdateStorageParams) ([]byte, ActorError) { - ctx := vmctx.Context() - var self StoragePowerState - old := vmctx.Storage().GetHead() - if err := vmctx.Storage().Get(old, &self); err != nil { - return nil, err - } - - has, err := MinerSetHas(vmctx, self.Miners, vmctx.Message().From) - if err != nil { - return nil, err - } - if !has { - return nil, aerrors.New(1, "update storage must only be called by a miner actor") - } - - self.TotalStorage = types.BigAdd(self.TotalStorage, params.Delta) - - previousBucket := params.PreviousSlashDeadline % build.SlashablePowerDelay - nextBucket := params.NextSlashDeadline % build.SlashablePowerDelay - - if previousBucket == nextBucket && params.PreviousSlashDeadline != 0 { - nroot, err := vmctx.Storage().Put(&self) - if err != nil { - return nil, err - } - - if err := vmctx.Storage().Commit(old, nroot); err != nil { - return nil, err - } - - return nil, nil // Nothing to do - } - - buckets, eerr := amt.LoadAMT(ctx, vmctx.Ipld(), self.ProvingBuckets) - if eerr != nil { - return nil, aerrors.HandleExternalError(eerr, "loading proving buckets amt") - } - - if params.PreviousSlashDeadline != 0 { // delete from previous bucket - err := deleteMinerFromBucket(vmctx, buckets, previousBucket) - if err != nil { - return nil, aerrors.Wrapf(err, "delete from bucket %d, next %d", previousBucket, nextBucket) - } - } - - err = addMinerToBucket(vmctx, buckets, nextBucket) - if err != nil { - return nil, err - } - - self.ProvingBuckets, eerr = buckets.Flush(ctx) - if eerr != nil { - return nil, aerrors.HandleExternalError(eerr, "flushing proving buckets") - } - - nroot, err := vmctx.Storage().Put(&self) - if err != nil { - return nil, err - } - - if err := vmctx.Storage().Commit(old, nroot); err != nil { - return nil, err - } - - return nil, nil -} - -func deleteMinerFromBucket(vmctx types.VMContext, buckets *amt.Root, previousBucket uint64) aerrors.ActorError { - ctx := vmctx.Context() - var bucket cid.Cid - err := buckets.Get(ctx, previousBucket, &bucket) - switch err.(type) { - case *amt.ErrNotFound: - return aerrors.HandleExternalError(err, "proving bucket missing") - case nil: // noop - default: - return aerrors.HandleExternalError(err, "getting proving bucket") - } - - bhamt, err := hamt.LoadNode(vmctx.Context(), vmctx.Ipld(), bucket) - if err != nil { - return aerrors.HandleExternalError(err, "failed to load proving bucket") - } - err = bhamt.Delete(vmctx.Context(), string(vmctx.Message().From.Bytes())) - if err != nil { - return aerrors.HandleExternalError(err, "deleting miner from proving bucket") - } - - err = bhamt.Flush(vmctx.Context()) - if err != nil { - return aerrors.HandleExternalError(err, "flushing previous proving bucket") - } - - bucket, err = vmctx.Ipld().Put(vmctx.Context(), bhamt) - if err != nil { - return aerrors.HandleExternalError(err, "putting previous proving bucket hamt") - } - - err = buckets.Set(ctx, previousBucket, bucket) - if err != nil { - return aerrors.HandleExternalError(err, "setting previous proving bucket cid in amt") - } - - return nil -} - -func addMinerToBucket(vmctx types.VMContext, buckets *amt.Root, nextBucket uint64) aerrors.ActorError { - ctx := vmctx.Context() - var bhamt *hamt.Node - var bucket cid.Cid - err := buckets.Get(ctx, nextBucket, &bucket) - switch err.(type) { - case *amt.ErrNotFound: - bhamt = hamt.NewNode(vmctx.Ipld()) - case nil: - bhamt, err = hamt.LoadNode(vmctx.Context(), vmctx.Ipld(), bucket) - if err != nil { - return aerrors.HandleExternalError(err, "failed to load proving bucket") - } - default: - return aerrors.HandleExternalError(err, "getting proving bucket") - } - - err = bhamt.Set(vmctx.Context(), string(vmctx.Message().From.Bytes()), CborNull) - if err != nil { - return aerrors.HandleExternalError(err, "setting miner in proving bucket") - } - - err = bhamt.Flush(vmctx.Context()) - if err != nil { - return aerrors.HandleExternalError(err, "flushing previous proving bucket") - } - - bucket, err = vmctx.Ipld().Put(vmctx.Context(), bhamt) - if err != nil { - return aerrors.HandleExternalError(err, "putting previous proving bucket hamt") - } - - err = buckets.Set(ctx, nextBucket, bucket) - if err != nil { - return aerrors.HandleExternalError(err, "setting previous proving bucket cid in amt") - } - return nil -} - -func (spa StoragePowerActor) GetTotalStorage(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) { - var self StoragePowerState - if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil { - return nil, err - } - - return nil, nil -} - -type PowerLookupParams struct { - Miner address.Address -} - -func (spa StoragePowerActor) PowerLookup(act *types.Actor, vmctx types.VMContext, params *PowerLookupParams) ([]byte, ActorError) { - var self StoragePowerState - if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil { - return nil, aerrors.Wrap(err, "getting head") - } - - - return nil, nil -} - -func powerLookup(ctx context.Context, vmctx types.VMContext, self *StoragePowerState, miner address.Address) (types.BigInt, ActorError) { - has, err := MinerSetHas(vmctx, self.Miners, miner) - if err != nil { - return types.EmptyInt, err - } - - if !has { - // A miner could be registered with storage power actor, but removed for some reasons, e.g. consensus fault - return types.EmptyInt, aerrors.New(1, "miner not registered with storage power actor, or removed already") - } - - // TODO: Use local amt - ret, err := vmctx.Send(miner, MAMethods.GetPower, types.NewInt(0), nil) - if err != nil { - return types.EmptyInt, aerrors.Wrap(err, "invoke Miner.GetPower") - } - - return types.BigFromBytes(ret), nil -} - -type IsValidMinerParam struct { - Addr address.Address -} - -func (spa StoragePowerActor) IsValidMiner(act *types.Actor, vmctx types.VMContext, param *IsValidMinerParam) ([]byte, ActorError) { - var self StoragePowerState - if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil { - return nil, err - } - - has, err := MinerSetHas(vmctx, self.Miners, param.Addr) - if err != nil { - return nil, err - } - - if !has { - log.Warnf("Miner INVALID: not in set: %s", param.Addr) - - return cbg.CborBoolFalse, nil - } - - ret, err := vmctx.Send(param.Addr, MAMethods.IsSlashed, types.NewInt(0), nil) - if err != nil { - return nil, err - } - - slashed := bytes.Equal(ret, cbg.CborBoolTrue) - - if slashed { - log.Warnf("Miner INVALID: /SLASHED/ : %s", param.Addr) - } - - return cbg.EncodeBool(!slashed), nil -} - -type PledgeCollateralParams struct { - Size types.BigInt -} - -func (spa StoragePowerActor) PledgeCollateralForSize(act *types.Actor, vmctx types.VMContext, param *PledgeCollateralParams) ([]byte, ActorError) { - var self StoragePowerState - if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil { - return nil, err - } - - return nil, nil -} - -func pledgeCollateralForSize(vmctx types.VMContext, size, totalStorage types.BigInt, minerCount uint64) (types.BigInt, aerrors.ActorError) { - netBalance, err := vmctx.GetBalance(NetworkAddress) - if err != nil { - return types.EmptyInt, err - } - - // TODO: the spec says to also grab 'total vested filecoin' and include it as available - // If we don't factor that in, we effectively assume all of the locked up filecoin is 'available' - // the blocker on that right now is that its hard to tell how much filecoin is unlocked - - availableFilecoin := types.BigSub( - types.BigMul(types.NewInt(build.TotalFilecoin), types.NewInt(build.FilecoinPrecision)), - netBalance, - ) - - totalPowerCollateral := types.BigDiv( - types.BigMul( - availableFilecoin, - types.NewInt(build.PowerCollateralProportion), - ), - types.NewInt(build.CollateralPrecision), - ) - - totalPerCapitaCollateral := types.BigDiv( - types.BigMul( - availableFilecoin, - types.NewInt(build.PerCapitaCollateralProportion), - ), - types.NewInt(build.CollateralPrecision), - ) - - // REVIEW: for bootstrapping purposes, we skip the power portion of the - // collateral if there is no collateral in the network yet - powerCollateral := types.NewInt(0) - if types.BigCmp(totalStorage, types.NewInt(0)) != 0 { - powerCollateral = types.BigDiv( - types.BigMul( - totalPowerCollateral, - size, - ), - totalStorage, - ) - } - - perCapCollateral := types.BigDiv( - totalPerCapitaCollateral, - types.NewInt(minerCount), - ) - - return types.BigAdd(powerCollateral, perCapCollateral), nil -} - -func (spa StoragePowerActor) CheckProofSubmissions(act *types.Actor, vmctx types.VMContext, param *struct{}) ([]byte, ActorError) { - if vmctx.Message().From != CronAddress { - return nil, aerrors.New(1, "CheckProofSubmissions is only callable from the cron actor") - } - - var self StoragePowerState - old := vmctx.Storage().GetHead() - if err := vmctx.Storage().Get(old, &self); err != nil { - return nil, err - } - - for i := self.LastMinerCheck; i < uint64(vmctx.BlockHeight()); i++ { - height := i + 1 - - err := checkProofSubmissionsAtH(vmctx, &self, height) - if err != nil { - return nil, err - } - } - - self.LastMinerCheck = uint64(vmctx.BlockHeight()) - - nroot, aerr := vmctx.Storage().Put(&self) - if aerr != nil { - return nil, aerr - } - - if err := vmctx.Storage().Commit(old, nroot); err != nil { - return nil, err - } - - return nil, nil -} - -func checkProofSubmissionsAtH(vmctx types.VMContext, self *StoragePowerState, height uint64) aerrors.ActorError { - ctx := vmctx.Context() - bucketID := height % build.SlashablePowerDelay - - buckets, eerr := amt.LoadAMT(ctx, vmctx.Ipld(), self.ProvingBuckets) - if eerr != nil { - return aerrors.HandleExternalError(eerr, "loading proving buckets amt") - } - - var bucket cid.Cid - err := buckets.Get(ctx, bucketID, &bucket) - switch err.(type) { - case *amt.ErrNotFound: - return nil // nothing to do - case nil: - default: - return aerrors.HandleExternalError(err, "getting proving bucket") - } - - bhamt, err := hamt.LoadNode(vmctx.Context(), vmctx.Ipld(), bucket) - if err != nil { - return aerrors.HandleExternalError(err, "failed to load proving bucket") - } - - forRemoval := make([]address.Address, 0) - - err = bhamt.ForEach(vmctx.Context(), func(k string, val interface{}) error { - _, span := trace.StartSpan(vmctx.Context(), "StoragePowerActor.CheckProofSubmissions.loop") - defer span.End() - - maddr, err := address.NewFromBytes([]byte(k)) - if err != nil { - return aerrors.Escalate(err, "parsing miner address") - } - - has, aerr := MinerSetHas(vmctx, self.Miners, maddr) - if aerr != nil { - return aerr - } - - if !has { - forRemoval = append(forRemoval, maddr) - } - - span.AddAttributes(trace.StringAttribute("miner", maddr.String())) - - params, err := SerializeParams(&CheckMinerParams{NetworkPower: self.TotalStorage}) - if err != nil { - return err - } - - ret, err := vmctx.Send(maddr, MAMethods.CheckMiner, types.NewInt(0), params) - if err != nil { - return err - } - - if len(ret) == 0 { - return nil // miner is fine - } - - var power types.BigInt - if err := power.UnmarshalCBOR(bytes.NewReader(ret)); err != nil { - return xerrors.Errorf("unmarshaling CheckMiner response (%x): %w", ret, err) - } - - return nil - }) - - if err != nil { - return aerrors.HandleExternalError(err, "iterating miners in proving bucket") - } - - if len(forRemoval) > 0 { - nBucket, err := MinerSetRemove(vmctx.Context(), vmctx, bucket, forRemoval...) - - if err != nil { - return aerrors.Wrap(err, "could not remove miners from set") - } - - eerr := buckets.Set(ctx, bucketID, nBucket) - if err != nil { - return aerrors.HandleExternalError(eerr, "could not set the bucket") - } - ncid, eerr := buckets.Flush(ctx) - if err != nil { - return aerrors.HandleExternalError(eerr, "could not flush buckets") - } - self.ProvingBuckets = ncid - } - - return nil -} - -func MinerSetHas(vmctx types.VMContext, rcid cid.Cid, maddr address.Address) (bool, aerrors.ActorError) { - nd, err := hamt.LoadNode(vmctx.Context(), vmctx.Ipld(), rcid) - if err != nil { - return false, aerrors.HandleExternalError(err, "failed to load miner set") - } - - err = nd.Find(vmctx.Context(), string(maddr.Bytes()), nil) - switch err { - case hamt.ErrNotFound: - return false, nil - case nil: - return true, nil - default: - return false, aerrors.HandleExternalError(err, "failed to do set lookup") - } -} - -func MinerSetList(ctx context.Context, cst cbor.IpldStore, rcid cid.Cid) ([]address.Address, error) { - nd, err := hamt.LoadNode(ctx, cst, rcid) - if err != nil { - return nil, xerrors.Errorf("failed to load miner set: %w", err) - } - - var out []address.Address - err = nd.ForEach(ctx, func(k string, val interface{}) error { - addr, err := address.NewFromBytes([]byte(k)) - if err != nil { - return err - } - out = append(out, addr) - return nil - }) - if err != nil { - return nil, err - } - - return out, nil -} - -func MinerSetAdd(ctx context.Context, vmctx types.VMContext, rcid cid.Cid, maddr address.Address) (cid.Cid, aerrors.ActorError) { - nd, err := hamt.LoadNode(ctx, vmctx.Ipld(), rcid) - if err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to load miner set") - } - - mkey := string(maddr.Bytes()) - err = nd.Find(ctx, mkey, nil) - if err == nil { - return cid.Undef, aerrors.New(20, "miner already in set") - } - - if !xerrors.Is(err, hamt.ErrNotFound) { - return cid.Undef, aerrors.HandleExternalError(err, "failed to do miner set check") - } - - if err := nd.Set(ctx, mkey, uint64(1)); err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "adding miner address to set failed") - } - - if err := nd.Flush(ctx); err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to flush miner set") - } - - c, err := vmctx.Ipld().Put(ctx, nd) - if err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to persist miner set to storage") - } - - return c, nil -} - -func MinerSetRemove(ctx context.Context, vmctx types.VMContext, rcid cid.Cid, maddrs ...address.Address) (cid.Cid, aerrors.ActorError) { - nd, err := hamt.LoadNode(ctx, vmctx.Ipld(), rcid) - if err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to load miner set") - } - - for _, maddr := range maddrs { - mkey := string(maddr.Bytes()) - switch nd.Delete(ctx, mkey) { - default: - return cid.Undef, aerrors.HandleExternalError(err, "failed to delete miner from set") - case hamt.ErrNotFound: - return cid.Undef, aerrors.New(1, "miner not found in set on delete") - case nil: - } - } - - if err := nd.Flush(ctx); err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to flush miner set") - } - - c, err := vmctx.Ipld().Put(ctx, nd) - if err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to persist miner set to storage") - } - - return c, nil -} - -type cbgNull struct{} - -var CborNull = &cbgNull{} - -func (cbgNull) MarshalCBOR(w io.Writer) error { - n, err := w.Write(cbg.CborNull) - if err != nil { - return err - } - if n != 1 { - return xerrors.New("expected to write 1 byte") - } - return nil -} - -func (cbgNull) UnmarshalCBOR(r io.Reader) error { - b := [1]byte{} - n, err := r.Read(b[:]) - if err != nil { - return err - } - if n != 1 { - return xerrors.New("expected 1 byte") - } - if !bytes.Equal(b[:], cbg.CborNull) { - return xerrors.New("expected cbor null") - } - return nil -} +type StoragePowerState = power.State diff --git a/chain/actors/cbor_gen.go b/chain/actors/cbor_gen.go index 43ac02d9b..6a6482ea1 100644 --- a/chain/actors/cbor_gen.go +++ b/chain/actors/cbor_gen.go @@ -5,10 +5,7 @@ package actors import ( "fmt" "io" - "sort" - "github.com/filecoin-project/lotus/chain/types" - "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" ) @@ -152,1986 +149,3 @@ func (t *ExecParams) UnmarshalCBOR(r io.Reader) error { } return nil } - -func (t *AccountActorState) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{129}); err != nil { - return err - } - - // t.Address (address.Address) (struct) - if err := t.Address.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *AccountActorState) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 1 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Address (address.Address) (struct) - - { - - if err := t.Address.UnmarshalCBOR(br); err != nil { - return err - } - - } - return nil -} - -func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{138}); err != nil { - return err - } - - // t.PreCommittedSectors (map[string]*actors.PreCommittedSector) (map) - { - if len(t.PreCommittedSectors) > 4096 { - return xerrors.Errorf("cannot marshal t.PreCommittedSectors map too large") - } - - if err := cbg.CborWriteHeader(w, cbg.MajMap, uint64(len(t.PreCommittedSectors))); err != nil { - return err - } - - keys := make([]string, 0, len(t.PreCommittedSectors)) - for k := range t.PreCommittedSectors { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - v := t.PreCommittedSectors[k] - - if len(k) > cbg.MaxLength { - return xerrors.Errorf("Value in field k was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(k)))); err != nil { - return err - } - if _, err := w.Write([]byte(k)); err != nil { - return err - } - - if err := v.MarshalCBOR(w); err != nil { - return err - } - - } - } - - // t.Sectors (cid.Cid) (struct) - - if err := cbg.WriteCid(w, t.Sectors); err != nil { - return xerrors.Errorf("failed to write cid field t.Sectors: %w", err) - } - - // t.ProvingSet (cid.Cid) (struct) - - if err := cbg.WriteCid(w, t.ProvingSet); err != nil { - return xerrors.Errorf("failed to write cid field t.ProvingSet: %w", err) - } - - // t.Info (cid.Cid) (struct) - - if err := cbg.WriteCid(w, t.Info); err != nil { - return xerrors.Errorf("failed to write cid field t.Info: %w", err) - } - - // t.FaultSet (types.BitField) (struct) - if err := t.FaultSet.MarshalCBOR(w); err != nil { - return err - } - - // t.LastFaultSubmission (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.LastFaultSubmission))); err != nil { - return err - } - - // t.Power (types.BigInt) (struct) - if err := t.Power.MarshalCBOR(w); err != nil { - return err - } - - // t.Active (bool) (bool) - if err := cbg.WriteBool(w, t.Active); err != nil { - return err - } - - // t.SlashedAt (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SlashedAt))); err != nil { - return err - } - - // t.ElectionPeriodStart (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ElectionPeriodStart))); err != nil { - return err - } - return nil -} - -func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 10 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.PreCommittedSectors (map[string]*actors.PreCommittedSector) (map) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajMap { - return fmt.Errorf("expected a map (major type 5)") - } - if extra > 4096 { - return fmt.Errorf("t.PreCommittedSectors: map too large") - } - - t.PreCommittedSectors = make(map[string]*PreCommittedSector, extra) - - for i, l := 0, int(extra); i < l; i++ { - - var k string - - { - sval, err := cbg.ReadString(br) - if err != nil { - return err - } - - k = string(sval) - } - - var v *PreCommittedSector - - { - - pb, err := br.PeekByte() - if err != nil { - return err - } - if pb == cbg.CborNull[0] { - var nbuf [1]byte - if _, err := br.Read(nbuf[:]); err != nil { - return err - } - } else { - v = new(PreCommittedSector) - if err := v.UnmarshalCBOR(br); err != nil { - return err - } - } - - } - - t.PreCommittedSectors[k] = v - - } - // t.Sectors (cid.Cid) (struct) - - { - - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("failed to read cid field t.Sectors: %w", err) - } - - t.Sectors = c - - } - // t.ProvingSet (cid.Cid) (struct) - - { - - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("failed to read cid field t.ProvingSet: %w", err) - } - - t.ProvingSet = c - - } - // t.Info (cid.Cid) (struct) - - { - - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("failed to read cid field t.Info: %w", err) - } - - t.Info = c - - } - // t.FaultSet (types.BitField) (struct) - - { - - if err := t.FaultSet.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.LastFaultSubmission (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.LastFaultSubmission = uint64(extra) - // t.Power (types.BigInt) (struct) - - { - - if err := t.Power.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.Active (bool) (bool) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajOther { - return fmt.Errorf("booleans must be major type 7") - } - switch extra { - case 20: - t.Active = false - case 21: - t.Active = true - default: - return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) - } - // t.SlashedAt (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.SlashedAt = uint64(extra) - // t.ElectionPeriodStart (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - return nil -} - -func (t *StorageMinerConstructorParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{132}); err != nil { - return err - } - - // t.Owner (address.Address) (struct) - if err := t.Owner.MarshalCBOR(w); err != nil { - return err - } - - // t.Worker (address.Address) (struct) - if err := t.Worker.MarshalCBOR(w); err != nil { - return err - } - - // t.SectorSize (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorSize))); err != nil { - return err - } - - // t.PeerID (peer.ID) (string) - if len(t.PeerID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.PeerID was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.PeerID)))); err != nil { - return err - } - if _, err := w.Write([]byte(t.PeerID)); err != nil { - return err - } - return nil -} - -func (t *SectorPreCommitInfo) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{132}); err != nil { - return err - } - - // t.SectorNumber (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorNumber))); err != nil { - return err - } - - // t.CommR ([]uint8) (slice) - if len(t.CommR) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.CommR was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommR)))); err != nil { - return err - } - if _, err := w.Write(t.CommR); err != nil { - return err - } - - // t.SealEpoch (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SealEpoch))); err != nil { - return err - } - - // t.DealIDs ([]uint64) (slice) - if len(t.DealIDs) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.DealIDs was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.DealIDs)))); err != nil { - return err - } - for _, v := range t.DealIDs { - if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, v); err != nil { - return err - } - } - return nil -} -func (i IsValidMinerParam) MarshalCBOR(io.Writer) error { - panic("implement me") -} - -func (t *SectorPreCommitInfo) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 4 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.SectorNumber (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - // t.CommR ([]uint8) (slice) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.CommR: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - t.CommR = make([]byte, extra) - if _, err := io.ReadFull(br, t.CommR); err != nil { - return err - } - // t.SealEpoch (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.SealEpoch = uint64(extra) - // t.DealIDs ([]uint64) (slice) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.DealIDs: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - if extra > 0 { - t.DealIDs = make([]uint64, extra) - } - for i := 0; i < int(extra); i++ { - - maj, val, err := cbg.CborReadHeader(br) - if err != nil { - return xerrors.Errorf("failed to read uint64 for t.DealIDs slice: %w", err) - } - - if maj != cbg.MajUnsignedInt { - return xerrors.Errorf("value read for array t.DealIDs was not a uint, instead got %d", maj) - } - - t.DealIDs[i] = val - } - - return nil -} - -func (t *PreCommittedSector) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{130}); err != nil { - return err - } - - // t.Info (actors.SectorPreCommitInfo) (struct) - if err := t.Info.MarshalCBOR(w); err != nil { - return err - } - - // t.ReceivedEpoch (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ReceivedEpoch))); err != nil { - return err - } - return nil -} - -func (t *PreCommittedSector) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 2 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Info (actors.SectorPreCommitInfo) (struct) - - { - - if err := t.Info.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.ReceivedEpoch (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.ReceivedEpoch = uint64(extra) - return nil -} - -func (t *MinerInfo) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{132}); err != nil { - return err - } - - // t.Owner (address.Address) (struct) - if err := t.Owner.MarshalCBOR(w); err != nil { - return err - } - - // t.Worker (address.Address) (struct) - if err := t.Worker.MarshalCBOR(w); err != nil { - return err - } - - // t.PeerID (peer.ID) (string) - if len(t.PeerID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.PeerID was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.PeerID)))); err != nil { - return err - } - if _, err := w.Write([]byte(t.PeerID)); err != nil { - return err - } - - // t.SectorSize (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorSize))); err != nil { - return err - } - return nil -} - -func (t *MinerInfo) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 4 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Owner (address.Address) (struct) - - { - - if err := t.Owner.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.Worker (address.Address) (struct) - - { - - if err := t.Worker.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.PeerID (peer.ID) (string) - - { - sval, err := cbg.ReadString(br) - if err != nil { - return err - } - - t.PeerID = peer.ID(sval) - } - // t.SectorSize (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - return nil -} - -func (t *SubmitFallbackPoStParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{130}); err != nil { - return err - } - - // t.Proof ([]uint8) (slice) - if len(t.Proof) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.Proof was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil { - return err - } - if _, err := w.Write(t.Proof); err != nil { - return err - } - - // t.Candidates ([]types.EPostTicket) (slice) - if len(t.Candidates) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Candidates was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Candidates)))); err != nil { - return err - } - for _, v := range t.Candidates { - if err := v.MarshalCBOR(w); err != nil { - return err - } - } - return nil -} - -func (t *SubmitFallbackPoStParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 2 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Proof ([]uint8) (slice) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.Proof: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - t.Proof = make([]byte, extra) - if _, err := io.ReadFull(br, t.Proof); err != nil { - return err - } - // t.Candidates ([]types.EPostTicket) (slice) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Candidates: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - if extra > 0 { - t.Candidates = make([]types.EPostTicket, extra) - } - for i := 0; i < int(extra); i++ { - - var v types.EPostTicket - if err := v.UnmarshalCBOR(br); err != nil { - return err - } - - t.Candidates[i] = v - } - - return nil -} - -func (t *PaymentVerifyParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{130}); err != nil { - return err - } - - // t.Extra ([]uint8) (slice) - if len(t.Extra) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.Extra was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Extra)))); err != nil { - return err - } - if _, err := w.Write(t.Extra); err != nil { - return err - } - - // t.Proof ([]uint8) (slice) - if len(t.Proof) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.Proof was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil { - return err - } - if _, err := w.Write(t.Proof); err != nil { - return err - } - return nil -} - -func (t *PaymentVerifyParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 2 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Extra ([]uint8) (slice) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.Extra: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - t.Extra = make([]byte, extra) - if _, err := io.ReadFull(br, t.Extra); err != nil { - return err - } - // t.Proof ([]uint8) (slice) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.Proof: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - t.Proof = make([]byte, extra) - if _, err := io.ReadFull(br, t.Proof); err != nil { - return err - } - return nil -} - -func (t *UpdatePeerIDParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{129}); err != nil { - return err - } - - // t.PeerID (peer.ID) (string) - if len(t.PeerID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.PeerID was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.PeerID)))); err != nil { - return err - } - if _, err := w.Write([]byte(t.PeerID)); err != nil { - return err - } - return nil -} - -func (t *UpdatePeerIDParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 1 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.PeerID (peer.ID) (string) - - { - sval, err := cbg.ReadString(br) - if err != nil { - return err - } - - t.PeerID = peer.ID(sval) - } - return nil -} - -func (t *DeclareFaultsParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{129}); err != nil { - return err - } - - // t.Faults (types.BitField) (struct) - if err := t.Faults.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *DeclareFaultsParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 1 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Faults (types.BitField) (struct) - - { - - if err := t.Faults.UnmarshalCBOR(br); err != nil { - return err - } - - } - return nil -} - -func (t *PaymentChannelActorState) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{134}); err != nil { - return err - } - - // t.From (address.Address) (struct) - if err := t.From.MarshalCBOR(w); err != nil { - return err - } - - // t.To (address.Address) (struct) - if err := t.To.MarshalCBOR(w); err != nil { - return err - } - - // t.ToSend (types.BigInt) (struct) - if err := t.ToSend.MarshalCBOR(w); err != nil { - return err - } - - // t.ClosingAt (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ClosingAt))); err != nil { - return err - } - - // t.MinCloseHeight (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.MinCloseHeight))); err != nil { - return err - } - - // t.LaneStates (map[string]*actors.LaneState) (map) - { - if len(t.LaneStates) > 4096 { - return xerrors.Errorf("cannot marshal t.LaneStates map too large") - } - - if err := cbg.CborWriteHeader(w, cbg.MajMap, uint64(len(t.LaneStates))); err != nil { - return err - } - - keys := make([]string, 0, len(t.LaneStates)) - for k := range t.LaneStates { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - v := t.LaneStates[k] - - if len(k) > cbg.MaxLength { - return xerrors.Errorf("Value in field k was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(k)))); err != nil { - return err - } - if _, err := w.Write([]byte(k)); err != nil { - return err - } - - if err := v.MarshalCBOR(w); err != nil { - return err - } - - } - } - return nil -} - -func (t *PaymentChannelActorState) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 6 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.From (address.Address) (struct) - - { - - if err := t.From.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.To (address.Address) (struct) - - { - - if err := t.To.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.ToSend (types.BigInt) (struct) - - { - - if err := t.ToSend.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.ClosingAt (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.ClosingAt = uint64(extra) - // t.MinCloseHeight (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.MinCloseHeight = uint64(extra) - // t.LaneStates (map[string]*actors.LaneState) (map) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajMap { - return fmt.Errorf("expected a map (major type 5)") - } - if extra > 4096 { - return fmt.Errorf("t.LaneStates: map too large") - } - - t.LaneStates = make(map[string]*LaneState, extra) - - for i, l := 0, int(extra); i < l; i++ { - - var k string - - { - sval, err := cbg.ReadString(br) - if err != nil { - return err - } - - k = string(sval) - } - - var v *LaneState - - { - - pb, err := br.PeekByte() - if err != nil { - return err - } - if pb == cbg.CborNull[0] { - var nbuf [1]byte - if _, err := br.Read(nbuf[:]); err != nil { - return err - } - } else { - v = new(LaneState) - if err := v.UnmarshalCBOR(br); err != nil { - return err - } - } - - } - - t.LaneStates[k] = v - - } - return nil -} - -func (t *PCAConstructorParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{129}); err != nil { - return err - } - - // t.To (address.Address) (struct) - if err := t.To.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *PCAConstructorParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 1 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.To (address.Address) (struct) - - { - - if err := t.To.UnmarshalCBOR(br); err != nil { - return err - } - - } - return nil -} - -func (t *LaneState) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{131}); err != nil { - return err - } - - // t.Closed (bool) (bool) - if err := cbg.WriteBool(w, t.Closed); err != nil { - return err - } - - // t.Redeemed (types.BigInt) (struct) - if err := t.Redeemed.MarshalCBOR(w); err != nil { - return err - } - - // t.Nonce (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Nonce))); err != nil { - return err - } - return nil -} - -func (t *LaneState) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 3 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Closed (bool) (bool) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajOther { - return fmt.Errorf("booleans must be major type 7") - } - switch extra { - case 20: - t.Closed = false - case 21: - t.Closed = true - default: - return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) - } - // t.Redeemed (types.BigInt) (struct) - - { - - if err := t.Redeemed.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.Nonce (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.Nonce = uint64(extra) - return nil -} - -func (t *PCAUpdateChannelStateParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{131}); err != nil { - return err - } - - // t.Sv (types.SignedVoucher) (struct) - if err := t.Sv.MarshalCBOR(w); err != nil { - return err - } - - // t.Secret ([]uint8) (slice) - if len(t.Secret) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.Secret was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Secret)))); err != nil { - return err - } - if _, err := w.Write(t.Secret); err != nil { - return err - } - - // t.Proof ([]uint8) (slice) - if len(t.Proof) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.Proof was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil { - return err - } - if _, err := w.Write(t.Proof); err != nil { - return err - } - return nil -} - -func (t *PCAUpdateChannelStateParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 3 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Sv (types.SignedVoucher) (struct) - - { - - if err := t.Sv.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.Secret ([]uint8) (slice) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.Secret: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - t.Secret = make([]byte, extra) - if _, err := io.ReadFull(br, t.Secret); err != nil { - return err - } - // t.Proof ([]uint8) (slice) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.Proof: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - t.Proof = make([]byte, extra) - if _, err := io.ReadFull(br, t.Proof); err != nil { - return err - } - return nil -} - -func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{132}); err != nil { - return err - } - - // t.PayChActor (address.Address) (struct) - if err := t.PayChActor.MarshalCBOR(w); err != nil { - return err - } - - // t.Payer (address.Address) (struct) - if err := t.Payer.MarshalCBOR(w); err != nil { - return err - } - - // t.ChannelMessage (cid.Cid) (struct) - - if t.ChannelMessage == nil { - if _, err := w.Write(cbg.CborNull); err != nil { - return err - } - } else { - if err := cbg.WriteCid(w, *t.ChannelMessage); err != nil { - return xerrors.Errorf("failed to write cid field t.ChannelMessage: %w", err) - } - } - - // t.Vouchers ([]*types.SignedVoucher) (slice) - if len(t.Vouchers) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Vouchers was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Vouchers)))); err != nil { - return err - } - for _, v := range t.Vouchers { - if err := v.MarshalCBOR(w); err != nil { - return err - } - } - return nil -} - -func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 4 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.PayChActor (address.Address) (struct) - - { - - if err := t.PayChActor.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.Payer (address.Address) (struct) - - { - - if err := t.Payer.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.ChannelMessage (cid.Cid) (struct) - - { - - pb, err := br.PeekByte() - if err != nil { - return err - } - if pb == cbg.CborNull[0] { - var nbuf [1]byte - if _, err := br.Read(nbuf[:]); err != nil { - return err - } - } else { - - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("failed to read cid field t.ChannelMessage: %w", err) - } - - t.ChannelMessage = &c - } - - } - // t.Vouchers ([]*types.SignedVoucher) (slice) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Vouchers: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - if extra > 0 { - t.Vouchers = make([]*types.SignedVoucher, extra) - } - for i := 0; i < int(extra); i++ { - - var v types.SignedVoucher - if err := v.UnmarshalCBOR(br); err != nil { - return err - } - - t.Vouchers[i] = &v - } - - return nil -} - -func (t *StoragePowerState) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{133}); err != nil { - return err - } - - // t.Miners (cid.Cid) (struct) - - if err := cbg.WriteCid(w, t.Miners); err != nil { - return xerrors.Errorf("failed to write cid field t.Miners: %w", err) - } - - // t.ProvingBuckets (cid.Cid) (struct) - - if err := cbg.WriteCid(w, t.ProvingBuckets); err != nil { - return xerrors.Errorf("failed to write cid field t.ProvingBuckets: %w", err) - } - - // t.MinerCount (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.MinerCount))); err != nil { - return err - } - - // t.LastMinerCheck (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.LastMinerCheck))); err != nil { - return err - } - - // t.TotalStorage (types.BigInt) (struct) - if err := t.TotalStorage.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *StoragePowerState) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 5 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Miners (cid.Cid) (struct) - - { - - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("failed to read cid field t.Miners: %w", err) - } - - t.Miners = c - - } - // t.ProvingBuckets (cid.Cid) (struct) - - { - - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("failed to read cid field t.ProvingBuckets: %w", err) - } - - t.ProvingBuckets = c - - } - // t.MinerCount (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.MinerCount = uint64(extra) - // t.LastMinerCheck (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.LastMinerCheck = uint64(extra) - // t.TotalStorage (types.BigInt) (struct) - - { - - if err := t.TotalStorage.UnmarshalCBOR(br); err != nil { - return err - } - - } - return nil -} - -func (t *CreateStorageMinerParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{132}); err != nil { - return err - } - - // t.Owner (address.Address) (struct) - if err := t.Owner.MarshalCBOR(w); err != nil { - return err - } - - // t.Worker (address.Address) (struct) - if err := t.Worker.MarshalCBOR(w); err != nil { - return err - } - - // t.SectorSize (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorSize))); err != nil { - return err - } - - // t.PeerID (peer.ID) (string) - if len(t.PeerID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.PeerID was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.PeerID)))); err != nil { - return err - } - if _, err := w.Write([]byte(t.PeerID)); err != nil { - return err - } - return nil -} - -func (t *PowerLookupParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{129}); err != nil { - return err - } - - // t.Miner (address.Address) (struct) - if err := t.Miner.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *PowerLookupParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 1 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Miner (address.Address) (struct) - - { - - if err := t.Miner.UnmarshalCBOR(br); err != nil { - return err - } - - } - return nil -} - -func (t *UpdateStorageParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{131}); err != nil { - return err - } - - // t.Delta (types.BigInt) (struct) - if err := t.Delta.MarshalCBOR(w); err != nil { - return err - } - - // t.NextSlashDeadline (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.NextSlashDeadline))); err != nil { - return err - } - - // t.PreviousSlashDeadline (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.PreviousSlashDeadline))); err != nil { - return err - } - return nil -} - -func (t *UpdateStorageParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 3 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Delta (types.BigInt) (struct) - - { - - if err := t.Delta.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.NextSlashDeadline (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.NextSlashDeadline = uint64(extra) - // t.PreviousSlashDeadline (uint64) (uint64) - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.PreviousSlashDeadline = uint64(extra) - return nil -} - -func (t *ArbitrateConsensusFaultParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{130}); err != nil { - return err - } - - // t.Block1 (types.BlockHeader) (struct) - if err := t.Block1.MarshalCBOR(w); err != nil { - return err - } - - // t.Block2 (types.BlockHeader) (struct) - if err := t.Block2.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *ArbitrateConsensusFaultParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 2 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Block1 (types.BlockHeader) (struct) - - { - - pb, err := br.PeekByte() - if err != nil { - return err - } - if pb == cbg.CborNull[0] { - var nbuf [1]byte - if _, err := br.Read(nbuf[:]); err != nil { - return err - } - } else { - t.Block1 = new(types.BlockHeader) - if err := t.Block1.UnmarshalCBOR(br); err != nil { - return err - } - } - - } - // t.Block2 (types.BlockHeader) (struct) - - { - - pb, err := br.PeekByte() - if err != nil { - return err - } - if pb == cbg.CborNull[0] { - var nbuf [1]byte - if _, err := br.Read(nbuf[:]); err != nil { - return err - } - } else { - t.Block2 = new(types.BlockHeader) - if err := t.Block2.UnmarshalCBOR(br); err != nil { - return err - } - } - - } - return nil -} - -func (t *PledgeCollateralParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{129}); err != nil { - return err - } - - // t.Size (types.BigInt) (struct) - if err := t.Size.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *PledgeCollateralParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 1 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Size (types.BigInt) (struct) - - { - - if err := t.Size.UnmarshalCBOR(br); err != nil { - return err - } - - } - return nil -} - -func (t *MinerSlashConsensusFault) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{131}); err != nil { - return err - } - - // t.Slasher (address.Address) (struct) - if err := t.Slasher.MarshalCBOR(w); err != nil { - return err - } - - // t.AtHeight (uint64) (uint64) - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.AtHeight))); err != nil { - return err - } - - // t.SlashedCollateral (types.BigInt) (struct) - if err := t.SlashedCollateral.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *MinerSlashConsensusFault) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 3 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Slasher (address.Address) (struct) - - { - - if err := t.Slasher.UnmarshalCBOR(br); err != nil { - return err - } - - } - // t.AtHeight (uint64) (uint64) - - // t.SlashedCollateral (types.BigInt) (struct) - - { - - if err := t.SlashedCollateral.UnmarshalCBOR(br); err != nil { - return err - } - - } - return nil -} -func (t *CheckMinerParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{129}); err != nil { - return err - } - - // t.NetworkPower (types.BigInt) (struct) - if err := t.NetworkPower.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *CheckMinerParams) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 1 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.NetworkPower (types.BigInt) (struct) - - { - - if err := t.NetworkPower.UnmarshalCBOR(br); err != nil { - return err - } - - } - return nil -} - -func (t *CronActorState) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{128}); err != nil { - return err - } - return nil -} - -func (t *CronActorState) UnmarshalCBOR(r io.Reader) error { - br := cbg.GetPeeker(r) - - maj, extra, err := cbg.CborReadHeader(br) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 0 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - return nil -} diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index d1a93589c..456e3c128 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -14,6 +14,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/util/adt" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -178,11 +179,12 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl } // all block miners created a valid post, go update the actor state + panic("sys actor call") postSubmitMsg := &types.Message{ From: actors.NetworkAddress, Nonce: netact.Nonce, To: b.Miner, - Method: actors.MAMethods.SubmitElectionPoSt, + Method: builtin.MethodsMiner.OnVerifiedElectionPoSt, GasPrice: types.NewInt(0), GasLimit: types.NewInt(10000000000), Value: types.NewInt(0), @@ -274,7 +276,7 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl Value: types.NewInt(0), GasPrice: types.NewInt(0), GasLimit: types.NewInt(1 << 30), // Make super sure this is never too little - Method: actors.CAMethods.EpochTick, + Method: builtin.MethodsCron.EpochTick, Params: nil, }) if err != nil { diff --git a/chain/store/weight.go b/chain/store/weight.go index 49ef9ef26..40dd9a755 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -23,10 +23,11 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn // >>> wFunction(totalPowerAtTipset(ts)) * 2^8 <<< + (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den) + panic("TODO") ret, err := cs.call(ctx, &types.Message{ From: actors.StoragePowerAddress, To: actors.StoragePowerAddress, - Method: actors.SPAMethods.GetTotalStorage, + Method: 999, // actors.SPAMethods.GetTotalStorage, }, ts) if err != nil { return types.EmptyInt, xerrors.Errorf("failed to get total power from chain: %w", err) diff --git a/chain/types/cbor_gen.go b/chain/types/cbor_gen.go index b332b6aee..e3a0d894e 100644 --- a/chain/types/cbor_gen.go +++ b/chain/types/cbor_gen.go @@ -680,7 +680,6 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { if maj != cbg.MajUnsignedInt { return fmt.Errorf("wrong type for uint64 field") } - t.Method = uint64(extra) // t.Params ([]uint8) (slice) maj, extra, err = cbg.CborReadHeader(br) diff --git a/chain/types/message.go b/chain/types/message.go index 4ed940b67..23228b9e2 100644 --- a/chain/types/message.go +++ b/chain/types/message.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" + "github.com/filecoin-project/specs-actors/actors/abi" block "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" "github.com/multiformats/go-multihash" @@ -22,7 +23,7 @@ type Message struct { GasPrice BigInt GasLimit BigInt - Method uint64 // TODO: decide + Method abi.MethodNum Params []byte } diff --git a/chain/types/vmcontext.go b/chain/types/vmcontext.go index fbd1f2cc3..3d83cfca1 100644 --- a/chain/types/vmcontext.go +++ b/chain/types/vmcontext.go @@ -33,7 +33,7 @@ type VMContext interface { Message() *Message Origin() address.Address Ipld() cbor.IpldStore - Send(to address.Address, method uint64, value BigInt, params []byte) ([]byte, aerrors.ActorError) + Send(to address.Address, method abi.MethodNum, value BigInt, params []byte) ([]byte, aerrors.ActorError) BlockHeight() abi.ChainEpoch GasUsed() BigInt Storage() Storage diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index 04709ce39..78878f6f8 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -7,6 +7,7 @@ import ( "reflect" "strings" + "github.com/filecoin-project/specs-actors/actors/abi" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -47,7 +48,7 @@ func NewInvoker() *invoker { return inv } -func (inv *invoker) Invoke(act *types.Actor, vmctx types.VMContext, method uint64, params []byte) ([]byte, aerrors.ActorError) { +func (inv *invoker) Invoke(act *types.Actor, vmctx types.VMContext, method abi.MethodNum, params []byte) ([]byte, aerrors.ActorError) { if act.Code == actors.AccountCodeCid { return nil, aerrors.Newf(254, "cannot invoke methods on account actors") @@ -58,7 +59,7 @@ func (inv *invoker) Invoke(act *types.Actor, vmctx types.VMContext, method uint6 log.Errorf("no code for actor %s (Addr: %s)", act.Code, vmctx.Message().To) return nil, aerrors.Newf(255, "no code for actor %s(%d)(%s)", act.Code, method, hex.EncodeToString(params)) } - if method >= uint64(len(code)) || code[method] == nil { + if method >= abi.MethodNum(len(code)) || code[method] == nil { return nil, aerrors.Newf(255, "no method %d on actor", method) } return code[method](act, vmctx, params) diff --git a/chain/vm/spec_shim.go b/chain/vm/spec_shim.go index 8067d75f6..656ee83d0 100644 --- a/chain/vm/spec_shim.go +++ b/chain/vm/spec_shim.go @@ -128,7 +128,7 @@ func (rs *runtimeShim) Send(to address.Address, method abi.MethodNum, m runtime. rs.Abort(exitcode.SysErrInvalidParameters, "failed to marshal input parameters: %s", err) } - ret, err := rs.vmctx.Send(to, uint64(method), types.BigInt(value), buf.Bytes()) + ret, err := rs.vmctx.Send(to, method, types.BigInt(value), buf.Bytes()) if err != nil { if err.IsFatal() { panic(err) diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 86199bb11..538297686 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -134,7 +134,7 @@ func (vmc *VMContext) Origin() address.Address { } // Send allows the current execution context to invoke methods on other actors in the system -func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt, params []byte) ([]byte, aerrors.ActorError) { +func (vmc *VMContext) Send(to address.Address, method abi.MethodNum, value types.BigInt, params []byte) ([]byte, aerrors.ActorError) { ctx, span := trace.StartSpan(vmc.ctx, "vmc.Send") defer span.End() if span.IsRecordingEvents() { @@ -627,7 +627,7 @@ func (vm *VM) SetBlockHeight(h abi.ChainEpoch) { vm.blockHeight = h } -func (vm *VM) Invoke(act *types.Actor, vmctx *VMContext, method uint64, params []byte) ([]byte, aerrors.ActorError) { +func (vm *VM) Invoke(act *types.Actor, vmctx *VMContext, method abi.MethodNum, params []byte) ([]byte, aerrors.ActorError) { ctx, span := trace.StartSpan(vmctx.ctx, "vm.Invoke") defer span.End() if span.IsRecordingEvents() {