Commit graph

7364 commits

Author SHA1 Message Date
Doyle
c19dad418b Formatting: loki_name_system_db -> loki_name_system, cold_sign_tx arg const 2020-02-13 11:07:46 +11:00
Doyle
7096726c40 Validate wallet addresses given in LNS txs 2020-02-13 11:07:46 +11:00
Doyle
e71962f3dc Remove block indirection in chain gen, support null lns_db for tests 2020-02-13 11:07:46 +11:00
Doyle
8785ef90fe Don't check lns heights unless both begin/end requested
Check that lns_end_height is non-zero, to see if it's valid to process
blocks in the LNS subsystem. Otherwise, the start_height of LNS can
potentially override the start height, but, LNS won't process any of
blocks causing the message that multiple blocks are being processed
into Loki subsystems every block.
2020-02-13 11:07:46 +11:00
Doyle
0be62f0aa2 Remove edkeys from account, wallet does something funky
The wallet does something funky with the key storage that the
values have changed, even after decrypting the wallet keys. The ed keys are
different from when we originally derived them, so for now, just re-derive
2020-02-13 11:07:46 +11:00
Doyle
6fbdb7bdcb Add support for Loki Name Service on the backend 2020-02-13 11:07:46 +11:00
Doyle
d33c937dd4 Start move away from hooks, combine rescanning of lns and snl to one function
Call service_node_lists's block added hook function manually instead of
hooking the hook. There's a common operation between the 2 subsystems,
Loki Name Service and Service Node List, in which they generate state
based off incoming blocks from the blockchain.

Upon profiling, the slowest factor of this is retrieving the blocks from
the DB in batches of a 1000 rather than the processing of the blocks in
the subsystems. So flatten out the hierarchy so that we can retrieve the
batch and simultaneously process the blocks in both subsystems on the
same fetch request.

A complete removal of the hook system so we have more flexibility at the
callsite can be done in a later PR, to avoid too many unneccesary
changes in the LNS PR.
2020-02-13 11:07:46 +11:00
Doyle
044c318cbd Add logging macros, add IF NOT EXIST qualifier to unique index 2020-02-13 11:07:46 +11:00
Doyle
8fc37f5246 Implement expiration/renewal of lokinet entries 2020-02-13 11:07:46 +11:00
Doyle
dc69d237e6 Add support for Loki Name Service on the backend 2020-02-13 11:07:46 +11:00
Doyle
e1893a1513 Distinguish staking transactions and revamp construct_tx 2020-02-13 11:07:46 +11:00
Sean
56d64a5a25
Creates a default address for the sweep_all command in the cli wallet (#1031)
* Creates a default address for the sweep_all command in the cli wallet

Previously the sweep all command required the user pass in the wallet
address for it to function. This commit allows for no address to be
passed in which case the software will use the same address that the
address command produces.

* Rename variable to addr, only call wallet if needed and update usage statements

* modify locked blocks parameters after making address optional

* removed log file and single sweep description

* updated the help descriptions for the 3 affected commands
2020-02-12 09:09:22 +11:00
Doyle
cedcc30911
Fix testing in quorum check, find_index_in_quorum_group(..) >= 0 (#1029) 2020-02-03 09:36:13 +11:00
Sean Darcy
243a73c47a modifies the print function so terminal bright mirrors the emphasis parameter
Previously the loki-wallet-rpc print function set the bright parameter in set_console_color(int color, bool bright) to true when its emphasis parameter was false. This changes the bright flag so it mirrors the emphasis flag.
2020-02-01 03:08:45 -04:00
Doyle
de3eef1619
Update v6 patch to 4 (#1023) 2020-01-20 12:38:54 +11:00
Doyle
bb39a51b4b
Merge pull request #1021 from jagerman/blink-lock-fixes
Blink lock fixes
2020-01-20 10:47:24 +11:00
Doyle
1be86c5813
Merge pull request #1020 from jagerman/misc-rpc-fixes
wallet: don't use pool tx list from long polling
2020-01-20 10:29:03 +11:00
Jason Rhinelander
58a1494559 Add systemd notify & watchdog support (#1022)
This enables optional support for systemd notification which allows
lokid to be run via `Type=notify`, allowing it to better signal status
to systemd and enables systemd watchdog handling to restart if something
goes wrong.

Enabled here are:
- systemd watchdog ping every 10s
- systemd status update every 10s, so that `systemctl status loki-node`
  gives you a status line such as:

      Status: "Height: 450085, SN: active, proof: 15m12s, storage: 3m7s,  lokinet: 27s"
- initialization notification so that systemd can wait for
  and report on initialization status rather than just that the process
  has launched.
- shutdown notification

All of these require changing the service type to `Type=notify` in the
`[Service]` section of the systemd service file; enabling the watchdog
also requires adding a `WatchdogSec=5min` line in the `[Service]`
section.

The systemd support is optional and requires the libsystemd-dev package
to be built (and is probably not feasible at all for a static build).
2020-01-20 09:44:18 +11:00
Jason Rhinelander
0cd096fc22 Fix rare blink pool deadlock
cryptonote_protocol_handler calls `pool.get_blink(hash)` while already
holding a blink shared lock, which should have been
`pool.get_blink(hash, true)` to avoid `get_blink` trying to take its own
lock.

That double lock is undefined behaviour and can cause a deadlock on the
mutex, although it appears rare that it actually does.  If it does,
however, this eventually backs up into vote relaying during the idle
loop, which then stalls the idle loop so we stop sending out uptime
proofs (since that is also in the idle loop).

A simple fix here is to add the `true` argument, but on reconsideration
this extra argument to take or not take a lock is messy and error prone,
so this commit instead removes the second argument entirely and instead
documents which call must and must not hold a lock, getting rid of the
three methods (get_blink, has_blink, and add_existing_blink) that had
the `have_lock` argument.  This ends up having only a small impact on
calling code - the vast majority of callers already hold a lock, and the
few that don't are easily adjusted.
2020-01-18 22:29:26 -04:00
Jason Rhinelander
7017d0edd4 Don't use pool tx list from long polling
This fixes two issues: first when running with --disable-rpc-long-poll
the long poll isn't present, so the list of pool txes will always be
empty, which means unconfirmed_txs will get cleared on refresh because
they don't appear to be in the node's pool.  This makes us likely to
wind up with double spending failures on subsequent txes since we don't
know about the outgoing unconfirmed_tx anymore.

Secondly, it seems like there's a potential race condition here even
when long polling is enabled that can cause the same failure depending
on the timing of polling in the long poll thread (for example, if it
hits the 30s cooldown from a MAX_CONNECTIONS response), so just fixing
this for the no-long-polling case doesn't seem sufficient.

The previous (< v6.1.1) code didn't have this issue because the tx
construction and refreshing new pool data were synchronous.  (There is a
potential race condition if refresh requests span the node finding a new
block between the block refresh and the pool tx refresh, but that's
already handled in the code by requiring two refreshes before setting it
as unspent).

This reverts the old synchronous fetch-pool-txes behaviour on refresh so
that there is no window of opportunity with long polling for us to
prematurely treat unconfirmed_txs as failed/unspent.
2020-01-18 19:25:50 -04:00
Jason Rhinelander
2655fc958e set_daemon mutex fix and simplifications
set_daemon got changed to set the long polling daemon, but then this
later got removed but the extra logic (now unnecessary) remained.  This
(mostly) reverts it back to the simpler pre-rpc-long-poll code.

The lock here also looked later than it should be: elsewhere it is
guarding changes to m_daemon_address and m_daemon_login but in the
change above it was moved to not guard them anymore.
2020-01-18 16:02:03 -04:00
Jason Rhinelander
9720b79e13 Remove pre-HF14 code 2020-01-18 13:56:31 -04:00
Jason Rhinelander
3c2eeb972b Remove pre-HF14 p2p vote relaying command 2020-01-18 12:12:29 -04:00
Doyle
cb954af945
Merge pull request #1015 from Doy-lee/AndroidPatches
Android patches, add blink param for sending blobs on mobile
2020-01-16 13:37:12 +11:00
Doyle
8e5e68531f
Merge pull request #1016 from Doy-lee/LongPollingInMobile
Enable long polling for mobile targets
2020-01-16 13:37:05 +11:00
Doyle
f04a92b152 Enable long polling for mobile targets 2020-01-16 11:53:39 +11:00
Doyle
621e1a0824 Update blink priority to 5 2020-01-16 10:29:36 +11:00
Doyle
8b0d202ddc Add blink param for sending blobs to remote nodes for mobile 2020-01-15 12:25:15 +11:00
Doyle
773e9e1a8a Use old serialization for libc++ (android and apple)
The common factor here is libc++ being buggy, so just target all compile
targets using libc++.
2020-01-15 12:25:15 +11:00
Doyle
40af332219
Merge pull request #1012 from Doy-lee/WalletAPIHandleBlinkParam
Handle blink param in WalletAPI
2020-01-14 12:08:18 +11:00
Doyle
bdec5432cf
Merge pull request #1013 from jagerman/qnet-comm-fix
Quorumnet - fix premature x25519 cache expiry
2020-01-14 10:41:50 +11:00
Doyle
4b12fb779f Update virtual to override for wallet api 2020-01-14 10:26:23 +11:00
Doyle
10081b510d Handle blink param in WalletAPI 2020-01-14 10:25:35 +11:00
Jason Rhinelander
4b66a2858f Add public ping target to quorumnet
This allows writing a script to test quorumnet reachability and status
(i.e. recognized as SN or not).
2020-01-13 18:29:28 -04:00
Jason Rhinelander
bf13bbfb26 Quorumnet - fix premature x25519 cache expiry
x25519 -> pubkey cache entries weren't being updated on new but
unchanged proofs, so would eventually expire and cause SNs to stop
authenticating new quorumnet connections as being from SNs.
2020-01-13 13:53:00 -04:00
Doyle
b9cac73c5c Delay checking the long poll disable flag until m_wallet is init 2020-01-13 15:39:52 +11:00
Doyle
98fe4d7bf9 Add a flag to disable long polling on wallets 2020-01-10 15:51:32 +11:00
Doyle
c4309edf33 Regenerate the checkpoint table in lmdb
Updating the checkpoint table in place, something must have been done
incorrectly or some bug, such that querying MDB_LAST on the checkpoint
table returns not the latest expected checkpoint.

Pulling out all the old checkpoints, generating a new table and
reinserting them resolves this.
2020-01-10 15:23:55 +11:00
Doyle
467b704120 Update v6 patch to 3 2020-01-10 13:07:37 +11:00
Doyle
04f9721c8f Long polling QOL, handle errors gracefully avoid lock contention
Handle errors better when long polling is disabled instead of endlessly
spamming logs.

Avoid lock contention when set_daemon is called. Instead of immediately
affecting the long polling thread (which could be engaging the mutex
until RPC timeout, meaning the program stalls for that duration), update
the address on the next iteration of the long polling thread.

Wallets handle daemons that disable long polling better by sleeping.
2020-01-10 13:07:37 +11:00
Doyle
f1b35a9f68
Add missing initialiser for m_store_quorum_history (#1009) 2020-01-09 13:50:17 +11:00
Doyle
1b750a6c38
Service Node List reset, should reset all transient fields (#953)
* Service Node List reset, should reset all transient fields

* Don't clear proofs/x25519 map on reset for robustness
2020-01-09 13:38:18 +11:00
Jason Rhinelander
5489cbac86 Handle no blink quorum result gracefully (#1006)
Fixes a segfault if we get no quorum.
2020-01-09 12:54:22 +11:00
Doyle
b7dc6b5f77 Update v6 patch to 2 2020-01-08 13:19:15 +11:00
Doyle
82147ac9ca Fallback to old stream deserialization for mac targets
// NOTE: Compiling with a minimum Mac OSX API of 10.13 and generating
// a binary_archive with a one_shot_read_buffer, causes the following snippet
// to fail

explicit binary_archive(stream_type &s) : base_type(s) {
  stream_type::pos_type pos = stream_.tellg();
  stream_.seekg(0, std::ios_base::end);
  eof_pos_ = stream_.tellg();
  stream_.seekg(pos);
}

// In particular
// stream_.seekg(0, std::ios_base::end);
// eof_pos_ = stream_.tellg();

// A seekg followed by a tellg returns 0, no state flags are set on the io
// stream. So use the old method that copies the blob into a stringstream
// instead for APPLE targets.
2020-01-08 12:41:29 +11:00
Jason Rhinelander
1f3b8891f1 Fix 6.1.1 compilation (#1002)
`tools::wallet2::rpc_long_poll_timeout` was a static member declaration
without a definition, which isn't allowed before C++17 (although can
work depending on compiler optimizations).  Adding the definition in
wallet2.cpp isn't really an option (it would make core depend on the
wallet), so just move it to a constexpr static global (which is allowed
without a definition, even before C++17) in `rpc/` instead.
2020-01-08 09:56:00 +11:00
Doyle
03930a8cab
Update v6 patch to 1 (#1000) 2020-01-07 17:14:52 +11:00
Doyle
cef9cdc52c
Merge pull request #986 from Doy-lee/LongPoll
Wallet long polls for transactions in the pool
2020-01-07 17:14:37 +11:00
Doyle
f1e0dce9b0 Add wait for condition to check tx pool count 2020-01-07 17:14:17 +11:00
Doyle
bd4f33243a
Merge pull request #998 from Doy-lee/MigrateSignatures
Migrate old checkpoints to new aligned checkpoints data structure
2020-01-07 13:44:33 +11:00
Doyle
92e5fb0e3f Parameterize the number of long poll connections via rpc-long-poll-connections
Reduce the default to 16 connections
2020-01-07 13:36:07 +11:00
Doyle
136dbd0e4d
Include <stack> in rpc_command_executor, macOSX10.13 failure (#999) 2020-01-07 12:48:51 +11:00
Doyle
00d7a32261 Don't update tx pool cache unless long poll succeeded 2020-01-07 12:35:06 +11:00
Doyle
644557d44d Stop endlessly asking the user for password after refreshing 2020-01-07 12:35:06 +11:00
Doyle
6d71d2fd6e Rate limit long polling connections 2020-01-07 12:35:06 +11:00
Doyle
0ec0780fd9 Add long polling to wallet-rpc 2020-01-07 12:35:06 +11:00
Doyle
3009f8fff7 Add wallet long polling to wallet-cli 2020-01-07 12:35:06 +11:00
Doyle
6c553307d6 Add voter_to_signature padding for 32/64bit uniformity 2020-01-07 12:27:43 +11:00
Doyle
e44acab3aa Detect unaligned entries via record size, static assert record sizes 2020-01-07 11:10:13 +11:00
Doyle
04150fc9a1 Migrate old checkpoints to new aligned checkpoints data structure 2020-01-06 18:58:45 +11:00
Doyle
3589ed1f69
Byte calc for signatures uses post-endian converted number (#997) 2020-01-06 15:15:57 +11:00
Jason Rhinelander
73f116f000 Add blinks even if tx already known
We need to add incoming blink signatures even if we already received the
tx without blink signatures previously.
2019-12-26 16:03:05 -04:00
Jason Rhinelander
16288433ca Add hardfork at height 442333
Estimated time: Thu Jan  9 00:00:00 2020 UTC
2019-12-26 13:30:06 -04:00
Jason Rhinelander
edd8d0df4a
Merge pull request #988 from Doy-lee/Version610
Nimble Nerthus version update -> 6.1.0
2019-12-26 12:33:42 -04:00
Jason Rhinelander
7c69e41970 test code: add ability to trigger p2p resync
This is really useful for the blink test suite as it lets us trigger a
resync (which normally only runs every 60s).  In particular where we
have a (test) situation like this:

A - B - C

where we want to take down B and bring it up again but want to be sure
that new things learned from A get seen right away by C: if B does a
resync with C *before* it does a resync with A then C wouldn't get the
sync updates for a full minute, while if we force B to sync then force C
to sync we can ensure quick propagation for the test suite.
2019-12-26 12:29:05 -04:00
Jason Rhinelander
b51fd0c5db --regtest fixes and mine n blocks ability
`--regtest` didn't work in some edge cases, this fixes various things:

- the genesis block wasn't accepted because it needed to be v7, not
  vMax
- reduce initial uptime proof delay to 5s in regtest mode
- add --regtest flag to the wallet so that it can talk to a daemon in
  --regtest mode.

This also adds two new mining options, available via rpc:

- slow_mining - this avoids the RandomX initialization.  It is much
  slower, but for regtest with fixed difficulty of 1 that is perfectly
  fine.
- `num_blocks` - instruct the miner to mine for the given number of
  blocks, then stop.  (This can overmine if mining with multiple
  threads at a low difficulty, but that's fine).
2019-12-26 12:29:05 -04:00
Jason Rhinelander
d1e956653b Don't request too-high or fail on blinks while syncing
While we're syncing it's not uncommon to receive some mempool blinks
that we can't validate yet: the inputs may refer to outputs that we
don't know about yet, and we may not be able to construct the blink
quorum yet.  We don't want to cut off our peers if they sent something
just because we can't handle it yet, so don't drop_connection in such a
case.
2019-12-26 12:29:05 -04:00
Jason Rhinelander
eb0dfd64b0 Blink blockchain rollback fixes
Blockchain rollback conditions weren't being properly detected/handled.
2019-12-26 12:29:05 -04:00
Jason Rhinelander
f35ccbb450 Give second chance to peers
If a peer sends something invalid (i.e. a block containing a tx that
conflicts with a blink) we don't want to immediately close it because
the peer may be able to recover by rolling back, but in order to do that
it needs to be able to receive our blinks which (probably) won't happen
if it gets instantly close.  So require *two* attempts to close before
we actually close the p2p connection.
2019-12-26 12:29:05 -04:00
Jason Rhinelander
880907cd51 Blink-related debugging addition 2019-12-26 12:29:05 -04:00
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
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
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
bbdc96b4b7 Another macOS workaround 2019-12-23 15:27:51 -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
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
Doyle
abe085942d Update minor versrion to 1, set release name 2019-12-19 10:41:41 +11: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
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
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