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.
This commit is contained in:
Larry Ruane 2020-05-07 09:18:02 -06:00 committed by Larry Ruane
parent 5e37f408e3
commit e3aca9bec7
1 changed files with 4 additions and 6 deletions

View File

@ -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 {