Commit Graph

13810 Commits

Author SHA1 Message Date
str4d b2b5cccf39
test: Fix LFSR period in comments
Verified using a Python implementation.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2020-09-26 00:56:20 +01:00
str4d b5ddac4b71
LockedPool: Switch to HTTPS URLs in licenses and comments
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2020-09-26 00:30:45 +01:00
practicalswift a3fbfe4efc Improve readability by removing redundant casts to same type (on all platforms) 2020-09-25 14:56:20 +01:00
Jeremy Rubin 94f7ae6ce8 Fix subscript[0] potential bugs in key.cpp 2020-09-25 14:54:17 +01:00
MarcoFalke 101857a291 Limit scope of all global std::once_flag
Zcash: Excludes change to src/rpc/server.cpp
2020-07-31 07:41:05 +01:00
Jack Grigg e591f94fcf Assorted small changes to the locked pool manager
Cherry-picked from:
- bitcoin/bitcoin#9233
- bitcoin/bitcoin#10483
- bitcoin/bitcoin#10645
- bitcoin/bitcoin#10969
- bitcoin/bitcoin#11351

Co-authored-by: fsb4000 <fsb4000@yandex.ru>
Co-authored-by: practicalswift <practicalswift@users.noreply.github.com>
Co-authored-by: Dan Raviv <dan@soundradix.com>
2020-07-31 07:40:06 +01:00
Vasil Dimov 71b79b85d1 lockedpool: avoid sensitive data in core files (FreeBSD)
This is a followup to
23991ee53 / https://github.com/bitcoin/bitcoin/pull/15600
to also use madvise(2) on FreeBSD to avoid sensitive data allocated
with secure_allocator ending up in core files in addition to preventing
it from going to the swap.
2020-07-31 07:23:44 +01:00
Luke Dashjr 6b278b20cb lockedpool: When possible, use madvise to avoid including sensitive information in core dumps 2020-07-31 07:22:23 +01:00
Jeffrey Czyz 4277ef2063 Fix segfault in allocator_tests/arena_tests
The test uses reinterpret_cast<void*> on unallocated memory. Using this
memory in printchunk as char* causes a segfault, so have printchunk take
void* instead.

Zcash: Includes change from bitcoin/bitcoin#13163
2020-07-31 07:21:19 +01:00
Jeffrey Czyz 28825123eb Fix compilation errors in support/lockedpool.cpp
Changes in #12048 cause a compilation error in Arena::walk() when
ARENA_DEBUG is defined. Specifically, Arena's chunks_free map was
changed to have a different value type.

Additionally, missing includes cause other compilation errors when
ARENA_DEBUG is defined.

Reproduced with:

make CPPFLAGS=-DARENA_DEBUG
2020-07-31 07:17:03 +01:00
practicalswift 3d635dd09f Fix out-of-bounds write in case of failing mmap(...) in PosixLockedPageAllocator::AllocateLocked 2020-07-31 07:16:36 +01:00
Martin Ankerl e64df07811 fix nits: variable naming, typos 2020-07-31 07:15:46 +01:00
Martin Ankerl 1245ce0d8c Use best-fit strategy in Arena, now O(log(n)) instead O(n)
This replaces the first-fit algorithm used in the Arena with a best-fit. According to "Dynamic Storage Allocation: A Survey and Critical Review", Wilson et. al. 1995, http://www.scs.stanford.edu/14wi-cs140/sched/readings/wilson.pdf, both startegies work well in practice.

The advantage of using best-fit is that we can switch the slow O(n) algorithm to O(log(n)) operations. Additionally, some previously O(log(n)) operations are now replaced with O(1) operations by using a hash map. The end effect is that the benchmark runs about 2.5 times faster on my machine:

old: BenchLockedPool, 5, 530, 5.25749, 0.00196938, 0.00199755, 0.00198172
new: BenchLockedPool, 5, 1300, 5.11313, 0.000781493, 0.000793314, 0.00078606

I've run all unit tests and benchmarks.

Zcash: Excludes change to benchmark.
2020-07-31 07:14:34 +01:00
Pieter Wuille 614d1bb207 Remove some unused functions and methods
In the case of CKey's destructor, it seems to have been an oversight in
f4d1fc259 not to delete it. At this point, it results in the move
constructors/assignment operators for CKey being deleted, which may have
a performance impact.
2020-07-31 06:51:33 +01:00
Kaz Wesley 2555074c22 LockedPool: avoid quadratic-time allocation
Use separate maps for used/free chunks to avoid linear scan through alloced
chunks for each alloc.
2020-07-31 06:51:33 +01:00
Kaz Wesley 817e36b217 LockedPool: fix explosion for illegal-sized alloc
Check for unreasonable alloc size in LockedPool rather than lancing through new
Arenas until we improbably find one worthy of the quixotic request or the system
can support no more Arenas.
2020-07-31 06:51:00 +01:00
Kaz Wesley 509652e936 LockedPool: test handling of invalid allocations
(Currently fails due to bug)
2020-07-31 06:51:00 +01:00
Pavel Janík d0df44f151 Do not shadow variable, use deprecated MAP_ANON if MAP_ANONYMOUS is not defined. 2020-07-31 06:51:00 +01:00
Wladimir J. van der Laan 088219f786 bench: Add benchmark for lockedpool allocation/deallocation 2020-07-31 06:43:09 +01:00
Wladimir J. van der Laan 82a667591e rpc: Add `getmemoryinfo` call
```
getmemoryinfo
Returns an object containing information about memory usage.

Result:
{
  "locked": {               (json object) Information about locked memory manager
    "used": xxxxx,          (numeric) Number of bytes used
    "free": xxxxx,          (numeric) Number of bytes available in current arenas
    "total": xxxxxxx,       (numeric) Total number of bytes managed
    "locked": xxxxxx,       (numeric) Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk.
  }
}

Examples:
> bitcoin-cli getmemoryinfo
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getmemoryinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
```
2020-07-31 06:43:09 +01:00
Wladimir J. van der Laan d570eabc38 support: Add LockedPool
Add a pool for locked memory chunks, replacing LockedPageManager.

This is something I've been wanting to do for a long time. The current
approach of locking objects where they happen to be on the stack or heap
in-place causes a lot of mlock/munlock system call overhead, slowing
down any handling of keys.

Also locked memory is a limited resource on many operating systems (and
using a lot of it bogs down the system), so the previous approach of
locking every page that may contain any key information (but also other
information) is wasteful.
2020-07-31 06:43:09 +01:00
Wladimir J. van der Laan 8d0f80f831 wallet: Get rid of LockObject and UnlockObject calls in key.h
Replace these with vectors allocated from the secure allocator.

This avoids mlock syscall churn on stack pages, as well as makes
it possible to get rid of these functions.

Please review this commit and the previous one carefully that
no `sizeof(vectortype)` remains in the memcpys and memcmps usage
(ick!), and `.data()` or `&vec[x]` is used as appropriate instead of
&vec.
2020-07-31 06:43:08 +01:00
Wladimir J. van der Laan b997b30a91 wallet: Change CCrypter to use vectors with secure allocator
Change CCrypter to use vectors with secure allocator instead of buffers
on in the object itself which will end up on the stack. This avoids
having to call LockedPageManager to lock stack memory pages to prevent the
memory from being swapped to disk. This is wasteful.
2020-07-31 06:43:08 +01:00
Thomas Snider 20280556ba [trivial] Switched constants to sizeof() 2020-07-31 06:43:08 +01:00
Homu 2589b2fcc5 Auto merge of #4614 - str4d:ctaes, r=str4d
Replace OpenSSL AES with ctaes-based version

Backported from upstream PR https://github.com/bitcoin/bitcoin/pull/7689.

This is backported primarily to remove merge conflicts for a subsequent
backport, and also helps us towards removing OpenSSL. Its actual usage
in wallet encryption would be replaced by a more modern construction
before we make wallet encryption a supported feature, but for now this
does not affect anyone using the experimental feature.
2020-07-31 00:14:40 +00:00
Jack Grigg fb2edcc352 Debian: Add copyright entries for ctaes and secp256k1 2020-07-30 05:57:00 +01:00
Homu f39e4dbaf1 Auto merge of #4627 - LarryRuane:issue4596-flush-wallet-db, r=str4d
flush witness cache (SetBestChain()) on clean shutdown

Closes #4596, follow-on to #4573. In addition to flushing witness data on shutdown, fix the RPC test that was preventing this change from being part of #4573.
2020-07-29 13:12:04 +00:00
Homu 615efd2a52 Auto merge of #4584 - defuse:update-ignore, r=str4d
Block release when we haven't checked dependency updates for security fixes
2020-07-29 10:45:44 +00:00
Homu 24f3bcf275 Auto merge of #4623 - str4d:metrics-locking, r=str4d
metrics: Collect general stats before clearing screen

This prevents the metrics screen from flashing if locks are being held
by long-running processes, specifically cs_main during block validation.

We split up locking on cs_main and cs_vNodes to make obtaining the locks
easier, at the expense of potentially having slightly out-of-sync
statistics (which doesn't really matter, as all we are fetching from the
latter lock is the number of connected peers).
2020-07-29 09:33:07 +00:00
Homu 91cb52adc5 Auto merge of #4606 - str4d:safe-mode-alert-for-pre-heartwood-nodes, r=str4d
Send alert to put pre-Heartwood nodes into safe mode.

The alert targets nodes running protocol version <= 170010.
Heartwood-compatible nodes run protocol version >= 170011.
2020-07-29 07:59:59 +00:00
Homu b1b65121ae Auto merge of #4590 - cwsaunders:master, r=str4d
Update two dev tool files from Python 2 to Python 3
2020-07-29 06:45:45 +00:00
Homu e789632c32 Auto merge of #4640 - therealyingtong:v3.1.0-release-notes-update, r=str4d
Add Debian8 deprecation to release notes
2020-07-29 05:39:22 +00:00
ying tong f7b3a55505
Update doc/release-notes/release-notes-3.1.0.md
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2020-07-29 07:21:25 +08:00
therealyingtong b5ee15b781
Add Debian8 deprecation to release notes 2020-07-29 05:42:12 +08:00
Homu 65f0a4736a Auto merge of #4638 - therealyingtong:release-v3.1.0, r=daira
Release v3.1.0
2020-07-28 12:11:27 +00:00
therealyingtong 369c16ef44
Set APPROX_RELEASE_HEIGHT to 917000 and update release-notes-3.1.0.md 2020-07-28 07:57:58 +08:00
therealyingtong 228b17c9e0
make-release.py: Updated release notes and changelog for 3.1.0. 2020-07-28 07:02:06 +08:00
therealyingtong f25e86a460
make-release.py: Updated manpages for 3.1.0. 2020-07-28 07:02:06 +08:00
therealyingtong e4963385a4
make-release.py: Versioning changes for 3.1.0. 2020-07-28 06:54:02 +08:00
Homu d08883263f Auto merge of #4636 - daira:disable-mining-regression, r=daira
Fix "--disable-mining" build regression

closes #4634

Test by building with:
* `CONFIGURE_FLAGS="--disable-tests --disable-mining --disable-bench" zcutil/build.sh`
* `zcutil/distclean.sh`
* `CONFIGURE_FLAGS="--disable-mining" zcutil/build.sh`

After the second build, run `qa/zcash/full-test-suite.py`. Stop when it gets to the RPC tests, which will hang. The preceding parts of the test suite are all expected to pass.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-07-27 21:41:25 +00:00
Homu 162d5a50ee Auto merge of #4610 - ebfull:testnet-dev-fund, r=str4d
Add dev fund addresses and set activation height for testnet NU4 activation.
2020-07-27 09:05:53 +00:00
Daira Hopwood 40b9cbf0b1 Allow Equihash validation tests to be compiled with --disable-mining.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-07-25 16:33:02 +01:00
Daira Hopwood c99a00596f Fix --disable-mining build regression. closes #4634
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-07-25 15:41:39 +01:00
therealyingtong 283287ab5b
Use 51 Testnet Dev Fund addresses, and adjust the end heights.
Co-authored-by: Ying Tong Lai <yingtong@electriccoin.co>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-07-25 09:45:30 +08:00
therealyingtong 62c3613816
Delay testnet activation height by one week 2020-07-24 08:15:35 +08:00
Homu de52eed974 Auto merge of #4628 - therealyingtong:block-903002-bug, r=str4d
Pass HistoryNode through Rust FFI as a C array

`std::array<T>` is guaranteed to store `T` contiguously. However, there is
no guarantee that `sizeof(std::array<unsigned char, N>) == N`, which
prevents us from interpreting `std::array<std::array<unsigned char, N>, 32>`
as `&[[u8; N]]` on the Rust side of the FFI.

Instead, we define `HistoryNode` as a struct wrapping a C array, which
(as checked by `static_assert`) contains no padding.

This is equivalent to 82fe37d22b, which
fixed this issue when passing a slice of `HistoryEntry`s from C++ to Rust;
the bug fixed here is writing `HistoryNodes` from Rust into C++ memory.
2020-07-23 22:40:42 +00:00
Kris Nuttycombe 04b4d42767 Zero-initialize HistoryNode values. 2020-07-23 16:24:48 -06:00
therealyingtong 13aa74aa45
Pass HistoryNode struct to librustzcash FFI 2020-07-21 17:56:47 +08:00
Larry Ruane a65ecaad54 flush wallet db (SetBestChain()) on clean shutdown 2020-07-20 20:04:48 -06:00
Jack Grigg 5d15ee1f22 metrics: Collect general stats before clearing screen
This prevents the metrics screen from flashing if locks are being held
by long-running processes, specifically cs_main during block validation.

We split up locking on cs_main and cs_vNodes to make obtaining the locks
easier, at the expense of potentially having slightly out-of-sync
statistics (which doesn't really matter, as all we are fetching from the
latter lock is the number of connected peers).
2020-07-18 23:35:19 +12:00