Merge branch 'feat/nv16'

This commit is contained in:
Aayush
2022-06-03 14:01:49 -04:00
324 changed files with 7417 additions and 3262 deletions
+10 -4
View File
@@ -12,6 +12,8 @@ import (
"strings"
"time"
market8 "github.com/filecoin-project/go-state-types/builtin/v8/market"
bstore "github.com/ipfs/go-ipfs-blockstore"
format "github.com/ipfs/go-ipld-format"
unixfile "github.com/ipfs/go-unixfs/file"
@@ -60,7 +62,6 @@ import (
"github.com/filecoin-project/lotus/markets/storageadapter"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/specs-actors/v3/actors/builtin/market"
"github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/node/repo/imports"
@@ -233,12 +234,17 @@ func (a *API) dealStarter(ctx context.Context, params *api.StartDealParams, isSt
// stateless flow from here to the end
//
dealProposal := &market.DealProposal{
label, err := market8.NewLabelFromString(params.Data.Root.Encode(multibase.MustNewEncoder('u')))
if err != nil {
return nil, xerrors.Errorf("failed to encode label: %w", err)
}
dealProposal := &market8.DealProposal{
PieceCID: *params.Data.PieceCid,
PieceSize: params.Data.PieceSize.Padded(),
Client: walletKey,
Provider: params.Miner,
Label: params.Data.Root.Encode(multibase.MustNewEncoder('u')),
Label: label,
StartEpoch: dealStart,
EndEpoch: calcDealExpiration(params.MinBlocksDuration, md, dealStart),
StoragePricePerEpoch: big.Zero(),
@@ -265,7 +271,7 @@ func (a *API) dealStarter(ctx context.Context, params *api.StartDealParams, isSt
return nil, xerrors.Errorf("failed to sign proposal : %w", err)
}
dealProposalSigned := &market.ClientDealProposal{
dealProposalSigned := &market8.ClientDealProposal{
Proposal: *dealProposal,
ClientSignature: *dealProposalSig,
}
-1
View File
@@ -35,7 +35,6 @@ type FullNodeAPI struct {
full.MsigAPI
full.WalletAPI
full.SyncAPI
full.BeaconAPI
DS dtypes.MetadataDS
NetworkName dtypes.NetworkName
-36
View File
@@ -1,36 +0,0 @@
package full
import (
"context"
"fmt"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/chain/beacon"
"github.com/filecoin-project/lotus/chain/types"
"go.uber.org/fx"
)
type BeaconAPI struct {
fx.In
Beacon beacon.Schedule
}
func (a *BeaconAPI) BeaconGetEntry(ctx context.Context, epoch abi.ChainEpoch) (*types.BeaconEntry, error) {
b := a.Beacon.BeaconForEpoch(epoch)
rr := b.MaxBeaconRoundForEpoch(epoch)
e := b.Entry(ctx, rr)
select {
case be, ok := <-e:
if !ok {
return nil, fmt.Errorf("beacon get returned no value")
}
if be.Err != nil {
return nil, be.Err
}
return &be.Entry, nil
case <-ctx.Done():
return nil, ctx.Err()
}
}
+55 -23
View File
@@ -6,8 +6,9 @@ import (
"math/rand"
"sort"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
lbuiltin "github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/go-state-types/builtin"
lru "github.com/hashicorp/golang-lru"
"go.uber.org/fx"
@@ -295,31 +296,62 @@ func gasEstimateGasLimit(
return -1, xerrors.Errorf("message execution failed: exit %s, reason: %s", res.MsgRct.ExitCode, res.Error)
}
ret := res.MsgRct.GasUsed
transitionalMulti := 1.0
// Overestimate gas around the upgrade
if ts.Height() <= build.UpgradeSkyrHeight && (build.UpgradeSkyrHeight-ts.Height() <= 20) {
transitionalMulti = 2.0
func() {
st, err := smgr.ParentState(ts)
if err != nil {
return
}
act, err := st.GetActor(msg.To)
if err != nil {
return
}
if lbuiltin.IsStorageMinerActor(act.Code) {
switch msgIn.Method {
case 5:
transitionalMulti = 3.954
case 6:
transitionalMulti = 4.095
case 7:
// skip, stay at 2.0
//transitionalMulti = 1.289
case 11:
transitionalMulti = 17.8758
case 16:
transitionalMulti = 2.1704
case 25:
transitionalMulti = 3.1177
case 26:
transitionalMulti = 2.3322
default:
}
}
// skip storage market, 80th percentie for everything ~1.9, leave it at 2.0
}()
}
ret = (ret * int64(transitionalMulti*1024)) >> 10
// Special case for PaymentChannel collect, which is deleting actor
// We ignore errors in this special case since they CAN occur,
// and we just want to detect existing payment channel actors
st, err := smgr.ParentState(ts)
if err != nil {
_ = err
// somewhat ignore it as it can happen and we just want to detect
// an existing PaymentChannel actor
return res.MsgRct.GasUsed, nil
}
act, err := st.GetActor(msg.To)
if err != nil {
_ = err
// somewhat ignore it as it can happen and we just want to detect
// an existing PaymentChannel actor
return res.MsgRct.GasUsed, nil
if err == nil {
act, err := st.GetActor(msg.To)
if err == nil && lbuiltin.IsPaymentChannelActor(act.Code) && msgIn.Method == builtin.MethodsPaych.Collect {
// add the refunded gas for DestroyActor back into the gas used
ret += 76e3
}
}
if !builtin.IsPaymentChannelActor(act.Code) {
return res.MsgRct.GasUsed, nil
}
if msgIn.Method != paych.Methods.Collect {
return res.MsgRct.GasUsed, nil
}
// return GasUsed without the refund for DestoryActor
return res.MsgRct.GasUsed + 76e3, nil
return ret, nil
}
func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, _ types.TipSetKey) (*types.Message, error) {
+64 -16
View File
@@ -4,8 +4,11 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"strconv"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/cbor"
@@ -22,6 +25,7 @@ import (
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
@@ -53,7 +57,7 @@ type StateModuleAPI interface {
StateLookupID(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error)
StateMarketBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MarketBalance, error)
StateMarketStorageDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*api.MarketDeal, error)
StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error)
StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (api.MinerInfo, error)
StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*dline.Info, error)
StateMinerPower(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error)
StateNetworkVersion(ctx context.Context, key types.TipSetKey) (network.Version, error)
@@ -132,27 +136,52 @@ func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Ad
return mas.LoadSectors(&activeSectors)
}
func (m *StateModule) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) {
func (m *StateModule) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (api.MinerInfo, error) {
ts, err := m.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return miner.MinerInfo{}, xerrors.Errorf("failed to load tipset: %w", err)
return api.MinerInfo{}, xerrors.Errorf("failed to load tipset: %w", err)
}
act, err := m.StateManager.LoadActor(ctx, actor, ts)
if err != nil {
return miner.MinerInfo{}, xerrors.Errorf("failed to load miner actor: %w", err)
return api.MinerInfo{}, xerrors.Errorf("failed to load miner actor: %w", err)
}
mas, err := miner.Load(m.StateManager.ChainStore().ActorStore(ctx), act)
if err != nil {
return miner.MinerInfo{}, xerrors.Errorf("failed to load miner actor state: %w", err)
return api.MinerInfo{}, xerrors.Errorf("failed to load miner actor state: %w", err)
}
info, err := mas.Info()
if err != nil {
return miner.MinerInfo{}, err
return api.MinerInfo{}, err
}
return info, nil
var pid *peer.ID
if peerID, err := peer.IDFromBytes(info.PeerId); err == nil {
pid = &peerID
}
ret := api.MinerInfo{
Owner: info.Owner,
Worker: info.Worker,
ControlAddresses: info.ControlAddresses,
NewWorker: address.Undef,
WorkerChangeEpoch: -1,
PeerId: pid,
Multiaddrs: info.Multiaddrs,
WindowPoStProofType: info.WindowPoStProofType,
SectorSize: info.SectorSize,
WindowPoStPartitionSectors: info.WindowPoStPartitionSectors,
ConsensusFaultElapsed: info.ConsensusFaultElapsed,
}
if info.PendingWorkerKey != nil {
ret.NewWorker = info.PendingWorkerKey.NewWorker
ret.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt
}
return ret, nil
}
func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]api.Deadline, error) {
@@ -680,8 +709,8 @@ func (a *StateAPI) StateMarketParticipants(ctx context.Context, tsk types.TipSet
return out, nil
}
func (a *StateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]api.MarketDeal, error) {
out := map[string]api.MarketDeal{}
func (a *StateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]*api.MarketDeal, error) {
out := map[string]*api.MarketDeal{}
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
@@ -710,7 +739,7 @@ func (a *StateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (m
} else if !found {
s = market.EmptyDealState()
}
out[strconv.FormatInt(int64(dealID), 10)] = api.MarketDeal{
out[strconv.FormatInt(int64(dealID), 10)] = &api.MarketDeal{
Proposal: d,
State: *s,
}
@@ -786,17 +815,17 @@ func (a *StateAPI) StateMinerSectorCount(ctx context.Context, addr address.Addre
return api.MinerSectors{Live: liveCount, Active: activeCount, Faulty: faultyCount}, nil
}
func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) {
func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (minertypes.SectorPreCommitOnChainInfo, error) {
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return miner.SectorPreCommitOnChainInfo{}, xerrors.Errorf("loading tipset %s: %w", tsk, err)
return minertypes.SectorPreCommitOnChainInfo{}, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
pci, err := stmgr.PreCommitInfo(ctx, a.StateManager, maddr, n, ts)
if err != nil {
return miner.SectorPreCommitOnChainInfo{}, err
return minertypes.SectorPreCommitOnChainInfo{}, err
} else if pci == nil {
return miner.SectorPreCommitOnChainInfo{}, xerrors.Errorf("precommit info is not exists")
return minertypes.SectorPreCommitOnChainInfo{}, xerrors.Errorf("precommit info is not exists")
}
return *pci, err
@@ -1062,7 +1091,7 @@ func (m *StateModule) MsigGetPending(ctx context.Context, addr address.Address,
var initialPledgeNum = types.NewInt(110)
var initialPledgeDen = types.NewInt(100)
func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr address.Address, pci miner.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) {
func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr address.Address, pci minertypes.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) {
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return types.EmptyInt, xerrors.Errorf("loading tipset %s: %w", tsk, err)
@@ -1122,7 +1151,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr
return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil
}
func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr address.Address, pci miner.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) {
func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr address.Address, pci minertypes.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) {
// TODO: this repeats a lot of the previous function. Fix that.
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
@@ -1440,6 +1469,25 @@ func (a *StateAPI) StateGetRandomnessFromBeacon(ctx context.Context, personaliza
}
func (a *StateAPI) StateGetBeaconEntry(ctx context.Context, epoch abi.ChainEpoch) (*types.BeaconEntry, error) {
b := a.Beacon.BeaconForEpoch(epoch)
rr := b.MaxBeaconRoundForEpoch(a.StateManager.GetNetworkVersion(ctx, epoch), epoch)
e := b.Entry(ctx, rr)
select {
case be, ok := <-e:
if !ok {
return nil, fmt.Errorf("beacon get returned no value")
}
if be.Err != nil {
return nil, be.Err
}
return &be.Entry, nil
case <-ctx.Done():
return nil, ctx.Err()
}
}
func (a *StateAPI) StateGetNetworkParams(ctx context.Context) (*api.NetworkParams, error) {
networkName, err := a.StateNetworkName(ctx)
if err != nil {
+10 -10
View File
@@ -10,8 +10,8 @@ import (
"github.com/filecoin-project/go-address"
paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/paychmgr"
)
@@ -83,10 +83,10 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address
return nil, err
}
svs := make([]*paych.SignedVoucher, len(vouchers))
svs := make([]*paychtypes.SignedVoucher, len(vouchers))
for i, v := range vouchers {
sv, err := a.PaychMgr.CreateVoucher(ctx, ch.Channel, paych.SignedVoucher{
sv, err := a.PaychMgr.CreateVoucher(ctx, ch.Channel, paychtypes.SignedVoucher{
Amount: v.Amount,
Lane: lane,
@@ -135,15 +135,15 @@ func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid.
return a.PaychMgr.Collect(ctx, addr)
}
func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error {
func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher) error {
return a.PaychMgr.CheckVoucherValid(ctx, ch, sv)
}
func (a *PaychAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) {
func (a *PaychAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher, secret []byte, proof []byte) (bool, error) {
return a.PaychMgr.CheckVoucherSpendable(ctx, ch, sv, secret, proof)
}
func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) {
func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) {
return a.PaychMgr.AddVoucherInbound(ctx, ch, sv, proof, minDelta)
}
@@ -155,16 +155,16 @@ func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *
// If there are insufficient funds in the channel to create the voucher,
// returns a nil voucher and the shortfall.
func (a *PaychAPI) PaychVoucherCreate(ctx context.Context, pch address.Address, amt types.BigInt, lane uint64) (*api.VoucherCreateResult, error) {
return a.PaychMgr.CreateVoucher(ctx, pch, paych.SignedVoucher{Amount: amt, Lane: lane})
return a.PaychMgr.CreateVoucher(ctx, pch, paychtypes.SignedVoucher{Amount: amt, Lane: lane})
}
func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych.SignedVoucher, error) {
func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([]*paychtypes.SignedVoucher, error) {
vi, err := a.PaychMgr.ListVouchers(ctx, pch)
if err != nil {
return nil, err
}
out := make([]*paych.SignedVoucher, len(vi))
out := make([]*paychtypes.SignedVoucher, len(vi))
for k, v := range vi {
out[k] = v.Voucher
}
@@ -172,6 +172,6 @@ func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([
return out, nil
}
func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) {
func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) {
return a.PaychMgr.SubmitVoucher(ctx, ch, sv, secret, proof)
}
+7 -6
View File
@@ -11,12 +11,13 @@ import (
"strconv"
"time"
minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner"
"github.com/filecoin-project/dagstore"
"github.com/filecoin-project/dagstore/shard"
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/lotus/chain/actors/builtin"
lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/gen"
"github.com/google/uuid"
@@ -413,7 +414,7 @@ func (sm *StorageMinerAPI) SectorMatchPendingPiecesToOpenSectors(ctx context.Con
return sm.Miner.SectorMatchPendingPiecesToOpenSectors(ctx)
}
func (sm *StorageMinerAPI) ComputeWindowPoSt(ctx context.Context, dlIdx uint64, tsk types.TipSetKey) ([]lminer.SubmitWindowedPoStParams, error) {
func (sm *StorageMinerAPI) ComputeWindowPoSt(ctx context.Context, dlIdx uint64, tsk types.TipSetKey) ([]minertypes.SubmitWindowedPoStParams, error) {
var ts *types.TipSet
var err error
if tsk == types.EmptyTSK {
@@ -461,7 +462,7 @@ func (sm *StorageMinerAPI) MarketImportDealData(ctx context.Context, propCid cid
return sm.StorageProvider.ImportDataForDeal(ctx, propCid, fi)
}
func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]api.MarketDeal, error) {
func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]*api.MarketDeal, error) {
ts, err := sm.Full.ChainHead(ctx)
if err != nil {
return nil, err
@@ -472,7 +473,7 @@ func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]api.MarketDeal, err
return nil, err
}
var out []api.MarketDeal
var out []*api.MarketDeal
for _, deal := range allDeals {
if deal.Proposal.Provider == sm.Miner.Address() {
@@ -483,7 +484,7 @@ func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]api.MarketDeal, err
return out, nil
}
func (sm *StorageMinerAPI) MarketListDeals(ctx context.Context) ([]api.MarketDeal, error) {
func (sm *StorageMinerAPI) MarketListDeals(ctx context.Context) ([]*api.MarketDeal, error) {
return sm.listDeals(ctx)
}
@@ -1108,7 +1109,7 @@ func (sm *StorageMinerAPI) DagstoreLookupPieces(ctx context.Context, cid cid.Cid
return ret, nil
}
func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]api.MarketDeal, error) {
func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]*api.MarketDeal, error) {
return sm.listDeals(ctx)
}