Commit graph

330 commits

Author SHA1 Message Date
Bruno Garcia
bc52e090ce p2p: remove alert msg 2025-07-10 13:07:50 -03:00
yyforyongyu
1827fcf2f5
main: fix typo 2025-06-25 16:55:33 +08:00
yyforyongyu
9dc2503295
main: refactor OnGetData to simplify the logic
The preivous usage of two channels - by piping them together to create a
semaphore effect, is difficult to follow and prone to bugs. This commit
now refactors the method to explicitly implement a semaphore.

Prior to this change, we would allow at max 3 concurrent goroutines -
this is now bumped to 5.
2025-06-25 16:55:33 +08:00
yyforyongyu
796d0efc0d
main: add method pushInventory to be used in OnGetData
A minor refactor on method `OnGetData`.
2025-06-23 21:31:26 +08:00
yyforyongyu
3913a72e2e
main+wire: fix line too long
This commit provides a minor fix on the format.
2025-06-23 20:03:33 +08:00
Olaoluwa Osuntokun
5ab25f3f2b config: add new --v2transport option to gate BIP 324 2025-05-26 13:46:25 -07:00
Olaoluwa Osuntokun
ef0e43ba06 multi: refactor v2 -> v1 downgrade logic
In this commit, we refactor the v2 -> v1 downgrade logic to: simplify
the code in the server for reconnection, use a functional option to
avoid breaking the connmgr API, and we also encapsulate the downgrade
state in a new struct so it can be re-used elsewhere.
2025-05-26 13:46:25 -07:00
Eugene Siegel
2d2bf57a69 server.go+connmgr: changes to trigger a reconnect in connmgr
This changes the Disconnect function to accept a `reconnect` argument.
Also change handleDisconnected to have reconnection logic.
2025-05-26 13:46:25 -07:00
Eugene Siegel
675d3007cf peer+server.go: pendingReconnects map to reconnect to downgraded v2->v1 peers
When ShouldDowngradeToV1() returns true, we'll:
- mark in pendingReconnects that we should attempt v1 bitcoin p2p transport
  when the connmgr successfully re-establishes the outbound TCP connection.
- set a bit on the associated *serverPeer that will cause us to tell the
  connmgr to reconnect. This is needed because not all outbound peers are
  permanent and we might otherwise not reconnect to them if the initial v2
  transport negotiation failed.
2025-05-26 13:46:25 -07:00
Eugene Siegel
b5f0ebb132 v2transport+server+peer: add v2->v1 downgrade error if EOF during handshake 2025-05-26 13:46:25 -07:00
Eugene Siegel
824e163e1e server.go+peer: enable v2 functionality in peer code
This adds the v2 software flag to the list of services btcd supports
and adds functionality to optionally use v2 transport if the peer
supports it.
2025-05-26 13:46:25 -07:00
cec489
d881c686e6
Fix the btcctl uptime command
commit 0b2998b7f279d3aef4d83415dae26948f5a6bdf4
Author: cec489 <173723251+cec489@users.noreply.github.com>
Date:   Mon Jun 24 20:01:13 2024 +0000

    A cleaner fix is to set the startTime in the server Start() function
    which is where the server is actually started.

commit ae6c1256981befb43972e83a086ea663df629873
Author: cec489 <173723251+cec489@users.noreply.github.com>
Date:   Mon Jun 24 19:15:23 2024 +0000

    Fix the btcctl uptime command by moving the setting of startupTime
2024-06-27 13:36:29 -04:00
Calvin Kim
d65999e4a1 main: add logging if the node is pruned
For debug purposes down the road, log that the node is pruned if it's
set to pruned.
2024-05-01 18:02:05 +09:00
Thabokani
a4df044cfd
Fix some typos (#2085)
* Dockerfile: fix typo

* blockchain: fix typos

* sample-btcd.conf: fix typos

* server: fix typos

* txscript: fix typos
2024-01-03 16:36:49 -05:00
Calvin Kim
16cd44f0e6 blockchain, netsync, main, cmd/addblock: Use utxocache
This change is part of the effort to add utxocache support to btcd.

utxo cache is now used by the BlockChain struct.  By default it's used
and the minimum cache is set to 250MiB.  The change made helps speed up
block/tx validation as the cache allows for much faster lookup of utxos.
The initial block download in particular is improved as the db i/o
bottleneck is remedied by the cache.
2023-12-16 16:53:17 +09:00
Calvin Kim
02469e16a6 main: Add prune flag
This change is part of the effort to add pruning support to btcd.

Pruning is now available to the end user via --prune flag.  There are
checks in place so that the user doesn't go below the minimum prune
target of 1536 MiB.  The minimum is set so that we keep at least 288
blocks per the requirement for NODE_NETWORK_LIMITED nodes specified by
BIP0159.  The default value of 0 will disable pruning.
2023-08-23 00:46:26 +09:00
Calvin Kim
0212c334ce wire, main: Add SFNodeNetworkLimited flag
This change is part of the effort to add pruning support to btcd.

Wire now supports the ability to signal NODE_NETWORK_LIMITED which
signals to peers that the node is able to serve the last 288 blocks.

Since archival nodes have all blocks, they can also signal for
NODE_NETWORK_LIMITED.  SFNodeNetworkLimited flag is added to the default
services.
2023-08-22 15:48:55 +09:00
David Vennik
e563459b72 Fixed ban bug that doesn't print numTxns
(cherry picked from commit 11c8d11a26d14a64fe6e412313624b6bfc5b4e2c)
2022-10-10 10:34:58 -04:00
eugene
cb6f21b598
peer+wire: add addrv2 message, protocol negotiation 2022-02-24 13:11:15 -05:00
eugene
201c0836ec
multi: update addrmgr, server to use NetAddressV2 instead of legacy 2022-02-24 13:11:15 -05:00
Olaoluwa Osuntokun
caac0f821a
multi: update btcutil imports to point to new sub-module
In this commit, we update all the btcutil imports to point to the new
sub-module.

In the same commit, we also modify the recently added `btcutil/go.mod`
file as we need to continue pointing to the _old_ version of btcd, until
we merge this PR and push a new tag.
2022-01-10 18:44:58 -08:00
Olaoluwa Osuntokun
e98a1a1b4c
peer+server: add new config option to optionally disable stall detection
In this commit, we add a new config options that allows one to start
`btcd` in an operating mode that disables the stall detection. This can
be useful in simnet/regtest integration tests settings where it's
important that `btcd` holds on to its possibly sole connection to the
only other node in the test harness.

A new config flag has been added to gate this behavior, which is off by
default.
2021-10-01 14:55:50 -07:00
yyforyongyu
61634447e7
btcd+netsync: support witness tx and block in notfound msg 2020-09-03 18:53:16 +08:00
Javed Khan
24db7d7c0c netsync: handle notfound messages from peers
backport from https://github.com/decred/dcrd/pull/2253

When a peer sends a notfound message, remove the hash from requested
map.  Also increase notfound ban score and return early if it
disconnects the peer.
2020-07-28 09:23:35 -04:00
David Hill
f7399e6157 build: clean linter warnings 2020-05-13 08:58:39 -04:00
Steven Roose
9e94ccbd0e server: Fix incorrect log message format 2020-03-05 17:00:45 -05:00
Olaoluwa Osuntokun
037489ef50
Merge pull request #1485 from wpaulino/syncmanager-done-peer-verack
server: remove peer from SyncManager on VerAckReceived
2019-11-08 18:21:37 -08:00
nsa
c2ca0a408e
server: add addressesMtx to fix race condition 2019-11-08 21:11:24 -05:00
Wilmer Paulino
bc21593480
server: remove peer from SyncManager on VerAckReceived
Peers are now added to the SyncManager if we receive their verack, but
we'd still attempt to remove them from the SyncManager if we didn't
receive it.
2019-10-29 19:38:38 -07:00
Wilmer Paulino
baeb789a7d
server: prevent adding peers if already disconnected
This addresses an issue where the server ends up tracking a peer that
has been disconnected due to it processing a peer's `done` message
before its `add` message.
2019-10-14 13:26:44 +02:00
Wilmer Paulino
769c4e152f
server: request addresses from new peers once they can process messages
This was previously done within the OnVersion listener, which should not
be a blocking operation. It turns out that requesting these messages
there can lead to blocking due to peers not being able to process
messages since their message queues have yet to start. Therefore, we'll
now request within handleAddPeerMsg, which should allow it to go
through.
2019-10-14 13:26:43 +02:00
Wilmer Paulino
a1a5bfa819
server: add new peers within OnVerAck instead of within OnVersion
This change is needed as part of requiring peers to also send a verack
message following their version message during protocol negotiation.
Peers were previously added to the SyncManager before their message
queues were started, causing the server to stall if a peer didn't
provide a timely verack response following their version. We now do this
within OnVerAck, which happens shortly before peer message queues are
started.
2019-10-14 13:26:42 +02:00
Wilmer Paulino
11b84f5cb5
server: signal SyncManager with new peer within AddPeer
This makes the logic a bit more unified as previously it was possible we
for us to report the new peer to the SyncManager, but for whatever
reason failed to track the peer in the server internally within AddPeer.
This change ensures this can no longer happen.
2019-10-14 13:26:16 +02:00
Wilmer Paulino
0d00cdf82c
server: request new peer after disconnection of non-persistent peers
Doing so ensures we reach our target number of outbound peers as soon as
possible. This is only necessary after calls to connmgr.Remove, as these
won't request a new peer connection.
2019-10-10 19:05:41 -04:00
Wilmer Paulino
45d66d46f9
server: standardize use of connmanager's Disconnect and Remove methods
The Disconnect method would still attempt to reconnect to the same
peer, which could cause us to reconnect to bad/unstable peers if we came
across them. Instead, we'll now use Remove whenever we intend to remove
a peer that is not persistent.
2019-10-10 19:05:37 -04:00
Wilmer Paulino
ab6f3089f6
server: mark address as connected within handleAddPeerMsg
We do this to ensure the address manager contains live addresses.
Previously, addresses with which we established connections with would
not be marked as connected because it would be done once we disconnect
peers. Given that we don't process all of the disconnect logic when
we're shutting down, addresses of stable and good peers would never be
marked as connected unless the connection was lost during operation.
2019-10-10 12:10:52 -04:00
Wilmer Paulino
06baabe5da
server: mark address attempted on attempt rather than upon connection
We should mark addresses as attempted when we attempt to connect to
them, not once we establish a connection with said address.
2019-10-10 12:03:47 -04:00
Wilmer Paulino
95d0a371d9
mempool: implement RBF signaling policy 2019-06-13 16:35:53 -07:00
Conner Fromknecht
39592eba78
btcd: pass user agent black and white lists to server 2019-04-16 21:31:08 -07:00
Conner Fromknecht
d3ecdc91a9
server: adds hybrid black/whitelist filtering to user agents 2019-04-15 17:46:08 -07:00
Dave Collins
8c981e4ef2
server: Use local addr var in version handler.
This modifies the OnVersion handler for server peers to use a local
variable for the remote address of the peer in order to avoid grabbing
the mutex multiple times.

There are no functional changes.

Backported from Decred.
2018-09-20 22:32:59 -05:00
Dave Collins
c8b9fab820
server: Only advertise local addr when current.
This changes the server peers OnVersion handler to only advertise the
server as a viable target for inbound connections when the server
believes it is close the best known tip.

Backported from Decred.
2018-09-20 22:32:41 -05:00
Dave Collins
d2c7892aa4
server: Use local inbound var in version handler.
This modifies the OnVersion handler for server peers to use a local
variable for the inbound status of the peer in order to avoid grabbing
the mutex multiple times.

While here, it also does some light cleanup.  There are no functional
changes.

Backported from Decred.
2018-09-20 22:32:16 -05:00
Dave Collins
4b20d4f86a
server: Update addrmgr services on outbound conns.
This adds code to update the address manager services for a known
address to the services advertised by peers when they are connected to
via an outbound connection.  It is only done for outbound connections to
help prevent malicious behavior from inbound connections.

Backported from Decred.
2018-09-20 22:31:50 -05:00
Dave Collins
9151ebc90b
server: Reject outbound conns to non-full nodes.
This modifies the server connection code to reject outbound peers that
do not offer full node services.
2018-09-20 22:30:46 -05:00
Dave Collins
7b103e2434
peer: Allow OnVersion callback to reject peer.
This modifies the OnVersion callback to allow a reject message to be
returned in which case the message will be sent to the peer and the peer
will be disconnected.

Backported from Decred.
2018-09-20 22:29:27 -05:00
Dave Collins
118f55233b
peer: Rework version negotiation.
This modifies the negotiation logic to ensure the callback has the
opportunity to see the message before the peer is disconnected and
improves the error handling when reading the remote version message.

It also has the side effect of ensuring the protocol version is
negotiated before sending reject messages with the exception of the
first message not being a version message since negotiation is not
possible in that case.

This is being changed because it is useful for the server to see the
message regardless in order to have the opportunity to things such as
update the address manager and reject peers that don't have desired
services.

Backported from Decred.
2018-09-20 22:26:36 -05:00
qshuai
badf5453e9 server: Fix struct name mismatch 2018-09-08 22:34:41 +08:00
Olaoluwa Osuntokun
222a6dac0d
server: fix panic bug when looking for cf checkpoint cache intersection w/ chain
In this commit, we fix a panic bug that can arise when we attempt to
process a cf checkpoint message from a remote peer. Before this commit,
if the size of the checkpoint cache was large than the number of
checkpoints requested by the peer, we would panic with an out of bounds
error. In order to prevent, this we'll now use the size of the requested
set of hashes as our bound to ensure that we don't panic.
2018-08-27 17:49:45 -07:00
Olaoluwa Osuntokun
c8e6363e22
server: modify locking in OnGetCFCheckpt to allow for read concurrency
In this commit, we modify the locking scheme when serving cf checkpoints
for peers to allow the server to serve multiple peers at the same time.
Before this commit, we would first grab the write lock, check to see for
expansion, then release the read lock. In this commit we reverse this
and instead will grab the read lock, and upgrade to the write lock if we
need to actually expand the size of the cache.
2018-08-27 17:46:41 -07:00