optimism-java / shisui

Ethereum Portal Network Client written in Go
https://www.ethportal.net/clients/shisui
GNU Lesser General Public License v3.0
5 stars 6 forks source link

Refactor of main to allow graceful shutdown #158

Closed r4f4ss closed 1 week ago

r4f4ss commented 1 week ago

solves #156

GrapeBaBa commented 1 week ago

Since we forked geth, is there any existing code to reuse or reference.

r4f4ss commented 1 week ago

Since we forked geth, is there any existing code to reuse or reference.

The reference comes from https://github.com/optimism-java/shisui/blob/b061173db18614af29b49b7dbab4186cd5d92497/cmd/utils/cmd.go#L77 that geth main function calls to create a new node. Inside this function (StartNode) a goroutine watches a channel for signals of interruption and executes the shutdown function (https://github.com/optimism-java/shisui/blob/b061173db18614af29b49b7dbab4186cd5d92497/cmd/utils/cmd.go#L115).

I studied this file to understand how to handle a syscall.SIGINT or a syscall.SIGTERM signals, but I believe it is not possible to reuse this code to deal with Shisui since geth implements an anonymous goroutine.

Other aspect is the behavior/functionality of CTRL-C command: in geth to force quit is necessary to press 10 times CTRL-C, or panic behavior:

for i := 10; i > 0; i-- {
        <-sigc
        if i > 1 {
          log.Warn("Already shutting down, interrupt more to panic.", "times", i-1)
        }
      }

while in Shisui only a second press of CTRL-c quits.

Please let me know if there is a better approach I should implement.