Commit graph

10178 commits

Author SHA1 Message Date
Jason Rhinelander
8bbc8a2b14 Wording fix for lock fix 2019-12-26 12:29:05 -04:00
Jason Rhinelander
0f1c2044d8 Improve locking in mempool removal
Take the blockchain lock simultaneously, and use a lmdb transaction lock
because otherwise the LMDB can apparently segfault sometimes.
2019-12-26 12:29:05 -04:00
Jason Rhinelander
ee27eabc79 Check for tx pool conflicts for non-blocks, too
The loop below this already assumes we have done so to detect conflicts
of incoming block txes with blinks.
2019-12-26 12:29:05 -04:00
Jason Rhinelander
1450c29795 Fix crash when receiving blocks for unknown quorum
This can occur when syncing if we get a blink tx before the blocks that
let us determine the quorum.  Just ignore it at this point; we'll pick
it up at the next once-per-minute sync run.
2019-12-26 12:29:05 -04:00
Jason Rhinelander
292a3b11d0 Blink RPC updates & fixes
Blink txes were not being properly passed in/out of the RPC wallet.
This adds the necessary bits both to submit a blink and to get a blink
submission status back from the daemon.
2019-12-26 12:29:05 -04:00
Jason Rhinelander
7344eb97ce Fix missing blink bug
The wrong value was being checked for still-in-mempool blinks, causing
them to cleaned up from the local node prematurely.
2019-12-26 12:29:05 -04:00
Jason Rhinelander
ac95105e4f Remove unused help message 2019-12-26 12:29:05 -04:00
Jason Rhinelander
f3fdcb1fbc Replace once_a_time_seconds; send proofs faster
This replaces the horrible, horrible, badly misused templated
once_a_time_seconds and once_a_time_milliseconds with a `periodic_task`
that works the same way but takes parameters as constructor arguments
instead of template parameters.

It also makes various small improvements:

- uses std::chrono::steady_clock instead of ifdef'ing platform dependent
  timer code.
- takes a std::chrono duration rather than a template integer and
  scaling parameter.
- timers can be reset to trigger on the next invocation, and this is
  thread-safe.
- timer intervals can be changed at run-time.

This all then gets used to reset the proof timer immediately upon
receiving a ping (initially or after expiring) from storage server and
lokinet so that we send proofs out faster.
2019-12-26 12:29:05 -04:00
Jason Rhinelander
6e436c29b7
Merge pull request #991 from jagerman/v6-release-fixes
Misc. fixes for 6.x
2019-12-26 12:27:40 -04:00
Jason Rhinelander
e3e4637a55 Blockchain/tx_pool/batch lock fix
Blockchain::prepare_handle_incoming_blocks locks m_tx_pool, but uses a
local RAII lock on the blockchain object itself, then also starts a
batch.  Blockchain::cleanup_handle_incoming_blocks then also takes out a
local RAII blockchain lock, then cleans up the batch.

But the lmdb layer is retarded in that it throws an exception if any
thread tries to write to the database while a batch is active in another
thread, and so the blockchain lock is *also* used as a guard writes.
Holding an open batch but *not* holding the blockchain lock then hits
this exception if a write arrives in another thread at just the right
time.

This is, of course, terrible design at multiple layers, but this close
to release I am reluctant to make more drastic fixes.

Other small changes here:

- All the locks in `blockchain.cpp` now use tools::unique_lock or
  tools::unique_locks rather than the nasty epee macro.  This also
  reduces the likelihood of accidental deadlock because this means the
  dual txpool-blockchain locks are not taken out simultaneously via
  std::lock rather than sequentially.

- Removed a completely useless "if (1)".  Git blame shows that there was
  previously a condition here, but apparently the upstream monero author
  who changed it was afraid of removing the `if` keyword.

- Reduced the sleep in the loop that waits for a batch to 100ms from
  1000ms because sleeping for a full second for a fairly light test is
  insane.

- boost isn't happy calling boost::lock() on the tx pool or blockchain
  object because the lock/unlock/try_lock methods are const, and so the
  workaround of using boost::lock because std::lock and
  std::shared_time_mutex are broken on the macOS SDK 10.11 that we use
  for mac builds now requires extra workarounds.  Joy.
2019-12-26 12:26:03 -04:00
Jason Rhinelander
38a4240c71 Avoid long-deprecated boost::sleep
Also don't return a completely useless bool.
2019-12-26 12:26:03 -04:00
Jason Rhinelander
279c993924 de-constexpr for xenial 2019-12-26 12:26:03 -04:00
Jason Rhinelander
8ddaf49d24 Disambiguate write txn error message
There's no way to know which of this was fired (the one above, in the
same function, has identical wording).
2019-12-26 12:26:03 -04:00
Jason Rhinelander
9bd15fe5c7
Merge pull request #990 from jagerman/depends-fixes
Depends fixes
2019-12-23 23:32:06 -04:00
Jason Rhinelander
bbdc96b4b7 Another macOS workaround 2019-12-23 15:27:51 -04:00
Jason Rhinelander
a8d4887bb8 Remove unneeded patch 2019-12-23 15:09:45 -04:00
Jason Rhinelander
63b52422f6 macos workaround: use boost::shared_mutex
The MacOSX 10.11 SDK we use is broken AF: it lies about supporting
C++14, but really only upgraded the headers but not the library itself,
so using std::shared_timed_mutex just results in a linking failure.

Upgrading the SDK is a huge pain (I tried, failed, and gave up), so for
now temporarily switch to boost::shared_mutex until we sort out the
macOS build disaster.
2019-12-23 15:02:20 -04:00
Jason Rhinelander
150850c148 openssl depends makefile fix 2019-12-22 22:52:11 -04:00
Howard Chu
dc0d2462fd "Fix" non-determinism in native_cctools build
By omitting the otool binary which is built non-deterministically.
We don't use it anyway.
2019-12-22 22:41:27 -04:00
Howard Chu
cfc94b9ede Fix unwind library ordering
Sort objects being archived
2019-12-22 22:41:06 -04:00
Howard Chu
6a0d18e102 Fixup sodium darwin
get rid of sodium-darwin.mk special case, unify back with sodium.mk
2019-12-22 22:40:36 -04:00
Howard Chu
e8cc7bfaad Add ARFLAGS
Needed to invoke deterministic mode on some archivers
2019-12-22 22:39:55 -04:00
Howard Chu
200a9efc51 depends: Add FreeBSD support 2019-12-22 22:37:36 -04:00
Howard Chu
2e8cdab270 Add Android support 2019-12-22 22:33:27 -04:00
hyperreality
f768f4e016 Fix Travis build on Windows + Mac
Following 13c0b8c, the unwind package is being attempted to be built on
Windows and Mac when it should only be built on Linux.
2019-12-22 22:24:05 -04:00
TheCharlatan
75fddd37e7 Add depends riscv 64 bit support 2019-12-22 22:24:00 -04:00
Jason Rhinelander
1422139736
Merge pull request #989 from jagerman/lib-fixes
Fix contrib/depends library incompatibilities
2019-12-19 20:41:33 -04:00
Jason Rhinelander
c0a2f0b88c Fix type disagreement (size_t vs uint64_t) 2019-12-19 20:39:59 -04:00
Jason Rhinelander
055b593237 Fix contrib/depends library incompatibilities
sodium and zmq libs weren't using the same variable name which would end
up linking to system libsodium even when we meant to link to the static
one from contrib/depends.
2019-12-19 20:24:38 -04:00
Jason Rhinelander
ac784faeb3 Don't print worker_index when not an obligations vote (#987)
DEBUG is printing:

    Signature accepted for checkpointing voter n/<pubkey> voting  for worker NNNNN at height H

where NNNNN is some random 16-bit number.
2019-12-19 09:40:49 +10:00
Jason Rhinelander
19c562f800 Vote serialization compatibility fix (#984)
quorum_vote_t's were serialized as blob data, which is highly
non-portable (probably isn't the same on non-amd64 arches) and broke
between 5.x and 6.x because `signature` is aligned now (which changed
its offset and thus broke 5.x <-> 6.x vote transmission).

This adds a hack to write votes into a block of memory compatible with
AMD64 5.x nodes up until HF14, then switches to a new command that fully
serializes starting at the hard fork (after which we can remove the
backwards compatibility stuff added here).
2019-12-17 10:47:12 +10:00
Jason Rhinelander
5d0b568709 Sort print_sn checkpoint votes (#985)
Checkpoint votes internally use a circular buffer, but that's rather
difficult to read for the `print_sn` output; this changes print_sn to
de-circularize the listed votes.
2019-12-17 10:28:26 +10:00
Jason Rhinelander
fab8ded246 Cleanup on block adding failure (#983)
If a block adding fails (triggering the "Block added hook signalled
failure" error message) the service node list doesn't get reset, which
immediately leads to a bad service node winner (because the winner was
already incremented and not popped off).

This updates it to call the blockchain detached hooks to do the cleanup.

It also changes around loki::defer a little bit to rename the internal
class to `deferred` and make it cancellable (by calling `.cancel()`).
`loki::defer` is repurposed as a free function to get a named `deferred`
object given a lambda, which is needed to be able to call `cancel()` on
it.  (The LOKI_DEFER macro still works as is).
2019-12-16 08:49:35 +10:00
Jason Rhinelander
78ded3af70 Do txn handling via TXN_BLOCK_PREFIX macro (#982)
The macro handles the case where we can be called from either inside or
outside a block batch transaction.
2019-12-16 08:44:53 +10:00
Doyle
01dd6484be
Merge pull request #981 from jagerman/quorumnet-backtalk-guard
Quorumnet backtalk guard
2019-12-13 14:29:58 +10:00
Jason Rhinelander
8ec77ef546 Add is_service_node()
It wasn't immediately obvious why checking `listener` means we're a
service node, so make it more explicit via an abstraction method.
2019-12-12 23:53:08 -04:00
Jason Rhinelander
608cb76d0e register_command: switch arg order; drop std::function
The argument order felt wrong: switch it to (NAME, TYPE, FUNC)

Since register_command is meant to be called statically there is little
purpose in being able to accept a non-function-pointer callback (i.e.
direct function or capture-less lambda), so drop using std::function<>'s
for command callbacks to avoid the virtual call overhead.
2019-12-12 23:36:04 -04:00
Jason Rhinelander
9cd4615b35 Abstract assert + reinterpret_cast 2019-12-12 23:35:05 -04:00
Doyle
85185340f0 Guard against null ptr deref on quorumnet layer
This can be abused by Service Nodes specifying normal daemon IP's not
running in Service Node mode causing a crash.
2019-12-12 23:02:48 -04:00
Jason Rhinelander
a1db78239d SNNetwork: make quorum commands tri-state
Changes commands from two types (quorum & public) to three:
- anyone -> service node (SNNetwork::command_type::public_)
- service node -> anyone (SNNetwork::command_type::response)
- service node -> service node (command_type::quorum)

Previously quorum commands could be issued to non-SN nodes, but that
should not be allowed (and the code would dereference a nullptr if that
happened).
2019-12-12 22:58:53 -04:00
Doyle
54333e5b49
Merge pull request #978 from jagerman/another-deadlock-fix
Another deadlock fix
2019-12-12 16:08:24 +10:00
Jason Rhinelander
7eca201eb5 Admit defeat for now: use boost::lock
macOS's std::lock() is broken in that it internally calls non-namespaced
function `try_lock` leading to an ADL conflict with boost::try_lock when
any of the arguments is a `boost::whatever`.  `boost::lock` will do the
job for now.
2019-12-12 01:35:35 -04:00
Jason Rhinelander
0538f6aa7d Attempted fix to make macOS clang happy 2019-12-12 01:05:42 -04:00
Jason Rhinelander
8b1df0ef4c Fix deadlock
The m_blockchain lock added in #975 was causing deadlocks because we
have ordered `m_blockchain -> ... -> m_sn_mutex` lock sequences but
`proof.store()` was adding a `m_sn_mutex -> ... -> m_blockchain`
sequence when called when receiving an uptime proof.  Fix it by also
taking out an m_blockchain lock where we take out the `m_sn_mutex`.
2019-12-11 23:29:52 -04:00
Jason Rhinelander
55bd5941aa Add helper header/func to obtain unique locks
auto locks = tools::unique_locks(mutex1, mutex2, ...);

gives you a tuple of unique_locks and obtains the locks atomically.

    auto lock = tools::unique_lock(lock1);

is essentially the same as:

    std::unique_lock<decltype(lock1)> lock{lock1};

but less ugly (and extends nicely to the plural version).
2019-12-11 23:28:05 -04:00
Jason Rhinelander
7c3dc58f8c Simplify and avoid uninitialized value warning (#976)
* Simplify and avoid uninitialized value warning

Rearranging/simplifying this code slightly to avoid gcc giving a
possibly-uninitialized value use on the dereference that follows this
changed code.

* More simplification: don't need optional
2019-12-12 11:05:09 +10:00
Doyle
b45d2b825b
Merge pull request #975 from jagerman/db-lock
Work around broken database interface/fix deadlock
2019-12-12 08:57:35 +10:00
Jason Rhinelander
19f59acfd8 Work around broken database interface
Apparently it's not safe to use "transactions" in the LMDB without first
taking out an exclusive lock on the Blockchain class.  Transactions
apparently aren't actually transactions, they are just fatal errors that
forever deadlock the database if you try to take two write transactions
at once.

Work around this terrible design by adding the appropriate magic
incantation.
2019-12-11 11:51:36 -04:00
Doyle
0e690e5394
Merge pull request #973 from Doy-lee/Gcc5.5Fix
Fix GCC 5.5 not being smart about evaluating dead branches
2019-12-11 15:21:30 +10:00
Doyle
0f2f01c43a Fix GCC5.5 not being smart about evaluating dead branches
src/quorumnet/bt_serialize.h: In instantiation of 'void quorumnet::detail::bt_deserialize<T, typename std::enable_if<std::is_integral<_Tp>::value, void>::type>::operator()(std::istream&, T&) [with T = long unsigned int; typename std::enable_if<std::is_integral<_Tp>::value, void>::type = void; std::istream = std::basic_istream<char>]':
src/quorumnet/bt_serialize.cpp:107:17:   required from here
src/quorumnet/bt_serialize.h:161:75: error: logical 'or' of collectively exhaustive tests is always true [-Werror=logical-op]
if (sizeof(T) < sizeof(int64_t) && (read.first.i64 < smin || read.first.i64 > smax))
2019-12-11 16:17:28 +11:00