From 154f2f25d3744dac8b9c05425fac8e2f7165e818 Mon Sep 17 00:00:00 2001 From: Connor Stein Date: Mon, 23 Dec 2019 11:11:32 -0500 Subject: [PATCH 01/21] porting https://github.com/reinerRubin/btcd bug fix --- btcjson/chainsvrcmds.go | 8 +++--- btcjson/chainsvrcmds_test.go | 43 +++++++++++++++++++------------ btcjson/chainsvrresults.go | 50 ++++++++++++++++++++++-------------- btcjson/cmdinfo_test.go | 2 +- btcjson/example_test.go | 29 ++++++++++----------- btcjson/help.go | 37 ++++++++++++++++---------- btcjson/help_test.go | 2 +- rpcclient/chain.go | 33 ++++++++++++++++++++---- rpcserver.go | 30 +++++++++++++++------- rpcserverhelp.go | 12 +++++---- 10 files changed, 156 insertions(+), 90 deletions(-) diff --git a/btcjson/chainsvrcmds.go b/btcjson/chainsvrcmds.go index 406357bd06..126780dfd5 100644 --- a/btcjson/chainsvrcmds.go +++ b/btcjson/chainsvrcmds.go @@ -130,8 +130,7 @@ func NewGetBestBlockHashCmd() *GetBestBlockHashCmd { // GetBlockCmd defines the getblock JSON-RPC command. type GetBlockCmd struct { Hash string - Verbose *bool `jsonrpcdefault:"true"` - VerboseTx *bool `jsonrpcdefault:"false"` + Verbosity *uint32 `jsonrpcdefault:"1"` } // NewGetBlockCmd returns a new instance which can be used to issue a getblock @@ -139,11 +138,10 @@ type GetBlockCmd struct { // // The parameters which are pointers indicate they are optional. Passing nil // for optional parameters will use the default value. -func NewGetBlockCmd(hash string, verbose, verboseTx *bool) *GetBlockCmd { +func NewGetBlockCmd(hash string, verbosity *uint32) *GetBlockCmd { return &GetBlockCmd{ Hash: hash, - Verbose: verbose, - VerboseTx: verboseTx, + Verbosity: verbosity, } } diff --git a/btcjson/chainsvrcmds_test.go b/btcjson/chainsvrcmds_test.go index 8cb4ee765a..79fccbc776 100644 --- a/btcjson/chainsvrcmds_test.go +++ b/btcjson/chainsvrcmds_test.go @@ -142,16 +142,15 @@ func TestChainSvrCmds(t *testing.T) { { name: "getblock", newCmd: func() (interface{}, error) { - return btcjson.NewCmd("getblock", "123") + return btcjson.NewCmd("getblock", "123", 0) }, staticCmd: func() interface{} { - return btcjson.NewGetBlockCmd("123", nil, nil) + return btcjson.NewGetBlockCmd("123", btcjson.Uint32(0)) }, - marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123"],"id":1}`, + marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",0],"id":1}`, unmarshalled: &btcjson.GetBlockCmd{ Hash: "123", - Verbose: btcjson.Bool(true), - VerboseTx: btcjson.Bool(false), + Verbosity: btcjson.Uint32(0), }, }, { @@ -160,32 +159,44 @@ func TestChainSvrCmds(t *testing.T) { // Intentionally use a source param that is // more pointers than the destination to // exercise that path. - verbosePtr := btcjson.Bool(true) - return btcjson.NewCmd("getblock", "123", &verbosePtr) + verbosityPtr := btcjson.Uint32(1) + return btcjson.NewCmd("getblock", "123", &verbosityPtr) }, staticCmd: func() interface{} { - return btcjson.NewGetBlockCmd("123", btcjson.Bool(true), nil) + return btcjson.NewGetBlockCmd("123", btcjson.Uint32(1)) }, - marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",true],"id":1}`, + marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",1],"id":1}`, unmarshalled: &btcjson.GetBlockCmd{ Hash: "123", - Verbose: btcjson.Bool(true), - VerboseTx: btcjson.Bool(false), + Verbosity: btcjson.Uint32(1), }, }, { name: "getblock required optional2", newCmd: func() (interface{}, error) { - return btcjson.NewCmd("getblock", "123", true, true) + return btcjson.NewCmd("getblock", "123", 2) }, staticCmd: func() interface{} { - return btcjson.NewGetBlockCmd("123", btcjson.Bool(true), btcjson.Bool(true)) + return btcjson.NewGetBlockCmd("123", btcjson.Uint32(2)) }, - marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",true,true],"id":1}`, + marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",2],"id":1}`, + unmarshalled: &btcjson.GetBlockCmd{ + Hash: "123", + Verbosity: btcjson.Uint32(2), + }, + }, + { + name: "getblock; default verbose level must be 1", + newCmd: func() (interface{}, error) { + return btcjson.NewCmd("getblock", "123") + }, + staticCmd: func() interface{} { + return btcjson.NewGetBlockCmd("123", nil) + }, + marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123"],"id":1}`, unmarshalled: &btcjson.GetBlockCmd{ Hash: "123", - Verbose: btcjson.Bool(true), - VerboseTx: btcjson.Bool(true), + Verbosity: btcjson.Uint32(1), }, }, { diff --git a/btcjson/chainsvrresults.go b/btcjson/chainsvrresults.go index 7e6c710766..25d0b646aa 100644 --- a/btcjson/chainsvrresults.go +++ b/btcjson/chainsvrresults.go @@ -24,27 +24,39 @@ type GetBlockHeaderVerboseResult struct { NextHash string `json:"nextblockhash,omitempty"` } +// GetBlockBaseVerboseResult models the common data from the getblock command when +// verbose flag set to 1 or 2. When the verbose flag is not set, getblock +// returns a hex-encoded string. +type GetBlockBaseVerboseResult struct { + Hash string `json:"hash"` + Confirmations int64 `json:"confirmations"` + StrippedSize int32 `json:"strippedsize"` + Size int32 `json:"size"` + Weight int32 `json:"weight"` + Height int64 `json:"height"` + Version int32 `json:"version"` + VersionHex string `json:"versionHex"` + MerkleRoot string `json:"merkleroot"` + Time int64 `json:"time"` + Nonce uint32 `json:"nonce"` + Bits string `json:"bits"` + Difficulty float64 `json:"difficulty"` + PreviousHash string `json:"previousblockhash"` + NextHash string `json:"nextblockhash,omitempty"` +} + // GetBlockVerboseResult models the data from the getblock command when the -// verbose flag is set. When the verbose flag is not set, getblock returns a -// hex-encoded string. +// verbose flag is set to 1 (default). type GetBlockVerboseResult struct { - Hash string `json:"hash"` - Confirmations int64 `json:"confirmations"` - StrippedSize int32 `json:"strippedsize"` - Size int32 `json:"size"` - Weight int32 `json:"weight"` - Height int64 `json:"height"` - Version int32 `json:"version"` - VersionHex string `json:"versionHex"` - MerkleRoot string `json:"merkleroot"` - Tx []string `json:"tx,omitempty"` - RawTx []TxRawResult `json:"rawtx,omitempty"` - Time int64 `json:"time"` - Nonce uint32 `json:"nonce"` - Bits string `json:"bits"` - Difficulty float64 `json:"difficulty"` - PreviousHash string `json:"previousblockhash"` - NextHash string `json:"nextblockhash,omitempty"` + *GetBlockBaseVerboseResult + Tx []string `json:"tx,omitempty"` +} + +// GetBlockVerboseTxResult models the data from the getblock command when the +// verbose flag is set to 2. +type GetBlockVerboseTxResult struct { + *GetBlockBaseVerboseResult + Tx []TxRawResult `json:"tx,omitempty"` } // CreateMultiSigResult models the data returned from the createmultisig diff --git a/btcjson/cmdinfo_test.go b/btcjson/cmdinfo_test.go index 044040279a..61a693e404 100644 --- a/btcjson/cmdinfo_test.go +++ b/btcjson/cmdinfo_test.go @@ -151,7 +151,7 @@ func TestMethodUsageText(t *testing.T) { { name: "getblock", method: "getblock", - expected: `getblock "hash" (verbose=true verbosetx=false)`, + expected: `getblock "hash" (verbosity=1)`, }, } diff --git a/btcjson/example_test.go b/btcjson/example_test.go index 527252c7fb..e18a30692c 100644 --- a/btcjson/example_test.go +++ b/btcjson/example_test.go @@ -11,17 +11,18 @@ import ( "github.com/btcsuite/btcd/btcjson" ) -// This example demonstrates how to create and marshal a command into a JSON-RPC -// request. +// Create a new getblock command. Notice the call to btcjson.Uint32 which is a +// convenience function for creating a pointer out of a primitive for +// optional parameters. Notice the nil parameter indicates +// to use the default parameter for that fields. This is a common +// pattern used in all of the NewCmdr functions in this package for +// optional fields. func ExampleMarshalCmd() { - // Create a new getblock command. Notice the nil parameter indicates - // to use the default parameter for that fields. This is a common - // pattern used in all of the NewCmd functions in this package for - // optional fields. Also, notice the call to btcjson.Bool which is a - // convenience function for creating a pointer out of a primitive for - // optional parameters. + // Create a new getblock command. blockHash := "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" - gbCmd := btcjson.NewGetBlockCmd(blockHash, btcjson.Bool(false), nil) + gbCmd := btcjson.NewGetBlockCmd(blockHash, btcjson.Uint32(2)) + // or + // gbCmd := btcjson.NewGetBlockCmd(blockHash, nil) // Marshal the command to the format suitable for sending to the RPC // server. Typically the client would increment the id here which is @@ -38,7 +39,7 @@ func ExampleMarshalCmd() { fmt.Printf("%s\n", marshalledBytes) // Output: - // {"jsonrpc":"1.0","method":"getblock","params":["000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",false],"id":1} + // {"jsonrpc":"1.0","method":"getblock","params":["000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",2],"id":1} } // This example demonstrates how to unmarshal a JSON-RPC request and then @@ -46,7 +47,7 @@ func ExampleMarshalCmd() { func ExampleUnmarshalCmd() { // Ordinarily this would be read from the wire, but for this example, // it is hard coded here for clarity. - data := []byte(`{"jsonrpc":"1.0","method":"getblock","params":["000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",false],"id":1}`) + data := []byte(`{"jsonrpc":"1.0","method":"getblock","params":["000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",0],"id":1}`) // Unmarshal the raw bytes from the wire into a JSON-RPC request. var request btcjson.Request @@ -84,13 +85,11 @@ func ExampleUnmarshalCmd() { // Display the fields in the concrete command. fmt.Println("Hash:", gbCmd.Hash) - fmt.Println("Verbose:", *gbCmd.Verbose) - fmt.Println("VerboseTx:", *gbCmd.VerboseTx) + fmt.Println("Verbosity:", *gbCmd.Verbosity) // Output: // Hash: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f - // Verbose: false - // VerboseTx: false + // Verbosity: 0 } // This example demonstrates how to marshal a JSON-RPC response. diff --git a/btcjson/help.go b/btcjson/help.go index f502d09fd8..ed3bd7931f 100644 --- a/btcjson/help.go +++ b/btcjson/help.go @@ -110,8 +110,8 @@ func resultStructHelp(xT descLookupFunc, rt reflect.Type, indentLevel int) []str fieldType := reflectTypeToJSONType(xT, rtfType) fieldDescKey := typeName + "-" + fieldName fieldExamples, isComplex := reflectTypeToJSONExample(xT, - rtfType, indentLevel, fieldDescKey) - if isComplex { + rtfType, indentLevel, fieldDescKey, rtf.Anonymous) + if isComplex && !rtf.Anonymous { var brace string kind := rtfType.Kind() if kind == reflect.Array || kind == reflect.Slice { @@ -123,6 +123,8 @@ func resultStructHelp(xT descLookupFunc, rt reflect.Type, indentLevel int) []str fieldName, brace, fieldType, xT(fieldDescKey)) results = append(results, result) results = append(results, fieldExamples...) + } else if isComplex && rtf.Anonymous { + results = append(results, fieldExamples...) } else { result := fmt.Sprintf("%s\"%s\": %s,\t(%s)\t%s", indent, fieldName, fieldExamples[0], fieldType, @@ -140,7 +142,7 @@ func resultStructHelp(xT descLookupFunc, rt reflect.Type, indentLevel int) []str // a tab writer. A bool is also returned which specifies whether or not the // type results in a complex JSON object since they need to be handled // differently. -func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel int, fieldDescKey string) ([]string, bool) { +func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel int, fieldDescKey string, embeddedStruct bool) ([]string, bool) { // Indirect pointer if needed. if rt.Kind() == reflect.Ptr { rt = rt.Elem() @@ -163,7 +165,12 @@ func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel in case reflect.Struct: indent := strings.Repeat(" ", indentLevel) - results := resultStructHelp(xT, rt, indentLevel+1) + nextIndentLevel := indentLevel + + if !embeddedStruct { + nextIndentLevel++ + } + results := resultStructHelp(xT, rt, nextIndentLevel) // An opening brace is needed for the first indent level. For // all others, it will be included as a part of the previous @@ -174,20 +181,22 @@ func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel in copy(newResults[1:], results) results = newResults } - - // The closing brace has a comma after it except for the first - // indent level. The final tabs are necessary so the tab writer - // lines things up properly. - closingBrace := indent + "}" - if indentLevel > 0 { - closingBrace += "," + if !embeddedStruct { + // The closing brace has a comma after it except for the first + // indent level. The final tabs are necessary so the tab writer + // lines things up properly. + closingBrace := indent + "}" + if indentLevel > 0 { + closingBrace += "," + } + results = append(results, closingBrace+"\t\t") } - results = append(results, closingBrace+"\t\t") + return results, true case reflect.Array, reflect.Slice: results, isComplex := reflectTypeToJSONExample(xT, rt.Elem(), - indentLevel, fieldDescKey) + indentLevel, fieldDescKey, false) // When the result is complex, it is because this is an array of // objects. @@ -251,7 +260,7 @@ func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel in // type. func resultTypeHelp(xT descLookupFunc, rt reflect.Type, fieldDescKey string) string { // Generate the JSON example for the result type. - results, isComplex := reflectTypeToJSONExample(xT, rt, 0, fieldDescKey) + results, isComplex := reflectTypeToJSONExample(xT, rt, 0, fieldDescKey, false) // When this is a primitive type, add the associated JSON type and // result description into the final string, format it accordingly, diff --git a/btcjson/help_test.go b/btcjson/help_test.go index 918aa14479..ee406ee4e9 100644 --- a/btcjson/help_test.go +++ b/btcjson/help_test.go @@ -246,7 +246,7 @@ func TestHelpReflectInternals(t *testing.T) { // Ensure the generated example is as expected. examples, isComplex := btcjson.TstReflectTypeToJSONExample(xT, - test.reflectType, test.indentLevel, "fdk") + test.reflectType, test.indentLevel, "fdk", false) if isComplex != test.isComplex { t.Errorf("Test #%d (%s) unexpected isComplex - got: %v, "+ "want: %v", i, test.name, isComplex, diff --git a/rpcclient/chain.go b/rpcclient/chain.go index 996d80458c..f7fe310e27 100644 --- a/rpcclient/chain.go +++ b/rpcclient/chain.go @@ -97,7 +97,7 @@ func (c *Client) GetBlockAsync(blockHash *chainhash.Hash) FutureGetBlockResult { hash = blockHash.String() } - cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(false), nil) + cmd := btcjson.NewGetBlockCmd(hash, btcjson.Uint32(0)) return c.sendCmd(cmd) } @@ -141,7 +141,7 @@ func (c *Client) GetBlockVerboseAsync(blockHash *chainhash.Hash) FutureGetBlockV hash = blockHash.String() } - cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(true), nil) + cmd := btcjson.NewGetBlockCmd(hash, btcjson.Uint32(1)) return c.sendCmd(cmd) } @@ -154,18 +154,41 @@ func (c *Client) GetBlockVerbose(blockHash *chainhash.Hash) (*btcjson.GetBlockVe return c.GetBlockVerboseAsync(blockHash).Receive() } +// FutureGetBlockVerboseTxResult is a future promise to deliver the result of a +// GetBlockVerboseTxAsync RPC invocation (or an applicable error). +type FutureGetBlockVerboseTxResult chan *response + +// Receive waits for the response promised by the future and returns the data +// structure from the server with information about the requested block. +func (r FutureGetBlockVerboseTxResult) Receive() (*btcjson.GetBlockVerboseTxResult, error) { + res, err := receiveFuture(r) + if err != nil { + return nil, err + } + + // Unmarshal the raw result into a BlockResult. + var blockResult btcjson.GetBlockVerboseTxResult + err = json.Unmarshal(res, &blockResult) + if err != nil { + return nil, err + } + return &blockResult, nil +} + // GetBlockVerboseTxAsync returns an instance of a type that can be used to get // the result of the RPC at some future time by invoking the Receive function on // the returned instance. // // See GetBlockVerboseTx or the blocking version and more details. -func (c *Client) GetBlockVerboseTxAsync(blockHash *chainhash.Hash) FutureGetBlockVerboseResult { +func (c *Client) GetBlockVerboseTxAsync(blockHash *chainhash.Hash) FutureGetBlockVerboseTxResult { + hash := "" if blockHash != nil { hash = blockHash.String() } - cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(true), btcjson.Bool(true)) + cmd := btcjson.NewGetBlockCmd(hash, btcjson.Uint32(2)) + return c.sendCmd(cmd) } @@ -174,7 +197,7 @@ func (c *Client) GetBlockVerboseTxAsync(blockHash *chainhash.Hash) FutureGetBloc // // See GetBlockVerbose if only transaction hashes are preferred. // See GetBlock to retrieve a raw block instead. -func (c *Client) GetBlockVerboseTx(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error) { +func (c *Client) GetBlockVerboseTx(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseTxResult, error) { return c.GetBlockVerboseTxAsync(blockHash).Receive() } diff --git a/rpcserver.go b/rpcserver.go index e762cc1a9d..a56171558a 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1082,13 +1082,13 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i } } - // When the verbose flag isn't set, simply return the serialized block + // When the verbosity value set to 0, simply return the serialized block // as a hex-encoded string. - if c.Verbose != nil && !*c.Verbose { + if *c.Verbosity == 0 { return hex.EncodeToString(blkBytes), nil } - // The verbose flag is set, so generate the JSON object and return it. + // Generate the JSON object and return it. // Deserialize the block. blk, err := btcutil.NewBlockFromBytes(blkBytes) @@ -1117,9 +1117,12 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i nextHashString = nextHash.String() } - params := s.cfg.ChainParams - blockHeader := &blk.MsgBlock().Header - blockReply := btcjson.GetBlockVerboseResult{ + var ( + blockReply interface{} + params = s.cfg.ChainParams + blockHeader = &blk.MsgBlock().Header + ) + baseBlockReply := &btcjson.GetBlockBaseVerboseResult{ Hash: c.Hash, Version: blockHeader.Version, VersionHex: fmt.Sprintf("%08x", blockHeader.Version), @@ -1137,14 +1140,19 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i NextHash: nextHashString, } - if c.VerboseTx == nil || !*c.VerboseTx { + // If verbose level does not match 0 or 1 + // we can consider it 2 (current bitcoin core behavior) + if *c.Verbosity == 1 { transactions := blk.Transactions() txNames := make([]string, len(transactions)) for i, tx := range transactions { txNames[i] = tx.Hash().String() } - blockReply.Tx = txNames + blockReply = btcjson.GetBlockVerboseResult{ + GetBlockBaseVerboseResult: baseBlockReply, + Tx: txNames, + } } else { txns := blk.Transactions() rawTxns := make([]btcjson.TxRawResult, len(txns)) @@ -1157,7 +1165,11 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i } rawTxns[i] = *rawTxn } - blockReply.RawTx = rawTxns + + blockReply = btcjson.GetBlockVerboseTxResult{ + GetBlockBaseVerboseResult: baseBlockReply, + Tx: rawTxns, + } } return blockReply, nil diff --git a/rpcserverhelp.go b/rpcserverhelp.go index cc6935b512..6d84cb497a 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -162,11 +162,13 @@ var helpDescsEnUS = map[string]string{ // GetBlockCmd help. "getblock--synopsis": "Returns information about a block given its hash.", "getblock-hash": "The hash of the block", - "getblock-verbose": "Specifies the block is returned as a JSON object instead of hex-encoded string", - "getblock-verbosetx": "Specifies that each transaction is returned as a JSON object and only applies if the verbose flag is true (btcd extension)", - "getblock--condition0": "verbose=false", - "getblock--condition1": "verbose=true", + "getblock-verbosity": "Specifies the block format returns", + "getblock--condition0": "verbosity=0", + "getblock--condition1": "verbosity=1", + "getblock--condition2": "verbosity=2", "getblock--result0": "Hex-encoded bytes of the serialized block", + "getblock--result1": "JSON object with information about block", + "getblock--result2": "JSON object with information about block and information about each transaction.", // GetBlockChainInfoCmd help. "getblockchaininfo--synopsis": "Returns information about the current blockchain state and the status of any active soft-fork deployments.", @@ -698,7 +700,7 @@ var rpcResultTypes = map[string][]interface{}{ "getaddednodeinfo": {(*[]string)(nil), (*[]btcjson.GetAddedNodeInfoResult)(nil)}, "getbestblock": {(*btcjson.GetBestBlockResult)(nil)}, "getbestblockhash": {(*string)(nil)}, - "getblock": {(*string)(nil), (*btcjson.GetBlockVerboseResult)(nil)}, + "getblock": {(*string)(nil), (*btcjson.GetBlockVerboseResult)(nil), (*btcjson.GetBlockVerboseTxResult)(nil)}, "getblockcount": {(*int64)(nil)}, "getblockhash": {(*string)(nil)}, "getblockheader": {(*string)(nil), (*btcjson.GetBlockHeaderVerboseResult)(nil)}, From 31b2ff47c9e8a92dd16030cd3fbaa35f6168e1cb Mon Sep 17 00:00:00 2001 From: Connor Stein Date: Mon, 23 Dec 2019 11:20:00 -0500 Subject: [PATCH 02/21] fmt --- rpcserver.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index a56171558a..d6265ba8a0 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1151,7 +1151,7 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i blockReply = btcjson.GetBlockVerboseResult{ GetBlockBaseVerboseResult: baseBlockReply, - Tx: txNames, + Tx: txNames, } } else { txns := blk.Transactions() @@ -1168,7 +1168,7 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i blockReply = btcjson.GetBlockVerboseTxResult{ GetBlockBaseVerboseResult: baseBlockReply, - Tx: rawTxns, + Tx: rawTxns, } } From 8337a5ef2a22053fda90967d48c74835e65b09db Mon Sep 17 00:00:00 2001 From: Connor Stein Date: Mon, 23 Dec 2019 12:01:34 -0500 Subject: [PATCH 03/21] fix test --- rpcserverhelp.go | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/rpcserverhelp.go b/rpcserverhelp.go index 6d84cb497a..5d8df658ad 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -239,23 +239,31 @@ var helpDescsEnUS = map[string]string{ "searchrawtransactionsresult-weight": "The transaction's weight (between vsize*4-3 and vsize*4)", // GetBlockVerboseResult help. - "getblockverboseresult-hash": "The hash of the block (same as provided)", - "getblockverboseresult-confirmations": "The number of confirmations", - "getblockverboseresult-size": "The size of the block", - "getblockverboseresult-height": "The height of the block in the block chain", - "getblockverboseresult-version": "The block version", - "getblockverboseresult-versionHex": "The block version in hexadecimal", - "getblockverboseresult-merkleroot": "Root hash of the merkle tree", - "getblockverboseresult-tx": "The transaction hashes (only when verbosetx=false)", - "getblockverboseresult-rawtx": "The transactions as JSON objects (only when verbosetx=true)", - "getblockverboseresult-time": "The block time in seconds since 1 Jan 1970 GMT", - "getblockverboseresult-nonce": "The block nonce", - "getblockverboseresult-bits": "The bits which represent the block difficulty", - "getblockverboseresult-difficulty": "The proof-of-work difficulty as a multiple of the minimum difficulty", - "getblockverboseresult-previousblockhash": "The hash of the previous block", - "getblockverboseresult-nextblockhash": "The hash of the next block (only if there is one)", - "getblockverboseresult-strippedsize": "The size of the block without witness data", - "getblockverboseresult-weight": "The weight of the block", + "getblockverboseresult-tx": "The transaction hashes", + + + // GetBlockVerboseTxResult help + "getblockverbosetxresult-tx": "The transaction hashes (verbosity = 1) or the transactions as JSON objects (verbosity = 2)", + // GetBlockBaseVerboseResult help. + "getblockbaseverboseresult-hash": "The hash of the block (same as provided)", + "getblockbaseverboseresult-confirmations": "The number of confirmations", + "getblockbaseverboseresult-size": "The size of the block", + "getblockbaseverboseresult-height": "The height of the block in the block chain", + "getblockbaseverboseresult-version": "The block version", + "getblockbaseverboseresult-versionHex": "The block version in hexadecimal", + "getblockbaseverboseresult-merkleroot": "Root hash of the merkle tree", + "getblockbaseverboseresult-time": "The block time in seconds since 1 Jan 1970 GMT", + "getblockbaseverboseresult-nonce": "The block nonce", + "getblockbaseverboseresult-bits": "The bits which represent the block difficulty", + "getblockbaseverboseresult-difficulty": "The proof-of-work difficulty as a multiple of the minimum difficulty", + "getblockbaseverboseresult-previousblockhash": "The hash of the previous block", + "getblockbaseverboseresult-nextblockhash": "The hash of the next block (only if there is one)", + "getblockbaseverboseresult-weight": "The weight of the block", + "getblockbaseverboseresult-strippedsize": "The size of the block without witness data", + + + // GetBlockVerboseTxResult help + // "getblockverbosetxresult-tx": "The transaction hashes (verbosity = 1) or the transactions as JSON objects (verbosity = 2)", // GetBlockCountCmd help. "getblockcount--synopsis": "Returns the number of blocks in the longest block chain.", @@ -775,6 +783,7 @@ func (c *helpCacher) rpcMethodHelp(method string) (string, error) { // Look up the result types for the method. resultTypes, ok := rpcResultTypes[method] if !ok { + fmt.Println("result types bad") return "", errors.New("no result types specified for method " + method) } @@ -782,6 +791,7 @@ func (c *helpCacher) rpcMethodHelp(method string) (string, error) { // Generate, cache, and return the help. help, err := btcjson.GenerateHelp(method, helpDescsEnUS, resultTypes...) if err != nil { + fmt.Println("generate fail", err.Error()) return "", err } c.methodHelp[method] = help From 8b0346208a038484961ba5a6cf087712f3fad4be Mon Sep 17 00:00:00 2001 From: Connor Stein Date: Mon, 23 Dec 2019 12:06:24 -0500 Subject: [PATCH 04/21] import --- rpcserverhelp.go | 1 + 1 file changed, 1 insertion(+) diff --git a/rpcserverhelp.go b/rpcserverhelp.go index 5d8df658ad..de34adb6ed 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -7,6 +7,7 @@ package main import ( "errors" + "fmt" "sort" "strings" "sync" From 0caea1ee67bf3a05c5e20d4d9f8721765f2ef382 Mon Sep 17 00:00:00 2001 From: Connor Stein Date: Mon, 23 Dec 2019 12:33:01 -0500 Subject: [PATCH 05/21] fix modules --- go.mod | 8 ++------ go.sum | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 606399481f..2c69fda07b 100644 --- a/go.mod +++ b/go.mod @@ -1,20 +1,16 @@ -module github.com/btcsuite/btcd +module github.com/paxosglobal/btcd 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/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 golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44 ) diff --git a/go.sum b/go.sum index dc773d4775..a6ab0ec4a6 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= +github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng= From 1f3ee44fd340ec4d7733f3d38c687c5070040fcf Mon Sep 17 00:00:00 2001 From: Connor Stein Date: Mon, 23 Dec 2019 14:34:35 -0500 Subject: [PATCH 06/21] more mod fixes --- cmd/debug/btc.go | 42 +++++++++++++++++++++++++++++++++++++ rpcclient/chain.go | 2 +- rpcclient/infrastructure.go | 2 +- rpcclient/notify.go | 2 +- rpcserver.go | 2 +- 5 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 cmd/debug/btc.go diff --git a/cmd/debug/btc.go b/cmd/debug/btc.go new file mode 100644 index 0000000000..9100cc7435 --- /dev/null +++ b/cmd/debug/btc.go @@ -0,0 +1,42 @@ +package main + +import ( + "fmt" + "github.com/btcsuite/btcd/chaincfg/chainhash" + "github.com/paxosglobal/btcd/rpcclient" +) + +func main() { + fmt.Println("vim-go") + connCfg := &rpcclient.ConnConfig{ + Host: "bitcoin.qa.itbitnonprod.com:19348", + User: "itbit", + Pass: "dNcmjINarwQU75gwdrPj", + HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode + DisableTLS: true, // Bitcoin core does not provide TLS by default + } + // Notice the notification parameter is nil since notifications are + // not supported in HTTP POST mode. + fmt.Println("connecting to node") + + btcClient, err := rpcclient.New(connCfg, nil) + if err != nil { + panic(err) + } + fmt.Println("connected") + + h, err := chainhash.NewHashFromStr("0000000000000f46179b523cf5ed1f0e96206592493dc455c0eba2d82b55d2c2") + if err != nil { + panic(err) + } + fmt.Println("getting block") + + block, err := btcClient.GetBlockVerboseTx(h) + if err != nil { + panic(err) + } + for _, tx := range block.Tx { + fmt.Println(tx) + } + fmt.Println(block) +} diff --git a/rpcclient/chain.go b/rpcclient/chain.go index f7fe310e27..7619e6651a 100644 --- a/rpcclient/chain.go +++ b/rpcclient/chain.go @@ -10,9 +10,9 @@ import ( "encoding/hex" "encoding/json" - "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" + "github.com/paxosglobal/btcd/btcjson" ) // FutureGetBestBlockHashResult is a future promise to deliver the result of a diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index 7a8f1885d1..ed2fb8b649 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -24,9 +24,9 @@ import ( "sync/atomic" "time" - "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/go-socks/socks" "github.com/btcsuite/websocket" + "github.com/paxosglobal/btcd/btcjson" ) var ( diff --git a/rpcclient/notify.go b/rpcclient/notify.go index 2454a94696..00abf2a6c2 100644 --- a/rpcclient/notify.go +++ b/rpcclient/notify.go @@ -13,10 +13,10 @@ import ( "fmt" "time" - "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" + "github.com/paxosglobal/btcd/btcjson" ) var ( diff --git a/rpcserver.go b/rpcserver.go index d6265ba8a0..463f0ef977 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -30,7 +30,6 @@ import ( "github.com/btcsuite/btcd/blockchain" "github.com/btcsuite/btcd/blockchain/indexers" "github.com/btcsuite/btcd/btcec" - "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/database" @@ -42,6 +41,7 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/btcsuite/websocket" + "github.com/paxosglobal/btcd/btcjson" ) // API version constants From 50798a2fc4412458141c311e7135b7bf96246ae5 Mon Sep 17 00:00:00 2001 From: Connor Stein Date: Thu, 6 Feb 2020 15:18:27 -0500 Subject: [PATCH 07/21] revert --- btcjson/chainsvrcmds.go | 8 +++-- btcjson/chainsvrcmds_test.go | 43 ++++++++++----------------- btcjson/chainsvrresults.go | 50 ++++++++++++------------------- btcjson/cmdinfo_test.go | 2 +- btcjson/example_test.go | 29 +++++++++--------- btcjson/help.go | 37 +++++++++-------------- btcjson/help_test.go | 2 +- cmd/debug/btc.go | 42 -------------------------- go.mod | 8 +++-- go.sum | 2 -- rpcclient/chain.go | 35 ++++------------------ rpcclient/infrastructure.go | 2 +- rpcclient/notify.go | 2 +- rpcserver.go | 32 +++++++------------- rpcserverhelp.go | 57 ++++++++++++++---------------------- 15 files changed, 117 insertions(+), 234 deletions(-) delete mode 100644 cmd/debug/btc.go diff --git a/btcjson/chainsvrcmds.go b/btcjson/chainsvrcmds.go index 126780dfd5..406357bd06 100644 --- a/btcjson/chainsvrcmds.go +++ b/btcjson/chainsvrcmds.go @@ -130,7 +130,8 @@ func NewGetBestBlockHashCmd() *GetBestBlockHashCmd { // GetBlockCmd defines the getblock JSON-RPC command. type GetBlockCmd struct { Hash string - Verbosity *uint32 `jsonrpcdefault:"1"` + Verbose *bool `jsonrpcdefault:"true"` + VerboseTx *bool `jsonrpcdefault:"false"` } // NewGetBlockCmd returns a new instance which can be used to issue a getblock @@ -138,10 +139,11 @@ type GetBlockCmd struct { // // The parameters which are pointers indicate they are optional. Passing nil // for optional parameters will use the default value. -func NewGetBlockCmd(hash string, verbosity *uint32) *GetBlockCmd { +func NewGetBlockCmd(hash string, verbose, verboseTx *bool) *GetBlockCmd { return &GetBlockCmd{ Hash: hash, - Verbosity: verbosity, + Verbose: verbose, + VerboseTx: verboseTx, } } diff --git a/btcjson/chainsvrcmds_test.go b/btcjson/chainsvrcmds_test.go index 79fccbc776..8cb4ee765a 100644 --- a/btcjson/chainsvrcmds_test.go +++ b/btcjson/chainsvrcmds_test.go @@ -142,15 +142,16 @@ func TestChainSvrCmds(t *testing.T) { { name: "getblock", newCmd: func() (interface{}, error) { - return btcjson.NewCmd("getblock", "123", 0) + return btcjson.NewCmd("getblock", "123") }, staticCmd: func() interface{} { - return btcjson.NewGetBlockCmd("123", btcjson.Uint32(0)) + return btcjson.NewGetBlockCmd("123", nil, nil) }, - marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",0],"id":1}`, + marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123"],"id":1}`, unmarshalled: &btcjson.GetBlockCmd{ Hash: "123", - Verbosity: btcjson.Uint32(0), + Verbose: btcjson.Bool(true), + VerboseTx: btcjson.Bool(false), }, }, { @@ -159,44 +160,32 @@ func TestChainSvrCmds(t *testing.T) { // Intentionally use a source param that is // more pointers than the destination to // exercise that path. - verbosityPtr := btcjson.Uint32(1) - return btcjson.NewCmd("getblock", "123", &verbosityPtr) + verbosePtr := btcjson.Bool(true) + return btcjson.NewCmd("getblock", "123", &verbosePtr) }, staticCmd: func() interface{} { - return btcjson.NewGetBlockCmd("123", btcjson.Uint32(1)) + return btcjson.NewGetBlockCmd("123", btcjson.Bool(true), nil) }, - marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",1],"id":1}`, + marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",true],"id":1}`, unmarshalled: &btcjson.GetBlockCmd{ Hash: "123", - Verbosity: btcjson.Uint32(1), + Verbose: btcjson.Bool(true), + VerboseTx: btcjson.Bool(false), }, }, { name: "getblock required optional2", newCmd: func() (interface{}, error) { - return btcjson.NewCmd("getblock", "123", 2) + return btcjson.NewCmd("getblock", "123", true, true) }, staticCmd: func() interface{} { - return btcjson.NewGetBlockCmd("123", btcjson.Uint32(2)) + return btcjson.NewGetBlockCmd("123", btcjson.Bool(true), btcjson.Bool(true)) }, - marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",2],"id":1}`, - unmarshalled: &btcjson.GetBlockCmd{ - Hash: "123", - Verbosity: btcjson.Uint32(2), - }, - }, - { - name: "getblock; default verbose level must be 1", - newCmd: func() (interface{}, error) { - return btcjson.NewCmd("getblock", "123") - }, - staticCmd: func() interface{} { - return btcjson.NewGetBlockCmd("123", nil) - }, - marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123"],"id":1}`, + marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",true,true],"id":1}`, unmarshalled: &btcjson.GetBlockCmd{ Hash: "123", - Verbosity: btcjson.Uint32(1), + Verbose: btcjson.Bool(true), + VerboseTx: btcjson.Bool(true), }, }, { diff --git a/btcjson/chainsvrresults.go b/btcjson/chainsvrresults.go index 25d0b646aa..7e6c710766 100644 --- a/btcjson/chainsvrresults.go +++ b/btcjson/chainsvrresults.go @@ -24,39 +24,27 @@ type GetBlockHeaderVerboseResult struct { NextHash string `json:"nextblockhash,omitempty"` } -// GetBlockBaseVerboseResult models the common data from the getblock command when -// verbose flag set to 1 or 2. When the verbose flag is not set, getblock -// returns a hex-encoded string. -type GetBlockBaseVerboseResult struct { - Hash string `json:"hash"` - Confirmations int64 `json:"confirmations"` - StrippedSize int32 `json:"strippedsize"` - Size int32 `json:"size"` - Weight int32 `json:"weight"` - Height int64 `json:"height"` - Version int32 `json:"version"` - VersionHex string `json:"versionHex"` - MerkleRoot string `json:"merkleroot"` - Time int64 `json:"time"` - Nonce uint32 `json:"nonce"` - Bits string `json:"bits"` - Difficulty float64 `json:"difficulty"` - PreviousHash string `json:"previousblockhash"` - NextHash string `json:"nextblockhash,omitempty"` -} - // GetBlockVerboseResult models the data from the getblock command when the -// verbose flag is set to 1 (default). +// verbose flag is set. When the verbose flag is not set, getblock returns a +// hex-encoded string. type GetBlockVerboseResult struct { - *GetBlockBaseVerboseResult - Tx []string `json:"tx,omitempty"` -} - -// GetBlockVerboseTxResult models the data from the getblock command when the -// verbose flag is set to 2. -type GetBlockVerboseTxResult struct { - *GetBlockBaseVerboseResult - Tx []TxRawResult `json:"tx,omitempty"` + Hash string `json:"hash"` + Confirmations int64 `json:"confirmations"` + StrippedSize int32 `json:"strippedsize"` + Size int32 `json:"size"` + Weight int32 `json:"weight"` + Height int64 `json:"height"` + Version int32 `json:"version"` + VersionHex string `json:"versionHex"` + MerkleRoot string `json:"merkleroot"` + Tx []string `json:"tx,omitempty"` + RawTx []TxRawResult `json:"rawtx,omitempty"` + Time int64 `json:"time"` + Nonce uint32 `json:"nonce"` + Bits string `json:"bits"` + Difficulty float64 `json:"difficulty"` + PreviousHash string `json:"previousblockhash"` + NextHash string `json:"nextblockhash,omitempty"` } // CreateMultiSigResult models the data returned from the createmultisig diff --git a/btcjson/cmdinfo_test.go b/btcjson/cmdinfo_test.go index 61a693e404..044040279a 100644 --- a/btcjson/cmdinfo_test.go +++ b/btcjson/cmdinfo_test.go @@ -151,7 +151,7 @@ func TestMethodUsageText(t *testing.T) { { name: "getblock", method: "getblock", - expected: `getblock "hash" (verbosity=1)`, + expected: `getblock "hash" (verbose=true verbosetx=false)`, }, } diff --git a/btcjson/example_test.go b/btcjson/example_test.go index e18a30692c..527252c7fb 100644 --- a/btcjson/example_test.go +++ b/btcjson/example_test.go @@ -11,18 +11,17 @@ import ( "github.com/btcsuite/btcd/btcjson" ) -// Create a new getblock command. Notice the call to btcjson.Uint32 which is a -// convenience function for creating a pointer out of a primitive for -// optional parameters. Notice the nil parameter indicates -// to use the default parameter for that fields. This is a common -// pattern used in all of the NewCmdr functions in this package for -// optional fields. +// This example demonstrates how to create and marshal a command into a JSON-RPC +// request. func ExampleMarshalCmd() { - // Create a new getblock command. + // Create a new getblock command. Notice the nil parameter indicates + // to use the default parameter for that fields. This is a common + // pattern used in all of the NewCmd functions in this package for + // optional fields. Also, notice the call to btcjson.Bool which is a + // convenience function for creating a pointer out of a primitive for + // optional parameters. blockHash := "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" - gbCmd := btcjson.NewGetBlockCmd(blockHash, btcjson.Uint32(2)) - // or - // gbCmd := btcjson.NewGetBlockCmd(blockHash, nil) + gbCmd := btcjson.NewGetBlockCmd(blockHash, btcjson.Bool(false), nil) // Marshal the command to the format suitable for sending to the RPC // server. Typically the client would increment the id here which is @@ -39,7 +38,7 @@ func ExampleMarshalCmd() { fmt.Printf("%s\n", marshalledBytes) // Output: - // {"jsonrpc":"1.0","method":"getblock","params":["000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",2],"id":1} + // {"jsonrpc":"1.0","method":"getblock","params":["000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",false],"id":1} } // This example demonstrates how to unmarshal a JSON-RPC request and then @@ -47,7 +46,7 @@ func ExampleMarshalCmd() { func ExampleUnmarshalCmd() { // Ordinarily this would be read from the wire, but for this example, // it is hard coded here for clarity. - data := []byte(`{"jsonrpc":"1.0","method":"getblock","params":["000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",0],"id":1}`) + data := []byte(`{"jsonrpc":"1.0","method":"getblock","params":["000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",false],"id":1}`) // Unmarshal the raw bytes from the wire into a JSON-RPC request. var request btcjson.Request @@ -85,11 +84,13 @@ func ExampleUnmarshalCmd() { // Display the fields in the concrete command. fmt.Println("Hash:", gbCmd.Hash) - fmt.Println("Verbosity:", *gbCmd.Verbosity) + fmt.Println("Verbose:", *gbCmd.Verbose) + fmt.Println("VerboseTx:", *gbCmd.VerboseTx) // Output: // Hash: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f - // Verbosity: 0 + // Verbose: false + // VerboseTx: false } // This example demonstrates how to marshal a JSON-RPC response. diff --git a/btcjson/help.go b/btcjson/help.go index ed3bd7931f..f502d09fd8 100644 --- a/btcjson/help.go +++ b/btcjson/help.go @@ -110,8 +110,8 @@ func resultStructHelp(xT descLookupFunc, rt reflect.Type, indentLevel int) []str fieldType := reflectTypeToJSONType(xT, rtfType) fieldDescKey := typeName + "-" + fieldName fieldExamples, isComplex := reflectTypeToJSONExample(xT, - rtfType, indentLevel, fieldDescKey, rtf.Anonymous) - if isComplex && !rtf.Anonymous { + rtfType, indentLevel, fieldDescKey) + if isComplex { var brace string kind := rtfType.Kind() if kind == reflect.Array || kind == reflect.Slice { @@ -123,8 +123,6 @@ func resultStructHelp(xT descLookupFunc, rt reflect.Type, indentLevel int) []str fieldName, brace, fieldType, xT(fieldDescKey)) results = append(results, result) results = append(results, fieldExamples...) - } else if isComplex && rtf.Anonymous { - results = append(results, fieldExamples...) } else { result := fmt.Sprintf("%s\"%s\": %s,\t(%s)\t%s", indent, fieldName, fieldExamples[0], fieldType, @@ -142,7 +140,7 @@ func resultStructHelp(xT descLookupFunc, rt reflect.Type, indentLevel int) []str // a tab writer. A bool is also returned which specifies whether or not the // type results in a complex JSON object since they need to be handled // differently. -func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel int, fieldDescKey string, embeddedStruct bool) ([]string, bool) { +func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel int, fieldDescKey string) ([]string, bool) { // Indirect pointer if needed. if rt.Kind() == reflect.Ptr { rt = rt.Elem() @@ -165,12 +163,7 @@ func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel in case reflect.Struct: indent := strings.Repeat(" ", indentLevel) - nextIndentLevel := indentLevel - - if !embeddedStruct { - nextIndentLevel++ - } - results := resultStructHelp(xT, rt, nextIndentLevel) + results := resultStructHelp(xT, rt, indentLevel+1) // An opening brace is needed for the first indent level. For // all others, it will be included as a part of the previous @@ -181,22 +174,20 @@ func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel in copy(newResults[1:], results) results = newResults } - if !embeddedStruct { - // The closing brace has a comma after it except for the first - // indent level. The final tabs are necessary so the tab writer - // lines things up properly. - closingBrace := indent + "}" - if indentLevel > 0 { - closingBrace += "," - } - results = append(results, closingBrace+"\t\t") - } + // The closing brace has a comma after it except for the first + // indent level. The final tabs are necessary so the tab writer + // lines things up properly. + closingBrace := indent + "}" + if indentLevel > 0 { + closingBrace += "," + } + results = append(results, closingBrace+"\t\t") return results, true case reflect.Array, reflect.Slice: results, isComplex := reflectTypeToJSONExample(xT, rt.Elem(), - indentLevel, fieldDescKey, false) + indentLevel, fieldDescKey) // When the result is complex, it is because this is an array of // objects. @@ -260,7 +251,7 @@ func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel in // type. func resultTypeHelp(xT descLookupFunc, rt reflect.Type, fieldDescKey string) string { // Generate the JSON example for the result type. - results, isComplex := reflectTypeToJSONExample(xT, rt, 0, fieldDescKey, false) + results, isComplex := reflectTypeToJSONExample(xT, rt, 0, fieldDescKey) // When this is a primitive type, add the associated JSON type and // result description into the final string, format it accordingly, diff --git a/btcjson/help_test.go b/btcjson/help_test.go index ee406ee4e9..918aa14479 100644 --- a/btcjson/help_test.go +++ b/btcjson/help_test.go @@ -246,7 +246,7 @@ func TestHelpReflectInternals(t *testing.T) { // Ensure the generated example is as expected. examples, isComplex := btcjson.TstReflectTypeToJSONExample(xT, - test.reflectType, test.indentLevel, "fdk", false) + test.reflectType, test.indentLevel, "fdk") if isComplex != test.isComplex { t.Errorf("Test #%d (%s) unexpected isComplex - got: %v, "+ "want: %v", i, test.name, isComplex, diff --git a/cmd/debug/btc.go b/cmd/debug/btc.go deleted file mode 100644 index 9100cc7435..0000000000 --- a/cmd/debug/btc.go +++ /dev/null @@ -1,42 +0,0 @@ -package main - -import ( - "fmt" - "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/paxosglobal/btcd/rpcclient" -) - -func main() { - fmt.Println("vim-go") - connCfg := &rpcclient.ConnConfig{ - Host: "bitcoin.qa.itbitnonprod.com:19348", - User: "itbit", - Pass: "dNcmjINarwQU75gwdrPj", - HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode - DisableTLS: true, // Bitcoin core does not provide TLS by default - } - // Notice the notification parameter is nil since notifications are - // not supported in HTTP POST mode. - fmt.Println("connecting to node") - - btcClient, err := rpcclient.New(connCfg, nil) - if err != nil { - panic(err) - } - fmt.Println("connected") - - h, err := chainhash.NewHashFromStr("0000000000000f46179b523cf5ed1f0e96206592493dc455c0eba2d82b55d2c2") - if err != nil { - panic(err) - } - fmt.Println("getting block") - - block, err := btcClient.GetBlockVerboseTx(h) - if err != nil { - panic(err) - } - for _, tx := range block.Tx { - fmt.Println(tx) - } - fmt.Println(block) -} diff --git a/go.mod b/go.mod index 2c69fda07b..606399481f 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,20 @@ -module github.com/paxosglobal/btcd +module github.com/btcsuite/btcd require ( - github.com/btcsuite/btcd v0.20.1-beta + github.com/aead/siphash v1.0.1 // indirect 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/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 golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44 ) diff --git a/go.sum b/go.sum index a6ab0ec4a6..dc773d4775 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= -github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= -github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng= diff --git a/rpcclient/chain.go b/rpcclient/chain.go index 7619e6651a..996d80458c 100644 --- a/rpcclient/chain.go +++ b/rpcclient/chain.go @@ -10,9 +10,9 @@ import ( "encoding/hex" "encoding/json" + "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" - "github.com/paxosglobal/btcd/btcjson" ) // FutureGetBestBlockHashResult is a future promise to deliver the result of a @@ -97,7 +97,7 @@ func (c *Client) GetBlockAsync(blockHash *chainhash.Hash) FutureGetBlockResult { hash = blockHash.String() } - cmd := btcjson.NewGetBlockCmd(hash, btcjson.Uint32(0)) + cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(false), nil) return c.sendCmd(cmd) } @@ -141,7 +141,7 @@ func (c *Client) GetBlockVerboseAsync(blockHash *chainhash.Hash) FutureGetBlockV hash = blockHash.String() } - cmd := btcjson.NewGetBlockCmd(hash, btcjson.Uint32(1)) + cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(true), nil) return c.sendCmd(cmd) } @@ -154,41 +154,18 @@ func (c *Client) GetBlockVerbose(blockHash *chainhash.Hash) (*btcjson.GetBlockVe return c.GetBlockVerboseAsync(blockHash).Receive() } -// FutureGetBlockVerboseTxResult is a future promise to deliver the result of a -// GetBlockVerboseTxAsync RPC invocation (or an applicable error). -type FutureGetBlockVerboseTxResult chan *response - -// Receive waits for the response promised by the future and returns the data -// structure from the server with information about the requested block. -func (r FutureGetBlockVerboseTxResult) Receive() (*btcjson.GetBlockVerboseTxResult, error) { - res, err := receiveFuture(r) - if err != nil { - return nil, err - } - - // Unmarshal the raw result into a BlockResult. - var blockResult btcjson.GetBlockVerboseTxResult - err = json.Unmarshal(res, &blockResult) - if err != nil { - return nil, err - } - return &blockResult, nil -} - // GetBlockVerboseTxAsync returns an instance of a type that can be used to get // the result of the RPC at some future time by invoking the Receive function on // the returned instance. // // See GetBlockVerboseTx or the blocking version and more details. -func (c *Client) GetBlockVerboseTxAsync(blockHash *chainhash.Hash) FutureGetBlockVerboseTxResult { - +func (c *Client) GetBlockVerboseTxAsync(blockHash *chainhash.Hash) FutureGetBlockVerboseResult { hash := "" if blockHash != nil { hash = blockHash.String() } - cmd := btcjson.NewGetBlockCmd(hash, btcjson.Uint32(2)) - + cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(true), btcjson.Bool(true)) return c.sendCmd(cmd) } @@ -197,7 +174,7 @@ func (c *Client) GetBlockVerboseTxAsync(blockHash *chainhash.Hash) FutureGetBloc // // See GetBlockVerbose if only transaction hashes are preferred. // See GetBlock to retrieve a raw block instead. -func (c *Client) GetBlockVerboseTx(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseTxResult, error) { +func (c *Client) GetBlockVerboseTx(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error) { return c.GetBlockVerboseTxAsync(blockHash).Receive() } diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index ed2fb8b649..7a8f1885d1 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -24,9 +24,9 @@ import ( "sync/atomic" "time" + "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/go-socks/socks" "github.com/btcsuite/websocket" - "github.com/paxosglobal/btcd/btcjson" ) var ( diff --git a/rpcclient/notify.go b/rpcclient/notify.go index 00abf2a6c2..2454a94696 100644 --- a/rpcclient/notify.go +++ b/rpcclient/notify.go @@ -13,10 +13,10 @@ import ( "fmt" "time" + "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/paxosglobal/btcd/btcjson" ) var ( diff --git a/rpcserver.go b/rpcserver.go index 463f0ef977..e762cc1a9d 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -30,6 +30,7 @@ import ( "github.com/btcsuite/btcd/blockchain" "github.com/btcsuite/btcd/blockchain/indexers" "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/database" @@ -41,7 +42,6 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/btcsuite/websocket" - "github.com/paxosglobal/btcd/btcjson" ) // API version constants @@ -1082,13 +1082,13 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i } } - // When the verbosity value set to 0, simply return the serialized block + // When the verbose flag isn't set, simply return the serialized block // as a hex-encoded string. - if *c.Verbosity == 0 { + if c.Verbose != nil && !*c.Verbose { return hex.EncodeToString(blkBytes), nil } - // Generate the JSON object and return it. + // The verbose flag is set, so generate the JSON object and return it. // Deserialize the block. blk, err := btcutil.NewBlockFromBytes(blkBytes) @@ -1117,12 +1117,9 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i nextHashString = nextHash.String() } - var ( - blockReply interface{} - params = s.cfg.ChainParams - blockHeader = &blk.MsgBlock().Header - ) - baseBlockReply := &btcjson.GetBlockBaseVerboseResult{ + params := s.cfg.ChainParams + blockHeader := &blk.MsgBlock().Header + blockReply := btcjson.GetBlockVerboseResult{ Hash: c.Hash, Version: blockHeader.Version, VersionHex: fmt.Sprintf("%08x", blockHeader.Version), @@ -1140,19 +1137,14 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i NextHash: nextHashString, } - // If verbose level does not match 0 or 1 - // we can consider it 2 (current bitcoin core behavior) - if *c.Verbosity == 1 { + if c.VerboseTx == nil || !*c.VerboseTx { transactions := blk.Transactions() txNames := make([]string, len(transactions)) for i, tx := range transactions { txNames[i] = tx.Hash().String() } - blockReply = btcjson.GetBlockVerboseResult{ - GetBlockBaseVerboseResult: baseBlockReply, - Tx: txNames, - } + blockReply.Tx = txNames } else { txns := blk.Transactions() rawTxns := make([]btcjson.TxRawResult, len(txns)) @@ -1165,11 +1157,7 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i } rawTxns[i] = *rawTxn } - - blockReply = btcjson.GetBlockVerboseTxResult{ - GetBlockBaseVerboseResult: baseBlockReply, - Tx: rawTxns, - } + blockReply.RawTx = rawTxns } return blockReply, nil diff --git a/rpcserverhelp.go b/rpcserverhelp.go index de34adb6ed..cc6935b512 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -7,7 +7,6 @@ package main import ( "errors" - "fmt" "sort" "strings" "sync" @@ -163,13 +162,11 @@ var helpDescsEnUS = map[string]string{ // GetBlockCmd help. "getblock--synopsis": "Returns information about a block given its hash.", "getblock-hash": "The hash of the block", - "getblock-verbosity": "Specifies the block format returns", - "getblock--condition0": "verbosity=0", - "getblock--condition1": "verbosity=1", - "getblock--condition2": "verbosity=2", + "getblock-verbose": "Specifies the block is returned as a JSON object instead of hex-encoded string", + "getblock-verbosetx": "Specifies that each transaction is returned as a JSON object and only applies if the verbose flag is true (btcd extension)", + "getblock--condition0": "verbose=false", + "getblock--condition1": "verbose=true", "getblock--result0": "Hex-encoded bytes of the serialized block", - "getblock--result1": "JSON object with information about block", - "getblock--result2": "JSON object with information about block and information about each transaction.", // GetBlockChainInfoCmd help. "getblockchaininfo--synopsis": "Returns information about the current blockchain state and the status of any active soft-fork deployments.", @@ -240,31 +237,23 @@ var helpDescsEnUS = map[string]string{ "searchrawtransactionsresult-weight": "The transaction's weight (between vsize*4-3 and vsize*4)", // GetBlockVerboseResult help. - "getblockverboseresult-tx": "The transaction hashes", - - - // GetBlockVerboseTxResult help - "getblockverbosetxresult-tx": "The transaction hashes (verbosity = 1) or the transactions as JSON objects (verbosity = 2)", - // GetBlockBaseVerboseResult help. - "getblockbaseverboseresult-hash": "The hash of the block (same as provided)", - "getblockbaseverboseresult-confirmations": "The number of confirmations", - "getblockbaseverboseresult-size": "The size of the block", - "getblockbaseverboseresult-height": "The height of the block in the block chain", - "getblockbaseverboseresult-version": "The block version", - "getblockbaseverboseresult-versionHex": "The block version in hexadecimal", - "getblockbaseverboseresult-merkleroot": "Root hash of the merkle tree", - "getblockbaseverboseresult-time": "The block time in seconds since 1 Jan 1970 GMT", - "getblockbaseverboseresult-nonce": "The block nonce", - "getblockbaseverboseresult-bits": "The bits which represent the block difficulty", - "getblockbaseverboseresult-difficulty": "The proof-of-work difficulty as a multiple of the minimum difficulty", - "getblockbaseverboseresult-previousblockhash": "The hash of the previous block", - "getblockbaseverboseresult-nextblockhash": "The hash of the next block (only if there is one)", - "getblockbaseverboseresult-weight": "The weight of the block", - "getblockbaseverboseresult-strippedsize": "The size of the block without witness data", - - - // GetBlockVerboseTxResult help - // "getblockverbosetxresult-tx": "The transaction hashes (verbosity = 1) or the transactions as JSON objects (verbosity = 2)", + "getblockverboseresult-hash": "The hash of the block (same as provided)", + "getblockverboseresult-confirmations": "The number of confirmations", + "getblockverboseresult-size": "The size of the block", + "getblockverboseresult-height": "The height of the block in the block chain", + "getblockverboseresult-version": "The block version", + "getblockverboseresult-versionHex": "The block version in hexadecimal", + "getblockverboseresult-merkleroot": "Root hash of the merkle tree", + "getblockverboseresult-tx": "The transaction hashes (only when verbosetx=false)", + "getblockverboseresult-rawtx": "The transactions as JSON objects (only when verbosetx=true)", + "getblockverboseresult-time": "The block time in seconds since 1 Jan 1970 GMT", + "getblockverboseresult-nonce": "The block nonce", + "getblockverboseresult-bits": "The bits which represent the block difficulty", + "getblockverboseresult-difficulty": "The proof-of-work difficulty as a multiple of the minimum difficulty", + "getblockverboseresult-previousblockhash": "The hash of the previous block", + "getblockverboseresult-nextblockhash": "The hash of the next block (only if there is one)", + "getblockverboseresult-strippedsize": "The size of the block without witness data", + "getblockverboseresult-weight": "The weight of the block", // GetBlockCountCmd help. "getblockcount--synopsis": "Returns the number of blocks in the longest block chain.", @@ -709,7 +698,7 @@ var rpcResultTypes = map[string][]interface{}{ "getaddednodeinfo": {(*[]string)(nil), (*[]btcjson.GetAddedNodeInfoResult)(nil)}, "getbestblock": {(*btcjson.GetBestBlockResult)(nil)}, "getbestblockhash": {(*string)(nil)}, - "getblock": {(*string)(nil), (*btcjson.GetBlockVerboseResult)(nil), (*btcjson.GetBlockVerboseTxResult)(nil)}, + "getblock": {(*string)(nil), (*btcjson.GetBlockVerboseResult)(nil)}, "getblockcount": {(*int64)(nil)}, "getblockhash": {(*string)(nil)}, "getblockheader": {(*string)(nil), (*btcjson.GetBlockHeaderVerboseResult)(nil)}, @@ -784,7 +773,6 @@ func (c *helpCacher) rpcMethodHelp(method string) (string, error) { // Look up the result types for the method. resultTypes, ok := rpcResultTypes[method] if !ok { - fmt.Println("result types bad") return "", errors.New("no result types specified for method " + method) } @@ -792,7 +780,6 @@ func (c *helpCacher) rpcMethodHelp(method string) (string, error) { // Generate, cache, and return the help. help, err := btcjson.GenerateHelp(method, helpDescsEnUS, resultTypes...) if err != nil { - fmt.Println("generate fail", err.Error()) return "", err } c.methodHelp[method] = help From f7f3d19fddf98ccd5e84ef698ab5caa5dfba9c1a Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 15:29:27 -0500 Subject: [PATCH 08/21] logs --- integration/rpctest/rpc_harness.go | 1 + rpcclient/infrastructure.go | 1 + 2 files changed, 2 insertions(+) diff --git a/integration/rpctest/rpc_harness.go b/integration/rpctest/rpc_harness.go index 1c2612e47b..19e204cec3 100644 --- a/integration/rpctest/rpc_harness.go +++ b/integration/rpctest/rpc_harness.go @@ -315,6 +315,7 @@ func (h *Harness) connectRPCClient() error { for i := 0; i < h.maxConnRetries; 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 diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index 7a8f1885d1..c62e6ce6fd 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -1262,6 +1262,7 @@ 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 { From a8d73cccd53e26c65e7973026079c98b93c49164 Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 15:34:35 -0500 Subject: [PATCH 09/21] try go mod --- go.mod | 8 ++------ go.sum | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 606399481f..2c69fda07b 100644 --- a/go.mod +++ b/go.mod @@ -1,20 +1,16 @@ -module github.com/btcsuite/btcd +module github.com/paxosglobal/btcd 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/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 golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44 ) diff --git a/go.sum b/go.sum index dc773d4775..a6ab0ec4a6 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= +github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng= From 8ad9ff1a426722b73bbb425de0024f4713f3c216 Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 15:36:32 -0500 Subject: [PATCH 10/21] a log --- integration/rpctest/rpc_harness.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integration/rpctest/rpc_harness.go b/integration/rpctest/rpc_harness.go index 19e204cec3..5bd30b38c2 100644 --- a/integration/rpctest/rpc_harness.go +++ b/integration/rpctest/rpc_harness.go @@ -102,6 +102,7 @@ func New(activeNet *chaincfg.Params, handlers *rpcclient.NotificationHandlers, harnessStateMtx.Lock() defer harnessStateMtx.Unlock() + fmt.Println("new rpc harness") // Add a flag for the appropriate network type based on the provided // chain params. From 42724fa80bf0eedf372f745c876e6e4a6977373f Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 16:28:43 -0500 Subject: [PATCH 11/21] rpcclient too --- integration/rpctest/rpc_harness.go | 2 +- rpcclient/infrastructure.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/integration/rpctest/rpc_harness.go b/integration/rpctest/rpc_harness.go index 5bd30b38c2..b86adbf6c2 100644 --- a/integration/rpctest/rpc_harness.go +++ b/integration/rpctest/rpc_harness.go @@ -17,7 +17,7 @@ import ( "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/btcsuite/btcd/rpcclient" + "github.com/paxosglobal/btcd/rpcclient" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" ) diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index c62e6ce6fd..b1f6324cb8 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -1270,6 +1270,7 @@ func New(config *ConnConfig, ntfnHandlers *NotificationHandlers) (*Client, error var err error wsConn, err = dial(config) if err != nil { + fmt.Println("unable to connect ws", err.Error()) return nil, err } start = true From d0903b768de23ed94d0f776a68035b88b6c6878a Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 16:30:50 -0500 Subject: [PATCH 12/21] m --- integration/rpctest/rpc_harness.go | 1 - integration/rpctest/utils.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/integration/rpctest/rpc_harness.go b/integration/rpctest/rpc_harness.go index b86adbf6c2..8214416cc0 100644 --- a/integration/rpctest/rpc_harness.go +++ b/integration/rpctest/rpc_harness.go @@ -102,7 +102,6 @@ func New(activeNet *chaincfg.Params, handlers *rpcclient.NotificationHandlers, harnessStateMtx.Lock() defer harnessStateMtx.Unlock() - fmt.Println("new rpc harness") // Add a flag for the appropriate network type based on the provided // chain params. diff --git a/integration/rpctest/utils.go b/integration/rpctest/utils.go index fc7d938dcf..8456ee1eff 100644 --- a/integration/rpctest/utils.go +++ b/integration/rpctest/utils.go @@ -9,7 +9,7 @@ import ( "time" "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/btcsuite/btcd/rpcclient" + "github.com/paxosglobal/btcd/rpcclient" ) // JoinType is an enum representing a particular type of "node join". A node From 12a9374c9834d02be5d18ecf935537a7ad985f81 Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 16:33:34 -0500 Subject: [PATCH 13/21] try replace --- go.mod | 7 +++++++ go.sum | 29 +++++++++++++++++------------ integration/rpctest/rpc_harness.go | 2 +- integration/rpctest/utils.go | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 2c69fda07b..b28a58a6f6 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,23 @@ module github.com/paxosglobal/btcd +replace github.com/btcsuite/btcd => github.com/paxosglobal/btcd v0.20.1-beta.0.20200206213050-d0903b768de2 + 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 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 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 ) diff --git a/go.sum b/go.sum index a6ab0ec4a6..e5afbd999d 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= -github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= -github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng= @@ -10,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= @@ -28,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= @@ -43,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= diff --git a/integration/rpctest/rpc_harness.go b/integration/rpctest/rpc_harness.go index 8214416cc0..19e204cec3 100644 --- a/integration/rpctest/rpc_harness.go +++ b/integration/rpctest/rpc_harness.go @@ -17,7 +17,7 @@ import ( "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/paxosglobal/btcd/rpcclient" + "github.com/btcsuite/btcd/rpcclient" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" ) diff --git a/integration/rpctest/utils.go b/integration/rpctest/utils.go index 8456ee1eff..fc7d938dcf 100644 --- a/integration/rpctest/utils.go +++ b/integration/rpctest/utils.go @@ -9,7 +9,7 @@ import ( "time" "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/paxosglobal/btcd/rpcclient" + "github.com/btcsuite/btcd/rpcclient" ) // JoinType is an enum representing a particular type of "node join". A node From e587e95b5f31c71a5f60dc25c686bf184861082a Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 16:52:54 -0500 Subject: [PATCH 14/21] specify retries --- integration/bip0009_test.go | 4 ++-- integration/csv_fork_test.go | 4 ++-- integration/rpcserver_test.go | 2 +- integration/rpctest/rpc_harness.go | 10 ++++++---- integration/rpctest/rpc_harness_test.go | 10 +++++----- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/integration/bip0009_test.go b/integration/bip0009_test.go index df3721b1e6..7f11a3b9b4 100644 --- a/integration/bip0009_test.go +++ b/integration/bip0009_test.go @@ -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() @@ -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() diff --git a/integration/csv_fork_test.go b/integration/csv_fork_test.go index 345217c864..b83e72ea77 100644 --- a/integration/csv_fork_test.go +++ b/integration/csv_fork_test.go @@ -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() @@ -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() diff --git a/integration/rpcserver_test.go b/integration/rpcserver_test.go index df526442be..a51ccda0e5 100644 --- a/integration/rpcserver_test.go +++ b/integration/rpcserver_test.go @@ -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 diff --git a/integration/rpctest/rpc_harness.go b/integration/rpctest/rpc_harness.go index 19e204cec3..7af9edb014 100644 --- a/integration/rpctest/rpc_harness.go +++ b/integration/rpctest/rpc_harness.go @@ -34,6 +34,8 @@ const ( // BlockVersion is the default block version used when generating // blocks. BlockVersion = 4 + + defaultConnRetries = 20 ) var ( @@ -213,13 +215,13 @@ 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 { // 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 { return err } @@ -307,12 +309,12 @@ 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()) diff --git a/integration/rpctest/rpc_harness_test.go b/integration/rpctest/rpc_harness_test.go index 717f8f45af..2720d5be80 100644 --- a/integration/rpctest/rpc_harness_test.go +++ b/integration/rpctest/rpc_harness_test.go @@ -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() @@ -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() @@ -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() @@ -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() @@ -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 From 3e2d6044e60d6f9187cc7fc929316054611832e0 Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 17:30:22 -0500 Subject: [PATCH 15/21] use post mode --- integration/rpctest/node.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integration/rpctest/node.go b/integration/rpctest/node.go index 6aec2b1168..e8ceac781e 100644 --- a/integration/rpctest/node.go +++ b/integration/rpctest/node.go @@ -150,6 +150,7 @@ func (n *nodeConfig) rpcConnConfig() rpc.ConnConfig { Pass: n.rpcPass, Certificates: n.certificates, DisableAutoReconnect: true, + HTTPPostMode: true, } } From 3b5c56ee9ef7f522bb46764f7ff8bc04ffcb2a07 Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 18:04:20 -0500 Subject: [PATCH 16/21] disable tls --- integration/rpctest/node.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/rpctest/node.go b/integration/rpctest/node.go index e8ceac781e..1f8bc7059d 100644 --- a/integration/rpctest/node.go +++ b/integration/rpctest/node.go @@ -150,7 +150,7 @@ func (n *nodeConfig) rpcConnConfig() rpc.ConnConfig { Pass: n.rpcPass, Certificates: n.certificates, DisableAutoReconnect: true, - HTTPPostMode: true, + DisableTLS: true, } } From 438bd2666ba2aa06d48379f372969f970b5cd104 Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 21:35:18 -0500 Subject: [PATCH 17/21] log ports --- integration/rpctest/rpc_harness.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integration/rpctest/rpc_harness.go b/integration/rpctest/rpc_harness.go index 7af9edb014..8333bb55f3 100644 --- a/integration/rpctest/rpc_harness.go +++ b/integration/rpctest/rpc_harness.go @@ -492,6 +492,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 } From a31b7e403fe4cd66fbd9a329d3d7d019c524e45e Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 22:28:11 -0500 Subject: [PATCH 18/21] log around bootup --- integration/rpctest/node.go | 4 ++++ integration/rpctest/rpc_harness.go | 1 + 2 files changed, 5 insertions(+) diff --git a/integration/rpctest/node.go b/integration/rpctest/node.go index 1f8bc7059d..57e0dbcb42 100644 --- a/integration/rpctest/node.go +++ b/integration/rpctest/node.go @@ -202,6 +202,7 @@ 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 } @@ -221,6 +222,7 @@ func (n *node) start() error { return err } + fmt.Println("created pid file", n.cmd.Process.Pid) return nil } @@ -237,6 +239,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) } @@ -246,6 +249,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) } diff --git a/integration/rpctest/rpc_harness.go b/integration/rpctest/rpc_harness.go index 8333bb55f3..aa77d0e83a 100644 --- a/integration/rpctest/rpc_harness.go +++ b/integration/rpctest/rpc_harness.go @@ -274,6 +274,7 @@ func (h *Harness) SetUp(createTestChain bool, numMatureOutputs uint32, connRetri // // 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() } From e9c70b11e324a338cd9c7f598aae7dc0e8b07cca Mon Sep 17 00:00:00 2001 From: connorwstein Date: Thu, 6 Feb 2020 23:09:07 -0500 Subject: [PATCH 19/21] exit status? --- integration/rpctest/node.go | 8 +++++++- integration/rpctest/rpc_harness.go | 1 + rpcclient/infrastructure.go | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/integration/rpctest/node.go b/integration/rpctest/node.go index 57e0dbcb42..0b21ba3cfa 100644 --- a/integration/rpctest/node.go +++ b/integration/rpctest/node.go @@ -206,6 +206,11 @@ func (n *node) start() error { 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))) @@ -222,7 +227,8 @@ func (n *node) start() error { return err } - fmt.Println("created pid file", n.cmd.Process.Pid) + fmt.Println("created pid file", n.cmd.Process.Pid, filepath.Join(n.dataDir, + fmt.Sprintf("%s.pid", n.config))) return nil } diff --git a/integration/rpctest/rpc_harness.go b/integration/rpctest/rpc_harness.go index aa77d0e83a..f88258469f 100644 --- a/integration/rpctest/rpc_harness.go +++ b/integration/rpctest/rpc_harness.go @@ -222,6 +222,7 @@ func (h *Harness) SetUp(createTestChain bool, numMatureOutputs uint32, connRetri return err } if err := h.connectRPCClient(connRetries); err != nil { + fmt.Println("process state", h.node.cmd.ProcessState.String()) return err } diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index b1f6324cb8..5c37242d83 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -1296,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) From 28f85a0ff9816800dcf4cacc57191599585465f0 Mon Sep 17 00:00:00 2001 From: connorwstein Date: Mon, 2 Mar 2020 15:08:09 -0500 Subject: [PATCH 20/21] enable tls --- integration/rpctest/node.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integration/rpctest/node.go b/integration/rpctest/node.go index 0b21ba3cfa..9cbe139df2 100644 --- a/integration/rpctest/node.go +++ b/integration/rpctest/node.go @@ -150,7 +150,6 @@ func (n *nodeConfig) rpcConnConfig() rpc.ConnConfig { Pass: n.rpcPass, Certificates: n.certificates, DisableAutoReconnect: true, - DisableTLS: true, } } From b86a005fa0f44f2cfa2416755011d31b5d04ed02 Mon Sep 17 00:00:00 2001 From: connorwstein Date: Mon, 2 Mar 2020 15:37:35 -0500 Subject: [PATCH 21/21] Revert "enable tls" This reverts commit 28f85a0ff9816800dcf4cacc57191599585465f0. --- integration/rpctest/node.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integration/rpctest/node.go b/integration/rpctest/node.go index 9cbe139df2..0b21ba3cfa 100644 --- a/integration/rpctest/node.go +++ b/integration/rpctest/node.go @@ -150,6 +150,7 @@ func (n *nodeConfig) rpcConnConfig() rpc.ConnConfig { Pass: n.rpcPass, Certificates: n.certificates, DisableAutoReconnect: true, + DisableTLS: true, } }