blockchain, fullblocktests, workmath, testhelper: add InvalidateBlock() method to BlockChain#2155
Merged
Roasbeef merged 10 commits intobtcsuite:masterfrom May 22, 2024
Merged
Conversation
Pull Request Test Coverage Report for Build 8891501246Details
💛 - Coveralls |
Roasbeef
requested changes
Apr 3, 2024
Crypt-iQ
reviewed
Apr 5, 2024
Collaborator
Crypt-iQ
left a comment
There was a problem hiding this comment.
looks good, think the tests could be cleaned up a little and have more comments
| }{ | ||
| { | ||
| name: "One branch, invalidate once", | ||
| chainGen: func() (*BlockChain, []*chainhash.Hash, func()) { |
Collaborator
There was a problem hiding this comment.
think this should be functions below rather than explicitly in full form here
Collaborator
Author
There was a problem hiding this comment.
Could you clarify what you mean here?
Collaborator
There was a problem hiding this comment.
I just mean moving the chainGen function into a function outside of the test so you just call chainGen:funcHere for readability. Just my preference, but it's non blocking
Member
|
Dependent PR merged, needs a rebase! |
6b3238e to
7e9b796
Compare
Some of the functions in difficulty.go are not dependent on any external functions and they are needed to introduce testing code for the invalidateblock and reconsiderblock methods that are to be added on in later commits. Having the workmath package let's us reuse the code and avoid dependency cycles. The existing functions that were exported already (HashToBig, CompactToBig, BigToCompact, CalcWork) are still kept in difficulty.go to avoid breaking external code that depends on those exported functions.
spendableOut and the functions related to it are is moved to package testhelper and are exported. This is done to make the code reusable without introducing an import cycle when the testing code for invalidateblock and reconsiderblock are added in follow up commits.
solveBlock is moved to testhelper and is exported. This is done so that the code can be reused without introducing import cycles. The testing code to be added in alter commits for invalidateblock and reconsider block will use SolveBlock.
The variables are moved to testhelper so that they can be reused in the blockchain package without introducing an import cycle. The testing code for invalidateblock and reconsiderblock that will be added in later commits will be using these variables.
uniqueOpReturnScript is moved to testhelper and is exported so that the code and be reused in package blockchain without introducing import cycles. The test code for invalidateblock and reconsiderblock that are gonna be added in later commits uses the functions.
standardCoinbaseScript is moved to testhelper and is exported. This allows test code in package blockchain to reuse the code without introducing an import cycle. This code is used in the testing code for invalidateblock and reconsiderblock that's added in the later commits.
createCoinbaseTx's code is refactored out and placed in testhelper package and is exported so that callers in package blockchain can reuse the code without introducing import cycles. The test code for invalidateblock and reconsiderblock that'll be added in later commits make use of this code.
createSpendTx is moved to testhelper so that the function can be used for callers in package blockchain without introducing import cycles. The test code for invalidateblock and reconsiderblock that are going to be added in later commits make use of this code.
The block generating functions here allow for a test to create mock blocks. This is useful for testing invalidateblock and reconsiderblock methods on blockchain that will be added in later commits.
7e9b796 to
2960f40
Compare
Crypt-iQ
reviewed
Apr 24, 2024
Collaborator
Crypt-iQ
left a comment
There was a problem hiding this comment.
changes look good to me, only thing is whether reconsiderblock should be implemented instead
2960f40 to
fa7e3d8
Compare
InvalidateBlock() invalidates a given block and marks all its descendents as invalid as well. The active chain tip changes if the invalidated block is part of the best chain.
fa7e3d8 to
635ae68
Compare
This was referenced Apr 30, 2024
asheswook
pushed a commit
to asheswook/btcd
that referenced
this pull request
Apr 2, 2026
…ate-block blockchain, fullblocktests, workmath, testhelper: add InvalidateBlock() method to BlockChain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #2153
All of the code except for the last two commits are for refactoring code. The vast majority is just moving code from
fullblockteststotesthelperso that the testing code forInvalidateBlock()can call the functions instead of having to copy over and duplicate functions.The
InvalidateBlock()method is operational and is tested but is not revealed through rpc in this PR.