From ba389598ee6f58145dc11cc86be9cd2dc4a2cccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 12 May 2020 19:58:12 +0200 Subject: [PATCH] Cleanup build package --- build/params_2k.go | 6 ++++-- build/params_shared.go | 35 +++++++++++++++++++++++---------- build/params_testnet.go | 15 +++++++------- chain/events/tscache.go | 2 +- chain/gen/gen_test.go | 12 +++++------ chain/stmgr/forks_test.go | 6 ++++-- chain/store/store_test.go | 21 +++++++++++--------- chain/sync.go | 4 ++-- chain/sync_test.go | 12 +++++++---- cmd/lotus-bench/main.go | 7 ++++--- cmd/lotus-storage-miner/init.go | 2 +- lotuspond/spawn.go | 16 ++++++++------- node/node_test.go | 3 +-- 13 files changed, 85 insertions(+), 56 deletions(-) diff --git a/build/params_2k.go b/build/params_2k.go index 50f6f1bc2..f9ce1cca2 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -5,15 +5,17 @@ package build import ( "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/power" ) func init() { power.ConsensusMinerMinPower = big.NewInt(2048) + miner.SupportedProofTypes = map[abi.RegisteredProof]struct{}{ + abi.RegisteredProof_StackedDRG2KiBSeal: {}, + } } -var SectorSizes = []abi.SectorSize{2048} - // Seconds const BlockDelay = 2 diff --git a/build/params_shared.go b/build/params_shared.go index 47b608850..53b3e4478 100644 --- a/build/params_shared.go +++ b/build/params_shared.go @@ -2,12 +2,35 @@ package build import ( "math/big" + "sort" "github.com/libp2p/go-libp2p-core/protocol" + "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" + "github.com/filecoin-project/lotus/node/modules/dtypes" ) +func DefaultSectorSize() abi.SectorSize { + szs := make([]abi.SectorSize, len(miner.SupportedProofTypes)) + for spt := range miner.SupportedProofTypes { + ss, err := spt.SectorSize() + if err != nil { + panic(err) + } + + szs = append(szs, ss) + } + + sort.Slice(szs, func(i, j int) bool { + return szs[i] < szs[i] + }) + + return szs[0] +} + // Core network constants func BlocksTopic(netName dtypes.NetworkName) string { return "/fil/blocks/" + string(netName) } @@ -22,14 +45,6 @@ func DhtProtocolName(netName dtypes.NetworkName) protocol.ID { const UnixfsChunkSize uint64 = 1 << 20 const UnixfsLinksPerLevel = 1024 -const SectorChallengeRatioDiv = 25 - -// ///// -// Payments - -// Epochs -const PaymentChannelClosingDelay = 6 * 60 * 60 / BlockDelay // six hours - // ///// // Consensus / Network @@ -40,10 +55,10 @@ const AllowableClockDrift = 1 const ForkLengthThreshold = Finality // Blocks (e) -const BlocksPerEpoch = 5 +var BlocksPerEpoch = uint64(builtin.ExpectedLeadersPerEpoch) // Epochs -const Finality = 500 +const Finality = miner.ChainFinalityish // constants for Weight calculation // The ratio of weight contributed by short-term vs long-term factors in a given round diff --git a/build/params_testnet.go b/build/params_testnet.go index 29f29ca98..093564e6b 100644 --- a/build/params_testnet.go +++ b/build/params_testnet.go @@ -6,20 +6,21 @@ package build import ( "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/power" ) func init() { power.ConsensusMinerMinPower = big.NewInt(2 << 30) -} - -var SectorSizes = []abi.SectorSize{ // TODO: This isn't really used anywhere - 512 << 20, - 32 << 30, - 64 << 30, + miner.SupportedProofTypes = map[abi.RegisteredProof]struct{}{ + abi.RegisteredProof_StackedDRG512MiBSeal: {}, + abi.RegisteredProof_StackedDRG32GiBSeal: {}, + abi.RegisteredProof_StackedDRG64GiBSeal: {}, + } } // Seconds -const BlockDelay = 25 +const BlockDelay = builtin.EpochDurationSeconds const PropagationDelay = 6 diff --git a/chain/events/tscache.go b/chain/events/tscache.go index 7fc0e8f57..3852c9930 100644 --- a/chain/events/tscache.go +++ b/chain/events/tscache.go @@ -21,7 +21,7 @@ type tipSetCache struct { storage tsByHFunc } -func newTSCache(cap int, storage tsByHFunc) *tipSetCache { +func newTSCache(cap abi.ChainEpoch, storage tsByHFunc) *tipSetCache { return &tipSetCache{ cache: make([]*types.TipSet, cap), start: 0, diff --git a/chain/gen/gen_test.go b/chain/gen/gen_test.go index 22381fa88..4deafbe68 100644 --- a/chain/gen/gen_test.go +++ b/chain/gen/gen_test.go @@ -4,18 +4,18 @@ import ( "testing" "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/actors/builtin/power" _ "github.com/filecoin-project/lotus/lib/sigs/bls" _ "github.com/filecoin-project/lotus/lib/sigs/secp" - - "github.com/filecoin-project/lotus/build" - - "github.com/filecoin-project/specs-actors/actors/abi/big" - "github.com/filecoin-project/specs-actors/actors/builtin/power" ) func init() { - build.SectorSizes = []abi.SectorSize{2048} + miner.SupportedProofTypes = map[abi.RegisteredProof]struct{}{ + abi.RegisteredProof_StackedDRG2KiBSeal: {}, + } power.ConsensusMinerMinPower = big.NewInt(2048) } diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index 585967869..72be579b5 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -11,12 +11,12 @@ import ( "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/specs-actors/actors/util/adt" "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/gen" @@ -36,7 +36,9 @@ import ( ) func init() { - build.SectorSizes = []abi.SectorSize{2048} + miner.SupportedProofTypes = map[abi.RegisteredProof]struct{}{ + abi.RegisteredProof_StackedDRG2KiBSeal: {}, + } power.ConsensusMinerMinPower = big.NewInt(2048) } diff --git a/chain/store/store_test.go b/chain/store/store_test.go index d182b08f2..1c8b05742 100644 --- a/chain/store/store_test.go +++ b/chain/store/store_test.go @@ -5,22 +5,25 @@ import ( "context" "testing" - "github.com/filecoin-project/lotus/build" + datastore "github.com/ipfs/go-datastore" + blockstore "github.com/ipfs/go-ipfs-blockstore" + + "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/actors/builtin/power" + "github.com/filecoin-project/specs-actors/actors/crypto" + "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/repo" - "github.com/filecoin-project/specs-actors/actors/abi" - "github.com/filecoin-project/specs-actors/actors/abi/big" - "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/crypto" - - datastore "github.com/ipfs/go-datastore" - blockstore "github.com/ipfs/go-ipfs-blockstore" ) func init() { - build.SectorSizes = []abi.SectorSize{2048} + miner.SupportedProofTypes = map[abi.RegisteredProof]struct{}{ + abi.RegisteredProof_StackedDRG2KiBSeal: {}, + } power.ConsensusMinerMinPower = big.NewInt(2048) } diff --git a/chain/sync.go b/chain/sync.go index 8aee6b167..578893e4b 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -1162,7 +1162,7 @@ loop: var ErrForkTooLong = fmt.Errorf("fork longer than threshold") func (syncer *Syncer) syncFork(ctx context.Context, from *types.TipSet, to *types.TipSet) ([]*types.TipSet, error) { - tips, err := syncer.Bsync.GetBlocks(ctx, from.Parents(), build.ForkLengthThreshold) + tips, err := syncer.Bsync.GetBlocks(ctx, from.Parents(), int(build.ForkLengthThreshold)) if err != nil { return nil, err } @@ -1333,7 +1333,7 @@ func (syncer *Syncer) collectChain(ctx context.Context, ts *types.TipSet) error ss.SetStage(api.StagePersistHeaders) - toPersist := make([]*types.BlockHeader, 0, len(headers)*build.BlocksPerEpoch) + toPersist := make([]*types.BlockHeader, 0, len(headers)*int(build.BlocksPerEpoch)) for _, ts := range headers { toPersist = append(toPersist, ts.Blocks()...) } diff --git a/chain/sync_test.go b/chain/sync_test.go index 80310a85f..b6847b0f2 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -7,15 +7,17 @@ import ( "testing" "time" - "github.com/filecoin-project/specs-actors/actors/abi" - "github.com/filecoin-project/specs-actors/actors/abi/big" - "github.com/filecoin-project/specs-actors/actors/builtin/power" logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p-core/peer" mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/actors/builtin/power" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/gen" @@ -31,7 +33,9 @@ import ( func init() { build.InsecurePoStValidation = true os.Setenv("TRUST_PARAMS", "1") - build.SectorSizes = []abi.SectorSize{2048} + miner.SupportedProofTypes = map[abi.RegisteredProof]struct{}{ + abi.RegisteredProof_StackedDRG2KiBSeal: {}, + } power.ConsensusMinerMinPower = big.NewInt(2048) } diff --git a/cmd/lotus-bench/main.go b/cmd/lotus-bench/main.go index 217e5f423..704fad010 100644 --- a/cmd/lotus-bench/main.go +++ b/cmd/lotus-bench/main.go @@ -20,16 +20,17 @@ import ( "github.com/filecoin-project/go-address" paramfetch "github.com/filecoin-project/go-paramfetch" + "github.com/filecoin-project/sector-storage/ffiwrapper" + "github.com/filecoin-project/sector-storage/ffiwrapper/basicfs" "github.com/filecoin-project/sector-storage/stores" "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-storage/storage" lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/genesis" - "github.com/filecoin-project/sector-storage/ffiwrapper" - "github.com/filecoin-project/sector-storage/ffiwrapper/basicfs" ) var log = logging.Logger("lotus-bench") @@ -72,7 +73,7 @@ func main() { log.Info("Starting lotus-bench") - build.SectorSizes = append(build.SectorSizes, 2048) + miner.SupportedProofTypes[abi.RegisteredProof_StackedDRG2KiBSeal] = struct{}{} app := &cli.App{ Name: "lotus-bench", diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 0a9fba221..c9c4e1730 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -79,7 +79,7 @@ var initCmd = &cli.Command{ &cli.StringFlag{ Name: "sector-size", Usage: "specify sector size to use", - Value: fmt.Sprint(build.SectorSizes[0]), + Value: fmt.Sprint(build.DefaultSectorSize()), }, &cli.StringSliceFlag{ Name: "pre-sealed-sectors", diff --git a/lotuspond/spawn.go b/lotuspond/spawn.go index c13a14065..4d8b8b9fd 100644 --- a/lotuspond/spawn.go +++ b/lotuspond/spawn.go @@ -11,20 +11,22 @@ import ( "sync/atomic" "time" - genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis" - "github.com/filecoin-project/lotus/genesis" - "github.com/filecoin-project/specs-actors/actors/abi/big" - - "github.com/filecoin-project/specs-actors/actors/abi" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/lotus/build" + genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis" + "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/lotus/cmd/lotus-seed/seed" + "github.com/filecoin-project/lotus/genesis" ) func init() { - build.SectorSizes = []abi.SectorSize{2048} + miner.SupportedProofTypes = map[abi.RegisteredProof]struct{}{ + abi.RegisteredProof_StackedDRG2KiBSeal: {}, + } } func (api *api) Spawn() (nodeInfo, error) { diff --git a/node/node_test.go b/node/node_test.go index 213f69fa2..4132d02dc 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -51,7 +51,6 @@ import ( func init() { _ = logging.SetLogLevel("*", "INFO") - build.SectorSizes = []abi.SectorSize{2048} power.ConsensusMinerMinPower = big.NewInt(2048) saminer.SupportedProofTypes = map[abi.RegisteredProof]struct{}{ abi.RegisteredProof_StackedDRG2KiBSeal: {}, @@ -394,7 +393,7 @@ func mockSbBuilder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test storers[i] = testStorageNode(ctx, t, genms[i].Worker, maddrs[i], pidKeys[i], f, mn, node.Options( node.Override(new(sectorstorage.SectorManager), func() (sectorstorage.SectorManager, error) { - return mock.NewMockSectorMgr(build.SectorSizes[0]), nil + return mock.NewMockSectorMgr(build.DefaultSectorSize()), nil }), node.Override(new(ffiwrapper.Verifier), mock.MockVerifier), node.Unset(new(*sectorstorage.Manager)),