diff --git a/README.md b/README.md index 9a98a9316..4ae40abee 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ Usage of powd: --grpchostaddr string gRPC host listening address. (default "/ip4/0.0.0.0/tcp/5002") --grpcwebproxyaddr string gRPC webproxy listening address. (default "0.0.0.0:6002") --ipfsapiaddr string IPFS API endpoint multiaddress. (Optional, only needed if FFS is used) (default "/ip4/127.0.0.1/tcp/5001") - --lotushost string Lotus client API endpoint multiaddress. (default "/ip4/127.0.0.1/tcp/1234") + --lotushost string Lotus client API endpoint address. (default "127.0.0.1:1234") --lotusmasteraddr string Existing wallet address in Lotus to be used as source of funding for new FFS instances. (Optional) --lotustoken string Lotus API authorization token. This flag or --lotustoken file are mandatory. --lotustokenfile string Path of a file that contains the Lotus API authorization token. diff --git a/api/client/utils_test.go b/api/client/utils_test.go index d3a502e9d..bb6e3808a 100644 --- a/api/client/utils_test.go +++ b/api/client/utils_test.go @@ -32,7 +32,7 @@ func defaultServerConfig(t *testing.T) server.Config { ipfsAddr := util.MustParseAddr(ipfsAddrStr) devnet := tests.LaunchDevnetDocker(t, 1, 300, ipfsAddrStr, false) - devnetAddr := util.MustParseAddr("/ip4/127.0.0.1/tcp/" + devnet.GetPort("7777/tcp")) + devnetAddr := "127.0.0.1:" + devnet.GetPort("7777/tcp") grpcMaddr := util.MustParseAddr(grpcHostAddress) conf := server.Config{ diff --git a/api/server/server.go b/api/server/server.go index a9e0cb078..3f7d0e398 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -109,7 +109,7 @@ type Config struct { Devnet bool IpfsAPIAddr ma.Multiaddr - LotusAddress ma.Multiaddr + LotusAddress string LotusAuthToken string LotusMasterAddr string LotusConnectionRetries int diff --git a/cmd/powd/main.go b/cmd/powd/main.go index cb7fdb854..031b27649 100644 --- a/cmd/powd/main.go +++ b/cmd/powd/main.go @@ -106,10 +106,7 @@ func configFromFlags() (server.Config, error) { return server.Config{}, fmt.Errorf("parsing grpchostaddr: %s", err) } - lotusHost, err := ma.NewMultiaddr(config.GetString("lotushost")) - if err != nil { - return server.Config{}, fmt.Errorf("parsing lotus api multiaddr: %s", err) - } + lotusHost := config.GetString("lotushost") walletInitialFunds := *big.NewInt(config.GetInt64("walletinitialfund")) ipfsAPIAddr := util.MustParseAddr(config.GetString("ipfsapiaddr")) @@ -365,7 +362,7 @@ func setupFlags() error { pflag.String("grpcwebproxyaddr", "0.0.0.0:6002", "gRPC webproxy listening address.") pflag.String("indexrawjsonhostaddr", "0.0.0.0:8889", "Indexes raw json output listening address") - pflag.String("lotushost", "/ip4/127.0.0.1/tcp/1234", "Lotus client API endpoint multiaddress.") + pflag.String("lotushost", "127.0.0.1:1234", "Lotus client API endpoint address.") pflag.String("lotustoken", "", "Lotus API authorization token. This flag or --lotustoken file are mandatory.") pflag.String("lotustokenfile", "", "Path of a file that contains the Lotus API authorization token.") pflag.String("lotusmasteraddr", "", "Existing wallet address in Lotus to be used as source of funding for new FFS instances. (Optional)") diff --git a/docker/docker-compose-localnet.yaml b/docker/docker-compose-localnet.yaml index 9145fd90c..7e2e161ea 100644 --- a/docker/docker-compose-localnet.yaml +++ b/docker/docker-compose-localnet.yaml @@ -14,7 +14,7 @@ services: - lotus environment: - POWD_DEVNET=true - - POWD_LOTUSHOST=/dns4/lotus/tcp/7777 + - POWD_LOTUSHOST=lotus:7777 - POWD_IPFSAPIADDR=/dns4/ipfs/tcp/5001 restart: unless-stopped diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 25a3d985f..72af574af 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -1,4 +1,4 @@ -version: '3.7' +version: "3.7" volumes: powergate-powd: @@ -6,7 +6,6 @@ volumes: powergate-lotus: services: - powergate: ports: - 8889:8889 @@ -19,7 +18,7 @@ services: - ipfs - lotus environment: - - POWD_LOTUSHOST=/dns4/lotus/tcp/1234 + - POWD_LOTUSHOST=lotus:1234 - POWD_IPFSAPIADDR=/dns4/ipfs/tcp/5001 - POWD_LOTUSTOKENFILE=/root/lotus/.lotus/token - POWD_REPOPATH=/root/powergate/.powergate @@ -27,7 +26,7 @@ services: volumes: - powergate-powd:/root/powergate - powergate-lotus:/root/lotus - + lotus: image: textile/lotus:${LOTUS_IMAGE_TAG} volumes: @@ -47,17 +46,17 @@ services: - 5001:5001 volumes: - powergate-ipfs:/data/ipfs - restart: unless-stopped - + restart: unless-stopped + prometheus: image: prom/prometheus:v2.1.0 volumes: - ./prometheus/:/etc/prometheus/ command: - - '--config.file=/etc/prometheus/prometheus.yml' - - '--storage.tsdb.path=/prometheus' - - '--web.console.libraries=/usr/share/prometheus/console_libraries' - - '--web.console.templates=/usr/share/prometheus/consoles' + - "--config.file=/etc/prometheus/prometheus.yml" + - "--storage.tsdb.path=/prometheus" + - "--web.console.libraries=/usr/share/prometheus/console_libraries" + - "--web.console.templates=/usr/share/prometheus/consoles" ports: - 9090:9090 depends_on: @@ -72,7 +71,7 @@ services: - /sys:/sys:ro - /var/lib/docker/:/var/lib/docker:ro command: - - '--port=8082' + - "--port=8082" ports: - 8082:8082 restart: unless-stopped @@ -89,4 +88,3 @@ services: env_file: - ./grafana/config.monitoring restart: unless-stopped - diff --git a/docs/manual_installation.md b/docs/manual_installation.md index aacad027d..6fa1fea82 100644 --- a/docs/manual_installation.md +++ b/docs/manual_installation.md @@ -117,7 +117,7 @@ You can download `powd` binaries from the [GitHub Releases section](https://gith In this section, we outline the basic configuration needed for Powergate. Recall you can execute `powd -h` to look for default values and format of configuration values. -The first configuration step is to provide information to connect to the Lotus API correctly. For this, you should provide `POWD_LOTUSHOST`/`--lotushost`, which should be multiaddress that indicates where is the Lotus API JSON-RPC endpoint mentioned in the previous section. +The first configuration step is to provide information to connect to the Lotus API correctly. For this, you should provide `POWD_LOTUSHOST`/`--lotushost`, which should be the `host:port` address that indicates where is the Lotus API JSON-RPC endpoint mentioned in the previous section. Additionally, you should indicate which is the _auth token_ of the API. The _auth token_ lives in `~/.lotus/token` in your Lotus host. Powergate allows this parameter to be configured in two ways: the path of this token file, or providing the token value directly. For the former, you should set `POWD_LOTUSTOKENFILE`/`--lotustokenfile`, and for the latter `POWD_LOTUSTOKEN`/`--lotustoken`. At least one of each env/flags should be provided. If that isn't the case `powd` will fail to start indicating that as an error. diff --git a/ffs/minerselector/sr2/sr2_test.go b/ffs/minerselector/sr2/sr2_test.go index 83f0fbe86..7ded14a3d 100644 --- a/ffs/minerselector/sr2/sr2_test.go +++ b/ffs/minerselector/sr2/sr2_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/filecoin-project/go-address" - "github.com/multiformats/go-multiaddr" "github.com/stretchr/testify/require" "github.com/textileio/powergate/v2/ffs" "github.com/textileio/powergate/v2/lotus" @@ -16,11 +15,9 @@ import ( // synced Lotus node. func TestMS(t *testing.T) { t.SkipNow() - lotusHost, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/5555") - require.NoError(t, err) lotusToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.4KpuySIvV4n6kBEXQOle-hi1Ec3lyUmRYCknz4NQyLM" - cb, err := lotus.NewBuilder(lotusHost, lotusToken, 1) + cb, err := lotus.NewBuilder("127.0.0.1:5555", lotusToken, 1) require.NoError(t, err) url := "https://raw.githubusercontent.com/filecoin-project/slingshot/master/miners.json" @@ -35,11 +32,9 @@ func TestMS(t *testing.T) { func TestCustom(t *testing.T) { t.SkipNow() - lotusHost, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/5555") - require.NoError(t, err) lotusToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.4KpuySIvV4n6kBEXQOle-hi1Ec3lyUmRYCknz4NQyLM" - cb, err := lotus.NewBuilder(lotusHost, lotusToken, 1) + cb, err := lotus.NewBuilder("127.0.0.1:5555", lotusToken, 1) require.NoError(t, err) c, cls, err := cb(context.Background()) diff --git a/index/miner/module/miner_test.go b/index/miner/module/miner_test.go index cf089289b..9003e165a 100644 --- a/index/miner/module/miner_test.go +++ b/index/miner/module/miner_test.go @@ -62,11 +62,9 @@ func TestIntegration(t *testing.T) { metaRefreshInterval = time.Hour minersRefreshInterval = time.Second - lotusHost, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/5555") - require.NoError(t, err) lotusToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.4KpuySIvV4n6kBEXQOle-hi1Ec3lyUmRYCknz4NQyLM" - cb, err := lotus.NewBuilder(lotusHost, lotusToken, 1) + cb, err := lotus.NewBuilder("127.0.0.1:5555", lotusToken, 1) require.NoError(t, err) mi, err := New(tests.NewTxMapDatastore(), cb, &p2pHostMock{}, &lrMock{}, false, false) diff --git a/lotus/client.go b/lotus/client.go index 916d38e0f..13fd9b24d 100644 --- a/lotus/client.go +++ b/lotus/client.go @@ -9,9 +9,6 @@ import ( "github.com/filecoin-project/go-jsonrpc" "github.com/filecoin-project/lotus/api/apistruct" logging "github.com/ipfs/go-log/v2" - ma "github.com/multiformats/go-multiaddr" - - "github.com/textileio/powergate/v2/util" ) var ( @@ -22,11 +19,7 @@ var ( type ClientBuilder func(ctx context.Context) (*apistruct.FullNodeStruct, func(), error) // NewBuilder creates a new ClientBuilder. -func NewBuilder(maddr ma.Multiaddr, authToken string, connRetries int) (ClientBuilder, error) { - addr, err := util.TCPAddrFromMultiAddr(maddr) - if err != nil { - return nil, err - } +func NewBuilder(addr string, authToken string, connRetries int) (ClientBuilder, error) { headers := http.Header{ "Authorization": []string{"Bearer " + authToken}, } diff --git a/tests/auth.go b/tests/auth.go deleted file mode 100644 index 6e850b129..000000000 --- a/tests/auth.go +++ /dev/null @@ -1,61 +0,0 @@ -package tests - -import ( - "fmt" - "os" - "os/exec" - "path/filepath" - "testing" - - ma "github.com/multiformats/go-multiaddr" - "github.com/stretchr/testify/require" -) - -const ( - lotusHost = "127.0.0.1" - lotusPort = 1234 -) - -// GetLotusToken returns the lotus token from a Lotus repo path. -func GetLotusToken(lotusFolderPath string) (string, error) { - tokenFullPath := filepath.Join(lotusFolderPath, "token") - if _, err := os.Stat(tokenFullPath); err != nil { - if os.IsNotExist(err) { - return createAdminToken() - } - return "", err - } - cmd := exec.Command("cat", tokenFullPath) - out, err := cmd.Output() - if err != nil { - return "", err - } - return string(out), nil -} - -func createAdminToken() (string, error) { - cmd := exec.Command("lotus", "auth", "create-token", "--perm", "admin") - out, err := cmd.Output() - if err != nil { - return "", err - } - return string(out), err -} - -// ClientConfigMA returns the prepared multiaddress and Lotus token, -// to connect to a Lotus node. -func ClientConfigMA(t *testing.T) (ma.Multiaddr, string) { - addr := fmt.Sprintf("/ip4/%v/tcp/%v", lotusHost, lotusPort) - multi, err := ma.NewMultiaddr(addr) - require.NoError(t, err) - authToken, ok := os.LookupEnv("TEXTILE_LOTUS_TOKEN") - if !ok { - home, err := os.UserHomeDir() - require.NoError(t, err) - path := filepath.Join(home, ".lotus") - authToken, err = GetLotusToken(path) - require.NoError(t, err) - } - - return multi, authToken -} diff --git a/tests/ldevnet.go b/tests/ldevnet.go index aa7c4d285..7873e66b2 100644 --- a/tests/ldevnet.go +++ b/tests/ldevnet.go @@ -13,7 +13,6 @@ import ( "github.com/ory/dockertest/v3/docker" "github.com/stretchr/testify/require" "github.com/textileio/powergate/v2/lotus" - "github.com/textileio/powergate/v2/util" ) // TestingTWithCleanup is an augmented require.TestingT with a Cleanup function. @@ -75,7 +74,7 @@ func LaunchDevnetDocker(t TestingTWithCleanup, numMiners, speed int, ipfsMaddr s // CreateLocalDevnetWithIPFS creates a local devnet connected to an IPFS node. func CreateLocalDevnetWithIPFS(t TestingTWithCleanup, numMiners, speed int, ipfsMaddr string, mountVolumes bool) (lotus.ClientBuilder, address.Address, []address.Address) { lotusDevnet := LaunchDevnetDocker(t, numMiners, speed, ipfsMaddr, mountVolumes) - cb, err := lotus.NewBuilder(util.MustParseAddr("/ip4/127.0.0.1/tcp/"+lotusDevnet.GetPort("7777/tcp")), "", 1) + cb, err := lotus.NewBuilder("127.0.0.1:"+lotusDevnet.GetPort("7777/tcp"), "", 1) require.NoError(t, err) ctx, cls := context.WithTimeout(context.Background(), time.Second*10) defer cls()