Make basic slashing work

This commit is contained in:
Łukasz Magiera 2019-11-14 01:02:24 +01:00
parent 7363ec714a
commit 2dd155e9e9
4 changed files with 22 additions and 4 deletions

View File

@ -13,6 +13,7 @@ const UnixfsChunkSize uint64 = 1 << 20
const UnixfsLinksPerLevel = 1024
var SectorSizes = []uint64{
1024,
16 << 20,
256 << 20,
1 << 30,
@ -37,7 +38,7 @@ const PaymentChannelClosingDelay = 6 * 60 * 2 // six hours
// Consensus / Network
// Seconds
const BlockDelay = 10
const BlockDelay = 2
// Seconds
const AllowableClockDrift = BlockDelay * 2
@ -60,7 +61,7 @@ const WRatioDen = 2
// Proofs
// Blocks
const ProvingPeriodDuration uint64 = 160
const ProvingPeriodDuration uint64 = 20
// PoStChallangeTime sets the window in which post computation should happen
// Blocks

View File

@ -739,7 +739,7 @@ func (sma StorageMinerActor) GetSectorSize(act *types.Actor, vmctx types.VMConte
}
func isLate(height uint64, self *StorageMinerActorState) bool {
return height >= self.ProvingPeriodEnd // TODO: review: maybe > ?
return self.ProvingPeriodEnd == 0 || height >= self.ProvingPeriodEnd // TODO: review: maybe > ?
}
func (sma StorageMinerActor) IsLate(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {

View File

@ -591,6 +591,8 @@ func (spa StoragePowerActor) CheckProofSubmissions(act *types.Actor, vmctx types
return nil // miner is fine
}
log.Warnf("slashing miner %s for missed PoSt", maddr)
power := types.NewInt(0)
power.SetBytes(ret)
@ -602,6 +604,15 @@ func (spa StoragePowerActor) CheckProofSubmissions(act *types.Actor, vmctx types
return nil, aerrors.HandleExternalError(err, "iterating miners in proving bucket")
}
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
}

View File

@ -187,11 +187,17 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
}
}
// TODO: this nonce-getting is a ting bit ugly
spa, err := vmi.StateTree().GetActor(actors.StoragePowerAddress)
if err != nil {
return cid.Undef, cid.Undef, err
}
// TODO: cron actor
ret, err := vmi.ApplyMessage(ctx, &types.Message{
To: actors.StoragePowerAddress,
From: actors.StoragePowerAddress,
Nonce: blks[0].Height - 1,
Nonce: spa.Nonce,
Value: types.NewInt(0),
GasPrice: types.NewInt(0),
GasLimit: types.NewInt(1 << 30), // Make super sure this is never too little