Seed random generator in RPC server during init.

Rather than reseeding the PRNG used throughout the RPC server on each
call, do it once during init.

Suggested by @jrick
This commit is contained in:
Dave Collins 2014-06-30 13:16:05 -05:00
parent 180f4ac0a2
commit ffe0b09890

View file

@ -156,10 +156,6 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
"verifychain": handleVerifyChain,
}
func init() {
rpcHandlers = rpcHandlersBeforeInit
}
// list of commands that we recognise, but for which btcd has no support because
// it lacks support for wallet functionality. For these commands the user
// should ask a connected instance of btcwallet.
@ -1447,7 +1443,6 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo
// to create their own coinbase.
var payAddr btcutil.Address
if !useCoinbaseValue {
rand.Seed(time.Now().UnixNano())
payAddr = cfg.miningAddrs[rand.Intn(len(cfg.miningAddrs))]
}
@ -1514,7 +1509,6 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo
// returned if none have been specified.
if !useCoinbaseValue && !template.validPayAddress {
// Choose a payment address at random.
rand.Seed(time.Now().UnixNano())
payToAddr := cfg.miningAddrs[rand.Intn(len(cfg.miningAddrs))]
// Update the block coinbase output of the template to
@ -2470,7 +2464,6 @@ func handleGetWorkRequest(s *rpcServer) (interface{}, error) {
state.prevHash = nil
// Choose a payment address at random.
rand.Seed(time.Now().UnixNano())
payToAddr := cfg.miningAddrs[rand.Intn(len(cfg.miningAddrs))]
template, err := NewBlockTemplate(s.server.txMemPool, payToAddr)
@ -3121,3 +3114,8 @@ func getDifficultyRatio(bits uint32) float64 {
}
return diff
}
func init() {
rpcHandlers = rpcHandlersBeforeInit
rand.Seed(time.Now().UnixNano())
}