From 03cd3760bbb561922ec59a2583bda6ec16ee65c4 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 19 Jan 2021 18:06:00 -0800 Subject: [PATCH] correctly pick the seal type based on the network version Of course, we should really just run all of our tests post actors v2. --- chain/actors/builtin/miner/miner.go | 23 +++++++++++++++++++++-- extern/storage-sealing/sealing.go | 7 ++++++- markets/storageadapter/provider.go | 19 ++++++++++++------- node/impl/client/client.go | 7 ++++++- node/modules/storageminer.go | 15 +++++++++------ 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 279ca5e50..3364f6195 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -2,6 +2,7 @@ package miner import ( "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/network" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" @@ -149,8 +150,26 @@ type DeclareFaultsRecoveredParams = miner0.DeclareFaultsRecoveredParams type SubmitWindowedPoStParams = miner0.SubmitWindowedPoStParams type ProveCommitSectorParams = miner0.ProveCommitSectorParams -// TODO: This may need to be epoch-sensitive -func PreferredSealProofTypeFromWindowPoStType(proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) { +func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) { + // We added support for the new proofs in network version 7, and removed support for the old + // ones in network version 8. + if nver < network.Version7 { + switch proof { + case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: + return abi.RegisteredSealProof_StackedDrg2KiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1: + return abi.RegisteredSealProof_StackedDrg8MiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1: + return abi.RegisteredSealProof_StackedDrg512MiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1: + return abi.RegisteredSealProof_StackedDrg32GiBV1, nil + case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: + return abi.RegisteredSealProof_StackedDrg64GiBV1, nil + default: + return -1, xerrors.Errorf("unrecognized window post type: %d", proof) + } + } + switch proof { case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: return abi.RegisteredSealProof_StackedDrg2KiBV1_1, nil diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index 2219d9d2c..f46403742 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -475,7 +475,12 @@ func (m *Sealing) currentSealProof(ctx context.Context) (abi.RegisteredSealProof return 0, err } - return miner.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) + ver, err := m.api.StateNetworkVersion(ctx, nil) + if err != nil { + return 0, err + } + + return miner.PreferredSealProofTypeFromWindowPoStType(ver, mi.WindowPoStProofType) } func (m *Sealing) minerSector(spt abi.RegisteredSealProof, num abi.SectorNumber) storage.SectorRef { diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 6a06c46e3..90a659d34 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -7,8 +7,6 @@ import ( "io" "time" - miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "golang.org/x/xerrors" @@ -26,6 +24,7 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/events/state" "github.com/filecoin-project/lotus/chain/types" @@ -158,30 +157,36 @@ func (n *ProviderNodeAdapter) VerifySignature(ctx context.Context, sig crypto.Si return err == nil, err } -func (n *ProviderNodeAdapter) GetMinerWorkerAddress(ctx context.Context, miner address.Address, tok shared.TipSetToken) (address.Address, error) { +func (n *ProviderNodeAdapter) GetMinerWorkerAddress(ctx context.Context, maddr address.Address, tok shared.TipSetToken) (address.Address, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { return address.Undef, err } - mi, err := n.StateMinerInfo(ctx, miner, tsk) + mi, err := n.StateMinerInfo(ctx, maddr, tsk) if err != nil { return address.Address{}, err } return mi.Worker, nil } -func (n *ProviderNodeAdapter) GetProofType(ctx context.Context, miner address.Address, tok shared.TipSetToken) (abi.RegisteredSealProof, error) { +func (n *ProviderNodeAdapter) GetProofType(ctx context.Context, maddr address.Address, tok shared.TipSetToken) (abi.RegisteredSealProof, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { return 0, err } - mi, err := n.StateMinerInfo(ctx, miner, tsk) + mi, err := n.StateMinerInfo(ctx, maddr, tsk) if err != nil { return 0, err } - return miner2.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) + + nver, err := n.StateNetworkVersion(ctx, tsk) + if err != nil { + return 0, err + } + + return miner.PreferredSealProofTypeFromWindowPoStType(nver, mi.WindowPoStProofType) } func (n *ProviderNodeAdapter) SignBytes(ctx context.Context, signer address.Address, b []byte) (*crypto.Signature, error) { diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 3868e69ea..00c840b63 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -159,7 +159,12 @@ func (a *API) ClientStartDeal(ctx context.Context, params *api.StartDealParams) dealStart = ts.Height() + abi.ChainEpoch(dealStartBufferHours*blocksPerHour) // TODO: Get this from storage ask } - st, err := miner.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) + networkVersion, err := a.StateNetworkVersion(ctx, types.EmptyTSK) + if err != nil { + return nil, xerrors.Errorf("failed to get network version: %w", err) + } + + st, err := miner.PreferredSealProofTypeFromWindowPoStType(networkVersion, mi.WindowPoStProofType) if err != nil { return nil, xerrors.Errorf("failed to get seal proof type: %w", err) } diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 165e98e01..2a0b3f8b2 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -10,8 +10,6 @@ import ( "path/filepath" "time" - miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "go.uber.org/fx" "go.uber.org/multierr" "golang.org/x/xerrors" @@ -60,6 +58,7 @@ import ( lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/gen/slashfilter" "github.com/filecoin-project/lotus/chain/types" @@ -68,7 +67,7 @@ import ( "github.com/filecoin-project/lotus/markets" marketevents "github.com/filecoin-project/lotus/markets/loggers" "github.com/filecoin-project/lotus/markets/retrievaladapter" - "github.com/filecoin-project/lotus/miner" + lotusminer "github.com/filecoin-project/lotus/miner" "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/helpers" @@ -129,8 +128,12 @@ func SealProofType(maddr dtypes.MinerAddress, fnapi lapi.FullNode) (abi.Register if err != nil { return 0, err } + networkVersion, err := fnapi.StateNetworkVersion(context.TODO(), types.EmptyTSK) + if err != nil { + return 0, err + } - return miner2.PreferredSealProofTypeFromWindowPoStType(mi.WindowPoStProofType) + return miner.PreferredSealProofTypeFromWindowPoStType(networkVersion, mi.WindowPoStProofType) } type sidsc struct { @@ -421,13 +424,13 @@ func StagingGraphsync(mctx helpers.MetricsCtx, lc fx.Lifecycle, ibs dtypes.Stagi return gs } -func SetupBlockProducer(lc fx.Lifecycle, ds dtypes.MetadataDS, api lapi.FullNode, epp gen.WinningPoStProver, sf *slashfilter.SlashFilter, j journal.Journal) (*miner.Miner, error) { +func SetupBlockProducer(lc fx.Lifecycle, ds dtypes.MetadataDS, api lapi.FullNode, epp gen.WinningPoStProver, sf *slashfilter.SlashFilter, j journal.Journal) (*lotusminer.Miner, error) { minerAddr, err := minerAddrFromDS(ds) if err != nil { return nil, err } - m := miner.NewMiner(api, epp, minerAddr, sf, j) + m := lotusminer.NewMiner(api, epp, minerAddr, sf, j) lc.Append(fx.Hook{ OnStart: func(ctx context.Context) error {