@@ -3,6 +3,7 @@ package node
33import  (
44	"context" 
55	"fmt" 
6+ 	"sync" 
67
78	"github.com/gin-gonic/gin" 
89	"github.com/sentinel-official/sentinel-go-sdk/libs/cmux" 
@@ -72,7 +73,12 @@ func (n *Node) Register(ctx context.Context) error {
7273		return  nil 
7374	}
7475
75- 	log .Info ("Registering node..." )
76+ 	log .Info ("Registering node" ,
77+ 		"addr" , n .NodeAddr (),
78+ 		"gigabyte_price" , n .GigabytePrices (),
79+ 		"hourly_price" , n .HourlyPrices (),
80+ 		"remote_addrs" , n .APIAddrs (),
81+ 	)
7682
7783	// Prepare a message to register the node. 
7884	msg  :=  v3 .NewMsgRegisterNodeRequest (
@@ -92,7 +98,12 @@ func (n *Node) Register(ctx context.Context) error {
9298
9399// UpdateDetails updates the node's pricing and address details on the network. 
94100func  (n  * Node ) UpdateDetails (ctx  context.Context ) error  {
95- 	log .Info ("Updating node details..." )
101+ 	log .Info ("Updating node details" ,
102+ 		"addr" , n .NodeAddr (),
103+ 		"gigabyte_prices" , n .GigabytePrices (),
104+ 		"hourly_prices" , n .HourlyPrices (),
105+ 		"remote_addrs" , n .APIAddrs (),
106+ 	)
96107
97108	// Prepare a message to update the node's details. 
98109	msg  :=  v3 .NewMsgUpdateNodeDetailsRequest (
@@ -125,8 +136,16 @@ func (n *Node) Start(ctx context.Context) error {
125136		return  fmt .Errorf ("failed to update node details: %w" , err )
126137	}
127138
139+ 	var  start  sync.WaitGroup 
140+ 	start .Add (3 )
141+ 
128142	// Launch the service stack as a background goroutine. 
129143	n .eg .Go (func () error  {
144+ 		log .Info ("Starting service routine" , "type" , n .Service ().Type ())
145+ 		start .Done ()
146+ 
147+ 		defer  log .Info ("Exiting service routine" )
148+ 
130149		if  err  :=  n .Service ().Up (ctx ); err  !=  nil  {
131150			return  fmt .Errorf ("failed to run service up task: %w" , err )
132151		}
@@ -142,6 +161,11 @@ func (n *Node) Start(ctx context.Context) error {
142161
143162	// Launch the cron-based job scheduler in the background. 
144163	n .eg .Go (func () error  {
164+ 		log .Info ("Starting scheduler routine" )
165+ 		start .Done ()
166+ 
167+ 		defer  log .Info ("Exiting scheduler routine" )
168+ 
145169		if  err  :=  n .Scheduler ().Start (ctx ); err  !=  nil  {
146170			return  fmt .Errorf ("failed to start scheduler: %w" , err )
147171		}
@@ -154,13 +178,21 @@ func (n *Node) Start(ctx context.Context) error {
154178
155179	// Launch the API server using the configured TLS certificates and router. 
156180	n .eg .Go (func () error  {
181+ 		log .Info ("Starting API server routine" , "listen" , n .APIListenAddr ())
182+ 		start .Done ()
183+ 
184+ 		defer  log .Info ("Exiting API server routine" )
185+ 
157186		if  err  :=  cmux .ListenAndServeTLS (ctx , n .APIListenAddr (), n .TLSCertFile (), n .TLSKeyFile (), n .Router ()); err  !=  nil  {
158187			return  fmt .Errorf ("failed to listen and serve tls: %w" , err )
159188		}
160189
161190		return  nil 
162191	})
163192
193+ 	// Wait until all routines started 
194+ 	start .Wait ()
195+ 
164196	log .Info ("Node started successfully" )
165197	return  nil 
166198}
@@ -195,6 +227,5 @@ func (n *Node) Stop() error {
195227		return  fmt .Errorf ("failed to stop scheduler: %w" , err )
196228	}
197229
198- 	log .Info ("Node stopped successfully" )
199230	return  nil 
200231}
0 commit comments