Skip to content

Conversation

ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Feb 17, 2021

This commit just moves function without making any changes. It can be reviewed with git log -p -n1 --color-moved=dimmed_zebra

Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems.

This moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files:

  • transaction.cpp/.h - CWalletTx and CMerkleTx class definitions
  • receive.cpp/.h - functions checking received transactions and computing balances
  • spend.cpp/.h - functions creating transactions and finding spendable coins

After #20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to:

  • sync.cpp/.h - functions handling chain notifications and rescanning

This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code.

Followup commit "refactor: Detach wallet transaction methods" in #21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 17, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK 2a855bf light verification of move-only and review of headers and makefile, local debug build and unit tests clean, the re-organisation choices of which code to move where look coherent

@ryanofsky
Copy link
Contributor Author

This is from a hacky, stolen script[1], but here are commands that can be used verify the change is move only. It just prints all the lines that were NOT moved (comment lines and #include lines)

diff_lines=$(git diff HEAD^..HEAD | grep -v '^\(---\|+++\|@@ \)'| grep '^\([><] \)\|[+-]' | sed 's/^+/> /;s/^-/< /')
while IFS= read -r line || [ -n "$line" ]
do
    contents="${line:2}"
    count_removes="$(grep -cFxe "< $contents" <<< "$diff_lines" || true)"
    count_adds="$(grep -cFxe "> $contents" <<< "$diff_lines" || true)"
    test -z "$contents" || test "$count_removes" -eq "$count_adds" || echo "$line"
done <<< "$diff_lines"

[1] script stolen from https://github.com/l0b0/diff-ignore-moved-lines/blob/master/diff-ignore-moved-lines.sh

@ryanofsky
Copy link
Contributor Author

ryanofsky commented Mar 4, 2021

Rebased 2a855bf -> 01f4bb2 (pr/txmove.1 -> pr/txmove.2, compare) due to conflict with #16546
Rebased 01f4bb2 -> 74d4529 (pr/txmove.2 -> pr/txmove.3, compare) due to conflict with #20536

@ryanofsky
Copy link
Contributor Author

Requesting concept ACKs for this PR!

No are no code changes, only moves, so the review should be trivial. Also, this is easy for me to rebase, so if anyone is concerned about conflicts and wants this delayed until another change is merged, that is no problem. I'm going to try to review PRs on the conflict list #21207 (comment), but it'd be good to know if any PRs in particular are a concern!

@promag
Copy link
Contributor

promag commented Mar 9, 2021

I've ACK this change on the follow up PR.

@practicalswift
Copy link
Contributor

Concept ACK: less monolithic is more

@Sjors
Copy link
Member

Sjors commented May 21, 2021

re-utACK 264b945

@ryanofsky
Copy link
Contributor Author

Rebased 264b945 -> ae93b95 (pr/txmove.7 -> pr/txmove.8, compare) due to conflict with #17331

@Sjors
Copy link
Member

Sjors commented May 25, 2021

re-utACK ae93b95 (checked that the range-diff is just changes inside the conflicting functions and that git show --color-moved=dimmed_zebra still only moves entire functions).

@practicalswift
Copy link
Contributor

cr ACK ae93b95: dimmed zebra looks correct

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

ACK after rebase due to #22042.

This commit just moves functions without making any changes. It can be
reviewed with `git log -p -n1 --color-moved=dimmed_zebra`

Motivation for this change is to make wallet.cpp/h less monolithic and
start to make wallet transaction state tracking comprehensible so bugs
in
https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking
can be fixed safely without introducing new problems.

This commit moves wallet classes and methods that deal with transactions
out of wallet.cpp/.h into better organized files:

- transaction.cpp/.h - CWalletTx and CMerkleTx class definitions
- receive.cpp/.h - functions checking received transactions and computing balances
- spend.cpp/.h - functions creating transactions and finding spendable coins

After bitcoin#20773, when loading is separated from syncing it will also be
possible to move more wallet.cpp/.h functions to:

- sync.cpp/.h - functions handling chain notifications and rescanning

This commit arranges receive.cpp and spend.cpp functions in dependency
order so it's possible to skim receive.cpp and get an idea of how
computing balances works, and skim spend.cpp and get an idea of how
transactions are created, without having to jump all over wallet.cpp
where functions are not in order and there is a lot of unrelated code.

Followup commit "refactor: Detach wallet transaction methods" in
bitcoin#21206 follows up this PR and
tweaks function names and arguments to reflect new locations. The two
commits are split into separate PRs because this commit is more work to
maintain and less work to review, while the other commit is less work to
maintain and more work to review, so hopefully this commit can be merged
earlier.
@ryanofsky
Copy link
Contributor Author

Rebased ae93b95 -> c7bd584 (pr/txmove.8 -> pr/txmove.9, compare) due to conflicts with #22042 and #18418

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Code review ACK c7bd584, verified move only claim.

This is base for #21206 which IMO is an awesome change. Reviewers might want to check that to get motivation for this one.

@Sjors
Copy link
Member

Sjors commented May 26, 2021

re-utACK c7bd584

In case we want more review / concept ACKs: cc @achow101, @instagibbs, @fjahr

@fjahr
Copy link
Contributor

fjahr commented May 26, 2021

utACK c7bd584

I reviewed using git show --color-moved=dimmed_zebra and manually confirmed the few instances were git was acting funny with the diffs. Move-only confirmed.

@fanquake fanquake requested a review from meshcollider May 27, 2021 13:39
Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

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

Dimmed-zebra-check and functional test run ACK c7bd584

@meshcollider meshcollider merged commit 55a156f into bitcoin:master May 30, 2021
domob1812 added a commit to domob1812/namecoin-core that referenced this pull request May 31, 2021
Updated bitcoin/bitcoin#21207 (code moves
out of wallet.cpp) for the Namecoin-specific changes made to
receiving and spending name coins.
Copy link

@doianmai2020 doianmai2020 left a comment

Choose a reason for hiding this comment

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

.

@bitcoin bitcoin locked and limited conversation to collaborators May 31, 2021
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.