gitlab.com/gpdionisio/tendermint@v0.34.19-dev2/cmd/priv_val_server/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "os" 6 "time" 7 8 "github.com/tendermint/tendermint/crypto/ed25519" 9 "github.com/tendermint/tendermint/libs/log" 10 tmnet "github.com/tendermint/tendermint/libs/net" 11 tmos "github.com/tendermint/tendermint/libs/os" 12 13 "github.com/tendermint/tendermint/privval" 14 ) 15 16 func main() { 17 var ( 18 addr = flag.String("addr", ":26659", "Address of client to connect to") 19 chainID = flag.String("chain-id", "mychain", "chain id") 20 privValKeyPath = flag.String("priv-key", "", "priv val key file path") 21 privValStatePath = flag.String("priv-state", "", "priv val state file path") 22 23 logger = log.NewTMLogger( 24 log.NewSyncWriter(os.Stdout), 25 ).With("module", "priv_val") 26 ) 27 flag.Parse() 28 29 logger.Info( 30 "Starting private validator", 31 "addr", *addr, 32 "chainID", *chainID, 33 "privKeyPath", *privValKeyPath, 34 "privStatePath", *privValStatePath, 35 ) 36 37 pv := privval.LoadFilePV(*privValKeyPath, *privValStatePath) 38 39 var dialer privval.SocketDialer 40 protocol, address := tmnet.ProtocolAndAddress(*addr) 41 switch protocol { 42 case "unix": 43 dialer = privval.DialUnixFn(address) 44 case "tcp": 45 connTimeout := 3 * time.Second // TODO 46 dialer = privval.DialTCPFn(address, connTimeout, ed25519.GenPrivKey()) 47 default: 48 logger.Error("Unknown protocol", "protocol", protocol) 49 os.Exit(1) 50 } 51 52 sd := privval.NewSignerDialerEndpoint(logger, dialer) 53 ss := privval.NewSignerServer(sd, *chainID, pv) 54 55 err := ss.Start() 56 if err != nil { 57 panic(err) 58 } 59 60 // Stop upon receiving SIGTERM or CTRL-C. 61 tmos.TrapSignal(logger, func() { 62 err := ss.Stop() 63 if err != nil { 64 panic(err) 65 } 66 }) 67 68 // Run forever. 69 select {} 70 }