implement AddFaults method

This commit is contained in:
whyrusleeping 2019-09-23 11:41:53 -07:00
parent a21846aa6e
commit 0419945d49

View File

@ -144,7 +144,7 @@ func (sma StorageMinerActor) Exports() []interface{} {
//16: sma.IsLate,
17: sma.PaymentVerifyInclusion,
18: sma.PaymentVerifySector,
19: nil,
19: sma.AddFaults,
20: sma.SlashConsensusFault,
}
}
@ -707,6 +707,40 @@ func (sma StorageMinerActor) PaymentVerifySector(act *types.Actor, vmctx types.V
return nil, nil
}
type AddFaultsParams struct {
Faults types.BitField
}
func (sma StorageMinerActor) AddFaults(act *types.Actor, vmctx types.VMContext, params *AddFaultsParams) ([]byte, ActorError) {
oldstate, self, aerr := loadState(vmctx)
if aerr != nil {
return nil, aerr
}
challengeHeight := self.ProvingPeriodEnd - build.PoSTChallangeTime
if vmctx.BlockHeight() < challengeHeight {
// TODO: optimized bitfield methods
for _, v := range params.Faults.All() {
self.CurrentFaultSet.Set(v)
}
} else {
for _, v := range params.Faults.All() {
self.NextFaultSet.Set(v)
}
}
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
}
type MinerSlashConsensusFault struct {
Slasher address.Address
AtHeight uint64