Commit graph

7389 commits

Author SHA1 Message Date
Doyle
91d9783487 Turn plain enums into enum-struct in loki name system 2020-02-13 11:07:46 +11:00
Doyle
4e09eda234 Be consistent with identifier quoting in SQLite 2020-02-13 11:07:46 +11:00
Doyle
a22157862b Update txtype activation hardforks 2020-02-13 11:07:46 +11:00
Doyle
41c51db583 Remove subsystems selection because we don't use it anymore 2020-02-13 11:07:46 +11:00
Doyle
70979fbeba Fix requirement to 30, and actually do the atomic step 2020-02-13 11:07:46 +11:00
Doyle
1093bab034 Send LNS values as blobs to the blockchain 2020-02-13 11:07:46 +11:00
Doyle
cb955c1952 Fix travis CI complaint about mapping_type not declared 2020-02-13 11:07:46 +11:00
Doyle
2962e27400 Update LNS burn to 15 loki, add tests to check burns 2020-02-13 11:07:46 +11:00
Doyle
a531f3fb90 Remove and undo some changes for github diffs 2020-02-13 11:07:46 +11:00
Doyle
9f3c97881e Force all incoming LNS txs to represent values as hex in the name->value mapping 2020-02-13 11:07:46 +11:00
Doyle
cc2e65db49 Improve error messaging for LNS txes 2020-02-13 11:07:46 +11:00
Doyle
658db0c3f1 Add query LNS mappings to the CLI wallet 2020-02-13 11:07:46 +11:00
Doyle
c7c32896fd Remove unused function rescan_starting_from_curr..
This has been combined into load_missing_blocks_into_loki_subsystem
which also handles loading blocks into LNS, but doesn't handle rescanning yet.
2020-02-13 11:07:46 +11:00
Doyle
632f6a6e83 Rebase fix, blink_lns -> blink, v15 and reserve types for protocol 2020-02-13 11:07:46 +11:00
Doyle
0b3df6c5ad Remove owner signature from loki name service tx extra
We want to allow people to buy LNS entries on behalf of other users. If
this is the case we don't need signatures to verify that the purchaser
knows the secret key. What we actually want in this scenario is that,
there's a LNS entry, and people can voluntarily pay to renew/buy that.
2020-02-13 11:07:46 +11:00
Doyle
766ea613ed Implement rpc, get_mappings_by_user 2020-02-13 11:07:46 +11:00
Doyle
d0bcaef852 LNS rpc get_lns_[owner|name]_mapping, stub get_mappings_by_user 2020-02-13 11:07:46 +11:00
Doyle
b78587c7b1 Handle duplicate LNS txs that are not checkpointed yet 2020-02-13 11:07:46 +11:00
Doyle
2a4009362e Remove extra LNS add_block call, incoporated into load_missing_blocks 2020-02-13 11:07:46 +11:00
Doyle
93f8bfb200 Fix rebase onto dev (blink) error 2020-02-13 11:07:46 +11:00
Doyle
6ef52ea940 Initialise DB from the immutable checkpoint height 2020-02-13 11:07:46 +11:00
Doyle
4340813d4b Check duplicate LNS entries via the name not the value 2020-02-13 11:07:46 +11:00
Doyle
7d259d47ff Verify LNS burn amounts and fix up tests to use burns 2020-02-13 11:07:46 +11:00
Doyle
aedd3675e7 Add lokinet domain name validation 2020-02-13 11:07:46 +11:00
Doyle
f17ed52182 Add buy lns rpc wallet, and wallet cli commands 2020-02-13 11:07:46 +11:00
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