diff --git a/core/kernel/http.go b/core/kernel/http.go index 103a1ad..927d1ac 100644 --- a/core/kernel/http.go +++ b/core/kernel/http.go @@ -35,7 +35,7 @@ func (k *Kernel) HandleHttp() { if k.cfg.IsAdmin { admin := api.Group(AdminType) admin.GET("stop", func(c *gin.Context) { - close(k.stopChan) + k.Stop() }) } diff --git a/core/kernel/kernel.go b/core/kernel/kernel.go index d8141eb..8d216b7 100644 --- a/core/kernel/kernel.go +++ b/core/kernel/kernel.go @@ -1,8 +1,6 @@ package kernel import ( - "sync" - "github.com/sirupsen/logrus" "github.com/yu-org/yu/common" @@ -29,7 +27,6 @@ type Kernel struct { *env.ChainEnv Land *tripod.Land - wg *sync.WaitGroup } func NewKernel( @@ -46,7 +43,6 @@ func NewKernel( wsPort: ip.MakePort(cfg.WsPort), ChainEnv: env, Land: land, - wg: &sync.WaitGroup{}, } env.Execute = k.SeqExecuteWritings @@ -76,24 +72,18 @@ func (k *Kernel) WithExecuteFn(fn env.ExecuteFn) { k.Execute = fn } -func (k *Kernel) WaitExit() { - k.wg.Wait() -} - func (k *Kernel) Startup() { k.InitBlockChain() go k.HandleHttp() go k.HandleWS() - k.wg.Add(1) go k.AcceptUnpkgTxnsJob() - go k.Run() + k.Run() } func (k *Kernel) Stop() { - close(k.stopChan) - k.wg.Wait() + k.stopChan <- struct{}{} } func (k *Kernel) InitBlockChain() { diff --git a/core/kernel/run.go b/core/kernel/run.go index 7216bfb..b896ddd 100644 --- a/core/kernel/run.go +++ b/core/kernel/run.go @@ -21,10 +21,7 @@ func (k *Kernel) AcceptUnpkgTxnsJob() { } func (k *Kernel) Run() { - defer func() { - logrus.Info("Run exit") - k.wg.Done() - }() + defer logrus.Info("Run exit") switch k.RunMode { case common.LocalNode: for {