Skip to content

Conversation

stickies-v
Copy link
Contributor

This PR addresses the outstanding comments/issues from #25768:

  • capitalization typo in docstring
  • remove unused locks that we previously needed for ReacceptWalletTransactions()
  • before wallet: Properly rebroadcast unconfirmed transaction chains #25768, only ResendWalletTransactions() would reset m_next_resend (formerly called nNextResend). By unifying it with ReacceptWalletTransactions() into ResubmitWalletTransactions(), the number of callsites that would reset the m_next_resend timer increased
    • since m_next_resend is only used in case of relay=true (formerly ResendWalletTransactions()), this is unintuitive
    • it leads to unexpected behaviour such as transactions potentially never being rebroadcasted.
    • it makes the ResubmitWalletTransactions()` logic more complicated than strictly necessary
    • since wallet: Properly rebroadcast unconfirmed transaction chains #25768, we relied on an earlier call of ResubmitWalletTransactions(relay=false, force=true) to initialize m_next_resend(), I think we can more elegantly do that by just providing m_next_resend with a default value
    • just to highlight: this commit introduces behaviour change

Note: the if (!fBroadcastTransactions) in CWallet:ShouldResend() is duplicated on purpose, since it potentially avoids the slightly more expensive if (!chain().isReadyToBroadcast()) check afterwards. I don't have a strong view on it, so happy to remove that additional check to reduce the diff, too.

ReacceptWalletTransactions is replaced by ResubmitWalletTransactions
which already handles acquiring the necessary locks internally.
@maflcko maflcko added this to the 24.0 milestone Sep 29, 2022
@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 30, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26238 (clang-tidy: fixup named argument comments by fanquake)
  • #25907 (wallet: rpc to add automatically generated descriptors by achow101)
  • #23544 (rpc, wallet: addhdseed, infer seed when importing descriptor with xpub by Sjors)
  • #23417 (wallet, spkm: Move key management from DescriptorScriptPubKeyMan to wallet level KeyManager by achow101)
  • #22341 (rpc: add getxpub by Sjors)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor Author

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

Force pushed to address MarcoFalke's review comments - thank you!

  • Split out "wallet: move resend timer logic out of ResubmitWalletTransactions" into two commits: one refactoring commit (that introduces ShouldResend() but has no behaviour change) and one bugfix commit that only updates m_next_resend when we're actually resending the transactions
  • Fixed int truncation bug
  • No need for m_next_resend to be std::atomic anymore, since it's now only called from a single thread (MaybeResendWalletTxs())
  • Made SetNextResend() argument-less since we're never actually passing the optional argument, can easily add back later.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

lgtm. I wouldn't call the last commit a "performance" improvement. Just a code clarity change.

@stickies-v
Copy link
Contributor Author

stickies-v commented Sep 30, 2022

Force pushed to remove "performance improvement" from the std::atomic revert commit message, and moved GetDefaultNextResend() implementation to wallet.cpp to reduce header includes in the header - thanks for both MarcoFalke.

Copy link
Contributor

@aureleoules aureleoules left a comment

Choose a reason for hiding this comment

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

01f3534: I verified that ResubmitWalletTransactions already locks the mutex so no need to lock it in the parent functions.

Left a comment, the rest looks good.

Moves the logic of whether or not transactions should actually be
resent out of the function that's resending them. This reduces
responsibilities of ResubmitWalletTransactions and allows
carving out the updating of m_next_resend in a future commit.
We only want to relay our resubmitted transactions once every 12-36h.
By separating the timer update logic out of ResubmitWalletTransactions
and into MaybeResendWalletTxs we avoid non-relay calls (previously in
the separate ReacceptWalletTransactions function) from resetting that
timer.
Since m_next_resend is now only called from MaybeResendWalletTxs()
we don't have any potential race conditions anymore, so the usage
of std::atomic can be reverted.
@stickies-v
Copy link
Contributor Author

Force pushed to make CWallet::ShouldResend() const - ty aureleoules!

@aureleoules
Copy link
Contributor

ACK b01682a

@luke-jr
Copy link
Member

luke-jr commented Oct 5, 2022

I verified that ResubmitWalletTransactions already locks the mutex so no need to lock it in the parent functions.

That's not necessarily a given. The parents may need to lock things for atomicity (with other changes/calls), or lock ordering consistency. (I didn't look at this particular case, just noting the general logic does not hold)

@luke-jr
Copy link
Member

luke-jr commented Oct 5, 2022

it leads to #25768 (comment) such as transactions potentially never being rebroadcasted.

I think this bugfix should be split out and backported. Ideally doing something more minimal which can be refactored here.

@achow101
Copy link
Member

ACK b01682a

@fanquake fanquake merged commit aa6fb37 into bitcoin:master Oct 13, 2022
@fanquake
Copy link
Member

Added to #26133 for backport.

fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Oct 13, 2022
ReacceptWalletTransactions is replaced by ResubmitWalletTransactions
which already handles acquiring the necessary locks internally.

Github-Pull: bitcoin#26205
Rebased-From: 01f3534
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Oct 13, 2022
Moves the logic of whether or not transactions should actually be
resent out of the function that's resending them. This reduces
responsibilities of ResubmitWalletTransactions and allows
carving out the updating of m_next_resend in a future commit.

Github-Pull: bitcoin#26205
Rebased-From: 7fbde8a
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Oct 13, 2022
We only want to relay our resubmitted transactions once every 12-36h.
By separating the timer update logic out of ResubmitWalletTransactions
and into MaybeResendWalletTxs we avoid non-relay calls (previously in
the separate ReacceptWalletTransactions function) from resetting that
timer.

Github-Pull: bitcoin#26205
Rebased-From: 9245f45
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Oct 13, 2022
Since m_next_resend is now only called from MaybeResendWalletTxs()
we don't have any potential race conditions anymore, so the usage
of std::atomic can be reverted.

Github-Pull: bitcoin#26205
Rebased-From: b01682a
achow101 added a commit that referenced this pull request Oct 13, 2022
e2e4c29 tests: Test that PSBT_OUT_TAP_TREE is included correctly (Andrew Chow)
4d42c3a psbt: Only include m_tap_tree if it has scripts (Andrew Chow)
d810fde psbt: Change m_tap_tree to store just the tuples (Andrew Chow)
a9419ef tests: Test that PSBT_OUT_TAP_TREE is combined correctly (Andrew Chow)
4abd2ab psbt: Fix merging of m_tap_tree (Andrew Chow)
1390c96 [BugFix]: Do not allow deserializing PSBT with empty PSBT_OUT_TAP_TREE (Jeremy Rubin)
9b438f0 refactor: revert m_next_resend to not be std::atomic (stickies-v)
43ced0b wallet: only update m_next_resend when actually resending (stickies-v)
fc8f2bf refactor: carve out tx resend timer logic into ShouldResend (stickies-v)
a6fb674 refactor: remove unused locks for ResubmitWalletTransactions (stickies-v)
5ad82a0 index: Improve BaseIndex::BlockUntilSyncedToCurrentChain reliability (Ryan Ofsky)
997faf6 contrib: Fix capture_output in getcoins.py (willcl-ark)
7e0bcfb p2p: ProcessHeadersMessage(): fix received_new_header (Larry Ruane)
c97d924 Correct sanity-checking script_size calculation (Pieter Wuille)
da6fba6 docs: Add 371 to bips.md (Andrew Chow)

Pull request description:

  Will collect backports for rc2 as they become available. Currently:
  * #25858
  * #26124
  * #26149
  * #26172
  * #26205
  * #26212
  * #26215

ACKs for top commit:
  dergoegge:
    ACK e2e4c29
  achow101:
    ACK e2e4c29
  instagibbs:
    ACK e2e4c29

Tree-SHA512: b6374fe202561057dbe1430d4c40f06f721eb568f91e7275ae1ee7747edf780ce64620382d13ecc4b9571d931dc25d226af8284987cf35ff6a6182c5f64eb10c
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 23, 2022
b01682a refactor: revert m_next_resend to not be std::atomic (stickies-v)
9245f45 wallet: only update m_next_resend when actually resending (stickies-v)
7fbde8a refactor: carve out tx resend timer logic into ShouldResend (stickies-v)
01f3534 refactor: remove unused locks for ResubmitWalletTransactions (stickies-v)
c6e8e11 wallet: fix capitalization in docstring (stickies-v)

Pull request description:

  This PR addresses the outstanding comments/issues from bitcoin#25768:

  - capitalization [typo](bitcoin#25768 (comment)) in docstring
  - remove [unused locks](bitcoin@01f3534) that we previously needed for `ReacceptWalletTransactions()`
  - before bitcoin#25768, only `ResendWalletTransactions()` would reset `m_next_resend` (formerly called `nNextResend`). By unifying it with `ReacceptWalletTransactions()` into `ResubmitWalletTransactions()`, the number of callsites that would reset the `m_next_resend` timer increased
    - since `m_next_resend` is only used in case of `relay=true` (formerly `ResendWalletTransactions()`), this is unintuitive
    - it leads to [unexpected behaviour](bitcoin#25768 (comment)) such as transactions potentially never being rebroadcasted.
    - it makes the ResubmitWalletTransactions()` logic [more complicated than strictly necessary](bitcoin#25768 (comment))
    - since bitcoin#25768, we relied on an earlier call of `ResubmitWalletTransactions(relay=false, force=true)` to initialize `m_next_resend()`, I think we can more elegantly do that by just providing `m_next_resend` with a default value
    - just to highlight: this commit introduces behaviour change

  Note: the `if (!fBroadcastTransactions)` in `CWallet:ShouldResend()` is duplicated on purpose, since it potentially avoids the slightly more expensive `if (!chain().isReadyToBroadcast())` check afterwards. I don't have a strong view on it, so happy to remove that additional check to reduce the diff, too.

ACKs for top commit:
  aureleoules:
    ACK b01682a
  achow101:
    ACK b01682a

Tree-SHA512: ac5f1d8858f8dd736dd1480f385984d660c1916b62a42562317020e8f9fd6a30bd8f23d973d47e4c9480d744c5ba39fdbefd69568a5eb0589a8422d7e5971c1c
@stickies-v stickies-v deleted the n25768-follow-ups branch July 31, 2023 14:23
@bitcoin bitcoin locked and limited conversation to collaborators Jul 30, 2024
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.

7 participants