Commit Graph

679 Commits

Author SHA1 Message Date
Thomas Eizinger
fc175a3f53
De-couple state from Monero wallet 2021-03-29 12:15:12 +11:00
Thomas Eizinger
42b6368298
Use full-qualified path for tracing macros
Saves an import line and makes it clear that we are using tracing.
2021-03-29 12:14:19 +11:00
Thomas Eizinger
5616683d7d
Monero confirmations are a u64
Trying to deserialize the number as a u32 caused deserialization
errors.
2021-03-29 12:14:19 +11:00
Thomas Eizinger
1b63d5486d
Move tick to the beginning of the loop
This ensures that we always wait for the provided interval, even in
the case of a `continue` which happens if there is an error within
the RPC call.
2021-03-29 12:14:19 +11:00
Thomas Eizinger
393ed45b9e
Say who we are in the --help message
The message now says:

swap 0.3.0
The COMIT guys <hello@comit.network>
CLI for swapping BTC for XMR

USAGE:
    swap [FLAGS] [OPTIONS] <SUBCOMMAND>

...
2021-03-26 14:31:14 +11:00
Thomas Eizinger
39b27e37d8
Delete empty file 2021-03-26 14:31:04 +11:00
rishflab
a3e85526c6 Specify LANG env variable for monero wallet rpc for unix systems
By specifying the language we can look for a specific string to check if
 monero wallet rpc is ready
2021-03-25 19:52:43 +11:00
rishflab
bc902ea63a Use language agnostic heuristic to check if monero_wallet_rpc is ready
Our strategy of searching for a english string to determine if
monero_wallet_rpc is ready is not compatible with languages other than
english. Instead we assume the monero rpc is ready if it has stopped
writing to stdout. We make a json rpc request to confirm this. A better
solution would have been to configure the monero_wallet_rpc to always
output in english but there is not command line argument to configure
the language.

Closes #353.
2021-03-25 18:13:06 +11:00
bors[bot]
7397cb5990
Merge #359
359: Bump bdk from 0.4.0 to 0.5.0 r=thomaseizinger a=dependabot[bot]

Bumps [bdk](https://github.com/bitcoindevkit/bdk) from 0.4.0 to 0.5.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/bitcoindevkit/bdk/blob/master/CHANGELOG.md">bdk's changelog</a>.</em></p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="f7944e871b"><code>f7944e8</code></a> Bump version to 0.5.0</li>
<li><a href="2fea1761c1"><code>2fea176</code></a> Bump deps version</li>
<li><a href="fa27ae210f"><code>fa27ae2</code></a> Update version in lib.rs</li>
<li><a href="46fa41470e"><code>46fa414</code></a> Update CHANGELOG with the new release tag</li>
<li><a href="8ebe7f0ea5"><code>8ebe7f0</code></a> Merge commit 'refs/pull/308/head' of github.com:bitcoindevkit/bdk into releas...</li>
<li><a href="eb85390846"><code>eb85390</code></a> Merge commit 'refs/pull/309/head' of github.com:bitcoindevkit/bdk into releas...</li>
<li><a href="dc83db273a"><code>dc83db2</code></a> better derivation path building</li>
<li><a href="201bd6ee02"><code>201bd6e</code></a> better derivation path building</li>
<li><a href="396ffb42f9"><code>396ffb4</code></a> handle descriptor xkey origin</li>
<li><a href="9cf62ce874"><code>9cf62ce</code></a> [ci] Manually install libclang-common-10-dev to 'check-wasm' job</li>
<li>Additional commits viewable in <a href="https://github.com/bitcoindevkit/bdk/compare/v0.4.0...v0.5.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=bdk&package-manager=cargo&previous-version=0.4.0&new-version=0.5.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-24 06:12:52 +00:00
bors[bot]
9c9b1e4f0c
Merge #370
370: No Bitcoin deposit for Alice r=da-kami a=da-kami

The message to deposit Bitcoin only applies to Bob, not Alice.
Alice does not require any initial Bitcoin.

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-03-24 05:03:19 +00:00
Thomas Eizinger
1057d115d1
Re-order bob::event_loop based on importance 2021-03-24 15:17:54 +11:00
Thomas Eizinger
638a169a04
Buffer transfer proof if we are not connected to Bob
The request-response behaviour that is used for sending the transfer
proof actually has a functionality for buffering a message if we
are currently not connected. However, the request-response behaviour
also emits a dial attempt and **drops** all buffered messages if this
dial attempt fails. For us, the dial attempt will very likely always
fail because Bob is very likely behind NAT and we have to wait for
him to reconnect to us.

To mitigate this, we build our own buffer within the EventLoop and
send transfer proofs as soon as we are connected again.

Resolves #348.
2021-03-24 15:17:54 +11:00
Thomas Eizinger
cde3f0f74a
Remove connection handling from swap execution
The swap should not be concerned with connection handling. This is
the responsibility of the overall application.

All but the execution-setup NetworkBehaviour are `request-response`
behaviours. These have built-in functionality to automatically emit
a dial attempt in case we are not connected at the time we want to
send a message. We remove all of the manual dialling code from the
swap in favor of this behaviour.

Additionally, we make sure to establish a connection as soon as the
EventLoop gets started. In case we ever loose the connection to Alice,
we try to re-establish it.
2021-03-24 15:17:54 +11:00
Daniel Karzel
1e2a3c2d32 No Bitcoin deposit for Alice
The message to deposit Bitcoin only applies to Bob, not Alice.
Alice does not require any initial Bitcoin.
2021-03-24 11:51:25 +11:00
Thomas Eizinger
804b34f6b0
Listen on all swarm events instead of just behaviour events 2021-03-24 11:39:41 +11:00
Thomas Eizinger
2200fce3f3
Pass Swarm into EventLoop
This reduces the amount of arguments we need to pass into the eventloop
at the expense of slightly more setup of the swarm.
2021-03-24 11:39:41 +11:00
Thomas Eizinger
2c9ab4f6eb
Improve code structure and error messages for running swaps
The quote message was repeated and we should set the overall
failure into a context to know what went wrong.
2021-03-24 11:39:41 +11:00
Thomas Eizinger
0c0a322a8f
Rename module to better represent what it contains
This module provides an implementation of the RequestResponseCodec
using a cbor serialization.
2021-03-24 11:39:40 +11:00
Thomas Eizinger
1de0b39b32
Unify encrypted-signature protocol to a single one 2021-03-24 11:39:40 +11:00
Thomas Eizinger
9979cc9f1f
Unify transfer-proof protocol to a single one
Previously, we had two implementations of this protocol. To reduce
code size, we make Alice and Bob use the same implementation.
2021-03-24 11:39:40 +11:00
Thomas Eizinger
9d0b9abde0
Introduce helper function for mapping RequestResponseEvent
Decomposing a RequestResponseEvent is quite verbose. We can introduce
a helper function that does the matching for us and delegates to
specific `From` implementations for the protocol specific bits.
2021-03-24 11:39:39 +11:00
Thomas Eizinger
73f30320a6
Seed should neither be Clone nor Copy
It is better to not copy around secret data within our process to
make heartbleed-like attacks harder.
2021-03-24 11:39:39 +11:00
Thomas Eizinger
96b2a76971
Take advantage of upgraded electrum-client dependency
The new version implements std::error::Error and fixes a bug that
allows us to use the default config again.
2021-03-23 14:57:27 +11:00
bors[bot]
968502827a
Merge #339
339: Bump dependency versions r=thomaseizinger a=thomaseizinger

Otherwise it will take a long time for dependabot to update all of
these.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-23 00:09:49 +00:00
bors[bot]
097197783c
Merge #351
351: Show the actual BTC amount and fee to be swapped r=da-kami a=da-kami

We got user feedback, that it is confusing that the amount "found" in the wallet does not match the amount actually being swapped, thus with this PR we explicitly display the amount swapped and fees.

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-03-22 23:42:31 +00:00
bors[bot]
189a13c063
Merge #319
319: Alice sweeps refunded funds into default wallet r=da-kami a=da-kami

Alice's refund scenario starts with generating the temporary wallet
from keys to claim the XMR which results in Alice' unloading the wallet.
Alice then loads her original wallet to be able to handle more swaps.
Since Alice is in the role of the long running daemon handling concurrent
swaps, the operation to close, claim and re-open her default wallet must
be atomic.
This PR adds an additional step, that sweeps all the refunded XMR back into
the default wallet. In order to ensure that this is possible, Alice has to
ensure that the locked XMR got enough confirmations.
These changes allow us to assert Alice's balance after refunding.

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-03-22 05:12:49 +00:00
Daniel Karzel
62079fc342 Punish scenario falls back to refund or fails
If we enter a punish scenario we can be sure the punish timelock is expired.
Thus, we must be able to punish unless Bob published the refund transaction.
There is no benefit in racing punish against refund here, because we cannot recover from a punish tx failure anyway.

The logic was changed to:
Try to broadcast punish tx and await finality.
  If either punish broadcasting of finality fails, try to fetch the refund transaction.
    If it is available extract Bob's Monero key part and transition to refund.
    If refund tx is not available fail without a status update.

Note that we do not distinguish different errors upon failure of punish, because
we cannot recover anyway. If we fail to retrieve Bob's refund tx, we just exit without
a status update so punish can be retried by resuming the swap.
2021-03-22 16:10:01 +11:00
Thomas Eizinger
a228349d8b
Bump dependency versions
Otherwise it will take a long time for dependabot to update all of
these.
2021-03-22 14:48:39 +11:00
Daniel Karzel
668d34080d Show the actual BTC amount and fee to be swapped 2021-03-19 17:40:14 +11:00
Thomas Eizinger
f49f8977d3
Remove dead code 2021-03-18 18:09:30 +11:00
Daniel Karzel
396c4177a6 Alice sweeps refunded funds into default wallet
Since Alice's refund scenario starts with generating the temporary wallet
from keys to claim the XMR which results in Alice' unloading the wallet.
Alice then loads her original wallet to be able to handle more swaps.
Since Alice is in the role of the long running daemon handling concurrent
swaps, the operation to close, claim and re-open her default wallet must
be atomic.
This PR adds an additional step, that sweeps all the refunded XMR back into
the default wallet. In order to ensure that this is possible, Alice has to
ensure that the locked XMR got enough confirmations.
These changes allow us to assert Alice's balance after refunding.
2021-03-18 17:59:48 +11:00
Thomas Eizinger
16dfea035b
Simplify code within BobState::XmrLockProofReceived
To achieve this, we decompose `watch_for_locked_xmr` into two parts:

1. A non-self-consuming function to construct a `WatchRequest`
2. A state transition that can now consume `self` again because
it is only called once within the whole select! expression.

Ideally, we would move more logic onto this state transition (like
comparing the actual amounts and fail the transition if it is not
valid). Doing so would have an unfortunate side-effect: We would
always wait for the full confirmations before checking whether or
not we actually receive enough XMR.

This allows us to have state transitions that consume self.
2021-03-18 15:45:58 +11:00
Thomas Eizinger
338f4b82e5
Introduce dedicated bob::State6 for cancelling 2021-03-18 15:45:57 +11:00
Thomas Eizinger
c32ef92cf5
Simplify code within BobState::EncSigSent 2021-03-18 15:45:57 +11:00
Thomas Eizinger
09e2d5b5d7
Simplify code within BobState::XmrLocked
By reducing the number of local variables, we can greatly simplify
this piece of code.
2021-03-18 15:45:57 +11:00
Thomas Eizinger
776a50137d
Use tokio::select macro instead of function
This is slightly less verbose and therefore hopefully easier to read.
2021-03-18 15:45:56 +11:00
Thomas Eizinger
b1affe3ecf
Insert latest state and call run_until only once
Instead of calling this function in all the branches, we can simply
make the whole match statement evaluate to the new state and perform
this functionality at the very end.
2021-03-18 15:45:56 +11:00
Thomas Eizinger
0d8962762a
Use early return to reduce one level of indentation 2021-03-18 15:45:55 +11:00
Thomas Eizinger
05849505b1
Inline wait_for_bitcoin_refund
This function is essentially a single select! statement and can
easily be inlined into the swap state machine.
2021-03-18 15:45:39 +11:00
Thomas Eizinger
8c9285f1f9
Inline step function because it has been reduced to a single statement 2021-03-18 15:45:36 +11:00
Thomas Eizinger
afb7e816a1
Don't wait for confirmations again
We only call this function within `CancelTimelockExpired`. There is
no need to check the confirmations again.
2021-03-18 15:44:37 +11:00
Thomas Eizinger
c92f2dbc77
Move more domain knowledge onto the TxCancel type 2021-03-18 15:44:37 +11:00
Thomas Eizinger
75aec95b0c
Introduce monero::TransferRequest
This allows us to move critical crypto logic onto `State3` which
holds all the necessary data which consequently allows us to get
rid of `lock_xmr` altogether by inlining it into the swap function.
The reduced indirection improves readability.
2021-03-18 15:44:36 +11:00
Thomas Eizinger
d682433ec9
Move EventLoopHandle next to its impl block
This struct is not that important so it can move further down.
2021-03-18 15:44:36 +11:00
Thomas Eizinger
e77f1729b4
Move extract_monero_private_key onto TxRefund
This functionality is domain-specific to the refund transaction.
Move it onto there.
2021-03-18 15:44:36 +11:00
Thomas Eizinger
a1e065b4e7
Simplify racing cancel timelock against learning enc-sig 2021-03-18 15:44:36 +11:00
Thomas Eizinger
575893fb51
Use domain types in fn signature instead of messages
This simplifies usage witin the swap module.
2021-03-18 15:44:35 +11:00
Thomas Eizinger
64b71d0b16
Remove unnecessary pinning 2021-03-18 15:44:31 +11:00
Daniel Karzel
105e291e67 Update the application name for --version print
swap --version
xmr-btc-swap 0.3.0

asb --version
xmr-btc-asb 0.3.0
2021-03-18 12:24:10 +11:00
bors[bot]
2c385ee7d9
Merge #321
321: Properly handle concurrent messages to and from peers r=thomaseizinger a=thomaseizinger

Previously, we were forwarding incoming messages from peers to all
swaps that were currently running. That is obviously wrong. The new
design scopes an `EventLoopHandle` to a specific PeerId to avoid
this problem.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-17 10:22:26 +00:00
bors[bot]
113f2fa385
Merge #322
322: Refactor `ExecutionParams` and harmonize sync intervals of wallets r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-17 06:25:59 +00:00
bors[bot]
fc28609a96
Merge #323 #324
323: Minor fixes r=thomaseizinger a=rishflab



324: Enable dependabot r=thomaseizinger a=thomaseizinger



Co-authored-by: rishflab <rishflab@hotmail.com>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-17 05:59:01 +00:00
Thomas Eizinger
e54d26b26c
Improve log messages by including PeerId 2021-03-17 16:32:19 +11:00
Thomas Eizinger
a57f88d1b4
Properly handle concurrent messages to and from peers
Previously, we were forwarding incoming messages from peers to all
swaps that were currently running. That is obviously wrong. The new
design scopes an `EventLoopHandle` to a specific PeerId to avoid
this problem.
2021-03-17 16:32:17 +11:00
Thomas Eizinger
ce78075932
Make Monero and Bitcoin wallet use a generalized sync interval
We define the sync interval as 1/10th of the blocktime. For the
special case of our tests, we however check at max once per second.
The tests have a super fast blocktime. As such we shouldn't hammer
the nodes with a request every 100ms.
2021-03-17 16:31:17 +11:00
Thomas Eizinger
09c41f89c4
Rename ExecutionParams to EnvironmentConfig 2021-03-17 16:31:16 +11:00
Thomas Eizinger
bc43ed6ebd
Pass execution params directly into wallet for initialization
This reduces the amount of parameters that we need to pass in.
2021-03-17 16:30:58 +11:00
Thomas Eizinger
7213907a79
Group bitcoin and monero fields together 2021-03-17 16:30:58 +11:00
bors[bot]
95acbc6277
Merge #307
307: Reduce load on electrum r=thomaseizinger a=rishflab

.

Co-authored-by: rishflab <rishflab@hotmail.com>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-17 05:10:50 +00:00
rishflab
8675d88727 Don't wait for tx lock confirmed after broadcast
Bob does not care whether tx lock is confirmed. That is alice's problem.
This wait was introduced to remedy a bug in status_of_script() which was
 failing when called on a transaction with no confirmations.
2021-03-17 15:34:29 +11:00
rishflab
f5e6ba18e0 Use different address for redeem and punish
Having the same address could potentially cause issues when subscribing
to transactions by script
2021-03-17 15:26:44 +11:00
bors[bot]
345bc5b316
Merge #320
320: Fix env filter for asb r=thomaseizinger a=thomaseizinger

1. The asb didn't log any if the statements within main.rs
2. We were initializing unnecessary filters that don't make any sense
for the asb. warp and http are not used and the harness-es are for
test only.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-17 03:51:18 +00:00
bors[bot]
9ed5ca9a04
Merge #317
317: Fix monero refresh interval r=thomaseizinger a=thomaseizinger

The comparison should be the MAXIMUM of the two values, not the
minimum, otherwise we always refresh at an interval of 1 second.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-17 02:38:46 +00:00
Thomas Eizinger
9e3a104b42
Disable timestamp if we log to a non-interactive terminal
A non-interactive terminal is likely something along the lines of
journalctl which captures a timestamp by itself. In theory, it could
also be just a logfile but we rather accept this limitation and keep
the configuration surface simple rather than exposing another config
switch.
2021-03-17 11:41:28 +11:00
Thomas Eizinger
edb8851ce2
Fix env filter for asb
1. The asb didn't log any if the statements within main.rs
2. We were initializing unnecessary filters that don't make any sense
for the asb. warp and http are not used and the harness-es are for
test only.
2021-03-17 11:21:05 +11:00
Thomas Eizinger
273cf15631
Introduce Watchable abstraction for Bitcoin wallet
We have a repeated pattern where we construct one of our
Tx{Cancel,Redeem,Punish,Refund,Lock} transactions and wait until
the status of this transaction changes. We can make this more
ergonomic by creating and implementing a `Watchable` trait that
gives access to the TxId and relevant script for this transaction.
This allows us to remove a parameter from the `watch_until_status`
function.

Additionally, there is a 2nd pattern: "Completing" one of these
transaction and waiting until they are confirmed with the configured
number of blocks for finality. We can make this more ergonomic by
returning a future from `broadcast` that callers can await in case
they want to wait for the broadcasted transaction to reach finality.
2021-03-16 19:24:32 +11:00
Thomas Eizinger
a0830f099f
Pass relevant execution params into wallet instead of via functions
The execution params don't change throughout the lifetime of the
program. They can be set in the wallet at the very beginning.
This simplifies the interface of the wallet functions.
2021-03-16 19:24:31 +11:00
Thomas Eizinger
84ea092a1b
Remove unnecessary state variables by constructing TXs on demand 2021-03-16 19:24:31 +11:00
rishflab
e5c0158597
Greatly reduce load onto the Electrum backend
We achieve our optimizations in three ways:

1. Batching calls instead of making them individually.

To get access to the batch calls, we replace all our
calls to the HTTP interface with RPC calls.

2. Never directly make network calls based on function
calls on the wallet.

Instead, inquiring about the status of a script always
just returns information based on local data. With every
call, we check when we last refreshed the local data and
do so if the data is considered to be too old. This
interval is configurable.

3. Use electrum's notification feature to get updated
with the latest blockheight.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Rishab Sharma <rishflab@hotmail.com>
2021-03-16 19:24:31 +11:00
Thomas Eizinger
e17cbadccb
Don't add signatures to transaction unless necessary
In order to compute the cancel TxID, we don't need to add the
signatures.
2021-03-16 19:22:47 +11:00
Thomas Eizinger
6beb732e35
Eliminate build_bitcoin_punish_transaction
We reduce indirection by constructing TxPunish directly based off
`State3` and make the type itself more powerful by moving the logic
of completing it with a signature onto it.
2021-03-16 19:21:15 +11:00
Daniel Karzel
ea05c306e0 Alice spawns swaps outside the event loop
Instead of spawning the swap inside the event loop we send the swap back
to the caller to be spawned. This means we no longer need the remote handle
that was only used in the tests.
This now properly logs the swap results in production.
It also gives us more control over Alice's swap in the tests.
2021-03-16 18:31:46 +11:00
Thomas Eizinger
dd6c66a594
Move completing of Bitcoin redeem tx onto RedeemTx
This allows us to have access to RedeemTx from within the scope
of the state transition which we are going to need for more
efficient watching of what happens to this TX on the blockchain.
2021-03-16 17:11:31 +11:00
rishflab
21429f24b2
Inline wait_for_locked_bitcoin() that is only called once
Reduce indirection.
2021-03-16 17:11:31 +11:00
rishflab
6a3e4802f1
Remove redundant reference 2021-03-16 17:11:30 +11:00
rishflab
458a8d594a
Rename fn param to correctly reflect underlying type 2021-03-16 17:11:30 +11:00
Thomas Eizinger
2704245ed5
Fix monero refresh interval
The comparison should be the MAXIMUM of the two values, not the
minimum, otherwise we always refresh at an interval of 1 second.
2021-03-16 17:10:34 +11:00
Daniel Karzel
0091b6cdaf Remove CLI config file in favour of parameters
The CLI has sensible default values for all parameters,
thus a config file is not really an advantage but just
keeps getting in our way, so re remove it.
2021-03-15 15:41:46 +11:00
bors[bot]
009597ac49
Merge #306
306: Fix logging and retrying of Monero transaction watching r=thomaseizinger a=thomaseizinger

Hopefully, this should also reduce the load because I am not asking the node every second.

Related: https://github.com/comit-network/xmr-btc-swap/issues/202

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-03-11 07:50:54 +00:00
Daniel Karzel
be52892e65
Monero wallet should not know about all execution params
Instead of passing all execution params in we only make the monero_avg_block_time known to the monero wallet.
2021-03-11 17:43:01 +11:00
Thomas Eizinger
82738b111e
Refactor monero::Wallet::watch_for_transfer to not use backoff
Instead, we use a regular loop and extract everything into a function
that can be independently tested.
`backoff` would be useful to retry the actual call to the node.
2021-03-11 17:42:54 +11:00
Thomas Eizinger
7e0c44ad1d
Add avg monero block time to execution params 2021-03-11 15:01:55 +11:00
Thomas Eizinger
d560e69203
Make durations more readable by using extension methods from time 2021-03-11 14:59:57 +11:00
Thomas Eizinger
ecff1d1cbe
Remove indirection of constants
We never use these constants anywhere else, inline them.
2021-03-11 14:57:47 +11:00
Thomas Eizinger
bac0f11898
Disable backoffs max_elapsed_time functionality
This config setting makes backoff stop retrying if we didn't get an
error within this timeframe.
For us, this results in backoff not actually doing anything.

The connection to kraken is very long-running. It might be active
for hours without failing. However, the default value for
`max_elapsed_time` is set to 15 minutes. As such, once the connection
fails any time after that, backoff doesn't actually retry the operation
but just gives up.

Fixes #303.
2021-03-11 13:33:46 +11:00
Thomas Eizinger
9ad2160c69
Refactor the kraken module to automatically re-connect on errors
In order to be able to re-connect on certain errors, we model
connection errors separately from parsing errors. We also change
the API of the whole module to no longer forward all errors to
the subscribers but instead, only update the subscribers with
either a latest rate or a permanent failure in case we exhausted
all our options to re-connect the websocket.

To model all of this properly, we introduce to sub-modules so that
each submodule can have their own `Error` type.

Resolves #297.
2021-03-09 17:37:37 +11:00
Thomas Eizinger
c560b3b21a
Introduce RateUpdate type alias to reduce duplication 2021-03-09 15:39:08 +11:00
Thomas Eizinger
fd5b38739a
Remove constant in favor of inlining string
This removes an import and simplifies the `connect_async` call.
2021-03-09 15:39:07 +11:00
Thomas Eizinger
142e5e2d3a
Use tracing macros by fully-qualifying them 2021-03-09 15:39:03 +11:00
bors[bot]
cc131ecf60
Merge #293
293: Some friday evening goodies r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-08 22:53:58 +00:00
Thomas Eizinger
08923a14f3
Simplify GET request for block tip height 2021-03-05 17:06:17 +11:00
Thomas Eizinger
e9d7d9299c
Simplify the GET request to the tx status URL 2021-03-05 16:56:48 +11:00
Thomas Eizinger
418ad7089d
Make tests more readable by following arrange-act-assert 2021-03-05 16:56:48 +11:00
Thomas Eizinger
c2329b19a2
Tell the user more about the monero lock transaction
First, we tell the user that we are now waiting for Alice to lock
the monero. Additionally, we tell them once we received the
transfer proof which will lead directly into the
"waiting for confirmations" function.
2021-03-05 16:56:47 +11:00
Thomas Eizinger
13c4d29d40
Tell the user immediately how many confirmations we expect
Without this, the user doesn't see a message before the first
confirmation.
2021-03-05 16:56:47 +11:00
Thomas Eizinger
4883e23dd8
Tell the user for how many confirmations we are waiting
Without this, the user has no idea for how long the program is
waiting.
2021-03-05 16:56:47 +11:00
Thomas Eizinger
5d4cf40831
Fix comparison of Monero confirmations 2021-03-05 16:56:46 +11:00
rishflab
f92a8ac300 Improve CLI help comments and "type" hints
The type hints are generated from the field names. This has the
unfortunate consequence of the config field becoming file_path which
does not really make sense people working on the codebase.
2021-03-05 16:46:17 +11:00
Daniel Karzel
196557b377 Rename binary to swap 2021-03-05 16:14:21 +11:00
Daniel Karzel
f8b61e2e0e Make monero daemon host configurable 2021-03-05 16:10:45 +11:00