fixup genesis creation

This commit is contained in:
Aayush 2022-09-08 16:31:12 -04:00
parent e9a3235291
commit 30f66578e1
4 changed files with 67 additions and 47 deletions

View File

@ -6,6 +6,12 @@ import (
"fmt"
"math/rand"
smoothing9 "github.com/filecoin-project/go-state-types/builtin/v9/util/smoothing"
miner9 "github.com/filecoin-project/go-state-types/builtin/v9/miner"
market9 "github.com/filecoin-project/go-state-types/builtin/v9/market"
"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
cbg "github.com/whyrusleeping/cbor-gen"
@ -26,7 +32,6 @@ import (
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
power0 "github.com/filecoin-project/specs-actors/actors/builtin/power"
reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward"
smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing"
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
reward2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/reward"
market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market"
@ -120,10 +125,12 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
presealExp abi.ChainEpoch
dealIDs []abi.DealID
dealIDs []abi.DealID
sectorWeight []abi.StoragePower
}, len(miners))
maxPeriods := policy.GetMaxSectorExpirationExtension() / minertypes.WPoStProvingPeriod
rawPow, qaPow := big.NewInt(0), big.NewInt(0)
for i, m := range miners {
// Create miner through power actor
i := i
@ -197,7 +204,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
}
}
// Publish preseal deals
// Publish preseal deals, and calculate the QAPower
{
publish := func(params *markettypes.PublishStorageDealsParams) error {
@ -227,6 +234,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
params := &markettypes.PublishStorageDealsParams{}
for _, preseal := range m.Sectors {
fmt.Println("presealing ", preseal.SectorID)
preseal.Deal.VerifiedDeal = true
preseal.Deal.EndEpoch = minerInfos[i].presealExp
p := markettypes.ClientDealProposal{
@ -257,6 +265,11 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
params = &markettypes.PublishStorageDealsParams{}
}
rawPow = big.Add(rawPow, big.NewInt(int64(m.SectorSize)))
sectorWeight := builtin.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, big.Zero(), big.NewInt(int64(preseal.Deal.PieceSize)))
minerInfos[i].sectorWeight = append(minerInfos[i].sectorWeight, sectorWeight)
qaPow = big.Add(qaPow, sectorWeight)
}
if len(params.Deals) > 0 {
@ -267,24 +280,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
}
}
// adjust total network power for equal pledge per sector
rawPow, qaPow := big.NewInt(0), big.NewInt(0)
{
for i, m := range miners {
for pi := range m.Sectors {
rawPow = types.BigAdd(rawPow, types.NewInt(uint64(m.SectorSize)))
dweight, vdweight, err := dealWeight(ctx, genesisVm, minerInfos[i].maddr, []abi.DealID{minerInfos[i].dealIDs[pi]}, 0, minerInfos[i].presealExp, av)
if err != nil {
return cid.Undef, xerrors.Errorf("getting deal weight: %w", err)
}
sectorWeight := builtin.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight, vdweight)
qaPow = types.BigAdd(qaPow, sectorWeight)
}
}
nh, err := genesisVm.Flush(ctx)
if err != nil {
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
@ -369,12 +364,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
Expiration: minerInfos[i].presealExp, // TODO: Allow setting externally!
}
dweight, vdweight, err := dealWeight(ctx, genesisVm, minerInfos[i].maddr, params.DealIDs, 0, minerInfos[i].presealExp, av)
if err != nil {
return cid.Undef, xerrors.Errorf("getting deal weight: %w", err)
}
sectorWeight := builtin.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight, vdweight)
sectorWeight := minerInfos[i].sectorWeight[pi]
// we've added fake power for this sector above, remove it now
@ -442,14 +432,13 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
return cid.Undef, xerrors.Errorf("getting current total power: %w", err)
}
pcd := miner0.PreCommitDepositForPower((*smoothing0.FilterEstimate)(&rewardSmoothed), tpow.QualityAdjPowerSmoothed, sectorWeight)
pcd := miner9.PreCommitDepositForPower(smoothing9.FilterEstimate(rewardSmoothed), smoothing9.FilterEstimate(*tpow.QualityAdjPowerSmoothed), miner9.QAPowerMax(m.SectorSize))
pledge := miner0.InitialPledgeForPower(
pledge := miner9.InitialPledgeForPower(
sectorWeight,
baselinePower,
tpow.PledgeCollateral,
(*smoothing0.FilterEstimate)(&rewardSmoothed),
tpow.QualityAdjPowerSmoothed,
smoothing9.FilterEstimate(rewardSmoothed),
smoothing9.FilterEstimate(*tpow.QualityAdjPowerSmoothed),
big.Zero(),
)
@ -617,7 +606,7 @@ func currentTotalPower(ctx context.Context, vm vm.Interface, maddr address.Addre
return &pwr, nil
}
func dealWeight(ctx context.Context, vm vm.Interface, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actorstypes.Version) (abi.DealWeight, abi.DealWeight, error) {
func dealWeight(ctx context.Context, vm vm.Interface, maddr address.Address, spt abi.RegisteredSealProof, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actorstypes.Version) (abi.DealWeight, abi.DealWeight, error) {
// TODO: This hack should move to market actor wrapper
if av <= actorstypes.Version2 {
params := &market0.VerifyDealsForActivationParams{
@ -654,27 +643,54 @@ func dealWeight(ctx context.Context, vm vm.Interface, maddr address.Address, dea
return weight, verifiedWeight, nil
}
params := &market4.VerifyDealsForActivationParams{Sectors: []market4.SectorDeals{{
SectorExpiry: sectorExpiry,
DealIDs: dealIDs,
}}}
var dealWeights market4.VerifyDealsForActivationReturn
if av < actorstypes.Version9 {
params := &market4.VerifyDealsForActivationParams{Sectors: []market4.SectorDeals{{
SectorExpiry: sectorExpiry,
DealIDs: dealIDs,
}}}
paramEnc := mustEnc(params)
var dealWeights market4.VerifyDealsForActivationReturn
ret, err := doExecValue(ctx, vm,
market.Address,
maddr,
abi.NewTokenAmount(0),
market.Methods.VerifyDealsForActivation,
paramEnc,
)
if err != nil {
return big.Zero(), big.Zero(), err
}
if err := dealWeights.UnmarshalCBOR(bytes.NewReader(ret)); err != nil {
return big.Zero(), big.Zero(), err
}
return dealWeights.Sectors[0].DealWeight, dealWeights.Sectors[0].VerifiedDealWeight, nil
}
params := &market9.ActivateDealsParams{
DealIDs: dealIDs,
SectorExpiry: sectorExpiry}
paramEnc := mustEnc(params)
var dealWeights market9.ActivateDealsResult
ret, err := doExecValue(ctx, vm,
market.Address,
maddr,
abi.NewTokenAmount(0),
market.Methods.VerifyDealsForActivation,
mustEnc(params),
market.Methods.ActivateDeals,
paramEnc,
)
if err != nil {
return big.Zero(), big.Zero(), err
return big.Zero(), big.Zero(), xerrors.Errorf("failed to activate deals: %w", err)
}
if err := dealWeights.UnmarshalCBOR(bytes.NewReader(ret)); err != nil {
if err := dealWeights.UnmarshalCBOR(bytes.NewReader(ret)); xerrors.Errorf("failed to unmarshal ret: %w", err) != nil {
return big.Zero(), big.Zero(), err
}
return dealWeights.Sectors[0].DealWeight, dealWeights.Sectors[0].VerifiedDealWeight, nil
return dealWeights.Weights.DealWeight, dealWeights.Weights.VerifiedDealWeight, nil
}
func currentEpochBlockReward(ctx context.Context, vm vm.Interface, maddr address.Address, av actorstypes.Version) (abi.StoragePower, builtin.FilterEstimate, error) {

2
extern/filecoin-ffi vendored

@ -1 +1 @@
Subproject commit f997fe6c77632c0bc58d0b1fdf53ee7a93f6027c
Subproject commit b3185c5fbe05a1032fde707fee2f95ef117461d0

2
go.mod
View File

@ -42,7 +42,7 @@ require (
github.com/filecoin-project/go-legs v0.4.4
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.1.12-0.20220907205406-e8b028ad923f
github.com/filecoin-project/go-state-types v0.1.12-0.20220909195146-6740cdd9390d
github.com/filecoin-project/go-statemachine v1.0.2
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/go-storedcounter v0.1.0

8
go.sum
View File

@ -343,8 +343,12 @@ github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psS
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.12-0.20220907205406-e8b028ad923f h1:khCYaU4ieUwhWiRncmGBBI21wXhVF1xaGSgw7Pwcvmw=
github.com/filecoin-project/go-state-types v0.1.12-0.20220907205406-e8b028ad923f/go.mod h1:n/kujdC9JphvYTrmaD1+vJpvDPy/DwzckoMzP0nBKWI=
github.com/filecoin-project/go-state-types v0.1.12-0.20220909165003-f4ad1a59d916 h1:30E8Wwpe17E816LVRZeeN4QLklGpVO2v+1tGXuQx1Ps=
github.com/filecoin-project/go-state-types v0.1.12-0.20220909165003-f4ad1a59d916/go.mod h1:n/kujdC9JphvYTrmaD1+vJpvDPy/DwzckoMzP0nBKWI=
github.com/filecoin-project/go-state-types v0.1.12-0.20220909170026-395c37ab732c h1:+QMHpDZ0Zhc1K1nAUg+S2Cm1muEJhGa8N8Nx2tL2Rcc=
github.com/filecoin-project/go-state-types v0.1.12-0.20220909170026-395c37ab732c/go.mod h1:n/kujdC9JphvYTrmaD1+vJpvDPy/DwzckoMzP0nBKWI=
github.com/filecoin-project/go-state-types v0.1.12-0.20220909195146-6740cdd9390d h1:r1uMayyVGBNZv2WPWEG6Qy7PUmjX8H+tFQnHjCOjwmM=
github.com/filecoin-project/go-state-types v0.1.12-0.20220909195146-6740cdd9390d/go.mod h1:n/kujdC9JphvYTrmaD1+vJpvDPy/DwzckoMzP0nBKWI=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=