Merge branch 'master' into feat/replace-multistore-carv2
This commit is contained in:
+19
-17
@@ -10,8 +10,8 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
)
|
||||
@@ -21,8 +21,6 @@ var session = uuid.New()
|
||||
type CommonAPI struct {
|
||||
fx.In
|
||||
|
||||
NetAPI
|
||||
|
||||
APISecret *dtypes.APIAlg
|
||||
ShutdownChan dtypes.ShutdownChan
|
||||
}
|
||||
@@ -48,6 +46,24 @@ func (a *CommonAPI) AuthNew(ctx context.Context, perms []auth.Permission) ([]byt
|
||||
return jwt.Sign(&p, (*jwt.HMACSHA)(a.APISecret))
|
||||
}
|
||||
|
||||
func (a *CommonAPI) Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) {
|
||||
return build.OpenRPCDiscoverJSON_Full(), nil
|
||||
}
|
||||
|
||||
func (a *CommonAPI) Version(context.Context) (api.APIVersion, error) {
|
||||
v, err := api.VersionForType(api.RunningNodeType)
|
||||
if err != nil {
|
||||
return api.APIVersion{}, err
|
||||
}
|
||||
|
||||
return api.APIVersion{
|
||||
Version: build.UserVersion(),
|
||||
APIVersion: v,
|
||||
|
||||
BlockDelay: build.BlockDelaySecs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *CommonAPI) LogList(context.Context) ([]string, error) {
|
||||
return logging.GetSubsystems(), nil
|
||||
}
|
||||
@@ -68,17 +84,3 @@ func (a *CommonAPI) Session(ctx context.Context) (uuid.UUID, error) {
|
||||
func (a *CommonAPI) Closing(ctx context.Context) (<-chan struct{}, error) {
|
||||
return make(chan struct{}), nil // relies on jsonrpc closing
|
||||
}
|
||||
|
||||
func (a *CommonAPI) Version(context.Context) (api.APIVersion, error) {
|
||||
v, err := api.VersionForType(api.RunningNodeType)
|
||||
if err != nil {
|
||||
return api.APIVersion{}, err
|
||||
}
|
||||
|
||||
return api.APIVersion{
|
||||
Version: build.UserVersion(),
|
||||
APIVersion: v,
|
||||
|
||||
BlockDelay: build.BlockDelaySecs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||
"github.com/libp2p/go-libp2p-core/metrics"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/libp2p/go-libp2p-core/protocol"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
var (
|
||||
errNotImplemented = errors.New("not implemented")
|
||||
)
|
||||
|
||||
type MockNetAPI struct {
|
||||
fx.In
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetAgentVersion(ctx context.Context, p peer.ID) (string, error) {
|
||||
return "", errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetConnectedness(ctx context.Context, pid peer.ID) (conn network.Connectedness, err error) {
|
||||
err = errNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetPubsubScores(context.Context) ([]api.PubsubScore, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetPeers(context.Context) ([]peer.AddrInfo, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetPeerInfo(_ context.Context, p peer.ID) (*api.ExtendedPeerInfo, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetConnect(ctx context.Context, p peer.AddrInfo) error {
|
||||
return errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetAddrsListen(context.Context) (ai peer.AddrInfo, err error) {
|
||||
err = errNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetDisconnect(ctx context.Context, p peer.ID) error {
|
||||
return errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetFindPeer(ctx context.Context, p peer.ID) (ai peer.AddrInfo, err error) {
|
||||
err = errNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetAutoNatStatus(ctx context.Context) (i api.NatInfo, err error) {
|
||||
err = errNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetBandwidthStats(ctx context.Context) (s metrics.Stats, err error) {
|
||||
err = errNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetBandwidthStatsByPeer(ctx context.Context) (map[string]metrics.Stats, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetBandwidthStatsByProtocol(ctx context.Context) (map[protocol.ID]metrics.Stats, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) ID(context.Context) (p peer.ID, err error) {
|
||||
err = errNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetBlockAdd(ctx context.Context, acl api.NetBlockList) error {
|
||||
return errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetBlockRemove(ctx context.Context, acl api.NetBlockList) error {
|
||||
return errNotImplemented
|
||||
}
|
||||
|
||||
func (a *MockNetAPI) NetBlockList(ctx context.Context) (result api.NetBlockList, err error) {
|
||||
err = errNotImplemented
|
||||
return
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
protocol "github.com/libp2p/go-libp2p-core/protocol"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||
)
|
||||
|
||||
type NetAPI interface {
|
||||
NetConnectedness(ctx context.Context, pid peer.ID) (network.Connectedness, error)
|
||||
NetPubsubScores(context.Context) ([]api.PubsubScore, error)
|
||||
NetPeers(context.Context) ([]peer.AddrInfo, error)
|
||||
NetPeerInfo(_ context.Context, p peer.ID) (*api.ExtendedPeerInfo, error)
|
||||
NetConnect(ctx context.Context, p peer.AddrInfo) error
|
||||
NetAddrsListen(context.Context) (peer.AddrInfo, error)
|
||||
NetDisconnect(ctx context.Context, p peer.ID) error
|
||||
NetFindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error)
|
||||
NetAutoNatStatus(ctx context.Context) (i api.NatInfo, err error)
|
||||
NetAgentVersion(ctx context.Context, p peer.ID) (string, error)
|
||||
NetBandwidthStats(ctx context.Context) (metrics.Stats, error)
|
||||
NetBandwidthStatsByPeer(ctx context.Context) (map[string]metrics.Stats, error)
|
||||
NetBandwidthStatsByProtocol(ctx context.Context) (map[protocol.ID]metrics.Stats, error)
|
||||
Discover(ctx context.Context) (apitypes.OpenRPCDocument, error)
|
||||
ID(context.Context) (peer.ID, error)
|
||||
NetBlockAdd(ctx context.Context, acl api.NetBlockList) error
|
||||
NetBlockRemove(ctx context.Context, acl api.NetBlockList) error
|
||||
NetBlockList(ctx context.Context) (api.NetBlockList, error)
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/node/impl/common"
|
||||
"github.com/filecoin-project/lotus/node/impl/full"
|
||||
"github.com/filecoin-project/lotus/node/impl/market"
|
||||
"github.com/filecoin-project/lotus/node/impl/net"
|
||||
"github.com/filecoin-project/lotus/node/impl/paych"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/node/modules/lp2p"
|
||||
@@ -23,6 +24,7 @@ var log = logging.Logger("node")
|
||||
|
||||
type FullNodeAPI struct {
|
||||
common.CommonAPI
|
||||
net.NetAPI
|
||||
full.ChainAPI
|
||||
client.API
|
||||
full.MpoolAPI
|
||||
|
||||
@@ -83,6 +83,9 @@ type ChainAPI struct {
|
||||
// expose externally. In the future, this will be segregated into two
|
||||
// blockstores.
|
||||
ExposedBlockstore dtypes.ExposedBlockstore
|
||||
|
||||
// BaseBlockstore is the underlying blockstore
|
||||
BaseBlockstore dtypes.BaseBlockstore
|
||||
}
|
||||
|
||||
func (m *ChainModule) ChainNotify(ctx context.Context) (<-chan []*api.HeadChange, error) {
|
||||
@@ -644,3 +647,21 @@ func (a *ChainAPI) ChainExport(ctx context.Context, nroots abi.ChainEpoch, skipo
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (a *ChainAPI) ChainCheckBlockstore(ctx context.Context) error {
|
||||
checker, ok := a.BaseBlockstore.(interface{ Check() error })
|
||||
if !ok {
|
||||
return xerrors.Errorf("underlying blockstore does not support health checks")
|
||||
}
|
||||
|
||||
return checker.Check()
|
||||
}
|
||||
|
||||
func (a *ChainAPI) ChainBlockstoreInfo(ctx context.Context) (map[string]interface{}, error) {
|
||||
info, ok := a.BaseBlockstore.(interface{ Info() map[string]interface{} })
|
||||
if !ok {
|
||||
return nil, xerrors.Errorf("underlying blockstore does not provide info")
|
||||
}
|
||||
|
||||
return info.Info(), nil
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package common
|
||||
package net
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
var cLog = logging.Logger("conngater")
|
||||
|
||||
func (a *Libp2pNetAPI) NetBlockAdd(ctx context.Context, acl api.NetBlockList) error {
|
||||
func (a *NetAPI) NetBlockAdd(ctx context.Context, acl api.NetBlockList) error {
|
||||
for _, p := range acl.Peers {
|
||||
err := a.ConnGater.BlockPeer(p)
|
||||
if err != nil {
|
||||
@@ -89,7 +89,7 @@ func (a *Libp2pNetAPI) NetBlockAdd(ctx context.Context, acl api.NetBlockList) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetBlockRemove(ctx context.Context, acl api.NetBlockList) error {
|
||||
func (a *NetAPI) NetBlockRemove(ctx context.Context, acl api.NetBlockList) error {
|
||||
for _, p := range acl.Peers {
|
||||
err := a.ConnGater.UnblockPeer(p)
|
||||
if err != nil {
|
||||
@@ -124,7 +124,7 @@ func (a *Libp2pNetAPI) NetBlockRemove(ctx context.Context, acl api.NetBlockList)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetBlockList(ctx context.Context) (result api.NetBlockList, err error) {
|
||||
func (a *NetAPI) NetBlockList(ctx context.Context) (result api.NetBlockList, err error) {
|
||||
result.Peers = a.ConnGater.ListBlockedPeers()
|
||||
for _, ip := range a.ConnGater.ListBlockedAddrs() {
|
||||
result.IPAddrs = append(result.IPAddrs, ip.String())
|
||||
@@ -1,29 +1,28 @@
|
||||
package common
|
||||
package net
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/fx"
|
||||
|
||||
"github.com/libp2p/go-libp2p-core/host"
|
||||
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
||||
"github.com/libp2p/go-libp2p-core/metrics"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
protocol "github.com/libp2p/go-libp2p-core/protocol"
|
||||
"github.com/libp2p/go-libp2p-core/protocol"
|
||||
swarm "github.com/libp2p/go-libp2p-swarm"
|
||||
basichost "github.com/libp2p/go-libp2p/p2p/host/basic"
|
||||
"github.com/libp2p/go-libp2p/p2p/net/conngater"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
"go.uber.org/fx"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/node/modules/lp2p"
|
||||
)
|
||||
|
||||
type Libp2pNetAPI struct {
|
||||
type NetAPI struct {
|
||||
fx.In
|
||||
|
||||
RawHost lp2p.RawHost
|
||||
@@ -34,11 +33,15 @@ type Libp2pNetAPI struct {
|
||||
Sk *dtypes.ScoreKeeper
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetConnectedness(ctx context.Context, pid peer.ID) (network.Connectedness, error) {
|
||||
func (a *NetAPI) ID(context.Context) (peer.ID, error) {
|
||||
return a.Host.ID(), nil
|
||||
}
|
||||
|
||||
func (a *NetAPI) NetConnectedness(ctx context.Context, pid peer.ID) (network.Connectedness, error) {
|
||||
return a.Host.Network().Connectedness(pid), nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetPubsubScores(context.Context) ([]api.PubsubScore, error) {
|
||||
func (a *NetAPI) NetPubsubScores(context.Context) ([]api.PubsubScore, error) {
|
||||
scores := a.Sk.Get()
|
||||
out := make([]api.PubsubScore, len(scores))
|
||||
i := 0
|
||||
@@ -54,7 +57,7 @@ func (a *Libp2pNetAPI) NetPubsubScores(context.Context) ([]api.PubsubScore, erro
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetPeers(context.Context) ([]peer.AddrInfo, error) {
|
||||
func (a *NetAPI) NetPeers(context.Context) ([]peer.AddrInfo, error) {
|
||||
conns := a.Host.Network().Conns()
|
||||
out := make([]peer.AddrInfo, len(conns))
|
||||
|
||||
@@ -70,7 +73,7 @@ func (a *Libp2pNetAPI) NetPeers(context.Context) ([]peer.AddrInfo, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetPeerInfo(_ context.Context, p peer.ID) (*api.ExtendedPeerInfo, error) {
|
||||
func (a *NetAPI) NetPeerInfo(_ context.Context, p peer.ID) (*api.ExtendedPeerInfo, error) {
|
||||
info := &api.ExtendedPeerInfo{ID: p}
|
||||
|
||||
agent, err := a.Host.Peerstore().Get(p, "AgentVersion")
|
||||
@@ -101,7 +104,7 @@ func (a *Libp2pNetAPI) NetPeerInfo(_ context.Context, p peer.ID) (*api.ExtendedP
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetConnect(ctx context.Context, p peer.AddrInfo) error {
|
||||
func (a *NetAPI) NetConnect(ctx context.Context, p peer.AddrInfo) error {
|
||||
if swrm, ok := a.Host.Network().(*swarm.Swarm); ok {
|
||||
swrm.Backoff().Clear(p.ID)
|
||||
}
|
||||
@@ -109,22 +112,22 @@ func (a *Libp2pNetAPI) NetConnect(ctx context.Context, p peer.AddrInfo) error {
|
||||
return a.Host.Connect(ctx, p)
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetAddrsListen(context.Context) (peer.AddrInfo, error) {
|
||||
func (a *NetAPI) NetAddrsListen(context.Context) (peer.AddrInfo, error) {
|
||||
return peer.AddrInfo{
|
||||
ID: a.Host.ID(),
|
||||
Addrs: a.Host.Addrs(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetDisconnect(ctx context.Context, p peer.ID) error {
|
||||
func (a *NetAPI) NetDisconnect(ctx context.Context, p peer.ID) error {
|
||||
return a.Host.Network().ClosePeer(p)
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetFindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error) {
|
||||
func (a *NetAPI) NetFindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error) {
|
||||
return a.Router.FindPeer(ctx, p)
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetAutoNatStatus(ctx context.Context) (i api.NatInfo, err error) {
|
||||
func (a *NetAPI) NetAutoNatStatus(ctx context.Context) (i api.NatInfo, err error) {
|
||||
autonat := a.RawHost.(*basichost.BasicHost).GetAutoNat()
|
||||
|
||||
if autonat == nil {
|
||||
@@ -148,7 +151,7 @@ func (a *Libp2pNetAPI) NetAutoNatStatus(ctx context.Context) (i api.NatInfo, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetAgentVersion(ctx context.Context, p peer.ID) (string, error) {
|
||||
func (a *NetAPI) NetAgentVersion(ctx context.Context, p peer.ID) (string, error) {
|
||||
ag, err := a.Host.Peerstore().Get(p, "AgentVersion")
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -161,11 +164,11 @@ func (a *Libp2pNetAPI) NetAgentVersion(ctx context.Context, p peer.ID) (string,
|
||||
return ag.(string), nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetBandwidthStats(ctx context.Context) (metrics.Stats, error) {
|
||||
func (a *NetAPI) NetBandwidthStats(ctx context.Context) (metrics.Stats, error) {
|
||||
return a.Reporter.GetBandwidthTotals(), nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetBandwidthStatsByPeer(ctx context.Context) (map[string]metrics.Stats, error) {
|
||||
func (a *NetAPI) NetBandwidthStatsByPeer(ctx context.Context) (map[string]metrics.Stats, error) {
|
||||
out := make(map[string]metrics.Stats)
|
||||
for p, s := range a.Reporter.GetBandwidthByPeer() {
|
||||
out[p.String()] = s
|
||||
@@ -173,14 +176,8 @@ func (a *Libp2pNetAPI) NetBandwidthStatsByPeer(ctx context.Context) (map[string]
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) NetBandwidthStatsByProtocol(ctx context.Context) (map[protocol.ID]metrics.Stats, error) {
|
||||
func (a *NetAPI) NetBandwidthStatsByProtocol(ctx context.Context) (map[protocol.ID]metrics.Stats, error) {
|
||||
return a.Reporter.GetBandwidthByProtocol(), nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) {
|
||||
return build.OpenRPCDiscoverJSON_Full(), nil
|
||||
}
|
||||
|
||||
func (a *Libp2pNetAPI) ID(context.Context) (peer.ID, error) {
|
||||
return a.Host.ID(), nil
|
||||
}
|
||||
var _ api.Net = &NetAPI{}
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/libp2p/go-libp2p-core/host"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"go.uber.org/fx"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
@@ -38,7 +39,6 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/markets/storageadapter"
|
||||
"github.com/filecoin-project/lotus/miner"
|
||||
"github.com/filecoin-project/lotus/node/impl/common"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/storage"
|
||||
"github.com/filecoin-project/lotus/storage/sectorblocks"
|
||||
@@ -46,7 +46,10 @@ import (
|
||||
)
|
||||
|
||||
type StorageMinerAPI struct {
|
||||
common.CommonAPI
|
||||
fx.In
|
||||
|
||||
api.Common
|
||||
api.Net
|
||||
|
||||
Full api.FullNode
|
||||
LocalStore *stores.Local
|
||||
|
||||
Reference in New Issue
Block a user