Page MenuHomePhabricator

refactor: Detach wallet transaction methods (followup for move-only)
ClosedPublic

Authored by PiRK on Dec 7 2022, 12:12.

Details

Summary

Followup to commit "MOVEONLY: CWallet transaction code out of
wallet.cpp/.h" that detaches and renames some CWalletTx methods, making
into them into standalone functions or CWallet methods instead.

There are no changes in behavior and no code changes that aren't purely
mechanical. It just gives spend and receive functions more consistent
names and removes the circular dependencies added by the earlier
MOVEONLY commit.

There are also no comment or documentation changes. Removed comments
from transaction.h are just migrated to spend.h, receive.h, and
wallet.h.

Note:

  • the function AttemptSelection from the source material is named SelectCoinsMinConf in BitcoinABC because we miss core#22008

This is a backport of core#22100

Test Plan

ninja all check-all

Event Timeline

PiRK requested review of this revision.Dec 7 2022, 12:12
Fabien requested changes to this revision.Dec 7 2022, 16:23
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/wallet/receive.cpp
267 ↗(On Diff #37044)

Unrelated, but fine

315 ↗(On Diff #37044)

Extra parenthesis

393 ↗(On Diff #37044)

Same, unrelated but good

414 ↗(On Diff #37044)

Revert

src/wallet/receive.h
47 ↗(On Diff #37044)

I don't understand why CWallet is an incomplete type here

src/wallet/spend.cpp
646 ↗(On Diff #37044)

Missing the lock annotation (also the AssertLockHeld probably from another backport)

1028 ↗(On Diff #37044)

Same there is no lock here, please check if it's needed or not

src/wallet/spend.h
12 ↗(On Diff #37044)

Layout

74 ↗(On Diff #37044)

Should be doxygen

166 ↗(On Diff #37044)
src/wallet/test/wallet_tests.cpp
604 ↗(On Diff #37044)

Why is that needed ? It breaks the test history in the CI

src/wallet/wallet.h
377 ↗(On Diff #37044)

Needs to be removed, it's now static

461 ↗(On Diff #37044)

Seems wrong ?

476 ↗(On Diff #37044)

dito

699 ↗(On Diff #37044)
This revision now requires changes to proceed.Dec 7 2022, 16:23
PiRK marked 7 inline comments as done.Dec 8 2022, 08:34
PiRK added inline comments.
src/wallet/receive.h
47 ↗(On Diff #37044)

I suspect this was not touched to make the PR Move-only-ish. I fixed it in a separate diff D12809

src/wallet/spend.cpp
646 ↗(On Diff #37044)

Yes, there must be some missing backports. Right now this function takes the lock on line 677 so I cannot add the lock annotation right now.

1028 ↗(On Diff #37044)

See reply for CreateTransactionInternal (the lock is taken inside that function for now, I will check which backport is missing)

src/wallet/wallet.h
461 ↗(On Diff #37044)

Will be fixed in D12809

Tail of the build log:

        list = ListCoins(*wallet);
               ^~~~~~~~~~~~~~~~~
../../src/wallet/test/wallet_tests.cpp:604:25: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'CWallet' to 'const wallet_tests::ListCoins' for 1st argument
BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup) {
                        ^
/usr/include/boost/test/unit_test_suite.hpp:182:10: note: expanded from macro 'BOOST_FIXTURE_TEST_CASE'
         __VA_ARGS__)                                                   \
         ^
/usr/include/boost/test/detail/pp_variadic.hpp:40:9: note: expanded from macro 'BOOST_TEST_INVOKE_IF_N_ARGS'
        __VA_ARGS__ )                                               \
        ^
/usr/include/boost/test/detail/pp_variadic.hpp:27:57: note: expanded from macro 'BOOST_TEST_INVOKE_VARIADIC'
#  define BOOST_TEST_INVOKE_VARIADIC( tool, ... ) tool (__VA_ARGS__)
                                                        ^
/usr/include/boost/test/unit_test_suite.hpp:172:37: note: expanded from macro 'BOOST_FIXTURE_TEST_CASE_NO_DECOR'
BOOST_FIXTURE_TEST_CASE_WITH_DECOR( test_name, F,                       \
                                    ^
/usr/include/boost/test/unit_test_suite.hpp:145:8: note: expanded from macro '\
BOOST_FIXTURE_TEST_CASE_WITH_DECOR'
struct test_name : public F { void test_method(); };                    \
       ^
../../src/wallet/test/wallet_tests.cpp:604:25: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided
../../src/wallet/test/wallet_tests.cpp:660:14: error: no viable overloaded '='
        list = ListCoins(*wallet);
        ~~~~ ^ ~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_map.h:319:7: note: candidate function not viable: no known conversion from 'wallet_tests::ListCoins' to 'const std::map<boost::variant<CNoDestination, PKHash, ScriptHash>, std::vector<COutput>>' for 1st argument
      operator=(const map&) = default;
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_map.h:323:7: note: candidate function not viable: no known conversion from 'wallet_tests::ListCoins' to 'std::map<boost::variant<CNoDestination, PKHash, ScriptHash>, std::vector<COutput>>' for 1st argument
      operator=(map&&) = default;
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_map.h:337:7: note: candidate function not viable: no known conversion from 'wallet_tests::ListCoins' to 'initializer_list<std::map<boost::variant<CNoDestination, PKHash, ScriptHash>, std::vector<COutput>>::value_type>' (aka 'initializer_list<pair<const boost::variant<CNoDestination, PKHash, ScriptHash>, std::vector<COutput>>>') for 1st argument
      operator=(initializer_list<value_type> __l)
      ^
6 errors generated.
[211/480] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/paymentservertests.cpp.o
[212/480] pow: testing aserti32d_tests
[213/480] Running utility command for check-pow-aserti32d_tests
[214/480] Running pow test suite
PASSED: pow test suite
[215/480] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/psbt_wallet_tests.cpp.o
[216/480] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/scriptpubkeyman_tests.cpp.o
[217/480] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/ismine_tests.cpp.o
[218/480] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/walletdb_tests.cpp.o
[219/480] secp256k1: testing secp256k1-exhaustive_tests
[220/480] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/apptests.cpp.o
[221/480] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/coinselector_tests.cpp.o
[222/480] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/__/__/wallet/test/wallet_test_fixture.cpp.o
[223/480] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/rpcnestedtests.cpp.o
[224/480] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/addressbooktests.cpp.o
[225/480] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/wallettests.cpp.o
[226/480] Linking CXX executable src/qt/test/test_bitcoin-qt
[227/480] bitcoin-qt: testing test_bitcoin-qt
[228/480] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[229/480] secp256k1: testing secp256k1-tests
[230/480] Running secp256k1 test suite
PASSED: secp256k1 test suite
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang failed with exit code 1
PiRK planned changes to this revision.Dec 8 2022, 08:40

something is wrong with my rebase

Tail of the build log:

[179/473] Test Bitcoin RPC authentication...
...
----------------------------------------------------------------------
Ran 3 tests in 0.021s

OK
[180/473] cd /work/contrib/devtools/chainparams && /usr/bin/python3.9 ./test_make_chainparams.py
.....
----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK
[181/473] pow: testing grasberg_tests
[182/473] Running utility command for check-pow-grasberg_tests
[183/473] Automatic MOC for target test_bitcoin-qt
[184/473] Building CXX object src/seeder/test/CMakeFiles/test-seeder.dir/message_writer_tests.cpp.o
[185/473] Building CXX object src/seeder/test/CMakeFiles/test-seeder.dir/write_name_tests.cpp.o
[186/473] Building CXX object src/seeder/test/CMakeFiles/test-seeder.dir/p2p_messaging_tests.cpp.o
[187/473] Test Bitcoin utilities...
[188/473] Linking CXX executable src/seeder/test/test-seeder
[189/473] seeder: testing options_tests
[190/473] Running utility command for check-seeder-options_tests
[191/473] seeder: testing message_writer_tests
[192/473] Running utility command for check-seeder-message_writer_tests
[193/473] seeder: testing p2p_messaging_tests
[194/473] Running utility command for check-seeder-p2p_messaging_tests
[195/473] seeder: testing parse_name_tests
[196/473] Running utility command for check-seeder-parse_name_tests
[197/473] seeder: testing write_name_tests
[198/473] Running utility command for check-seeder-write_name_tests
[199/473] Running seeder test suite
PASSED: seeder test suite
[200/473] pow: testing aserti32d_tests
[201/473] Running utility command for check-pow-aserti32d_tests
[202/473] Running pow test suite
PASSED: pow test suite
[203/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/bitcoinaddressvalidatortests.cpp.o
[204/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/compattests.cpp.o
[205/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/test_bitcoin-qt_autogen/mocs_compilation.cpp.o
[206/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/guiutiltests.cpp.o
[207/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/util.cpp.o
[208/473] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/scriptpubkeyman_tests.cpp.o
[209/473] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/ismine_tests.cpp.o
[210/473] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/psbt_wallet_tests.cpp.o
[211/473] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/walletdb_tests.cpp.o
[212/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/rpcnestedtests.cpp.o
[213/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/apptests.cpp.o
[214/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/uritests.cpp.o
[215/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/test_main.cpp.o
[216/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/paymentservertests.cpp.o
[217/473] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/coinselector_tests.cpp.o
[218/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/__/__/wallet/test/wallet_test_fixture.cpp.o
[219/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/addressbooktests.cpp.o
[220/473] Building CXX object src/qt/test/CMakeFiles/test_bitcoin-qt.dir/wallettests.cpp.o
[221/473] Linking CXX executable src/qt/test/test_bitcoin-qt
[222/473] bitcoin-qt: testing test_bitcoin-qt
[223/473] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang-tidy failed with exit code 1

Tail of the build log:

interface_usdt_validation.py              | ○ Skipped | 0 s

ALL                                       | ✓ Passed  | 1933 s (accumulated) 
Runtime: 396 s

[34/481] Test Bitcoin RPC authentication...
...
----------------------------------------------------------------------
Ran 3 tests in 0.005s

OK
[36/481] cd /work/contrib/devtools/chainparams && /usr/bin/python3.9 ./test_make_chainparams.py
.....
----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK
[176/481] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/wallet_tests.cpp.o
FAILED: src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/wallet_tests.cpp.o 
/usr/bin/ccache /usr/bin/c++ -DABORT_ON_FAILED_ASSUME -DBOOST_AC_USE_STD_ATOMIC -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_SP_USE_STD_ATOMIC -DBOOST_TEST_DYN_LINK -DBOOST_THREAD_DYN_LINK -DBOOST_UNIT_TEST_FRAMEWORK_DYN_LINK -DBUILD_BITCOIN_INTERNAL -DDEBUG -DDEBUG_LOCKORDER -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I../../src/univalue/include -I../../src/. -Isrc -Isrc/crypto/.. -I../../src/secp256k1/include -I../../src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -O0 -fPIE -fvisibility=hidden -g3 -ftrapv -fstack-reuse=none -fstack-protector-all -Wstack-protector -U_FORTIFY_SOURCE -Wall -Wextra -Wformat -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wredundant-decls -Wsign-compare -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Wformat-security -Wredundant-move -Woverloaded-virtual -Wno-unused-parameter -Wno-implicit-fallthrough -pthread -std=gnu++17 -MD -MT src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/wallet_tests.cpp.o -MF src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/wallet_tests.cpp.o.d -o src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/wallet_tests.cpp.o -c ../../src/wallet/test/wallet_tests.cpp
../../src/wallet/test/wallet_tests.cpp: In member function ‘void wallet_tests::ListCoins::test_method()’:
../../src/wallet/test/wallet_tests.cpp:612:33: error: no matching function for call to ‘wallet_tests::ListCoins::ListCoins(CWallet&)’
  612 |         list = ListCoins(*wallet);
      |                                 ^
In file included from /usr/include/boost/test/unit_test.hpp:19,
                 from ../../src/wallet/test/wallet_tests.cpp:25:
../../src/wallet/test/wallet_tests.cpp:604:25: note: candidate: ‘wallet_tests::ListCoins::ListCoins()’
  604 | BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup) {
      |                         ^~~~~~~~~
../../src/wallet/test/wallet_tests.cpp:604:25: note:   candidate expects 0 arguments, 1 provided
../../src/wallet/test/wallet_tests.cpp:630:33: error: no matching function for call to ‘wallet_tests::ListCoins::ListCoins(CWallet&)’
  630 |         list = ListCoins(*wallet);
      |                                 ^
In file included from /usr/include/boost/test/unit_test.hpp:19,
                 from ../../src/wallet/test/wallet_tests.cpp:25:
../../src/wallet/test/wallet_tests.cpp:604:25: note: candidate: ‘wallet_tests::ListCoins::ListCoins()’
  604 | BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup) {
      |                         ^~~~~~~~~
../../src/wallet/test/wallet_tests.cpp:604:25: note:   candidate expects 0 arguments, 1 provided
../../src/wallet/test/wallet_tests.cpp:660:33: error: no matching function for call to ‘wallet_tests::ListCoins::ListCoins(CWallet&)’
  660 |         list = ListCoins(*wallet);
      |                                 ^
In file included from /usr/include/boost/test/unit_test.hpp:19,
                 from ../../src/wallet/test/wallet_tests.cpp:25:
../../src/wallet/test/wallet_tests.cpp:604:25: note: candidate: ‘wallet_tests::ListCoins::ListCoins()’
  604 | BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup) {
      |                         ^~~~~~~~~
../../src/wallet/test/wallet_tests.cpp:604:25: note:   candidate expects 0 arguments, 1 provided
[207/481] Running seeder test suite
PASSED: seeder test suite
[217/481] Running pow test suite
PASSED: pow test suite
[225/481] Running avalanche test suite
PASSED: avalanche test suite
[228/481] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[230/481] Running secp256k1 test suite
PASSED: secp256k1 test suite
ninja: build stopped: cannot make progress due to previous errors.
Build build-debug failed with exit code 1

Tail of the build log:

tool_wallet.py --descriptors              | ✓ Passed  | 2 s
wallet_abandonconflict.py                 | ✓ Passed  | 4 s
wallet_address_types.py                   | ✓ Passed  | 17 s
wallet_address_types.py --descriptors     | ✓ Passed  | 8 s
wallet_avoidreuse.py                      | ✓ Passed  | 4 s
wallet_avoidreuse.py --descriptors        | ✓ Passed  | 4 s
wallet_backup.py                          | ✓ Passed  | 31 s
wallet_balance.py                         | ✓ Passed  | 4 s
wallet_balance.py --descriptors           | ✓ Passed  | 6 s
wallet_basic.py                           | ✓ Passed  | 18 s
wallet_coinbase_category.py               | ✓ Passed  | 1 s
wallet_create_tx.py                       | ✓ Passed  | 5 s
wallet_createwallet.py                    | ✓ Passed  | 2 s
wallet_createwallet.py --descriptors      | ✓ Passed  | 2 s
wallet_createwallet.py --usecli           | ✓ Passed  | 2 s
wallet_descriptor.py                      | ✓ Passed  | 6 s
wallet_disable.py                         | ✓ Passed  | 1 s
wallet_dump.py                            | ✓ Passed  | 5 s
wallet_encryption.py                      | ✓ Passed  | 5 s
wallet_encryption.py --descriptors        | ✓ Passed  | 5 s
wallet_groups.py                          | ✓ Passed  | 15 s
wallet_hd.py                              | ✓ Passed  | 6 s
wallet_hd.py --descriptors                | ✓ Passed  | 6 s
wallet_import_rescan.py                   | ✓ Passed  | 7 s
wallet_import_with_label.py               | ✓ Passed  | 1 s
wallet_importdescriptors.py               | ✓ Passed  | 5 s
wallet_importmulti.py                     | ✓ Passed  | 2 s
wallet_importprunedfunds.py               | ✓ Passed  | 2 s
wallet_importprunedfunds.py --descriptors | ✓ Passed  | 2 s
wallet_keypool.py                         | ✓ Passed  | 3 s
wallet_keypool_topup.py                   | ✓ Passed  | 3 s
wallet_keypool_topup.py --descriptors     | ✓ Passed  | 5 s
wallet_labels.py                          | ✓ Passed  | 2 s
wallet_labels.py --descriptors            | ✓ Passed  | 1 s
wallet_listreceivedby.py                  | ✓ Passed  | 5 s
wallet_listsinceblock.py                  | ✓ Passed  | 6 s
wallet_listsinceblock.py --descriptors    | ✓ Passed  | 6 s
wallet_listtransactions.py                | ✓ Passed  | 4 s
wallet_listtransactions.py --descriptors  | ✓ Passed  | 4 s
wallet_multiwallet.py                     | ✓ Passed  | 41 s
wallet_multiwallet.py --usecli            | ✓ Passed  | 9 s
wallet_reorgsrestore.py                   | ✓ Passed  | 3 s
wallet_resendwallettransactions.py        | ✓ Passed  | 5 s
wallet_send.py                            | ✓ Passed  | 6 s
wallet_startup.py                         | ✓ Passed  | 2 s
wallet_txn_clone.py                       | ✓ Passed  | 1 s
wallet_txn_clone.py --mineblock           | ✓ Passed  | 3 s
wallet_txn_doublespend.py                 | ✓ Passed  | 1 s
wallet_txn_doublespend.py --mineblock     | ✓ Passed  | 3 s
wallet_watchonly.py                       | ✓ Passed  | 1 s
wallet_watchonly.py --usecli              | ✓ Passed  | 1 s
interface_usdt_net.py                     | ○ Skipped | 0 s
interface_usdt_utxocache.py               | ○ Skipped | 0 s
interface_usdt_validation.py              | ○ Skipped | 0 s

ALL                                       | ✓ Passed  | 1274 s (accumulated) 
Runtime: 255 s

ninja: build stopped: cannot make progress due to previous errors.
Build build-diff failed with exit code 1

revert reverting the renaming of unit test, because the initial change was necessary to avoid a naming conflict with the ListCoins function

src/wallet/test/wallet_tests.cpp
604 ↗(On Diff #37044)

OK now I understand why this is needed. The name conflicts with the function ListCoins. I don't see how to fix it right now, but maybe we can later revert the name back after the wallet:: namespace backport.

core#22008 is the backport that changes the lock for CreateTransaction and CreateTransactionInternal. It is not a bugfix, just a way of improving the code by unindenting a large part of the function, so it can safely be backport in a separate diff.

src/wallet/spend.cpp
646 ↗(On Diff #37044)

core#22008

Fabien added inline comments.
src/wallet/spend.cpp
650 ↗(On Diff #37104)

Macro likestamp:

src/wallet/test/wallet_tests.cpp
604 ↗(On Diff #37044)

Got it, leave as the source material then

This revision is now accepted and ready to land.Dec 8 2022, 12:04