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

Move to not using multiaddr for config values #791

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion api/client/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type Config struct {
Devnet bool
IpfsAPIAddr ma.Multiaddr

LotusAddress ma.Multiaddr
LotusAddress string
LotusAuthToken string
LotusMasterAddr string
LotusConnectionRetries int
Expand Down
7 changes: 2 additions & 5 deletions cmd/powd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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)")
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-localnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 10 additions & 12 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
version: '3.7'
version: "3.7"

volumes:
powergate-powd:
powergate-ipfs:
powergate-lotus:

services:

powergate:
ports:
- 8889:8889
Expand All @@ -19,15 +18,15 @@ 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
restart: unless-stopped
volumes:
- powergate-powd:/root/powergate
- powergate-lotus:/root/lotus

lotus:
image: textile/lotus:${LOTUS_IMAGE_TAG}
volumes:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -89,4 +88,3 @@ services:
env_file:
- ./grafana/config.monitoring
restart: unless-stopped

2 changes: 1 addition & 1 deletion docs/manual_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 2 additions & 7 deletions ffs/minerselector/sr2/sr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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())
Expand Down
4 changes: 1 addition & 3 deletions index/miner/module/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions lotus/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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},
}
Expand Down
61 changes: 0 additions & 61 deletions tests/auth.go

This file was deleted.

3 changes: 1 addition & 2 deletions tests/ldevnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down