Merge pull request #737 from wpaulino/block-from-network
chain: request pruned blocks from backend peers
This commit is contained in:
commit
683061f797
11 changed files with 1658 additions and 75 deletions
|
@ -10,7 +10,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
|
@ -40,10 +39,6 @@ type BitcoindClient struct {
|
|||
// chain.
|
||||
birthday time.Time
|
||||
|
||||
// chainParams are the parameters of the current chain this client is
|
||||
// active under.
|
||||
chainParams *chaincfg.Params
|
||||
|
||||
// id is the unique ID of this client assigned by the backing bitcoind
|
||||
// connection.
|
||||
id uint64
|
||||
|
@ -145,7 +140,7 @@ func (c *BitcoindClient) GetBlockHeight(hash *chainhash.Hash) (int32, error) {
|
|||
|
||||
// GetBlock returns a block from the hash.
|
||||
func (c *BitcoindClient) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error) {
|
||||
return c.chainConn.client.GetBlock(hash)
|
||||
return c.chainConn.GetBlock(hash)
|
||||
}
|
||||
|
||||
// GetBlockVerbose returns a verbose block from the hash.
|
||||
|
@ -920,7 +915,7 @@ func (c *BitcoindClient) reorg(currentBlock waddrmgr.BlockStamp,
|
|||
func (c *BitcoindClient) FilterBlocks(
|
||||
req *FilterBlocksRequest) (*FilterBlocksResponse, error) {
|
||||
|
||||
blockFilterer := NewBlockFilterer(c.chainParams, req)
|
||||
blockFilterer := NewBlockFilterer(c.chainConn.cfg.ChainParams, req)
|
||||
|
||||
// Iterate over the requested blocks, fetching each from the rpc client.
|
||||
// Each block will scanned using the reverse addresses indexes generated
|
||||
|
@ -1282,7 +1277,7 @@ func (c *BitcoindClient) filterTx(tx *wire.MsgTx,
|
|||
// Non-standard outputs can be safely skipped.
|
||||
continue
|
||||
}
|
||||
addr, err := pkScript.Address(c.chainParams)
|
||||
addr, err := pkScript.Address(c.chainConn.cfg.ChainParams)
|
||||
if err != nil {
|
||||
// Non-standard outputs can be safely skipped.
|
||||
continue
|
||||
|
@ -1298,7 +1293,7 @@ func (c *BitcoindClient) filterTx(tx *wire.MsgTx,
|
|||
// add it to our watch list.
|
||||
for i, txOut := range tx.TxOut {
|
||||
_, addrs, _, err := txscript.ExtractPkScriptAddrs(
|
||||
txOut.PkScript, c.chainParams,
|
||||
txOut.PkScript, c.chainConn.cfg.ChainParams,
|
||||
)
|
||||
if err != nil {
|
||||
// Non-standard outputs can be safely skipped.
|
||||
|
|
|
@ -9,11 +9,13 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightninglabs/gozmq"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -36,26 +38,74 @@ const (
|
|||
// seqNumLen is the length of the sequence number of a message sent from
|
||||
// bitcoind through ZMQ.
|
||||
seqNumLen = 4
|
||||
|
||||
// errBlockPrunedStr is the error message returned by bitcoind upon
|
||||
// calling GetBlock on a pruned block.
|
||||
errBlockPrunedStr = "Block not available (pruned data)"
|
||||
)
|
||||
|
||||
// BitcoindConfig contains all of the parameters required to establish a
|
||||
// connection to a bitcoind's RPC.
|
||||
type BitcoindConfig struct {
|
||||
// ChainParams are the chain parameters the bitcoind server is running
|
||||
// on.
|
||||
ChainParams *chaincfg.Params
|
||||
|
||||
// Host is the IP address and port of the bitcoind's RPC server.
|
||||
Host string
|
||||
|
||||
// User is the username to use to authenticate to bitcoind's RPC server.
|
||||
User string
|
||||
|
||||
// Pass is the passphrase to use to authenticate to bitcoind's RPC
|
||||
// server.
|
||||
Pass string
|
||||
|
||||
// ZMQBlockHost is the IP address and port of the bitcoind's rawblock
|
||||
// listener.
|
||||
ZMQBlockHost string
|
||||
|
||||
// ZMQTxHost is the IP address and port of the bitcoind's rawtx
|
||||
// listener.
|
||||
ZMQTxHost string
|
||||
|
||||
// ZMQReadDeadline represents the read deadline we'll apply when reading
|
||||
// ZMQ messages from either subscription.
|
||||
ZMQReadDeadline time.Duration
|
||||
|
||||
// Dialer is a closure we'll use to dial Bitcoin peers. If the chain
|
||||
// backend is running over Tor, this must support dialing peers over Tor
|
||||
// as well.
|
||||
Dialer Dialer
|
||||
|
||||
// PrunedModeMaxPeers is the maximum number of peers we'll attempt to
|
||||
// retrieve pruned blocks from.
|
||||
//
|
||||
// NOTE: This only applies for pruned bitcoind nodes.
|
||||
PrunedModeMaxPeers int
|
||||
}
|
||||
|
||||
// BitcoindConn represents a persistent client connection to a bitcoind node
|
||||
// that listens for events read from a ZMQ connection.
|
||||
type BitcoindConn struct {
|
||||
started int32 // To be used atomically.
|
||||
stopped int32 // To be used atomically.
|
||||
|
||||
cfg BitcoindConfig
|
||||
|
||||
// rescanClientCounter is an atomic counter that assigns a unique ID to
|
||||
// each new bitcoind rescan client using the current bitcoind
|
||||
// connection.
|
||||
rescanClientCounter uint64
|
||||
|
||||
// chainParams identifies the current network the bitcoind node is
|
||||
// running on.
|
||||
chainParams *chaincfg.Params
|
||||
|
||||
// client is the RPC client to the bitcoind node.
|
||||
client *rpcclient.Client
|
||||
|
||||
// prunedBlockDispatcher handles all of the pruned block requests.
|
||||
//
|
||||
// NOTE: This is nil when the bitcoind node is not pruned.
|
||||
prunedBlockDispatcher *PrunedBlockDispatcher
|
||||
|
||||
// zmqBlockConn is the ZMQ connection we'll use to read raw block
|
||||
// events.
|
||||
zmqBlockConn *gozmq.Conn
|
||||
|
@ -73,35 +123,54 @@ type BitcoindConn struct {
|
|||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
// Dialer represents a way to dial Bitcoin peers. If the chain backend is
|
||||
// running over Tor, this must support dialing peers over Tor as well.
|
||||
type Dialer = func(string) (net.Conn, error)
|
||||
|
||||
// NewBitcoindConn creates a client connection to the node described by the host
|
||||
// string. The ZMQ connections are established immediately to ensure liveness.
|
||||
// If the remote node does not operate on the same bitcoin network as described
|
||||
// by the passed chain parameters, the connection will be disconnected.
|
||||
func NewBitcoindConn(chainParams *chaincfg.Params,
|
||||
host, user, pass, zmqBlockHost, zmqTxHost string,
|
||||
zmqPollInterval time.Duration) (*BitcoindConn, error) {
|
||||
|
||||
func NewBitcoindConn(cfg *BitcoindConfig) (*BitcoindConn, error) {
|
||||
clientCfg := &rpcclient.ConnConfig{
|
||||
Host: host,
|
||||
User: user,
|
||||
Pass: pass,
|
||||
Host: cfg.Host,
|
||||
User: cfg.User,
|
||||
Pass: cfg.Pass,
|
||||
DisableAutoReconnect: false,
|
||||
DisableConnectOnNew: true,
|
||||
DisableTLS: true,
|
||||
HTTPPostMode: true,
|
||||
}
|
||||
|
||||
client, err := rpcclient.New(clientCfg, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Verify that the node is running on the expected network.
|
||||
net, err := getCurrentNet(client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if net != cfg.ChainParams.Net {
|
||||
return nil, fmt.Errorf("expected network %v, got %v",
|
||||
cfg.ChainParams.Net, net)
|
||||
}
|
||||
|
||||
// Check if the node is pruned, as we'll need to perform additional
|
||||
// operations if so.
|
||||
chainInfo, err := client.GetBlockChainInfo()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to determine if bitcoind is "+
|
||||
"pruned: %v", err)
|
||||
}
|
||||
|
||||
// Establish two different ZMQ connections to bitcoind to retrieve block
|
||||
// and transaction event notifications. We'll use two as a separation of
|
||||
// concern to ensure one type of event isn't dropped from the connection
|
||||
// queue due to another type of event filling it up.
|
||||
zmqBlockConn, err := gozmq.Subscribe(
|
||||
zmqBlockHost, []string{rawBlockZMQCommand}, zmqPollInterval,
|
||||
cfg.ZMQBlockHost, []string{rawBlockZMQCommand},
|
||||
cfg.ZMQReadDeadline,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to subscribe for zmq block "+
|
||||
|
@ -109,7 +178,7 @@ func NewBitcoindConn(chainParams *chaincfg.Params,
|
|||
}
|
||||
|
||||
zmqTxConn, err := gozmq.Subscribe(
|
||||
zmqTxHost, []string{rawTxZMQCommand}, zmqPollInterval,
|
||||
cfg.ZMQTxHost, []string{rawTxZMQCommand}, cfg.ZMQReadDeadline,
|
||||
)
|
||||
if err != nil {
|
||||
zmqBlockConn.Close()
|
||||
|
@ -117,16 +186,37 @@ func NewBitcoindConn(chainParams *chaincfg.Params,
|
|||
"events: %v", err)
|
||||
}
|
||||
|
||||
conn := &BitcoindConn{
|
||||
chainParams: chainParams,
|
||||
client: client,
|
||||
zmqBlockConn: zmqBlockConn,
|
||||
zmqTxConn: zmqTxConn,
|
||||
rescanClients: make(map[uint64]*BitcoindClient),
|
||||
quit: make(chan struct{}),
|
||||
// Only initialize the PrunedBlockDispatcher when the connected bitcoind
|
||||
// node is pruned.
|
||||
var prunedBlockDispatcher *PrunedBlockDispatcher
|
||||
if chainInfo.Pruned {
|
||||
prunedBlockDispatcher, err = NewPrunedBlockDispatcher(
|
||||
&PrunedBlockDispatcherConfig{
|
||||
ChainParams: cfg.ChainParams,
|
||||
NumTargetPeers: cfg.PrunedModeMaxPeers,
|
||||
Dial: cfg.Dialer,
|
||||
GetPeers: client.GetPeerInfo,
|
||||
PeerReadyTimeout: defaultPeerReadyTimeout,
|
||||
RefreshPeersTicker: ticker.New(
|
||||
defaultRefreshPeersInterval,
|
||||
),
|
||||
MaxRequestInvs: wire.MaxInvPerMsg,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return conn, nil
|
||||
return &BitcoindConn{
|
||||
cfg: *cfg,
|
||||
client: client,
|
||||
prunedBlockDispatcher: prunedBlockDispatcher,
|
||||
zmqBlockConn: zmqBlockConn,
|
||||
zmqTxConn: zmqTxConn,
|
||||
rescanClients: make(map[uint64]*BitcoindClient),
|
||||
quit: make(chan struct{}),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Start attempts to establish a RPC and ZMQ connection to a bitcoind node. If
|
||||
|
@ -139,14 +229,13 @@ func (c *BitcoindConn) Start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Verify that the node is running on the expected network.
|
||||
net, err := c.getCurrentNet()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if net != c.chainParams.Net {
|
||||
return fmt.Errorf("expected network %v, got %v",
|
||||
c.chainParams.Net, net)
|
||||
// If we're connected to a pruned backend, we'll need to also start our
|
||||
// pruned block dispatcher to handle pruned block requests.
|
||||
if c.prunedBlockDispatcher != nil {
|
||||
log.Debug("Detected pruned bitcoind backend")
|
||||
if err := c.prunedBlockDispatcher.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
c.wg.Add(2)
|
||||
|
@ -172,6 +261,10 @@ func (c *BitcoindConn) Stop() {
|
|||
c.zmqBlockConn.Close()
|
||||
c.zmqTxConn.Close()
|
||||
|
||||
if c.prunedBlockDispatcher != nil {
|
||||
c.prunedBlockDispatcher.Stop()
|
||||
}
|
||||
|
||||
c.client.WaitForShutdown()
|
||||
c.wg.Wait()
|
||||
}
|
||||
|
@ -380,8 +473,8 @@ func (c *BitcoindConn) txEventHandler() {
|
|||
}
|
||||
|
||||
// getCurrentNet returns the network on which the bitcoind node is running.
|
||||
func (c *BitcoindConn) getCurrentNet() (wire.BitcoinNet, error) {
|
||||
hash, err := c.client.GetBlockHash(0)
|
||||
func getCurrentNet(client *rpcclient.Client) (wire.BitcoinNet, error) {
|
||||
hash, err := client.GetBlockHash(0)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -407,8 +500,7 @@ func (c *BitcoindConn) NewBitcoindClient() *BitcoindClient {
|
|||
|
||||
id: atomic.AddUint64(&c.rescanClientCounter, 1),
|
||||
|
||||
chainParams: c.chainParams,
|
||||
chainConn: c,
|
||||
chainConn: c,
|
||||
|
||||
rescanUpdate: make(chan interface{}),
|
||||
watchedAddresses: make(map[string]struct{}),
|
||||
|
@ -448,6 +540,55 @@ func (c *BitcoindConn) RemoveClient(id uint64) {
|
|||
delete(c.rescanClients, id)
|
||||
}
|
||||
|
||||
// isBlockPrunedErr determines if the error returned by the GetBlock RPC
|
||||
// corresponds to the requested block being pruned.
|
||||
func isBlockPrunedErr(err error) bool {
|
||||
rpcErr, ok := err.(*btcjson.RPCError)
|
||||
return ok && rpcErr.Code == btcjson.ErrRPCMisc &&
|
||||
rpcErr.Message == errBlockPrunedStr
|
||||
}
|
||||
|
||||
// GetBlock returns a raw block from the server given its hash. If the server
|
||||
// has already pruned the block, it will be retrieved from one of its peers.
|
||||
func (c *BitcoindConn) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error) {
|
||||
block, err := c.client.GetBlock(hash)
|
||||
// Got the block from the backend successfully, return it.
|
||||
if err == nil {
|
||||
return block, nil
|
||||
}
|
||||
|
||||
// We failed getting the block from the backend for whatever reason. If
|
||||
// it wasn't due to the block being pruned, return the error
|
||||
// immediately.
|
||||
if !isBlockPrunedErr(err) || c.prunedBlockDispatcher == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Now that we know the block has been pruned for sure, request it from
|
||||
// our backend peers.
|
||||
blockChan, errChan := c.prunedBlockDispatcher.Query(
|
||||
[]*chainhash.Hash{hash},
|
||||
)
|
||||
|
||||
for {
|
||||
select {
|
||||
case block := <-blockChan:
|
||||
return block, nil
|
||||
|
||||
case err := <-errChan:
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// errChan fired before blockChan with a nil error, wait
|
||||
// for the block now.
|
||||
|
||||
case <-c.quit:
|
||||
return nil, ErrBitcoindClientShuttingDown
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// isASCII is a helper method that checks whether all bytes in `data` would be
|
||||
// printable ASCII characters if interpreted as a string.
|
||||
func isASCII(s string) bool {
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
package chain
|
||||
|
||||
import "github.com/btcsuite/btclog"
|
||||
import (
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightninglabs/neutrino/query"
|
||||
)
|
||||
|
||||
// log is a logger that is initialized with no output filters. This
|
||||
// means the package will not perform any logging by default until the caller
|
||||
|
@ -27,4 +30,5 @@ func DisableLog() {
|
|||
// using btclog.
|
||||
func UseLogger(logger btclog.Logger) {
|
||||
log = logger
|
||||
query.UseLogger(logger)
|
||||
}
|
||||
|
|
625
chain/pruned_block_dispatcher.go
Normal file
625
chain/pruned_block_dispatcher.go
Normal file
|
@ -0,0 +1,625 @@
|
|||
package chain
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/blockchain"
|
||||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/peer"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightninglabs/neutrino/query"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
)
|
||||
|
||||
const (
|
||||
// defaultRefreshPeersInterval represents the default polling interval
|
||||
// at which we attempt to refresh the set of known peers.
|
||||
defaultRefreshPeersInterval = 30 * time.Second
|
||||
|
||||
// defaultPeerReadyTimeout is the default amount of time we'll wait for
|
||||
// a query peer to be ready to receive incoming block requests. Peers
|
||||
// cannot respond to requests until the version exchange is completed
|
||||
// upon connection establishment.
|
||||
defaultPeerReadyTimeout = 15 * time.Second
|
||||
|
||||
// requiredServices are the requires services we require any candidate
|
||||
// peers to signal such that we can retrieve pruned blocks from them.
|
||||
requiredServices = wire.SFNodeNetwork | wire.SFNodeWitness
|
||||
|
||||
// prunedNodeService is the service bit signaled by pruned nodes on the
|
||||
// network.
|
||||
prunedNodeService wire.ServiceFlag = 1 << 11
|
||||
)
|
||||
|
||||
// queryPeer represents a Bitcoin network peer that we'll query for blocks.
|
||||
// The ready channel serves as a signal for us to know when we can be sending
|
||||
// queries to the peer. Any messages received from the peer are sent through the
|
||||
// msgsRecvd channel.
|
||||
type queryPeer struct {
|
||||
*peer.Peer
|
||||
ready chan struct{}
|
||||
msgsRecvd chan wire.Message
|
||||
quit chan struct{}
|
||||
}
|
||||
|
||||
// signalUponDisconnect closes the peer's quit chan to signal it has
|
||||
// disconnected.
|
||||
func (p *queryPeer) signalUponDisconnect(f func()) {
|
||||
go func() {
|
||||
p.WaitForDisconnect()
|
||||
close(p.quit)
|
||||
f()
|
||||
}()
|
||||
}
|
||||
|
||||
// SubscribeRecvMsg adds a OnRead subscription to the peer. All bitcoin messages
|
||||
// received from this peer will be sent on the returned channel. A closure is
|
||||
// also returned, that should be called to cancel the subscription.
|
||||
//
|
||||
// NOTE: This method exists to satisfy the query.Peer interface.
|
||||
func (p *queryPeer) SubscribeRecvMsg() (<-chan wire.Message, func()) {
|
||||
return p.msgsRecvd, func() {}
|
||||
}
|
||||
|
||||
// OnDisconnect returns a channel that will be closed once the peer disconnects.
|
||||
//
|
||||
// NOTE: This method exists to satisfy the query.Peer interface.
|
||||
func (p *queryPeer) OnDisconnect() <-chan struct{} {
|
||||
return p.quit
|
||||
}
|
||||
|
||||
// PrunedBlockDispatcherConfig encompasses all of the dependencies required by
|
||||
// the PrunedBlockDispatcher to carry out its duties.
|
||||
type PrunedBlockDispatcherConfig struct {
|
||||
// ChainParams represents the parameters of the current active chain.
|
||||
ChainParams *chaincfg.Params
|
||||
|
||||
// NumTargetPeer represents the target number of peers we should
|
||||
// maintain connections with. This exists to prevent establishing
|
||||
// connections to all of the bitcoind's peers, which would be
|
||||
// unnecessary and ineffecient.
|
||||
NumTargetPeers int
|
||||
|
||||
// Dial establishes connections to Bitcoin peers. This must support
|
||||
// dialing peers running over Tor if the backend also supports it.
|
||||
Dial func(string) (net.Conn, error)
|
||||
|
||||
// GetPeers retrieves the active set of peers known to the backend node.
|
||||
GetPeers func() ([]btcjson.GetPeerInfoResult, error)
|
||||
|
||||
// PeerReadyTimeout is the amount of time we'll wait for a query peer to
|
||||
// be ready to receive incoming block requests. Peers cannot respond to
|
||||
// requests until the version exchange is completed upon connection
|
||||
// establishment.
|
||||
PeerReadyTimeout time.Duration
|
||||
|
||||
// RefreshPeersTicker is the polling ticker that signals us when we
|
||||
// should attempt to refresh the set of known peers.
|
||||
RefreshPeersTicker ticker.Ticker
|
||||
|
||||
// AllowSelfPeerConns is only used to allow the tests to bypass the peer
|
||||
// self connection detecting and disconnect logic since they
|
||||
// intentionally do so for testing purposes.
|
||||
AllowSelfPeerConns bool
|
||||
|
||||
// MaxRequestInvs dictates how many invs we should fit in a single
|
||||
// getdata request to a peer. This only exists to facilitate the testing
|
||||
// of a request spanning multiple getdata messages.
|
||||
MaxRequestInvs int
|
||||
}
|
||||
|
||||
// PrunedBlockDispatcher enables a chain client to request blocks that the
|
||||
// server has already pruned. This is done by connecting to the server's full
|
||||
// node peers and querying them directly. Ideally, this is a capability
|
||||
// supported by the server, though this is not yet possible with bitcoind.
|
||||
type PrunedBlockDispatcher struct {
|
||||
cfg PrunedBlockDispatcherConfig
|
||||
|
||||
// workManager handles satisfying all of our incoming pruned block
|
||||
// requests.
|
||||
workManager *query.WorkManager
|
||||
|
||||
// blocksQueried represents the set of pruned blocks we've been
|
||||
// requested to query. Each block maps to a list of clients waiting to
|
||||
// be notified once the block is received.
|
||||
//
|
||||
// NOTE: The blockMtx lock must always be held when accessing this
|
||||
// field.
|
||||
blocksQueried map[chainhash.Hash][]chan *wire.MsgBlock
|
||||
blockMtx sync.Mutex
|
||||
|
||||
// currentPeers represents the set of peers we're currently connected
|
||||
// to. Each peer found here will have a worker spawned within the
|
||||
// workManager to handle our queries.
|
||||
//
|
||||
// NOTE: The peerMtx lock must always be held when accessing this
|
||||
// field.
|
||||
currentPeers map[string]*peer.Peer
|
||||
|
||||
// bannedPeers represents the set of peers who have sent us an invalid
|
||||
// reply corresponding to a query. Peers within this set should not be
|
||||
// dialed.
|
||||
//
|
||||
// NOTE: The peerMtx lock must always be held when accessing this
|
||||
// field.
|
||||
bannedPeers map[string]struct{}
|
||||
peerMtx sync.Mutex
|
||||
|
||||
// peersConnected is the channel through which we'll send new peers
|
||||
// we've established connections to.
|
||||
peersConnected chan query.Peer
|
||||
|
||||
// timeSource provides a mechanism to add several time samples which are
|
||||
// used to determine a median time which is then used as an offset to
|
||||
// the local clock when validating blocks received from peers.
|
||||
timeSource blockchain.MedianTimeSource
|
||||
|
||||
quit chan struct{}
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
// NewPrunedBlockDispatcher initializes a new PrunedBlockDispatcher instance
|
||||
// backed by the given config.
|
||||
func NewPrunedBlockDispatcher(cfg *PrunedBlockDispatcherConfig) (
|
||||
*PrunedBlockDispatcher, error) {
|
||||
|
||||
if cfg.NumTargetPeers < 1 {
|
||||
return nil, errors.New("config option NumTargetPeer must be >= 1")
|
||||
}
|
||||
if cfg.MaxRequestInvs > wire.MaxInvPerMsg {
|
||||
return nil, fmt.Errorf("config option MaxRequestInvs must be "+
|
||||
"<= %v", wire.MaxInvPerMsg)
|
||||
}
|
||||
|
||||
peersConnected := make(chan query.Peer)
|
||||
return &PrunedBlockDispatcher{
|
||||
cfg: *cfg,
|
||||
workManager: query.New(&query.Config{
|
||||
ConnectedPeers: func() (<-chan query.Peer, func(), error) {
|
||||
return peersConnected, func() {}, nil
|
||||
},
|
||||
NewWorker: query.NewWorker,
|
||||
Ranking: query.NewPeerRanking(),
|
||||
}),
|
||||
blocksQueried: make(map[chainhash.Hash][]chan *wire.MsgBlock),
|
||||
currentPeers: make(map[string]*peer.Peer),
|
||||
bannedPeers: make(map[string]struct{}),
|
||||
peersConnected: peersConnected,
|
||||
timeSource: blockchain.NewMedianTime(),
|
||||
quit: make(chan struct{}),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Start allows the PrunedBlockDispatcher to begin handling incoming block
|
||||
// requests.
|
||||
func (d *PrunedBlockDispatcher) Start() error {
|
||||
log.Tracef("Starting pruned block dispatcher")
|
||||
|
||||
if err := d.workManager.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.wg.Add(1)
|
||||
go d.pollPeers()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop stops the PrunedBlockDispatcher from accepting any more incoming block
|
||||
// requests.
|
||||
func (d *PrunedBlockDispatcher) Stop() {
|
||||
log.Tracef("Stopping pruned block dispatcher")
|
||||
|
||||
close(d.quit)
|
||||
d.wg.Wait()
|
||||
|
||||
_ = d.workManager.Stop()
|
||||
}
|
||||
|
||||
// pollPeers continuously polls the backend node for new peers to establish
|
||||
// connections to.
|
||||
func (d *PrunedBlockDispatcher) pollPeers() {
|
||||
defer d.wg.Done()
|
||||
|
||||
if err := d.connectToPeers(); err != nil {
|
||||
log.Warnf("Unable to establish peer connections: %v", err)
|
||||
}
|
||||
|
||||
d.cfg.RefreshPeersTicker.Resume()
|
||||
defer d.cfg.RefreshPeersTicker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-d.cfg.RefreshPeersTicker.Ticks():
|
||||
// Quickly determine if we need any more peer
|
||||
// connections. If we don't, we'll wait for our next
|
||||
// tick.
|
||||
d.peerMtx.Lock()
|
||||
peersNeeded := d.cfg.NumTargetPeers - len(d.currentPeers)
|
||||
d.peerMtx.Unlock()
|
||||
if peersNeeded <= 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// If we do, attempt to establish connections until
|
||||
// we've reached our target number.
|
||||
if err := d.connectToPeers(); err != nil {
|
||||
log.Warnf("Unable to establish peer "+
|
||||
"connections: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
case <-d.quit:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// connectToPeers attempts to establish new peer connections until the target
|
||||
// number is reached. Once a connection is successfully established, the peer is
|
||||
// sent through the peersConnected channel to notify the internal workManager.
|
||||
func (d *PrunedBlockDispatcher) connectToPeers() error {
|
||||
// Refresh the list of peers our backend is currently connected to, and
|
||||
// filter out any that do not meet our requirements.
|
||||
peers, err := d.cfg.GetPeers()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
peers, err = filterPeers(peers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rand.Shuffle(len(peers), func(i, j int) {
|
||||
peers[i], peers[j] = peers[j], peers[i]
|
||||
})
|
||||
|
||||
// For each unbanned peer we don't already have a connection to, try to
|
||||
// establish one, and if successful, notify the peer.
|
||||
for _, peer := range peers {
|
||||
d.peerMtx.Lock()
|
||||
_, isBanned := d.bannedPeers[peer.Addr]
|
||||
_, isConnected := d.currentPeers[peer.Addr]
|
||||
d.peerMtx.Unlock()
|
||||
if isBanned || isConnected {
|
||||
continue
|
||||
}
|
||||
|
||||
queryPeer, err := d.newQueryPeer(peer)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to configure query peer %v: "+
|
||||
"%v", peer.Addr, err)
|
||||
}
|
||||
if err := d.connectToPeer(queryPeer); err != nil {
|
||||
log.Debugf("Failed connecting to peer %v: %v",
|
||||
peer.Addr, err)
|
||||
continue
|
||||
}
|
||||
|
||||
select {
|
||||
case d.peersConnected <- queryPeer:
|
||||
case <-d.quit:
|
||||
return errors.New("shutting down")
|
||||
}
|
||||
|
||||
// If the new peer helped us reach our target number, we're done
|
||||
// and can exit.
|
||||
d.peerMtx.Lock()
|
||||
d.currentPeers[queryPeer.Addr()] = queryPeer.Peer
|
||||
numPeers := len(d.currentPeers)
|
||||
d.peerMtx.Unlock()
|
||||
if numPeers == d.cfg.NumTargetPeers {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// filterPeers filters out any peers which cannot handle arbitrary witness block
|
||||
// requests, i.e., any peer which is not considered a segwit-enabled
|
||||
// "full-node".
|
||||
func filterPeers(peers []btcjson.GetPeerInfoResult) (
|
||||
[]btcjson.GetPeerInfoResult, error) {
|
||||
|
||||
var eligible []btcjson.GetPeerInfoResult
|
||||
for _, peer := range peers {
|
||||
rawServices, err := hex.DecodeString(peer.Services)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
services := wire.ServiceFlag(binary.BigEndian.Uint64(rawServices))
|
||||
|
||||
// Skip nodes that cannot serve full block witness data.
|
||||
if services&requiredServices != requiredServices {
|
||||
continue
|
||||
}
|
||||
// Skip pruned nodes.
|
||||
if services&prunedNodeService == prunedNodeService {
|
||||
continue
|
||||
}
|
||||
|
||||
eligible = append(eligible, peer)
|
||||
}
|
||||
|
||||
return eligible, nil
|
||||
}
|
||||
|
||||
// newQueryPeer creates a new peer instance configured to relay any received
|
||||
// messages to the internal workManager.
|
||||
func (d *PrunedBlockDispatcher) newQueryPeer(
|
||||
peerInfo btcjson.GetPeerInfoResult) (*queryPeer, error) {
|
||||
|
||||
ready := make(chan struct{})
|
||||
msgsRecvd := make(chan wire.Message)
|
||||
|
||||
cfg := &peer.Config{
|
||||
ChainParams: d.cfg.ChainParams,
|
||||
// We're not interested in transactions, so disable their relay.
|
||||
DisableRelayTx: true,
|
||||
Listeners: peer.MessageListeners{
|
||||
// Add the remote peer time as a sample for creating an
|
||||
// offset against the local clock to keep the network
|
||||
// time in sync.
|
||||
OnVersion: func(p *peer.Peer, msg *wire.MsgVersion) *wire.MsgReject {
|
||||
d.timeSource.AddTimeSample(p.Addr(), msg.Timestamp)
|
||||
return nil
|
||||
},
|
||||
// Register a callback to signal us when we can start
|
||||
// querying the peer for blocks.
|
||||
OnVerAck: func(*peer.Peer, *wire.MsgVerAck) {
|
||||
close(ready)
|
||||
},
|
||||
// Register a callback to signal us whenever the peer
|
||||
// has sent us a block message.
|
||||
OnRead: func(p *peer.Peer, _ int, msg wire.Message, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var block *wire.MsgBlock
|
||||
switch msg := msg.(type) {
|
||||
case *wire.MsgBlock:
|
||||
block = msg
|
||||
case *wire.MsgVersion, *wire.MsgVerAck:
|
||||
return
|
||||
default:
|
||||
log.Debugf("Received unexpected message "+
|
||||
"%T from peer %v", msg, p.Addr())
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case msgsRecvd <- block:
|
||||
case <-d.quit:
|
||||
}
|
||||
},
|
||||
},
|
||||
AllowSelfConns: true,
|
||||
}
|
||||
p, err := peer.NewOutboundPeer(cfg, peerInfo.Addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &queryPeer{
|
||||
Peer: p,
|
||||
ready: ready,
|
||||
msgsRecvd: msgsRecvd,
|
||||
quit: make(chan struct{}),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// connectToPeer attempts to establish a connection to the given peer and waits
|
||||
// up to PeerReadyTimeout for the version exchange to complete so that we can
|
||||
// begin sending it our queries.
|
||||
func (d *PrunedBlockDispatcher) connectToPeer(peer *queryPeer) error {
|
||||
conn, err := d.cfg.Dial(peer.Addr())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
peer.AssociateConnection(conn)
|
||||
|
||||
select {
|
||||
case <-peer.ready:
|
||||
case <-time.After(d.cfg.PeerReadyTimeout):
|
||||
peer.Disconnect()
|
||||
return errors.New("timed out waiting for protocol negotiation")
|
||||
case <-d.quit:
|
||||
return errors.New("shutting down")
|
||||
}
|
||||
|
||||
// Remove the peer once it has disconnected.
|
||||
peer.signalUponDisconnect(func() {
|
||||
d.peerMtx.Lock()
|
||||
delete(d.currentPeers, peer.Addr())
|
||||
d.peerMtx.Unlock()
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// banPeer bans a peer by disconnecting them and ensuring we don't reconnect.
|
||||
func (d *PrunedBlockDispatcher) banPeer(peer string) {
|
||||
d.peerMtx.Lock()
|
||||
defer d.peerMtx.Unlock()
|
||||
|
||||
d.bannedPeers[peer] = struct{}{}
|
||||
if p, ok := d.currentPeers[peer]; ok {
|
||||
p.Disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
// Query submits a request to query the information of the given blocks.
|
||||
func (d *PrunedBlockDispatcher) Query(blocks []*chainhash.Hash,
|
||||
opts ...query.QueryOption) (<-chan *wire.MsgBlock, <-chan error) {
|
||||
|
||||
reqs, blockChan, err := d.newRequest(blocks)
|
||||
if err != nil {
|
||||
errChan := make(chan error, 1)
|
||||
errChan <- err
|
||||
return nil, errChan
|
||||
}
|
||||
|
||||
var errChan chan error
|
||||
if len(reqs) > 0 {
|
||||
errChan = d.workManager.Query(reqs, opts...)
|
||||
}
|
||||
return blockChan, errChan
|
||||
}
|
||||
|
||||
// newRequest construct a new query request for the given blocks to submit to
|
||||
// the internal workManager. A channel is also returned through which the
|
||||
// requested blocks are sent through.
|
||||
func (d *PrunedBlockDispatcher) newRequest(blocks []*chainhash.Hash) (
|
||||
[]*query.Request, <-chan *wire.MsgBlock, error) {
|
||||
|
||||
// Make sure the channel is buffered enough to handle all blocks.
|
||||
blockChan := make(chan *wire.MsgBlock, len(blocks))
|
||||
|
||||
d.blockMtx.Lock()
|
||||
defer d.blockMtx.Unlock()
|
||||
|
||||
// Each GetData message can only include up to MaxRequestInvs invs,
|
||||
// and each block consumes a single inv.
|
||||
var (
|
||||
reqs []*query.Request
|
||||
getData *wire.MsgGetData
|
||||
)
|
||||
for i, block := range blocks {
|
||||
if getData == nil {
|
||||
getData = wire.NewMsgGetData()
|
||||
}
|
||||
|
||||
if _, ok := d.blocksQueried[*block]; !ok {
|
||||
log.Debugf("Queuing new block %v for request", *block)
|
||||
inv := wire.NewInvVect(wire.InvTypeBlock, block)
|
||||
if err := getData.AddInvVect(inv); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
} else {
|
||||
log.Debugf("Received new request for pending query of "+
|
||||
"block %v", *block)
|
||||
}
|
||||
|
||||
d.blocksQueried[*block] = append(
|
||||
d.blocksQueried[*block], blockChan,
|
||||
)
|
||||
|
||||
// If we have any invs to request, or we've reached the maximum
|
||||
// allowed, queue the getdata message as is, and proceed to the
|
||||
// next if any.
|
||||
if (len(getData.InvList) > 0 && i == len(blocks)-1) ||
|
||||
len(getData.InvList) == d.cfg.MaxRequestInvs {
|
||||
|
||||
reqs = append(reqs, &query.Request{
|
||||
Req: getData,
|
||||
HandleResp: d.handleResp,
|
||||
})
|
||||
getData = nil
|
||||
}
|
||||
}
|
||||
|
||||
return reqs, blockChan, nil
|
||||
}
|
||||
|
||||
// handleResp is a response handler that will be called for every message
|
||||
// received from the peer that the request was made to. It should validate the
|
||||
// response against the request made, and return a Progress indicating whether
|
||||
// the request was answered by this particular response.
|
||||
//
|
||||
// NOTE: Since the worker's job queue will be stalled while this method is
|
||||
// running, it should not be doing any expensive operations. It should validate
|
||||
// the response and immediately return the progress. The response should be
|
||||
// handed off to another goroutine for processing.
|
||||
func (d *PrunedBlockDispatcher) handleResp(req, resp wire.Message,
|
||||
peer string) query.Progress {
|
||||
|
||||
// We only expect MsgBlock as replies.
|
||||
block, ok := resp.(*wire.MsgBlock)
|
||||
if !ok {
|
||||
return query.Progress{
|
||||
Progressed: false,
|
||||
Finished: false,
|
||||
}
|
||||
}
|
||||
|
||||
// We only serve MsgGetData requests.
|
||||
getData, ok := req.(*wire.MsgGetData)
|
||||
if !ok {
|
||||
return query.Progress{
|
||||
Progressed: false,
|
||||
Finished: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Check that we've actually queried for this block and validate it.
|
||||
blockHash := block.BlockHash()
|
||||
d.blockMtx.Lock()
|
||||
blockChans, ok := d.blocksQueried[blockHash]
|
||||
if !ok {
|
||||
d.blockMtx.Unlock()
|
||||
return query.Progress{
|
||||
Progressed: false,
|
||||
Finished: false,
|
||||
}
|
||||
}
|
||||
|
||||
err := blockchain.CheckBlockSanity(
|
||||
btcutil.NewBlock(block), d.cfg.ChainParams.PowLimit,
|
||||
d.timeSource,
|
||||
)
|
||||
if err != nil {
|
||||
d.blockMtx.Unlock()
|
||||
|
||||
log.Warnf("Received invalid block %v from peer %v: %v",
|
||||
blockHash, peer, err)
|
||||
d.banPeer(peer)
|
||||
|
||||
return query.Progress{
|
||||
Progressed: false,
|
||||
Finished: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Once validated, we can safely remove it.
|
||||
delete(d.blocksQueried, blockHash)
|
||||
|
||||
// Check whether we have any other pending blocks we've yet to receive.
|
||||
// If we do, we'll mark the response as progressing our query, but not
|
||||
// completing it yet.
|
||||
progress := query.Progress{Progressed: true, Finished: true}
|
||||
for _, inv := range getData.InvList {
|
||||
if _, ok := d.blocksQueried[inv.Hash]; ok {
|
||||
progress.Finished = false
|
||||
break
|
||||
}
|
||||
}
|
||||
d.blockMtx.Unlock()
|
||||
|
||||
// Launch a goroutine to notify all clients of the block as we don't
|
||||
// want to potentially block our workManager.
|
||||
d.wg.Add(1)
|
||||
go func() {
|
||||
defer d.wg.Done()
|
||||
|
||||
for _, blockChan := range blockChans {
|
||||
select {
|
||||
case blockChan <- block:
|
||||
case <-d.quit:
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return progress
|
||||
}
|
590
chain/pruned_block_dispatcher_test.go
Normal file
590
chain/pruned_block_dispatcher_test.go
Normal file
|
@ -0,0 +1,590 @@
|
|||
package chain
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/peer"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func init() {
|
||||
b := btclog.NewBackend(os.Stdout)
|
||||
l := b.Logger("")
|
||||
l.SetLevel(btclog.LevelTrace)
|
||||
UseLogger(l)
|
||||
}
|
||||
|
||||
var (
|
||||
addrCounter int32 // Increased atomically.
|
||||
|
||||
chainParams = chaincfg.RegressionNetParams
|
||||
)
|
||||
|
||||
func nextAddr() string {
|
||||
port := atomic.AddInt32(&addrCounter, 1)
|
||||
return fmt.Sprintf("10.0.0.1:%d", port)
|
||||
}
|
||||
|
||||
// prunedBlockDispatcherHarness is a harness used to facilitate the testing of the
|
||||
// PrunedBlockDispatcher.
|
||||
type prunedBlockDispatcherHarness struct {
|
||||
t *testing.T
|
||||
|
||||
dispatcher *PrunedBlockDispatcher
|
||||
|
||||
hashes []*chainhash.Hash
|
||||
blocks map[chainhash.Hash]*wire.MsgBlock
|
||||
|
||||
peerMtx sync.Mutex
|
||||
peers map[string]*peer.Peer
|
||||
localConns map[string]net.Conn // Connections to peers.
|
||||
remoteConns map[string]net.Conn // Connections from peers.
|
||||
|
||||
dialedPeer chan struct{}
|
||||
queriedPeer chan struct{}
|
||||
blocksQueried map[chainhash.Hash]int
|
||||
|
||||
shouldReply uint32 // 0 == true, 1 == false, 2 == invalid reply
|
||||
}
|
||||
|
||||
// newNetworkBlockTestHarness initializes a new PrunedBlockDispatcher test harness
|
||||
// backed by a custom chain and peers.
|
||||
func newNetworkBlockTestHarness(t *testing.T, numBlocks,
|
||||
numPeers, numWorkers uint32) *prunedBlockDispatcherHarness {
|
||||
|
||||
h := &prunedBlockDispatcherHarness{
|
||||
t: t,
|
||||
peers: make(map[string]*peer.Peer, numPeers),
|
||||
localConns: make(map[string]net.Conn, numPeers),
|
||||
remoteConns: make(map[string]net.Conn, numPeers),
|
||||
dialedPeer: make(chan struct{}),
|
||||
queriedPeer: make(chan struct{}),
|
||||
blocksQueried: make(map[chainhash.Hash]int),
|
||||
}
|
||||
|
||||
h.hashes, h.blocks = genBlockChain(numBlocks)
|
||||
for i := uint32(0); i < numPeers; i++ {
|
||||
h.addPeer()
|
||||
}
|
||||
|
||||
dial := func(addr string) (net.Conn, error) {
|
||||
go func() {
|
||||
h.dialedPeer <- struct{}{}
|
||||
}()
|
||||
|
||||
h.peerMtx.Lock()
|
||||
defer h.peerMtx.Unlock()
|
||||
|
||||
localConn, ok := h.localConns[addr]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("local conn %v not found", addr)
|
||||
}
|
||||
remoteConn, ok := h.remoteConns[addr]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("remote conn %v not found", addr)
|
||||
}
|
||||
|
||||
h.peers[addr].AssociateConnection(remoteConn)
|
||||
return localConn, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
h.dispatcher, err = NewPrunedBlockDispatcher(&PrunedBlockDispatcherConfig{
|
||||
ChainParams: &chainParams,
|
||||
NumTargetPeers: int(numWorkers),
|
||||
Dial: dial,
|
||||
GetPeers: func() ([]btcjson.GetPeerInfoResult, error) {
|
||||
h.peerMtx.Lock()
|
||||
defer h.peerMtx.Unlock()
|
||||
|
||||
res := make([]btcjson.GetPeerInfoResult, 0, len(h.peers))
|
||||
for addr, peer := range h.peers {
|
||||
var rawServices [8]byte
|
||||
binary.BigEndian.PutUint64(
|
||||
rawServices[:], uint64(peer.Services()),
|
||||
)
|
||||
|
||||
res = append(res, btcjson.GetPeerInfoResult{
|
||||
Addr: addr,
|
||||
Services: hex.EncodeToString(rawServices[:]),
|
||||
})
|
||||
}
|
||||
|
||||
return res, nil
|
||||
},
|
||||
PeerReadyTimeout: time.Hour,
|
||||
RefreshPeersTicker: ticker.NewForce(time.Hour),
|
||||
AllowSelfPeerConns: true,
|
||||
MaxRequestInvs: wire.MaxInvPerMsg,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
// start starts the PrunedBlockDispatcher and asserts that connections are made
|
||||
// to all available peers.
|
||||
func (h *prunedBlockDispatcherHarness) start() {
|
||||
h.t.Helper()
|
||||
|
||||
err := h.dispatcher.Start()
|
||||
require.NoError(h.t, err)
|
||||
|
||||
h.peerMtx.Lock()
|
||||
numPeers := len(h.peers)
|
||||
h.peerMtx.Unlock()
|
||||
|
||||
for i := 0; i < numPeers; i++ {
|
||||
h.assertPeerDialed()
|
||||
}
|
||||
}
|
||||
|
||||
// stop stops the PrunedBlockDispatcher and asserts that all internal fields of
|
||||
// the harness have been properly consumed.
|
||||
func (h *prunedBlockDispatcherHarness) stop() {
|
||||
h.dispatcher.Stop()
|
||||
|
||||
select {
|
||||
case <-h.dialedPeer:
|
||||
h.t.Fatal("did not consume all dialedPeer signals")
|
||||
default:
|
||||
}
|
||||
|
||||
select {
|
||||
case <-h.queriedPeer:
|
||||
h.t.Fatal("did not consume all queriedPeer signals")
|
||||
default:
|
||||
}
|
||||
|
||||
require.Empty(h.t, h.blocksQueried)
|
||||
}
|
||||
|
||||
// addPeer adds a new random peer available for use by the
|
||||
// PrunedBlockDispatcher.
|
||||
func (h *prunedBlockDispatcherHarness) addPeer() string {
|
||||
addr := nextAddr()
|
||||
|
||||
h.peerMtx.Lock()
|
||||
defer h.peerMtx.Unlock()
|
||||
|
||||
h.resetPeer(addr)
|
||||
return addr
|
||||
}
|
||||
|
||||
// resetPeer resets the internal peer connection state allowing the
|
||||
// PrunedBlockDispatcher to establish a mock connection to it.
|
||||
func (h *prunedBlockDispatcherHarness) resetPeer(addr string) {
|
||||
h.peers[addr] = h.newPeer()
|
||||
|
||||
// Establish a mock connection between us and each peer.
|
||||
inConn, outConn := pipe(
|
||||
&conn{localAddr: addr, remoteAddr: "10.0.0.1:8333"},
|
||||
&conn{localAddr: "10.0.0.1:8333", remoteAddr: addr},
|
||||
)
|
||||
h.localConns[addr] = outConn
|
||||
h.remoteConns[addr] = inConn
|
||||
}
|
||||
|
||||
// newPeer returns a new properly configured peer.Peer instance that will be
|
||||
// used by the PrunedBlockDispatcher.
|
||||
func (h *prunedBlockDispatcherHarness) newPeer() *peer.Peer {
|
||||
return peer.NewInboundPeer(&peer.Config{
|
||||
ChainParams: &chainParams,
|
||||
DisableRelayTx: true,
|
||||
Listeners: peer.MessageListeners{
|
||||
OnGetData: func(p *peer.Peer, msg *wire.MsgGetData) {
|
||||
go func() {
|
||||
h.queriedPeer <- struct{}{}
|
||||
}()
|
||||
|
||||
for _, inv := range msg.InvList {
|
||||
// Invs should always be for blocks.
|
||||
require.Equal(h.t, wire.InvTypeBlock, inv.Type)
|
||||
|
||||
// Invs should always be for known blocks.
|
||||
block, ok := h.blocks[inv.Hash]
|
||||
require.True(h.t, ok)
|
||||
|
||||
switch atomic.LoadUint32(&h.shouldReply) {
|
||||
// Don't reply if requested.
|
||||
case 1:
|
||||
continue
|
||||
// Make the block invalid and send it.
|
||||
case 2:
|
||||
block = produceInvalidBlock(block)
|
||||
}
|
||||
|
||||
go p.QueueMessage(block, nil)
|
||||
}
|
||||
},
|
||||
},
|
||||
Services: wire.SFNodeNetwork | wire.SFNodeWitness,
|
||||
AllowSelfConns: true,
|
||||
})
|
||||
}
|
||||
|
||||
// query requests the given blocks from the PrunedBlockDispatcher.
|
||||
func (h *prunedBlockDispatcherHarness) query(blocks []*chainhash.Hash) (
|
||||
<-chan *wire.MsgBlock, <-chan error) {
|
||||
|
||||
h.t.Helper()
|
||||
|
||||
blockChan, errChan := h.dispatcher.Query(blocks)
|
||||
select {
|
||||
case err := <-errChan:
|
||||
require.NoError(h.t, err)
|
||||
default:
|
||||
}
|
||||
|
||||
for _, block := range blocks {
|
||||
h.blocksQueried[*block]++
|
||||
}
|
||||
|
||||
return blockChan, errChan
|
||||
}
|
||||
|
||||
// disablePeerReplies prevents the query peer from replying.
|
||||
func (h *prunedBlockDispatcherHarness) disablePeerReplies() {
|
||||
atomic.StoreUint32(&h.shouldReply, 1)
|
||||
}
|
||||
|
||||
// enablePeerReplies allows the query peer to reply.
|
||||
func (h *prunedBlockDispatcherHarness) enablePeerReplies() {
|
||||
atomic.StoreUint32(&h.shouldReply, 0)
|
||||
}
|
||||
|
||||
// enableInvalidPeerReplies
|
||||
func (h *prunedBlockDispatcherHarness) enableInvalidPeerReplies() {
|
||||
atomic.StoreUint32(&h.shouldReply, 2)
|
||||
}
|
||||
|
||||
// refreshPeers forces the RefreshPeersTicker to fire.
|
||||
func (h *prunedBlockDispatcherHarness) refreshPeers() {
|
||||
h.t.Helper()
|
||||
|
||||
h.dispatcher.cfg.RefreshPeersTicker.(*ticker.Force).Force <- time.Now()
|
||||
}
|
||||
|
||||
// disconnectPeer simulates a peer disconnecting from the PrunedBlockDispatcher.
|
||||
func (h *prunedBlockDispatcherHarness) disconnectPeer(addr string) {
|
||||
h.t.Helper()
|
||||
|
||||
h.peerMtx.Lock()
|
||||
defer h.peerMtx.Unlock()
|
||||
|
||||
require.Contains(h.t, h.peers, addr)
|
||||
|
||||
// Obtain the current number of peers before disconnecting such that we
|
||||
// can block until the peer has been fully disconnected.
|
||||
h.dispatcher.peerMtx.Lock()
|
||||
numPeers := len(h.dispatcher.currentPeers)
|
||||
h.dispatcher.peerMtx.Unlock()
|
||||
|
||||
h.peers[addr].Disconnect()
|
||||
|
||||
require.Eventually(h.t, func() bool {
|
||||
h.dispatcher.peerMtx.Lock()
|
||||
defer h.dispatcher.peerMtx.Unlock()
|
||||
return len(h.dispatcher.currentPeers) == numPeers-1
|
||||
}, time.Second, 200*time.Millisecond)
|
||||
|
||||
// Reset the peer connection state to allow connections to them again.
|
||||
h.resetPeer(addr)
|
||||
}
|
||||
|
||||
// assertPeerDialed asserts that a connection was made to the given peer.
|
||||
func (h *prunedBlockDispatcherHarness) assertPeerDialed() {
|
||||
h.t.Helper()
|
||||
|
||||
select {
|
||||
case <-h.dialedPeer:
|
||||
case <-time.After(5 * time.Second):
|
||||
h.t.Fatalf("expected peer to be dialed")
|
||||
}
|
||||
}
|
||||
|
||||
// assertPeerQueried asserts that query was sent to the given peer.
|
||||
func (h *prunedBlockDispatcherHarness) assertPeerQueried() {
|
||||
h.t.Helper()
|
||||
|
||||
select {
|
||||
case <-h.queriedPeer:
|
||||
case <-time.After(5 * time.Second):
|
||||
h.t.Fatalf("expected a peer to be queried")
|
||||
}
|
||||
}
|
||||
|
||||
// assertPeerReplied asserts that the query peer replies with a block the
|
||||
// PrunedBlockDispatcher queried for.
|
||||
func (h *prunedBlockDispatcherHarness) assertPeerReplied(
|
||||
blockChan <-chan *wire.MsgBlock, errChan <-chan error,
|
||||
expectCompletionSignal bool) {
|
||||
|
||||
h.t.Helper()
|
||||
|
||||
select {
|
||||
case block := <-blockChan:
|
||||
blockHash := block.BlockHash()
|
||||
_, ok := h.blocksQueried[blockHash]
|
||||
require.True(h.t, ok)
|
||||
|
||||
expBlock, ok := h.blocks[blockHash]
|
||||
require.True(h.t, ok)
|
||||
require.Equal(h.t, expBlock, block)
|
||||
|
||||
// Decrement how many clients queried the same block. Once we
|
||||
// have none left, remove it from the map.
|
||||
h.blocksQueried[blockHash]--
|
||||
if h.blocksQueried[blockHash] == 0 {
|
||||
delete(h.blocksQueried, blockHash)
|
||||
}
|
||||
|
||||
case <-time.After(5 * time.Second):
|
||||
select {
|
||||
case err := <-errChan:
|
||||
h.t.Fatalf("received unexpected error send: %v", err)
|
||||
default:
|
||||
}
|
||||
h.t.Fatal("expected reply from peer")
|
||||
}
|
||||
|
||||
// If we should expect a nil error to be sent by the internal
|
||||
// workManager to signal completion of the request, wait for it now.
|
||||
if expectCompletionSignal {
|
||||
select {
|
||||
case err := <-errChan:
|
||||
require.NoError(h.t, err)
|
||||
case <-time.After(5 * time.Second):
|
||||
h.t.Fatal("expected nil err to signal completion")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// assertNoPeerDialed asserts that the PrunedBlockDispatcher hasn't established
|
||||
// a new peer connection.
|
||||
func (h *prunedBlockDispatcherHarness) assertNoPeerDialed() {
|
||||
h.t.Helper()
|
||||
|
||||
select {
|
||||
case peer := <-h.dialedPeer:
|
||||
h.t.Fatalf("unexpected connection established with peer %v", peer)
|
||||
case <-time.After(2 * time.Second):
|
||||
}
|
||||
}
|
||||
|
||||
// assertNoReply asserts that the peer hasn't replied to a query.
|
||||
func (h *prunedBlockDispatcherHarness) assertNoReply(
|
||||
blockChan <-chan *wire.MsgBlock, errChan <-chan error) {
|
||||
|
||||
h.t.Helper()
|
||||
|
||||
select {
|
||||
case block := <-blockChan:
|
||||
h.t.Fatalf("received unexpected block %v", block.BlockHash())
|
||||
case err := <-errChan:
|
||||
h.t.Fatalf("received unexpected error send: %v", err)
|
||||
case <-time.After(2 * time.Second):
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrunedBlockDispatcherQuerySameBlock tests that client requests for the
|
||||
// same block result in only fetching the block once while pending.
|
||||
func TestPrunedBlockDispatcherQuerySameBlock(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const numBlocks = 1
|
||||
const numPeers = 5
|
||||
const numRequests = numBlocks * numPeers
|
||||
|
||||
h := newNetworkBlockTestHarness(t, numBlocks, numPeers, numPeers)
|
||||
h.start()
|
||||
defer h.stop()
|
||||
|
||||
// Queue all the block requests one by one.
|
||||
blockChans := make([]<-chan *wire.MsgBlock, 0, numRequests)
|
||||
errChans := make([]<-chan error, 0, numRequests)
|
||||
for i := 0; i < numRequests; i++ {
|
||||
blockChan, errChan := h.query(h.hashes)
|
||||
blockChans = append(blockChans, blockChan)
|
||||
errChans = append(errChans, errChan)
|
||||
}
|
||||
|
||||
// We should only see one query.
|
||||
h.assertPeerQueried()
|
||||
for i := 0; i < numRequests; i++ {
|
||||
h.assertPeerReplied(blockChans[i], errChans[i], i == 0)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrunedBlockDispatcherMultipleGetData tests that a client requesting blocks
|
||||
// that span across multiple queries works as intended.
|
||||
func TestPrunedBlockDispatcherMultipleGetData(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const maxRequestInvs = 5
|
||||
const numBlocks = (maxRequestInvs * 5) + 1
|
||||
|
||||
h := newNetworkBlockTestHarness(t, numBlocks, 1, 1)
|
||||
h.dispatcher.cfg.MaxRequestInvs = maxRequestInvs
|
||||
h.start()
|
||||
defer h.stop()
|
||||
|
||||
// Request all blocks.
|
||||
blockChan, errChan := h.query(h.hashes)
|
||||
|
||||
// Since we have more blocks than can fit in a single GetData message,
|
||||
// we should expect multiple queries. For each query, we should expect
|
||||
// wire.MaxInvPerMsg replies until we've received all of them.
|
||||
blocksRecvd := 0
|
||||
numMsgs := (numBlocks / maxRequestInvs)
|
||||
if numBlocks%wire.MaxInvPerMsg > 0 {
|
||||
numMsgs++
|
||||
}
|
||||
for i := 0; i < numMsgs; i++ {
|
||||
h.assertPeerQueried()
|
||||
for j := 0; j < maxRequestInvs; j++ {
|
||||
expectCompletionSignal := blocksRecvd == numBlocks-1
|
||||
h.assertPeerReplied(
|
||||
blockChan, errChan, expectCompletionSignal,
|
||||
)
|
||||
|
||||
blocksRecvd++
|
||||
if blocksRecvd == numBlocks {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrunedBlockDispatcherMultipleQueryPeers tests that client requests are
|
||||
// distributed across multiple query peers.
|
||||
func TestPrunedBlockDispatcherMultipleQueryPeers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const numBlocks = 10
|
||||
const numPeers = numBlocks / 2
|
||||
|
||||
h := newNetworkBlockTestHarness(t, numBlocks, numPeers, numPeers)
|
||||
h.start()
|
||||
defer h.stop()
|
||||
|
||||
// Queue all the block requests one by one.
|
||||
blockChans := make([]<-chan *wire.MsgBlock, 0, numBlocks)
|
||||
errChans := make([]<-chan error, 0, numBlocks)
|
||||
for i := 0; i < numBlocks; i++ {
|
||||
blockChan, errChan := h.query(h.hashes[i : i+1])
|
||||
blockChans = append(blockChans, blockChan)
|
||||
errChans = append(errChans, errChan)
|
||||
}
|
||||
|
||||
// We should see one query per block.
|
||||
for i := 0; i < numBlocks; i++ {
|
||||
h.assertPeerQueried()
|
||||
h.assertPeerReplied(blockChans[i], errChans[i], i == numBlocks-1)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrunedBlockDispatcherPeerPoller ensures that the peer poller can detect
|
||||
// when more connections are required to satisfy a request.
|
||||
func TestPrunedBlockDispatcherPeerPoller(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Initialize our harness as usual, but don't create any peers yet.
|
||||
h := newNetworkBlockTestHarness(t, 1, 0, 2)
|
||||
h.start()
|
||||
defer h.stop()
|
||||
|
||||
// We shouldn't see any peers dialed since we don't have any.
|
||||
h.assertNoPeerDialed()
|
||||
|
||||
// We'll then query for a block.
|
||||
blockChan, errChan := h.query(h.hashes)
|
||||
|
||||
// Refresh our peers. This would dial some peers, but we don't have any
|
||||
// yet.
|
||||
h.refreshPeers()
|
||||
h.assertNoPeerDialed()
|
||||
|
||||
// Add a new peer and force a refresh. We should see the peer be dialed.
|
||||
// We'll disable replies for now, as we'll want to test the disconnect
|
||||
// case.
|
||||
h.disablePeerReplies()
|
||||
peer := h.addPeer()
|
||||
h.refreshPeers()
|
||||
h.assertPeerDialed()
|
||||
h.assertPeerQueried()
|
||||
|
||||
// Disconnect our peer and re-enable replies.
|
||||
h.disconnectPeer(peer)
|
||||
h.enablePeerReplies()
|
||||
h.assertNoReply(blockChan, errChan)
|
||||
|
||||
// Force a refresh once again. Since the peer has disconnected, a new
|
||||
// connection should be made and the peer should be queried again.
|
||||
h.refreshPeers()
|
||||
h.assertPeerDialed()
|
||||
h.assertPeerQueried()
|
||||
|
||||
// Refresh our peers again. We can afford to have one more query peer,
|
||||
// but there isn't another one available. We also shouldn't dial the one
|
||||
// we're currently connected to again.
|
||||
h.refreshPeers()
|
||||
h.assertNoPeerDialed()
|
||||
|
||||
// Now that we know we've connected to the peer, we should be able to
|
||||
// receive their response.
|
||||
h.assertPeerReplied(blockChan, errChan, true)
|
||||
}
|
||||
|
||||
// TestPrunedBlockDispatcherInvalidBlock ensures that validation is performed on
|
||||
// blocks received from peers, and that any peers which have sent an invalid
|
||||
// block are banned and not connected to.
|
||||
func TestPrunedBlockDispatcherInvalidBlock(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
h := newNetworkBlockTestHarness(t, 1, 1, 1)
|
||||
h.start()
|
||||
defer h.stop()
|
||||
|
||||
// We'll start the test by signaling our peer to send an invalid block.
|
||||
h.enableInvalidPeerReplies()
|
||||
|
||||
// We'll then query for a block. We shouldn't see a response as the
|
||||
// block should have failed validation.
|
||||
blockChan, errChan := h.query(h.hashes)
|
||||
h.assertPeerQueried()
|
||||
h.assertNoReply(blockChan, errChan)
|
||||
|
||||
// Since the peer sent us an invalid block, they should have been
|
||||
// disconnected and banned. Refreshing our peers shouldn't result in a
|
||||
// new connection attempt because we don't have any other peers
|
||||
// available.
|
||||
h.refreshPeers()
|
||||
h.assertNoPeerDialed()
|
||||
|
||||
// Signal to our peers to send valid replies and add a new peer.
|
||||
h.enablePeerReplies()
|
||||
_ = h.addPeer()
|
||||
|
||||
// Force a refresh, which should cause our new peer to be dialed and
|
||||
// queried. We expect them to send a valid block and fulfill our
|
||||
// request.
|
||||
h.refreshPeers()
|
||||
h.assertPeerDialed()
|
||||
h.assertPeerQueried()
|
||||
h.assertPeerReplied(blockChan, errChan, true)
|
||||
}
|
229
chain/utils_test.go
Normal file
229
chain/utils_test.go
Normal file
|
@ -0,0 +1,229 @@
|
|||
package chain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/blockchain"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
// conn mocks a network connection by implementing the net.Conn interface. It is
|
||||
// used to test peer connection without actually opening a network connection.
|
||||
type conn struct {
|
||||
io.Reader
|
||||
io.Writer
|
||||
io.Closer
|
||||
localAddr string
|
||||
remoteAddr string
|
||||
}
|
||||
|
||||
func (c conn) LocalAddr() net.Addr {
|
||||
return &addr{"tcp", c.localAddr}
|
||||
}
|
||||
func (c conn) RemoteAddr() net.Addr {
|
||||
return &addr{"tcp", c.remoteAddr}
|
||||
}
|
||||
func (c conn) SetDeadline(t time.Time) error { return nil }
|
||||
func (c conn) SetReadDeadline(t time.Time) error { return nil }
|
||||
func (c conn) SetWriteDeadline(t time.Time) error { return nil }
|
||||
|
||||
// addr mocks a network address.
|
||||
type addr struct {
|
||||
net, address string
|
||||
}
|
||||
|
||||
func (m addr) Network() string { return m.net }
|
||||
func (m addr) String() string { return m.address }
|
||||
|
||||
// pipe turns two mock connections into a full-duplex connection similar to
|
||||
// net.Pipe to allow pipe's with (fake) addresses.
|
||||
func pipe(c1, c2 *conn) (*conn, *conn) {
|
||||
r1, w1 := io.Pipe()
|
||||
r2, w2 := io.Pipe()
|
||||
|
||||
c1.Writer = w1
|
||||
c1.Closer = w1
|
||||
c2.Reader = r1
|
||||
c1.Reader = r2
|
||||
c2.Writer = w2
|
||||
c2.Closer = w2
|
||||
|
||||
return c1, c2
|
||||
}
|
||||
|
||||
// calcMerkleRoot creates a merkle tree from the slice of transactions and
|
||||
// returns the root of the tree.
|
||||
//
|
||||
// This function was copied from:
|
||||
// https://github.com/btcsuite/btcd/blob/36a96f6a0025b6aeaebe4106821c2d46ee4be8d4/blockchain/fullblocktests/generate.go#L303
|
||||
func calcMerkleRoot(txns []*wire.MsgTx) chainhash.Hash {
|
||||
if len(txns) == 0 {
|
||||
return chainhash.Hash{}
|
||||
}
|
||||
|
||||
utilTxns := make([]*btcutil.Tx, 0, len(txns))
|
||||
for _, tx := range txns {
|
||||
utilTxns = append(utilTxns, btcutil.NewTx(tx))
|
||||
}
|
||||
merkles := blockchain.BuildMerkleTreeStore(utilTxns, false)
|
||||
return *merkles[len(merkles)-1]
|
||||
}
|
||||
|
||||
// solveBlock attempts to find a nonce which makes the passed block header hash
|
||||
// to a value less than the target difficulty. When a successful solution is
|
||||
// found true is returned and the nonce field of the passed header is updated
|
||||
// with the solution. False is returned if no solution exists.
|
||||
//
|
||||
// This function was copied from:
|
||||
// https://github.com/btcsuite/btcd/blob/36a96f6a0025b6aeaebe4106821c2d46ee4be8d4/blockchain/fullblocktests/generate.go#L324
|
||||
func solveBlock(header *wire.BlockHeader) bool {
|
||||
// sbResult is used by the solver goroutines to send results.
|
||||
type sbResult struct {
|
||||
found bool
|
||||
nonce uint32
|
||||
}
|
||||
|
||||
// Make sure all spawned goroutines finish executing before returning.
|
||||
var wg sync.WaitGroup
|
||||
defer func() {
|
||||
wg.Wait()
|
||||
}()
|
||||
|
||||
// solver accepts a block header and a nonce range to test. It is
|
||||
// intended to be run as a goroutine.
|
||||
targetDifficulty := blockchain.CompactToBig(header.Bits)
|
||||
quit := make(chan bool)
|
||||
results := make(chan sbResult)
|
||||
solver := func(hdr wire.BlockHeader, startNonce, stopNonce uint32) {
|
||||
defer wg.Done()
|
||||
|
||||
// We need to modify the nonce field of the header, so make sure
|
||||
// we work with a copy of the original header.
|
||||
for i := startNonce; i >= startNonce && i <= stopNonce; i++ {
|
||||
select {
|
||||
case <-quit:
|
||||
return
|
||||
default:
|
||||
hdr.Nonce = i
|
||||
hash := hdr.BlockHash()
|
||||
if blockchain.HashToBig(&hash).Cmp(
|
||||
targetDifficulty) <= 0 {
|
||||
|
||||
select {
|
||||
case results <- sbResult{true, i}:
|
||||
case <-quit:
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
select {
|
||||
case results <- sbResult{false, 0}:
|
||||
case <-quit:
|
||||
}
|
||||
}
|
||||
|
||||
startNonce := uint32(1)
|
||||
stopNonce := uint32(math.MaxUint32)
|
||||
numCores := uint32(runtime.NumCPU())
|
||||
noncesPerCore := (stopNonce - startNonce) / numCores
|
||||
wg.Add(int(numCores))
|
||||
for i := uint32(0); i < numCores; i++ {
|
||||
rangeStart := startNonce + (noncesPerCore * i)
|
||||
rangeStop := startNonce + (noncesPerCore * (i + 1)) - 1
|
||||
if i == numCores-1 {
|
||||
rangeStop = stopNonce
|
||||
}
|
||||
go solver(*header, rangeStart, rangeStop)
|
||||
}
|
||||
for i := uint32(0); i < numCores; i++ {
|
||||
result := <-results
|
||||
if result.found {
|
||||
close(quit)
|
||||
header.Nonce = result.nonce
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// genBlockChain generates a test chain with the given number of blocks.
|
||||
func genBlockChain(numBlocks uint32) ([]*chainhash.Hash, map[chainhash.Hash]*wire.MsgBlock) {
|
||||
prevHash := chainParams.GenesisHash
|
||||
prevHeader := &chainParams.GenesisBlock.Header
|
||||
|
||||
hashes := make([]*chainhash.Hash, numBlocks)
|
||||
blocks := make(map[chainhash.Hash]*wire.MsgBlock, numBlocks)
|
||||
|
||||
// Each block contains three transactions, including the coinbase
|
||||
// transaction. Each non-coinbase transaction spends outputs from
|
||||
// the previous block. We also need to produce blocks that succeed
|
||||
// validation through blockchain.CheckBlockSanity.
|
||||
script := []byte{0x01, 0x01}
|
||||
createTx := func(prevOut wire.OutPoint) *wire.MsgTx {
|
||||
return &wire.MsgTx{
|
||||
TxIn: []*wire.TxIn{{
|
||||
PreviousOutPoint: prevOut,
|
||||
SignatureScript: script,
|
||||
}},
|
||||
TxOut: []*wire.TxOut{{PkScript: script}},
|
||||
}
|
||||
}
|
||||
for i := uint32(0); i < numBlocks; i++ {
|
||||
txs := []*wire.MsgTx{
|
||||
createTx(wire.OutPoint{Index: wire.MaxPrevOutIndex}),
|
||||
createTx(wire.OutPoint{Hash: *prevHash, Index: 0}),
|
||||
createTx(wire.OutPoint{Hash: *prevHash, Index: 1}),
|
||||
}
|
||||
header := &wire.BlockHeader{
|
||||
Version: 1,
|
||||
PrevBlock: *prevHash,
|
||||
MerkleRoot: calcMerkleRoot(txs),
|
||||
Timestamp: prevHeader.Timestamp.Add(10 * time.Minute),
|
||||
Bits: chainParams.PowLimitBits,
|
||||
Nonce: 0,
|
||||
}
|
||||
if !solveBlock(header) {
|
||||
panic(fmt.Sprintf("could not solve block at idx %v", i))
|
||||
}
|
||||
block := &wire.MsgBlock{
|
||||
Header: *header,
|
||||
Transactions: txs,
|
||||
}
|
||||
|
||||
blockHash := block.BlockHash()
|
||||
hashes[i] = &blockHash
|
||||
blocks[blockHash] = block
|
||||
|
||||
prevHash = &blockHash
|
||||
prevHeader = header
|
||||
}
|
||||
|
||||
return hashes, blocks
|
||||
}
|
||||
|
||||
// producesInvalidBlock produces a copy of the block that duplicates the last
|
||||
// transaction. When the block has an odd number of transactions, this results
|
||||
// in the invalid block maintaining the same hash as the valid block.
|
||||
func produceInvalidBlock(block *wire.MsgBlock) *wire.MsgBlock {
|
||||
numTxs := len(block.Transactions)
|
||||
lastTx := block.Transactions[numTxs-1]
|
||||
blockCopy := &wire.MsgBlock{
|
||||
Header: block.Header,
|
||||
Transactions: make([]*wire.MsgTx, numTxs),
|
||||
}
|
||||
copy(blockCopy.Transactions, block.Transactions)
|
||||
blockCopy.AddTransaction(lastTx)
|
||||
return blockCopy
|
||||
}
|
5
go.mod
5
go.mod
|
@ -1,7 +1,7 @@
|
|||
module github.com/btcsuite/btcwallet
|
||||
|
||||
require (
|
||||
github.com/btcsuite/btcd v0.20.1-beta.0.20200513120220-b470eee47728
|
||||
github.com/btcsuite/btcd v0.21.0-beta.0.20210316172410-f86ae60936d7
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
|
||||
github.com/btcsuite/btcutil/psbt v1.0.3-0.20201208143702-a53e38424cce
|
||||
|
@ -18,8 +18,9 @@ require (
|
|||
github.com/kkdai/bstream v0.0.0-20181106074824-b3251f7901ec // indirect
|
||||
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf
|
||||
github.com/lightninglabs/neutrino v0.11.0
|
||||
github.com/lightningnetwork/lnd/ticker v1.0.0
|
||||
github.com/stretchr/testify v1.5.1
|
||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
|
||||
google.golang.org/genproto v0.0.0-20190201180003-4b09977fb922 // indirect
|
||||
google.golang.org/grpc v1.18.0
|
||||
|
|
29
go.sum
29
go.sum
|
@ -1,16 +1,15 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
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.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0=
|
||||
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
|
||||
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/btcd v0.20.1-beta.0.20200513120220-b470eee47728 h1:kF1MN22IdIZ1I7VMgS5WuihFuYaWOoP69Btm4bLUBxY=
|
||||
github.com/btcsuite/btcd v0.20.1-beta.0.20200513120220-b470eee47728/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||
github.com/btcsuite/btcd v0.21.0-beta.0.20210316172410-f86ae60936d7 h1:NOnU2sx+tjFC/gao1wGSQhX7danZx+RjiCAMBN1o48I=
|
||||
github.com/btcsuite/btcd v0.21.0-beta.0.20210316172410-f86ae60936d7/go.mod h1:Sv4JPQ3/M+teHz9Bo5jBpkNcP0x6r7rdihlNL/7tTAs=
|
||||
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=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2uts=
|
||||
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ=
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o=
|
||||
github.com/btcsuite/btcutil/psbt v1.0.3-0.20201208143702-a53e38424cce h1:3PRwz+js0AMMV1fHRrCdQ55akoomx4Q3ulozHC3BDDY=
|
||||
|
@ -27,11 +26,12 @@ github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3
|
|||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495 h1:6IyqGr3fnd0tM3YxipK27TUskaOVUjU2nG45yzwcQKY=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
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/decred/dcrd/lru v1.0.0 h1:Kbsb1SFDsIlaupWPwsPp+dkxiBY1frcS07PCPgotKz8=
|
||||
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
|
||||
|
@ -42,14 +42,12 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM
|
|||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89 h1:12K8AlpT0/6QUXSfV0yi4Q0jkbq8NDtIKFtF61AoqV0=
|
||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
|
||||
github.com/jessevdk/go-flags v1.4.0/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/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
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 v0.0.0-20181106074824-b3251f7901ec h1:n1NeQ3SgUHyISrjFFoO5dR748Is8dBL9qpaTNfphQrs=
|
||||
github.com/kkdai/bstream v0.0.0-20181106074824-b3251f7901ec/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
|
@ -68,11 +66,9 @@ github.com/lightningnetwork/lnd/queue v1.0.1 h1:jzJKcTy3Nj5lQrooJ3aaw9Lau3I0IwvQ
|
|||
github.com/lightningnetwork/lnd/queue v1.0.1/go.mod h1:vaQwexir73flPW43Mrm7JOgJHmcEFBWWSl9HlyASoms=
|
||||
github.com/lightningnetwork/lnd/ticker v1.0.0 h1:S1b60TEGoTtCe2A0yeB+ecoj/kkS4qpwh6l+AkQEZwU=
|
||||
github.com/lightningnetwork/lnd/ticker v1.0.0/go.mod h1:iaLXJiVgI1sPANIF2qYYUJXjoksPNvGNYowB8aRbpX0=
|
||||
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=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.1 h1:PZSj/UFNaVp3KxrzHOcS7oyuWA7LoOY/77yCTEFu21U=
|
||||
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
|
@ -83,22 +79,19 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
|
|||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
go.etcd.io/bbolt v1.3.5-0.20200615073812-232d8fc87f50 h1:ASw9n1EHMftwnP3Az4XW6e308+gNsrHzmdhd0Olz9Hs=
|
||||
go.etcd.io/bbolt v1.3.5-0.20200615073812-232d8fc87f50/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
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/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
|
||||
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d h1:2+ZP7EfsZV7Vvmx3TIqSlSzATMkTAKqM14YGFPoSKjI=
|
||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181106065722-10aee1819953 h1:LuZIitY8waaxUfNIdtajyE/YzA/zyf0YxXG27VpLrkg=
|
||||
golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 h1:bfLnR+k0tq5Lqt6dflRLcZiz6UaXCMt3vhYJ1l4FQ80=
|
||||
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
|
@ -110,25 +103,20 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h
|
|||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/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/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190201180003-4b09977fb922 h1:mBVYJnbrXLA/ZCBTCe7PtEgAUP+1bg92qTaFoPHdz+8=
|
||||
google.golang.org/genproto v0.0.0-20190201180003-4b09977fb922/go.mod h1:L3J43x8/uS+qIUoksaLKe6OS3nUKxOKuIFz1sl2/jx4=
|
||||
google.golang.org/grpc v1.16.0 h1:dz5IJGuC2BB7qXR5AyHNwAUBhZscK2xVez7mznh72sY=
|
||||
google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
|
||||
google.golang.org/grpc v1.18.0 h1:IZl7mfBGfbhYx2p2rKRtYgDFw6SBz+kclmxYrCksPPA=
|
||||
google.golang.org/grpc v1.18.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
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=
|
||||
|
@ -136,7 +124,6 @@ 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.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
|
|
@ -212,8 +212,10 @@ var helpDescsEnUS = map[string]string{
|
|||
"listtransactionsresult-confirmations": "The number of block confirmations of the transaction",
|
||||
"listtransactionsresult-generated": "Whether the transaction output is a coinbase output",
|
||||
"listtransactionsresult-blockhash": "The hash of the block this transaction is mined in, or the empty string if unmined",
|
||||
"listtransactionsresult-blockheight": "The block height containing the transaction.",
|
||||
"listtransactionsresult-blockindex": "Unset",
|
||||
"listtransactionsresult-blocktime": "The Unix time of the block header this transaction is mined in, or 0 if unmined",
|
||||
"listtransactionsresult-label": "A comment for the address/transaction, if any",
|
||||
"listtransactionsresult-txid": "The hash of the transaction",
|
||||
"listtransactionsresult-vout": "The transaction output index",
|
||||
"listtransactionsresult-walletconflicts": "Unset",
|
||||
|
|
|
@ -26,8 +26,8 @@ func helpDescsEnUS() map[string]string {
|
|||
"listlockunspent": "listlockunspent\n\nReturns a JSON array of outpoints marked as locked (with lockunspent) for this wallet session.\n\nArguments:\nNone\n\nResult:\n[{\n \"txid\": \"value\", (string) The transaction hash of the referenced output\n \"vout\": n, (numeric) The output index of the referenced output\n},...]\n",
|
||||
"listreceivedbyaccount": "listreceivedbyaccount (minconf=1 includeempty=false includewatchonly=false)\n\nDEPRECATED -- Returns a JSON array of objects listing all accounts and the total amount received by each account.\n\nArguments:\n1. minconf (numeric, optional, default=1) Minimum number of block confirmations required before a transaction is considered\n2. includeempty (boolean, optional, default=false) Unused\n3. includewatchonly (boolean, optional, default=false) Unused\n\nResult:\n[{\n \"account\": \"value\", (string) The name of the account\n \"amount\": n.nnn, (numeric) Total amount received by payment addresses of the account valued in bitcoin\n \"confirmations\": n, (numeric) Number of block confirmations of the most recent transaction relevant to the account\n},...]\n",
|
||||
"listreceivedbyaddress": "listreceivedbyaddress (minconf=1 includeempty=false includewatchonly=false)\n\nReturns a JSON array of objects listing wallet payment addresses and their total received amounts.\n\nArguments:\n1. minconf (numeric, optional, default=1) Minimum number of block confirmations required before a transaction is considered\n2. includeempty (boolean, optional, default=false) Unused\n3. includewatchonly (boolean, optional, default=false) Unused\n\nResult:\n[{\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) The payment address\n \"amount\": n.nnn, (numeric) Total amount received by the payment address valued in bitcoin\n \"confirmations\": n, (numeric) Number of block confirmations of the most recent transaction relevant to the address\n \"txids\": [\"value\",...], (array of string) Transaction hashes of all transactions involving this address\n \"involvesWatchonly\": true|false, (boolean) Unset\n},...]\n",
|
||||
"listsinceblock": "listsinceblock (\"blockhash\" targetconfirmations=1 includewatchonly=false)\n\nReturns a JSON array of objects listing details of all wallet transactions after some block.\n\nArguments:\n1. blockhash (string, optional) Hash of the parent block of the first block to consider transactions from, or unset to list all transactions\n2. targetconfirmations (numeric, optional, default=1) Minimum number of block confirmations of the last block in the result object. Must be 1 or greater. Note: The transactions array in the result object is not affected by this parameter\n3. includewatchonly (boolean, optional, default=false) Unused\n\nResult:\n{\n \"transactions\": [{ (array of object) JSON array of objects containing verbose details of the each transaction\n \"abandoned\": true|false, (boolean) Unset\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) Payment address for a transaction output\n \"amount\": n.nnn, (numeric) The value of the transaction output valued in bitcoin\n \"bip125-replaceable\": \"value\", (string) Unset\n \"blockhash\": \"value\", (string) The hash of the block this transaction is mined in, or the empty string if unmined\n \"blockindex\": n, (numeric) Unset\n \"blocktime\": n, (numeric) The Unix time of the block header this transaction is mined in, or 0 if unmined\n \"category\": \"value\", (string) The kind of transaction: \"send\" for sent transactions, \"immature\" for immature coinbase outputs, \"generate\" for mature coinbase outputs, or \"recv\" for all other received outputs. Note: A single output may be included multiple times under different categories\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"fee\": n.nnn, (numeric) The total input value minus the total output value for sent transactions\n \"generated\": true|false, (boolean) Whether the transaction output is a coinbase output\n \"involveswatchonly\": true|false, (boolean) Unset\n \"time\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"timereceived\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"trusted\": true|false, (boolean) Unset\n \"txid\": \"value\", (string) The hash of the transaction\n \"vout\": n, (numeric) The transaction output index\n \"walletconflicts\": [\"value\",...], (array of string) Unset\n \"comment\": \"value\", (string) Unset\n \"otheraccount\": \"value\", (string) Unset\n },...], \n \"lastblock\": \"value\", (string) Hash of the latest-synced block to be used in later calls to listsinceblock\n} \n",
|
||||
"listtransactions": "listtransactions (\"account\" count=10 from=0 includewatchonly=false)\n\nReturns a JSON array of objects containing verbose details for wallet transactions.\n\nArguments:\n1. account (string, optional) DEPRECATED -- Unused (must be unset or \"*\")\n2. count (numeric, optional, default=10) Maximum number of transactions to create results from\n3. from (numeric, optional, default=0) Number of transactions to skip before results are created\n4. includewatchonly (boolean, optional, default=false) Unused\n\nResult:\n[{\n \"abandoned\": true|false, (boolean) Unset\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) Payment address for a transaction output\n \"amount\": n.nnn, (numeric) The value of the transaction output valued in bitcoin\n \"bip125-replaceable\": \"value\", (string) Unset\n \"blockhash\": \"value\", (string) The hash of the block this transaction is mined in, or the empty string if unmined\n \"blockindex\": n, (numeric) Unset\n \"blocktime\": n, (numeric) The Unix time of the block header this transaction is mined in, or 0 if unmined\n \"category\": \"value\", (string) The kind of transaction: \"send\" for sent transactions, \"immature\" for immature coinbase outputs, \"generate\" for mature coinbase outputs, or \"recv\" for all other received outputs. Note: A single output may be included multiple times under different categories\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"fee\": n.nnn, (numeric) The total input value minus the total output value for sent transactions\n \"generated\": true|false, (boolean) Whether the transaction output is a coinbase output\n \"involveswatchonly\": true|false, (boolean) Unset\n \"time\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"timereceived\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"trusted\": true|false, (boolean) Unset\n \"txid\": \"value\", (string) The hash of the transaction\n \"vout\": n, (numeric) The transaction output index\n \"walletconflicts\": [\"value\",...], (array of string) Unset\n \"comment\": \"value\", (string) Unset\n \"otheraccount\": \"value\", (string) Unset\n},...]\n",
|
||||
"listsinceblock": "listsinceblock (\"blockhash\" targetconfirmations=1 includewatchonly=false)\n\nReturns a JSON array of objects listing details of all wallet transactions after some block.\n\nArguments:\n1. blockhash (string, optional) Hash of the parent block of the first block to consider transactions from, or unset to list all transactions\n2. targetconfirmations (numeric, optional, default=1) Minimum number of block confirmations of the last block in the result object. Must be 1 or greater. Note: The transactions array in the result object is not affected by this parameter\n3. includewatchonly (boolean, optional, default=false) Unused\n\nResult:\n{\n \"transactions\": [{ (array of object) JSON array of objects containing verbose details of the each transaction\n \"abandoned\": true|false, (boolean) Unset\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) Payment address for a transaction output\n \"amount\": n.nnn, (numeric) The value of the transaction output valued in bitcoin\n \"bip125-replaceable\": \"value\", (string) Unset\n \"blockhash\": \"value\", (string) The hash of the block this transaction is mined in, or the empty string if unmined\n \"blockheight\": n, (numeric) The block height containing the transaction.\n \"blockindex\": n, (numeric) Unset\n \"blocktime\": n, (numeric) The Unix time of the block header this transaction is mined in, or 0 if unmined\n \"category\": \"value\", (string) The kind of transaction: \"send\" for sent transactions, \"immature\" for immature coinbase outputs, \"generate\" for mature coinbase outputs, or \"recv\" for all other received outputs. Note: A single output may be included multiple times under different categories\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"fee\": n.nnn, (numeric) The total input value minus the total output value for sent transactions\n \"generated\": true|false, (boolean) Whether the transaction output is a coinbase output\n \"involveswatchonly\": true|false, (boolean) Unset\n \"label\": \"value\", (string) A comment for the address/transaction, if any\n \"time\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"timereceived\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"trusted\": true|false, (boolean) Unset\n \"txid\": \"value\", (string) The hash of the transaction\n \"vout\": n, (numeric) The transaction output index\n \"walletconflicts\": [\"value\",...], (array of string) Unset\n \"comment\": \"value\", (string) Unset\n \"otheraccount\": \"value\", (string) Unset\n },...], \n \"lastblock\": \"value\", (string) Hash of the latest-synced block to be used in later calls to listsinceblock\n} \n",
|
||||
"listtransactions": "listtransactions (\"account\" count=10 from=0 includewatchonly=false)\n\nReturns a JSON array of objects containing verbose details for wallet transactions.\n\nArguments:\n1. account (string, optional) DEPRECATED -- Unused (must be unset or \"*\")\n2. count (numeric, optional, default=10) Maximum number of transactions to create results from\n3. from (numeric, optional, default=0) Number of transactions to skip before results are created\n4. includewatchonly (boolean, optional, default=false) Unused\n\nResult:\n[{\n \"abandoned\": true|false, (boolean) Unset\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) Payment address for a transaction output\n \"amount\": n.nnn, (numeric) The value of the transaction output valued in bitcoin\n \"bip125-replaceable\": \"value\", (string) Unset\n \"blockhash\": \"value\", (string) The hash of the block this transaction is mined in, or the empty string if unmined\n \"blockheight\": n, (numeric) The block height containing the transaction.\n \"blockindex\": n, (numeric) Unset\n \"blocktime\": n, (numeric) The Unix time of the block header this transaction is mined in, or 0 if unmined\n \"category\": \"value\", (string) The kind of transaction: \"send\" for sent transactions, \"immature\" for immature coinbase outputs, \"generate\" for mature coinbase outputs, or \"recv\" for all other received outputs. Note: A single output may be included multiple times under different categories\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"fee\": n.nnn, (numeric) The total input value minus the total output value for sent transactions\n \"generated\": true|false, (boolean) Whether the transaction output is a coinbase output\n \"involveswatchonly\": true|false, (boolean) Unset\n \"label\": \"value\", (string) A comment for the address/transaction, if any\n \"time\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"timereceived\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"trusted\": true|false, (boolean) Unset\n \"txid\": \"value\", (string) The hash of the transaction\n \"vout\": n, (numeric) The transaction output index\n \"walletconflicts\": [\"value\",...], (array of string) Unset\n \"comment\": \"value\", (string) Unset\n \"otheraccount\": \"value\", (string) Unset\n},...]\n",
|
||||
"listunspent": "listunspent (minconf=1 maxconf=9999999 [\"address\",...])\n\nReturns a JSON array of objects representing unlocked unspent outputs controlled by wallet keys.\n\nArguments:\n1. minconf (numeric, optional, default=1) Minimum number of block confirmations required before a transaction output is considered\n2. maxconf (numeric, optional, default=9999999) Maximum number of block confirmations required before a transaction output is excluded\n3. addresses (array of string, optional) If set, limits the returned details to unspent outputs received by any of these payment addresses\n\nResult:\n{\n \"txid\": \"value\", (string) The transaction hash of the referenced output\n \"vout\": n, (numeric) The output index of the referenced output\n \"address\": \"value\", (string) The payment address that received the output\n \"account\": \"value\", (string) The account associated with the receiving payment address\n \"scriptPubKey\": \"value\", (string) The output script encoded as a hexadecimal string\n \"redeemScript\": \"value\", (string) Unset\n \"amount\": n.nnn, (numeric) The amount of the output valued in bitcoin\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"spendable\": true|false, (boolean) Whether the output is entirely controlled by wallet keys/scripts (false for partially controlled multisig outputs or outputs to watch-only addresses)\n} \n",
|
||||
"lockunspent": "lockunspent unlock [{\"txid\":\"value\",\"vout\":n},...]\n\nLocks or unlocks an unspent output.\nLocked outputs are not chosen for transaction inputs of authored transactions and are not included in 'listunspent' results.\nLocked outputs are volatile and are not saved across wallet restarts.\nIf unlock is true and no transaction outputs are specified, all locked outputs are marked unlocked.\n\nArguments:\n1. unlock (boolean, required) True to unlock outputs, false to lock\n2. transactions (array of object, required) Transaction outputs to lock or unlock\n[{\n \"txid\": \"value\", (string) The transaction hash of the referenced output\n \"vout\": n, (numeric) The output index of the referenced output\n},...]\n\nResult:\ntrue|false (boolean) The boolean 'true'\n",
|
||||
"sendfrom": "sendfrom \"fromaccount\" \"toaddress\" amount (minconf=1 \"comment\" \"commentto\")\n\nDEPRECATED -- Authors, signs, and sends a transaction that outputs some amount to a payment address.\nA change output is automatically included to send extra output value back to the original account.\n\nArguments:\n1. fromaccount (string, required) Account to pick unspent outputs from\n2. toaddress (string, required) Address to pay\n3. amount (numeric, required) Amount to send to the payment address valued in bitcoin\n4. minconf (numeric, optional, default=1) Minimum number of block confirmations required before a transaction output is eligible to be spent\n5. comment (string, optional) Unused\n6. commentto (string, optional) Unused\n\nResult:\n\"value\" (string) The transaction hash of the sent transaction\n",
|
||||
|
@ -45,8 +45,8 @@ func helpDescsEnUS() map[string]string {
|
|||
"exportwatchingwallet": "exportwatchingwallet (\"account\" download=false)\n\nCreates and returns a duplicate of the wallet database without any private keys to be used as a watching-only wallet.\n\nArguments:\n1. account (string, optional) Unused (must be unset or \"*\")\n2. download (boolean, optional, default=false) Unused\n\nResult:\n\"value\" (string) The watching-only database encoded as a base64 string\n",
|
||||
"getbestblock": "getbestblock\n\nReturns the hash and height of the newest block in the best chain that wallet has finished syncing with.\n\nArguments:\nNone\n\nResult:\n{\n \"hash\": \"value\", (string) The hash of the block\n \"height\": n, (numeric) The blockchain height of the block\n} \n",
|
||||
"getunconfirmedbalance": "getunconfirmedbalance (\"account\")\n\nCalculates the unspent output value of all unmined transaction outputs for an account.\n\nArguments:\n1. account (string, optional) The account to query the unconfirmed balance for (default=\"default\")\n\nResult:\nn.nnn (numeric) Total amount of all unmined unspent outputs of the account valued in bitcoin.\n",
|
||||
"listaddresstransactions": "listaddresstransactions [\"address\",...] (\"account\")\n\nReturns a JSON array of objects containing verbose details for wallet transactions pertaining some addresses.\n\nArguments:\n1. addresses (array of string, required) Addresses to filter transaction results by\n2. account (string, optional) Unused (must be unset or \"*\")\n\nResult:\n[{\n \"abandoned\": true|false, (boolean) Unset\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) Payment address for a transaction output\n \"amount\": n.nnn, (numeric) The value of the transaction output valued in bitcoin\n \"bip125-replaceable\": \"value\", (string) Unset\n \"blockhash\": \"value\", (string) The hash of the block this transaction is mined in, or the empty string if unmined\n \"blockindex\": n, (numeric) Unset\n \"blocktime\": n, (numeric) The Unix time of the block header this transaction is mined in, or 0 if unmined\n \"category\": \"value\", (string) The kind of transaction: \"send\" for sent transactions, \"immature\" for immature coinbase outputs, \"generate\" for mature coinbase outputs, or \"recv\" for all other received outputs. Note: A single output may be included multiple times under different categories\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"fee\": n.nnn, (numeric) The total input value minus the total output value for sent transactions\n \"generated\": true|false, (boolean) Whether the transaction output is a coinbase output\n \"involveswatchonly\": true|false, (boolean) Unset\n \"time\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"timereceived\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"trusted\": true|false, (boolean) Unset\n \"txid\": \"value\", (string) The hash of the transaction\n \"vout\": n, (numeric) The transaction output index\n \"walletconflicts\": [\"value\",...], (array of string) Unset\n \"comment\": \"value\", (string) Unset\n \"otheraccount\": \"value\", (string) Unset\n},...]\n",
|
||||
"listalltransactions": "listalltransactions (\"account\")\n\nReturns a JSON array of objects in the same format as 'listtransactions' without limiting the number of returned objects.\n\nArguments:\n1. account (string, optional) Unused (must be unset or \"*\")\n\nResult:\n[{\n \"abandoned\": true|false, (boolean) Unset\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) Payment address for a transaction output\n \"amount\": n.nnn, (numeric) The value of the transaction output valued in bitcoin\n \"bip125-replaceable\": \"value\", (string) Unset\n \"blockhash\": \"value\", (string) The hash of the block this transaction is mined in, or the empty string if unmined\n \"blockindex\": n, (numeric) Unset\n \"blocktime\": n, (numeric) The Unix time of the block header this transaction is mined in, or 0 if unmined\n \"category\": \"value\", (string) The kind of transaction: \"send\" for sent transactions, \"immature\" for immature coinbase outputs, \"generate\" for mature coinbase outputs, or \"recv\" for all other received outputs. Note: A single output may be included multiple times under different categories\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"fee\": n.nnn, (numeric) The total input value minus the total output value for sent transactions\n \"generated\": true|false, (boolean) Whether the transaction output is a coinbase output\n \"involveswatchonly\": true|false, (boolean) Unset\n \"time\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"timereceived\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"trusted\": true|false, (boolean) Unset\n \"txid\": \"value\", (string) The hash of the transaction\n \"vout\": n, (numeric) The transaction output index\n \"walletconflicts\": [\"value\",...], (array of string) Unset\n \"comment\": \"value\", (string) Unset\n \"otheraccount\": \"value\", (string) Unset\n},...]\n",
|
||||
"listaddresstransactions": "listaddresstransactions [\"address\",...] (\"account\")\n\nReturns a JSON array of objects containing verbose details for wallet transactions pertaining some addresses.\n\nArguments:\n1. addresses (array of string, required) Addresses to filter transaction results by\n2. account (string, optional) Unused (must be unset or \"*\")\n\nResult:\n[{\n \"abandoned\": true|false, (boolean) Unset\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) Payment address for a transaction output\n \"amount\": n.nnn, (numeric) The value of the transaction output valued in bitcoin\n \"bip125-replaceable\": \"value\", (string) Unset\n \"blockhash\": \"value\", (string) The hash of the block this transaction is mined in, or the empty string if unmined\n \"blockheight\": n, (numeric) The block height containing the transaction.\n \"blockindex\": n, (numeric) Unset\n \"blocktime\": n, (numeric) The Unix time of the block header this transaction is mined in, or 0 if unmined\n \"category\": \"value\", (string) The kind of transaction: \"send\" for sent transactions, \"immature\" for immature coinbase outputs, \"generate\" for mature coinbase outputs, or \"recv\" for all other received outputs. Note: A single output may be included multiple times under different categories\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"fee\": n.nnn, (numeric) The total input value minus the total output value for sent transactions\n \"generated\": true|false, (boolean) Whether the transaction output is a coinbase output\n \"involveswatchonly\": true|false, (boolean) Unset\n \"label\": \"value\", (string) A comment for the address/transaction, if any\n \"time\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"timereceived\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"trusted\": true|false, (boolean) Unset\n \"txid\": \"value\", (string) The hash of the transaction\n \"vout\": n, (numeric) The transaction output index\n \"walletconflicts\": [\"value\",...], (array of string) Unset\n \"comment\": \"value\", (string) Unset\n \"otheraccount\": \"value\", (string) Unset\n},...]\n",
|
||||
"listalltransactions": "listalltransactions (\"account\")\n\nReturns a JSON array of objects in the same format as 'listtransactions' without limiting the number of returned objects.\n\nArguments:\n1. account (string, optional) Unused (must be unset or \"*\")\n\nResult:\n[{\n \"abandoned\": true|false, (boolean) Unset\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) Payment address for a transaction output\n \"amount\": n.nnn, (numeric) The value of the transaction output valued in bitcoin\n \"bip125-replaceable\": \"value\", (string) Unset\n \"blockhash\": \"value\", (string) The hash of the block this transaction is mined in, or the empty string if unmined\n \"blockheight\": n, (numeric) The block height containing the transaction.\n \"blockindex\": n, (numeric) Unset\n \"blocktime\": n, (numeric) The Unix time of the block header this transaction is mined in, or 0 if unmined\n \"category\": \"value\", (string) The kind of transaction: \"send\" for sent transactions, \"immature\" for immature coinbase outputs, \"generate\" for mature coinbase outputs, or \"recv\" for all other received outputs. Note: A single output may be included multiple times under different categories\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"fee\": n.nnn, (numeric) The total input value minus the total output value for sent transactions\n \"generated\": true|false, (boolean) Whether the transaction output is a coinbase output\n \"involveswatchonly\": true|false, (boolean) Unset\n \"label\": \"value\", (string) A comment for the address/transaction, if any\n \"time\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"timereceived\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"trusted\": true|false, (boolean) Unset\n \"txid\": \"value\", (string) The hash of the transaction\n \"vout\": n, (numeric) The transaction output index\n \"walletconflicts\": [\"value\",...], (array of string) Unset\n \"comment\": \"value\", (string) Unset\n \"otheraccount\": \"value\", (string) Unset\n},...]\n",
|
||||
"renameaccount": "renameaccount \"oldaccount\" \"newaccount\"\n\nRenames an account.\n\nArguments:\n1. oldaccount (string, required) The old account name to rename\n2. newaccount (string, required) The new name for the account\n\nResult:\nNothing\n",
|
||||
"walletislocked": "walletislocked\n\nReturns whether or not the wallet is locked.\n\nArguments:\nNone\n\nResult:\ntrue|false (boolean) Whether the wallet is locked\n",
|
||||
}
|
||||
|
|
|
@ -461,9 +461,13 @@ out:
|
|||
wsc.wg.Add(1)
|
||||
go func() {
|
||||
resp, jsonErr := f()
|
||||
mresp, err := btcjson.MarshalResponse(req.ID, resp, jsonErr)
|
||||
mresp, err := btcjson.MarshalResponse(
|
||||
btcjson.RpcVersion1, req.ID,
|
||||
resp, jsonErr,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Unable to marshal response: %v", err)
|
||||
log.Errorf("Unable to marshal "+
|
||||
"response: %v", err)
|
||||
} else {
|
||||
_ = wsc.send(mresp)
|
||||
}
|
||||
|
@ -560,7 +564,10 @@ func (s *Server) postClientRPC(w http.ResponseWriter, r *http.Request) {
|
|||
var req btcjson.Request
|
||||
err = json.Unmarshal(rpcRequest, &req)
|
||||
if err != nil {
|
||||
resp, err := btcjson.MarshalResponse(req.ID, nil, btcjson.ErrRPCInvalidRequest)
|
||||
resp, err := btcjson.MarshalResponse(
|
||||
btcjson.RpcVersion1, req.ID, nil,
|
||||
btcjson.ErrRPCInvalidRequest,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Unable to marshal response: %v", err)
|
||||
http.Error(w, "500 Internal Server Error",
|
||||
|
@ -592,7 +599,9 @@ func (s *Server) postClientRPC(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Marshal and send.
|
||||
mresp, err := btcjson.MarshalResponse(req.ID, res, jsonErr)
|
||||
mresp, err := btcjson.MarshalResponse(
|
||||
btcjson.RpcVersion1, req.ID, res, jsonErr,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Unable to marshal response: %v", err)
|
||||
http.Error(w, "500 Internal Server Error", http.StatusInternalServerError)
|
||||
|
|
Loading…
Reference in a new issue