Skip to content

Conversation

amitiuttarwar
Copy link
Contributor

@amitiuttarwar amitiuttarwar commented Sep 4, 2020

Addresses some outstanding review comments from #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 2 3

thanks to jnewbery & adamjonas for flagging these ! !

amitiuttarwar and others added 4 commits September 4, 2020 14:29
When I originally implemented the unbroadcast set in 18038, it just tracked
txids. After 18038 was merged, I offered a patch to 18044 to make the
unbroadcast changes compatible with wtxid relay. In this patch, I updated
`unbroadcast_txids` to a map of txid -> wtxid. Post merge review comments shed
light on the fact that this update was unnecessary, and distracting. So, this
commit updates the unbroadcast ids back to a set.
The else clause is dead code because the only way to not enter the if branch is
if TX_WITNESS_STRIPPED is true. In that case, it would not have a witness to
match the `tx.HasWitness()` else condition.

Co-authored-by: Adam Jonas <jonas@chaincode.com>
Co-authored-by: John Newbery <john@johnnewbery.com>
Previously, `tx` was being read after having `std::move` called on it. The
std::move operator indicates to the compiler that this object may be "moved
from", so we shouldn't subsequently read from it. The current code is not
problematic since tx is passed in as a const ref. But this `std::move` is at
best misleading & at worst problematic, so remove it.
@fanquake fanquake added the P2P label Sep 4, 2020
Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

utACK a8a64ac

Thanks for tidying up these loose ends! If you retouch, I suggest you update the commit log for the [mempool] Revert unbroadcast set to tracking just txid commit to include the hash of the commit that this is reverting (c7eb6b4).

@naumenkogs
Copy link
Member

utACK a8a64ac

@fanquake fanquake requested a review from sdaftuar September 15, 2020 02:18
@sdaftuar
Copy link
Member

utACK a8a64ac

@fanquake fanquake merged commit 1c4f597 into bitcoin:master Sep 15, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 16, 2020
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 16, 2021
Summary:
Previously, `tx` was being read after having `std::move` called on it. The
std::move operator indicates to the compiler that this object may be "moved
from", so we shouldn't subsequently read from it. The current code is not
problematic since tx is passed in as a const ref. But this `std::move` is at
best misleading & at worst problematic, so remove it.

This is a backport of [[bitcoin/bitcoin#19879 | core#19879]]
bitcoin/bitcoin@a8a64ac

The other commits of that pull request are not relevant, as they deal with segwit issues.
This missing backport was noticed in the review of D10464, which adds a use of `tx` after move.

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10474
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants