Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chain: wait for bitcoind rpc to warm up #677

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 24 additions & 3 deletions chain/bitcoind_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,30 @@ func NewBitcoindConn(cfg *BitcoindConfig) (*BitcoindConn, error) {
}

// Verify that the node is running on the expected network.
net, err := getCurrentNet(client)
if err != nil {
return nil, err
var net wire.BitcoinNet

btcInWarmup := false
for {
net, err = getCurrentNet(client)
if err == nil {
// No error means bitcoind is responsive and we can proceed.
break
}
if rpcErr, ok := err.(*btcjson.RPCError); ok &&
rpcErr.Code == btcjson.ErrRPCInWarmup {
// Error code -28 indicates the bitcoind rpc is warming up.
// We will wait and recheck periodically until rpc is ready.
if !btcInWarmup {
btcInWarmup = true
log.Info("Waiting for bitcoind RPC to finish warming up...")
}
time.Sleep(time.Second * 1)
} else {
return nil, err
}
}
if btcInWarmup {
log.Info("Bitcoind finished warming up and RPC is ready")
}
if net != cfg.ChainParams.Net {
return nil, fmt.Errorf("expected network %v, got %v",
Expand Down