Merge branch 'master' into sbansal/nonce-coordination-and-consensus-for-chain-nodes

This commit is contained in:
Shrenuj Bansal
2022-11-11 14:41:38 -05:00
261 changed files with 7497 additions and 19074 deletions
+37 -7
View File
@@ -10,6 +10,7 @@ import (
"os"
"sort"
"strings"
"sync"
"time"
"github.com/ipfs/go-blockservice"
@@ -52,7 +53,7 @@ import (
"github.com/filecoin-project/go-padreader"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
market8 "github.com/filecoin-project/go-state-types/builtin/v8/market"
markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market"
"github.com/filecoin-project/go-state-types/dline"
"github.com/filecoin-project/lotus/api"
@@ -97,6 +98,7 @@ type API struct {
Imports dtypes.ClientImportMgr
StorageBlockstoreAccessor storagemarket.BlockstoreAccessor
RtvlBlockstoreAccessor rm.BlockstoreAccessor
ApiBlockstoreAccessor *retrievaladapter.APIBlockstoreAccessor
DataTransfer dtypes.ClientDataTransfer
Host host.Host
@@ -228,12 +230,12 @@ func (a *API) dealStarter(ctx context.Context, params *api.StartDealParams, isSt
// stateless flow from here to the end
//
label, err := market8.NewLabelFromString(params.Data.Root.Encode(multibase.MustNewEncoder('u')))
label, err := markettypes.NewLabelFromString(params.Data.Root.Encode(multibase.MustNewEncoder('u')))
if err != nil {
return nil, xerrors.Errorf("failed to encode label: %w", err)
}
dealProposal := &market8.DealProposal{
dealProposal := &markettypes.DealProposal{
PieceCID: *params.Data.PieceCid,
PieceSize: params.Data.PieceSize.Padded(),
Client: walletKey,
@@ -265,7 +267,7 @@ func (a *API) dealStarter(ctx context.Context, params *api.StartDealParams, isSt
return nil, xerrors.Errorf("failed to sign proposal : %w", err)
}
dealProposalSigned := &market8.ClientDealProposal{
dealProposalSigned := &markettypes.ClientDealProposal{
Proposal: *dealProposal,
ClientSignature: *dealProposalSig,
}
@@ -845,6 +847,13 @@ func (a *API) doRetrieval(ctx context.Context, order api.RetrievalOrder, sel dat
}
id := a.Retrieval.NextID()
if order.RemoteStore != nil {
if err := a.ApiBlockstoreAccessor.RegisterDealToRetrievalStore(id, *order.RemoteStore); err != nil {
return 0, xerrors.Errorf("registering api store: %w", err)
}
}
id, err = a.Retrieval.Retrieve(
ctx,
id,
@@ -999,6 +1008,8 @@ func (a *API) outputCAR(ctx context.Context, ds format.DAGService, bs bstore.Blo
roots[i] = dag.root
}
var lk sync.Mutex
return dest.doWrite(func(w io.Writer) error {
if err := car.WriteHeader(&car.CarHeader{
@@ -1011,13 +1022,29 @@ func (a *API) outputCAR(ctx context.Context, ds format.DAGService, bs bstore.Blo
cs := cid.NewSet()
for _, dagSpec := range dags {
dagSpec := dagSpec
if err := utils.TraverseDag(
ctx,
ds,
root,
dagSpec.selector,
func(node format.Node) error {
// if we're exporting merkle proofs for this dag, export all nodes read by the traversal
if dagSpec.exportAll {
lk.Lock()
defer lk.Unlock()
if cs.Visit(node.Cid()) {
err := util.LdWrite(w, node.Cid().Bytes(), node.RawData())
if err != nil {
return xerrors.Errorf("writing block data: %w", err)
}
}
}
return nil
},
func(p traversal.Progress, n ipld.Node, r traversal.VisitReason) error {
if r == traversal.VisitReason_SelectionMatch {
if !dagSpec.exportAll && r == traversal.VisitReason_SelectionMatch {
var c cid.Cid
if p.LastBlock.Link == nil {
c = root
@@ -1082,8 +1109,9 @@ func (a *API) outputUnixFS(ctx context.Context, root cid.Cid, ds format.DAGServi
}
type dagSpec struct {
root cid.Cid
selector ipld.Node
root cid.Cid
selector ipld.Node
exportAll bool
}
func parseDagSpec(ctx context.Context, root cid.Cid, dsp []api.DagSpec, ds format.DAGService, car bool) ([]dagSpec, error) {
@@ -1098,6 +1126,7 @@ func parseDagSpec(ctx context.Context, root cid.Cid, dsp []api.DagSpec, ds forma
out := make([]dagSpec, len(dsp))
for i, spec := range dsp {
out[i].exportAll = spec.ExportMerkleProof
if spec.DataSelector == nil {
return nil, xerrors.Errorf("invalid DagSpec at position %d: `DataSelector` can not be nil", i)
@@ -1131,6 +1160,7 @@ func parseDagSpec(ctx context.Context, root cid.Cid, dsp []api.DagSpec, ds forma
ds,
root,
rsn,
nil,
func(p traversal.Progress, n ipld.Node, r traversal.VisitReason) error {
if r == traversal.VisitReason_SelectionMatch {
if !car && p.LastBlock.Path.String() != p.Path.String() {
+174 -11
View File
@@ -19,6 +19,7 @@ import (
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/go-state-types/big"
minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/dline"
@@ -30,6 +31,7 @@ import (
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/datacap"
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/actors/builtin/multisig"
@@ -769,6 +771,135 @@ func (m *StateModule) StateMarketStorageDeal(ctx context.Context, dealId abi.Dea
return stmgr.GetStorageDeal(ctx, m.StateManager, dealId, ts)
}
func (a *StateAPI) StateGetAllocationForPendingDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*verifregtypes.Allocation, error) {
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
st, err := a.StateManager.GetMarketState(ctx, ts)
if err != nil {
return nil, err
}
allocationId, err := st.GetAllocationIdForPendingDeal(dealId)
if err != nil {
return nil, err
}
if allocationId == verifregtypes.NoAllocationID {
return nil, nil
}
dealState, err := a.StateMarketStorageDeal(ctx, dealId, tsk)
if err != nil {
return nil, err
}
return a.StateGetAllocation(ctx, dealState.Proposal.Client, allocationId, tsk)
}
func (a *StateAPI) StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) {
idAddr, err := a.StateLookupID(ctx, clientAddr, tsk)
if err != nil {
return nil, err
}
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
st, err := a.StateManager.GetVerifregState(ctx, ts)
if err != nil {
return nil, err
}
allocation, found, err := st.GetAllocation(idAddr, allocationId)
if err != nil {
return nil, xerrors.Errorf("getting allocation: %w", err)
}
if !found {
return nil, nil
}
return allocation, nil
}
func (a *StateAPI) StateGetAllocations(ctx context.Context, clientAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) {
idAddr, err := a.StateLookupID(ctx, clientAddr, tsk)
if err != nil {
return nil, err
}
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
st, err := a.StateManager.GetVerifregState(ctx, ts)
if err != nil {
return nil, xerrors.Errorf("loading verifreg state: %w", err)
}
allocations, err := st.GetAllocations(idAddr)
if err != nil {
return nil, xerrors.Errorf("getting allocations: %w", err)
}
return allocations, nil
}
func (a *StateAPI) StateGetClaim(ctx context.Context, providerAddr address.Address, claimId verifregtypes.ClaimId, tsk types.TipSetKey) (*verifregtypes.Claim, error) {
idAddr, err := a.StateLookupID(ctx, providerAddr, tsk)
if err != nil {
return nil, err
}
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
st, err := a.StateManager.GetVerifregState(ctx, ts)
if err != nil {
return nil, err
}
claim, found, err := st.GetClaim(idAddr, claimId)
if err != nil {
return nil, xerrors.Errorf("getting claim: %w", err)
}
if !found {
return nil, nil
}
return claim, nil
}
func (a *StateAPI) StateGetClaims(ctx context.Context, providerAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) {
idAddr, err := a.StateLookupID(ctx, providerAddr, tsk)
if err != nil {
return nil, err
}
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
st, err := a.StateManager.GetVerifregState(ctx, ts)
if err != nil {
return nil, xerrors.Errorf("loading verifreg state: %w", err)
}
claims, err := st.GetClaims(idAddr)
if err != nil {
return nil, xerrors.Errorf("getting claims: %w", err)
}
return claims, nil
}
func (a *StateAPI) StateComputeDataCID(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error) {
nv, err := a.StateNetworkVersion(ctx, tsk)
if err != nil {
@@ -962,7 +1093,7 @@ func (a *StateAPI) StateListMessages(ctx context.Context, match *api.MessageMatc
_, err := a.StateLookupID(ctx, match.To, tsk)
// if the recipient doesn't exist at the start point, we're not gonna find any matches
if xerrors.Is(err, types.ErrActorNotFound) {
if xerrors.Is(err, &api.ErrActorNotFound{}) {
return nil, nil
}
@@ -973,7 +1104,7 @@ func (a *StateAPI) StateListMessages(ctx context.Context, match *api.MessageMatc
_, err := a.StateLookupID(ctx, match.From, tsk)
// if the sender doesn't exist at the start point, we're not gonna find any matches
if xerrors.Is(err, types.ErrActorNotFound) {
if xerrors.Is(err, &api.ErrActorNotFound{}) {
return nil, nil
}
@@ -1399,26 +1530,56 @@ func (a *StateAPI) StateVerifierStatus(ctx context.Context, addr address.Address
// Returns zero if there is no entry in the data cap table for the
// address.
func (m *StateModule) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) {
act, err := m.StateGetActor(ctx, verifreg.Address, tsk)
if err != nil {
return nil, err
}
aid, err := m.StateLookupID(ctx, addr, tsk)
if err != nil {
log.Warnf("lookup failure %v", err)
return nil, err
}
vrs, err := verifreg.Load(m.StateManager.ChainStore().ActorStore(ctx), act)
nv, err := m.StateNetworkVersion(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("failed to load verified registry state: %w", err)
return nil, err
}
verified, dcap, err := vrs.VerifiedClientDataCap(aid)
av, err := actorstypes.VersionForNetwork(nv)
if err != nil {
return nil, xerrors.Errorf("looking up verified client: %w", err)
return nil, err
}
var dcap abi.StoragePower
var verified bool
if av <= 8 {
act, err := m.StateGetActor(ctx, verifreg.Address, tsk)
if err != nil {
return nil, err
}
vrs, err := verifreg.Load(m.StateManager.ChainStore().ActorStore(ctx), act)
if err != nil {
return nil, xerrors.Errorf("failed to load verified registry state: %w", err)
}
verified, dcap, err = vrs.VerifiedClientDataCap(aid)
if err != nil {
return nil, xerrors.Errorf("looking up verified client: %w", err)
}
} else {
act, err := m.StateGetActor(ctx, datacap.Address, tsk)
if err != nil {
return nil, err
}
dcs, err := datacap.Load(m.StateManager.ChainStore().ActorStore(ctx), act)
if err != nil {
return nil, xerrors.Errorf("failed to load datacap actor state: %w", err)
}
verified, dcap, err = dcs.VerifiedClientDataCap(aid)
if err != nil {
return nil, xerrors.Errorf("looking up verified client: %w", err)
}
}
if !verified {
return nil, nil
}
@@ -1636,6 +1797,8 @@ func (a *StateAPI) StateGetNetworkParams(ctx context.Context) (*api.NetworkParam
UpgradeHyperdriveHeight: build.UpgradeHyperdriveHeight,
UpgradeChocolateHeight: build.UpgradeChocolateHeight,
UpgradeOhSnapHeight: build.UpgradeOhSnapHeight,
UpgradeSkyrHeight: build.UpgradeSkyrHeight,
UpgradeSharkHeight: build.UpgradeSharkHeight,
},
}, nil
}