Skip to content

Conversation

domob1812
Copy link
Contributor

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

@domob1812
Copy link
Contributor Author

domob1812 commented Apr 28, 2020

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 28, 2020

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

Conflicts

No conflicts as of last run.

@laanwj
Copy link
Member

laanwj commented Apr 30, 2020

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

@domob1812
Copy link
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).

Copy link
Member

@maflcko maflcko left a comment

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
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.

Copy link
Member

@maflcko maflcko left a comment

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
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
Copy link
Member

maflcko commented May 14, 2020

ACK 7aeaa92

@DrahtBot DrahtBot mentioned this pull request Jul 15, 2020
@decryp2kanon
Copy link
Contributor

Concept ACK

Copy link
Contributor

@LarryRuane LarryRuane left a comment

Choose a reason for hiding this comment

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

ACK 7aeaa92
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.

"untrusted_pending": 0,
"immature": 0,
})
self.nodes[1].sendtoaddress(address=self.nodes[0].getnewaddress(), amount=9, subtractfeefromamount=True)
Copy link
Contributor

@LarryRuane LarryRuane Dec 16, 2020

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
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
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.)

Copy link

@leonardojobim leonardojobim left a comment

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
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
Contributor

ACK ef9f3f4

Copy link

@leonardojobim leonardojobim left a comment

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
Member

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
Contributor Author

Thanks for the reminder, rebased.

Copy link
Contributor

@LarryRuane LarryRuane left a comment

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
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
Member

CI fail is unrelated, see #20975

Copy link

@leonardojobim leonardojobim left a comment

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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 4, 2021
e4356f6 Testcase for wallet issue with orphaned rewards. (Daniel Kraft)

Pull request description:

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

ACKs for top commit:
  LarryRuane:
    ACK e4356f6
  leonardojobim:
    reACK bitcoin@e4356f6 .

Tree-SHA512: e9a2310ee1b3d52cfa302f431ed3d272bbc1b9195439ff318d9eb1006c0b28968dbe840e1600b6ff185e5d7ea57e4dcc837cef16051b5537445e10bc363b8c22
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