Commit graph

13585 commits

Author SHA1 Message Date
MeshCollider
7263424458
Merge #16001: Give WalletModel::UnlockContext move semantics
0b09a57ae Give WalletModel::UnlockContext move semantics (Pieter Wuille)

Pull request description:

  WalletModel::UnlockContext seems to implement "move upon copy" semantics; with C++11 this can be done more safely using move semantics (making attempts to actually copy fail instead).

  Not a big deal if this isn't worth review time.

ACKs for commit 0b09a5:
  Empact:
    utACK 0b09a57aec
  jonasschnelli:
    utACK 0b09a57aec
  jb55:
    utACK 0b09a57aec

Tree-SHA512: f827856586afd03666c2d9f50320776afb3dd511ac1bcd293b330f015acd1588551b163dccc97b1351301e3295f4c74d90e5754bcee89faeadf6437d7db165c8
2019-05-20 00:13:53 +12:00
Jonas Schnelli
7110d455eb
Merge #12980: Allow quicker shutdowns during LoadBlockIndex()
af5fa82b6 Allow quicker shutdowns during LoadBlockIndex() (Jonas Schnelli)

Pull request description:

ACKs for commit af5fa8:
  promag:
    utACK af5fa82b67.
  practicalswift:
    utACK af5fa82b67

Tree-SHA512: 1c64dcc5d8a9d3411553257cd5a598dcd29be981660e5bca9283c1d957dc56798abcf41d9969cd573088137597a23e48e62a8c476c463d3f176b86a10048f47b
2019-05-19 10:43:32 +02:00
Hennadii Stepanov
78f9b5160f
Do not show list for the only recipient. 2019-05-18 22:22:05 +03:00
Andrew Chow
ccb26cf347 Batch writes for importmulti
When writing all of the imported data to the wallet, use a common
WalletBatch object so that batch writes are done and the writes
finish more quickly.

AddKeypoolPubkey is no longer needed so it is also removed
2019-05-18 12:59:17 -04:00
Andrew Chow
d6576e349e Have WalletBatch automatically flush every 1000 updates
Since it now automatically flushes, we don't need to have
UpgradeKeyMetadata count and flush separately
2019-05-18 12:58:50 -04:00
Andrew Chow
366fe0be0b Add AddWatchOnlyWithDB, AddKeyOriginWithDB, AddCScriptWithDB functions
AddWatchOnlyWithDB, AddKeyOriginWithDB, and AddCScriptWithDB add their
respective data to the wallet using the provided WalletBatch instead
of creating a new WalletBatch object every time. This allows for batching
writes to the database.
2019-05-18 12:57:58 -04:00
Jonas Schnelli
387eb5b343
Merge #15957: Show "No wallets available" in open menu instead of nothing
c3ef63a52 Show loaded wallets as disabled in open menu instead of nothing (MeshCollider)

Pull request description:

  Fixes the confusing behavior reported in #15952

  ![image](https://user-images.githubusercontent.com/3211283/57224284-0e8e7f80-705d-11e9-9554-2450cc3dbb8e.png)

ACKs for commit c3ef63:
  jonasschnelli:
    Tested ACK c3ef63a52f
  kristapsk:
    tACK c3ef63a52f

Tree-SHA512: fc2b94936ca32b89e8146c65e3629785883d78660afc8838818df652a4df9185ddca6b36ebf140a7159ab42b0fa5aa72867558d4572a009be06f0831fa813d1f
2019-05-18 13:02:29 +02:00
Wladimir J. van der Laan
82b64a5a81
Merge #15224: Add RNG strengthening (10ms once every minute)
3cb9ce85d0 Document strenghtening (Pieter Wuille)
1d207bc46f Add hash strengthening to the RNG (Pieter Wuille)

Pull request description:

  This patch improves the built-in RNG using hash strengthening.

  At startup, and once every minute, 32 bytes of entropy are produced from the RNG, repeatedly hashed using SHA512 for 10ms, and then fed back into the RNG, together with high-precision timestamps obtained every 1000 iterations.

ACKs for commit 3cb9ce:
  pstratem:
    utACK 3cb9ce85d0

Tree-SHA512: 4fb6f61639b392697beb81c5f0903f79f10dd1087bed7f34de2abb5c22704a671e37b2d828ed141492491863efb1e7d1fa04408a1d32c9de2f2cc8ac406bbe57
2019-05-18 10:01:54 +02:00
practicalswift
9f85e9cb3d scripted-diff: Rename LockAnnotation to LockAssertion
-BEGIN VERIFY SCRIPT-
git grep -l LockAnnotation | xargs sed -i 's/LockAnnotation/LockAssertion/'
-END VERIFY SCRIPT-
2019-05-17 13:29:04 +02:00
practicalswift
de9b5dbca3 Make sure the compile-time locking promises given via LockAnnotation:s hold also in practice at runtime (ifdef DEBUG_LOCKORDER) 2019-05-17 13:29:04 +02:00
practicalswift
3a809446b3 Move LockAnnotation to make it reflect the truth 2019-05-17 13:29:04 +02:00
practicalswift
cc2588579c Move LockAnnotation from threadsafety.h (imported code) to sync.h (our code) 2019-05-17 13:29:04 +02:00
MarcoFalke
a822a0e4f6
Merge #15999: init: Remove dead code in LoadChainTip
fa86c8aec6 init: Remove dead code in LoadChainTip (MarcoFalke)

Pull request description:

  `LoadChainTip` sets `::ChainActive()` based on `pcoinsTip`'s best block. `LoadChainTip` is never called when that block is null, so we can remove all code from within that method that is only executed when that block is null.

  Fixes #15967  Inconsistent locking behavior in LoadChainTip

ACKs for commit fa86c8:
  promag:
    utACK fa86c8aec6.
  practicalswift:
    utACK fa86c8aec6
  Empact:
    utACK fa86c8aec6
  laanwj:
    utACK fa86c8aec6
  ryanofsky:
    utACK fa86c8aec6. LoadChainTip isn't called currently when pcoinsTip best block is null due to this line:
  jamesob:
    utACK fa86c8aec6

Tree-SHA512: 8961c0e579800a52038ac5655478468852faac055299b64d6cfdf0c213d3bf09669c4889467d09d93457f6c8b073967bb0475a137f77ddd3a3a3c03ad90001c4
2019-05-17 07:22:52 -04:00
MarcoFalke
f3d27d126b
Merge #16033: Hold cs_main when reading chainActive via getTipLocator(). Remove assumeLocked().
9402ef0739 Remove temporary method assumeLocked(). Remove LockingStateImpl. Remove redundant cs_main locks. (practicalswift)
593a8e8a2c wallet: Use chain.lock() instead of temporary chain.assumeLocked() (practicalswift)

Pull request description:

  Fixes #16028.

  Problem description:

  `LockAnnotation lock(::cs_main)` is a guarantee to the compiler thread analysis that `::cs_main` is locked (when it couldn't be determined otherwise).

  Despite being annotated with the locking guarantee ...

  65526fc866/src/interfaces/chain.cpp (L134-L138)

  ... `getTipLocator()` reads `chainActive` (via `::ChainActive()`) without holding `cs_main`.

  This can be verified by adding the following `AssertLockHeld(cs_main)`:

  ```
  $ git diff
  diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp
  index 59623284d..9fc693a0f 100644
  --- a/src/interfaces/chain.cpp
  +++ b/src/interfaces/chain.cpp
  @@ -134,6 +134,7 @@ class LockImpl : public Chain::Lock
       CBlockLocator getTipLocator() override
       {
           LockAnnotation lock(::cs_main);
  +        AssertLockHeld(::cs_main);
           return ::ChainActive().GetLocator();
       }
       Optional<int> findLocatorFork(const CBlockLocator& locator) override
  $ make check
  ../build-aux/test-driver: line 107: 12881 Aborted                 "$@" > $log_file 2>&1
  FAIL: qt/test/test_bitcoin-qt
  ```

ACKs for commit 9402ef:
  MarcoFalke:
    utACK 9402ef0739
  ryanofsky:
    utACK 9402ef0739. Changes are consolidating commits and removing redundant lock2 cs_main calls

Tree-SHA512: 0a030bf0c07eb53194ecc246f973ef389dd42a0979f51932bf94bdf7e90c52473ae03be49718ee1629582b05dd8e0dc020b5a210318c93378ea4ace90c0f9f72
2019-05-17 07:17:41 -04:00
practicalswift
9402ef0739 Remove temporary method assumeLocked(). Remove LockingStateImpl. Remove redundant cs_main locks. 2019-05-16 21:43:22 +02:00
practicalswift
593a8e8a2c wallet: Use chain.lock() instead of temporary chain.assumeLocked() 2019-05-16 21:42:34 +02:00
Wladimir J. van der Laan
8f2f17f79a
Merge #15970: Utils and libraries: fix static_assert for macro HAVE_THREAD_LOCAL
41ab2a8924 fix static_assert for macro HAVE_THREAD_LOCAL (orient)

Pull request description:

  Utils and libraries: fix static_assert for macro HAVE_THREAD_LOCAL if define DEBUG_LOCKCONTENTION

ACKs for commit 41ab2a:
  laanwj:
    utACK 41ab2a8924

Tree-SHA512: 6c1d20375a70cbdef1140c544f443106d6bf6c34b1da2ddc66739f2b662a0d6b800288f48bf451a3d5937bac7e40b8ecda3a4effcc978d0093fc497410447ea7
2019-05-16 20:19:10 +02:00
Wladimir J. van der Laan
376638afcf
Merge #14047: Add HKDF_HMAC256_L32 and method to negate a private key
8794a4b3ae QA: add test for HKDF HMAC_SHA256 L32 (Jonas Schnelli)
551d489416 Add HKDF HMAC_SHA256 L=32 implementations (Jonas Schnelli)
3b64f852e4 QA: add test for CKey::Negate() (Jonas Schnelli)
463921bb64 CKey: add method to negate the key (Jonas Schnelli)

Pull request description:

  This adds a limited implementation of `HKDF` (defined by rfc5869) that supports only HMAC-SHA256  and length output of 32 bytes (will be required for v2 transport protocol).

  This PR also includes a method to negate a private key which is useful to enforce public keys starting with 0x02 (or 0x03) (a requirement for the v2 transport protocol). The new `CKey::Negate()` method is pretty much a wrapper around `secp256k1_ec_privkey_negate()`.

  Including tests.

  This is a subset of #14032 and a pre-requirement for the v2 transport protocol.

ACKs for commit 8794a4:

Tree-SHA512: 5341929dfa29f5da766ec3612784baec6a3ad69972f08b5a985a8aafdae4dae36f104a2b888d1f5d1f33561456bd111f960d7e32c2cc4fd18e48358468f26c1a
2019-05-16 19:24:52 +02:00
Wladimir J. van der Laan
df7addc4c6
Merge #15990: Add tests and documentation for blocksonly
fa8ced32a6 doc: Mention blocksonly in reduce-traffic.md, unhide option (MarcoFalke)
fa320de79f test: Add test for p2p_blocksonly (MarcoFalke)
fa3872e7b4 test: Format predicate source as multiline on error (MarcoFalke)
fa1dce7329 net: Rename ::fRelayTxes to ::g_relay_txes (MarcoFalke)

Pull request description:

  This is de-facto no longer hidden

ACKs for commit fa8ced:
  jamesob:
    utACK fa8ced32a6

Tree-SHA512: 474fbdee6cbd035ed9068a066b6056c1f909ec7520be0417820fcd1672ab3069b53f55c5147968978d9258fd3a3933fe1a9ef8e4f6e14fb6ebbd79701a0a1245
2019-05-16 19:05:24 +02:00
Wladimir J. van der Laan
1c719f78d3
Merge #15006: Add option to create an encrypted wallet
662d1171d9 Add option to create an encrypted wallet (Andrew Chow)

Pull request description:

  This PR adds a new `passphrase` argument to `createwallet` which will create a wallet that is encrypted with that passphrase.

  This is built on #15226 because it needs to first create an empty wallet, then encrypt the empty wallet and generate new keys that have only been stored in an encrypted state.

ACKs for commit 662d11:
  laanwj:
    utACK 662d1171d9
  jnewbery:
    Looks great. utACK 662d1171d9

Tree-SHA512: a53fc9a0f341eaec1614eb69abcf2d48eb4394bc89041ab69bfc05a63436ed37c65ad586c07fd37dc258ac7c7d5e4f7f93b4191407f5824bbf063b4c50894c4a
2019-05-16 18:20:14 +02:00
MarcoFalke
d5931f3676
Merge #15870: wallet: Only fail rescan when blocks have actually been pruned
fa7e311e16 [doc] rpcwallet: Only fail rescan when blocks have been pruned (MarcoFalke)
aaaa57c2aa scripted-diff: Bump copyright headers in wallet (MarcoFalke)
faf3729242 wallet: Only fail rescan when blocks have actually been pruned (MarcoFalke)

Pull request description:

  This brings the behaviour of the import* calls closer to importmulti. After this change, the difference between importmulti and the other import* calls is

  * that in importmulti you can "opt-out" of scanning early blocks by setting a later timestamp.
  * that in importmulti the wallet will successfully import the data, but fail to rescan. Whereas in the other calls, the wallet will abort before importing the data.

ACKs for commit fa7e31:
  promag:
    utACK fa7e311e16.
  jnewbery:
    utACK fa7e311e16

Tree-SHA512: a57d52ffea94b64e0eb9b5d3a7a63031325833908297dd14eb0c5251ffea3b2113b131003f1db4e9599e014369165a57f107a7150bb65e4c791e5fe742f33cb8
2019-05-16 11:18:27 -04:00
Wladimir J. van der Laan
fd61b9fc22
Merge #15950: Do not construct out-of-bound pointers in SHA2 code
c01c065b9d Do not construct out-of-bound pointers in SHA512/SHA1/RIPEMD160 code (Pieter Wuille)

Pull request description:

  This looks like an issue in the current SHA256/512 code, where a pointer outside of the area pointed to may be constructed (this is UB in theory, though in practice every supported platform treats pointers as integers).

  I discovered this while investigating #14580. Sadly, it does not fix it.

ACKs for commit c01c06:
  practicalswift:
    utACK c01c065b9d

Tree-SHA512: 47660e00f164f38c36a1ab46e52dd91cd33cfda6a6048d67541c2f8e73c050d4d9d81b5c149bfad281212d52f204f57bebf5b19879dc7a6a5f48aa823fbc2c02
2019-05-16 16:23:38 +02:00
James O'Beirne
403e677c9e refactoring: IsInitialBlockDownload -> CChainState
We introduce CChainState.m_cached_finished_ibd because the static state it
replaces would've been shared across all CChainState instances.
2019-05-16 09:06:54 -04:00
James O'Beirne
3ccbc376dd refactoring: FlushStateToDisk -> CChainState
Also renames global methods for clarity:

- ::FlushStateToDisk() -> CChainState::ForceFlushStateToDisk()
  - This performs an unconditional flush.

- ::PruneAndFlush() -> CChainState::PruneAndFlush()
2019-05-16 09:06:54 -04:00
James O'Beirne
4d6688603b refactoring: introduce ChainstateActive()
To be used once we move global functions (e.g. FlushStateToDisk()) into
CChainState methods.

Thanks to Marco Falke for suggestions
2019-05-16 09:06:54 -04:00
James O'Beirne
d7c97edeea move-only: make the CChainState interface public
along with DisconnectResult, and CBlockIndexWorkComparator.

The CChainState interface needs to be known to the rest of the system because
many global functions will move to CChainState methods. This is to allow
other parts of the system to be parameterized per chainstate instance
instead of assuming a single global.
2019-05-16 09:05:07 -04:00
Wladimir J. van der Laan
47ec8318a6
Merge #15968: Fix portability issue with pthreads
1b05dff080 Fix portability issue with pthreads (grim-trigger)

Pull request description:

  This change resolves the following issue:
  https://github.com/bitcoin/bitcoin/issues/15951

  Only tested on OpenBSD 6.5/amd64

ACKs for commit 1b05df:
  fanquake:
    tACK 1b05dff. Tested on OpenBSD6.4 (`vagrant`).
  laanwj:
    utACK 1b05dff080

Tree-SHA512: af48581af32820d5adc9ae5abb44f8f1b592c323f86fe2484108b81629389f6ef347598f9a087aa6476ac553e59828cd7927bb4ab11dc70e7c9a944a92fc54ae
2019-05-16 14:19:06 +02:00
Carl Dong
8be3f30633 netaddress: Update CNetAddr for ORCHIDv2
The original ORCHID prefix was deprecated as of 2014-03, the new
ORCHIDv2 prefix was allocated by RFC7343 as of 2014-07. We did not
consider the original ORCHID prefix routable, and I don't see any reason
to consider the new one to be either.
2019-05-15 14:21:48 -04:00
MarcoFalke
fa7e311e16
[doc] rpcwallet: Only fail rescan when blocks have been pruned 2019-05-15 14:09:28 -04:00
MarcoFalke
2d16fb7a2b
Merge #14984: rpc: Speedup getrawmempool when verbose=true
2d5cf4c41d rpc: Speedup getrawmempool when verbose=true (João Barbosa)

Pull request description:

  Instead of calling `pushKV(hash, info)`, which incurs in duplicate key checks, call `__pushKV` which (currently) doesn't.

  Improves RPC `getrawmempool` and REST `/rest/mempool/contents.json`.

  Fixes #14765.

ACKs for commit 2d5cf4:

Tree-SHA512: c3e91371bb41f39e79dcef820815e1dc27fb689ca3c4bf3a00467d2215b3baecd44d9792f7a481577a5b7ae1fc6cbaa07b1cd62123b845082eba65b35c2b3ca5
2019-05-15 11:32:29 -04:00
practicalswift
1609809fb2 validation: Hold cs_main when reading chainActive in RewindBlockIndex 2019-05-15 14:58:15 +02:00
Chris Capobianco
e23809a05b [rpc] deriveaddresses: Correct descriptor checksum in RPCExamples 2019-05-14 12:46:24 -04:00
MarcoFalke
65526fc866
Merge #15777: [docs] Add doxygen comments for keypool classes
f1a77b0c51 [docs] Add doxygen comment for CReserveKey (John Newbery)
37796b2dd4 [docs] Add doxygen comment for CKeyPool (John Newbery)
ef2d515af3 [wallet] move-only: move CReserveKey to be next to CKeyPool (John Newbery)

Pull request description:

  Docs/move-only

  Adds doxygen comments for the CKeyPool and CReserveKey objects. The way these work is pretty confusing and it's easy to overlook details (eg https://github.com/bitcoin/bitcoin/pull/15557#discussion_r271956393).

  These are on the verbose side, but I think too much commenting is better than not enough. Happy to take feedback on what's an appropriate level.

ACKs for commit f1a77b:
  jonatack:
    Thanks, John. Re-ACK f1a77b0c51, doc-only changes with respect to previous review.
  jb55:
    ACK f1a77b0c51

Tree-SHA512: 8bc97c7029cd2e8d9bfd2d2144eeff73474c71eda5a9d10817e1578ca0b70da677252037d83143faaff1808e2193408a21a8a89d36049eac77fd313990f0b67b
2019-05-14 09:16:33 -04:00
MarcoFalke
6f4ba6492a
Merge #15988: Add test for ArgsManager::GetChainName
f6bb11fd37 Add test for ArgsManager::GetChainName (Russell Yanofsky)
4b331159df Add unit test NextString, ForEachNoDup functions (Russell Yanofsky)
05bfee3451 util_SettingsMerge test cleanup (Russell Yanofsky)

Pull request description:

  There was some test coverage previously, but it was limited and didn't test conflicting and negated arguments.

ACKs for commit f6bb11:
  MarcoFalke:
    re-utACK f6bb11fd37

Tree-SHA512: d03596614dc48584c7a9440117b107c6abb23fd4c7fa15fb4015351ec3de08b2656bc956ce05310663675672343d7a6aff35421657f29172080c7005045680b0
2019-05-14 08:53:37 -04:00
MarcoFalke
fa2b52af32
Disallow extended encoding for non-witness transactions (take 3) 2019-05-14 08:33:55 -04:00
MarcoFalke
40c66bb3d1
Merge #15855: [refactor] interfaces: Add missing LockAnnotation for cs_main
fa3c651143 [refactor] interfaces: Add missing LockAnnotation for cs_main (MarcoFalke)

Pull request description:

  This adds missing `LockAnnotation lock(::cs_main);` to `src/interfaces/chain.cpp` (as well as tests and  benchmarks)

ACKs for commit fa3c65:
  practicalswift:
    utACK fa3c651143
  ryanofsky:
    utACK fa3c651143

Tree-SHA512: b67082fe3718c94b4addf7f2530593915225c25080f20c3ffa4ff7e08f1f49548f255fb285f89a8feff84be3f6c91e1792495ced9f6bf396732396d1356d597a
2019-05-14 08:23:24 -04:00
Andrew Chow
662d1171d9 Add option to create an encrypted wallet 2019-05-13 22:49:34 -04:00
MarcoFalke
fa3c651143
[refactor] interfaces: Add missing LockAnnotation for cs_main 2019-05-13 14:46:01 -04:00
MarcoFalke
667a861741
Merge #14364: doc: Clarify -blocksdir usage
ccc27bdcd2 doc: Clarify -blocksdir usage (Daniel McNally)

Pull request description:

  This PR attempts to clarify and correct the `-blocksdir` argument description and default value. `-blocksdir` does not refer to the full path to the actual `blocks` directory, but rather the root/parent directory which contains the `blocks` directory. Accordingly, the default value is `<datadir>` and not `<datadir>/blocks` - this behavior of defaulting to the datadir can also be seen in init.cpp:

  ```cpp
      if (gArgs.IsArgSet("-blocksdir")) {
          path = fs::system_complete(gArgs.GetArg("-blocksdir", ""));
          if (!fs::is_directory(path)) {
              path = "";
              return path;
          }
      } else {
          path = GetDataDir(false);
      }
  ```

  It also attempts to clarify that only the `.dat` files containing block data are impacted by `-blocksdir`, not the index files.

  I believe this would close #12828.

ACKs for commit ccc27b:
  hebasto:
    utACK ccc27bdcd2

Tree-SHA512: 7b65f66b0579fd56e8c8cd4f9f22d6af56181817762a68deccd7fca51820ad82d9a0c48f5f1f012e746c67bcdae7af4555fad867cb620a9ca538d465c9d86c2b
2019-05-13 12:46:03 -04:00
MarcoFalke
fa86c8aec6
init: Remove dead code in LoadChainTip 2019-05-13 11:53:38 -04:00
MarcoFalke
fa8ced32a6
doc: Mention blocksonly in reduce-traffic.md, unhide option 2019-05-13 10:44:46 -04:00
Jonas Schnelli
8794a4b3ae
QA: add test for HKDF HMAC_SHA256 L32 2019-05-11 09:14:09 +02:00
Jonas Schnelli
551d489416
Add HKDF HMAC_SHA256 L=32 implementations 2019-05-11 09:14:07 +02:00
MarcoFalke
e2371f842f
Merge #14802: rpc: faster getblockstats using BlockUndo data
d20d756752 rpc: faster getblockstats using BlockUndo data (Felix Weis)

Pull request description:

  Using undo data for a block (rev?????.dat) we can retrieve value information about prevouts and calculate the final transaction fee (rate). This approach is about 80x faster, drops the requirement for `-txindex`, and works for all non-pruned blocks.

  ```
  # 2018-11-25T16:36:19Z Bitcoin Core version v0.17.99.0-edc715240-dirty (release build)
  seq 550100 550200  0.00s user 0.00s system 62% cpu 0.004 total
  xargs -n1 src/bitcoin-cli getblockstats  0.21s user 0.19s system 17% cpu 2.302 total

  # 2018-11-25T16:39:17Z Bitcoin Core version v0.17.0 (release build)
  seq 550100 550200  0.00s user 0.00s system 87% cpu 0.002 total
  xargs -n1 src/bitcoin-cli getblockstats  0.24s user 0.22s system 0% cpu 3:19.42 total
  ```

ACKs for commit d20d75:
  MarcoFalke:
    re-utACK d20d756752

Tree-SHA512: 5babc3eb8d2fee2cb23dc12f522656b80737a540cbf2b13390a8f388304c46c064cca76f896b46a6e2abae8cc582d28e1ab20dd4bb17ad6142f20630c2d30c54
2019-05-10 13:20:48 -04:00
Felix Weis
d20d756752 rpc: faster getblockstats using BlockUndo data
Using undo data for a block (rev?????.dat) we can retrieve value information about prevouts and calculate the final transaction fee (rate). This approach is about 80x faster, drops the requirement for -txindex, and works for all non-pruned blocks.
2019-05-10 08:33:14 -04:00
MarcoFalke
14959753a4
Merge #15744: refactor: Extract ParseDescriptorRange
510c6532ba Extract ParseDescriptorRange (Ben Woosley)

Pull request description:

  So as to be consistently informative when the checks fail, and
  to protect against unintentional divergence among the checks.

ACKs for commit 510c65:
  meshcollider:
    Oh apologies, yes. Thanks :) utACK 510c6532ba
  MarcoFalke:
    utACK 510c6532ba
  sipa:
    utACK 510c6532ba

Tree-SHA512: b1f0792bfaa163890a20654a0fc2c4c4a996659916bf5f4a495662436b39326692a1a0c825caafd859e48c05f5dd1865c4f7c28092be5074edda3c94f94f9f8b
2019-05-10 08:09:44 -04:00
Jonas Schnelli
695141bf7a
Merge #15512: Add ChaCha20 encryption option (XOR)
2dfe27517 Add ChaCha20 bench (Jonas Schnelli)
2bc2b8b49 Add ChaCha20 encryption option (XOR) (Jonas Schnelli)

Pull request description:

  The current ChaCha20 implementation does not support message encryption (it can only output the keystream which is sufficient for the RNG).

  This PR adds the actual XORing of the `plaintext` with the `keystream` in order to return the desired `ciphertext`.

  Required for v2 message transport protocol.

ACKs for commit 2dfe27:
  jnewbery:
    Looks good. utACK 2dfe275171.
  jnewbery:
    utACK 2dfe275171
  sipa:
    utACK 2dfe275171
  ryanofsky:
    utACK 2dfe275171. Changes since last review are just renaming the Crypt method, adding comments, and simplifying the benchmark.

Tree-SHA512: 84bb234da2ca9fdc44bc29a786d9dd215520f81245270c1aef801ef66b6091b7793e2eb38ad6dbb084925245065c5dce9e5582f2d0fa220ab3e182d43412d5b5
2019-05-10 09:26:23 +02:00
Pieter Wuille
0b09a57aec Give WalletModel::UnlockContext move semantics 2019-05-09 18:07:33 -07:00
Wladimir J. van der Laan
de5af41e35
Merge #15452: Replace CScriptID and CKeyID in CTxDestination with dedicated types
78e407ad0c GetKeyBirthTimes should return key ids, not destinations (Gregory Sanders)
70946e7fee Replace CScriptID and CKeyID in CTxDestination with dedicated types (Gregory Sanders)

Pull request description:

  The current usage seems to be an overloading of meanings. `CScriptID` is used in the wallet as a lookup key, as well as a destination, and `CKeyID` likewise. Instead, have all destinations be dedicated types.

  New types:
  `CScriptID`->`ScriptHash`
  `CKeyID`->`PKHash`

ACKs for commit 78e407:
  ryanofsky:
    utACK 78e407ad0c. Only changes are removing extra CScriptID()s and fixing the test case.
  Sjors:
    utACK 78e407a
  meshcollider:
    utACK 78e407ad0c

Tree-SHA512: 437f59fc3afb83a40540da3351507aef5aed44e3a7f15b01ddad6226854edeee762ff0b0ef336fe3654c4cd99a205cef175211de8b639abe1130c8a6313337b9
2019-05-09 18:54:43 +02:00
MarcoFalke
fa1dce7329
net: Rename ::fRelayTxes to ::g_relay_txes
This helps to distinguish it from CNode::fRelayTxes and avoid bugs like
425278d17b
2019-05-09 09:10:53 -04:00
MarcoFalke
08788ce170
Merge #15890: Doc: remove text about txes always relayed from -whitelist
e0bb279999 Doc: remove text about txes always relayed from -whitelist (David A. Harding)

Pull request description:

  Updates text since -whitelistforcerelay was set to false by default in PR #15193.

ACKs for commit e0bb27:
  fanquake:
    utACK e0bb279
  MarcoFalke:
    utACK e0bb279999

Tree-SHA512: cf0c9321d72692d573039a04f8f1d048cbdf67ed86cc781523dabd3c45d2731b788f53749e6bb29d7da1ab44eb04030f352469b20489bb2a26c2c38fb61f6489
2019-05-08 15:59:42 -04:00
MarcoFalke
49c1aa5f83
Merge #15971: validation: Add compile-time checking for negative locking requirement in LimitValidationInterfaceQueue
62d50ef308 Add LOCKS_EXCLUDED(cs_main) to LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main) (practicalswift)

Pull request description:

  This PR adds compile-time checking for negative locking requirements that follow from the run-time locking requirement `AssertLockNotHeld(cs_main)` in `LimitValidationInterfaceQueue(...)`.

  Changes:
  * Add `LOCKS_EXCLUDED(cs_main)` to `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `CChainState::ActivateBestChain(…)`, `CChainState:: InvalidateBlock(…)` and `CChainState::RewindBlockIndex(…)` which all call `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `InvalidateBlock(…)` which calls `CChainState::InvalidateBlock(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which  does `AssertLockNotHeld(cs_main)`
  * Add `LOCKS_EXCLUDED(cs_main)` to `RewindBlockIndex(…)` which calls `CChainState::RewindBlockIndex(...)` which in turn calls `LimitValidationInterfaceQueue(...)` which does `AssertLockNotHeld(cs_main)`

ACKs for commit 62d50e:
  MarcoFalke:
    utACK 62d50ef308

Tree-SHA512: 73d092ccd08c851ae3c5d60370c369fc030c5793f5507e2faccb6f91c851ddc0ce059fbea3899f2856330d7a8c78f2ac6a2988e8268b03154f946be9e60e3be1
2019-05-08 09:19:41 -04:00
MeshCollider
ef802ef5d6
Merge #15880: utils and libraries: Replace deprecated Boost Filesystem functions
a0a222eec Replace deprecated Boost Filesystem function (Hennadii Stepanov)
4f65af97b Remove dead code for walletFile check (Hennadii Stepanov)

Pull request description:

  Boost Filesystem `basename()` and `extension()` functions are [deprecated since v1.36.0](https://www.boost.org/doc/libs/1_36_0/libs/filesystem/doc/reference.html#Convenience-functions).

  See more: https://lists.boost.org/Archives/boost/2010/01/160905.php

  Also this PR prevents further use of deprecated Boost Filesystem functions.
  Ref: https://www.boost.org/doc/libs/1_64_0/libs/filesystem/doc/index.htm#Coding-guidelines

  Note: On my Linux system Boost 1.65.1 header `/usr/include/boost/filesystem/convenience.hpp` contains:
  ```c++
  # ifndef BOOST_FILESYSTEM_NO_DEPRECATED

      inline std::string extension(const path & p)
      {
        return p.extension().string();
      }

      inline std::string basename(const path & p)
      {
        return p.stem().string();
      }

      inline path change_extension( const path & p, const path & new_extension )
      {
        path new_p( p );
        new_p.replace_extension( new_extension );
        return new_p;
      }

  # endif
  ```

  UPDATE:
  Also removed unused code as [noted](https://github.com/bitcoin/bitcoin/pull/15880#discussion_r279386614) by **ryanofsky**.

ACKs for commit a0a222:
  Empact:
    utACK a0a222eec0
  practicalswift:
    utACK a0a222eec0
  fanquake:
    utACK a0a222e
  ryanofsky:
    utACK a0a222eec0. Only change is dropping assert and squashing first two commits.

Tree-SHA512: bc54355441c49957507eb8d3a5782b92d65674504d69779bc16b1b997b2e7424d5665eb6bfb6e10b430a6cacd2aca70af2f94e5f7f10bea24624202834ad35c7
2019-05-09 00:01:29 +12:00
MeshCollider
c3ef63a52f Show loaded wallets as disabled in open menu instead of nothing 2019-05-08 23:54:25 +12:00
practicalswift
62d50ef308 Add LOCKS_EXCLUDED(cs_main) to LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main)
Add LOCKS_EXCLUDED(cs_main) to functions calling LimitValidationInterfaceQueue(...) which does AssertLockNotHeld(cs_main)

Add LOCKS_EXCLUDED(cs_main) to functions calling CChainState::InvalidateBlock(...) which calls LimitValidationInterfaceQueue(...) which in turn does AssertLockNotHeld(cs_main)

Add LOCKS_EXCLUDED(cs_main) to functions calling CChainState::RewindBlockIndex(...) which calls LimitValidationInterfaceQueue(...) which in turn does AssertLockNotHeld(cs_main)
2019-05-08 10:31:54 +02:00
Russell Yanofsky
f6bb11fd37 Add test for ArgsManager::GetChainName
There was some test coverage previously, but it was limited and didn't test
conflicting and negated arguments.
2019-05-07 11:51:30 -04:00
MarcoFalke
b2a6b02161
Merge #15948: refactor: rename chainActive
486c1eea86 refactoring: remove unused chainActive (James O'Beirne)
631940aab2 scripted-diff: replace chainActive -> ::ChainActive() (James O'Beirne)
a3a609079c refactoring: introduce unused ChainActive() (James O'Beirne)
1b6e6fcfd2 rename: CChainState.chainActive -> m_chain (James O'Beirne)

Pull request description:

  This is part of the assumeutxo project:

  Parent PR: #15606
  Issue: #15605
  Specification: https://github.com/jamesob/assumeutxo-docs/tree/2019-04-proposal/proposal

  ---

  This change refactors the `chainActive` reference into a `::ChainActive()` call. It also distinguishes `CChainState`'s `CChain` data member as `m_chain` instead of the current `chainActive`, which makes it easily confused with the global data.

  The active chain must be obtained via function because its reference will be swapped at some point during runtime after loading a UTXO snapshot.

  This change, though lengthy, should be pretty easy to review since most of it is contained within a scripted-diff. Once merged, the parent PR should be easier to review.

ACKs for commit 486c1e:
  Sjors:
    utACK 486c1ee
  promag:
    utACK 486c1ee.
  practicalswift:
    utACK 486c1eea86

Tree-SHA512: 06ed8f9e77f2d25fc9bea0ba86436d80dbbce90a1e8be23e37ec4eeb26060483e60b4a5c4fba679cb1867f61e3921c24abeb9cabdfb4d0a9b1c4ddd77b17456a
2019-05-07 11:51:30 -04:00
Russell Yanofsky
4b331159df Add unit test NextString, ForEachNoDup functions
Remove testcase generating code from util_SettingsMerge so it can be reused in
new tests.

The hash value expected in util_SettingsMerge changes as a result of this, but
only because the testcases are generated in a different order, not because any
cases are added or removed. It is possible to verify this with:

    SETTINGS_MERGE_TEST_OUT=new.txt test/test_bitcoin --run_test=util_tests/util_SettingsMerge
    git checkout HEAD~1
    make test/test_bitcoin
    SETTINGS_MERGE_TEST_OUT=old.txt test/test_bitcoin --run_test=util_tests/util_SettingsMerge
    diff -u <(sort old.txt) <(sort new.txt)

The new output is a little more readable, with simpler testcases sorted first.
2019-05-07 11:51:30 -04:00
Russell Yanofsky
05bfee3451 util_SettingsMerge test cleanup
Followup to #15869. Treat "-wallet" as the network-specific argument in test
instead of "-server", to make test output clearer and be more consistent with
bitcoind. Update embedded hash to match changed output from this.
2019-05-07 11:51:30 -04:00
orient
41ab2a8924
fix static_assert for macro HAVE_THREAD_LOCAL
fix static_assert for macro HAVE_THREAD_LOCAL while define DEBUG_LOCKCONTENTION
2019-05-07 14:11:35 +08:00
grim-trigger
1b05dff080
Fix portability issue with pthreads
This change resolves the following issue:
https://github.com/bitcoin/bitcoin/issues/15951

Only tested on OpenBSD 6.5/amd64
2019-05-07 00:17:33 +00:00
Pieter Wuille
3cb9ce85d0 Document strenghtening 2019-05-06 15:15:04 -07:00
Pieter Wuille
1d207bc46f Add hash strengthening to the RNG
Once every minute, this will feed the RNG state through repeated SHA512
for 10ms. The timings of that operation are used as entropy source as
well.
2019-05-06 15:15:04 -07:00
Pieter Wuille
c01c065b9d Do not construct out-of-bound pointers in SHA512/SHA1/RIPEMD160 code 2019-05-06 15:11:10 -07:00
MarcoFalke
3632143ebb
Merge #14266: refactor: Lift prevector default vals to the member declaration
d2eee87928 Lift prevector default vals to the member declaration (Ben Woosley)

Pull request description:

  I overlooked this possibility in #14028

ACKs for commit d2eee8:
  promag:
    utACK d2eee87, change looks good because members are always initialized.
  251Labs:
    utACK d2eee87 nice one.
  ken2812221:
    utACK d2eee87928
  practicalswift:
    utACK d2eee87928
  scravy:
    utACK d2eee87928

Tree-SHA512: f2726bae1cf892fd680cf8571027bcdc2e42ba567eaa901fb5fb5423b4d11b29e745e0163d82cb513d8c81399cc85933a16ed66d4a30829382d4721ffc41dc97
2019-05-06 15:32:24 -04:00
MarcoFalke
aaaa57c2aa
scripted-diff: Bump copyright headers in wallet
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./src/wallet/
-END VERIFY SCRIPT-
2019-05-06 14:05:52 -04:00
MarcoFalke
faf3729242
wallet: Only fail rescan when blocks have actually been pruned 2019-05-06 14:03:56 -04:00
Wladimir J. van der Laan
c5ffe8d515
Merge #15730: rpc: Show scanning details in getwalletinfo
b6c748f849 doc: Add release notes for 15730 (João Barbosa)
d3e8458365 rpc: Show scanning details in getwalletinfo (João Barbosa)
90e27abe37 wallet: Track current scanning progress (João Barbosa)
2ee811e693 wallet: Track scanning duration (João Barbosa)

Pull request description:

  Closes #15724.

ACKs for commit b6c748:
  MarcoFalke:
    re-utACK b6c748f849 (Only change since my last review is rebase, adding release notes, and returning false instead of null)
  laanwj:
    utACK b6c748f849
  jonatack:
    ACK b6c748f849, only changes appear to be rebase for https://github.com/bitcoin/bitcoin/pull/15730#discussion_r280030617 and release notes.

Tree-SHA512: 8ee98f971c15f66ce8138fc92c55e51abc9faf01866a31ac7ce2ad766aa2bb88559eabee3b5815d645c84cdf1c19dc35ec03f31461e39bc5f6040edec0b87116
2019-05-06 13:38:12 +02:00
Wladimir J. van der Laan
a3d2d6b067
Merge #15930: rpc: Add balances RPC
facfb4111d rpc: Deprecate getunconfirmedbalance and getwalletinfo balances (MarcoFalke)
999931cf8f rpc: Add getbalances RPC (MarcoFalke)
fad13e925e rpcwallet: Make helper methods const on CWallet (MarcoFalke)
fad40ec915 wallet: Use IsValidNumArgs in getwalletinfo rpc (MarcoFalke)

Pull request description:

  This exposes the `CWallet::GetBalance()` struct over RPC.

  In the future, incorrectly named rpcs such as `getunconfirmedbalance` or rpcs redundant to this such as `getbalance` could be removed.

ACKs for commit facfb4:
  jnewbery:
    utACK facfb4111d

Tree-SHA512: 1f54fedce55df9a8ea82d2b6265354b39a956072621876ebaee2355aac0e23c7b64340c3279502415598c095858529e18b50789be956250aafda1cd3a8d948a5
2019-05-06 11:36:42 +02:00
Wladimir J. van der Laan
9bbaac73bb
Merge #15928: GUI: Move QRImageWidget to its own file-pair
fc929842c2 GUI: Move QRImageWidget to its own file-pair (Luke Dashjr)
77851ab682 GUI: Refactor actual QR code rendering into new QRImageWidget::setQR (Luke Dashjr)

Pull request description:

  For at least QR-code based pairing of mobile wallets with nodes, it will be desirable to render QR codes even without wallet support.

  Therefore, this prepares by moving the QRImageWidget out of a wallet-specific file into its own `qrencoder` file-pair.

ACKs for commit fc9298:
  laanwj:
    utACK fc929842c2
  jonasschnelli:
    utACK fc929842c2

Tree-SHA512: 95529a38c0573a4b3f1253fb5f11ca07a5b3a9840ec24acc7d87270212f3c9f7c5b186d9274d297517a3b80494f38a57574fb9730b1574db01688539b987bd91
2019-05-06 10:04:33 +02:00
Wladimir J. van der Laan
d7d7d31506
Merge #15141: Rewrite DoS interface between validation and net_processing
0ff1c2a838 Separate reason for premature spends (coinbase/locktime) (Suhas Daftuar)
54470e767b Assert validation reasons are contextually correct (Suhas Daftuar)
2120c31521 [refactor] Update some comments in validation.cpp as we arent doing DoS there (Matt Corallo)
12dbdd7a41 [refactor] Drop unused state.DoS(), state.GetDoS(), state.CorruptionPossible() (Matt Corallo)
aa502b88d1 scripted-diff: Remove DoS calls to CValidationState (Matt Corallo)
7721ad64f4 [refactor] Prep for scripted-diff by removing some \ns which annoy sed. (Matt Corallo)
5e78c5734b Allow use of state.Invalid() for all reasons (Matt Corallo)
6b34bc6b6f Fix handling of invalid headers (Suhas Daftuar)
ef54b486d5 [refactor] Use Reasons directly instead of DoS codes (Matt Corallo)
9ab2a0412e CorruptionPossible -> BLOCK_MUTATED (Matt Corallo)
6e55b292b0 CorruptionPossible -> TX_WITNESS_MUTATED (Matt Corallo)
7df16e70e6 LookupBlockIndex -> CACHED_INVALID (Matt Corallo)
c8b0d22698 [refactor] Drop redundant nDoS, corruptionPossible, SetCorruptionPossible (Matt Corallo)
34477ccd39 [refactor] Add useful-for-dos "reason" field to CValidationState (Matt Corallo)
6a7f8777a0 Ban all peers for all block script failures (Suhas Daftuar)
7b999103e2 Clean up banning levels (Matt Corallo)
b8b4c80146 [refactor] drop IsInvalid(nDoSOut) (Matt Corallo)
8818729013 [refactor] Refactor misbehavior ban decisions to MaybePunishNode() (Matt Corallo)
00e11e61c0 [refactor] rename stateDummy -> orphan_state (Matt Corallo)
f34fa719cf Drop obsolete sigops comment (Matt Corallo)

Pull request description:

  This is a rebase of #11639 with some fixes for the last few comments which were not yet addressed.

  The original PR text, with some strikethroughs of text that is no longer correct:

  > This cleans up an old main-carryover - it made sense that main could decide what DoS scores to assign things because the DoS scores were handled in a different part of main, but now validation is telling net_processing what DoS scores to assign to different things, which is utter nonsense. Instead, we replace CValidationState's nDoS and CorruptionPossible with a general ValidationInvalidReason, which net_processing can handle as it sees fit. I keep the behavior changes here to a minimum, but in the future we can utilize these changes for other smarter behavior, such as disconnecting/preferring to rotate outbound peers based on them providing things which are invalid due to SOFT_FORK because we shouldn't ban for such cases.
  >
  > This is somewhat complementary with, though obviously conflicts heavily with #11523, which added enums in place of DoS scores, as well as a few other cleanups (which are still relevant).
  >
  > Compared with previous bans, the following changes are made:
  >
  > Txn with empty vin/vout or null prevouts move from 10 DoS
  > points to 100.
  > Loose transactions with a dependency loop now result in a ban
  > instead of 10 DoS points.
  > ~~BIP68-violation no longer results in a ban as it is SOFT_FORK.~~
  > ~~Non-SegWit SigOp violation no longer results in a ban as it
  > considers P2SH sigops and is thus SOFT_FORK.~~
  > ~~Any script violation in a block no longer results in a ban as
  > it may be the result of a SOFT_FORK. This should likely be
  > fixed in the future by differentiating between them.~~
  > Proof of work failure moves from 50 DoS points to a ban.
  > Blocks with timestamps under MTP now result in a ban, blocks
  > too far in the future continue to not result in a ban.
  > Inclusion of non-final transactions in a block now results in a
  > ban instead of 10 DoS points.

  Note: The change to ban all peers for consensus violations is actually NOT the change I'd like to make -- I'd prefer to only ban outbound peers in those situations.  The current behavior is a bit of a mess, however, and so in the interests of advancing this PR I tried to keep the changes to a minimum.  I plan to revisit the behavior in a followup PR.

  EDIT: One reviewer suggested I add some additional context for this PR:

  > The goal of this work was to make net_processing aware of the actual reasons for validation failures, rather than just deal with opaque numbers instructing it to do something.
  >
  > In the future, I'd like to make it so that we use more context to decide how to punish a peer. One example is to differentiate inbound and outbound peer misbehaviors. Another potential example is if we'd treat RECENT_CONSENSUS_CHANGE failures differently (ie after the next consensus change is implemented), and perhaps again we'd want to treat some peers differently than others.

ACKs for commit 0ff1c2:
  jnewbery:
    utACK 0ff1c2a838
  ryanofsky:
    utACK 0ff1c2a838. Only change is dropping the first commit (f3883a321bf4ab289edcd9754b12cae3a648b175), and dropping the temporary `assert(level == GetDoS())` that was in 35ee77f2832eaffce30042e00785c310c5540cdc (now c8b0d22698)

Tree-SHA512: e915a411100876398af5463d0a885920e44d473467bb6af991ef2e8f2681db6c1209bb60f848bd154be72d460f039b5653df20a6840352c5f7ea5486d9f777a3
2019-05-04 11:58:57 +02:00
Jonas Schnelli
2dfe275171
Add ChaCha20 bench 2019-05-03 22:52:11 +02:00
James O'Beirne
486c1eea86 refactoring: remove unused chainActive 2019-05-03 15:03:05 -04:00
James O'Beirne
631940aab2 scripted-diff: replace chainActive -> ::ChainActive()
Though at the moment ChainActive() simply references `g_chainstate.m_chain`,
doing this change now clears the way for multiple chainstate usage and allows
us to script the diff.

-BEGIN VERIFY SCRIPT-
git grep -l "chainActive" | grep -E '(h|cpp)$' | xargs sed -i '/chainActive =/b; /extern CChain& chainActive/b; s/\(::\)\{0,1\}chainActive/::ChainActive()/g'
-END VERIFY SCRIPT-
2019-05-03 15:02:54 -04:00
James O'Beirne
a3a609079c refactoring: introduce unused ChainActive()
in preparation for the following scripted-diff commit.
2019-05-03 14:38:38 -04:00
James O'Beirne
1b6e6fcfd2 rename: CChainState.chainActive -> m_chain
This can't be a scripted-diff due to the confusion of the global
chainActive and the CChainState member of the same name.

This specific rename makes the following chainActive -> ::ChainActive() diff
scriptable.
2019-05-03 14:38:30 -04:00
Jonas Schnelli
2bc2b8b49a
Add ChaCha20 encryption option (XOR) 2019-05-03 20:31:18 +02:00
MarcoFalke
facfb4111d
rpc: Deprecate getunconfirmedbalance and getwalletinfo balances 2019-05-03 13:59:44 -04:00
MarcoFalke
94daebf327
Merge #15932: rpc: Serialize in getblock without cs_main
faea56400d rpc: Add lock annotations to block{,header}ToJSON (MarcoFalke)
fab00a5cb9 rpc: Serialize in getblock without cs_main (MarcoFalke)
fa1c3591ad rpc: Use IsValidNumArgs in getblock (MarcoFalke)

Pull request description:

  No need to hold cs_main when serializing a struct to json

  Fixes: #15925

ACKs for commit faea56:
  jnewbery:
    utACK faea56400d
  jonasschnelli:
    utACK faea56400d

Tree-SHA512: 005d378cda1e6024e9f5142f99a8adbefe202cd7bfeaafee55eb909e8990a3790aa27fcf5dd16119cc9afe9dc8bd30f660de40233316781669be166bac3018e7
2019-05-03 08:09:22 -04:00
Suhas Daftuar
0ff1c2a838 Separate reason for premature spends (coinbase/locktime) 2019-05-02 15:30:58 -04:00
Suhas Daftuar
54470e767b Assert validation reasons are contextually correct 2019-05-02 15:29:09 -04:00
Matt Corallo
2120c31521 [refactor] Update some comments in validation.cpp as we arent doing DoS there 2019-05-02 15:27:32 -04:00
Matt Corallo
12dbdd7a41 [refactor] Drop unused state.DoS(), state.GetDoS(), state.CorruptionPossible()
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2019-05-02 15:25:43 -04:00
Matt Corallo
aa502b88d1 scripted-diff: Remove DoS calls to CValidationState
-BEGIN VERIFY SCRIPT-
sed -i 's/\.DoS(\(.*\), REJECT_\(.*\), \(true\|false\)/.DoS(\1, REJECT_\2/' src/validation.cpp src/consensus/tx_verify.cpp src/consensus/tx_check.cpp
sed -i 's/state.GetRejectCode(), state.GetRejectReason(), [^,]\+, state.GetDebugMessage())/state.GetRejectCode(), state.GetRejectReason(), state.GetDebugMessage())/' src/validation.cpp
sed -i 's/\.DoS([^,]*, /.Invalid\(/' src/validation.cpp src/consensus/tx_verify.cpp src/consensus/tx_check.cpp
-END VERIFY SCRIPT-

Co-authored-by: Suhas Daftuar <sdaftuar@gmail.com>
2019-05-02 15:24:07 -04:00
Matt Corallo
7721ad64f4 [refactor] Prep for scripted-diff by removing some \ns which annoy sed. 2019-05-02 15:22:29 -04:00
Matt Corallo
5e78c5734b Allow use of state.Invalid() for all reasons
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2019-05-02 15:21:24 -04:00
Suhas Daftuar
6b34bc6b6f Fix handling of invalid headers
We only disconnect outbound peers (excluding HB compact block peers and manual
connections) when receiving a CACHED_INVALID header.
2019-05-02 15:17:24 -04:00
Matt Corallo
ef54b486d5 [refactor] Use Reasons directly instead of DoS codes 2019-05-02 15:15:50 -04:00
Matt Corallo
9ab2a0412e CorruptionPossible -> BLOCK_MUTATED
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2019-05-02 15:14:12 -04:00
Matt Corallo
6e55b292b0 CorruptionPossible -> TX_WITNESS_MUTATED
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2019-05-02 15:12:38 -04:00
Matt Corallo
7df16e70e6 LookupBlockIndex -> CACHED_INVALID
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2019-05-02 15:11:03 -04:00
Matt Corallo
c8b0d22698 [refactor] Drop redundant nDoS, corruptionPossible, SetCorruptionPossible
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2019-05-02 15:10:32 -04:00
Matt Corallo
34477ccd39 [refactor] Add useful-for-dos "reason" field to CValidationState
This is a first step towards cleaning up our DoS interface - make
validation return *why* something is invalid, and let net_processing
figure out what that implies in terms of banning/disconnection/etc.

Behavior change: peers will now be banned for providing blocks
with premature coinbase spends.

Co-authored-by: Anthony Towns <aj@erisian.com.au>
                Suhas Daftuar <sdaftuar@gmail.com>
2019-05-02 14:55:13 -04:00
MarcoFalke
faea56400d
rpc: Add lock annotations to block{,header}ToJSON 2019-05-02 14:33:26 -04:00
Suhas Daftuar
6a7f8777a0 Ban all peers for all block script failures
This eliminates a discrepancy between block validation with multiple
script check threads, versus a single script check thread.
2019-05-02 11:00:19 -04:00
Matt Corallo
7b999103e2 Clean up banning levels
Compared with previous bans, the following changes are made:
 * Txn with empty vin/vout or null prevouts move from 10 DoS
   points to 100.
 * Loose transactions with a dependency loop now result in a ban
   instead of 10 DoS points.
 * Many pre-segwit soft-fork errors now result in a ban.
   Note: Transactions that violate soft-fork script flags since P2SH do not generally
   result in a ban. Also, banning behavior for invalid blocks is dependent on
   whether the node is validating with multiple script check threads, due to a long-
   standing bug. That inconsistency is still present after this commit.
 * Proof of work failure moves from 50 DoS points to a ban.
 * Blocks with timestamps under MTP now result in a ban, blocks
   too far in the future continue to *not* result in a ban.
 * Inclusion of non-final transactions in a block now results in a
   ban instead of 10 DoS points.

Co-authored-by: Anthony Towns <aj@erisian.com.au>
2019-05-02 11:00:19 -04:00
Matt Corallo
b8b4c80146 [refactor] drop IsInvalid(nDoSOut)
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2019-05-02 11:00:19 -04:00
Matt Corallo
8818729013 [refactor] Refactor misbehavior ban decisions to MaybePunishNode()
Isolate the decision of whether to ban a peer to one place in the
code, rather than having it sprinkled throughout net_processing.

Co-authored-by: Anthony Towns <aj@erisian.com.au>
                Suhas Daftuar <sdaftuar@gmail.com>
                John Newbery <john@johnnewbery.com>
2019-05-02 11:00:19 -04:00
Matt Corallo
00e11e61c0 [refactor] rename stateDummy -> orphan_state
Co-authored-by: Anthony Towns <aj@erisian.com.au>
                Suhas Daftuar <sdaftuar@gmail.com>
2019-05-02 11:00:19 -04:00
Matt Corallo
f34fa719cf Drop obsolete sigops comment
This comment was confusing and incorrect when first added ("invalid rather than
merely non-standard" has the opposite meaning of what is actually the case),
and was also not updated after segwit with the correct variable names.

Delete it since the code reads just fine on its own.

Co-authored by: Anthony Towns <aj@erisian.com.au>
                Suhas Daftuar <sdaftuar@gmail.com>
2019-05-02 11:00:19 -04:00