Commit graph

238 commits

Author SHA1 Message Date
pedro martelletto c8627cbee4 Use a harcoded key to generate filters
Pointed out by alex@. Using a dummy key for now.
2018-05-23 16:46:15 -07:00
pedro martelletto dc25da8296 Generate a filter for a given block 2018-05-23 16:46:15 -07:00
pedro martelletto e9298934b9 Add a stub GetCBFilter message.
Actual semantic and payload format yet to be defined.
2018-05-23 16:46:15 -07:00
pedro martelletto 333af136ef Create a knob to switch CBFs off.
While having them on by default. We may want to revisit this and
make no CBFs the default.
2018-05-23 16:46:15 -07:00
Olaoluwa Osuntokun 2842f933bb server: fix linter error 2018-05-15 20:47:29 -07:00
Nicola 'tekNico' Larosa 11fcd83963 btcd/multi: fix a number of typos in comments. 2018-01-25 23:23:59 -06:00
Dave Collins 8c883d1fca
blockchain/indexers: Allow interrupts.
This propagates the interrupt channel through to blockchain and the
indexers so that it is possible to interrupt long-running operations
such as catching up indexes.
2017-09-05 11:02:46 -05:00
Jim Posen 30d4caeac6 server: Simplify logic to bind listeners.
The helper function parseListeners has been changed to return a
slice of net.Addrs with Network() returning tcp4 or tcp6 instead of
returning two slices of IPv4 and IPv6 addresses to simplify calling
code. Also improves how local addresses are added to the address
manager when listening on wildcard addresses.

Also splits some newServer logic into new method initListeners.
2017-09-04 11:55:37 -07:00
David Hill a2085c68f8 config: Add --whitelist support. 2017-08-31 09:59:43 -04:00
Dave Collins 9bd7bcfff6
travis: Update to go 1.8 and 1.9.
Also, make the gosimple linter happy while here.
2017-08-30 01:03:26 -05:00
Andy Weidenbaum a1d1ea70dd rm extra word segwit, s/segwit segwit/segwit 2017-08-26 10:56:46 -07:00
Jim Posen 46fd4ec358 netsync: Change name of blockManager to syncManager. 2017-08-25 13:41:22 -05:00
Dave Collins 34b1373a68
blockchain: Refactor inv discovery for chain view.
This refactors the code that locates blocks (inventory discovery) out of
server and into blockchain where it can make use of the new much more
efficient chain view and more easily be tested.  As an aside, it really
belongs in blockchain anyways since it's purely dealing with the block
index and best chain.

Since the majority of the network has moved to header-based semantics,
this also provides an additional optimization to allow headers to be
located directly versus needing to first discover the hashes and then
fetch the headers.

The new functions are named LocateBlocks and LocateHeaders.  The former
returns a slice of located hashes and the latter returns a slice of
located headers.

Finally, it also updates the RPC server getheaders call and related
plumbing to use the new LocateHeaders function.

A comprehensive suite of tests is provided to ensure both functions
behave correctly for both correct and incorrect block locators.
2017-08-24 14:15:34 -05:00
Jim Posen 08955805d5 blockmanager: Remove serverPeer from blockmanager completely.
The purpose is to remove the dependency of blockmanager on serverPeer,
which is defined in the main package. Instead, we split out some of
the fields from serverPeer into a separate struct called peerSyncState
in blockmanager.go. While they are in the same package now, this
change makes it easier to move blockManager into its own package along
with peerSyncState. The blockManager tracks a map of Peer pointers to
the peer state and keeps it updated as peers connect and disconnect.
2017-08-23 10:02:12 -07:00
Jim Posen 088ccfd828 blockmanager: Remove dependency on cfg in main package. 2017-08-23 11:45:25 -05:00
Jim Posen 28606122c3 main: Reduce shared state between server and blockManager.
Instead of having both server and blockManager be aware of the
txProcessed and blockProcessed channels, now the server passed them as
method arguments to blockProcessor.
2017-08-15 15:41:59 -05:00
Jim Posen 095bba1a25 peer: Move IsWitnessEnabled() from serverPeer to Peer.
serverPeer is a problematic struct because it is local to the main
package.
2017-08-15 11:34:17 -07:00
Dave Collins c5c46376ba
rpcserver: Refactor listener logic to server.
This refactors the RPC server to accept and take ownership of already
configured listeners and refactors the logic to setup those listeners to
the server.  This mirrors the logic used by the connection manager and
is desirable since it is another step closer to being able to split the
RPC server code out into a separate package and will make it much easier
to internally test since it allows creating mock listeners.
2017-08-15 01:07:38 -05:00
Dave Collins a7a1029445
rpcserver: Decouple from server.
This decouples the RPC server from the internal btcd server to move
closer to being able to split it out into a separate package.

In order to accomplish this, it introduces an rpcserverConfig type and
several new interfaces, named rpcserverPeer, rpcserverConnManager, and
rpcserverBlockManager, which are necessary to break the direct
dependencies on the main server and block manager instances.

It also adds concrete implementations of the new interfaces and uses
them to configure the RPC server.

Ultimately, the RPC server should ideally be decoupled even more such
that all of the types in the configuration struct use interfaces instead
of the concrete types.  Doing this would make the RPC server much easier
to internally test since it would allow creating lightweight stubs for
the various pieces.
2017-08-14 23:01:07 -05:00
Jim Posen b71d6c3010 Create blockManagerConfig struct passed to newBlockManager.
The config struct accepts an instance of server as an implementation
of the new PeerNotifier wrapping interface.
2017-08-14 20:19:02 -07:00
Jim Posen 49949d4c96 Remove references from blockManager to rpcServer.
Instead of having the block manager notify the RPC server about
accepted, connected, and disconnected blocks, the RPC server will
directly listen for notifications from the blockchain.
2017-08-14 20:14:42 -07:00
Jim Posen 22de1f6d08 Create blockmanager with reference to txMemPool.
The objective is to remove the reference from blockManager to
server. Since the blockManager is responsible for keeping the mempool
in sync, it should have a direct reference to it.
2017-08-14 20:14:42 -07:00
Olaoluwa Osuntokun 1244c45b88 mining+config: modify GBT mining to limit by weight, add witness commitment
This commit modifies the existing block selection logic to limit
preferentially by weight instead of serialized block size, and also to
adhere to the new sig-op cost limits which are weighted according to
the witness discount.
2017-08-13 23:17:40 -05:00
Olaoluwa Osuntokun 26ff8ddce4 mempool: modify mempool sanity checks to be segwit aware 2017-08-13 23:17:40 -05:00
Olaoluwa Osuntokun 0db14c740b BIP0144: properly fetch witness data from witness-enabled peers
This commit modifies the logic within the block manager and service to
preferentially fetch transactions and blocks which include witness data
from fully upgraded peers.

Once the initial version handshake has completed, the server now tracks
which of the connected peers are witness enabled (they advertise
SFNodeWitness). From then on, if a peer is witness enabled, then btcd
will always request full witness data when fetching
transactions/blocks.
2017-08-13 23:17:40 -05:00
Ricardo Velhote 948d80b198
New RPC command to display the uptime of the server
Version 0.15.0 of Bitcoin Core will include a new RPC command that will
allow us to obtain the amount of time (in seconds) that the server has
been running.
2017-07-03 00:07:27 +01:00
Steven Roose bf43e56f2f Fix warnings from ineffassign
I left one at the end of fullblocktest, since I suspected the unused
variable assignments there were set for the possibility of extending the
tests.
2017-06-07 17:59:33 -05:00
Steven Roose 3d0dfed40b Fix a ton of typos accumulated over time 2017-05-30 16:59:51 +02:00
Steven Roose 53f55a4634 config: Add user agent comments flag --uacomment
Just like Core's -uacomment, this flag allows to specify user agent
comments like defined in BIP 14.
2017-05-17 13:22:26 +02:00
Dave Collins d06c0bb181
blockchain: Use hash values in structs.
This modifies the blockNode and BestState structs in the blockchain
package to store hashes directly instead of pointers to them and updates
callers to deal with the API change in the exported BestState struct.

In general, the preferred approach for hashes moving forward is to store
hash values in complex data structures, particularly those that will be
used for cache entries, and accept pointers to hashes in arguments to
functions.

Some of the reasoning behind making this change is:

- It is generally preferred to avoid storing pointers to data in cache
  objects since doing so can easily lead to storing interior pointers
  into other structs that then can't be GC'd
- Keeping the hash values directly in the block node provides better
  cache locality
2017-02-03 11:36:33 -06:00
Dave Collins 59169540c3
blockchain: Reconstruct headers from block nodes.
This modifies the block node structure to include a couple of extra
fields needed to be able to reconstruct the block header from a node,
and exposes a new function from chain to fetch the block headers which
takes advantage of the new functionality to reconstruct the headers from
memory when possible.  Finally, it updates both the p2p and RPC servers
to make use of the new function.

This is useful since many of the block header fields need to be kept in
order to form the block index anyways and storing the extra fields means
the database does not have to be consulted when headers are requested if
the associated node is still in memory.

The following timings show representative performance gains as measured
from one system:

new: Time to fetch 100000 headers:   59ms
old: Time to fetch 100000 headers: 4783ms
2017-02-01 12:27:56 -06:00
David Hill ecd348b2a7 btcd: disable mempool requests if bloom filtering is disabled 2017-01-27 20:51:25 -06:00
David Hill db5b9aef91 btcd: fix rebroadcasting of local txs. 2017-01-27 10:28:48 -05:00
David Hill 9bedd7720c btcd: only allow one getaddr request per peer 2017-01-25 12:05:55 -05:00
Javed Khan 8caa921ac3 server: Fix connections to onion nodes.
A DNS lookup was being attempted on onion addresses causing
connections to fail. This has been fixed by introducing type
onionAddr (which implements a net.Addr interface) and passing
it to btcdDial.

Also, the following onion related fixes have been made:

* getaddednodeinfo - updated to handle onion addrs.
* TorLookupIP - fixed err being shadowed.
* newServer - rename tcpAddr to netAddr
* addrStringToNetAddr - skip if host is already an IP addr.
* addrStringToNetAddr - err if tor is disabled
* getaddednodeinfo - check if host is already an IP addr.
2017-01-18 21:40:41 +05:30
Alex 7c44b6472f Port getheaders JSON-RPC command from dcrd 2017-01-10 19:11:18 -07:00
David de Kloet 4021ae2f6e server.go: Optimize newAddressFunc
Change the order of conditions to avoid calling fmt.Sprintf
unnecessarily.
2016-12-08 22:55:43 +01:00
Steven Roose 95e6de00b8 btcd: fix error in mempool response inv counting 2016-11-25 10:30:24 +01:00
dskloet e1b2ceca80 addrmgr: Remove unused param from GetAddress()
addrmgr.GetAddress() had a parameter `class string` originally intended
to support looking up addresses according to some type of filter such as
IPv4, IPv6, and only those which support specific wire.ServiceFlags
(full nodes, nodes that support bloom filters, nodes that support
segwit, etc). But currently the parameter is unused and also has an
inappropriate type `string`.

If it would ever be used, it's easy to add back and should then get an
appropriate type such as something that allows bitflags to be set so
that the caller could request combinations such as peers that support
IPv6, are full nodes, and support bloom filters.
2016-11-21 08:56:46 -06:00
David Hill 807d344fe9 Unassign some TODO's 2016-11-15 17:47:33 -06:00
Dave Collins 0d4546c965
server: Return error on address lookup fails.
This corrects an issue introduced by commit
e8f63bc295 where a failure to lookup a
hostname could lead to a panic in certain circumstances.  An error is
now returned in that case as expected.
2016-11-11 20:54:25 -06:00
Olaoluwa Osuntokun e8f63bc295
connmgr: switch to using net.Addr interface throughout for addresses
This commit modifies the `ConnManager` to use the `net.Add` interface
through the package instead of a plain string to represent and
manipulate addresses. This change makes the package much more general as
users of the package can possibly utilize custom implementations of the
`net.Addr` interface to establish connections.

More precisely, the `ConnReq` struct has been modified to use a net.Addr
instance explicitly, and the `DialFunc` type has also been modified to
take a `net.Addr` directly. This latter change gives functions that
adhere to the `DialFunc` type more flexibility as to exactly how the
connection is established.

Additionally, the `connmgr.Config.GetNewAddress` configuration option
now directly returns a `net.Addr. This change allows the `connmgr` to be
decoupled from all DNS queries which allows callers to preferentially
select more secure methods like performing DNS lookups over a Tor proxy.
2016-11-10 11:22:36 -08:00
Dave Collins df33d4340e
server: Ensure callbacks use the server peer.
This modifies the signatures of all serverPeer callbacks that are
provided as peer.Listeners to use _ for the first parameter name which
ensures the passed peer can't be used within the function and updates
all references to the server peer.

This helps ensure any overridden methods that might be defined on a
serverPeer will be invoked where directly calling methods on the passed
peer would not.

Also, while here, add a comment to the OnFeeFilter function.
2016-11-04 13:38:13 -05:00
Dave Collins d98430d8ca
connmgr: Implement inbound connection handling.
This modifies the connection manager to provide support for accepting
inbound connections on a caller-provided set of listeners and notify the
caller via a callback.

This is only the minimum work necessary to get inbound support into the
connection manager.  The intention for future commits is to move more
connection-related logic such as limiting the maximum number of overall
connections and banned peer tracking into the connection manager.
2016-11-04 13:14:44 -05:00
Dave Collins ea9bf748bb
connmgr: Remove type defs for callbacks.
This removes the type definitions for the callback functions in favor of
declaring them directly in the Config struct.  This is more consistent
with the rest of the code base and is preferred since it means callers
reviewing the documentation don't have to follow another level of
indirection to figure out the signature.
2016-11-04 13:14:39 -05:00
Javed Khan a041b4349b server: Use Disconnect in handleDonePeerMsg 2016-11-04 00:36:13 -05:00
Javed Khan b320129e9b server: Check max peers before connecting 2016-11-04 00:36:13 -05:00
Javed Khan aca9fc040c connmgr: Rename max outbound to target outbound 2016-11-04 00:36:13 -05:00
David Hill 2510baac35 btcd: support feefilter requests.
This only adds support for handling remote peer requests.
2016-11-03 14:47:30 -04:00
Dave Collins 915fa6639b
multi: Simplify code per gosimple linter.
This simplifies the code based on the recommendations of the gosimple
lint tool.
2016-11-03 13:00:35 -05:00