Skip to content

Commit

Permalink
join: Do not publish the network when joining
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Luzzardi <[email protected]>
  • Loading branch information
aluzzardi committed Dec 6, 2018
1 parent 11f09a3 commit bebb57d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
8 changes: 5 additions & 3 deletions cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ var joinCmd = &cobra.Command{

ui.Info("Joining network %s", chainID)
cfg := &config.Config{
RootDir: path.Join(networksDir, filepath.Base(chainID)),
RootDir: path.Join(networksDir, filepath.Base(chainID)),
PublishNetwork: false,
ChainID: chainID,
}
cfg.Ports, err = config.AllocatePorts()
if err != nil {
Expand All @@ -45,9 +47,9 @@ var joinCmd = &cobra.Command{
}
defer d.Stop()

p, genesis, err := d.Join(ctx, chainID, cfg.ManifestPath())
p, genesis, err := d.Join(ctx, cfg.ChainID, cfg.ManifestPath())
if err != nil {
ui.Fatal("Unable to retrieve network information for %q: %v", chainID, err)
ui.Fatal("Unable to retrieve network information for %q: %v", cfg.ChainID, err)
}

n := node.New(cfg, d)
Expand Down
3 changes: 2 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ var startCmd = &cobra.Command{

ctx := context.Background()
cfg := &config.Config{
RootDir: rootDir,
RootDir: rootDir,
PublishNetwork: true,
}
cfg.Ports, err = config.AllocatePorts()
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (

// Config represents the node configuration.
type Config struct {
RootDir string
Ports *PortMapper
RootDir string
Ports *PortMapper
ChainID string
PublishNetwork bool
}

// StateDir returns the state directory within the project.
Expand Down
31 changes: 18 additions & 13 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,22 @@ func (n *Node) Start(ctx context.Context, p *project.Project, genesis []byte) er
return err
}

chainID := n.config.ChainID

// Create a network.
ui.Info("Publishing network...")
chainID, err := n.createNetwork(n.parentCtx, p)
if err != nil {
return err
if n.config.PublishNetwork {
ui.Info("Publishing network...")
var err error
chainID, err = n.createNetwork(n.parentCtx, p)
if err != nil {
return err
}
ui.Success("Success! Published network %s as %s\n\nOther nodes can now join this network by running\n %s\n",
ui.Emphasize(p.Name),
ui.Emphasize(chainID),
ui.Emphasize(fmt.Sprintf("chainkit join %s", chainID)),
)
}
ui.Success("Success! Published network %s as %s\n\nOther nodes can now join this network by running\n %s\n",
ui.Emphasize(p.Name),
ui.Emphasize(chainID),
ui.Emphasize(fmt.Sprintf("chainkit join %s", chainID)),
)

ui.Info("Starting node...")
if err := n.server.start(n.parentCtx, p); err != nil {
Expand All @@ -78,10 +83,10 @@ func (n *Node) Start(ctx context.Context, p *project.Project, genesis []byte) er
}

ui.Success("Success! The node is now up and running.")
ui.Success("Node ID: %s", ui.Emphasize(peer.NodeID))
ui.Success("Logs can be found in: %s", ui.Emphasize(n.config.LogFile()))
ui.Success("Application is live at: %s", ui.Emphasize(fmt.Sprintf("http://localhost:%d/", n.config.Ports.TendermintRPC)))
ui.Success("Cosmos Explorer is live at: %s", ui.Emphasize(fmt.Sprintf("http://localhost:%d/?rpc_port=%d", n.config.Ports.Explorer, n.config.Ports.TendermintRPC)))
ui.Success(" Node ID : %s", ui.Emphasize(peer.NodeID))
ui.Success(" Logs can be found in : %s", ui.Emphasize(n.config.LogFile()))
ui.Success(" Application is live at : %s", ui.Emphasize(fmt.Sprintf("http://localhost:%d/", n.config.Ports.TendermintRPC)))
ui.Success(" Cosmos Explorer is live at: %s", ui.Emphasize(fmt.Sprintf("http://localhost:%d/?rpc_port=%d", n.config.Ports.Explorer, n.config.Ports.TendermintRPC)))

g, gctx := errgroup.WithContext(n.parentCtx)

Expand Down

0 comments on commit bebb57d

Please sign in to comment.