multi: remove getblocktemplate.

This removes the getblocktemplate and its helpers from the codebase.
Ongoing mining updates focused on the voting/block validation process
 with respect to generating block templates  for getwork makes it the
better option for decred.  Also getblocktemplate rpc was buggy and
has been disabled for a while.

Some lint related issues have been addressed as well.
This commit is contained in:
Donald Adu-Poku 2019-09-05 12:11:00 +00:00 committed by Dave Collins
parent 38203c8f4d
commit 1bae334dd9
27 changed files with 34 additions and 1383 deletions

View File

@ -297,8 +297,7 @@ type headerNode struct {
// PeerNotifier provides an interface for server peer notifications.
type PeerNotifier interface {
// AnnounceNewTransactions generates and relays inventory vectors and
// notifies both websocket and getblocktemplate long poll clients of
// the passed transactions.
// notifies websocket clients of the passed transactions.
AnnounceNewTransactions(txns []*dcrutil.Tx)
// UpdatePeerHeights updates the heights of all peers who have
@ -1071,13 +1070,6 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) {
// Clear the rejected transactions.
b.rejectedTxns = make(map[chainhash.Hash]struct{})
// Allow any clients performing long polling via the
// getblocktemplate RPC to be notified when the new block causes
// their old block template to become stale.
if r := b.cfg.RpcServer(); r != nil {
r.gbtWorkState.NotifyBlockConnected(blockHash)
}
}
}
@ -1646,13 +1638,6 @@ out:
b.cfg.TxMemPool.PruneExpiredTx()
}
// Allow any clients performing long polling via the
// getblocktemplate RPC to be notified when the new block causes
// their old block template to become stale.
if r != nil {
r.gbtWorkState.NotifyBlockConnected(msg.block.Hash())
}
msg.reply <- processBlockResponse{
isOrphan: isOrphan,
err: nil,

View File

@ -20,7 +20,7 @@ import (
"github.com/decred/dcrd/dcrutil/v2"
"github.com/decred/dcrd/internal/version"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
wallettypes "github.com/decred/dcrwallet/rpc/jsonrpc/types"
flags "github.com/jessevdk/go-flags"

View File

@ -16,7 +16,7 @@ import (
"strings"
"github.com/decred/dcrd/dcrjson/v3"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
wallettypes "github.com/decred/dcrwallet/rpc/jsonrpc/types"
)

View File

@ -27,7 +27,7 @@ import (
"github.com/decred/dcrd/dcrutil/v2"
"github.com/decred/dcrd/internal/version"
"github.com/decred/dcrd/mempool/v3"
"github.com/decred/dcrd/rpc/jsonrpc/types"
"github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/sampleconfig"
"github.com/decred/go-socks/socks"
"github.com/decred/slog"

View File

@ -610,7 +610,7 @@ func (m *CPUMiner) GenerateNBlocks(n uint32) ([]*chainhash.Hash, error) {
if m.started || m.discreteMining {
m.Unlock()
return nil, errors.New("server is already CPU mining. Please call " +
"`setgenerate 0` before calling discrete `generate` commands.")
"`setgenerate 0` before calling discrete `generate` commands")
}
m.started = true

6
go.mod
View File

@ -25,7 +25,7 @@ require (
github.com/decred/dcrd/mempool/v3 v3.0.0
github.com/decred/dcrd/mining/v2 v2.0.0
github.com/decred/dcrd/peer/v2 v2.0.0
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0
github.com/decred/dcrd/rpc/jsonrpc/types/v2 v2.0.0
github.com/decred/dcrd/rpcclient/v5 v5.0.0
github.com/decred/dcrd/txscript/v2 v2.0.0
github.com/decred/dcrd/wire v1.2.0
@ -36,12 +36,10 @@ require (
github.com/jessevdk/go-flags v1.4.0
github.com/jrick/bitset v1.0.0
github.com/jrick/logrotate v1.0.0
github.com/kr/pretty v0.1.0 // indirect
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)
@ -66,7 +64,7 @@ replace (
github.com/decred/dcrd/mempool/v3 => ./mempool
github.com/decred/dcrd/mining/v2 => ./mining
github.com/decred/dcrd/peer/v2 => ./peer
github.com/decred/dcrd/rpc/jsonrpc/types => ./rpc/jsonrpc/types
github.com/decred/dcrd/rpc/jsonrpc/types/v2 => ./rpc/jsonrpc/types
github.com/decred/dcrd/rpcclient/v5 => ./rpcclient
github.com/decred/dcrd/txscript/v2 => ./txscript
github.com/decred/dcrd/wire => ./wire

12
go.sum
View File

@ -9,7 +9,6 @@ github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46f
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/blake256 v1.0.0/go.mod h1:xXNWCE1jsAP8DAjP+rKw2MbeqLczjI3TRx2VK+9OEYY=
github.com/dchest/blake256 v1.1.0 h1:4AuEhGPT/3TTKFhTfBpZ8hgZE7wJpawcYaEawwsbtqM=
github.com/dchest/blake256 v1.1.0/go.mod h1:xXNWCE1jsAP8DAjP+rKw2MbeqLczjI3TRx2VK+9OEYY=
github.com/dchest/siphash v1.2.1 h1:4cLinnzVJDKxTCl9B01807Yiy+W7ZzVHj/KIroQRvT4=
@ -25,8 +24,8 @@ github.com/decred/dcrd/dcrec/edwards v1.0.0/go.mod h1:HblVh1OfMt7xSxUL1ufjToaEvp
github.com/decred/dcrd/dcrec/secp256k1 v1.0.1/go.mod h1:lhu4eZFSfTJWUnR3CFRcpD+Vta0KUAqnhTsTksHXgy0=
github.com/decred/dcrd/dcrec/secp256k1 v1.0.2 h1:awk7sYJ4pGWmtkiGHFfctztJjHMKGLV8jctGQhAbKe0=
github.com/decred/dcrd/dcrec/secp256k1 v1.0.2/go.mod h1:CHTUIVfmDDd0KFVFpNX1pFVCBUegxW387nN0IGwNKR0=
github.com/decred/dcrd/gcs v1.1.0 h1:djuYzaFUzUTJR+6ulMSRZOQ+P9rxtIyuxQeViAEfB8s=
github.com/decred/dcrd/gcs v1.1.0/go.mod h1:yBjhj217Vw5lw3aKnCdHip7fYb9zwMos8bCy5s79M9w=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0 h1:d5ptnjuSADTQMa3i83VpeJNoMRTOJZZBqk7P+E41VXM=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0/go.mod h1:0dwmpIP21tJxjg/UuUHWIFMbfoLv2ifCBMokNKlOxpo=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.1.0 h1:ZOMpbSK/Cz8D8Yfrt7/yNfS+myBUWMNOdgAg31ND7bM=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.1.0/go.mod h1:xUT7XXATLOzE0pwwmvgfRWtZdrB+PsWFilo+jkH5/Ig=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.2.0 h1:k17F1rYmYRqX3iO8nQBrSacbB8A50qNU+HT3gfNo4dw=
@ -49,11 +48,6 @@ github.com/jrick/bitset v1.0.0 h1:Ws0PXV3PwXqWK2n7Vz6idCdrV/9OrBXgHEJi27ZB9Dw=
github.com/jrick/bitset v1.0.0/go.mod h1:ZOYB5Uvkla7wIEY4FEssPVi3IQXa02arznRaYaAEPe4=
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/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
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=
@ -81,8 +75,6 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
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/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/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=

View File

@ -9,9 +9,6 @@
package types
import (
"encoding/json"
"fmt"
"github.com/decred/dcrd/dcrjson/v3"
)
@ -463,94 +460,6 @@ func NewGetBlockSubsidyCmd(height int64, voters uint16) *GetBlockSubsidyCmd {
}
}
// TemplateRequest is a request object as defined in BIP22
// (https://en.bitcoin.it/wiki/BIP_0022), it is optionally provided as an
// pointer argument to GetBlockTemplateCmd.
type TemplateRequest struct {
Mode string `json:"mode,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
// Optional long polling.
LongPollID string `json:"longpollid,omitempty"`
// Optional template tweaking. SigOpLimit and SizeLimit can be int64
// or bool.
SigOpLimit interface{} `json:"sigoplimit,omitempty"`
SizeLimit interface{} `json:"sizelimit,omitempty"`
MaxVersion uint32 `json:"maxversion,omitempty"`
// Basic pool extension from BIP 0023.
Target string `json:"target,omitempty"`
// Block proposal from BIP 0023. Data is only provided when Mode is
// "proposal".
Data string `json:"data,omitempty"`
WorkID string `json:"workid,omitempty"`
}
// convertTemplateRequestField potentially converts the provided value as
// needed.
func convertTemplateRequestField(fieldName string, iface interface{}) (interface{}, error) {
switch val := iface.(type) {
case nil:
return nil, nil
case bool:
return val, nil
case float64:
if val == float64(int64(val)) {
return int64(val), nil
}
}
str := fmt.Sprintf("the %s field must be unspecified, a boolean, or "+
"a 64-bit integer", fieldName)
return nil, dcrjson.Error{Code: dcrjson.ErrInvalidType, Message: str}
}
// UnmarshalJSON provides a custom Unmarshal method for TemplateRequest. This
// is necessary because the SigOpLimit and SizeLimit fields can only be specific
// types.
func (t *TemplateRequest) UnmarshalJSON(data []byte) error {
type templateRequest TemplateRequest
request := (*templateRequest)(t)
if err := json.Unmarshal(data, &request); err != nil {
return err
}
// The SigOpLimit field can only be nil, bool, or int64.
val, err := convertTemplateRequestField("sigoplimit", request.SigOpLimit)
if err != nil {
return err
}
request.SigOpLimit = val
// The SizeLimit field can only be nil, bool, or int64.
val, err = convertTemplateRequestField("sizelimit", request.SizeLimit)
if err != nil {
return err
}
request.SizeLimit = val
return nil
}
// GetBlockTemplateCmd defines the getblocktemplate JSON-RPC command.
type GetBlockTemplateCmd struct {
Request *TemplateRequest
}
// NewGetBlockTemplateCmd returns a new instance which can be used to issue a
// getblocktemplate JSON-RPC command.
//
// The parameters which are pointers indicate they are optional. Passing nil
// for optional parameters will use the default value.
func NewGetBlockTemplateCmd(request *TemplateRequest) *GetBlockTemplateCmd {
return &GetBlockTemplateCmd{
Request: request,
}
}
// GetCFilterCmd defines the getcfilter JSON-RPC command.
type GetCFilterCmd struct {
Hash string
@ -1226,7 +1135,6 @@ func init() {
dcrjson.MustRegister(Method("getblockhash"), (*GetBlockHashCmd)(nil), flags)
dcrjson.MustRegister(Method("getblockheader"), (*GetBlockHeaderCmd)(nil), flags)
dcrjson.MustRegister(Method("getblocksubsidy"), (*GetBlockSubsidyCmd)(nil), flags)
dcrjson.MustRegister(Method("getblocktemplate"), (*GetBlockTemplateCmd)(nil), flags)
dcrjson.MustRegister(Method("getcfilter"), (*GetCFilterCmd)(nil), flags)
dcrjson.MustRegister(Method("getcfilterheader"), (*GetCFilterHeaderCmd)(nil), flags)
dcrjson.MustRegister(Method("getchaintips"), (*GetChainTipsCmd)(nil), flags)

View File

@ -343,89 +343,6 @@ func TestChainSvrCmds(t *testing.T) {
Voters: 256,
},
},
{
name: "getblocktemplate",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd(Method("getblocktemplate"))
},
staticCmd: func() interface{} {
return NewGetBlockTemplateCmd(nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getblocktemplate","params":[],"id":1}`,
unmarshalled: &GetBlockTemplateCmd{Request: nil},
},
{
name: "getblocktemplate optional - template request",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd(Method("getblocktemplate"), `{"mode":"template","capabilities":["longpoll","coinbasetxn"]}`)
},
staticCmd: func() interface{} {
template := TemplateRequest{
Mode: "template",
Capabilities: []string{"longpoll", "coinbasetxn"},
}
return NewGetBlockTemplateCmd(&template)
},
marshalled: `{"jsonrpc":"1.0","method":"getblocktemplate","params":[{"mode":"template","capabilities":["longpoll","coinbasetxn"]}],"id":1}`,
unmarshalled: &GetBlockTemplateCmd{
Request: &TemplateRequest{
Mode: "template",
Capabilities: []string{"longpoll", "coinbasetxn"},
},
},
},
{
name: "getblocktemplate optional - template request with tweaks",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd(Method("getblocktemplate"), `{"mode":"template","capabilities":["longpoll","coinbasetxn"],"sigoplimit":500,"sizelimit":100000000,"maxversion":2}`)
},
staticCmd: func() interface{} {
template := TemplateRequest{
Mode: "template",
Capabilities: []string{"longpoll", "coinbasetxn"},
SigOpLimit: 500,
SizeLimit: 100000000,
MaxVersion: 2,
}
return NewGetBlockTemplateCmd(&template)
},
marshalled: `{"jsonrpc":"1.0","method":"getblocktemplate","params":[{"mode":"template","capabilities":["longpoll","coinbasetxn"],"sigoplimit":500,"sizelimit":100000000,"maxversion":2}],"id":1}`,
unmarshalled: &GetBlockTemplateCmd{
Request: &TemplateRequest{
Mode: "template",
Capabilities: []string{"longpoll", "coinbasetxn"},
SigOpLimit: int64(500),
SizeLimit: int64(100000000),
MaxVersion: 2,
},
},
},
{
name: "getblocktemplate optional - template request with tweaks 2",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd(Method("getblocktemplate"), `{"mode":"template","capabilities":["longpoll","coinbasetxn"],"sigoplimit":true,"sizelimit":100000000,"maxversion":2}`)
},
staticCmd: func() interface{} {
template := TemplateRequest{
Mode: "template",
Capabilities: []string{"longpoll", "coinbasetxn"},
SigOpLimit: true,
SizeLimit: 100000000,
MaxVersion: 2,
}
return NewGetBlockTemplateCmd(&template)
},
marshalled: `{"jsonrpc":"1.0","method":"getblocktemplate","params":[{"mode":"template","capabilities":["longpoll","coinbasetxn"],"sigoplimit":true,"sizelimit":100000000,"maxversion":2}],"id":1}`,
unmarshalled: &GetBlockTemplateCmd{
Request: &TemplateRequest{
Mode: "template",
Capabilities: []string{"longpoll", "coinbasetxn"},
SigOpLimit: true,
SizeLimit: int64(100000000),
MaxVersion: 2,
},
},
},
{
name: "getcfilter",
newCmd: func() (interface{}, error) {
@ -1250,55 +1167,3 @@ func TestChainSvrCmds(t *testing.T) {
}
}
}
// TestChainSvrCmdErrors ensures any errors that occur in the command during
// custom marshal and unmarshal are as expected.
func TestChainSvrCmdErrors(t *testing.T) {
t.Parallel()
tests := []struct {
name string
result interface{}
marshalled string
err error
}{
{
name: "template request with invalid type",
result: &TemplateRequest{},
marshalled: `{"mode":1}`,
err: &json.UnmarshalTypeError{},
},
{
name: "invalid template request sigoplimit field",
result: &TemplateRequest{},
marshalled: `{"sigoplimit":"invalid"}`,
err: dcrjson.Error{Code: dcrjson.ErrInvalidType},
},
{
name: "invalid template request sizelimit field",
result: &TemplateRequest{},
marshalled: `{"sizelimit":"invalid"}`,
err: dcrjson.Error{Code: dcrjson.ErrInvalidType},
},
}
t.Logf("Running %d tests", len(tests))
for i, test := range tests {
err := json.Unmarshal([]byte(test.marshalled), &test.result)
if reflect.TypeOf(err) != reflect.TypeOf(test.err) {
t.Errorf("Test #%d (%s) wrong error type - got `%T` (%v), got `%T`",
i, test.name, err, err, test.err)
continue
}
if terr, ok := test.err.(dcrjson.Error); ok {
gotErrorCode := err.(dcrjson.Error).Code
if gotErrorCode != terr.Code {
t.Errorf("Test #%d (%s) mismatched error code "+
"- got %v (%v), want %v", i, test.name,
gotErrorCode, terr, terr.Code)
continue
}
}
}
}

View File

@ -159,61 +159,6 @@ type GetBlockSubsidyResult struct {
Total int64 `json:"total"`
}
// GetBlockTemplateResultTx models the transactions field of the
// getblocktemplate command.
type GetBlockTemplateResultTx struct {
Data string `json:"data"`
Hash string `json:"hash"`
Depends []int64 `json:"depends"`
Fee int64 `json:"fee"`
SigOps int64 `json:"sigops"`
TxType string `json:"txtype"`
}
// GetBlockTemplateResultAux models the coinbaseaux field of the
// getblocktemplate command.
type GetBlockTemplateResultAux struct {
Flags string `json:"flags"`
}
// GetBlockTemplateResult models the data returned from the getblocktemplate
// command.
type GetBlockTemplateResult struct {
// Base fields from BIP 0022. CoinbaseAux is optional. One of
// CoinbaseTxn or CoinbaseValue must be specified, but not both.
// GBT has been modified from the Bitcoin semantics to include
// the header rather than various components which are all part
// of the header anyway.
Header string `json:"header"`
SigOpLimit int64 `json:"sigoplimit,omitempty"`
SizeLimit int64 `json:"sizelimit,omitempty"`
Transactions []GetBlockTemplateResultTx `json:"transactions"`
STransactions []GetBlockTemplateResultTx `json:"stransactions"`
CoinbaseAux *GetBlockTemplateResultAux `json:"coinbaseaux,omitempty"`
CoinbaseTxn *GetBlockTemplateResultTx `json:"coinbasetxn,omitempty"`
CoinbaseValue *int64 `json:"coinbasevalue,omitempty"`
WorkID string `json:"workid,omitempty"`
// Optional long polling from BIP 0022.
LongPollID string `json:"longpollid,omitempty"`
LongPollURI string `json:"longpolluri,omitempty"`
SubmitOld *bool `json:"submitold,omitempty"`
// Basic pool extension from BIP 0023.
Target string `json:"target,omitempty"`
Expires int64 `json:"expires,omitempty"`
// Mutations from BIP 0023.
MaxTime int64 `json:"maxtime,omitempty"`
MinTime int64 `json:"mintime,omitempty"`
Mutable []string `json:"mutable,omitempty"`
NonceRange string `json:"noncerange,omitempty"`
// Block proposal from BIP 0023.
Capabilities []string `json:"capabilities,omitempty"`
RejectReasion string `json:"reject-reason,omitempty"`
}
// GetChainTipsResult models the data returns from the getchaintips command.
type GetChainTipsResult struct {
Height int64 `json:"height"`

View File

@ -1,4 +1,4 @@
module github.com/decred/dcrd/rpc/jsonrpc/types
module github.com/decred/dcrd/rpc/jsonrpc/types/v2
go 1.11

View File

@ -16,7 +16,7 @@ import (
"github.com/decred/dcrd/dcrutil/v2"
"github.com/decred/dcrd/gcs/v2"
"github.com/decred/dcrd/gcs/v2/blockcf"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/wire"
)

View File

@ -13,7 +13,7 @@ import (
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/dcrjson/v3"
"github.com/decred/dcrd/dcrutil/v2"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/wire"
walletjson "github.com/decred/dcrwallet/rpc/jsonrpc/types"
)

View File

@ -10,6 +10,7 @@ require (
github.com/decred/dcrd/gcs/v2 v2.0.0-00010101000000-000000000000
github.com/decred/dcrd/hdkeychain/v2 v2.0.1
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0
github.com/decred/dcrd/rpc/jsonrpc/types/v2 v2.0.0-00010101000000-000000000000
github.com/decred/dcrd/wire v1.2.0
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.1.0
github.com/decred/go-socks v1.0.0
@ -17,4 +18,7 @@ require (
github.com/gorilla/websocket v1.4.0
)
replace github.com/decred/dcrd/gcs/v2 => ../gcs
replace (
github.com/decred/dcrd/gcs/v2 => ../gcs
github.com/decred/dcrd/rpc/jsonrpc/types/v2 => ../rpc/jsonrpc/types
)

View File

@ -28,7 +28,7 @@ import (
"github.com/gorilla/websocket"
"github.com/decred/dcrd/dcrjson/v3"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/go-socks/socks"
)

View File

@ -12,7 +12,7 @@ import (
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/dcrutil/v2"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
)
// FutureGenerateResult is a future promise to deliver the result of a
@ -364,45 +364,6 @@ func (c *Client) GetWorkSubmit(data string) (bool, error) {
return c.GetWorkSubmitAsync(data).Receive()
}
// FutureGetBlockTemplate is a future promise to deliver the result of a
// GetBlockTemplateAsync RPC invocation (or an applicable error).
type FutureGetBlockTemplate chan *response
// Receive waits for the response promised by the future and returns an error if
// any occurred while generating the block template.
func (r FutureGetBlockTemplate) Receive() (*chainjson.GetBlockTemplateResult, error) {
res, err := receiveFuture(r)
if err != nil {
return nil, err
}
// Unmarshal result.
var gbt chainjson.GetBlockTemplateResult
err = json.Unmarshal(res, &gbt)
if err != nil {
return nil, err
}
return &gbt, nil
}
// GetBlockTemplateAsync 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
// on the returned instance.
//
// See GetBlockTemplate for the blocking version and more details.
func (c *Client) GetBlockTemplateAsync(req *chainjson.TemplateRequest) FutureGetBlockTemplate {
cmd := chainjson.NewGetBlockTemplateCmd(req)
return c.sendCmd(cmd)
}
// GetBlockTemplate returns a block template to work on.
//
// See SubmitBlock to submit the found solution.
func (c *Client) GetBlockTemplate(req *chainjson.TemplateRequest) (*chainjson.GetBlockTemplateResult, error) {
return c.GetBlockTemplateAsync(req).Receive()
}
// FutureSubmitBlockResult is a future promise to deliver the result of a
// SubmitBlockAsync RPC invocation (or an applicable error).
type FutureSubmitBlockResult chan *response

View File

@ -8,7 +8,7 @@ package rpcclient
import (
"encoding/json"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
)
// AddNodeCommand enumerates the available commands that the AddNode function

View File

@ -14,7 +14,7 @@ import (
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/dcrutil/v2"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/wire"
walletjson "github.com/decred/dcrwallet/rpc/jsonrpc/types"
)

View File

@ -13,7 +13,7 @@ import (
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/dcrjson/v3"
"github.com/decred/dcrd/dcrutil/v2"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/wire"
walletjson "github.com/decred/dcrwallet/rpc/jsonrpc/types"
)

View File

@ -13,7 +13,8 @@ import (
"github.com/decred/dcrd/dcrjson/v3"
"github.com/decred/dcrd/dcrutil/v2"
"github.com/decred/dcrd/hdkeychain/v2"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
chainjsonv1 "github.com/decred/dcrd/rpc/jsonrpc/types"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/wire"
walletjson "github.com/decred/dcrwallet/rpc/jsonrpc/types"
)
@ -336,9 +337,9 @@ func (r FutureLockUnspentResult) Receive() error {
//
// See LockUnspent for the blocking version and more details.
func (c *Client) LockUnspentAsync(unlock bool, ops []*wire.OutPoint) FutureLockUnspentResult {
outputs := make([]chainjson.TransactionInput, len(ops))
outputs := make([]chainjsonv1.TransactionInput, len(ops))
for i, op := range ops {
outputs[i] = chainjson.TransactionInput{
outputs[i] = chainjsonv1.TransactionInput{
Txid: op.Hash.String(),
Vout: op.Index,
Tree: op.Tree,

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ import (
"sync"
"github.com/decred/dcrd/dcrjson/v3"
"github.com/decred/dcrd/rpc/jsonrpc/types"
"github.com/decred/dcrd/rpc/jsonrpc/types/v2"
)
// helpDescsEnUS defines the English descriptions used for the help strings.
@ -376,64 +376,6 @@ var helpDescsEnUS = map[string]string{
"getblocksubsidyresult-pow": "The Proof-of-Work subsidy",
"getblocksubsidyresult-total": "The total subsidy",
// TemplateRequest help.
"templaterequest-mode": "This is 'template', 'proposal', or omitted",
"templaterequest-capabilities": "List of capabilities",
"templaterequest-longpollid": "The long poll ID of a job to monitor for expiration; required and valid only for long poll requests",
"templaterequest-sigoplimit": "Number of signature operations allowed in blocks (this parameter is ignored)",
"templaterequest-sizelimit": "Number of bytes allowed in blocks (this parameter is ignored)",
"templaterequest-maxversion": "Highest supported block version number (this parameter is ignored)",
"templaterequest-target": "The desired target for the block template (this parameter is ignored)",
"templaterequest-data": "Hex-encoded block data (only for mode=proposal)",
"templaterequest-workid": "The server provided workid if provided in block template (not applicable)",
// GetBlockTemplateResultTx help.
"getblocktemplateresulttx-data": "Hex-encoded transaction data (byte-for-byte)",
"getblocktemplateresulttx-hash": "Hex-encoded transaction hash (little endian if treated as a 256-bit number)",
"getblocktemplateresulttx-depends": "Other transactions before this one (by 1-based index in the 'transactions' list) that must be present in the final block if this one is",
"getblocktemplateresulttx-fee": "Difference in value between transaction inputs and outputs (in Atoms)",
"getblocktemplateresulttx-sigops": "Total number of signature operations as counted for purposes of block limits",
"getblocktemplateresulttx-txtype": "Type of the transaction",
// GetBlockTemplateResultAux help.
"getblocktemplateresultaux-flags": "Hex-encoded byte-for-byte data to include in the coinbase signature script",
// GetBlockTemplateResult help.
"getblocktemplateresult-bits": "Hex-encoded compressed difficulty",
"getblocktemplateresult-curtime": "Current time as seen by the server (recommended for block time); must fall within mintime/maxtime rules",
"getblocktemplateresult-height": "Height of the block to be solved",
"getblocktemplateresult-previousblockhash": "Hex-encoded big-endian hash of the previous block",
"getblocktemplateresult-sigoplimit": "Number of sigops allowed in blocks",
"getblocktemplateresult-sizelimit": "Number of bytes allowed in blocks",
"getblocktemplateresult-transactions": "Array of transactions as JSON objects",
"getblocktemplateresult-version": "The block version",
"getblocktemplateresult-coinbaseaux": "Data that should be included in the coinbase signature script",
"getblocktemplateresult-coinbasetxn": "Information about the coinbase transaction",
"getblocktemplateresult-coinbasevalue": "Total amount available for the coinbase in Atoms",
"getblocktemplateresult-workid": "This value must be returned with result if provided (not provided)",
"getblocktemplateresult-longpollid": "Identifier for long poll request which allows monitoring for expiration",
"getblocktemplateresult-longpolluri": "An alternate URI to use for long poll requests if provided (not provided)",
"getblocktemplateresult-submitold": "Not applicable",
"getblocktemplateresult-target": "Hex-encoded big-endian number which valid results must be less than",
"getblocktemplateresult-expires": "Maximum number of seconds (starting from when the server sent the response) this work is valid for",
"getblocktemplateresult-maxtime": "Maximum allowed time",
"getblocktemplateresult-mintime": "Minimum allowed time",
"getblocktemplateresult-mutable": "List of mutations the server explicitly allows",
"getblocktemplateresult-noncerange": "Two concatenated hex-encoded big-endian 32-bit integers which represent the valid ranges of nonces the miner may scan",
"getblocktemplateresult-capabilities": "List of server capabilities including 'proposal' to indicate support for block proposals",
"getblocktemplateresult-reject-reason": "Reason the proposal was invalid as-is (only applies to proposal responses)",
"getblocktemplateresult-stransactions": "Stake transactions",
"getblocktemplateresult-header": "Block header",
// GetBlockTemplateCmd help.
"getblocktemplate--synopsis": "Returns a JSON object with information necessary to construct a block to mine or accepts a proposal to validate.\n" +
"See BIP0022 and BIP0023 for the full specification.",
"getblocktemplate-request": "Request object which controls the mode and several parameters",
"getblocktemplate--condition0": "mode=template",
"getblocktemplate--condition1": "mode=proposal, rejected",
"getblocktemplate--condition2": "mode=proposal, accepted",
"getblocktemplate--result1": "An error string which represents why the proposal was rejected or nothing if accepted",
// GetCFilterCmd help.
"getcfilter--synopsis": "Returns the committed filter for a block",
"getcfilter--result0": "The committed filter serialized with the N value and encoded as a hex string",
@ -998,7 +940,6 @@ var rpcResultTypes = map[types.Method][]interface{}{
"getblockhash": {(*string)(nil)},
"getblockheader": {(*string)(nil), (*types.GetBlockHeaderVerboseResult)(nil)},
"getblocksubsidy": {(*types.GetBlockSubsidyResult)(nil)},
"getblocktemplate": {(*types.GetBlockTemplateResult)(nil), (*string)(nil), nil},
"getcfilter": {(*string)(nil)},
"getcfilterheader": {(*string)(nil)},
"getchaintips": {(*[]types.GetChainTipsResult)(nil)},

View File

@ -17,7 +17,7 @@ import (
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v2"
"github.com/decred/dcrd/dcrutil/v2"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/txscript/v2"
"github.com/decred/dcrd/wire"
)

View File

@ -9,7 +9,7 @@ import (
"reflect"
"time"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/rpcclient/v5"
)

View File

@ -17,7 +17,7 @@ import (
"github.com/decred/dcrd/dcrec"
"github.com/decred/dcrd/dcrec/secp256k1"
"github.com/decred/dcrd/dcrutil/v2"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/rpcclient/v5"
"github.com/decred/dcrd/txscript/v2"
"github.com/decred/dcrd/wire"

View File

@ -28,7 +28,7 @@ import (
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/dcrjson/v3"
"github.com/decred/dcrd/dcrutil/v2"
"github.com/decred/dcrd/rpc/jsonrpc/types"
"github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/txscript/v2"
"github.com/decred/dcrd/wire"
)

View File

@ -1213,9 +1213,8 @@ func (s *server) PruneRebroadcastInventory() {
}
// AnnounceNewTransactions generates and relays inventory vectors and notifies
// both websocket and getblocktemplate long poll clients of the passed
// transactions. This function should be called whenever new transactions
// are added to the mempool.
// websocket clients of the passed transactions. This function should be
// called whenever new transactions are added to the mempool.
func (s *server) AnnounceNewTransactions(txns []*dcrutil.Tx) {
// Generate and relay inventory vectors for all newly accepted
// transactions into the memory pool due to the original being
@ -1228,10 +1227,6 @@ func (s *server) AnnounceNewTransactions(txns []*dcrutil.Tx) {
if s.rpcServer != nil {
// Notify websocket clients about mempool transactions.
s.rpcServer.ntfnMgr.NotifyMempoolTx(tx, true)
// Potentially notify any getblocktemplate long poll clients
// about stale block templates due to the new transaction.
s.rpcServer.gbtWorkState.NotifyMempoolTx(s.txMemPool.LastUpdated())
}
}
}