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

Add test for syncing blocks generated after invalidateblock. #17335

Closed

Conversation

TheBlueMatt
Copy link
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)

@TheBlueMatt
Copy link
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
Copy link
Contributor

DrahtBot commented Nov 1, 2019

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
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

utACK

# file COPYING or http://www.opensource.org/licenses/mit-license.php.

#
# Test invalidateblock
Copy link
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)

test/functional/p2p_post_invalidate_sync.py Outdated Show resolved Hide resolved
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

#
Copy link
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
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
Contributor

Choose a reason for hiding this comment

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

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

test/functional/p2p_post_invalidate_sync.py Outdated Show resolved Hide resolved
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)
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.

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

# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

#
Copy link
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
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
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
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
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
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.

Copy link
Member

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

@jnewbery
Copy link
Contributor

jnewbery commented Dec 15, 2019

Suggeted fixups: jnewbery@3357670 (in branch https://github.com/jnewbery/bitcoin/tree/pr17335.1)

@DrahtBot
Copy link
Contributor

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

@jnewbery
Copy link
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
Contributor

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