From 14f9724bc9155a8d88ff1bae167f951d2b285617 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 10 Mar 2020 15:42:41 -0700 Subject: [PATCH] Don't double account for miner power when setting up genesis blocks --- build/params_testnet.go | 3 --- chain/gen/gen_test.go | 7 ++++--- chain/gen/genesis/miners.go | 14 ++++++++------ chain/gen/genesis/t04_power.go | 3 ++- chain/stmgr/forks_test.go | 4 +++- chain/store/store_test.go | 4 +++- chain/sync_test.go | 4 +++- node/node_test.go | 3 ++- 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/build/params_testnet.go b/build/params_testnet.go index 24f64e93e..623ef4e2c 100644 --- a/build/params_testnet.go +++ b/build/params_testnet.go @@ -25,6 +25,3 @@ const SlashablePowerDelay = miner.ProvingPeriod * 3 // TODO: remove // Epochs const InteractivePoRepConfidence = 6 - -// Bytes -var MinimumMinerPower uint64 = 2 << 30 // 2 GiB diff --git a/chain/gen/gen_test.go b/chain/gen/gen_test.go index c271a0845..b61a59e10 100644 --- a/chain/gen/gen_test.go +++ b/chain/gen/gen_test.go @@ -9,13 +9,14 @@ import ( _ "github.com/filecoin-project/lotus/lib/sigs/secp" "github.com/filecoin-project/lotus/build" - _ "github.com/filecoin-project/lotus/lib/sigs/bls" - _ "github.com/filecoin-project/lotus/lib/sigs/secp" + + "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} - build.MinimumMinerPower = 2048 + power.ConsensusMinerMinPower = big.NewInt(2048) } func testGeneration(t testing.TB, n int, msgs int) { diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 0fb2f5741..025e3840d 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -46,11 +46,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err) } - err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power.State) error { - st.TotalNetworkPower = networkPower - return nil - }) - if len(miners) == 0 { return cid.Undef, xerrors.New("no genesis miners") } @@ -185,11 +180,12 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } spower := power.ConsensusPowerForWeight(weight) - pledge = power.PledgeForWeight(weight, big.Sub(st.TotalNetworkPower, spower)) + pledge = power.PledgeForWeight(weight, st.TotalNetworkPower) err := st.AddToClaim(&state.AdtStore{cst}, maddr, spower, pledge) if err != nil { return xerrors.Errorf("add to claim: %w", err) } + fmt.Println("Added weight to claim: ", st.TotalNetworkPower) return nil }) if err != nil { @@ -197,6 +193,12 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } } + // TODO: to avoid division by zero, we set the initial power actor power to 1, this adjusts that back down so the accounting is accurate. + err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power.State) error { + st.TotalNetworkPower = big.Sub(st.TotalNetworkPower, big.NewInt(1)) + return nil + }) + // Put sectors to miner sector sets { newSectorInfo := &miner.SectorOnChainInfo{ diff --git a/chain/gen/genesis/t04_power.go b/chain/gen/genesis/t04_power.go index 49bc5aa4d..d0204a609 100644 --- a/chain/gen/genesis/t04_power.go +++ b/chain/gen/genesis/t04_power.go @@ -2,6 +2,7 @@ package genesis import ( "context" + "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/abi/big" @@ -23,7 +24,7 @@ func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) { } sms := &power.State{ - TotalNetworkPower: big.NewInt(1), + TotalNetworkPower: big.NewInt(1), // TODO: has to be 1 initially to avoid div by zero. Kinda annoying, should find a way to fix MinerCount: 0, EscrowTable: emptyhamt, CronEventQueue: emptyhamt, diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index a61752616..f70bd106b 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -8,8 +8,10 @@ import ( "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" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" + "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" @@ -36,7 +38,7 @@ import ( func init() { build.SectorSizes = []abi.SectorSize{2048} - build.MinimumMinerPower = 2048 + power.ConsensusMinerMinPower = big.NewInt(2048) } const testForkHeight = 40 diff --git a/chain/store/store_test.go b/chain/store/store_test.go index ebbd3f440..70513fed9 100644 --- a/chain/store/store_test.go +++ b/chain/store/store_test.go @@ -10,13 +10,15 @@ import ( "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" blockstore "github.com/ipfs/go-ipfs-blockstore" ) func init() { build.SectorSizes = []abi.SectorSize{2048} - build.MinimumMinerPower = 2048 + power.ConsensusMinerMinPower = big.NewInt(2048) } func BenchmarkGetRandomness(b *testing.B) { diff --git a/chain/sync_test.go b/chain/sync_test.go index 3a0122cf6..70c3232e2 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -8,6 +8,8 @@ import ( "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" @@ -29,7 +31,7 @@ func init() { build.InsecurePoStValidation = true os.Setenv("TRUST_PARAMS", "1") build.SectorSizes = []abi.SectorSize{2048} - build.MinimumMinerPower = 2048 + power.ConsensusMinerMinPower = big.NewInt(2048) } const source = 0 diff --git a/node/node_test.go b/node/node_test.go index 901f3f4fd..c915c9328 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -23,6 +23,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin" saminer "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/api/client" @@ -49,7 +50,7 @@ func init() { _ = logging.SetLogLevel("*", "INFO") build.SectorSizes = []abi.SectorSize{2048} - build.MinimumMinerPower = 2048 + power.ConsensusMinerMinPower = big.NewInt(2048) } func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, act address.Address, pk crypto.PrivKey, tnd test.TestNode, mn mocknet.Mocknet, opts node.Option) test.TestStorageNode {