Skip to content

Add test for syncing blocks generated after invalidateblock. - #17335

Closed
TheBlueMatt wants to merge 1 commit into
bitcoin:masterfrom
TheBlueMatt:2019-10-invalid-mine-test
Closed

TheBlueMatt wants to merge 1 commit into
bitcoin:masterfrom
TheBlueMatt:2019-10-invalid-mine-test

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Contributor

Suhas wrote this test to demonstrate a bug in invalidateblock back
in 2015, and at some point between then and now it started passing,
so best to just merge it so we don't regress.

Closes #5806 (the original issue in which this test was written)

@DrahtBot DrahtBot added the Tests label Oct 31, 2019
@TheBlueMatt
TheBlueMatt force-pushed the 2019-10-invalid-mine-test branch from 479dda1 to 1b0a68c Compare October 31, 2019 23:35
@TheBlueMatt

Copy link
Copy Markdown
Contributor Author

Can we turn off these lints? Who cares at all if we have some unused imports in some python tests? This seems entirely useless.

@TheBlueMatt
TheBlueMatt force-pushed the 2019-10-invalid-mine-test branch 3 times, most recently from 7b3518f to 50190df Compare November 1, 2019 01:35
@DrahtBot

DrahtBot commented Nov 1, 2019 •

Copy link
Copy Markdown
Contributor

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.

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

utACK

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.

for p2p, since we already have RPC tests for it(I had to look)

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.

Prefer to use file docstrings over code comments for the top-level comment

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.

I don't know what a docstrng is.

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.

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.

Take a look at the other tests, particularly https://github.com/bitcoin/bitcoin/blob/master/test/functional/example_test.py#L5 and https://github.com/bitcoin/bitcoin/blob/master/test/functional/README.md#style-guidelines. Documenting what the test is supposed to be testing and why is a courtesy to any other developer who tries to understand this in future. "Test invalidateblock" doesn't explain what this test is for.

Suhas wrote this test to demonstrate a bug in invalidateblock back
in 2015, and at some point between then and now it started passing,
so best to just merge it so we don't regress.

Closes bitcoin#5806 (the original issue in which this test was written)
@TheBlueMatt
TheBlueMatt force-pushed the 2019-10-invalid-mine-test branch from 50190df to df117c8 Compare November 4, 2019 17:07

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

Getting better. You'll be a python developer soon!

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.

Take a look at the other tests, particularly https://github.com/bitcoin/bitcoin/blob/master/test/functional/example_test.py#L5 and https://github.com/bitcoin/bitcoin/blob/master/test/functional/README.md#style-guidelines. Documenting what the test is supposed to be testing and why is a courtesy to any other developer who tries to understand this in future. "Test invalidateblock" doesn't explain what this test is for.

raise AssertionError("Failed to invalidate initial blocks")

# The test framework uses a static per-node address which will generate
# a deterministic block if we have no wallet.

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.

'if we have no wallet' is inaccurate. All calls to generate in the functional test framework will generate blocks to a hardcoded address.

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.

I think it's slightly clearer if all blocks are generated on node0 and sync'ed to node1. It makes it more obvious to someone reading the test that this is testing node1 being able to resync to an less-work chain if it previously invalidated a different chain.

def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True
self.extra_args = [[],[]]

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.

This isn't required if you're not adding any extra args.

# than the one we previously used, making this block unique.
self.nodes[0].generate(17)

print("All blocks generated, trying to sync")

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.

Use self.log.info() rather than print

class InvalidateBlockTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True

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.

If you remove this line, you can also remove the following lines from run_test:

        self.nodes[0].generate(1) # Leave IBD
        self.sync_all()

The test will run more quickly and it'll be clearer to readers what the test is for.

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

Concept ACK.

@jnewbery

jnewbery commented Dec 15, 2019 •

Copy link
Copy Markdown
Contributor

@DrahtBot

Copy link
Copy Markdown
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@jnewbery

Copy link
Copy Markdown
Contributor

This has unaddressed review comments from > 6 months ago. Closing and marking 'up for grabs'.

@TheBlueMatt - if you want to pick this up again, let me know and I'll reopen.

@jonatack

Copy link
Copy Markdown
Member

Picked this up in #19397.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block download can stall after call to InvalidateBlock()

7 participants