Implement BIPs 141, 142, 143, 145 and 147 (Segregated Witness) - #656
Merged
Conversation
| PrevBlock: wire.ShaHash{}, // 0000000000000000000000000000000000000000000000000000000000000000 | ||
| MerkleRoot: segNetGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b | ||
| Timestamp: time.Unix(1452831101, 0), // 2016-01-15 04:11:41 +0000 UTC | ||
| Bits: 0x1e01ffff, // ?? [000007ffff000000000000000000000000000000000000000000000000000000] |
Member
There was a problem hiding this comment.
Also, the bits equate to 000001ffff000000000000000000000000000000000000000000000000000000 as opposed to the value in the comment.
Member
Author
There was a problem hiding this comment.
Fixed. The value in the comment was left over from segnet3.
Member
|
Thanks for all of the work on this. I know it was a lot of it. I also really appreciate the detail put into PR description regarding the changes. |
| @@ -0,0 +1,101 @@ | |||
| // Copyright (c) 2013-2016 The btcsuite developers | |||
This commit adds a new function to btcec: IsCompressedPubKey. This function returns true iff the passed serialized public key is encoded in compressed format.
This commit modifies the op-code execution for OP_IF and OP_NOTIF to enforce the additional “minimal if” constraints which require the top-stack item when the op codes are encountered to be either an empty vector, or exactly [0x01].
This commit adds verification of the post-segwit standardness requirement that all pubkeys involved in checks operations MUST be serialized as compressed public keys. A new ScriptFlag has been added to guard this behavior when executing scripts.
This commit implements the new “weight” metric introduced as part of the segwit soft-fork. Post-fork activation, rather than limiting the size of blocks and transactions based purely on serialized size, a new metric “weight” will instead be used as a way to more accurately reflect the costs of a tx/block on the system. With blocks constrained by weight, the maximum block-size increases to ~4MB.
This commit implements the new block validation rules as defined by BIP0141. The new rules include the constraints that if a block has transactions with witness data, then there MUST be a commitment within the conies transaction to the root of a new merkle tree which commits to the wtxid of all transactions. Additionally, rather than limiting the size of a block by size in bytes, blocks are now limited by their total weight unit. Similarly, a newly define “sig op cost” is now used to limit the signature validation cost of transactions found within blocks.
…itment This commit modifies the existing block selection logic to limit preferentially by weight instead of serialized block size, and also to adhere to the new sig-op cost limits which are weighted according to the witness discount.
This commit adds set of BIP0009 (Version Bits) deployment parameters for all networks detailing the activation parameters for the segwit soft-fork. Additionally, the BIP0009 integration test has been updated to test for the proper transitioning of version bits state for the segwit soft fork. Finally, the `getblockchaininfo` test has also been updated to properly display the state of segwit.
This commit updates the new segwit validation logic within block validation to be guarded by an initial check to the version bits state before conditionally enforcing the logic based off of the state.
This commit updates the block template generation logic to only include witness transactions once the soft-fork has activated and to also include the OP_RETURN witness commitment (with additional block weight accounting).
davecgh
approved these changes
Aug 14, 2017
davecgh
left a comment
Member
There was a problem hiding this comment.
I'll take care of the test failure in another PR since it's a false positive and this is ready otherwise.
Contributor
|
congrats on merging it. any eta for next btcd release? |
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.
This PR makes several modifications across
btcd, and many of the sub-packages in order to add compatibility for the upcoming Segregated Witness soft-fork. As the set of changes is rather expansive, this PR has been split up into several commits to in order to facilitate thorough code review of each change.This PR currently implements the changes dictated by the following BIPS:
As of the writing of this PR description, with this patch set
btcdis able to successful sync up, and correctly validate all blocks and witness commitments on Bitcoin'stestnet. This PR is still being extensively tested in order to ensure all new consensus critical decision related to transactions, blocks, and script validation are functioning properly.The changes across all packages are briefly summarized below:
blockchain:BuildMerkleTreeStorefunction is now able to calculate the witness merkle root. This allowed the creation of new functions to extract, and validate the witness commitment.txscript.ScriptVerifyWitnessis now used by default when validating transaction scripts. Once BIP9 support is in place, this will instead be gated by the appropriateversionbitsstage threshold.txValidatornow also uses the newHashCachein order to more efficiently validate inputs spending witness program outputs.chaincfg:segnet4have been added, along with the new address bytes for the new standard output types.database:peer:QueueMessageWithEncodinghas been added in order to allow callers to specify the encoding type to use when serializing messages. This was required in order to allow callers to selectively send witness data to peers.MaxProtocolVersionhas been increased to 70012 in order to signal to other peers we support segwit.txscript:p2wsh,p2wkh, and nested p2sh outputs have been added. In the processtxscript.Enginenow takes an optionalHashCacheas well as the input value of the output being spent.HashCachehas been introduced which caches partial sighashes to be re-used within the mempool, and block across all concurrent script validation goroutines.wire:SFNodeWitnessservice bit has been added along with new inventory types for segwit, and and increase in theMaxBlockPayloadsize.wire.Messageinterface in order to cleanly facilitate optinoally encoding or decoding the witness data. Finally, a new methods has been added towire.MsgTxto compute thewtxid, and ascertain if a transaction has any witness data.btcditself:syncPeer.wire.MsgGetDatasent will request with the new witness inv types by default. Additionally the new inv types are no longer ignored when received by other peers (TODO(roasbeef): thought they were only to be used within getdata?).Thanks to @T909 for the initial work which laid the base for much of this PR, along with coming up with the initial idea for the
HashCache.TODO
rpcserver, andbtcjsonto display the new transactions, and block related data. The display changes can be summarized as: display of witness data needs to be added to the transaction display, add a newhashfield to show thewtxid, addvsize(virtual size) to transaction display, showcostfor blocks.script_tests.jsontx_valid.json, andtx_invalid.jsontxscript.Engineto be returned when a new segwit specific error is encountered. At the moment, it returns some ad-hoc errors I created to facilitate debugging.txscript.Engine.cpuminer.go, and the GBT logic to account for the new cost metrics.btcd, guard new seg wit behavior with a checking of theversionbitsstate.HashCacheCloses #962.