Skip to content

Test: wallet issue with orphaned rewards - #18795

Merged
maflcko merged 1 commit into
bitcoin:masterfrom
domob1812:orphanedreward-test
Jun 4, 2021
Merged

maflcko merged 1 commit into
bitcoin:masterfrom
domob1812:orphanedreward-test

Conversation

@domob1812

Copy link
Copy Markdown
Contributor

This adds a new test case demonstrating the wallet issue when block rewards are orphaned (#14148).

@domob1812

domob1812 commented Apr 28, 2020 •

Copy link
Copy Markdown
Contributor Author

This is meant as an example for #14148 as requested by @MarcoFalke , not to be merged for now.

@DrahtBot

DrahtBot commented Apr 28, 2020 •

Copy link
Copy Markdown
Contributor

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

Conflicts

No conflicts as of last run.

@laanwj

laanwj commented Apr 30, 2020

Copy link
Copy Markdown
Member

If this demonstrates an unfixed issue, shouldn't the test fail on master?

@domob1812

Copy link
Copy Markdown
Contributor Author

If this demonstrates an unfixed issue, shouldn't the test fail on master?

That's a good point. The test was originally written to assert the current behaviour and thus passed (but looking at the code one could see the behaviour described in #14148).

But I agree that is probably confusing. I've added another commit now that makes the test fail as expected (the original version is still preserved in the first commit, as it might be interesting as well for understanding what the issue is about).

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Concept ACK

@domob1812

Copy link
Copy Markdown
Contributor Author

Thanks for the feeback, @MarcoFalke ! I've addressed it with a new commit (so as to not invalidate comments made on previous commits), but am of course happy to squash all history into a single commit any time.

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🄰🄲🄺 I think I am going to merge this.

Maybe squash the commits and add a check for getbalances also before the abandontransaction call. Due to the bug it should be all zeros, right?

@domob1812
domob1812 force-pushed the orphanedreward-test branch 2 times, most recently from 957dee4 to 7aeaa92 Compare May 14, 2020 04:56
@domob1812

Copy link
Copy Markdown
Contributor Author

@MarcoFalke Thanks! I've rebased onto latest master, squashed all commits, and added in a getbalances check before the abandontransaction call as well (which indeed shows all zero).

@maflcko maflcko changed the title Testcase for wallet issue with orphaned rewards Test: wallet issue with orphaned rewards May 14, 2020
@maflcko

maflcko commented May 14, 2020

Copy link
Copy Markdown
Member

ACK 7aeaa92ae0d45cddd2cdbdc735cdbcfa5fb2871a

@DrahtBot DrahtBot mentioned this pull request Jul 15, 2020
@decryp2kanon

Copy link
Copy Markdown
Contributor

Concept ACK

@LarryRuane LarryRuane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK 7aeaa92ae0d45cddd2cdbdc735cdbcfa5fb2871a
Nice PR! I made sure the test passes as written, and that removing the abandontransaction makes it fail as expected. Suggestions are minor nits, nonblocking.

@LarryRuane LarryRuane Dec 16, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can this last sendtoaddress be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes it can, but I think having it in there is an extra check that the wallet does properly handle the coins. So unless there is a strong preference to remove it, I'd rather keep it in to make the test more robust and descriptive.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

... having it in there is an extra check ...

I verified that if this sendtoaddress fails (which I forced by increasing the amount sent to 99999), the entire test fails, which is good. (I wasn't aware of that, which is why I thought this was an unnecessary line of code -- good to leave it in as you have. Need to put an RPC within a try to have its failure not fail the overall test.)

@leonardojobim leonardojobim left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tACK 7aeaa92. Tested on Ubuntu 20.04.

The test successfully demonstrates that when an orphaned block reward is spent together with other outputs, the wallet stops showing any funds and that "abandontransaction(txid)" restores the valid funds.

Agree with #18795 (comment) and #18795 (comment). Using 152 blocks apparently works fine and there's no need of the last line.

The code below would also work as the final validation of this test:

        self.stop_node(1)
        self.start_node(1, ["-zapwallettxes=2"])

        assert_equal(self.nodes[1].getbalances()["mine"], {
          "trusted": 10,
          "untrusted_pending": 0,
          "immature": 0,
        })

@domob1812

Copy link
Copy Markdown
Contributor Author

Thanks @LarryRuane and @leonardojobim , and sorry for the long response time on my end. I have now rebased the PR onto latest master and addressed your comments.

As for the alternate final validation with -zapwallettxes, I agree this is possible, but I think abandontransaction is more explicit as it specifies the transaction in question. I'm happy to change it, though.

@LarryRuane

Copy link
Copy Markdown
Contributor

ACK ef9f3f4b25a6158aa3ff32bf74c104c325c910b1

@leonardojobim leonardojobim left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

reACK ef9f3f4

@adamjonas

Copy link
Copy Markdown
Contributor

Ping for rebase @domob1812.

This adds a new test case demonstrating the wallet issue when block
rewards are orphaned (bitcoin#14148).
@domob1812
domob1812 force-pushed the orphanedreward-test branch from ef9f3f4 to e4356f6 Compare June 2, 2021 12:33
@domob1812

Copy link
Copy Markdown
Contributor Author

Thanks for the reminder, rebased.

@LarryRuane LarryRuane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK e4356f6
I verified that without the abandontransaction, the assertion fails, and (if I comment out the assertion) the sendtoaddress fails.

self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 10)
self.nodes[0].generate(1)

# Get a block reward with node 1 and remember the block so we can orphan

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Get a block reward with node 1 and remember the block so we can orphan
# Get a block reward (25) with node 1 and remember the block so we can orphan

(Non-blocking, only if you touch-up, would have made the test easier for me to understand.)

@adamjonas

Copy link
Copy Markdown
Contributor

CI fail is unrelated, see #20975

@leonardojobim leonardojobim left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

reACK e4356f6 .
Tested on Ubuntu 20.04.

@maflcko
maflcko merged commit 3ac5209 into bitcoin:master Jun 4, 2021
@domob1812
domob1812 deleted the orphanedreward-test branch June 4, 2021 14:23
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
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.

9 participants