Skip to content

Commit

Permalink
node UX improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
  • Loading branch information
aluzzardi committed Dec 6, 2018
1 parent f30e1c0 commit 11f09a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
10 changes: 4 additions & 6 deletions discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func (s *Server) Stop() error {

// Start starts the discovery server
func (s *Server) Start(ctx context.Context) error {
ui.Info("Initializing node...")

daemonLocked, err := fsrepo.LockedByOtherProcess(s.root)
if err != nil {
return err
Expand Down Expand Up @@ -153,9 +155,7 @@ func (s *Server) dhtConnect(ctx context.Context) {
ui.Error("Connection with bootstrap node %v failed: %v", *peerinfo, err)
continue
}
ui.Verbose("Connection established with bootstrap node: %v", *peerinfo)
}
ui.Info("connect done")
}

// Publish publishes chain information. Returns the chain ID.
Expand Down Expand Up @@ -284,12 +284,10 @@ func (s *Server) Announce(ctx context.Context, chainID string, peer *PeerInfo) e
return nil
}

// SearchPeers looks for peers in the network
func (s *Server) SearchPeers(ctx context.Context, chainID string) (<-chan *PeerInfo, error) {
// Peers looks for peers in the network
func (s *Server) Peers(ctx context.Context, chainID string) (<-chan *PeerInfo, error) {
// Wait for the DHT to be connected before searching.
ui.Info("waiting for connection")
<-s.connectedCh
ui.Info("wait done")

id, err := cid.Decode(filepath.Base(chainID))
if err != nil {
Expand Down
30 changes: 18 additions & 12 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ func (n *Node) Start(ctx context.Context, p *project.Project, genesis []byte) er
}

// Create a network.
ui.Info("Publishing network...")
chainID, err := n.createNetwork(n.parentCtx, p)
if err != nil {
return err
}
ui.Success("Network is live at: %v", 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 {
return err
}
Expand All @@ -71,6 +77,12 @@ func (n *Node) Start(ctx context.Context, p *project.Project, genesis []byte) er
return err
}

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)))

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

// Monitor the server
Expand All @@ -93,11 +105,6 @@ func (n *Node) Start(ctx context.Context, p *project.Project, genesis []byte) er
return n.discoverPeers(gctx, chainID)
})

ui.Success("Node is up and running: %s", peer.NodeID)
ui.Info(" Logs can be found in: %s", 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)))

return g.Wait()
}

Expand Down Expand Up @@ -149,8 +156,6 @@ func (n *Node) createNetwork(ctx context.Context, p *project.Project) (string, e
}
f.Close()

ui.Verbose("Image saved at %s", f.Name())

chainID, err := n.discovery.Publish(ctx, n.config.ManifestPath(), n.config.GenesisPath(), f.Name())
if err != nil {
return "", errors.Wrap(err, "unable to create network")
Expand All @@ -160,6 +165,7 @@ func (n *Node) createNetwork(ctx context.Context, p *project.Project) (string, e
}

func (n *Node) announce(ctx context.Context, chainID string, peer *discovery.PeerInfo) error {
ui.Info("Registering this node on the network...")
for {
select {
case <-ctx.Done():
Expand All @@ -169,7 +175,7 @@ func (n *Node) announce(ctx context.Context, chainID string, peer *discovery.Pee

err := n.discovery.Announce(ctx, chainID, peer)
if err == nil {
ui.Success("Node successfully announced")
ui.Info("Node successfully registered")
return nil
}
ui.Error("Failed to announce: %v", err)
Expand All @@ -182,7 +188,7 @@ func (n *Node) announce(ctx context.Context, chainID string, peer *discovery.Pee
}

func (n *Node) discoverPeers(ctx context.Context, chainID string) error {
ui.Info("Discovering peer nodes...")
ui.Info("Discovering network nodes...")

seenNodes := make(map[string]struct{})

Expand All @@ -194,7 +200,7 @@ func (n *Node) discoverPeers(ctx context.Context, chainID string) error {
default:
}

peerCh, err := n.discovery.SearchPeers(ctx, chainID)
peerCh, err := n.discovery.Peers(ctx, chainID)
if err != nil {
return err
}
Expand All @@ -203,7 +209,7 @@ func (n *Node) discoverPeers(ctx context.Context, chainID string) error {
if _, ok := seenNodes[peer.NodeID]; ok {
continue
}
ui.Info("Discovered node %q", peer.NodeID)
ui.Info("Discovered node %s", ui.Emphasize(peer.NodeID))
if err := n.server.dialSeeds(ctx, peer); err != nil {
ui.Error("Failed to dial peer: %v", err)
continue
Expand Down

0 comments on commit 11f09a3

Please sign in to comment.