lotus/storage/pipeline/pledge.go
Łukasz Magiera 6a0f16b084 feat: sealing: Support nv22 DDO features in the sealing pipeline (#11226)
* Initial work supporting DDO pieces in lotus-miner

* sealing: Update pipeline input to operate on UniversalPiece

* sealing: Update pipeline checks/sealing states to operate on UniversalPiece

* sealing: Make pipeline build with UniversalPiece

* move PieceDealInfo out of api

* make gen

* make sealing pipeline unit tests pass

* fix itest ensemble build

* don't panic in SectorsStatus with deals

* stop linter from complaining about checkPieces

* fix sector import tests

* mod tidy

* sealing: Add logic for (pre)committing DDO sectors

* sealing: state-types with method defs

* DDO non-snap pipeline works(?), DDO Itests

* DDO support in snapdeals pipeline

* make gen

* update actor bundles

* update the gst market fix

* fix: chain: use PreCommitSectorsBatch2 when setting up genesis

* some bug fixes

* integration working changes

* update actor bundles

* Make TestOnboardRawPieceSnap pass

* Appease the linter

* Make deadlines test pass with v12 actors

* Update go-state-types, abstract market DealState

* make gen

* mod tidy, lint fixes

* Fix some more tests

* Bump version in master

Bump version in master

* Make gen

Make gen

* fix sender

* fix: lotus-provider: Fix winning PoSt

* fix: sql Scan cannot write to an object

* Actually show miner-addrs in info-log

Actually show miner-addrs in lotus-provider info-log

* [WIP] feat: Add nv22 skeleton

Addition of Network Version 22 skeleton

* update FFI

* ddo is now nv22

* make gen

* temp actor bundle with ddo

* use working go-state-types

* gst with v13 market migration

* update bundle, builtin.MethodsMiner.ProveCommitSectors2 -> 3

* actually working v13 migration, v13 migration itest

* Address review

* sealing: Correct DDO snap pledge math

* itests: Mixed ddo itest

* pipeline: Fix sectorWeight

* sealing: convert market deals into PAMs in mixed sectors

* sealing: make market to ddo conversion work

* fix lint

* update gst

* Update actors and GST to lastest integ branch

* commit batcher: Update ProveCommitSectors3Params builder logic

* make gen

* use builtin-actors master

* ddo: address review

* itests: Add commd assertions to ddo tests

* make gen

* gst with fixed types

* config knobs for RequireActivationSuccess

* storage: Drop obsolete flaky tasts

---------

Co-authored-by: Jennifer Wang <jiayingw703@gmail.com>
Co-authored-by: Aayush <arajasek94@gmail.com>
Co-authored-by: Shrenuj Bansal <shrenuj.bansal@protocol.ai>
Co-authored-by: Phi <orjan.roren@gmail.com>
Co-authored-by: Andrew Jackson (Ajax) <snadrus@gmail.com>
Co-authored-by: TippyFlits <james.bluett@protocol.ai>
2024-03-22 07:00:28 +01:00

115 lines
3.6 KiB
Go

package sealing
import (
"context"
cbor "github.com/ipfs/go-ipld-cbor"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
bstore "github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
"github.com/filecoin-project/lotus/chain/types"
)
var initialPledgeNum = types.NewInt(110)
var initialPledgeDen = types.NewInt(100)
func (m *Sealing) pledgeForPower(ctx context.Context, addedPower abi.StoragePower) (abi.TokenAmount, error) {
store := adt.WrapStore(ctx, cbor.NewCborStore(bstore.NewAPIBlockstore(m.Api)))
// load power actor
var (
powerSmoothed builtin.FilterEstimate
pledgeCollateral abi.TokenAmount
)
if act, err := m.Api.StateGetActor(ctx, power.Address, types.EmptyTSK); err != nil {
return types.EmptyInt, xerrors.Errorf("loading power actor: %w", err)
} else if s, err := power.Load(store, act); err != nil {
return types.EmptyInt, xerrors.Errorf("loading power actor state: %w", err)
} else if p, err := s.TotalPowerSmoothed(); err != nil {
return types.EmptyInt, xerrors.Errorf("failed to determine total power: %w", err)
} else if c, err := s.TotalLocked(); err != nil {
return types.EmptyInt, xerrors.Errorf("failed to determine pledge collateral: %w", err)
} else {
powerSmoothed = p
pledgeCollateral = c
}
// load reward actor
rewardActor, err := m.Api.StateGetActor(ctx, reward.Address, types.EmptyTSK)
if err != nil {
return types.EmptyInt, xerrors.Errorf("loading reward actor: %w", err)
}
rewardState, err := reward.Load(store, rewardActor)
if err != nil {
return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err)
}
// get circulating supply
circSupply, err := m.Api.StateVMCirculatingSupplyInternal(ctx, types.EmptyTSK)
if err != nil {
return big.Zero(), xerrors.Errorf("getting circulating supply: %w", err)
}
// do the calculation
initialPledge, err := rewardState.InitialPledgeForPower(
addedPower,
pledgeCollateral,
&powerSmoothed,
circSupply.FilCirculating,
)
if err != nil {
return big.Zero(), xerrors.Errorf("calculating initial pledge: %w", err)
}
return types.BigDiv(types.BigMul(initialPledge, initialPledgeNum), initialPledgeDen), nil
}
func (m *Sealing) sectorWeight(ctx context.Context, sector SectorInfo, expiration abi.ChainEpoch) (abi.StoragePower, error) {
spt, err := m.currentSealProof(ctx)
if err != nil {
return types.EmptyInt, xerrors.Errorf("getting seal proof type: %w", err)
}
ssize, err := spt.SectorSize()
if err != nil {
return types.EmptyInt, xerrors.Errorf("getting sector size: %w", err)
}
ts, err := m.Api.ChainHead(ctx)
if err != nil {
return types.EmptyInt, xerrors.Errorf("getting chain head: %w", err)
}
// get verified deal infos
var w, vw = big.Zero(), big.Zero()
for _, piece := range sector.Pieces {
if !piece.HasDealInfo() {
// todo StateMinerInitialPledgeCollateral doesn't add cc/padding to non-verified weight, is that correct?
continue
}
alloc, err := piece.GetAllocation(ctx, m.Api, ts.Key())
if err != nil || alloc == nil {
w = big.Add(w, abi.NewStoragePower(int64(piece.Piece().Size)))
continue
}
vw = big.Add(vw, abi.NewStoragePower(int64(piece.Piece().Size)))
}
// load market actor
duration := expiration - ts.Height()
sectorWeight := builtin.QAPowerForWeight(ssize, duration, w, vw)
return sectorWeight, nil
}