Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet: Never schedule MaybeCompactWalletDB when -flushwallet is off #18923

Merged
merged 5 commits into from
Jul 11, 2020

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented May 9, 2020

User-facing, this is a refactor. Internally, the scheduler does not have to call a mostly empty function every half a second.

@maflcko
Copy link
Member Author

maflcko commented May 9, 2020

Can be tested by applying the following diff and observing a failing test:

diff --git a/test/functional/wallet_dump.py b/test/functional/wallet_dump.py
index 6bfb468823..f30589761a 100755
--- a/test/functional/wallet_dump.py
+++ b/test/functional/wallet_dump.py
@@ -190,7 +190,7 @@ class WalletDumpTest(BitcoinTestFramework):
         assert_raises_rpc_error(-8, "already exists", lambda: self.nodes[0].dumpwallet(wallet_enc_dump))
 
         # Restart node with new wallet, and test importwallet
-        self.restart_node(0, ['-wallet=w2'])
+        self.restart_node(0, ['-wallet=w2', '-flushwallet=0'])
 
         # Make sure the address is not IsMine before import
         result = self.nodes[0].getaddressinfo(multisig_addr)

@maflcko maflcko force-pushed the 2005-walletNoFlush branch 4 times, most recently from fa5be60 to fabdbbf Compare May 9, 2020 18:32
@DrahtBot
Copy link
Contributor

DrahtBot commented May 10, 2020

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
Contributor

@ryanofsky ryanofsky 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 fa61954

src/interfaces/wallet.cpp Outdated Show resolved Hide resolved
@maflcko maflcko force-pushed the 2005-walletNoFlush branch from fa61954 to 9ddddd2 Compare May 29, 2020 12:48
Copy link
Contributor

@ryanofsky ryanofsky 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 9ddddd2. SInce last review was changed to pass periodic flush option from WalletInit::Construct

Copy link
Contributor

@ryanofsky ryanofsky 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 00000d4. No important suggestions. First two commits are the same since last review, last commit is basically the same, middle commits switch back to passing ArgsManager instead of the bool, but going through WalletContext struct from #19096

src/wallet/test/init_test_fixture.h Outdated Show resolved Hide resolved
src/util/check.h Outdated Show resolved Hide resolved
@fanquake
Copy link
Member

fanquake commented Jun 6, 2020

Concept ACK

@maflcko maflcko force-pushed the 2005-walletNoFlush branch from 00000d4 to faf18d6 Compare June 8, 2020 12:39
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Would be good to merge #19277 first, but code review ACK fac1736. Only change since last review is suggested change to assert return type

@maflcko
Copy link
Member Author

maflcko commented Jul 4, 2020

Rebased

MarcoFalke added 5 commits July 9, 2020 13:07
Its only purpose is to create a directory. So instead of keeping it
alive, use it only to get the path of the directory and then create it
explicitly.
This refactor does not change behavior
for (auto it = env->mapFileUseCount.begin() ; it != env->mapFileUseCount.end(); it++) {
if ((*it).second > 0) return false;
for (const auto& use_count : env->mapFileUseCount) {
if (use_count.second > 0) return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

fa73493

nit, if you feel like cleaning it a bit more maybe do this below:

if (env->mapFileUseCount.erase(strFile) == 0) return false

And drop .erase(it).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, but I'll leave that for a follow-up

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 fa73493

One comment on the new test. Feel free to ignore.

@@ -202,5 +202,10 @@ def run_test(self):
result = self.nodes[0].getaddressinfo(multisig_addr)
assert result['ismine']

self.log.info('Check that wallet is flushed')
with self.nodes[0].assert_debug_log(['Flushing wallet.dat'], timeout=20):
Copy link
Contributor

Choose a reason for hiding this comment

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

I know you'll disagree, but I think it's always better to test the result of an action rather than whether it was logged. In this case, I think you could test the file modification time before and after.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think both can be done at the same time, but asserting the modification time increases requires a time.sleep(1), since os.path.getmtime returns seconds. I don't like sleeps longer than 200 ms in tests, so I'll leave that for a follow-up ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

No need for a follow-up. Fast tests are nice too!

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.

utACK fa73493

Copy link
Contributor

@ryanofsky ryanofsky 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 fa73493. Just rebased since last review

@meshcollider meshcollider merged commit 5f96bce into bitcoin:master Jul 11, 2020
@maflcko maflcko deleted the 2005-walletNoFlush branch July 11, 2020 11:31
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 11, 2020
… -flushwallet is off

fa73493 refactor: Use C++11 range-based for loop (MarcoFalke)
fa7b164 wallet: Never schedule MaybeCompactWalletDB when -flushwallet is off (MarcoFalke)
faf8401 wallet: Pass unused args to StartWallets (MarcoFalke)
fa6c186 gui tests: Limit life-time of dummy testing setup (MarcoFalke)
fa28a61 test: Add smoke test to check that wallets are flushed by default (MarcoFalke)

Pull request description:

  User-facing, this is a refactor. Internally, the scheduler does not have to call a mostly empty function every half a second.

ACKs for top commit:
  jnewbery:
    utACK fa73493
  meshcollider:
    utACK fa73493
  ryanofsky:
    Code review ACK fa73493. Just rebased since last review

Tree-SHA512: 99e1fe1b2c22a3f4b19de3e566241d38693f4fd8d5a68ba1838d86740aa6c08e3325c11a072e30fd262a8861af4278bed52eb9374c85179b8f536477f528247c
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 9, 2020
Summary:
```
User-facing, this is a refactor. Internally, the scheduler does not have
to call a mostly empty function every half a second.
```

Backport of core [[bitcoin/bitcoin#18923 | PR18923]].

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D8638
@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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants