From e3aca9bec7d5ab20675dc217b9b663a83c9db4f5 Mon Sep 17 00:00:00 2001 From: Larry Ruane Date: Thu, 7 May 2020 09:18:02 -0600 Subject: [PATCH] review comment: 30-minute shutdown improvement Safer to shutdown darksidewalletd directly after 30 minutes, instead of waiting for a zcashd rpc to occur (darksideRawRequest()); also using a goroutine is simpler. --- common/darkside.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/common/darkside.go b/common/darkside.go index 8473e49..ac653cf 100644 --- a/common/darkside.go +++ b/common/darkside.go @@ -25,7 +25,6 @@ type darksideState struct { // Should always be nonempty. Index 0 is the block at height start_height. blocks [][]byte // full blocks, binary, as from zcashd getblock rpc incomingTransactions [][]byte // full transactions, binary, zcashd getrawtransaction txid - serverStart time.Time } var state darksideState @@ -43,7 +42,6 @@ func DarksideInit() { chainName: "darkside", blocks: make([][]byte, 0), incomingTransactions: make([][]byte, 0), - serverStart: time.Now(), } RawRequest = darksideRawRequest f := "testdata/darkside/init-blocks" @@ -55,6 +53,10 @@ func DarksideInit() { if err = readBlocks(testBlocks); err != nil { Log.Warn("Error loading default darksidewalletd blocks") } + go func() { + time.Sleep(30 * time.Minute) + Log.Fatal("Shutting down darksidewalletd to prevent accidental deployment in production.") + }() } // DarksideAddBlock adds a single block to the blocks list. @@ -192,10 +194,6 @@ func DarksideSendTransaction(txHex []byte) ([]byte, error) { } func darksideRawRequest(method string, params []json.RawMessage) (json.RawMessage, error) { - if time.Now().Sub(state.serverStart).Minutes() >= 30 { - Log.Fatal("Shutting down darksidewalletd to prevent accidental deployment in production.") - } - switch method { case "getblockchaininfo": type upgradeinfo struct {