diff --git a/build/params_debug.go b/build/params_debug.go index 093566aa7..aaa58038b 100644 --- a/build/params_debug.go +++ b/build/params_debug.go @@ -29,6 +29,9 @@ const InteractivePoRepDelay = 2 // Epochs const InteractivePoRepConfidence = 6 +// Bytes +const MinimumMinerPower = 2 << 10 // 2KiB + func init() { os.Setenv("TRUST_PARAMS", "1") } diff --git a/build/params_devnet.go b/build/params_devnet.go index f187bf60a..ca356aff5 100644 --- a/build/params_devnet.go +++ b/build/params_devnet.go @@ -31,3 +31,6 @@ const InteractivePoRepDelay = 8 // Epochs const InteractivePoRepConfidence = 6 + +// Bytes +const MinimumMinerPower = 20 << 30 // 20GB diff --git a/build/params_shared.go b/build/params_shared.go index 3d3bc9aac..755bda687 100644 --- a/build/params_shared.go +++ b/build/params_shared.go @@ -77,6 +77,7 @@ const CollateralPrecision = 1000 const TotalFilecoin = 2_000_000_000 const MiningRewardTotal = 1_400_000_000 + const InitialRewardStr = "153856861913558700202" var InitialReward *big.Int diff --git a/chain/actors/actor_miner.go b/chain/actors/actor_miner.go index 4e1ba5570..3360f5e25 100644 --- a/chain/actors/actor_miner.go +++ b/chain/actors/actor_miner.go @@ -926,8 +926,14 @@ func onSuccessfulPoSt(self *StorageMinerActorState, vmctx types.VMContext) aerro self.FaultSet = types.NewBitField() oldPower := self.Power - self.Power = types.BigMul(types.NewInt(pss.Count-uint64(len(faults))), - types.NewInt(mi.SectorSize)) + newPower := types.BigMul(types.NewInt(pss.Count-uint64(len(faults))), types.NewInt(mi.SectorSize)) + + // If below the minimum size requirement, miners have zero power + if newPower.LessThan(types.NewInt(build.MinimumMinerPower)) { + newPower = types.NewInt(0) + } + + self.Power = newPower delta := types.BigSub(self.Power, oldPower) if self.SlashedAt != 0 { @@ -936,23 +942,25 @@ func onSuccessfulPoSt(self *StorageMinerActorState, vmctx types.VMContext) aerro } prevSlashingDeadline := self.ElectionPeriodStart + build.SlashablePowerDelay - if !self.Active { + if !self.Active && newPower.GreaterThan(types.NewInt(0)) { self.Active = true prevSlashingDeadline = 0 } - enc, err := SerializeParams(&UpdateStorageParams{ - Delta: delta, - NextProvingPeriodEnd: vmctx.BlockHeight() + build.SlashablePowerDelay, - PreviousProvingPeriodEnd: prevSlashingDeadline, - }) - if err != nil { - return err - } + if !(oldPower.IsZero() && newPower.IsZero()) { + enc, err := SerializeParams(&UpdateStorageParams{ + Delta: delta, + NextProvingPeriodEnd: vmctx.BlockHeight() + build.SlashablePowerDelay, + PreviousProvingPeriodEnd: prevSlashingDeadline, + }) + if err != nil { + return err + } - _, err = vmctx.Send(StoragePowerAddress, SPAMethods.UpdateStorage, types.NewInt(0), enc) - if err != nil { - return err + _, err = vmctx.Send(StoragePowerAddress, SPAMethods.UpdateStorage, types.NewInt(0), enc) + if err != nil { + return err + } } ncid, err := RemoveFromSectorSet(vmctx.Context(), vmctx.Storage(), self.Sectors, faults) diff --git a/chain/types/bigint.go b/chain/types/bigint.go index 266f2a8af..612fd34dc 100644 --- a/chain/types/bigint.go +++ b/chain/types/bigint.go @@ -237,3 +237,7 @@ func (bi *BigInt) UnmarshalCBOR(br io.Reader) error { return nil } + +func (bi *BigInt) IsZero() bool { + return bi.Int.Sign() == 0 +} diff --git a/lotuspond/spawn.go b/lotuspond/spawn.go index f3534ece1..2146554b6 100644 --- a/lotuspond/spawn.go +++ b/lotuspond/spawn.go @@ -17,6 +17,10 @@ import ( "github.com/filecoin-project/lotus/cmd/lotus-seed/seed" ) +func init() { + build.SectorSizes = []uint64{1024} +} + func (api *api) Spawn() (nodeInfo, error) { dir, err := ioutil.TempDir(os.TempDir(), "lotus-") if err != nil { @@ -36,7 +40,7 @@ func (api *api) Spawn() (nodeInfo, error) { } sbroot := filepath.Join(dir, "preseal") - genm, err := seed.PreSeal(genMiner, build.SectorSizes[0], 0, 1, sbroot, []byte("8")) + genm, err := seed.PreSeal(genMiner, build.SectorSizes[0], 0, 2, sbroot, []byte("8")) if err != nil { return nodeInfo{}, xerrors.Errorf("preseal failed: %w", err) } diff --git a/miner/miner.go b/miner/miner.go index ee59f5d59..98def0e07 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -170,8 +170,6 @@ eventLoop: } lastBase = *base - log.Infof("Time delta between now and our mining base: %ds", uint64(time.Now().Unix())-base.ts.MinTimestamp()) - blks := make([]*types.BlockMsg, 0) for _, addr := range addrs { @@ -272,6 +270,8 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB return nil, nil } + log.Infof("Time delta between now and our mining base: %ds", uint64(time.Now().Unix())-base.ts.MinTimestamp()) + ticket, err := m.computeTicket(ctx, addr, base) if err != nil { return nil, xerrors.Errorf("scratching ticket failed: %w", err)