implement a minimum miner size

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
whyrusleeping 2019-12-09 17:08:34 +01:00 committed by Jakub Sztandera
parent 0b4db5530c
commit d64f8a38d1
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
7 changed files with 40 additions and 17 deletions

View File

@ -29,6 +29,9 @@ const InteractivePoRepDelay = 2
// Epochs
const InteractivePoRepConfidence = 6
// Bytes
const MinimumMinerPower = 2 << 10 // 2KiB
func init() {
os.Setenv("TRUST_PARAMS", "1")
}

View File

@ -31,3 +31,6 @@ const InteractivePoRepDelay = 8
// Epochs
const InteractivePoRepConfidence = 6
// Bytes
const MinimumMinerPower = 20 << 30 // 20GB

View File

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

View File

@ -912,8 +912,14 @@ func onSuccessfulPoSt(self *StorageMinerActorState, vmctx types.VMContext) aerro
faults := []uint64{} // TODO
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 {
@ -922,23 +928,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
}
}
self.ProvingSet = self.Sectors

View File

@ -237,3 +237,7 @@ func (bi *BigInt) UnmarshalCBOR(br io.Reader) error {
return nil
}
func (bi *BigInt) IsZero() bool {
return bi.Int.Sign() == 0
}

View File

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

View File

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