Improve getwork interaction with regtest mode.

Ordinarily, getwork will return an error if btcd is not connected to any
other peers.  This commit relaxes that requirement when running in
regression test mode since it is useful for development purposes.

While here, also improve check which returns an error from getwork is not
current to exclude the check when the best chain height is zero since the
code never believes it is current when at height 0.
This commit is contained in:
Dave Collins 2014-05-08 19:46:56 -05:00
parent 47e65634a7
commit 6a325f4c6a

View file

@ -1749,12 +1749,14 @@ func handleGetWork(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
// Return an error if there are no peers connected since there is no
// way to relay a found block or receive transactions to work on.
if s.server.ConnectedCount() == 0 {
// However, allow this state when running in regression test mode.
if !cfg.RegressionTest && s.server.ConnectedCount() == 0 {
return nil, btcjson.ErrClientNotConnected
}
// No point in generating or accepting work before the chain is synced.
if !s.server.blockManager.IsCurrent() {
_, currentHeight := s.server.blockManager.chainState.Best()
if currentHeight != 0 && !s.server.blockManager.IsCurrent() {
return nil, btcjson.ErrClientInInitialDownload
}