-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Sync BIP30/BIP34 Handling With Bitcoin Core #2467
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
Open
starius
wants to merge
5
commits into
btcsuite:master
Choose a base branch
from
starius:bip30bypassfix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+497
−24
Conversation
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
Upcoming commits tweak the conditions under which the expensive BIP30 duplicate-coinbase check should run. To unit-test those changes, this commit moves the decision logic out of BlockChain.checkConnectBlock and into a dedicated helper, bip0030CheckNeeded. The behaviour is unchanged; the new helper is covered by tests in bip30_test.go.
Sync the behaviour with Bitcoin Core. See bitcoin/bitcoin#6931 In Core, the BIP30 flag is cleared only if the previous block's ancestor chain already contains the BIP34 activation block. For the activation block itself (height = BIP0034Height), pindex->pprev->GetAncestor(BIP34Height) returns nullptr, so the flag stays on and BIP30 is still enforced. In other words, Core enforces BIP30 for the activation block and skips it starting with the following block.
Mirror BIP34-aware BIP30 skip logic from Bitcoin Core. PR bitcoin/bitcoin#6931 in Bitcoin Core introduced an optimization that skips the expensive BIP30 duplicate coinbase check once BIP34 is active *and* the chain actually contains the recorded activation block. See the comment in that PR "//Only continue to enforce if we're below BIP34 activation height or the block hash at that height doesn't correspond." btcd used to drop the check purely based on height. On a fork that lacks the BIP34 activation block, that difference lets a duplicate coinbase slip through consensus. This patch ports the missing pieces: we store the activation hash in chain parameters and only disable BIP30 after we see that block on-chain.
Bitcoin Core PR bitcoin/bitcoin#12204 tightened BIP30 handling: re-enable the check once height 1,983,702 is reached. This change ports that logic into btcd and adds a regression test.
Set regtest buried heights to match Core: BIP34/65/66 at height 1 and make CSV/SegWit/Taproot always active. Added regtest coverage for header version floors, coinbase height enforcement, and deployment state to ensure we now reject the blocks Core rejects and accept the ones Core accepts. Updated package fullblocktests to generate BIP34-compliant blocks. Test helpers now set prev block height to 0 (not the default -1) so generated blocks start at height 1 and satisfy coinbase height rules.
Pull Request Test Coverage Report for Build 20497333340Details
💛 - Coveralls |
Contributor
Author
|
Moved regtest sync to a separate PR #2469 since it reduces coverage and is unrelated to other commits. |
7 tasks
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.
Change Description
This PR aligns btcd's consensus logic with Bitcoin Core when deciding when to run the expensive BIP30 duplicate-coinbase check. The changes mirror the behavior introduced in bitcoin/bitcoin#6931 and bitcoin/bitcoin#12204.
Summary
bip0030CheckNeeded).1_983_702, matching Core’s protection against pre-BIP34 coinbases that serialized future heights.Steps to Test
Pull Request Checklist
Testing
Code Style and Documentation
📝 Please see our Contribution Guidelines for further guidance.