Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented May 27, 2020

Extend the test to check the balance remains the same before and after the salvage

@jonasschnelli
Copy link
Contributor

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 2, 2020

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

Conflicts

No conflicts as of last run.

@maflcko maflcko closed this Jun 5, 2020
@maflcko maflcko reopened this Jun 5, 2020
@DrahtBot DrahtBot closed this Jun 5, 2020
@DrahtBot DrahtBot reopened this Jun 5, 2020
@maflcko maflcko force-pushed the 2005-testWalletToolSalvage branch from 166187b to 3650390 Compare June 5, 2020 17:42
@jonatack
Copy link
Member

jonatack commented Jun 5, 2020

Concept ACK.

Seeing this error: Assertion `new_tx' failed:

2020-06-05T18:01:34.518000Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_func_test_hf5xwzyh
2020-06-05T18:01:34.975000Z TestFramework (INFO): Testing that various invalid commands raise with specific error messages
2020-06-05T18:01:35.809000Z TestFramework (INFO): Calling wallet tool info, testing output
2020-06-05T18:01:36.535000Z TestFramework (INFO): Generating transaction to mutate wallet
2020-06-05T18:01:39.036000Z TestFramework (INFO): Calling wallet tool info after generating a transaction, testing output
2020-06-05T18:01:39.238000Z TestFramework (INFO): Calling wallet tool create on an existing wallet, testing output
2020-06-05T18:01:41.947000Z TestFramework (INFO): Starting node with arg -wallet=foo
2020-06-05T18:01:42.716000Z TestFramework (INFO): Calling getwalletinfo on a different wallet ("foo"), testing output
2020-06-05T18:01:42.975000Z TestFramework (INFO): Check salvage
2020-06-05T18:01:51.543000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/home/jon/projects/bitcoin/bitcoin/test/functional/test_framework/test_framework.py", line 119, in main
    self.run_test()
  File "test/functional/tool_wallet.py", line 245, in run_test
    self.test_salvage()
  File "test/functional/tool_wallet.py", line 232, in test_salvage
    self.assert_tool_output('', '-wallet=salvage', 'salvage')
  File "test/functional/tool_wallet.py", line 52, in assert_tool_output
    assert_equal(stderr, '')
  File "/home/jon/projects/bitcoin/bitcoin/test/functional/test_framework/util.py", line 46, in assert_equal
    raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
AssertionError: not(bitcoin-wallet: wallet/walletdb.cpp:289: auto ReadKeyValue(CWallet *, CDataStream &, CDataStream &, CWalletScanState &, std::string &, std::string &)::(anonymous class)::operator()(CWalletTx &, bool) const: Assertion `new_tx' failed.
 == )
2020-06-05T18:01:51.595000Z TestFramework (INFO): Stopping nodes

@maflcko maflcko force-pushed the 2005-testWalletToolSalvage branch 2 times, most recently from b53ccb5 to fab4fa1 Compare July 2, 2020 11:39
self.stop_node(0)

self.assert_tool_output('', '-wallet=salvage', 'salvage')

self.start_node(0, ['-wallet=salvage'])
Copy link
Member

Choose a reason for hiding this comment

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

I had to add self.nodes[0].rescanblockchain(0) to make this pass after merging with #19457

@achow101
Copy link
Member

#19805 is a potential solution to the test failure as it just avoids deserializing those records entirely.

#19793 is a another potential solution to the test failure where the assert is removed.

@ryanofsky
Copy link
Contributor

#19805 is a potential solution to the test failure as it just avoids deserializing those records entirely.

#19793 is a another potential solution to the test failure where the assert is removed.

Maybe I should look at the test to understand better, but both of these changes are avoiding failures when there are duplicate transactions in the database. But we still don't know how duplicate transactions are winding up in the database to begin with?

@achow101
Copy link
Member

achow101 commented Aug 25, 2020

But we still don't know how duplicate transactions are winding up in the database to begin with?

The duplicate transactions are showing up in the records the salvage pulls from the database. This doesn't mean the database actually contains duplicate transactions but is actually more of an artifact of the aggressive salvage.

Specifically, the aggressive salvage will likely recover deleted data as such data is not actually overwritten, just marked deleted. The aggressive salvage ignores the deletion flag so it will pull up those records. In this test, the Btree ends up being rebalanced which involves moving data around and this is done via copy and delete. So the aggressive salvage is finding records in the "deleted space".

fanquake added a commit that referenced this pull request Sep 3, 2020
0bbe26a wallet: filter for keys only before record deser in salvage (Andrew Chow)
544e12a walletdb: Add KeyFilterFn to ReadKeyValue (Andrew Chow)

Pull request description:

  When salvaging a wallet, the only things that matter are the private keys. It is not necessary to attempt to deserialize any other records, especially if those records are corrupted too.

  This PR adds a `KeyFilterFn` function callback to `ReadKeyValue` that salvage uses to filter for only the records that it wants. Of course doing it this way also lets us do other filters in the future from other places should we so desire.

ACKs for top commit:
  ryanofsky:
    Code review ACK 0bbe26a. Looks great! This should make the recovery code more robust. Normally it'd be good to have a test case for the problem this fixes, but Marco already wrote one in #19078, so I think we're covered
  laanwj:
    Code review ACK 0bbe26a

Tree-SHA512: 8e3ee283a22a79273915711c4fb751f3c9b02ce94e6bf08dc468f1cfdf9fac35c693bbfd2435ce43c3a06c601b9b0a67e209621f6814bedfe3bc7a7ccc37bb01
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 3, 2020
…salvaging

0bbe26a wallet: filter for keys only before record deser in salvage (Andrew Chow)
544e12a walletdb: Add KeyFilterFn to ReadKeyValue (Andrew Chow)

Pull request description:

  When salvaging a wallet, the only things that matter are the private keys. It is not necessary to attempt to deserialize any other records, especially if those records are corrupted too.

  This PR adds a `KeyFilterFn` function callback to `ReadKeyValue` that salvage uses to filter for only the records that it wants. Of course doing it this way also lets us do other filters in the future from other places should we so desire.

ACKs for top commit:
  ryanofsky:
    Code review ACK 0bbe26a. Looks great! This should make the recovery code more robust. Normally it'd be good to have a test case for the problem this fixes, but Marco already wrote one in bitcoin#19078, so I think we're covered
  laanwj:
    Code review ACK 0bbe26a

Tree-SHA512: 8e3ee283a22a79273915711c4fb751f3c9b02ce94e6bf08dc468f1cfdf9fac35c693bbfd2435ce43c3a06c601b9b0a67e209621f6814bedfe3bc7a7ccc37bb01
@maflcko maflcko force-pushed the 2005-testWalletToolSalvage branch from 9670752 to fa6154b Compare October 15, 2020 08:16
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 fa6154b

Test looks right to me but there is an travis failure on one platform

self.nodes[0].generatetoaddress(1, gna())
self.nodes[0].sendmany(amounts={gna(): 0.05 for _ in range(50)})
self.nodes[0].sendmany(amounts={gna(): 0.05 for _ in range(50)})
balances_before = self.nodes[0].getbalances()
self.stop_node(0)

self.assert_tool_output('', '-wallet=salvage', 'salvage')
Copy link
Contributor

Choose a reason for hiding this comment

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

In commit "test: Add salvage test for wallet tool" (fa6154b)

It seems the test is failing on this line due to stderr output https://travis-ci.org/github/bitcoin/bitcoin/jobs/735969416#L2582:

Salvage: WARNING: Number of keys in data does not match number of values.
Salvage: WARNING: Unexpected end of file while reading salvage output.
WARNING: WalletBatch::Recover skipping key: CDataStream::read(): end of data: unspecified iostream_category error
WARNING: WalletBatch::Recover skipping key: CDataStream::read(): end of data: unspecified iostream_category error
WARNING: WalletBatch::Recover skipping key: Error reading wallet database: CPubKey/CPrivKey corrupt

Copy link
Member Author

Choose a reason for hiding this comment

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

@maflcko maflcko force-pushed the 2005-testWalletToolSalvage branch 2 times, most recently from 96239e8 to 66660e4 Compare October 30, 2020 10:52
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 66660e4. Only change since last review is rebase. Also travis seems to pass now.

I'm confused about why the test was failing before #19078 (comment) but succeeding now. The bug report #20151 just points back to this PR for steps to reproduce (which I guess no longer work?) and doesn't mention whether the problem happens reliably or is maybe random or platform specific.

@maflcko
Copy link
Member Author

maflcko commented Nov 3, 2020

Please don't merge this. The failure still happens intermittently.

@meshcollider
Copy link
Contributor

meshcollider commented Sep 28, 2021

@MarcoFalke how often does the intermittent test failure occur? I've rebased this on a branch which incorporates a few other salvage things, which fixes the assert(new_tx) thing again. I haven't been able to hit #20151 yet after multiple re-runs locally.

@maflcko maflcko force-pushed the 2005-testWalletToolSalvage branch from 66660e4 to 8d600d6 Compare September 28, 2021 10:10
@maflcko
Copy link
Member Author

maflcko commented Sep 28, 2021

How often did you try? I am running

while test/functional/tool_wallet.py --legacy-wallet ; do ( echo 1 >> /tmp/runs )  ; done

and it fails after 36 tries:

$ wc -l  /tmp/runs 
36 /tmp/runs

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 7, 2022
…salvaging

0bbe26a wallet: filter for keys only before record deser in salvage (Andrew Chow)
544e12a walletdb: Add KeyFilterFn to ReadKeyValue (Andrew Chow)

Pull request description:

  When salvaging a wallet, the only things that matter are the private keys. It is not necessary to attempt to deserialize any other records, especially if those records are corrupted too.

  This PR adds a `KeyFilterFn` function callback to `ReadKeyValue` that salvage uses to filter for only the records that it wants. Of course doing it this way also lets us do other filters in the future from other places should we so desire.

ACKs for top commit:
  ryanofsky:
    Code review ACK 0bbe26a. Looks great! This should make the recovery code more robust. Normally it'd be good to have a test case for the problem this fixes, but Marco already wrote one in bitcoin#19078, so I think we're covered
  laanwj:
    Code review ACK 0bbe26a

Tree-SHA512: 8e3ee283a22a79273915711c4fb751f3c9b02ce94e6bf08dc468f1cfdf9fac35c693bbfd2435ce43c3a06c601b9b0a67e209621f6814bedfe3bc7a7ccc37bb01
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 7, 2022
…salvaging

0bbe26a wallet: filter for keys only before record deser in salvage (Andrew Chow)
544e12a walletdb: Add KeyFilterFn to ReadKeyValue (Andrew Chow)

Pull request description:

  When salvaging a wallet, the only things that matter are the private keys. It is not necessary to attempt to deserialize any other records, especially if those records are corrupted too.

  This PR adds a `KeyFilterFn` function callback to `ReadKeyValue` that salvage uses to filter for only the records that it wants. Of course doing it this way also lets us do other filters in the future from other places should we so desire.

ACKs for top commit:
  ryanofsky:
    Code review ACK 0bbe26a. Looks great! This should make the recovery code more robust. Normally it'd be good to have a test case for the problem this fixes, but Marco already wrote one in bitcoin#19078, so I think we're covered
  laanwj:
    Code review ACK 0bbe26a

Tree-SHA512: 8e3ee283a22a79273915711c4fb751f3c9b02ce94e6bf08dc468f1cfdf9fac35c693bbfd2435ce43c3a06c601b9b0a67e209621f6814bedfe3bc7a7ccc37bb01
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 7, 2022
…salvaging

0bbe26a wallet: filter for keys only before record deser in salvage (Andrew Chow)
544e12a walletdb: Add KeyFilterFn to ReadKeyValue (Andrew Chow)

Pull request description:

  When salvaging a wallet, the only things that matter are the private keys. It is not necessary to attempt to deserialize any other records, especially if those records are corrupted too.

  This PR adds a `KeyFilterFn` function callback to `ReadKeyValue` that salvage uses to filter for only the records that it wants. Of course doing it this way also lets us do other filters in the future from other places should we so desire.

ACKs for top commit:
  ryanofsky:
    Code review ACK 0bbe26a. Looks great! This should make the recovery code more robust. Normally it'd be good to have a test case for the problem this fixes, but Marco already wrote one in bitcoin#19078, so I think we're covered
  laanwj:
    Code review ACK 0bbe26a

Tree-SHA512: 8e3ee283a22a79273915711c4fb751f3c9b02ce94e6bf08dc468f1cfdf9fac35c693bbfd2435ce43c3a06c601b9b0a67e209621f6814bedfe3bc7a7ccc37bb01
@achow101
Copy link
Member

Are you still working on this?

@achow101
Copy link
Member

Closing this as it has not had any activity in a while. If you are interested in continuing work on this, please leave a comment so that it can be reopened.

@achow101 achow101 closed this Nov 10, 2022
@maflcko maflcko changed the title test: Add salvage test for wallet tool test: Extend salvage test for wallet tool Nov 11, 2022
@maflcko
Copy link
Member Author

maflcko commented Nov 11, 2022

Ok, I'll rebase

@maflcko maflcko reopened this Nov 11, 2022
@maflcko maflcko force-pushed the 2005-testWalletToolSalvage branch from 8d600d6 to fa60b70 Compare November 11, 2022 12:23
@maflcko
Copy link
Member Author

maflcko commented Nov 11, 2022

The test still fails locally after a sufficient number of iterations, so I guess it is best to remove the command along with the removal of bdb

@maflcko maflcko closed this Nov 11, 2022
@maflcko maflcko deleted the 2005-testWalletToolSalvage branch November 11, 2022 13:56
@bitcoin bitcoin locked and limited conversation to collaborators Nov 11, 2023
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.

8 participants