Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multi-miner to single LID support #1656

Merged
merged 18 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,27 @@ workflows:
- test:
name: test-all
suite: all
target: "`go list ./... | grep -v boost/itests`"
target: "`go list ./... | grep -v boost/itests | grep -v cmd/booster-http | grep -v cmd/booster-bitswap`"

- test:
name: test-itest-ipni
suite: itest-ipni
target: "./itests/ipni_publish_test.go"

- test:
name: test-itest-multiminer-graphsync
suite: itest-multiminer-graphsync
target: "./itests/multiminer_retrieval_graphsync_test.go"

- test:
name: test-booster-http
suite: booster-http
target: "./cmd/booster-http"

- test:
name: test-booster-bitswap
suite: booster-bitswap
target: "./cmd/booster-bitswap"

- lid-docker-compose

13 changes: 13 additions & 0 deletions build/params_calibnet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build calibnet
// +build calibnet

package build

import (
"github.com/filecoin-project/go-address"
)

func init() {
SetAddressNetwork(address.Testnet)
BuildType = BuildCalibnet
}
13 changes: 13 additions & 0 deletions build/params_mainnet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !calibnet && !debug && !2k
// +build !calibnet,!debug,!2k

package build

import (
"github.com/filecoin-project/go-address"
)

func init() {
SetAddressNetwork(address.Mainnet)
BuildType = BuildMainnet
}
13 changes: 13 additions & 0 deletions build/params_testnets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build debug || 2k
// +build debug 2k

package build

import (
"github.com/filecoin-project/go-address"
)

func init() {
SetAddressNetwork(address.Testnet)
BuildType = BuildDebug
}
31 changes: 30 additions & 1 deletion build/version.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
package build

var CurrentCommit string
var BuildType int

const (
BuildMainnet = 0x1
Build2k = 0x2
BuildDebug = 0x3
BuildCalibnet = 0x4
BuildInteropnet = 0x5
BuildButterflynet = 0x7
)

func BuildTypeString() string {
switch BuildType {
case BuildMainnet:
return "+mainnet"
case Build2k:
return "+2k"
case BuildDebug:
return "+debug"
case BuildCalibnet:
return "+calibnet"
case BuildInteropnet:
return "+interopnet"
case BuildButterflynet:
return "+butterflynet"
default:
return "+huh?"
}
}

const BuildVersion = "2.0.0-rc1"

func UserVersion() string {
return BuildVersion + CurrentCommit
return BuildVersion + BuildTypeString() + CurrentCommit
}
1 change: 1 addition & 0 deletions cmd/boostd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func before(cctx *cli.Context) error {
_ = logging.SetLogLevel("piecedoc", "INFO")
_ = logging.SetLogLevel("piecedirectory", "INFO")
_ = logging.SetLogLevel("sectorstatemgr", "INFO")
_ = logging.SetLogLevel("migrations", "INFO")

if cliutil.IsVeryVerbose {
_ = logging.SetLogLevel("boostd", "DEBUG")
Expand Down
5 changes: 5 additions & 0 deletions cmd/boostd/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ func action(cctx *cli.Context) error {
}
defer ncloser()

err = lib.CheckFullNodeApiVersion(ctx, fullnodeApi)
if err != nil {
return err
}

// Connect to the storage API and create a sector accessor
storageApiInfo := cctx.String("api-storage")

Expand Down
21 changes: 13 additions & 8 deletions cmd/booster-bitswap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ipld/go-ipld-prime"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/traversal"
"github.com/libp2p/go-libp2p/core/host"
mh "github.com/multiformats/go-multihash"

"github.com/filecoin-project/boost/cmd/booster-bitswap/bitswap"
Expand Down Expand Up @@ -90,14 +91,7 @@ var fetchCmd = &cli.Command{
return err
}

host, err := libp2p.New(
libp2p.Transport(tcp.NewTCPTransport),
libp2p.Transport(quic.NewTransport),
libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport),
libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport),
libp2p.Identity(privKey),
libp2p.ResourceManager(&network.NullResourceManager{}),
)
host, err := createClientHost(privKey)
if err != nil {
return err
}
Expand Down Expand Up @@ -169,6 +163,17 @@ var fetchCmd = &cli.Command{
},
}

func createClientHost(privKey crypto.PrivKey) (host.Host, error) {
return libp2p.New(
libp2p.Transport(tcp.NewTCPTransport),
libp2p.Transport(quic.NewTransport),
libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport),
libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport),
libp2p.Identity(privKey),
libp2p.ResourceManager(&network.NullResourceManager{}),
)
}

func getBlocks(ctx context.Context, bsClient *client.Client, c cid.Cid, throttle chan struct{}) (uint64, uint64, error) {
var size uint64
var links []cid.Cid
Expand Down
31 changes: 16 additions & 15 deletions cmd/booster-bitswap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ var FlagRepo = &cli.StringFlag{
EnvVars: []string{"BOOSTER_BITSWAP_REPO"},
}

var app = &cli.App{
Name: "booster-bitswap",
Usage: "Bitswap endpoint for retrieval from Filecoin",
EnableBashCompletion: true,
Version: build.UserVersion(),
Flags: []cli.Flag{
cliutil.FlagVeryVerbose,
FlagRepo,
},
Commands: []*cli.Command{
initCmd,
runCmd,
fetchCmd,
},
}

func main() {
app := &cli.App{
Name: "booster-bitswap",
Usage: "Bitswap endpoint for retrieval from Filecoin",
EnableBashCompletion: true,
Version: build.UserVersion(),
Flags: []cli.Flag{
cliutil.FlagVeryVerbose,
FlagRepo,
},
Commands: []*cli.Command{
initCmd,
runCmd,
fetchCmd,
},
}
app.Setup()

if err := app.Run(os.Args); err != nil {
Expand Down
134 changes: 134 additions & 0 deletions cmd/booster-bitswap/multiminer_retrieval_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package main

import (
"context"
"crypto/rand"
"fmt"
"github.com/filecoin-project/boost/cmd/booster-bitswap/bitswap"
"github.com/filecoin-project/boost/itests/shared"
carv2 "github.com/ipld/go-car/v2"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
"path"
"sort"
"testing"
"time"
)

func TestMultiMinerBitswapRetrieval(t *testing.T) {
shared.RunMultiminerRetrievalTest(t, func(ctx context.Context, t *testing.T, rt *shared.RetrievalTest) {
miner1ApiInfo, err := rt.BoostAndMiner1.LotusMinerApiInfo()
require.NoError(t, err)

miner2ApiInfo, err := rt.BoostAndMiner2.LotusMinerApiInfo()
require.NoError(t, err)

fullNode2ApiInfo, err := rt.BoostAndMiner2.LotusFullNodeApiInfo()
require.NoError(t, err)

repoDir := t.TempDir()
peerID, _, err := configureRepo(repoDir, true)
require.NoError(t, err)

runCtx, cancelRun := context.WithCancel(ctx)
defer cancelRun()

go func() {
// Configure booster-bitswap to
// - Get piece location information from the shared LID instance
// - Get the piece data from either miner1 or miner2 (depending on the location info)
apiInfo := []string{miner1ApiInfo, miner2ApiInfo}
_ = runBoosterBitswap(runCtx, repoDir, apiInfo, fullNode2ApiInfo, "ws://localhost:8042")
}()

maddr, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/8888")
require.NoError(t, err)

privKey, _, err := crypto.GenerateECDSAKeyPair(rand.Reader)
require.NoError(t, err)

clientHost, err := createClientHost(privKey)
require.NoError(t, err)

t.Logf("waiting for server to come up")
start := time.Now()
require.Eventually(t, func() bool {
err := connectToHost(ctx, clientHost, maddr, peerID)
if err != nil {
t.Logf("connecting to host: %s", err)
return false
}
return true
}, 30*time.Second, time.Second)
t.Logf("booster-bitswap is up after %s", time.Since(start))

outPath := path.Join(t.TempDir(), "out.dat")
fetchAddr := maddr.String() + "/p2p/" + peerID.String()
err = runBoosterBitswapFetch(ctx, fetchAddr, rt.RootCid.String(), outPath)
require.NoError(t, err)

t.Logf("retrieval is done, compare root cid %s to downloaded CAR root cid", rt.RootCid)
r, err := carv2.OpenReader(outPath)
require.NoError(t, err)

roots, err := r.Roots()
require.NoError(t, err)
require.Len(t, roots, 1)
require.Equal(t, rt.RootCid, roots[0])

t.Logf("file retrieved successfully")
})
}

func connectToHost(ctx context.Context, clientHost host.Host, maddr multiaddr.Multiaddr, pid peer.ID) error {
// Connect to host
err := clientHost.Connect(ctx, peer.AddrInfo{
ID: pid,
Addrs: []multiaddr.Multiaddr{maddr},
})
if err != nil {
return err
}

// Check host's libp2p protocols
protos, err := clientHost.Peerstore().GetProtocols(pid)
if err != nil {
return fmt.Errorf("getting protocols from peer store for %s: %w", pid, err)
}
sort.Slice(protos, func(i, j int) bool {
return protos[i] < protos[j]
})
fmt.Println("host libp2p protocols", "protocols", protos)
p, err := clientHost.Peerstore().FirstSupportedProtocol(pid, bitswap.Protocols...)
if err != nil {
return fmt.Errorf("getting first supported protocol from peer store for %s: %w", pid, err)
}
if p == "" {
return fmt.Errorf("host %s does not support any know bitswap protocols: %s", pid, bitswap.ProtocolStrings)
}
return nil
}

func runBoosterBitswap(ctx context.Context, repo string, minerApiInfo []string, fullNodeApiInfo string, lidApiInfo string) error {
app.Setup()

args := []string{"booster-bitswap",
"--repo=" + repo,
"run",
"--api-fullnode=" + fullNodeApiInfo,
"--api-lid=" + lidApiInfo,
"--api-version-check=false",
}
for _, apiInfo := range minerApiInfo {
args = append(args, "--api-storage="+apiInfo)
}
return app.RunContext(ctx, args)
}

func runBoosterBitswapFetch(ctx context.Context, multiaddr string, rootCid string, outputPath string) error {
args := []string{"booster-bitswap", "fetch", multiaddr, rootCid, outputPath}
return app.RunContext(ctx, args)
}
Loading