Don't double account for miner power when setting up genesis blocks

This commit is contained in:
whyrusleeping 2020-03-10 15:42:41 -07:00
parent da52596d79
commit 14f9724bc9
8 changed files with 25 additions and 17 deletions

View File

@ -25,6 +25,3 @@ const SlashablePowerDelay = miner.ProvingPeriod * 3 // TODO: remove
// Epochs
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/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) {

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)
}
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{

View File

@ -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,

View File

@ -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

View File

@ -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) {

View File

@ -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

View File

@ -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 {