From 0336b32fcd2b458203dc507960a037ea6bea88d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 15 Apr 2020 22:22:58 +0200 Subject: [PATCH] windowpost: Wire up challenge generation --- api/api_full.go | 1 + api/apistruct/struct.go | 5 ++ chain/stmgr/utils.go | 10 ++++ node/impl/full/state.go | 8 +++ storage/adapter_storage_miner.go | 9 ++++ storage/miner.go | 2 +- storage/wdpost_run.go | 88 ++++++++------------------------ 7 files changed, 54 insertions(+), 69 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index d81b0f97a..2a95c33a6 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -120,6 +120,7 @@ type FullNode interface { StateMinerSectors(context.Context, address.Address, *abi.BitField, types.TipSetKey) ([]*ChainSectorInfo, error) StateMinerPower(context.Context, address.Address, types.TipSetKey) (*MinerPower, error) StateMinerWorker(context.Context, address.Address, types.TipSetKey) (address.Address, error) + StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) (*miner.Deadlines, error) StateMinerPeerID(ctx context.Context, m address.Address, tsk types.TipSetKey) (peer.ID, error) StateMinerSectorSize(context.Context, address.Address, types.TipSetKey) (abi.SectorSize, error) StateMinerFaults(context.Context, address.Address, types.TipSetKey) ([]abi.SectorNumber, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index b70997505..92451abc7 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -118,6 +118,7 @@ type FullNodeStruct struct { StateMinerWorker func(context.Context, address.Address, types.TipSetKey) (address.Address, error) `perm:"read"` StateMinerPeerID func(ctx context.Context, m address.Address, tsk types.TipSetKey) (peer.ID, error) `perm:"read"` StateMinerSectorSize func(context.Context, address.Address, types.TipSetKey) (abi.SectorSize, error) `perm:"read"` + StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) (*miner.Deadlines, error) StateMinerFaults func(context.Context, address.Address, types.TipSetKey) ([]abi.SectorNumber, error) `perm:"read"` StateSectorPreCommitInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"` StateCall func(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) `perm:"read"` @@ -498,6 +499,10 @@ func (c *FullNodeStruct) StateMinerSectorSize(ctx context.Context, actor address return c.Internal.StateMinerSectorSize(ctx, actor, tsk) } +func (c *FullNodeStruct) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) (*miner.Deadlines, error) { + return c.Internal.StateMinerDeadlines(ctx, m, tsk) +} + func (c *FullNodeStruct) StateMinerFaults(ctx context.Context, actor address.Address, tsk types.TipSetKey) ([]abi.SectorNumber, error) { return c.Internal.StateMinerFaults(ctx, actor, tsk) } diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 9eb3976b5..4fcf5aa7d 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -208,6 +208,16 @@ func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, ma return false, nil } +func GetMinerDeadlines(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (*miner.Deadlines, error) { + var mas miner.State + _, err := sm.LoadActorState(ctx, maddr, &mas, ts) + if err != nil { + return nil, xerrors.Errorf("(get ssize) failed to load miner actor state: %w", err) + } + + return miner.LoadDeadlines(sm.cs.Store(ctx), &mas) +} + func GetMinerFaults(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) ([]abi.SectorNumber, error) { var mas miner.State _, err := sm.LoadActorState(ctx, maddr, &mas, ts) diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 77d979a42..2dad67f91 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -81,6 +81,14 @@ func (a *StateAPI) StateMinerSectorSize(ctx context.Context, actor address.Addre return stmgr.GetMinerSectorSize(ctx, a.StateManager, ts, actor) } +func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) (*miner.Deadlines, error) { + ts, err := a.Chain.GetTipSetFromKey(tsk) + if err != nil { + return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) + } + return stmgr.GetMinerDeadlines(ctx, a.StateManager, ts, m) +} + func (a *StateAPI) StateMinerFaults(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]abi.SectorNumber, error) { ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index 980526801..c256519de 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -52,6 +52,15 @@ func (s SealingAPIAdapter) StateMinerWorkerAddress(ctx context.Context, maddr ad return s.delegate.StateMinerWorker(ctx, maddr, tsk) } +func (s SealingAPIAdapter) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) (*miner.Deadlines, error) { + tsk, err := types.TipSetKeyFromBytes(tok) + if err != nil { + return nil, xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) + } + + return s.delegate.StateMinerDeadlines(ctx, maddr, tsk) +} + func (s SealingAPIAdapter) StateWaitMsg(ctx context.Context, mcid cid.Cid) (sealing.MsgLookup, error) { wmsg, err := s.delegate.StateWaitMsg(ctx, mcid) if err != nil { diff --git a/storage/miner.go b/storage/miner.go index 112ca53bc..a88c76ff5 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -50,7 +50,7 @@ type storageMinerApi interface { // Call a read only method on actors (no interaction with the chain required) StateCall(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) StateMinerWorker(context.Context, address.Address, types.TipSetKey) (address.Address, error) - StateMinerPostState(ctx context.Context, actor address.Address, ts types.TipSetKey) (*miner.PoStState, error) + StateMinerDeadlines(ctx context.Context, maddr address.Address, tok types.TipSetKey) (*miner.Deadlines, error) StateMinerSectors(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) StateMinerProvingSet(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) StateMinerSectorSize(context.Context, address.Address, types.TipSetKey) (abi.SectorSize, error) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 4aaecf33f..f2b628d2c 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -10,7 +10,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "go.opencensus.io/trace" "golang.org/x/xerrors" @@ -55,42 +54,6 @@ func (s *WindowPoStScheduler) doPost(ctx context.Context, deadline *Deadline, ts }() } -func (s *WindowPoStScheduler) declareFaults(ctx context.Context, fc uint64, params *miner.DeclareTemporaryFaultsParams) error { - log.Warnf("DECLARING %d FAULTS", fc) - - enc, aerr := actors.SerializeParams(params) - if aerr != nil { - return xerrors.Errorf("could not serialize declare faults parameters: %w", aerr) - } - - msg := &types.Message{ - To: s.actor, - From: s.worker, - Method: builtin.MethodsMiner.DeclareTemporaryFaults, - Params: enc, - Value: types.NewInt(0), - GasLimit: 10000000, // i dont know help - GasPrice: types.NewInt(1), - } - - sm, err := s.api.MpoolPushMessage(ctx, msg) - if err != nil { - return xerrors.Errorf("pushing faults message to mpool: %w", err) - } - - rec, err := s.api.StateWaitMsg(ctx, sm.Cid()) - if err != nil { - return xerrors.Errorf("waiting for declare faults: %w", err) - } - - if rec.Receipt.ExitCode != 0 { - return xerrors.Errorf("declare faults exit %d", rec.Receipt.ExitCode) - } - - log.Infof("Faults declared successfully") - return nil -} - func (s *WindowPoStScheduler) checkFaults(ctx context.Context, ssi []abi.SectorNumber) ([]abi.SectorNumber, error) { //faults := s.prover.Scrub(ssi) log.Warnf("Stub checkFaults") @@ -114,37 +77,13 @@ func (s *WindowPoStScheduler) checkFaults(ctx context.Context, ssi []abi.SectorN var faultIDs []abi.SectorNumber if len(faults) > 0 { - params := &miner.DeclareTemporaryFaultsParams{ - Duration: 900, // TODO: duration is annoying - SectorNumbers: abi.NewBitField(), - } - - for _, fault := range faults { - if _, ok := declaredFaults[(fault.SectorNum)]; ok { - continue - } - - log.Warnf("new fault detected: sector %d: %s", fault.SectorNum, fault.Err) - declaredFaults[fault.SectorNum] = struct{}{} - } - - faultIDs = make([]abi.SectorNumber, 0, len(declaredFaults)) - for fault := range declaredFaults { - faultIDs = append(faultIDs, fault) - params.SectorNumbers.Set(uint64(fault)) - } - - if len(faultIDs) > 0 { - if err := s.declareFaults(ctx, uint64(len(faultIDs)), params); err != nil { - return nil, err - } - } + panic("Aaaaaaaaaaaaaaaaaaaa") } return faultIDs, nil } -func (s *WindowPoStScheduler) runPost(ctx context.Context, deadline Deadline, ts *types.TipSet) (*abi.OnChainWindowPoStVerifyInfo, error) { +func (s *WindowPoStScheduler) runPost(ctx context.Context, deadline Deadline, ts *types.TipSet) (*abi.WindowPoStVerifyInfo, error) { ctx, span := trace.StartSpan(ctx, "storage.runPost") defer span.End() @@ -164,7 +103,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, deadline Deadline, ts return nil, err } - ssi, err := s.sortedSectorInfo(ctx, partitions, ts) + ssi, err := s.sortedSectorInfo(ctx, partitions, ts) // TODO: Optimization: Only get challenged sectors if err != nil { return nil, xerrors.Errorf("getting sorted sector info: %w", err) } @@ -199,8 +138,18 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, deadline Deadline, ts return nil, err } + ci, err := s.prover.GenerateWinningPoStSectorChallenge(ctx, s.proofType, abi.ActorID(mid), abi.PoStRandomness(rand), uint64(len(ssi))) + if err != nil { + return nil, xerrors.Errorf("generating window post challenge: %w", err) + } + + cssi := make([]abi.SectorInfo, len(ci)) + for i, u := range ci { + cssi[i] = ssi[u] + } + // TODO: Faults! - postOut, err := s.prover.GenerateWindowPoSt(ctx, abi.ActorID(mid), ssi, abi.PoStRandomness(rand)) + postOut, err := s.prover.GenerateWindowPoSt(ctx, abi.ActorID(mid), cssi, abi.PoStRandomness(rand)) if err != nil { return nil, xerrors.Errorf("running post failed: %w", err) } @@ -212,8 +161,11 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, deadline Deadline, ts elapsed := time.Since(tsStart) log.Infow("submitting PoSt", "elapsed", elapsed) - return &abi.OnChainWindowPoStVerifyInfo{ - Proofs: postOut, + return &abi.WindowPoStVerifyInfo{ + Randomness: abi.PoStRandomness(rand), + Proofs: postOut, + ChallengedSectors: cssi, + Prover: abi.ActorID(mid), }, nil } @@ -235,7 +187,7 @@ func (s *WindowPoStScheduler) sortedSectorInfo(ctx context.Context, partitions [ return sbsi, nil } -func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *abi.OnChainWindowPoStVerifyInfo) error { +func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *abi.WindowPoStVerifyInfo) error { ctx, span := trace.StartSpan(ctx, "storage.commitPost") defer span.End()