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

Supply max retries #2

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
module github.com/btcsuite/btcd
module github.com/paxosglobal/btcd

replace github.com/btcsuite/btcd => github.com/paxosglobal/btcd v0.20.1-beta.0.20200206213050-d0903b768de2
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed this


require (
github.com/aead/siphash v1.0.1 // indirect
github.com/btcsuite/btcd v0.20.1-beta
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723 // indirect
github.com/btcsuite/snappy-go v1.0.0 // indirect
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792
github.com/btcsuite/winsvc v1.0.0
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89
github.com/jrick/logrotate v1.0.0
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 // indirect
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/kkdai/bstream v1.0.0 // indirect
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44
)

Expand Down
27 changes: 17 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JG
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd h1:qdGvebPBDuYDPGi1WCPjy1tGyMpmDK8IEapSsszn7HE=
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723 h1:ZA/jbKoGcVAnER6pCHPEkGdZOV7U1oLUedErBHCUMs0=
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJGQE=
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0 h1:J9B4L7e3oqhXOcm+2IuNApwzQec85lE+QaikUcCs+dk=
Expand All @@ -26,13 +26,16 @@ github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89 h1:12K8AlpT0/6QU
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jrick/logrotate v1.0.0 h1:lQ1bL/n9mBNeIXoTUoYRlK4dHuNJVofX9oWqBtPnSzI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 h1:FOOIBWrEkLgmlgGfMuZT83xIwfPDxEI2OHu6xUmJMFE=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/kkdai/bstream v1.0.0 h1:Se5gHwgp2VT2uHfDrkbbgbgEvV9cimLELwrPJctSjg8=
github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg=
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/paxosglobal/btcd v0.20.1-beta.0.20200206213050-d0903b768de2 h1:4a4D6H5pOMeCQDc1Sh3IRipAINaR6JrIzQFKOat98YI=
github.com/paxosglobal/btcd v0.20.1-beta.0.20200206213050-d0903b768de2/go.mod h1:ZrXZzyoIkjdGNjl5BwA7eFb1qOlqOAhtZJCjDt0cuCY=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44 h1:9lP3x0pW80sDI6t1UMSLA4to18W7R7imwAI/sWS9S8Q=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
Expand All @@ -41,13 +44,17 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6Zh
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
4 changes: 2 additions & 2 deletions integration/bip0009_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) {
if err != nil {
t.Fatalf("unable to create primary harness: %v", err)
}
if err := r.SetUp(false, 0); err != nil {
if err := r.SetUp(false, 0, defaultConnRetries); err != nil {
t.Fatalf("unable to setup test chain: %v", err)
}
defer r.TearDown()
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestBIP0009Mining(t *testing.T) {
if err != nil {
t.Fatalf("unable to create primary harness: %v", err)
}
if err := r.SetUp(true, 0); err != nil {
if err := r.SetUp(true, 0, defaultConnRetries); err != nil {
t.Fatalf("unable to setup test chain: %v", err)
}
defer r.TearDown()
Expand Down
4 changes: 2 additions & 2 deletions integration/csv_fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestBIP0113Activation(t *testing.T) {
if err != nil {
t.Fatal("unable to create primary harness: ", err)
}
if err := r.SetUp(true, 1); err != nil {
if err := r.SetUp(true, 1, defaultConnRetries); err != nil {
t.Fatalf("unable to setup test chain: %v", err)
}
defer r.TearDown()
Expand Down Expand Up @@ -409,7 +409,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) {
if err != nil {
t.Fatal("unable to create primary harness: ", err)
}
if err := r.SetUp(true, 1); err != nil {
if err := r.SetUp(true, 1, defaultConnRetries); err != nil {
t.Fatalf("unable to setup test chain: %v", err)
}
defer r.TearDown()
Expand Down
2 changes: 1 addition & 1 deletion integration/rpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestMain(m *testing.M) {
// Initialize the primary mining node with a chain of length 125,
// providing 25 mature coinbases to allow spending from for testing
// purposes.
if err := primaryHarness.SetUp(true, 25); err != nil {
if err := primaryHarness.SetUp(true, 25, defaultConnRetries); err != nil {
fmt.Println("unable to setup test chain: ", err)

// Even though the harness was not fully setup, it still needs
Expand Down
11 changes: 11 additions & 0 deletions integration/rpctest/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (n *nodeConfig) rpcConnConfig() rpc.ConnConfig {
Pass: n.rpcPass,
Certificates: n.certificates,
DisableAutoReconnect: true,
DisableTLS: true,
}
}

Expand Down Expand Up @@ -201,9 +202,15 @@ func newNode(config *nodeConfig, dataDir string) (*node, error) {
// test case, or panic, it is important that the process be stopped via stop(),
// otherwise, it will persist unless explicitly killed.
func (n *node) start() error {
fmt.Println("starting rpc node")
if err := n.cmd.Start(); err != nil {
return err
}
foundP, err := os.FindProcess(n.cmd.Process.Pid)
if err != nil {
return err
}
fmt.Println("found p", foundP)

pid, err := os.Create(filepath.Join(n.dataDir,
fmt.Sprintf("%s.pid", n.config)))
Expand All @@ -220,6 +227,8 @@ func (n *node) start() error {
return err
}

fmt.Println("created pid file", n.cmd.Process.Pid, filepath.Join(n.dataDir,
fmt.Sprintf("%s.pid", n.config)))
return nil
}

Expand All @@ -236,6 +245,7 @@ func (n *node) stop() error {
if runtime.GOOS == "windows" {
return n.cmd.Process.Signal(os.Kill)
}
fmt.Println("signalling to interrupt the process")
return n.cmd.Process.Signal(os.Interrupt)
}

Expand All @@ -245,6 +255,7 @@ func (n *node) stop() error {
func (n *node) cleanup() error {
if n.pidFile != "" {
if err := os.Remove(n.pidFile); err != nil {
fmt.Printf("unable to remove pid file %s %v\n", n.pidFile, err)
log.Printf("unable to remove file %s: %v", n.pidFile,
err)
}
Expand Down
14 changes: 10 additions & 4 deletions integration/rpctest/rpc_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
// BlockVersion is the default block version used when generating
// blocks.
BlockVersion = 4

defaultConnRetries = 20
)

var (
Expand Down Expand Up @@ -213,13 +215,14 @@ func New(activeNet *chaincfg.Params, handlers *rpcclient.NotificationHandlers,
//
// NOTE: This method and TearDown should always be called from the same
// goroutine as they are not concurrent safe.
func (h *Harness) SetUp(createTestChain bool, numMatureOutputs uint32) error {
func (h *Harness) SetUp(createTestChain bool, numMatureOutputs uint32, connRetries int) error {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New param for tests

// Start the btcd node itself. This spawns a new process which will be
// managed
if err := h.node.start(); err != nil {
return err
}
if err := h.connectRPCClient(); err != nil {
if err := h.connectRPCClient(connRetries); err != nil {
fmt.Println("process state", h.node.cmd.ProcessState.String())
return err
}

Expand Down Expand Up @@ -272,6 +275,7 @@ func (h *Harness) SetUp(createTestChain bool, numMatureOutputs uint32) error {
//
// This function MUST be called with the harness state mutex held (for writes).
func (h *Harness) tearDown() error {
fmt.Println("tearing down rpc node")
if h.Node != nil {
h.Node.Shutdown()
}
Expand Down Expand Up @@ -307,14 +311,15 @@ func (h *Harness) TearDown() error {
// the time between subsequent attempts. If after h.maxConnRetries attempts,
// we're not able to establish a connection, this function returns with an
// error.
func (h *Harness) connectRPCClient() error {
func (h *Harness) connectRPCClient(connRetries int) error {
var client *rpcclient.Client
var err error

rpcConf := h.node.config.rpcConnConfig()
for i := 0; i < h.maxConnRetries; i++ {
for i := 0; i < connRetries; i++ {
if client, err = rpcclient.New(&rpcConf, h.handlers); err != nil {
time.Sleep(time.Duration(i) * 50 * time.Millisecond)
fmt.Println("error connecting via RPC", err.Error())
continue
}
break
Expand Down Expand Up @@ -489,6 +494,7 @@ func generateListeningAddresses() (string, string) {

p2p := net.JoinHostPort(localhost, portString(minPeerPort, maxPeerPort))
rpc := net.JoinHostPort(localhost, portString(minRPCPort, maxRPCPort))
fmt.Println("using ports", p2p, rpc, processID)
return p2p, rpc
}

Expand Down
10 changes: 5 additions & 5 deletions integration/rpctest/rpc_harness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func testConnectNode(r *Harness, t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := harness.SetUp(false, 0); err != nil {
if err := harness.SetUp(false, 0, defaultConnRetries); err != nil {
t.Fatalf("unable to complete rpctest setup: %v", err)
}
defer harness.TearDown()
Expand Down Expand Up @@ -185,7 +185,7 @@ func testJoinMempools(r *Harness, t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := harness.SetUp(false, 0); err != nil {
if err := harness.SetUp(false, 0, defaultConnRetries); err != nil {
t.Fatalf("unable to complete rpctest setup: %v", err)
}
defer harness.TearDown()
Expand Down Expand Up @@ -285,7 +285,7 @@ func testJoinBlocks(r *Harness, t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := harness.SetUp(false, 0); err != nil {
if err := harness.SetUp(false, 0, defaultConnRetries); err != nil {
t.Fatalf("unable to complete rpctest setup: %v", err)
}
defer harness.TearDown()
Expand Down Expand Up @@ -473,7 +473,7 @@ func testMemWalletReorg(r *Harness, t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := harness.SetUp(true, 5); err != nil {
if err := harness.SetUp(true, 5, defaultConnRetries); err != nil {
t.Fatalf("unable to complete rpctest setup: %v", err)
}
defer harness.TearDown()
Expand Down Expand Up @@ -575,7 +575,7 @@ func TestMain(m *testing.M) {
// Initialize the main mining node with a chain of length 125,
// providing 25 mature coinbases to allow spending from for testing
// purposes.
if err = mainHarness.SetUp(true, numMatureOutputs); err != nil {
if err = mainHarness.SetUp(true, numMatureOutputs, defaultConnRetries); err != nil {
fmt.Println("unable to setup test chain: ", err)

// Even though the harness was not fully setup, it still needs
Expand Down
3 changes: 3 additions & 0 deletions rpcclient/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,13 +1262,15 @@ func New(config *ConnConfig, ntfnHandlers *NotificationHandlers) (*Client, error
var err error
httpClient, err = newHTTPClient(config)
if err != nil {
fmt.Println("unable to connect http", err.Error())
return nil, err
}
} else {
if !config.DisableConnectOnNew {
var err error
wsConn, err = dial(config)
if err != nil {
fmt.Println("unable to connect ws", err.Error())
return nil, err
}
start = true
Expand All @@ -1294,6 +1296,7 @@ func New(config *ConnConfig, ntfnHandlers *NotificationHandlers) (*Client, error
log.Infof("Established connection to RPC server %s",
config.Host)
close(connEstablished)
fmt.Println("starting ws client")
client.start()
if !client.config.HTTPPostMode && !client.config.DisableAutoReconnect {
client.wg.Add(1)
Expand Down