Skip to content

Conversation

@knst
Copy link
Collaborator

@knst knst commented Jan 24, 2024

Issue being fixed or feature implemented

Just regular bitcoin backports, mostly from v21

What was done?

Note for reviewers:

How Has This Been Tested?

Run unit/functional tests

Breaking Changes

N/A

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone

@knst knst added this to the 20.1 milestone Jan 24, 2024
@knst knst requested a review from UdjinM6 January 25, 2024 21:40
@knst knst marked this pull request as draft January 26, 2024 09:56
@knst knst marked this pull request as ready for review January 26, 2024 11:41
Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK for merging via merge commit

laanwj and others added 10 commits January 27, 2024 22:55
…processing

fb56d37 p2p: ensure inv is GenMsgTx before ToGenTxid in inv processing (John Newbery)
aa36213 test: use CInv::MSG_WITNESS_TX flag in p2p_segwit (Jon Atack)
24ee4f0 p2p: make gtxid(.hash) and fAlreadyHave localvars const (Jon Atack)
b1c8554 p2p: use CInv block message helpers in net_processing.cpp (Jon Atack)
acd6642 [net processing] Change AlreadyHaveTx() to take a GenTxid (John Newbery)
5fdfb80 [net processing] Change AlreadyHaveBlock() to take block_hash argument (John Newbery)
430e183 [net processing] Remove mempool argument from AlreadyHaveBlock() (John Newbery)
42ca561 [net processing] Split AlreadyHave() into separate block and tx functions (John Newbery)
39f1dc9 p2p: remove nFetchFlags from NetMsgType TX and INV processing (Jon Atack)
471714e p2p: add CInv block message helper methods (Jon Atack)

Pull request description:

  Building on bitcoin#19590 and the recent `wtxid` and `GenTxid` changes, this is a refactoring and cleanup PR to simplify and improve some of the net processing code.

  Some of the diffs are best reviewed with `-w` to ignore spacing.

  Co-authored by John Newbery.

ACKs for top commit:
  laanwj:
    Code review ACK fb56d37
  jnewbery:
    utACK fb56d37
  vasild:
    ACK fb56d37

Tree-SHA512: ba39b58e6aaf850880a842fe5f6295e9f1870906ef690206acfc17140aae2ac854981e1066dbcd4238062478762fbd040ef772fdc2c50eea6869997c583e6a6d
a8a64ac [BroadcastTransaction] Remove unsafe move operator (Amiti Uttarwar)
125c038 [p2p] Remove dead code (Amiti Uttarwar)
fc66d0a [p2p] Check for nullptr before dereferencing pointer (Adam Jonas)
cb79b9d [mempool] Revert unbroadcast set to tracking just txid (Amiti Uttarwar)

Pull request description:

  Addresses some outstanding review comments from bitcoin#18044

  - reverts unbroadcast txids to a set instead of a map (simpler, communicates intent better, takes less space, no efficiency advantages of map)
  - adds safety around two touchpoints (check for nullptr before dereferencing pointer, remove an inaccurate std::move operator)
  - removes some dead code

  Links to comments on wtxid PR: [1](bitcoin#18044 (comment)) [2](bitcoin#18044 (comment)) [3](bitcoin#18044 (comment))

  thanks to jnewbery & adamjonas for flagging these ! !

ACKs for top commit:
  sdaftuar:
    utACK a8a64ac
  naumenkogs:
    utACK a8a64ac
  jnewbery:
    utACK a8a64ac

Tree-SHA512: 7be669cb30cc17fb9e06b50e636ef7887c6a27354697987e4e4d38dba4b8f50e175647587430cd9bc3295bec01ce8b1e6639a50a4249d8fff9b1ca1b9ead3277
ddefb5c p2p: Use the greatest common version in peer logic (Hennadii Stepanov)
e084d45 p2p: Remove SetCommonVersion() from VERACK handler (Hennadii Stepanov)
8d20267 refactor: Rename local variable nSendVersion (Hennadii Stepanov)
e9a6d8b p2p: Unify Send and Receive protocol versions (Hennadii Stepanov)

Pull request description:

  On master (6fef85b) `CNode` has two members to keep protocol version:
  - `nRecvVersion` for received messages
  - `nSendVersion` for messages to send

  After exchanging with `VERSION` and `VERACK` messages via protocol version `INIT_PROTO_VERSION`, both nodes set `nRecvVersion` _and_ `nSendVersion` to _the same_ value which is the greatest common protocol version.

  This PR:
  - replaces two `CNode` members, `nRecvVersion` `nSendVersion`, with `m_greatest_common_version`
  - removes duplicated getter and setter

  There is no change in behavior on the P2P network.

ACKs for top commit:
  jnewbery:
    ACK ddefb5c
  naumenkogs:
    ACK ddefb5c
  fjahr:
    Code review ACK ddefb5c
  amitiuttarwar:
    code review but untested ACK ddefb5c
  benthecarman:
    utACK `ddefb5c`

Tree-SHA512: 5305538dbaa5426b923b0afd20bdef4f248d310855d1d78427210c00716c67b7cb691515c421716b6157913e453076e293b10ff5fd2cd26a8e5375d42da7809d
…and remove confusing Test_Node.p2p property

10d6150 [test] remove confusing p2p property (gzhao408)
549d30f scripted-diff: replace p2p with p2ps[0] in p2p_invalid_tx (gzhao408)
7a0de46 [doc] sample code for test framework p2p objects (gzhao408)
784f757 [refactor] clarify tests by referencing p2p objects directly (gzhao408)

Pull request description:

  The `TestNode` has a `p2p` property which is an alias for `p2ps[0]`.

  I think this should be removed because it can be confusing and misleading (to both the test writer and reviewer), especially if a TestNode has multiple p2ps connected (which is the case for many tests).
  Another example is when a test has multiple subtests that connect 1 p2p and use the `p2p` property to reference it. If the subtests don't completely clean up after themselves, the subtests may affect one another.

  The best way to refer to a connected p2p is use the object returned by `add_p2p_connection` like this:
  ```py
  p2p_conn = node.add_p2p_connection(P2PInterface())
  ```
  A good example is [p2p_invalid_locator.py](https://github.com/bitcoin/bitcoin/blob/master/test/functional/p2p_invalid_locator.py), which cleans up after itself (waits in both `wait_for_disconnect` and in `disconnect_p2ps`) but wouldn't need so much complexity if it just referenced the connections directly.

  If there is only one connected, it's not really that tedious to just use `node.p2ps[0]` instead of `node.p2p` (and it can always be aliased inside the test itself).

ACKs for top commit:
  robot-dreams:
    utACK 10d6150
  jnewbery:
    utACK 10d6150
  guggero:
    Concept ACK 10d6150.

Tree-SHA512: 5965548929794ec660dae03467640cb2156d7d826cefd26d3a126472cbc2494b855c1d26bbb7b412281fbdc92b9798b9765a85c27bc1a97f7798f27f64db6f13
0fcaf73 test: use explicit p2p objects where available (Oliver Gugger)

Pull request description:

  This is a follow-up patch to bitcoin#19804 as suggested by MarcoFalke (bitcoin#19804 (comment)).

  To make the intent of the tests easier to understand, we reference the
  p2p connection objects by their explicit names instead of the p2ps array.

ACKs for top commit:
  theStack:
    ACK 0fcaf73

Tree-SHA512: 37db22185077beeadfa7245bb768b87d6b7a2cfb906c3c859ab92ec3d657122db7301777f0838e13dfc748f37303850144fb7553e6cb6c66903e304d6e10e659
b6834e3 Avoid 'timing mishap' warnings when mocking (Pieter Wuille)
ec3916f Use mockable time everywhere in net_processing (Pieter Wuille)

Pull request description:

  The fact that net_processing uses a mix of mockable tand non-mockable time functions made it hard to write functional tests for bitcoin#19988.

  I'm opening this as a separate PR as I believe it's independently useful. In some ways this doesn't go quite as far as it could, as there are now several data structures that could be converted to `std::chrono` types as well now. I haven't done that here, but I'm happy to reconsider that.

ACKs for top commit:
  MarcoFalke:
    ACK b6834e3 🌶
  jnewbery:
    utACK b6834e3
  naumenkogs:
    utACK b6834e3

Tree-SHA512: 6528a167c57926ca12894e0c476826411baf5de2f7b01c2125b97e5f710e620f427bbb13f72bdfc3de59072e56a9c1447bce832f41c725e00e81fea019518f0e
faad92f test: Remove unused nVersion=1 in p2p tests (MarcoFalke)

Pull request description:

  After commit ddefb5c nVersion is no
  longer used in p2p logic when sending messages. Only when receiving
  messages, but in this test no messages are received.

ACKs for top commit:
  laanwj:
    Code review ACK faad92f
  fanquake:
    ACK faad92f

Tree-SHA512: 9a7029187aaa5a7929a4a2199646131ff1ea72df6a855ce7022dd3bb2647dd525356dbc5e460c77007eebcdeab400a689db8cb77e8239af3b539c117a4e0d16e
…onnections during restart

a490d07 doc: Add anchors.dat to files.md (Hennadii Stepanov)
0a85e5a p2p: Try to connect to anchors once (Hennadii Stepanov)
5543c7a p2p: Fix off-by-one error in fetching address loop (Hennadii Stepanov)
4170b46 p2p: Integrate DumpAnchors() and ReadAnchors() into CConnman (Hennadii Stepanov)
bad16af p2p: Add CConnman::GetCurrentBlockRelayOnlyConns() (Hennadii Stepanov)
c29272a p2p: Add ReadAnchors() (Hennadii Stepanov)
567008d p2p: Add DumpAnchors() (Hennadii Stepanov)

Pull request description:

  This is an implementation of bitcoin#17326:
  - all (currently 2) outbound block-relay-only connections (bitcoin#15759) are dumped to `anchors.dat` file
  - on restart a node tries to connect to the addresses from `anchors.dat`

  This PR prevents a type of eclipse attack when an attacker exploits a victim node restart to force it to connect to new, probably adversarial, peers.

ACKs for top commit:
  jnewbery:
    code review ACK a490d07
  laanwj:
    Code review ACK a490d07

Tree-SHA512: 0f5098a3882f2814be1aa21de308cd09e6654f4e7054b79f3cfeaf26bc02b814ca271497ed00018d199ee596a8cb9b126acee8b666a29e225b08eb2a49b02ddd
…on type field

41dca08 [trivial] Extract connection type doc into file where it is used. (Amiti Uttarwar)
3069b56 [doc] Improve help for getpeerinfo connection_type field. (Amiti Uttarwar)

Pull request description:

  two commits addressing small followups from bitcoin#19725

  * first commit adds a clarification in the release notes that this field shouldn't be expected to be stable (suggested by sdaftuar in bitcoin#19725 (comment))

  * second commit moves the `CONNECTION_TYPE_DOC` object out of the header file to reduce the size of the binary (suggested by MarcoFalke in bitcoin#19725 (comment), he tested and found a decrease of 10kB)

ACKs for top commit:
  achow101:
    ACK 41dca08
  laanwj:
    Code review ACK 41dca08

Tree-SHA512: a555df978b4341fbe05deeb40a8a655f0d3c5c1c0adcc1737fd2cf61b204a5a24a301ca0c2b5a3616554d4abf8c57074d22dbda5a50d8450bc22c57679424985
f32c408 Make sure unconfirmed parents are requestable (Pieter Wuille)
c4626bc Drop setInventoryTxToSend based filtering (Pieter Wuille)
43f02cc Only respond to requests for recently announced transactions (Pieter Wuille)
b24a17f Introduce constant for mempool-based relay separate from mapRelay caching (Pieter Wuille)
a9bc563 Swap relay pool and mempool lookup (Pieter Wuille)

Pull request description:

  This implements the follow-up suggested here: bitcoin#18861 (comment) . Instead of checking `setInventoryTxToSend`, maintain an explicit bloom filter with the 3500 most recently announced invs, and permit fetching any of these as long as they're in the relay pool or the mempool. In addition, permit relay from the mempool after just 2 minutes instead of 15.

  This:

  * Fixes the brief opportunity an attacker has to request unannounced invs just after the connection is established (pointed out by naumenkogs, see bitcoin#18861 (comment)).
  * Guarantees that locally resubmitted invs after `filterInventoryKnown` rolls over can still be requested (pointed out by luke-jr, see bitcoin#18861 (comment)).

  It adds 37 KiB of filter per peer.

  This is also a step towards dropping the relay pool entirely and always relaying from the mempool directly (see bitcoin#17303), but that is still blocked by dealing properly with NOTFOUNDs (see bitcoin#18238).

ACKs for top commit:
  jnewbery:
    reACK f32c408
  jonatack:
    re-ACK f32c408 per `git range-diff f7c19e8 2da7ee3 f32c408` and redid the following: code review, thought about motivation, DoS and privacy aspects, debug build to check for warnings after updating Clang from 6 to 11 since last review.
  ajtowns:
    re-ACK f32c408

Tree-SHA512: aa05b9fd01bad59581c4ec91836a52d7415dc933fa49d4c4adced79aa25aaad51e11166357e8c8b29fbf6021a7401b98c21b850b5d8e8ad773fdb5d6608e1e85
@PastaPastaPasta PastaPastaPasta merged commit f0b42ca into dashpay:develop Jan 28, 2024
{RPCResult::Type::BOOL, "inbound", "Inbound (true) or Outbound (false)"},
{RPCResult::Type::BOOL, "addnode", "Whether connection was due to addnode/-connect or if it was an automatic/inbound connection"},
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + "."},
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another case where the help output order doesn't align with the actual RPC response. In the actual output, this field comes last: https://github.com/dashpay/dash/blob/develop/src/rpc/net.cpp#L256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants