Commit Graph

74 Commits (620ac569f7db4b19c3dc761619e7a4d0ab0841dd)

Author SHA1 Message Date
Daniel Karzel c0070f8fa7
Move files from `protocol` to appropriate module
Some network and application specific code does not belong in the protocol module and was moved.
Eventloop, recovery and the outside behaviour were moved to the respective application module because they are application specific.

The `swap_setup` was moved into the network module because upon change both sides will have to be changed and should thus stay close together.
3 years ago
Daniel Karzel 818147a629
`swap_setup` instead of `spot_price` and `execution_setup`
Having `spot_price` and `execution_setup` as separate protocols did not bring any advantages, but was problematic because we had to ensure that `execution_setup` would be triggered after `spot_price`. Because of this dependency it is better to combine the protocols into one.

Combining the protocols also allows a refactoring to get rid of the `libp2p-async-await` dependency.

Alice always listens for the `swap_setup` protocol. When Bob opens a substream on that protocol the spot price is communicated, and then all execution setup messages (swap-id and signature exchange).
3 years ago
Thomas Eizinger ff8cd0ab93
Harmonise log statements between applications
The refactoring of the transport initialization removed the log statement
for the asb. We re-introduce this log statement in main for consistency.
3 years ago
Thomas Eizinger 90deb6451c
Rename swarm constructors to be per tool instead of per role 3 years ago
bors[bot] 5385fc1aa0
Merge #531 #535
531: Bump thiserror from 1.0.24 to 1.0.25 r=thomaseizinger a=dependabot[bot]

Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.24 to 1.0.25.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/dtolnay/thiserror/releases">thiserror's releases</a>.</em></p>
<blockquote>
<h2>1.0.25</h2>
<ul>
<li>Support <code>error(transparent)</code> on errors containing a non-<code>'static</code> inner error (<a href="https://github-redirect.dependabot.com/dtolnay/thiserror/issues/113">#113</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="19cb5cee4b"><code>19cb5ce</code></a> Release 1.0.25</li>
<li><a href="e49c10f2ba"><code>e49c10f</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dtolnay/thiserror/issues/134">#134</a> from dtolnay/nonstatic</li>
<li><a href="1ed8751081"><code>1ed8751</code></a> Support non-static AsDynError lifetimes</li>
<li><a href="51a1ff6593"><code>51a1ff6</code></a> Add regression test for issue 113</li>
<li><a href="ee2a47d3af"><code>ee2a47d</code></a> Adjust macro hygiene test formatting</li>
<li><a href="c610d97267"><code>c610d97</code></a> Update ui test suite to nightly-2021-05-14</li>
<li><a href="c10adbc25e"><code>c10adbc</code></a> Ignore manual_map clippy lint</li>
<li>See full diff in <a href="https://github.com/dtolnay/thiserror/compare/1.0.24...1.0.25">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=thiserror&package-manager=cargo&previous-version=1.0.24&new-version=1.0.25)](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>

535: Bitcoin network check when building PSBT r=da-kami a=da-kami

This ensures that funds are not sent to an address on the wrong network.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel 766ac706de
Application arg tests
Includes validation for given Bitcoin address against network.
3 years ago
bors[bot] baf5a0896e
Merge #536
536: Switch to using stable Rust instead of nightly r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger 8f9d612af2
Change to stable Rust 1.52
Fix clippy warnings that are new in this version.
3 years ago
TDevD 5da075f533 fix typo 3 years ago
Daniel Karzel cfa85e0bad
Simplify ASB initial setup signature 3 years ago
Daniel Karzel 7f8af7926d
ASB config may specify finality confirmations
By default the finality confirmations of the network's `env::Config` will be applied and no finality confirmations will be persisted on disk in the config file.
It is however possible to set finality confirmations in the config file for bitcoin and monero for power users at their own risk.
If set the defaults will be overwritten with the parameter from the config file upon startup.
3 years ago
Daniel Karzel af60d3bb54
Network check upon spot price request 3 years ago
Daniel Karzel 02974811ad
Activate mainnet for the ASB
To run the ASB on testnet, one actively has to provide the `--testnet` flag.
Mainnet and testnet data and config are separated into sub-folders, i.e. `{data/config-dir}/asb/testnet` and `{data-dir}/asb/mainnet`.
The initial setup is also per network. If (default) config for the network cannot be found the initial setup is triggered.
Startup includes network check to ensure the bitcoin/monero network in config file is the same as the one in the `env::Config`.

Note: Wallet initialization is done with the network set in the `env::Config`, the network saved in the config file is just to indicate what network the config file is for.
3 years ago
Philipp Hoenisch 26e0383e17
Apply suggestions from code review
Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech>
3 years ago
Philipp Hoenisch fc0cceb180
Toggle json logs using commandline flag. 3 years ago
Philipp Hoenisch 316f95c65b
Always log whole causality chain for errors. 3 years ago
Philipp Hoenisch c011e95062
Improve logging by adding details as fields instead of into the msg. 3 years ago
Philipp Hoenisch 1706b36800
Log exchange rate at each state. 3 years ago
Daniel Karzel 652aae9590
Introduce a minimum buy amount
Introduces a minimum buy Bitcoin amount similar to the maximum amount already present.
For the CLI the minimum amount is enforced by waiting until at least the minimum is available as max-giveable amount.
3 years ago
Daniel Karzel 1d62f4916c
Move `max_buy` and `ask_spread` into config
Max-buy and spread is not something that one would configure on every run.
More convenient to keep this in the config.

The max-buy Bitcoin value was adapted to `0.02` which is more reasonable for mainnet.
Activated feature `serde-float` to serialize the spread (Decimal) as float instead of string.

```
...

[maker]
max_buy_btc = 0.02
ask_spread = 0.02
```
3 years ago
Daniel Karzel daa572e5bf
Move recovery commands in dedicated module
Less clutter in the folder structure.
3 years ago
Daniel Karzel 4deb96a3c5
ASB manual recovery commands
Adds `cancel`, `refund`, `punish`, `redeem` and `safely-abort` commands to the ASB that can be used to trigger the specific scenario for the swap by ID.
3 years ago
Daniel Karzel 52f648e1de
Alice's spot price logic into dedicated behaviour
Move Alice's spot price logic into a dedicated network behaviour that handles all the logic.
The new behaviour encapsulates the complete state necessary for spot price request decision making.
The network behaviour cannot handle asynchronous calls, thus the balance is managed inside the spot price and has to updated regularly from the outside to ensure the spot price balance check has up to date data.
At the moment the balance is updated upon an incoming quote requests.

Code that is relevant for both ASB and CLI remains in the `network::spot_price` module (e.g. `network::spot_price::Error`).
3 years ago
Daniel Karzel f6497778ed
Add resume-only mode for the ASB
Resume-only is a maintenance mode where no swaps are accepted but unfinished swaps are resumed.
This is achieve by ignoring incoming spot-price requests (that would lead to execution setup) in the event-loop.
3 years ago
Philipp Hoenisch 46e0449b8e
Add config/argument to swap/asb to configure bitcoin tx fees. 3 years ago
Philipp Hoenisch ee90c228b4
Dynamically calculate fees using electrum's estimate_fee.
Electrum has an estimate-fee feature which takes as input the block you want a tx to be included.
The result is a recommendation of BTC/vbyte.
Using this recommendation and the knowledge about the size of our transactions we compute an appropriate fee.
The size of the transactions were taken from real transactions as published on bitcoin testnet.
Note: in reality these sizes might fluctuate a bit but not for much.
3 years ago
Daniel Karzel b0ffeeab1d
Different default directories for CLI and ASB
Using the same default directory as data-/config-dir has caused unwanted side effects when running both applications on the same machine.
Use these directory names:
- ASB: xmr-btc-swap-asb
- CLI: xmr-btc-swap-cli

Since the functionality is now application specific the respective functions were moved into the appropriate module of the application.
3 years ago
Philipp Hoenisch 632293cf91
Add support for swapping through Tor.
This PR does a few things.
* It adds a TorTransport which either dials through Tor's socks5 proxy or via clearnet.
* It enables ASB to register hidden services for each network it is listening on. We assume that we only care about different ports and re-use the same onion-address for all of them. The ASB requires to have access to Tor's control port.
* It adds support to dial through a local Tor socks5 proxy. We assume that Tor is always available on localhost.  Swap cli only requires Tor to be running so that it can send messages via Tor's socks5 proxy.
* It adds a new e2e test which swaps through Tor. For this we assume that Tor is currently running on localhost. All other tests are running via clear net.
3 years ago
Daniel Karzel f70e2aa8d6
Listen on tcp and websocket transports
- Listen on both tcp and websockets as default
- Listening addresses in config as array
- Configure fallback transport using `or_transport` - if listening on a given address fails on WS, we fall back to TCP.
3 years ago
Thomas Eizinger d4c10a1292
Introduce swarm::{alice,bob} function to construct a Swarm instance 3 years ago
rishflab 8805002f96 Remove redundant noun from tracing initialiser functions 3 years ago
rishflab e517c5934e Move asb tracing initializer to asb module 3 years ago
Thomas Eizinger a99d12b9df
Add a configurable spread to the ASB
Fixes #381.
3 years ago
Thomas Eizinger 654cfff2a8
Make `kraken` module emit `PriceUpdate`s instead of `Rate`s 3 years ago
Daniel Karzel 04b49d7117 Add command to print Bitcoin and Monero balance 3 years ago
Daniel Karzel 96008ec130 Add command to withdraw BTC
If no amount is given the wallet will be drained.
3 years ago
Daniel Karzel f5e81bb0ee Move seed and env_config outside Start command 3 years ago
Daniel Karzel d9d697821e Separate bitcoin and monero wallet initialization 3 years ago
Daniel Karzel 1c129d58c4
Distinguish loading all swaps for alice or bob on db level 3 years ago
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>
3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
Thomas Eizinger 09c41f89c4
Rename ExecutionParams to EnvironmentConfig 3 years ago
Thomas Eizinger bc43ed6ebd
Pass execution params directly into wallet for initialization
This reduces the amount of parameters that we need to pass in.
3 years ago
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>
3 years ago
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.
3 years ago
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>
3 years ago
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.
3 years ago
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.
3 years ago