extra careful power checks on slashing

This commit is contained in:
whyrusleeping 2020-01-30 16:36:18 -08:00
parent f2340579a5
commit 8ad8fa902d

View File

@ -404,6 +404,7 @@ func (sma StorageMinerActor2) GetPower(act *types.Actor, vmctx types.VMContext,
if err != nil {
return nil, err
}
return self.Power.Bytes(), nil
}
@ -631,6 +632,8 @@ func (sma StorageMinerActor2) CheckMiner(act *types.Actor, vmctx types.VMContext
// Slash for being late
self.SlashedAt = vmctx.BlockHeight()
oldPower := self.Power
self.Power = types.NewInt(0)
nstate, err := vmctx.Storage().Put(self)
if err != nil {
@ -641,7 +644,7 @@ func (sma StorageMinerActor2) CheckMiner(act *types.Actor, vmctx types.VMContext
}
var out bytes.Buffer
if err := self.Power.MarshalCBOR(&out); err != nil {
if err := oldPower.MarshalCBOR(&out); err != nil {
return nil, aerrors.HandleExternalError(err, "marshaling return value")
}
return out.Bytes(), nil
@ -726,6 +729,21 @@ func (sma StorageMinerActor2) SlashConsensusFault(act *types.Actor, vmctx types.
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