Commit Graph

137 Commits

Author SHA1 Message Date
Hennadii Stepanov
f47dda2c58
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
* 2020: fa0074e2d8
* 2019: aaaaad6ac9
2021-12-30 19:36:57 +02:00
MarcoFalke
fa50d8b66e
doc: Remove TODO comment in tx_verify 2021-12-27 16:47:24 +01:00
MarcoFalke
fa44237d76
doc: Fix typos in endif header comments 2021-11-16 09:56:45 +01:00
John Newbery
92a3aeecf6 [validation] Add CChainState::ProcessTransaction()
This just calls through to AcceptToMemoryPool() internally, and is currently unused.

Also add a new transaction validation failure reason TX_NO_MEMPOOL to
indicate that there is no mempool.
2021-11-03 14:34:38 +00:00
Kennan Mell
1946af2c45
Add comment to COIN constant.
The COIN constant is critical in understanding Bitcoin's supply, but what it represents isn't clear from the name of the constant. Adding a comment clarifies the meaning of the constant for future readers.
2021-10-16 13:35:57 -07:00
fanquake
9d0379cea6
consensus: use <cstdint> over <stdint.h> in amount.h 2021-09-30 07:42:01 +08:00
fanquake
863e52fe63
consensus: make COIN & MAX_MONEY constexpr 2021-09-30 07:42:00 +08:00
fanquake
d09071da5b
[MOVEONLY] consensus: move amount.h into consensus
Move amount.h to consensus/amount.h.
Renames, adds missing and removes uneeded includes.
2021-09-30 07:41:57 +08:00
Anthony Towns
059171009b consensus/params: simplify ValidDeployment check to avoid gcc warning 2021-08-02 23:48:32 +10:00
MarcoFalke
9faa4b68db
Merge bitcoin/bitcoin#22232: refactor: Pass interpreter flags as uint32_t instead of signed int
fa621ededd refactor: Pass script verify flags as uint32_t (MarcoFalke)

Pull request description:

  The flags are cast to unsigned in the interpreter anyway, so avoid the confusion (and fuzz crashes) by just passing them as unsigned from the beginning.

  Also, the flags are often inverted bit-wise with the `~` operator, which also works on signed integers, but might cause confusion as the sign bit is flipped.

  Fixes #22233

ACKs for top commit:
  theStack:
    Concept and code review ACK fa621ededd
  kristapsk:
    ACK fa621ededd
  jonatack:
    ACK fa621ededd

Tree-SHA512: ea0720f32f823fa7f075309978672aa39773c6019d12b6c1c9d611fc1983a76115b7fe2a28d50814673bb6415c311ccc05b99d6e871575fb6900faf75ed17769
2021-07-20 15:36:23 +02:00
MarcoFalke
fa11fecf0d
doc: Move buried deployment doc to the enum that enumerates them
This is more visible than a comment hidden in an RPC helper function.
2021-07-01 20:04:07 +02:00
MarcoFalke
ddc6979b8b
Merge bitcoin/bitcoin#19438: Introduce deploymentstatus
e48826ad87 tests: remove ComputeBlockVersion shortcut from versionbits tests (Anthony Towns)
c5f36725e8 [refactor] Move ComputeBlockVersion into VersionBitsCache (Anthony Towns)
4a69b4dbe0 [move-only] Move ComputeBlockVersion from validation to versionbits (Anthony Towns)
0cfd6c6a8f [refactor] versionbits: make VersionBitsCache a full class (Anthony Towns)
8ee3e0bed5 [refactor] rpc/blockchain.cpp: SoftForkPushBack (Anthony Towns)
92f48f360d deploymentinfo: Add DeploymentName() (Anthony Towns)
ea68b3a572 [move-only] Rename versionbitsinfo to deploymentinfo (Anthony Towns)
c64b2c6a0f scripted-diff: rename versionbitscache (Anthony Towns)
de55304f6e [refactor] Add versionbits deployments to deploymentstatus.h (Anthony Towns)
2b0d291da8 [refactor] Add deploymentstatus.h (Anthony Towns)
eccd736f3d versionbits: Use dedicated lock instead of cs_main (Anthony Towns)
36a4ba0aaa versionbits: correct doxygen comments (Anthony Towns)

Pull request description:

  Introduces helper functions to make it easy to bury future deployments, along the lines of the suggestion from [11398](https://github.com/bitcoin/bitcoin/pull/11398#issuecomment-335599326) "I would prefer it if a buried deployment wouldn't require all code paths that check the BIP9 status to require changing".

  This provides three functions: `DeploymentEnabled()` which tests if a deployment can ever be active, `DeploymentActiveAt()` which checks if a deployment should be enforced in the given block, and `DeploymentActiveAfter()` which checks if a deployment should be enforced in the block following the given block, and overloads all three to work both with buried deployments and versionbits deployments.

  This adds a dedicated lock for the versionbits cache, which is acquired internally by the versionbits functions, rather than relying on `cs_main`. It also moves moves versionbitscache into deploymentstatus to avoid a circular dependency with validation.

ACKs for top commit:
  jnewbery:
    ACK e48826ad87
  gruve-p:
    ACK e48826ad87
  MarcoFalke:
    re-ACK e48826ad87 🥈

Tree-SHA512: c846ba64436d36f8180046ad551d8b0d9e20509b9bc185aa2639055fc28803dd8ec2d6771ab337e80da0b40009ad959590d5772f84a0bf6199b65190d4155bed
2021-07-01 19:15:09 +02:00
MarcoFalke
e1a13f12e1
Merge bitcoin/bitcoin#18096: doc: IsFinalTx comment about nSequence & OP_CLTV
f9e37f33ce doc: IsFinalTx comment about nSequence & OP_CLTV (Yuval Kogman)

Pull request description:

  It's somewhat surprising that a transaction's `nLockTime` field is ignored
  when all `nSequence` fields are final, so this change aims to clarify this
  behavior and cross reference relevant details of `OP_CHECKLOCKTIMEVERIFY`.

ACKs for top commit:
  MarcoFalke:
    ACK f9e37f33ce

Tree-SHA512: 88460dacbe4b8115fb1948715f09b21d4f34ba1da9e88d52f0b774a969f845e9eddc5940e7fee66eacdd3062dc40d6d44c3f282b0e5144411fd47eb2320b44f5
2021-06-30 09:43:21 +02:00
Anthony Towns
ea68b3a572 [move-only] Rename versionbitsinfo to deploymentinfo 2021-06-30 08:19:12 +10:00
Anthony Towns
de55304f6e [refactor] Add versionbits deployments to deploymentstatus.h
Adds support for versionbits deployments to DeploymentEnabled,
DeploymentActiveAfter and DeploymentActiveAt. Also moves versionbitscache
from validation to deploymentstatus.
2021-06-30 08:18:58 +10:00
Anthony Towns
2b0d291da8 [refactor] Add deploymentstatus.h
Provides DeploymentEnabled, DeploymentActiveAt, and DeploymentActiveAfter
helpers for checking the status of buried deployments. Can be overloaded
so the same syntax works for non-buried deployments, allowing future
soft forks to be changed from signalled to buried deployments without
having to touch the implementation code.

Replaces IsWitnessEnabled and IsScriptWitnessEnabled.
2021-06-29 17:11:12 +10:00
MarcoFalke
fa621ededd
refactor: Pass script verify flags as uint32_t
They are cast to unsigned anyway when calling VerifyScript,
bitcoinconsensus_verify_script*, or CountWitnessSigOps.
2021-06-14 08:02:45 +02:00
practicalswift
37371268d1 Mark CheckTxInputs [[nodiscard]] (out-param txfee only set if call is successful). Avoid UUM in fuzzing harness coins_view. 2021-05-25 21:09:05 +00:00
Yuval Kogman
f9e37f33ce doc: IsFinalTx comment about nSequence & OP_CLTV
It's somewhat surprising that a transaction's nLockTime field is ignored
when all nSequence fields are final, so this change aims to clarify this
behavior and cross reference relevant details of OP_CHECKLOCKTIMEVERIFY.
2021-04-27 11:52:13 +00:00
Anthony Towns
55ac5f568a versionbits: Add explicit NEVER_ACTIVE deployments
Previously we used deployments that would timeout prior to Bitcoin's
invention, which allowed the deployment to still be activated in unit
tests. This switches those deployments to be truly never active.
2021-04-12 11:14:49 +10:00
Anthony Towns
73d4a70639 versionbits: Add support for delayed activation 2021-04-12 11:14:49 +10:00
MarcoFalke
fa0074e2d8
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-
2020-12-31 09:45:41 +01:00
MarcoFalke
fa729cdb2c
doc: Move assumed-values doxygen comments to header 2020-10-15 11:28:13 +02:00
Pieter Wuille
d7ff237f29 Activate Taproot/Tapscript on regtest (BIP 341, BIP 342)
Define a versionbits-based activation for the new consensus rules on regtest.
No activation or activation mechanism is defined for testnet or mainnet.
2020-10-12 17:18:47 -07:00
Karl-Johan Alm
404682b7cd
add signet basic support (signet.cpp)
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2020-09-10 10:47:40 +09:00
Karl-Johan Alm
a2147d7dad
validation: move GetWitnessCommitmentIndex to consensus/validation 2020-09-10 10:47:40 +09:00
Suhas Daftuar
7989901c7e Add txids with non-standard inputs to reject filter
Our policy checks for non-standard inputs depend only on the non-witness
portion of a transaction: we look up the scriptPubKey of the input being
spent from our UTXO set (which is covered by the input txid), and the p2sh
checks only rely on the scriptSig portion of the input.

Consequently it's safe to add txids of transactions that fail these checks to
the reject filter, as the witness is irrelevant to the failure. This is helpful
for any situation where we might request the transaction again via txid (either
from txid-relay peers, or if we might fetch the transaction via txid due to
parent-fetching of orphans).

Further, in preparation for future witness versions being deployed on the
network, ensure that WITNESS_UNKNOWN transactions are rejected in
AreInputsStandard(), so that transactions spending v1 (or greater) witness
outputs will fall into this category of having their txid added to the reject
filter.
2020-08-04 13:29:40 -04:00
Wladimir J. van der Laan
ccef10261e
Merge #18044: Use wtxid for transaction relay
0a4f1422cd Further improve comments around recentRejects (Suhas Daftuar)
0e20cfedb7 Disconnect peers sending wtxidrelay message after VERACK (Suhas Daftuar)
cacd85209e test: Use wtxid relay generally in functional tests (Fabian Jahr)
8d8099e97a test: Add tests for wtxid tx relay in segwit test (Fabian Jahr)
9a5392fdf6 test: Update test framework p2p protocol version to 70016 (Fabian Jahr)
dd78d1d641 Rename AddInventoryKnown() to AddKnownTx() (Suhas Daftuar)
4eb515574e Make TX_WITNESS_STRIPPED its own rejection reason (Suhas Daftuar)
97141ca442 Delay getdata requests from peers using txid-based relay (Suhas Daftuar)
46d78d47de Add p2p message "wtxidrelay" (Suhas Daftuar)
2d282e0cba ignore non-wtxidrelay compliant invs (Anthony Towns)
ac88e2eb61 Add support for tx-relay via wtxid (Suhas Daftuar)
8e68fc246d Add wtxids to recentRejects instead of txids (Suhas Daftuar)
144c385820 Add wtxids of confirmed transactions to bloom filter (Suhas Daftuar)
85c78d54af Add wtxid-index to orphan map (Suhas Daftuar)
08b39955ec Add a wtxid-index to mapRelay (Suhas Daftuar)
60f0acda71 Just pass a hash to AddInventoryKnown (Suhas Daftuar)
c7eb6b4f1f Add wtxid to mempool unbroadcast tracking (Amiti Uttarwar)
2b4b90aa8f Add a wtxid-index to the mempool (Suhas Daftuar)

Pull request description:

  Using txids (a transaction's hash, without witness) for transaction relay is problematic, post-segwit -- if a peer gives us a segwit transaction that fails policy checks, it could be because the txid associated with the transaction is definitely unacceptable to our node (regardless of the witness), or it could be that the transaction was malleated and with a different witness, the txid could be accepted to our mempool.

  We have a bloom filter of recently rejected transactions, whose purpose is to help us avoid redownloading and revalidating transactions that fail to be accepted, but because of this potential for witness malleability to interfere with relay of valid transactions, we do not use the filter for segwit transactions.  This issue is discussed at some length in #8279.  The effect of this is that whenever a segwit transaction that fails policy checks is relayed, a node would download that transaction from every peer announcing it, because it has no way presently to cache failure.  Historically this hasn't been a big problem, but if/when policy for accepting segwit transactions were to change (eg taproot, or any other change), we could expect older nodes talking to newer nodes to be wasting bandwidth because of this.

  As discussed in that issue, switching to wtxid-based relay solves this problem -- by using an identifier for a transaction that commits to all the data in our relay protocol, we can be certain if a transaction that a peer is announcing is one that we've already tried to process, or if it's something new.  This PR introduces support for wtxid-based relay with peers that support it (and remains backwards compatible with peers that use txids for relay, of course).

  Apart from code correctness, one issue to be aware of is that by downloading from old and new peers alike, we should expect there to be some bandwidth wasted, because sometimes we might download the same transaction via txid-relay as well as wtxid-relay.  The last commit in this PR implements a heuristic I want to analyze, which is to just delay relay from txid-relay peers by 2 seconds, if we have at least 1 wtxid-based peer.  I've just started running a couple nodes with this heuristic so I can measure how well it works, but I'm open to other ideas for minimizing that issue.  In the long run, I think this will be essentially a non-issue, so I don't think it's too big a concern, we just need to bite the bullet and deal with it during upgrade.

  Finally, this proposal would need a simple BIP describing the changes, which I haven't yet drafted.  However, review and testing of this code in the interim would be welcome.

  To do items:
  - [x] Write BIP explaining the spec here (1 new p2p message for negotiating wtxid-based relay, along with a new INV type)
  - [ ] Measure and evaluate a heuristic for minimizing how often a node downloads the same transaction twice, when connected to old and new nodes.

ACKs for top commit:
  naumenkogs:
    utACK 0a4f1422cd
  laanwj:
    utACK 0a4f1422cd

Tree-SHA512: d8eb8f0688cf0cbe9507bf738e143edab1f595551fdfeddc2b6734686ea26e7f156b6bfde38bad8bbbe8bec1857c7223e1687f8f018de7463dde8ecaa8f450df
2020-07-22 20:58:55 +02:00
Suhas Daftuar
4eb515574e Make TX_WITNESS_STRIPPED its own rejection reason
Previously, TX_WITNESS_MUTATED could be returned during transaction validation
for either transactions that had a witness that was non-standard, or for
transactions that had no witness but were invalid due to segwit validation
rules.

However, for txid/wtxid-relay considerations, net_processing distinguishes the
witness stripped case separately, because it affects whether a wtxid should be
able to be added to the reject filter. It is safe to add the wtxid of a
witness-mutated transaction to the filter (as that wtxid shouldn't collide with
the txid, and hence it wouldn't interfere with transaction relay from
txid-relay peers), but it is not safe to add the wtxid (== txid) of a
witness-stripped transaction to the filter, because that would interfere with
relay of another transaction with the same txid (but different wtxid) when
relaying from txid-relay peers.

Also updates the comment explaining this logic, and explaining that we can get
rid of this complexity once there's a sufficient deployment of wtxid-relaying
peers on the network.
2020-07-19 02:10:42 -04:00
MarcoFalke
fa492895b5
refactor: Switch ValidationState mode to C++11 enum class 2020-07-15 14:52:16 +02:00
Sebastian Falbesoner
b00266fe0c refactor: replace pointers by references within tx_verify.{h,cpp}
affects "prevHeights" parameter of the functions
- CalculateSequenceLocks()
- SequenceLocks()
2020-05-26 16:05:51 +02:00
MarcoFalke
fa488f131f
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-
2020-04-16 13:33:09 -04:00
4d55397500
5b59a19731
Update merkle.cpp
Change comment from `The reason is that if the number of hashes in the list at a given time
is odd`, to ` The reason is that if the number of hashes in the list at a given level
       is odd` (to be a bit more precise)
2020-03-18 10:34:53 -07:00
Jeffrey Czyz
10efc0487c Templatize ValidationState instead of subclassing
This removes boilerplate code in the subclasses which otherwise only
differ by the result type.
2020-02-27 17:59:21 -08:00
Jeffrey Czyz
10e85d4adc Remove ValidationState's constructor 2020-02-27 17:59:21 -08:00
Jeffrey Czyz
0aed17ef28 Refactor FormatStateMessage into ValidationState 2020-02-27 17:59:07 -08:00
MarcoFalke
aaaaad6ac9
scripted-diff: Bump copyright of files changed in 2019
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-
2019-12-30 10:42:20 +13:00
practicalswift
73b96c94cb net: Fix uninitialized read in ProcessMessage(...) 2019-11-27 21:27:56 +00:00
John Newbery
3004d5a12d [validation] Remove fMissingInputs from AcceptToMemoryPool()
Handle this failure in the same way as all other failures: call Invalid()
with the reasons for the failure.
2019-10-29 15:46:45 -04:00
John Newbery
7204c6434b [validation] Remove useless ret parameter from Invalid()
ValidationState::Invalid() takes a parameter `ret` which is returned to
the caller. All call sites set this to false. Remove the `ret` parameter
and just return false always.
2019-10-29 15:46:45 -04:00
John Newbery
067981e492 [validation] Tidy Up ValidationResult class
Minor style fixups and comment updates.

This is purely a style change. There is no change in behavior.
2019-10-29 15:46:45 -04:00
John Newbery
a27a2957ed [validation] Add CValidationState subclasses
Split CValidationState into TxValidationState and BlockValidationState
to store validation results for transactions and blocks respectively.
2019-10-29 15:46:45 -04:00
MarcoFalke
fa92813407
consensus: Explain why fCheckDuplicateInputs can not be skipped and remove it 2019-10-24 14:58:34 -04:00
Wladimir J. van der Laan
b688b859db
Merge #17004: validation: Remove REJECT code from CValidationState
9075d13153 [docs] Add release notes for removal of REJECT reasons (John Newbery)
04a2f326ec [validation] Fix REJECT message comments (John Newbery)
e9d5a59e34 [validation] Remove REJECT code from CValidationState (John Newbery)
0053e16714 [logging] Don't log REJECT code when transaction is rejected (John Newbery)
a1a07cfe99 [validation] Fix peer punishment for bad blocks (John Newbery)

Pull request description:

  We no longer send BIP 61 REJECT messages, so there's no need to set
  a REJECT code in the CValidationState object.

  Note that there is a minor bug fix in p2p behaviour here. Because the
  call to `MaybePunishNode()` in `PeerLogicValidation::BlockChecked()` only
  previously happened if the REJECT code was > 0 and < `REJECT_INTERNAL`,
  then there are cases were `MaybePunishNode()` can get called where it
  wasn't previously:

  - when `AcceptBlockHeader()` fails with `CACHED_INVALID`.
  - when `AcceptBlockHeader()` fails with `BLOCK_MISSING_PREV`.

  Note that `BlockChecked()` cannot fail with an 'internal' reject code. The
  only internal reject code was `REJECT_HIGHFEE`, which was only set in
  ATMP.

  This reverts a minor bug introduced in 5d08c9c579.

ACKs for top commit:
  ariard:
    ACK 9075d13, changes since last reviewed are splitting them in separate commits to ease understanding and fix nits
  fjahr:
    ACK 9075d13153, confirmed diff to last review was fixing nits in docs/comments.
  ryanofsky:
    Code review ACK 9075d13153. Only changes since last review are splitting the main commit and updating comments

Tree-SHA512: 58e8a1a4d4e6f156da5d29fb6ad6a62fc9c594bbfc6432b3252e962d0e9e10149bf3035185dc5320c46c09f3e49662bc2973ec759679c0f3412232087cb8a3a7
2019-10-24 10:49:45 +02:00
practicalswift
084e17cebd Remove unused includes 2019-10-15 22:56:43 +00:00
John Newbery
e9d5a59e34 [validation] Remove REJECT code from CValidationState
We no longer send BIP 61 REJECT messages, so there's no need to set
a REJECT code in the CValidationState object.
2019-10-10 13:31:53 -04:00
MarcoFalke
6b2210f101
Merge #16713: Ignore old versionbit activations to avoid 'unknown softforks' warning
fdb3e8f8b2 Ignore old versionbit activations (Anthony Towns)

Pull request description:

  PR 16060 removed the CSV and Segwit BIP9 softfork definitions and hard-coded ('buried') the activation heights. The versionbits code will warn users if an undefined softfork has been signalled in block header versions, and removing the CSV/Segwit definitions caused those warnings to be triggered.

  Change the BIP 9 warning code to only check for unknown softforks after the segwit activation height.

ACKs for top commit:
  MarcoFalke:
    ACK fdb3e8f8b2
  ajtowns:
    ACK fdb3e8f8b2 for what it's worth
  achow101:
    ACK fdb3e8f8b2
  Sjors:
    ACK fdb3e8f8b2. It makes the bit 0 warning go away in mainnet and testnet QT when a new block arrives. I think the code is clear enough.
  jonatack:
    ACK fdb3e8f8b2

Tree-SHA512: e6fd34e8902f8c7affb28e8951803e47d542710d5f1229000746656a37ee59d754439fc33e36b7eef87544262e5aac374645db91b74cb507e73514003ca7a67f
2019-09-27 15:25:53 -04:00
Wladimir J. van der Laan
feb162d500
Merge #14696: qa: Add explicit references to related CVE's in p2p_invalid_block test.
0c62e3aa73 New regression testing for CVE-2018-17144, CVE-2012-2459, and CVE-2010-5137. (lucash-dev)
38bfca6bb2 Added comments referencing multiple CVEs in tests and production code. (lucash-dev)

Pull request description:

  This functional test includes two scenarios that test for regressions of vulnerabilities, but they are only briefly described. There are freely available documents explaining in detail the issues, but without explicit mentions, the developer trying to maintain the code needs an additional step of digging in commit history and PR conversations to figure it out.
  Added comments to explicitly mention  CVE-2018-17144 and CVE-2012-2459, for more complete documentation.
  This improves developer experience by making understanding the tests easier.

ACKs for top commit:
  laanwj:
    ACK 0c62e3aa73, checked the CVE numbers, thanks for adding documentation

Tree-SHA512: 3ee05351745193b8b959e4a25d50f25a693b2d24b0732ed53cf7d5882df40b5dd0f1877bd5c69cffb921d4a7acf9deb3cc1160b96dc730d9b5984151ad06b7c9
2019-09-18 16:00:54 +02:00
Anthony Towns
fdb3e8f8b2 Ignore old versionbit activations
Adds a hardcoded height to the consensus chain parameters for
ignoring versionbit activations prior to a fixed height.
2019-09-05 13:51:01 -04:00
John Newbery
0328dcdcfc [Consensus] Bury segwit deployment
Hardcode segwit deployment height to 481824 for mainnet.
2019-08-14 15:52:52 -04:00