actors: IsMiner -> IsValidMiner

This commit is contained in:
Łukasz Magiera 2019-11-14 00:00:11 +01:00
parent e094ace303
commit 05f157554f
4 changed files with 42 additions and 15 deletions

View File

@ -125,12 +125,13 @@ type maMethods struct {
GetSectorSize uint64
UpdatePeerID uint64
ChangeWorker uint64
IsLate uint64
CheckMiner uint64
DeclareFaults uint64
SlashConsensusFault uint64
}
var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}
func (sma StorageMinerActor) Exports() []interface{} {
return []interface{}{
@ -149,9 +150,10 @@ func (sma StorageMinerActor) Exports() []interface{} {
13: sma.GetSectorSize,
14: sma.UpdatePeerID,
//15: sma.ChangeWorker,
16: sma.CheckMiner,
17: sma.DeclareFaults,
18: sma.SlashConsensusFault,
16: sma.IsLate,
17: sma.CheckMiner,
18: sma.DeclareFaults,
19: sma.SlashConsensusFault,
}
}
@ -736,6 +738,19 @@ func (sma StorageMinerActor) GetSectorSize(act *types.Actor, vmctx types.VMConte
return types.NewInt(mi.SectorSize).Bytes(), nil
}
func isLate(height uint64, self *StorageMinerActorState) bool {
return height >= self.ProvingPeriodEnd // TODO: review: maybe > ?
}
func (sma StorageMinerActor) IsLate(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
_, self, err := loadState(vmctx)
if err != nil {
return nil, err
}
return cbg.EncodeBool(isLate(vmctx.BlockHeight(), self)), nil
}
// TODO: better name
func (sma StorageMinerActor) CheckMiner(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
if vmctx.Message().From != StoragePowerAddress {
@ -747,7 +762,7 @@ func (sma StorageMinerActor) CheckMiner(act *types.Actor, vmctx types.VMContext,
return nil, err
}
if vmctx.BlockHeight() < self.ProvingPeriodEnd {
if !isLate(vmctx.BlockHeight(), self) {
// Everything's fine
return cbg.EncodeBool(true), nil
}

View File

@ -1,6 +1,7 @@
package actors
import (
"bytes"
"context"
"github.com/filecoin-project/go-amt-ipld"
@ -25,7 +26,7 @@ type spaMethods struct {
UpdateStorage uint64
GetTotalStorage uint64
PowerLookup uint64
IsMiner uint64
IsValidMiner uint64
PledgeCollateralForSize uint64
CheckProofSubmissions uint64
}
@ -40,7 +41,7 @@ func (spa StoragePowerActor) Exports() []interface{} {
4: spa.UpdateStorage,
5: spa.GetTotalStorage,
6: spa.PowerLookup,
7: spa.IsMiner,
7: spa.IsValidMiner,
8: spa.PledgeCollateralForSize,
9: spa.CheckProofSubmissions,
}
@ -442,7 +443,7 @@ type IsMinerParam struct {
Addr address.Address
}
func (spa StoragePowerActor) IsMiner(act *types.Actor, vmctx types.VMContext, param *IsMinerParam) ([]byte, ActorError) {
func (spa StoragePowerActor) IsValidMiner(act *types.Actor, vmctx types.VMContext, param *IsMinerParam) ([]byte, ActorError) {
var self StoragePowerState
if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil {
return nil, err
@ -453,7 +454,18 @@ func (spa StoragePowerActor) IsMiner(act *types.Actor, vmctx types.VMContext, pa
return nil, err
}
return cbg.EncodeBool(has), nil
if !has {
return cbg.CborBoolFalse, nil
}
ret, err := vmctx.Send(param.Addr, MAMethods.IsLate, types.NewInt(0), nil)
if err != nil {
return nil, err
}
late := bytes.Equal(ret, cbg.CborBoolTrue)
return cbg.EncodeBool(!late), nil
}
type PledgeCollateralParams struct {
@ -565,7 +577,7 @@ func (spa StoragePowerActor) CheckProofSubmissions(act *types.Actor, vmctx types
return aerrors.Escalate(err, "parsing miner address")
}
ret, err := vmctx.Send(maddr, MAMethods.CheckMiner, vmctx.Message().Value, nil)
ret, err := vmctx.Send(maddr, MAMethods.CheckMiner, types.NewInt(0), nil)
if err != nil {
return err
}

View File

@ -52,7 +52,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) {
}
{
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.IsMiner,
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.IsValidMiner,
&IsMinerParam{Addr: minerAddr})
ApplyOK(t, ret)
@ -63,7 +63,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) {
}
if !output {
t.Fatalf("%s is miner but IsMiner call returned false", minerAddr)
t.Fatalf("%s is miner but IsValidMiner call returned false", minerAddr)
}
}
@ -108,7 +108,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) {
}
{
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.IsMiner, &IsMinerParam{minerAddr})
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.IsValidMiner, &IsMinerParam{minerAddr})
ApplyOK(t, ret)
assert.Equal(t, ret.Return, cbg.CborBoolFalse)
}

View File

@ -426,7 +426,7 @@ func (syncer *Syncer) minerIsValid(ctx context.Context, maddr address.Address, b
ret, err := syncer.sm.Call(ctx, &types.Message{
To: actors.StoragePowerAddress,
From: maddr,
Method: actors.SPAMethods.IsMiner,
Method: actors.SPAMethods.IsValidMiner,
Params: enc,
}, baseTs)
if err != nil {
@ -434,7 +434,7 @@ func (syncer *Syncer) minerIsValid(ctx context.Context, maddr address.Address, b
}
if ret.ExitCode != 0 {
return xerrors.Errorf("StorageMarket.IsMiner check failed (exit code %d)", ret.ExitCode)
return xerrors.Errorf("StorageMarket.IsValidMiner check failed (exit code %d)", ret.ExitCode)
}
// TODO: ensure the miner is currently not late on their PoSt submission (this hasnt landed in the spec yet)