storage: Move window-post logic into a separate package

This commit is contained in:
Łukasz Magiera
2022-06-14 19:27:09 +02:00
parent 12c91bb41d
commit dff1bf2868
11 changed files with 62 additions and 24 deletions
@@ -1,4 +1,4 @@
package storage
package wdpost
import (
"context"
@@ -1,5 +1,5 @@
//stm: #unit
package storage
package wdpost
import (
"context"
@@ -117,7 +117,7 @@ func (m *mockAPI) startGeneratePoST(
completeGeneratePoST CompleteGeneratePoSTCb,
) context.CancelFunc {
ctx, cancel := context.WithCancel(ctx)
log.Errorf("mock posting\n")
storage.log.Errorf("mock posting\n")
m.statesLk.Lock()
defer m.statesLk.Unlock()
m.postStates[deadline.Open] = postStatusProving
@@ -1,4 +1,4 @@
package storage
package wdpost
import (
"github.com/ipfs/go-cid"
@@ -1,5 +1,5 @@
//stm: #unit
package storage
package wdpost
import (
"testing"
@@ -1,4 +1,4 @@
package storage
package wdpost
import (
"bytes"
@@ -1,5 +1,5 @@
//stm: #unit
package storage
package wdpost
import (
"bytes"
@@ -32,12 +32,13 @@ import (
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
"github.com/filecoin-project/lotus/journal"
storage2 "github.com/filecoin-project/lotus/storage"
)
type mockStorageMinerAPI struct {
partitions []api.Partition
pushedMessages chan *types.Message
fullNodeFilteredAPI
storage2.fullNodeFilteredAPI
}
func newMockStorageMinerAPI() *mockStorageMinerAPI {
@@ -236,7 +237,7 @@ func TestWDPostDoPost(t *testing.T) {
proofType: proofType,
actor: postAct,
journal: journal.NilJournal(),
addrSel: &AddressSelector{},
addrSel: &storage2.AddressSelector{},
}
di := &dline.Info{
@@ -419,4 +420,4 @@ func (m *mockStorageMinerAPI) WalletHas(ctx context.Context, address address.Add
return true, nil
}
var _ fullNodeFilteredAPI = &mockStorageMinerAPI{}
var _ storage2.fullNodeFilteredAPI = &mockStorageMinerAPI{}
@@ -1,15 +1,21 @@
package storage
package wdpost
import (
"context"
"time"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
"go.opencensus.io/trace"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v8/miner"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/dline"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/specs-storage/storage"
"github.com/filecoin-project/lotus/api"
@@ -20,8 +26,36 @@ import (
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
"github.com/filecoin-project/lotus/journal"
"github.com/filecoin-project/lotus/node/config"
storage2 "github.com/filecoin-project/lotus/storage"
)
var log = logging.Logger("wdpost")
type NodeAPI interface {
ChainHead(context.Context) (*types.TipSet, error)
ChainNotify(context.Context) (<-chan []*api.HeadChange, error)
StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error)
StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error)
StateMinerSectors(context.Context, address.Address, *bitfield.BitField, types.TipSetKey) ([]*miner.SectorOnChainInfo, error)
StateNetworkVersion(context.Context, types.TipSetKey) (network.Version, error)
StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error)
StateGetRandomnessFromBeacon(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error)
StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error)
StateMinerPartitions(context.Context, address.Address, uint64, types.TipSetKey) ([]api.Partition, error)
StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error)
StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error)
MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error)
GasEstimateMessageGas(context.Context, *types.Message, *api.MessageSendSpec, types.TipSetKey) (*types.Message, error)
GasEstimateFeeCap(context.Context, *types.Message, int64, types.TipSetKey) (types.BigInt, error)
GasEstimateGasPremium(_ context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error)
WalletBalance(context.Context, address.Address) (types.BigInt, error)
WalletHas(context.Context, address.Address) (bool, error)
}
// WindowPoStScheduler is the coordinator for WindowPoSt submissions, fault
// declaration, and recovery declarations. It watches the chain for reverts and
// applies, and schedules/run those processes as partition deadlines arrive.
@@ -29,9 +63,9 @@ import (
// WindowPoStScheduler watches the chain though the changeHandler, which in turn
// turn calls the scheduler when the time arrives to do work.
type WindowPoStScheduler struct {
api fullNodeFilteredAPI
api NodeAPI
feeCfg config.MinerFeeConfig
addrSel *AddressSelector
addrSel *storage2.AddressSelector
prover storage.Prover
verifier ffiwrapper.Verifier
faultTracker sectorstorage.FaultTracker
@@ -49,9 +83,9 @@ type WindowPoStScheduler struct {
}
// NewWindowedPoStScheduler creates a new WindowPoStScheduler scheduler.
func NewWindowedPoStScheduler(api fullNodeFilteredAPI,
func NewWindowedPoStScheduler(api NodeAPI,
cfg config.MinerFeeConfig,
as *AddressSelector,
as *storage2.AddressSelector,
sp storage.Prover,
verif ffiwrapper.Verifier,
ft sectorstorage.FaultTracker,
@@ -88,7 +122,7 @@ func (s *WindowPoStScheduler) Run(ctx context.Context) {
// callbacks is a union of the fullNodeFilteredAPI and ourselves.
callbacks := struct {
fullNodeFilteredAPI
NodeAPI
*WindowPoStScheduler
}{s.api, s}