Merge pull request #1390 from filecoin-project/fix/genesis-double-power-accounting

Don't double account for miner power when setting up genesis blocks
This commit is contained in:
Whyrusleeping 2020-03-10 18:56:47 -07:00 committed by GitHub
commit 65506376a4
8 changed files with 25 additions and 17 deletions

View File

@ -25,6 +25,3 @@ const SlashablePowerDelay = miner.ProvingPeriod * 3 // TODO: remove
// Epochs // Epochs
const InteractivePoRepConfidence = 6 const InteractivePoRepConfidence = 6
// Bytes
var MinimumMinerPower uint64 = 2 << 30 // 2 GiB

View File

@ -9,13 +9,14 @@ import (
_ "github.com/filecoin-project/lotus/lib/sigs/secp" _ "github.com/filecoin-project/lotus/lib/sigs/secp"
"github.com/filecoin-project/lotus/build" "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() { func init() {
build.SectorSizes = []abi.SectorSize{2048} build.SectorSizes = []abi.SectorSize{2048}
build.MinimumMinerPower = 2048 power.ConsensusMinerMinPower = big.NewInt(2048)
} }
func testGeneration(t testing.TB, n int, msgs int) { func testGeneration(t testing.TB, n int, msgs int) {

View File

@ -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) 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 { if len(miners) == 0 {
return cid.Undef, xerrors.New("no genesis miners") 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) 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) err := st.AddToClaim(&state.AdtStore{cst}, maddr, spower, pledge)
if err != nil { if err != nil {
return xerrors.Errorf("add to claim: %w", err) return xerrors.Errorf("add to claim: %w", err)
} }
fmt.Println("Added weight to claim: ", st.TotalNetworkPower)
return nil return nil
}) })
if err != 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 // Put sectors to miner sector sets
{ {
newSectorInfo := &miner.SectorOnChainInfo{ newSectorInfo := &miner.SectorOnChainInfo{

View File

@ -2,6 +2,7 @@ package genesis
import ( import (
"context" "context"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/abi/big"
@ -23,7 +24,7 @@ func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
} }
sms := &power.State{ 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, MinerCount: 0,
EscrowTable: emptyhamt, EscrowTable: emptyhamt,
CronEventQueue: emptyhamt, CronEventQueue: emptyhamt,

View File

@ -8,8 +8,10 @@ import (
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi" "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"
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" 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/runtime"
"github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/specs-actors/actors/util/adt"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -36,7 +38,7 @@ import (
func init() { func init() {
build.SectorSizes = []abi.SectorSize{2048} build.SectorSizes = []abi.SectorSize{2048}
build.MinimumMinerPower = 2048 power.ConsensusMinerMinPower = big.NewInt(2048)
} }
const testForkHeight = 40 const testForkHeight = 40

View File

@ -10,13 +10,15 @@ import (
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/node/repo"
"github.com/filecoin-project/specs-actors/actors/abi" "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" "github.com/filecoin-project/specs-actors/actors/crypto"
blockstore "github.com/ipfs/go-ipfs-blockstore" blockstore "github.com/ipfs/go-ipfs-blockstore"
) )
func init() { func init() {
build.SectorSizes = []abi.SectorSize{2048} build.SectorSizes = []abi.SectorSize{2048}
build.MinimumMinerPower = 2048 power.ConsensusMinerMinPower = big.NewInt(2048)
} }
func BenchmarkGetRandomness(b *testing.B) { func BenchmarkGetRandomness(b *testing.B) {

View File

@ -8,6 +8,8 @@ import (
"time" "time"
"github.com/filecoin-project/specs-actors/actors/abi" "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" logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
@ -29,7 +31,7 @@ func init() {
build.InsecurePoStValidation = true build.InsecurePoStValidation = true
os.Setenv("TRUST_PARAMS", "1") os.Setenv("TRUST_PARAMS", "1")
build.SectorSizes = []abi.SectorSize{2048} build.SectorSizes = []abi.SectorSize{2048}
build.MinimumMinerPower = 2048 power.ConsensusMinerMinPower = big.NewInt(2048)
} }
const source = 0 const source = 0

View File

@ -23,6 +23,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi/big" "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"
saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner" 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"
"github.com/filecoin-project/lotus/api/client" "github.com/filecoin-project/lotus/api/client"
@ -49,7 +50,7 @@ func init() {
_ = logging.SetLogLevel("*", "INFO") _ = logging.SetLogLevel("*", "INFO")
build.SectorSizes = []abi.SectorSize{2048} 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 { 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 {