fixup genesis creation
This commit is contained in:
parent
e9a3235291
commit
30f66578e1
@ -6,6 +6,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"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"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
@ -26,7 +32,6 @@ import (
|
|||||||
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||||
power0 "github.com/filecoin-project/specs-actors/actors/builtin/power"
|
power0 "github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||||
reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward"
|
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"
|
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
|
||||||
reward2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/reward"
|
reward2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/reward"
|
||||||
market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market"
|
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
|
presealExp abi.ChainEpoch
|
||||||
|
|
||||||
dealIDs []abi.DealID
|
dealIDs []abi.DealID
|
||||||
|
sectorWeight []abi.StoragePower
|
||||||
}, len(miners))
|
}, len(miners))
|
||||||
|
|
||||||
maxPeriods := policy.GetMaxSectorExpirationExtension() / minertypes.WPoStProvingPeriod
|
maxPeriods := policy.GetMaxSectorExpirationExtension() / minertypes.WPoStProvingPeriod
|
||||||
|
rawPow, qaPow := big.NewInt(0), big.NewInt(0)
|
||||||
for i, m := range miners {
|
for i, m := range miners {
|
||||||
// Create miner through power actor
|
// Create miner through power actor
|
||||||
i := i
|
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 {
|
publish := func(params *markettypes.PublishStorageDealsParams) error {
|
||||||
@ -227,6 +234,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
|
|||||||
|
|
||||||
params := &markettypes.PublishStorageDealsParams{}
|
params := &markettypes.PublishStorageDealsParams{}
|
||||||
for _, preseal := range m.Sectors {
|
for _, preseal := range m.Sectors {
|
||||||
|
fmt.Println("presealing ", preseal.SectorID)
|
||||||
preseal.Deal.VerifiedDeal = true
|
preseal.Deal.VerifiedDeal = true
|
||||||
preseal.Deal.EndEpoch = minerInfos[i].presealExp
|
preseal.Deal.EndEpoch = minerInfos[i].presealExp
|
||||||
p := markettypes.ClientDealProposal{
|
p := markettypes.ClientDealProposal{
|
||||||
@ -257,6 +265,11 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
|
|||||||
|
|
||||||
params = &markettypes.PublishStorageDealsParams{}
|
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 {
|
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)
|
nh, err := genesisVm.Flush(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
|
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!
|
Expiration: minerInfos[i].presealExp, // TODO: Allow setting externally!
|
||||||
}
|
}
|
||||||
|
|
||||||
dweight, vdweight, err := dealWeight(ctx, genesisVm, minerInfos[i].maddr, params.DealIDs, 0, minerInfos[i].presealExp, av)
|
sectorWeight := minerInfos[i].sectorWeight[pi]
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("getting deal weight: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sectorWeight := builtin.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight, vdweight)
|
|
||||||
|
|
||||||
// we've added fake power for this sector above, remove it now
|
// 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)
|
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,
|
sectorWeight,
|
||||||
baselinePower,
|
baselinePower,
|
||||||
tpow.PledgeCollateral,
|
smoothing9.FilterEstimate(rewardSmoothed),
|
||||||
(*smoothing0.FilterEstimate)(&rewardSmoothed),
|
smoothing9.FilterEstimate(*tpow.QualityAdjPowerSmoothed),
|
||||||
tpow.QualityAdjPowerSmoothed,
|
|
||||||
big.Zero(),
|
big.Zero(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -617,7 +606,7 @@ func currentTotalPower(ctx context.Context, vm vm.Interface, maddr address.Addre
|
|||||||
return &pwr, nil
|
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
|
// TODO: This hack should move to market actor wrapper
|
||||||
if av <= actorstypes.Version2 {
|
if av <= actorstypes.Version2 {
|
||||||
params := &market0.VerifyDealsForActivationParams{
|
params := &market0.VerifyDealsForActivationParams{
|
||||||
@ -654,27 +643,54 @@ func dealWeight(ctx context.Context, vm vm.Interface, maddr address.Address, dea
|
|||||||
|
|
||||||
return weight, verifiedWeight, nil
|
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,
|
ret, err := doExecValue(ctx, vm,
|
||||||
market.Address,
|
market.Address,
|
||||||
maddr,
|
maddr,
|
||||||
abi.NewTokenAmount(0),
|
abi.NewTokenAmount(0),
|
||||||
market.Methods.VerifyDealsForActivation,
|
market.Methods.ActivateDeals,
|
||||||
mustEnc(params),
|
paramEnc,
|
||||||
)
|
)
|
||||||
if err != nil {
|
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 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) {
|
func currentEpochBlockReward(ctx context.Context, vm vm.Interface, maddr address.Address, av actorstypes.Version) (abi.StoragePower, builtin.FilterEstimate, error) {
|
||||||
|
2
extern/filecoin-ffi
vendored
2
extern/filecoin-ffi
vendored
@ -1 +1 @@
|
|||||||
Subproject commit f997fe6c77632c0bc58d0b1fdf53ee7a93f6027c
|
Subproject commit b3185c5fbe05a1032fde707fee2f95ef117461d0
|
2
go.mod
2
go.mod
@ -42,7 +42,7 @@ require (
|
|||||||
github.com/filecoin-project/go-legs v0.4.4
|
github.com/filecoin-project/go-legs v0.4.4
|
||||||
github.com/filecoin-project/go-padreader v0.0.1
|
github.com/filecoin-project/go-padreader v0.0.1
|
||||||
github.com/filecoin-project/go-paramfetch v0.0.4
|
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-statemachine v1.0.2
|
||||||
github.com/filecoin-project/go-statestore v0.2.0
|
github.com/filecoin-project/go-statestore v0.2.0
|
||||||
github.com/filecoin-project/go-storedcounter v0.1.0
|
github.com/filecoin-project/go-storedcounter v0.1.0
|
||||||
|
8
go.sum
8
go.sum
@ -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.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.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.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.20220909165003-f4ad1a59d916 h1:30E8Wwpe17E816LVRZeeN4QLklGpVO2v+1tGXuQx1Ps=
|
||||||
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/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 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 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
|
||||||
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=
|
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=
|
||||||
|
Loading…
Reference in New Issue
Block a user