Commit Graph

1035 Commits (f2df838a3ccd565f39ed5eded9b804824e43193f)

Author SHA1 Message Date
rishflab 86f312e143 Safely abort swap if TxLock is not confirmed in a reasonable time
If TxLock does not confirm in a reasonable amount of time, Alice should
give up on the swap rather than waiting forever. Watching for TxLock in
the mempool is not required and it causes unnecessary complexity. What
if Alice does not see the transaction in mempool but it is already
confirmed? She will abort the swap for no reason.
3 years ago
Thomas Eizinger 01739eddb1
Introduce a more flexible transaction subscription system
Instead of watching for status changes directly on bitcoin::Wallet,
we return a Subscription object back to the caller. This subscription
object can be re-used multiple times.

Among other things, this now allows callers of `broadcast` to decide
on what to wait for given the returned Subscription object.

The new API is also more concise which allows us to remove some of
the functions on the actor states in favor of simple inline calls.

Co-authored-by: rishflab <rishflab@hotmail.com>
3 years ago
bors[bot] 6fb495b6ab
Merge #383 #385 #386
383: Improve resilience of balance assertions r=thomaseizinger a=thomaseizinger

The final commit is the relevant patch!

It sits on top of several refactoring commits that happened while I was debugging why things didn't work as expected. Turned out to be reasonably useful so I just left them in :)

385: Bump anyhow from 1.0.39 to 1.0.40 r=thomaseizinger a=dependabot[bot]

Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.39 to 1.0.40.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/dtolnay/anyhow/releases">anyhow's releases</a>.</em></p>
<blockquote>
<h2>1.0.40</h2>
<ul>
<li>Reduce memory footprint of errors on Rust versions 1.51+ (<a href="https://github-redirect.dependabot.com/dtolnay/anyhow/issues/145">#145</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="704622f25d"><code>704622f</code></a> Release 1.0.40</li>
<li><a href="64ac0c00a9"><code>64ac0c0</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dtolnay/anyhow/issues/145">#145</a> from dtolnay/addrof</li>
<li><a href="ef082670ea"><code>ef08267</code></a> Eliminate functionally duplicate vtable methods on rustc 1.51+</li>
<li><a href="1295b1fef9"><code>1295b1f</code></a> Add additional builds on 1.50 and 1.51 validating addr_of codepath</li>
<li><a href="be89adf403"><code>be89adf</code></a> Detect whether ptr::addr_of is supported by current compiler</li>
<li><a href="ac64560c42"><code>ac64560</code></a> Switch object_ref return from real ref to Ref ptr</li>
<li><a href="2987c9b59e"><code>2987c9b</code></a> Ignore redundant_else pedantic clippy lint</li>
<li><a href="827bb9d4c6"><code>827bb9d</code></a> Catch some warnings in addr_of-related codepaths</li>
<li><a href="ce0041866d"><code>ce00418</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dtolnay/anyhow/issues/144">#144</a> from dtolnay/ptr</li>
<li><a href="3c32aa7dcd"><code>3c32aa7</code></a> Relax Sized bound on Own, Ref, Mut ptrs</li>
<li>Additional commits viewable in <a href="https://github.com/dtolnay/anyhow/compare/1.0.39...1.0.40">compare view</a></li>
</ul>
</details>
<br />


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

386: Bump hyper from 0.14.4 to 0.14.5 r=thomaseizinger a=dependabot[bot]

Bumps [hyper](https://github.com/hyperium/hyper) from 0.14.4 to 0.14.5.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/hyperium/hyper/releases">hyper's releases</a>.</em></p>
<blockquote>
<h2>v0.14.5</h2>
<h2>Bug Fixes</h2>
<ul>
<li><strong>client:</strong> omit default port from automatic Host headers (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2441">#2441</a>) (<a href="0b11eee9bd">0b11eee9</a>)</li>
<li><strong>headers:</strong> Support multiple Content-Length values on same line (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2471">#2471</a>) (<a href="48fdaf1606">48fdaf16</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2470">#2470</a>)</li>
<li><strong>server:</strong> skip automatic Content-Length headers when not allowed (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2216">#2216</a>) (<a href="8cbf9527df">8cbf9527</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2215">#2215</a>)</li>
</ul>
<h2>Features</h2>
<ul>
<li><strong>client:</strong> allow HTTP/0.9 responses behind a flag (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2473">#2473</a>) (<a href="68d4e4a3db">68d4e4a3</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2468">#2468</a>)</li>
<li><strong>server:</strong> add <code>AddrIncoming::from_listener</code> constructor (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2439">#2439</a>) (<a href="4c946af49c">4c946af4</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/hyperium/hyper/blob/master/CHANGELOG.md">hyper's changelog</a>.</em></p>
<blockquote>
<h3>v0.14.5 (2021-03-26)</h3>
<h4>Bug Fixes</h4>
<ul>
<li><strong>client:</strong> omit default port from automatic Host headers (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2441">#2441</a>) (<a href="0b11eee9bd">0b11eee9</a>)</li>
<li><strong>headers:</strong> Support multiple Content-Length values on same line (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2471">#2471</a>) (<a href="48fdaf1606">48fdaf16</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2470">#2470</a>)</li>
<li><strong>server:</strong> skip automatic Content-Length headers when not allowed (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2216">#2216</a>) (<a href="8cbf9527df">8cbf9527</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2215">#2215</a>)</li>
</ul>
<h4>Features</h4>
<ul>
<li><strong>client:</strong> allow HTTP/0.9 responses behind a flag (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2473">#2473</a>) (<a href="68d4e4a3db">68d4e4a3</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2468">#2468</a>)</li>
<li><strong>server:</strong> add <code>AddrIncoming::from_listener</code> constructor (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2439">#2439</a>) (<a href="4c946af49c">4c946af4</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="98e7e0bd15"><code>98e7e0b</code></a> v0.14.5</li>
<li><a href="895e4cf3fb"><code>895e4cf</code></a> refactor(ffi): return null ptr instead of aborting in C API (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2478">#2478</a>)</li>
<li><a href="68d4e4a3db"><code>68d4e4a</code></a> feat(client): allow HTTP/0.9 responses behind a flag (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2473">#2473</a>)</li>
<li><a href="51ed71b0a6"><code>51ed71b</code></a> docs(client): use Method::POST to match the example in <a href="https://hyper.rs/guide">https://hyper.rs/guide</a>...</li>
<li><a href="41f99578a5"><code>41f9957</code></a> refactor(dependencies): update to socket2 v0.4.0 (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2472">#2472</a>)</li>
<li><a href="48fdaf1606"><code>48fdaf1</code></a> fix(headers): Support multiple Content-Length values on same line (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2471">#2471</a>)</li>
<li><a href="eb0e718696"><code>eb0e718</code></a> docs(body): add links to to_bytes and aggregate (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2464">#2464</a>)</li>
<li><a href="297a068454"><code>297a068</code></a> docs(examples): upgrade tokio version (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2456">#2456</a>)</li>
<li><a href="34085afef6"><code>34085af</code></a> docs(examples): use hyper v0.14 and full feature (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2451">#2451</a>)</li>
<li><a href="8cbf9527df"><code>8cbf952</code></a> fix(server): skip automatic Content-Length headers when not allowed (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2216">#2216</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/hyperium/hyper/compare/v0.14.4...v0.14.5">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=hyper&package-manager=cargo&previous-version=0.14.4&new-version=0.14.5)](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: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
3 years ago
bors[bot] a18c071559
Merge #384
384: Include author information in the `--help` text r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger 0a82ce989b
Improve resilience of balance assertions
Sometimes, a single sync is not enough because we are still waiting
for the block to be mined.

We introduce an abstraction that loops on fetching the latest balance
with a certain timeout for asserting the balance.
3 years ago
Thomas Eizinger a4c70dfe94
Don't call as_ref() unless necessary 3 years ago
Thomas Eizinger 4ab7e83806
Make use of `cargo test`s scoped test output
By using `test_writer`, cargo can automatically scope the output
of the test to the relevant thread and will also only output it
if the test fails or is run with `--nocapture`.
3 years ago
Thomas Eizinger 908dae3442
Inline tracing initialization
This code snippet is so short, it might as well be inlined to give
the test more control over what it wants to log.
3 years ago
Thomas Eizinger c01cccb288
Use `tracing-log` feature flag instead of manual initialization
This also formats `log` events more nicely. Instead of

```
Mar 29 09:46:16.775  INFO log: Found message after comparing 82 lines log.target="testcontainers::core::wait_for_message" log.module_path="testcontainers::core::wait_for_message" log.file="/home/thomas/.cargo/registry/src/github.com-1ecc6299db9ec823/testcontainers-0.12.0/src/core/wait_for_message.rs" log.line=35
```

We now have

```
Mar 29 09:57:15.860  INFO testcontainers::core::wait_for_message: Found message after comparing 81 lines
```
3 years ago
Thomas Eizinger c5827f84ca
Refactor recursive function to loop
This should get rid of the ever-growing stack size issue.
3 years ago
Thomas Eizinger fc175a3f53
De-couple state from Monero wallet 3 years ago
Thomas Eizinger 42b6368298
Use full-qualified path for tracing macros
Saves an import line and makes it clear that we are using tracing.
3 years ago
Thomas Eizinger 5616683d7d
Monero confirmations are a u64
Trying to deserialize the number as a u32 caused deserialization
errors.
3 years ago
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.
3 years ago
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>

...
3 years ago
Thomas Eizinger 39b27e37d8
Delete empty file 3 years ago
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
3 years ago
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.
3 years ago
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>
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
Thomas Eizinger 1057d115d1
Re-order bob::event_loop based on importance 3 years ago
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.
3 years ago
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.
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 804b34f6b0
Listen on all swarm events instead of just behaviour events 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
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.
3 years ago
Thomas Eizinger 0c0a322a8f
Rename module to better represent what it contains
This module provides an implementation of the RequestResponseCodec
using a cbor serialization.
3 years ago
Thomas Eizinger 1de0b39b32
Unify encrypted-signature protocol to a single one 3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
dependabot[bot] 7f6299075c
Bump bdk from 0.4.0 to 0.5.0
Bumps [bdk](https://github.com/bitcoindevkit/bdk) from 0.4.0 to 0.5.0.
- [Release notes](https://github.com/bitcoindevkit/bdk/releases)
- [Changelog](https://github.com/bitcoindevkit/bdk/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bitcoindevkit/bdk/compare/v0.4.0...v0.5.0)

Signed-off-by: dependabot[bot] <support@github.com>
3 years ago
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>
3 years ago
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>
3 years ago
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>
3 years ago
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.
3 years ago
Thomas Eizinger a228349d8b
Bump dependency versions
Otherwise it will take a long time for dependabot to update all of
these.
3 years ago
Daniel Karzel 668d34080d Show the actual BTC amount and fee to be swapped 3 years ago
Thomas Eizinger f49f8977d3
Remove dead code 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 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.
3 years ago
Thomas Eizinger 338f4b82e5
Introduce dedicated bob::State6 for cancelling 3 years ago
Thomas Eizinger c32ef92cf5
Simplify code within BobState::EncSigSent 3 years ago
Thomas Eizinger 09e2d5b5d7
Simplify code within BobState::XmrLocked
By reducing the number of local variables, we can greatly simplify
this piece of code.
3 years ago
Thomas Eizinger 776a50137d
Use tokio::select macro instead of function
This is slightly less verbose and therefore hopefully easier to read.
3 years ago
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.
3 years ago
Thomas Eizinger 0d8962762a
Use early return to reduce one level of indentation 3 years ago
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.
3 years ago
Thomas Eizinger 8c9285f1f9
Inline step function because it has been reduced to a single statement 3 years ago
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.
3 years ago
Thomas Eizinger c92f2dbc77
Move more domain knowledge onto the `TxCancel` type 3 years ago
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.
3 years ago
Thomas Eizinger d682433ec9
Move `EventLoopHandle` next to its impl block
This struct is not that important so it can move further down.
3 years ago
Thomas Eizinger e77f1729b4
Move `extract_monero_private_key` onto TxRefund
This functionality is domain-specific to the refund transaction.
Move it onto there.
3 years ago
Thomas Eizinger a1e065b4e7
Simplify racing cancel timelock against learning enc-sig 3 years ago
Thomas Eizinger 575893fb51
Use domain types in fn signature instead of messages
This simplifies usage witin the swap module.
3 years ago
Thomas Eizinger 64b71d0b16
Remove unnecessary pinning 3 years ago
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
3 years ago
Daniel Karzel 07542d75ac prepare 0.3 release 3 years ago
bors[bot] d487aa3c5b
Merge #327 #330 #331
327: Bump actions/setup-python from v1 to v2.2.1 r=thomaseizinger a=dependabot[bot]

Bumps [actions/setup-python](https://github.com/actions/setup-python) from v1 to v2.2.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/actions/setup-python/releases">actions/setup-python's releases</a>.</em></p>
<blockquote>
<h2>v2.2.1</h2>
<ul>
<li>Fix PyPy3 issues with Windows</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="3105fb18c0"><code>3105fb1</code></a> fix is_windows (<a href="https://github.com/actions/setup-python/issues/172">#172</a>)</li>
<li><a href="8c5ea631b2"><code>8c5ea63</code></a> Adding support for more PyPy versions and installing them on-flight (<a href="https://github.com/actions/setup-python/issues/168">#168</a>)</li>
<li><a href="2831efe49a"><code>2831efe</code></a> Improve find-python to add &quot;Scripts&quot; folder to PATH on Windows machines (<a href="https://github.com/actions/setup-python/issues/169">#169</a>)</li>
<li><a href="3b3f2de1b1"><code>3b3f2de</code></a> update pypy3 to point to 3.6 (<a href="https://github.com/actions/setup-python/issues/164">#164</a>)</li>
<li><a href="723e46dad7"><code>723e46d</code></a> CODEOWNERS needs the org name for teams</li>
<li><a href="195f5c388b"><code>195f5c3</code></a> Create CODEOWNERS</li>
<li><a href="41b7212b16"><code>41b7212</code></a> Update README.md (<a href="https://github.com/actions/setup-python/issues/145">#145</a>)</li>
<li><a href="878156f1de"><code>878156f</code></a> Inject LD_LIBRARY_PATH library path into Python manifest install and setup (#...</li>
<li><a href="c181ffa198"><code>c181ffa</code></a> Add Environment Files (<a href="https://github.com/actions/setup-python/issues/138">#138</a>)</li>
<li><a href="1ce870e10f"><code>1ce870e</code></a> Fix links in documentation (<a href="https://github.com/actions/setup-python/issues/135">#135</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/actions/setup-python/compare/v1...3105fb18c05ddd93efea5f9e0bef7a03a6e9e7df">compare view</a></li>
</ul>
</details>
<br />


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>

330: Bump dialoguer from 0.7.1 to 0.8.0 r=thomaseizinger a=dependabot[bot]

Bumps [dialoguer](https://github.com/mitsuhiko/dialoguer) from 0.7.1 to 0.8.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/mitsuhiko/dialoguer/blob/master/CHANGELOG.md">dialoguer's changelog</a>.</em></p>
<blockquote>
<h2>0.8.0</h2>
<h3>Enhancements</h3>
<ul>
<li><code>Input::validate_with</code> can take a <code>FnMut</code> (allowing multiple references)</li>
</ul>
<h3>Breaking</h3>
<ul>
<li><code>Input::interact*</code> methods take <code>&amp;mut self</code> instead of <code>&amp;self</code></li>
</ul>
<h2>0.7.0</h2>
<h3>Enhancements</h3>
<ul>
<li>Added <code>wait_for_newline</code> to <code>Confirm</code></li>
<li>More secure password prompt</li>
<li>More documentation</li>
<li>Added <code>interact_text</code> method for input prompt</li>
<li>Added <code>inline_selections</code> to <code>ColorfulTheme</code></li>
</ul>
<h3>Breaking</h3>
<ul>
<li>Removed <code>theme::CustomPromptCharacterTheme</code></li>
<li><code>Input</code> validators now take the input type <code>T</code> as arg</li>
<li><code>Confirm</code> has no <code>default</code> value by default now</li>
</ul>
<h2>0.6.2</h2>
<h3>Enhancements</h3>
<ul>
<li>Updating some docs</li>
</ul>
<h2>0.6.1</h2>
<h3>Bugfixes</h3>
<ul>
<li><code>theme::ColorfulTheme</code> default styles are for stderr</li>
</ul>
<h2>0.6.0</h2>
<h3>Breaking</h3>
<ul>
<li>Removed <code>theme::SelectionStyle</code> enum</li>
<li>Allowed more customization for <code>theme::Theme</code> trait by changing methods</li>
<li>Allowed more customization for <code>theme::ColorfulTheme</code> by changing members</li>
<li>Renamed prompt <code>Confirmation</code> to <code>Confirm</code></li>
<li>Renamed prompt <code>PasswordInput</code> to <code>Password</code></li>
<li>Renamed prompt <code>OrderList</code> to <code>Sort</code></li>
<li>Renamed prompt <code>Checkboxes</code> to <code>MultiSelect</code></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="2c3fe6b646"><code>2c3fe6b</code></a> Release 0.8.0</li>
<li><a href="64f5f9c6f5"><code>64f5f9c</code></a> Allow confirm with no choice (<a href="https://github.com/mitsuhiko/dialoguer/issues/101">#101</a>)</li>
<li><a href="0250090f95"><code>0250090</code></a> Update some docs in confirm prompt</li>
<li><a href="a76fb72c54"><code>a76fb72</code></a> Merge pull request <a href="https://github.com/mitsuhiko/dialoguer/issues/102">#102</a> from spenserblack/typo-fix</li>
<li><a href="3dd93bb75a"><code>3dd93bb</code></a> Fix typo: ereased -&gt; erased</li>
<li><a href="7ea6275caa"><code>7ea6275</code></a> Update CI for i686 ubuntu</li>
<li><a href="af664807da"><code>af66480</code></a> Allow FnMut for validate (<a href="https://github.com/mitsuhiko/dialoguer/issues/96">#96</a>)</li>
<li><a href="2b5722d0f5"><code>2b5722d</code></a> Update README.md</li>
<li><a href="2df3a705eb"><code>2df3a70</code></a> Update ci.yml</li>
<li><a href="8cebf522b3"><code>8cebf52</code></a> Merge pull request <a href="https://github.com/mitsuhiko/dialoguer/issues/94">#94</a> from mitsuhiko/remove-travis</li>
<li>Additional commits viewable in <a href="https://github.com/mitsuhiko/dialoguer/compare/0.7.1...0.8.0">compare view</a></li>
</ul>
</details>
<br />


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

331: Bump tokio from 1.0.2 to 1.3.0 r=thomaseizinger a=dependabot[bot]

Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.0.2 to 1.3.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/tokio-rs/tokio/releases">tokio's releases</a>.</em></p>
<blockquote>
<h2>Tokio v1.3.0</h2>
<h3>Added</h3>
<ul>
<li>coop: expose an <code>unconstrained()</code> opt-out (<a href="https://github.com/tokio-rs/tokio/issues/3547">#3547</a>)</li>
<li>net: add <code>into_std</code> for net types without it (<a href="https://github.com/tokio-rs/tokio/issues/3509">#3509</a>)</li>
<li>sync: add <code>same_channel</code> method to <code>mpsc::Sender</code> (<a href="https://github.com/tokio-rs/tokio/issues/3532">#3532</a>)</li>
<li>sync: add <code>{try_,}acquire_many_owned</code> to <code>Semaphore</code> (<a href="https://github.com/tokio-rs/tokio/issues/3535">#3535</a>)</li>
<li>sync: add back <code>RwLockWriteGuard::map</code> and <code>RwLockWriteGuard::try_map</code> (<a href="https://github.com/tokio-rs/tokio/issues/3348">#3348</a>)</li>
</ul>
<h3>Fixed</h3>
<ul>
<li>sync: allow <code>oneshot::Receiver::close</code> after successful <code>try_recv</code> (<a href="https://github.com/tokio-rs/tokio/issues/3552">#3552</a>)</li>
<li>time: do not panic on <code>timeout(Duration::MAX)</code> (<a href="https://github.com/tokio-rs/tokio/issues/3551">#3551</a>)</li>
</ul>
<h3>Documented</h3>
<ul>
<li>doc: doc aliases for pre-1.0 function names (<a href="https://github.com/tokio-rs/tokio/issues/3523">#3523</a>)</li>
<li>io: fix typos (<a href="https://github.com/tokio-rs/tokio/issues/3541">#3541</a>)</li>
<li>io: note the EOF behaviour of <code>read_until</code> (<a href="https://github.com/tokio-rs/tokio/issues/3536">#3536</a>)</li>
<li>io: update <code>AsyncRead::poll_read</code> doc (<a href="https://github.com/tokio-rs/tokio/issues/3557">#3557</a>)</li>
<li>net: update <code>UdpSocket</code> splitting doc (<a href="https://github.com/tokio-rs/tokio/issues/3517">#3517</a>)</li>
<li>runtime: add link to <code>LocalSet</code> on <code>new_current_thread</code> (<a href="https://github.com/tokio-rs/tokio/issues/3508">#3508</a>)</li>
<li>runtime: update documentation of thread limits (<a href="https://github.com/tokio-rs/tokio/issues/3527">#3527</a>)</li>
<li>sync: do not recommend <code>join_all</code> for <code>Barrier</code> (<a href="https://github.com/tokio-rs/tokio/issues/3514">#3514</a>)</li>
<li>sync: documentation for <code>oneshot</code> (<a href="https://github.com/tokio-rs/tokio/issues/3592">#3592</a>)</li>
<li>sync: rename <code>notify</code> to <code>notify_one</code> (<a href="https://github.com/tokio-rs/tokio/issues/3526">#3526</a>)</li>
<li>time: fix typo in <code>Sleep</code> doc (<a href="https://github.com/tokio-rs/tokio/issues/3515">#3515</a>)</li>
<li>time: sync <code>interval.rs</code> and <code>time/mod.rs</code> docs (<a href="https://github.com/tokio-rs/tokio/issues/3533">#3533</a>)</li>
</ul>
<h2>Tokio v1.2.0</h2>
<h3>Added</h3>
<ul>
<li>signal: make <code>Signal::poll_recv</code> method public (<a href="https://github.com/tokio-rs/tokio/issues/3383">#3383</a>)</li>
</ul>
<h3>Fixed</h3>
<ul>
<li>time: make <code>test-util</code> paused time fully deterministic (<a href="https://github.com/tokio-rs/tokio/issues/3492">#3492</a>)</li>
</ul>
<h3>Documented</h3>
<ul>
<li>sync: link to new broadcast and watch wrappers (<a href="https://github.com/tokio-rs/tokio/issues/3504">#3504</a>)</li>
</ul>
<h2>Tokio v1.1.1</h2>
<p>Forward ports 1.0.3 fix.</p>
<h3>Fixed</h3>
<ul>
<li>io: memory leak during shutdown (<a href="https://github.com/tokio-rs/tokio/issues/3477">#3477</a>).</li>
</ul>
<h2>Tokio v1.1.0</h2>
<h3>Added</h3>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="d0e4dd1d7b"><code>d0e4dd1</code></a> chore: prepare Tokio v1.3.0 (<a href="https://github.com/tokio-rs/tokio/issues/3597">#3597</a>)</li>
<li><a href="872bc09e83"><code>872bc09</code></a> examples: update chat example (<a href="https://github.com/tokio-rs/tokio/issues/3587">#3587</a>)</li>
<li><a href="db1d90453c"><code>db1d904</code></a> util: fuse PollSemaphore (<a href="https://github.com/tokio-rs/tokio/issues/3578">#3578</a>)</li>
<li><a href="05eeea570e"><code>05eeea5</code></a> coop: expose an unconstrained() opt-out (<a href="https://github.com/tokio-rs/tokio/issues/3547">#3547</a>)</li>
<li><a href="f70b9b84f7"><code>f70b9b8</code></a> sync: documenation for oneshot (<a href="https://github.com/tokio-rs/tokio/issues/3592">#3592</a>)</li>
<li><a href="704de8c01b"><code>704de8c</code></a> stream: remove duplicate <code>doc(test(..))</code> &amp; <code>cfg_attr</code> declarations (<a href="https://github.com/tokio-rs/tokio/issues/3571">#3571</a>)</li>
<li><a href="47be928444"><code>47be928</code></a> sync: yield initial value in WatchStream (<a href="https://github.com/tokio-rs/tokio/issues/3576">#3576</a>)</li>
<li><a href="e06b257e09"><code>e06b257</code></a> sync: add same_channel method to mpsc Senders (<a href="https://github.com/tokio-rs/tokio/issues/3532">#3532</a>)</li>
<li><a href="0867a6fc03"><code>0867a6f</code></a> util: add pollable mpsc::Sender (<a href="https://github.com/tokio-rs/tokio/issues/3490">#3490</a>)</li>
<li><a href="0d838bf5ad"><code>0d838bf</code></a> io: fix link to std src in util (<a href="https://github.com/tokio-rs/tokio/issues/3568">#3568</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/tokio-rs/tokio/compare/tokio-1.0.2...tokio-1.3.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tokio&package-manager=cargo&previous-version=1.0.2&new-version=1.3.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>
3 years ago
dependabot[bot] 47544764d9
Bump tokio from 1.0.2 to 1.3.0
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.0.2 to 1.3.0.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.0.2...tokio-1.3.0)

Signed-off-by: dependabot[bot] <support@github.com>
3 years ago
bors[bot] 7f6f2408a3
Merge #332
332: Bump base64 from 0.12.3 to 0.13.0 r=thomaseizinger a=dependabot[bot]

Bumps [base64](https://github.com/marshallpierce/rust-base64) from 0.12.3 to 0.13.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/marshallpierce/rust-base64/blob/master/RELEASE-NOTES.md">base64's changelog</a>.</em></p>
<blockquote>
<h1>0.13.0</h1>
<ul>
<li>Config methods are const</li>
<li>Added <code>EncoderStringWriter</code> to allow encoding directly to a String</li>
<li><code>EncoderWriter</code> now owns its delegate writer rather than keeping a reference to it (though refs still work)
<ul>
<li>As a consequence, it is now possible to extract the delegate writer from an <code>EncoderWriter</code> via <code>finish()</code>, which returns <code>Result&lt;W&gt;</code> instead of <code>Result&lt;()&gt;</code>. If you were calling <code>finish()</code> explicitly, you will now need to use <code>let _ = foo.finish()</code> instead of just <code>foo.finish()</code> to avoid a warning about the unused value.</li>
</ul>
</li>
<li>When decoding input that has both an invalid length and an invalid symbol as the last byte, <code>InvalidByte</code> will be emitted instead of <code>InvalidLength</code> to make the problem more obvious.</li>
</ul>
<h1>0.12.2</h1>
<ul>
<li>Add <code>BinHex</code> alphabet</li>
</ul>
<h1>0.12.1</h1>
<ul>
<li>Add <code>Bcrypt</code> alphabet</li>
</ul>
<h1>0.12.0</h1>
<ul>
<li>A <code>Read</code> implementation (<code>DecoderReader</code>) to let users transparently decoded data from a b64 input source</li>
<li>IMAP's modified b64 alphabet</li>
<li>Relaxed type restrictions to just <code>AsRef&lt;[ut8]&gt;</code> for main <code>encode*</code>/<code>decode*</code> functions</li>
<li>A minor performance improvement in encoding</li>
</ul>
<h1>0.11.0</h1>
<ul>
<li>Minimum rust version 1.34.0</li>
<li><code>no_std</code> is now supported via the two new features <code>alloc</code> and <code>std</code>.</li>
</ul>
<h1>0.10.1</h1>
<ul>
<li>Minimum rust version 1.27.2</li>
<li>Fix bug in streaming encoding (<a href="https://github.com/marshallpierce/rust-base64/pull/90">#90</a>): if the underlying writer didn't write all the bytes given to it, the remaining bytes would not be retried later. See the docs on <code>EncoderWriter::write</code>.</li>
<li>Make it configurable whether or not to return an error when decoding detects excess trailing bits.</li>
</ul>
<h1>0.10.0</h1>
<ul>
<li>Remove line wrapping. Line wrapping was never a great conceptual fit in this library, and other features (streaming encoding, etc) either couldn't support it or could support only special cases of it with a great increase in complexity. Line wrapping has been pulled out into a <a href="https://crates.io/crates/line-wrap">line-wrap</a> crate, so it's still available if you need it.
<ul>
<li><code>Base64Display</code> creation no longer uses a <code>Result</code> because it can't fail, which means its helper methods for common
configs that <code>unwrap()</code> for you are no longer needed</li>
</ul>
</li>
<li>Add a streaming encoder <code>Write</code> impl to transparently base64 as you write.</li>
<li>Remove the remaining <code>unsafe</code> code.</li>
<li>Remove whitespace stripping to simplify <code>no_std</code> support. No out of the box configs use it, and it's trivial to do yourself if needed: <code>filter(|b| !b&quot; \n\t\r\x0b\x0c&quot;.contains(b)</code>.</li>
<li>Detect invalid trailing symbols when decoding and return an error rather than silently ignoring them.</li>
</ul>
<h1>0.9.3</h1>
<ul>
<li>Update safemem</li>
</ul>
<h1>0.9.2</h1>
<ul>
<li>Derive <code>Clone</code> for <code>DecodeError</code>.</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="b4fc91325e"><code>b4fc913</code></a> v0.13.0</li>
<li><a href="bba4c5d11e"><code>bba4c5d</code></a> Merge pull request <a href="https://github.com/marshallpierce/rust-base64/issues/145">#145</a> from marshallpierce/mp/cleanup</li>
<li><a href="42967320b3"><code>4296732</code></a> Add docs and other cleanup</li>
<li><a href="6bb3556633"><code>6bb3556</code></a> Merge pull request <a href="https://github.com/marshallpierce/rust-base64/issues/144">#144</a> from untitaker/invalid-bytes-not-length</li>
<li><a href="5b40e0c04e"><code>5b40e0c</code></a> Merge pull request <a href="https://github.com/marshallpierce/rust-base64/issues/142">#142</a> from marshallpierce/mp/string-writer</li>
<li><a href="8b1ae22bab"><code>8b1ae22</code></a> Rename StrWrite to StrConsumer</li>
<li><a href="27ccb6591e"><code>27ccb65</code></a> fix tests</li>
<li><a href="d15cd384e1"><code>d15cd38</code></a> Give better error messages when decoding data with trailing newlines</li>
<li><a href="5a56885c65"><code>5a56885</code></a> Introduce StrWriter to allow ESW to wrap both a String and a &amp;mut String</li>
<li><a href="2dc0296d2a"><code>2dc0296</code></a> Merge pull request <a href="https://github.com/marshallpierce/rust-base64/issues/143">#143</a> from marshallpierce/mp/invalid-length-doc</li>
<li>Additional commits viewable in <a href="https://github.com/marshallpierce/rust-base64/compare/v0.12.3...v0.13.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=base64&package-manager=cargo&previous-version=0.12.3&new-version=0.13.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>
3 years ago
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>
3 years ago
dependabot[bot] e6fda4a787
Bump base64 from 0.12.3 to 0.13.0
Bumps [base64](https://github.com/marshallpierce/rust-base64) from 0.12.3 to 0.13.0.
- [Release notes](https://github.com/marshallpierce/rust-base64/releases)
- [Changelog](https://github.com/marshallpierce/rust-base64/blob/master/RELEASE-NOTES.md)
- [Commits](https://github.com/marshallpierce/rust-base64/compare/v0.12.3...v0.13.0)

Signed-off-by: dependabot[bot] <support@github.com>
3 years ago
dependabot[bot] 64351a29b5
Bump dialoguer from 0.7.1 to 0.8.0
Bumps [dialoguer](https://github.com/mitsuhiko/dialoguer) from 0.7.1 to 0.8.0.
- [Release notes](https://github.com/mitsuhiko/dialoguer/releases)
- [Changelog](https://github.com/mitsuhiko/dialoguer/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/dialoguer/compare/0.7.1...0.8.0)

Signed-off-by: dependabot[bot] <support@github.com>
3 years ago
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>
3 years ago
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>
3 years ago
Thomas Eizinger e54d26b26c
Improve log messages by including PeerId 3 years ago
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.
3 years ago
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.
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
Thomas Eizinger 7213907a79
Group bitcoin and monero fields together 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
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.
3 years ago
rishflab f5e6ba18e0 Use different address for redeem and punish
Having the same address could potentially cause issues when subscribing
to transactions by script
3 years ago
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>
3 years ago
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>
3 years ago
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.
3 years ago
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.
3 years ago
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.
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
Thomas Eizinger 84ea092a1b
Remove unnecessary state variables by constructing TXs on demand 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
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.
3 years ago
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.
3 years ago
Daniel Karzel d85c0ce57c Re-introduce punish test 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
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.
3 years ago
rishflab 21429f24b2
Inline wait_for_locked_bitcoin() that is only called once
Reduce indirection.
3 years ago
rishflab 6a3e4802f1
Remove redundant reference 3 years ago
rishflab 458a8d594a
Rename fn param to correctly reflect underlying type 3 years ago
rishflab 752e5be8f3
Cleanup test logging 3 years ago
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.
3 years ago
bors[bot] a02389f8bd
Merge #314
314: Remove CLI config file in favour of parameters r=thomaseizinger a=da-kami

Fixes #282 

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.

Trait impls on `Data` needed for structopt, see https://docs.rs/structopt/0.3.21/structopt/#default-values

Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
bors[bot] 8505d76561
Merge #311
311: Add asb to release including ARM build r=da-kami a=da-kami

https://github.com/da-kami/xmr-btc-swap/releases/tag/0.3-test

The asb ARM build does neither run tests on CI not smoke test for the binary upon release because the there is no standard runner for ARM. One can configure a self-hosted one but I think that might be an overkill: https://docs.github.com/en/actions/hosting-your-own-runners/adding-self-hosted-runners

I did download the produced ARM tar, unpack and test on the raspi, it works :)

Concerning openssl depdency see:

https://github.com/da-kami/xmr-btc-swap/runs/2093523365?check_suite_focus=true
https://www.reddit.com/r/rust/comments/axaq9b/opensslsys_error_when_crosscompiling_for/


Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
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.
3 years ago
Daniel Karzel 442c377490 Remove openssl dependency
Upgrade tokio-tungstenite to 0.14 and use feature flag rustls-tls
to get rid of the openssl dependency.
3 years ago
Daniel Karzel 58c33f8468 Add asb to release including ARM build 3 years ago
rishflab 7cb198aea1 Remove pointless todo
The container is defined in the tests module indicating it is only
suitable for these tests
3 years ago
rishflab 9f534996ee Remove unused capability to configure bitcoind docker version tag
We only use one version of this container
3 years ago
rishflab 7b1d901ea0 Fix incorrectly formatted tag 3 years ago
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>
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
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.
3 years ago
Thomas Eizinger 7e0c44ad1d
Add avg monero block time to execution params 3 years ago
Thomas Eizinger d560e69203
Make durations more readable by using extension methods from `time` 3 years ago
Thomas Eizinger ecff1d1cbe
Remove indirection of constants
We never use these constants anywhere else, inline them.
3 years ago
Thomas Eizinger bac0f11898
Disable `backoff`s `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.
3 years ago
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.
3 years ago
Thomas Eizinger c560b3b21a
Introduce `RateUpdate` type alias to reduce duplication 3 years ago
Thomas Eizinger fd5b38739a
Remove constant in favor of inlining string
This removes an import and simplifies the `connect_async` call.
3 years ago
Thomas Eizinger 142e5e2d3a
Use tracing macros by fully-qualifying them 3 years ago
bors[bot] cc131ecf60
Merge #293
293: Some friday evening goodies r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger 08923a14f3
Simplify GET request for block tip height 3 years ago
Thomas Eizinger e9d7d9299c
Simplify the GET request to the tx status URL 3 years ago
Thomas Eizinger 418ad7089d
Make tests more readable by following arrange-act-assert 3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
Thomas Eizinger 5d4cf40831
Fix comparison of Monero confirmations 3 years ago
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.
3 years ago
Daniel Karzel 196557b377 Rename binary to swap 3 years ago
Daniel Karzel f8b61e2e0e Make monero daemon host configurable 3 years ago
Daniel Karzel f091402c7a Remove parameter duplication by introducing structs 3 years ago
Thomas Eizinger c826a28911
Add context if we fail to compute extended private key 3 years ago
Thomas Eizinger 1aa6d177bf
Improve error messages when determining BTC amount to be swapped 3 years ago
Thomas Eizinger 4138039ea0
Make sure all error messages start with an uppercase letter
These might potentially be shown to a user, let's make them all
consistent.
3 years ago
Thomas Eizinger 816e8b9b96
Add more context to fallible functions inside bitcoin::Wallet 3 years ago
Thomas Eizinger 5c24a46298
Improve error message if stuff fails directly in main 3 years ago
Thomas Eizinger 37f97ac471
Shorten function name
The variable will always be at least called `wallet`, hence we can
omit the `_wallet` postfix from the function name.
3 years ago
Thomas Eizinger 4f66269887
Move error message on sync _into_ the function
The bitcoin::Wallet::sync_wallet function doesn't do anything else
other than delegating. As such, we have just as much information
about what went wrong inside this function as we have outside.

By moving the .context call into the function, we can avoid repeating
us on every call-site.
3 years ago
Thomas Eizinger 5953037b81
Don't repeat the module name within the type 3 years ago
Thomas Eizinger 87f928f56c
Move const to function where it is used 3 years ago
Thomas Eizinger 4642e6c0e3
Simplify arguments to `init_XYZ_wallet` functions
This makes the function calls fit onto one line.
3 years ago
Thomas Eizinger d0db6cba10
Favour individual logs over one in main 3 years ago
bors[bot] 2041f367c6
Merge #288
288: Switch to public stagenet node that works r=rishflab a=rishflab

The xmr.to node has been unreliable lately. The exan.tech node seems to
working.

@da-kami is following up with making this configurable. Lets get this in so we can get a release on Friday.

Co-authored-by: rishflab <rishflab@hotmail.com>
3 years ago
rishflab 754159c9f8 Switch to public stagenet node that works
The xmr.to node has been unreliable lately. The exan.tech node seems to
working.
3 years ago
Thomas Eizinger b178e95f95
Redo layout of eventloop module
1. Move internal types to the bottom and make them private
2. Sort public types by their importance
3 years ago
Thomas Eizinger 1822886cd0
Provide stronger isolation of kraken module
Instead of leaking the tokio::sync::Receiver type in our
return value, we create a newtype that implements the desired
interface. This allows us to get rid of the `RateService` structs
and instead implement `LatestRate` directly on top of this struct.

Given that `LatestRate` is only used within the event_loop module,
we move the definition of this type into there.
3 years ago
Thomas Eizinger f6ed4d65b5
Properly deal with additional messages sent from kraken 3 years ago
Thomas Eizinger 7575d412b8
Add kraken_ticker CLI for local testing of the client 3 years ago
Thomas Eizinger 60d6d50246
Extract kraken websocket client into dedicated module 3 years ago
Thomas Eizinger 25c4639689
Prepare for next release 3 years ago
bors[bot] 20f2e56e2d
Merge #271
271: Bob can verify that the XMR lock tx was published r=da-kami a=da-kami

The Monero `txhash` log was removed. I feel the user should have the possibility to verify that the transaction was actually published so I added the tx-hash to the confirmation output. 

We could potentially print the tx-hash when receiving the transfer proof already, but that might not add much value compared to printing it with the confirmations. 

Additionally we should allow the user to at least know when the XMR can be expected in the user's wallet, otherwise the swap ends like this:

```
2021-03-04 13:49:19   INFO Monero lock tx received 5 out of 5 confirmations
```

This is just not very informative - yes, the final transaction is an implementation detail, but I don't think we should hide the transactions from the user. By printing the tx-hash for spending from the lock-tx into the user wallet we ensure the user knows that the XMR can now be expected in the user wallet. 

--- 

To add context, here the complete log (with debug enabled) **before** this change: 

```
2021-03-04 13:30:46  DEBUG Database and seed will be stored in /Users/dakami/Library/Application Support/xmr-btc-swap
2021-03-04 13:30:46  DEBUG Starting monero-wallet-rpc on port 56145
2021-03-04 13:30:51  DEBUG Requesting quote
2021-03-04 13:30:51   INFO Received quote: 1 XMR = 0.00433500 BTC
2021-03-04 13:30:51   INFO Still got 0.01018746 BTC left in wallet, swapping ...
2021-03-04 13:30:51   INFO Spot price for 0.00500000 BTC is 1.153402537485 XMR
2021-03-04 13:30:52  DEBUG Starting execution setup with 12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi
2021-03-04 13:30:55   INFO Published Bitcoin 3a6690a962191529892318819fb20e7f1ac4625400e64ee734056a9b2a17ad8f transaction as lock
2021-03-04 13:41:13  DEBUG Received Transfer Proof from 12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi
2021-03-04 13:42:11   INFO Monero lock tx received 1 out of 5 confirmations
2021-03-04 13:45:33   INFO Monero lock tx received 2 out of 5 confirmations
2021-03-04 13:47:49   INFO Monero lock tx received 3 out of 5 confirmations
2021-03-04 13:48:56   INFO Monero lock tx received 4 out of 5 confirmations
2021-03-04 13:49:19   INFO Monero lock tx received 5 out of 5 confirmations
2021-03-04 13:49:19  DEBUG Encrypted signature sent
2021-03-04 13:49:19  DEBUG Alice acknowledged encrypted signature
2021-03-04 13:49:19  DEBUG watching for tx: e5569d3f0bcccac95252dffaebe74ead0360c09b76bc762de890aaa0e51afbcf
2021-03-04 13:49:20  DEBUG Received protocol error "missing transaction" from Electrum, retrying...
2021-03-04 13:49:22  DEBUG Received protocol error "missing transaction" from Electrum, retrying...
```



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel 47a31760c0 Bob can verify the Monero txs by tx-hash
Print tx-hashes for monero transactions to allow Bob to look the transaction up in block explorer.

The story of Bab:
Our famous actor Bob has a brother named Bab.
In school they were often mixed up, because their names were so similar.
Eventually Bab renamed himself into Barbara, but that was even more confusing for now he
carried a female name even though he was not female. Bob wanted to help his brother and told him he
could just go for Bub. But that did not solve anything. Fun fact: Bub is actually married to Alice.
3 years ago
Thomas Eizinger 14dcd150af
Extract `determine_btc_to_swap` function and test it
We also instantiate tracing in to order to quickly validate, what
the output for the different scenarios looks like.
3 years ago
Thomas Eizinger 601bf07255
Introduce `quote` protocol and display it to the user before they fund
Previously, the user neither knew the price nor the maximum quantity
they could trade. We now request a quote from the user and display
it to them.

Fixes #255.
3 years ago
Thomas Eizinger 3da01ea44a
Rename local variables according to new protocol name 3 years ago
Thomas Eizinger ead5db3f45
Re-order fields to group them semantically 3 years ago
Thomas Eizinger bc176bc4fb
Minor import optimizations 3 years ago
Thomas Eizinger 6d9b21cb47
Change `imports_granularity` to module
This reduces the overall amount of LoC that imports take up in our
codebase by almost 100.
It also makes merge-conflicts less likely because there is less
grouping together of imports that may lead to layout changes which
in turn can cause merge conflicts.
3 years ago
Thomas Eizinger 2c8200621d
Move `pub use` into pub use block 3 years ago
bors[bot] d1363d130c
Merge #265
265: Replace quote with spot-price protocol r=thomaseizinger a=thomaseizinger

This is essentially functionally equivalent but includes some
cleanups by removing a layer of abstraction: `spot_price::Behaviour`
is now just a type-alias for a request-response behaviour.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Daniel Karzel 7504c6ceee Context for monero address parsing errors
Most of the errors are not user friendly, thus added context to tell the user the given address is incorrect.
3 years ago
Daniel Karzel 35d0e246d8 Monero address network check
Add a network check to ensure the given monero address is on the configured network.
3 years ago
bors[bot] cba9f119b6
Merge #261
261: Sweep xmr funds from generated temp wallet r=da-kami a=da-kami

Fixes #252

Please review by commit :)
Did a few cleanups before actually doing the feature.

Please note the comment that influenced this solution: https://github.com/comit-network/xmr-btc-swap/issues/252#issuecomment-789387074



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel 2e3c2d8edf Remove Arcs in favour of references 3 years ago
Daniel Karzel 5d807e9647 Reorder: Move utility functionality to bottom 3 years ago
Daniel Karzel 862c29f1a8 Reorder: Move sweep_all after transfer 3 years ago
Daniel Karzel 5a43b3453e Reorder: Move create after open 3 years ago
Daniel Karzel b17e6cbd94 Reorder: Move open to top 3 years ago
Daniel Karzel d63790c2a6 Remove unnecessary monero wallet trait abstractions 3 years ago
Daniel Karzel 1041212a60 Work in review comments 3 years ago
Daniel Karzel 66c8401c95 Sweep all from generated wallet to user wallet
The default implementation for the command was removed because it does not
add additional value if we have a mandatory parameter anyway.
3 years ago
Thomas Eizinger 7042ed9441
Replace quote with spot-price protocol
This is essentially functionally equivalent but includes some
cleanups by removing a layer of abstraction: `spot_price::Behaviour`
is now just a type-alias for a request-response behaviour.
3 years ago
Daniel Karzel 5111a12706 Wallet name constants for the e2e test setup
Container initialization and wallet initialization have to ensure to use the same wallet name.
In order to avoid problems constants are introduced to ensure we use the same wallet name.
3 years ago
Daniel Karzel 2bb1c1e177 No prefix for wallets in monero harness
Prefixing docker-containers and -networks is a necessity to be able to spin up multiple containers and networks.
However, there is no reason to prefix the wallet names that live inside a container. One cannot add a wallet with
the same name twice, so the prefixing of wallets does not bring any advantage. When re-opening a wallet by name
the wallet name prefix is cumbersome and was thus removed.
3 years ago
Daniel Karzel 9f53dab3c6 Harmonize names to make more sense
The wallet is an instance of a wallet that has a name.
When we use `CreateWalletForOutputThenReloadWallet` we actually unload the wallet.
It would be cleaner to create a new instance that does that swap, but I did not go that far.
3 years ago
Daniel Karzel 70494fcb4f Create means creating the current wallet 3 years ago
Daniel Karzel 5b798217bc Open means opening the current wallet 3 years ago
Thomas Eizinger 2440964385
Allow ASB to be configured with max BTC buy amount
This will make it easier to also configure the CLI to display an appropriate max amount the user has to deal with.
3 years ago
Thomas Eizinger ce077a3ff5
Decouple Bob's EventLoop from the builder
Instead of instantiating the `EventLoop` within the builder, we only
pass in the necessary arguments (which is the `EventLoopHandle`) to
the Builder upon `new`.

This is work towards #255 which will require us to perform network
communication (which implies having the `EventLoop`) before starting
a swap.
3 years ago
Thomas Eizinger 54bc91581f
Don't unnecessarily create async blocks
If our expression directly evaluates to a future, we don't need to
create an async block.

This requires us to have `EventLoopRun::run` consume the instance
instead of just taking a mutable reference (otherwise we run into
lifetime issues). However, that is better anyway because `run` is
an endless loop so you never get to use the handle afterwards
anyway.
3 years ago
Thomas Eizinger a4c25080b6
Merge network::Seed into crate::Seed
This allows us to unify the way we derive new secret key material
and simplify the usage of seed by only having a single one.
3 years ago
Thomas Eizinger 089ac0806e
Simplify constructor of Bob's EventLoop
We never customize the behaviour or transport. Might as well hide
those details in the implementation.
3 years ago
Daniel Karzel 1b167f3eb6 Cleanup swap initialization for Alice and Bob 3 years ago
bors[bot] a8ebd4d16e
Merge #259
259: Upgrade bitcoin wallet to use BIP84 derivation scheme r=rishflab a=rishflab

Closes #258 

Co-authored-by: rishflab <rishflab@hotmail.com>
3 years ago
rishflab a41b255dab Upgrade bitcoin wallet to use BIP84 derivation scheme
Explicitly specify the change descriptor because the behaviour when it
is not specified is unclear.
3 years ago
rishflab bcdde021eb Add windows support to monero rpc installer 3 years ago
rishflab 27df9128be Bail if monero wallet rpc is not found in downloaded archive
Previously we were ignoring if the monero wallet rpc was not found and
unpacked from archive leading to a failure down the line when trying to
run a non-existent executable. Bail when the executable is no found in
the archive.
3 years ago
Thomas Eizinger 3ad9516188
Reduce logging when signing transactions
1. We can generalize the signing interface by passing a PSBT in
instead of the `TxLock` transaction.
2. Knowing the transaction ID of a transaction that we are about
to sign is not very useful. Instead, it is much more useful to know
what failed. Hence we add a `.context` to the call of `sign_and_finalize`.
3. In case the signing succeeds, we will immediately broadcast it
afterwards. The new broadcasting interface will tell us that we broadcasted
the "lock" transaction.
3 years ago
Thomas Eizinger 8c9b087e39
Unify logging of broadcasted transactions
We eliminate unnecessary layers of indirection for broadcasting logic
and force our callers to provide us with the `kind` of transaction
that we are publishing.

Eventually, we can replace this string with some type-system magic
we can derive the name from the actual transaction. For now, we just
require the caller to duplicate this information because it is faster
and good enough TM.
3 years ago
Thomas Eizinger 3a503bf95f
Shorten function name
This struct is a wallet. The only thing it can meaningfully broadcast
are transactions. The fact that they have to be signed for that is
implied. You cannot broadcast unsigned transactions.
3 years ago
Thomas Eizinger 45cff81ea5
Remove traits in favor of using the wallet struct directly
Abstracting over the individual bits of functionality of the wallet
does have its place, especially if one wants to keep a separation
of an abstract protocol library that other people can use with their
own wallets.

However, at the moment, the traits only cause unnecessary friction.
We can always add such abstraction layers again once we need them.
3 years ago
Thomas Eizinger 8c0df23647
Only show _log_ output if the user passes `--debug`
If the user doesn't pass `--debug`, we only show `INFO` logs but
without time and level to make it clearer that it is meant to be
read by the user.

Without `--debug`, the user sees:

 Still got 0.00009235 BTC left in wallet, swapping ...

With `--debug`, they see:

2021-03-01 12:21:07  DEBUG Database and seed will be stored in /home/thomas/.local/share/xmr-btc-swap
2021-03-01 12:21:07  DEBUG Starting monero-wallet-rpc on port 40779
2021-03-01 12:21:11   INFO Still got 0.00009235 BTC left in wallet, swapping ...
2021-03-01 12:21:11  DEBUG Dialing alice at 12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi
2021-03-01 12:21:12  DEBUG Requesting quote for 0.00008795 BTC
3 years ago
Thomas Eizinger cb4e2c041b
Rename `opt` to `args` 3 years ago
Thomas Eizinger f4827e3fa4
Improve time formatting of log output
Previously, the time was formatted as ISO8601 timestamps which is
barely readable by humans. Activating the `chrono` feature allows
us to format with a different format string. The output now looks
like this:

2021-03-01 11:59:52  DEBUG Database and seed will be stored in /home/thomas/.local/share/xmr-btc-swap
2021-03-01 11:59:52  DEBUG Starting monero-wallet-rpc on port 40673
2021-03-01 11:59:59  DEBUG Still got 0.00009235 BTC left in wallet, swapping ...
2021-03-01 11:59:59  DEBUG Dialing alice at 12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi
2021-03-01 11:59:59  DEBUG Requesting quote for 0.00008795 BTC

There is a double space after the time which is already fixed in
tracing-subscriber but not yet released.

See https://github.com/tokio-rs/tracing/issues/1271.
3 years ago
Thomas Eizinger a82e82edd5
Tell the user about the monero-wallet-rpc download
Fixes #242.
3 years ago
Thomas Eizinger 06e3bccaa6
Don't print PeerId when requesting quote
Bob always just talks to one party, the PeerId is just noise.
3 years ago
Thomas Eizinger cbef577e2d
Inform user that we are going to swap the remainder of the balance 3 years ago
Thomas Eizinger b7c3524b4f
Abort the eventloop if the dialling fails 3 years ago
Thomas Eizinger 4e9e186462
Don't log things the user doesn't care about
The user configured neither a Bitcoin wallet backend nor the monero-wallet-rpc so let's not tell them about it.

Fixes #244.
3 years ago
Thomas Eizinger 6b74761e34
Remove tracing context
The swap_cli can only do one swap at a time, no need for the swap ID span.
3 years ago
Thomas Eizinger 3d2d447fba
Improve error message
YMMV but I think this sounds better.
3 years ago
Thomas Eizinger bbbe5f7ae8
Demote / promote log messages to their appropriate level 3 years ago
Thomas Eizinger 7387884e6d
Move log messages to the appropriate abstraction layer
Log messages are ideally as close to the functionality they are talking about, otherwise we might end up repeating ourselves on several callsites or the log messages gets outdated if the behaviour changes.
3 years ago
Thomas Eizinger b8df4a3145
Inline tracing configuration for swap_cli
This allows us to configure the presentation separately from the ASB.
3 years ago
Thomas Eizinger a0e7c6ecf7
Don't Arc the AtomicU32
We never clone this type, there is no need to wrap it in an `Arc`.
3 years ago
Thomas Eizinger 40dcf0355a
Simplify `Transfer::transfer` return type
We never use the fee returned from this function, remove it.
3 years ago
bors[bot] 1de3fa486e
Merge #247
247: Calculate max_giveable based on spending script size r=da-kami a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger 9f0b1c5cbe
Calculate max_giveable based on spending script size 3 years ago
Daniel Karzel 8c40ee1da4 Change anyhow! to bail! in error scenarios 3 years ago
bors[bot] 7251588e79
Merge #233
233: ASB max sell amount r=thomaseizinger a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
bors[bot] 5ddf41721e
Merge #238
238: Bob error handling r=thomaseizinger a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
rishflab 975d604405 Test to ensure default alice peer id and multi addr is valid 3 years ago
rishflab 9a82b572ec Default to buy xmr using default trait 3 years ago
rishflab d6d67f62f1 Swap cli executes BuyXmr path if subcommand is not given 3 years ago
rishflab 60de6a9219 Remove intermediate structs in cli arguments
These intermediate structs were creating unnecessary noise. The peer id
and multiaddr fields are going to be removed in the future further
reducing the need to have seperate structs for cancel, resume and
refund.
3 years ago
bors[bot] 9a32f7d405
Merge #236
236: Some wallet cleanup + watch for deposit r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Daniel Karzel bb1537d6f2 Error feedback for the user upon communication errors
If communication with the other party fails the program should stop and the user should see the respective error.
Communication errors are handled in the event-loop. Upon a communication error the event loop is stopped.
Since the event loop is only stopped upon error the Result returned from the event loop is Infallible.

If one of the two futures, event loop and swap,  finishes (success/failure) the other future should be stopped as well.
We use tokio::selec! to stop either future if the other stops.
3 years ago
Daniel Karzel 019d6c725a Maximum sell amount for ASB that defaults to 0.5 XMR 3 years ago
bors[bot] bb0377c6c7
Merge #232
232: ASB only sends quote response if sufficient XMR balance r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel e66e84085b Rename Bob's Behavior Failure to CommunicationError
Failure does not express what the error represents. It is only used for communication
errors for quote requests, receiving the XMR transfer proof and sending the encryption signature.
3 years ago
Thomas Eizinger f472070546
Remove `--send-btc` in favor of swapping the available balance
If the current balance is 0, we wait until the user deposits money
to the given address. After that, we simply swap the full balance.

Not only does this simplify the interface by removing a parameter,
but it also integrates the `deposit` command into the `buy-xmr`
command.

Syncing a wallet that is backed by electrum includes transactions
that are part of the mempool when computing the balance.
As such, waiting for a deposit is a very quick action because it
allows us to build our lock transaction on top of the yet to be
confirmed deposit transactions.

This patch introduces another function to the `bitcoin::Wallet` that
relies on the currently statically encoded fee rate. To make sure
future developers don't forget to adjust both, we extract a function
that "selects" a fee rate and return the constant from there.

Fixes #196.
3 years ago
Thomas Eizinger 32cb0eb896
Rename `build_tx_lock_psbt` to `send_to_address`
Being defined on the wallet itself, a more generic name fits better
on what this function actually does.
3 years ago
Thomas Eizinger 67fe01a2ef
Remove `BuildTxLockPsbt` and `GetNetwork` traits
These traits were only used once within the `TxLock` constructor.
Looking at the rest of the codebase, we don't really seem to follow
any abstractions here where the protocol shouldn't know about the
exact types that is being passed in.

As such, these types are just noise and might as well be removed in
favor of simplicity.
3 years ago
Thomas Eizinger 6c38d66864
Remove `Tx` arguments from `add_signatures` functions
The only reason we need this argument is because we need to access
the output descriptor. We can save that one ahead of time at when
we construct the type.
3 years ago
Thomas Eizinger 0f8fbd087f
Make all fields of `bitcoin::Wallet` private
This reveals that the `network` field is actually unused.
3 years ago
Thomas Eizinger 1876d17ba4
Remove `map_err` in favor of `?`
`?` maps the error automatically.
3 years ago
Thomas Eizinger 7d324d966a
Remove `syncing` wallet log
BDK already has a log line for the sync that we could enable if we
wanted such a log.
Additionally, _we_ are not actually syncing the wallet, bdk is so our
log line was lying. It should have said "calling bdk to sync wallet".
3 years ago
bors[bot] 93d59398af
Merge #231
231: Error only on close message when fetching the rate r=thomaseizinger a=da-kami

Ping/Pong messages disturb the rate requests quite frequently resulting in failed swap setup because there is no rate available.

As a result messages Ping, Pong and Binary are now ignored and not reported as error.


Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel 1f1b3a95bc Logging for different scenarios when reading from rate stream 3 years ago
rishflab abc9aaa327 Use default alice peer id and multiaddr if not specified in cli args 3 years ago
Daniel Karzel cad6a1c3a7 ABS only sends quote response if sufficient XMR balance 3 years ago
rishflab f52567155a Use default testnet config if config file path not specified 3 years ago
Daniel Karzel fc2c08c7c9 Error only on close message when fetching the rate
Messages Ping, Pong and Binary are ignored and not reported as error.
3 years ago
rishflab 51c16f23d8
Download and run monero wallet rpc on swap cli startup
If the monero wallet rpc has not already been downloaded we download the monero cli package and extract the wallet rpc. The unneeded files are cleaned up. The monero wallet rpc is started on a random port which is provided to the swap cli.

We added a fork of tokio-tar via a git subtree because we needed a tokio-tar version that was compatible with tokio 1.0. Remove this subtree in favor of a regular cargo dependency when this PR merges: https://github.com/vorot93/tokio-tar/pull/3.
3 years ago
Daniel Karzel 0945cee459 Remove traits in favour of public functions 3 years ago
Daniel Karzel 578d23d7fc Proper encapsulation of wallet boundaries through private fields 3 years ago
Daniel Karzel 947bcb6192 ASB reloads the default wallet after generate_from_keys atomically 3 years ago
Daniel Karzel 684cbe4d0b Remember monero wallet-height for Alice's refund scenario 3 years ago
Daniel Karzel fa04775188 Rename function explicit to cancellation to cancel
For transitioning to state4 we either go into a redeem or a cancellation scenario.
The function name state4 is misleading, because it is only used for cancellation scenarios.
3 years ago
Daniel Karzel 1404057dbe Remove misleading TODO
This TDOO is misleading, because - to our current knowledge - it is impossible for
Bob to retrieve the exact inclusion block-height of the lock transaction (send by Alice).
The wallet RPC is only capable of retrieving the inclusion block height of a transaction
through `get_payments` and `get_bulk_payments` which requires the `payment_id`.
The `payment_id` can be retrieved through `get_transfer_by_txid` which states
"Show information about a transfer to/from this address." - however the address that the
transfer goes to is not part of Bob's wallet yet! Thus, it is impossible for Bob to use
`get_transfer_by_txid` which in turn means Bob is unable to use `get_payments`.

The only possible way for Bob to know the exact inclusion block/height of the lock transaction
would be if Alice sends it over to Bob. But for that Alice would have to extract it she would have
to wait for confirmation - which she currently does not and might never do. Even if she does await
the first confirmation before sending the transfer proof the solution for retrieving the inclusion
block-height is not fleshed out on her side yet.
3 years ago
Daniel Karzel 9f1deb9fdc Wrap the Monero wallet client in a Mutex
In order to ensure that we can atomically generate_from_keys and then reload a wallet,
we have to wrap the client of the monero wallet RPC inside a mutex.
When introducing the Mutex I noticed that several inner RPC calls were leaking to the
swap crate monero wallet. As this is a violation of boundaries I introduced the traits
`GetAddress`, `WalletBlockHeight` and `Refresh`.

Note that the monero wallet could potentially know its own public view key and
public spend key. If we refactor the wallet to include this information upon wallet
creation we can also generate addresses using `monero::Address::standard`.
3 years ago
Daniel Karzel aed8358fb7 Remove dead code 3 years ago
bors[bot] 2654879ff3
Merge #218
218: Cleanup dependencies r=thomaseizinger a=thomaseizinger

Fixes https://github.com/comit-network/xmr-btc-swap/issues/208.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
bors[bot] fb2057453a
Merge #219 #221
219: Rename variables to add to understanding the code r=da-kami a=da-kami



221: Fix/improve comment explaining TxRefund encsigning r=thomaseizinger a=rishflab



Co-authored-by: Daniel Karzel <daniel@comit.network>
Co-authored-by: rishflab <rishflab@hotmail.com>
3 years ago
Thomas Eizinger 66db8e1851
Remove unnecessary log dependency
By updating `tracing_log`, we can access the re-export. That we need
to initialize the `tracing_log` adaptor.

The usage of `log::LevelFilter` for the `init_tracing` function was
conceptually incorrect. We should be using a type from the `tracing`
library here.
3 years ago
Thomas Eizinger 03078f328c
Split monero-harness into harness and rpc
This allows us to move `monero-harness` and `bitcoin-harness` into
`[dev-dependencies]` of `swap`.
3 years ago
Thomas Eizinger 2a3db9bd80
Remove unnecessary derivative dependency 3 years ago
Thomas Eizinger f0ba80794c
Remove unnecessary serde_derive dependency declaration
We already express the same thing through the serde `derive` feature.
3 years ago
Thomas Eizinger d54fac6fd9
Remove unnecessary tempfile prod dependency 3 years ago
Thomas Eizinger 729f4f09a8
Remove unnecessary tracing_core dependency 3 years ago
Thomas Eizinger 418aa02191
Remove unnecessary ed25519-dalek dependency 3 years ago
rishflab 8280072400 Fix/improve comment explaining TxRefund encsigning 3 years ago
Daniel Karzel 151f33ba10 Rename variables to add to understanding the code 3 years ago
bors[bot] 61a8282be1
Merge #203
203: Introduce dynamic rates r=da-kami a=D4nte



Co-authored-by: Franck Royer <franck@coblox.tech>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel b4ceee49df Change monitoring to default wallet
The automated swap backend (asb) requires Monero funds, because Alice is selling Monero.
We use a hardcoded default wallet named asb-wallet. This wallet is opened upon startup.
If the default wallet does not exist it will be created.
3 years ago
Daniel Karzel 9496dce917 Skip heartbeat messages 3 years ago
Thomas Eizinger a8bfc1d686 Make LatestRate::Error require std::error::Error trait bound
This allows us to use .context instead of .map_err when calling
`latest_rate()`. For the static rate module, we simply fill in
`Infallible` which is actually better suited because it describes
that we are never using this error.
3 years ago
Thomas Eizinger b47b06aa23 Import anyhow::Result across the codebase
There is no need to fully qualify this type because it is a type
alias for std::Result. We can mix and match the two as we want.
3 years ago
Franck Royer 519d1a5701 Log rate and amounts for Alice when doing execution setup 3 years ago
Franck Royer b20c16df78 Improving logging on failure 3 years ago
Franck Royer 644f4c1732 Bubble up ws error to consumer
Note that because we are using `watch` channel, only a reference to the
channel value can be returned.
Hence, using custom Error that can be cloned to be able to
pass `Result` through the channel.
3 years ago
Franck Royer 92b3df4158 Introduce dynamic rates 3 years ago
bors[bot] 0359f8fbc0
Merge #216
216: To avoid CI failure wait for the balance instead of sleep r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
bors[bot] a6724f29af
Merge #214
214: Rename nectar to asb (automated swap backend) r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel bdb35c310d To avoid CI failure wait for the balance instead of sleep 3 years ago
bors[bot] 81228c9d5b
Merge #209
209: Upgrade to bdk 0.4 r=thomaseizinger a=thomaseizinger

Effectively, this also means:

- Upgrading to rust-bitcoin 0.26
- Upgrading to miniscript 5
- Upgrading monero to 0.10
- Upgrading curve25519-dalek to 3
- Upgrading bitcoin-harness to rust-bitcoin 0.26 (https://github.com/coblox/bitcoin-harness-rs/pull/21)
- Upgrade `ecdsa_fun` to latest version
- Replace `cross_curve_dleq` with `sigma_fun` (to avoid an upgrade dance on that library)

I refrained from specifying `rev`s in the Cargo.toml because we have a lock-file anyway. This should allow us to update those dependencies easier in the future by just running `cargo update -p <dependency>`.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Daniel Karzel fe3d6f1fef Rename nectar to asb (automated swap backend) 3 years ago
Daniel Karzel 164de3c524 Properly calculate the confirmations for Bitcoin tx
Once the transaction was included into a block it has one confirmation - before inclusion it has zero.
current-block-height - transaction-block-height = zero; but that means one confirmation.
Hence, the confirmation calculation was adapted to: Current-block-height - (transaction-block-height - 1).
3 years ago
Thomas Eizinger 2d8ede80e1
Use released version of backoff 3 years ago
Thomas Eizinger cabf0efb8c
Only construct proof system once
The proof system is a static element and can be reused several times.
3 years ago
Thomas Eizinger 84bc2c82b7
Upgrade to bdk 4.0
To achieve this we also:

- upgrade rust-bitcoin to 0.26
- upgrade bitcoin-harness to latest version (which also depends bitcoin 0.26)
- upgrade to latest edcsa-fun
- replace cross_curve_dleq proof with sigma_fun (to avoid an upgrade dance over there)
3 years ago
bors[bot] b3f49cf83e
Merge #200
200: Wait for refund if insufficient Monero is locked up r=da-kami a=da-kami

In a scenario where Alice does not lock up sufficient funds Bob should properly transition to refunds. At the moment the CLI just panics. 
I noticed this when Alice accidentally had a different amount set than Bob. In the future this should not happen, because Alice provides the amount for Bob. However, in case Alice is malicious Bob should still transition correctly. 

Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
bors[bot] 8537b88a68
Merge #201
201: Fix ASB - Prevent the future from being stopped in production r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
bors[bot] 48635156ad
Merge #206
206: Remove misplaced wallet sync call r=rishflab a=rishflab

These bdk wallet sync calls must of gotten lost during a rebase. Removed the call in build TxLock and added one when nectar starts up

Co-authored-by: rishflab <rishflab@hotmail.com>
3 years ago
Daniel Karzel babd1d7b60
Wait for refund if insufficient Monero is locked up 3 years ago
Daniel Karzel ebb869e6f4 Distinguish transient and permanent Electrum errors 3 years ago
Daniel Karzel 9b93cabfdf Use context instead of map_error 3 years ago
rishflab fe362d765b Add sync wallet on nectar's startup 3 years ago
rishflab 00e2b257c4 Remove misplaced sync wallet call 3 years ago
Thomas Eizinger 8c83f7e2e1
Upgrade to testcontainers v0.12 3 years ago
Daniel Karzel 2ced9ddba4 Prevent future from being stopped by calling forget on handle 3 years ago
Daniel Karzel 77ec7e502f Distinguish permanent and transient error when watching tx 3 years ago
rishflab b66bb00c77 Remove stale code 3 years ago
rishflab bc1d2bda54 Test URL creation for default electrum HTTP API 3 years ago
rishflab d296c22ecf Log bitcoin deposit address on startup 3 years ago
rishflab 4768c79070 Derive bitcoin private key from seed 3 years ago
Thomas Eizinger a51194b9fa Instantiate electrum client with custom config with 2 retries
The default number of retries is 1. Unfortunately, the way this config
value is interpreted doesn't actually lead to a retry. We have to set
it to 2 to actually make it retry.

See https://github.com/bitcoindevkit/rust-electrum-client/issues/47.
3 years ago
rishflab 180e778df9 Allow blockchain calls to fail
Prior to this change, functions could not fail early on permanent errors eg. parsing a url. Merged error enums.
3 years ago
rishflab a0ef1f96ec Replace bitcoind wallet with bdk wallet
The bitcoind wallet required the user to run a bitcoind node. It was replaced with a bdk wallet which allows the user to connect to an electrum instance hosted remotely. An electrum and bitcoind testcontainer were created to the test the bdk wallet. The electrum container reads the blockdata from the bitcoind testcontainer through a shared volume. bitcoind-harness was removed as bitcoind initialisation code was moved into test_utils. The bdk wallet differs from the bitcoind wallet in that it needs to be manually synced with an electrum node. We synchronise the wallet once upon initialisation to prevent a potentially long running blocking task from interrupting protocol execution. The electrum HTTP API was used to get the latest block height and the transaction block height as this functionality was not present in the bdk wallet API or it required the bdk wallet to be re-synced to get an up to date value.
3 years ago
bors[bot] 4d8e801c1e
Merge #190
190: Do not pass Monero amount to the CLI r=D4nte a=D4nte

The CLI user only pass the Bitcoin amount they want to sell.

The CLI then do a quote request to nectar which provides the Monero amount the taker can get.

Co-authored-by: Franck Royer <franck@coblox.tech>
3 years ago
bors[bot] 5d215caf35
Merge #188
188: Tor cleanup r=da-kami a=da-kami

We never removed Tor install from CI. I don't think it should be necessary given that Tor was removed in code.

Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Franck Royer f36f5acaf1
Remove unnecessary async block 3 years ago
Franck Royer 73c52ffb61
Remove unused structs 3 years ago
Franck Royer 2dbd43e2c0
Only pass btc amount to CLI
The CLI requests a quote to nectar to know how much xmr it can get.
Also align terminology with the sequence diagram.
3 years ago
Franck Royer 144da75270
Remove redundant data 3 years ago
Franck Royer fb3b2aa546
Remove unnecessary pub qualifier 3 years ago
Franck Royer b4e2e11dde
Remove unnecessary fields 3 years ago
Franck Royer d6effb7d39
Remove unnecessary pub qualifiers 3 years ago
Franck Royer b8a84aa34b
Avoid possible mix up between timelocks
Introduce new type to ensure no mix up happens when ordering the fields
in function calls.
3 years ago
Franck Royer 9a321a4f09
Move transaction types in dedicated modules
To allow the related timelock to be defined with the
transaction that uses it. This will allow the access to the
timelock's struct inner field with defining `From` impl.
3 years ago
Franck Royer 65e0e5b731
Use Remote handle to access ongoing swaps on Alice 3 years ago
bors[bot] a0753e24dc
Merge #189
189: The first message is more of a quote request than a swap request r=D4nte a=D4nte



Co-authored-by: Franck Royer <franck@coblox.tech>
3 years ago
Franck Royer 5d78556665
Give a more specific name to the CLI binary: `swap-cli`
The current binary name is very generic `cli`. `swap-cli` better
describes what this binary does.
3 years ago
Franck Royer 8fada42074
Make `config` argument global
The `config` argument apply to all commands. It is now optional and
needs to be passed before a command.
E.g. `cli --config ./config.toml history`
3 years ago
Franck Royer 83dcf4ba3c
Add `nectar` binary 3 years ago
Daniel Karzel c166232daf Remove unnecessary mention of Tor in comment 3 years ago
Franck Royer 9ded728879
The first message is actually a quote or rate request 3 years ago
Franck Royer ee43125bdd
Add `nectar` binary 3 years ago
Franck Royer fac5b59d17
Remove unnecessary specification of the types 3 years ago
Franck Royer 7805a6d684
Move cli specific modules under cli folder
nectar will also have its own folder with a separate config.
3 years ago
Franck Royer 901c9e89c9
No evident added value of having separate `Seed` structs
Hence, reducing complexity of the codebase. Note that the seed will be
used by both nectar and the cli whereas the config mod will be different
so this changes helps with the next step of having a dedicated config
module for each binary.
3 years ago
Franck Royer 7d392c3086
This files contains `Command` and `Arguments` structs 3 years ago
Franck Royer 45dccb8be2
Rename the config struct `Config` 3 years ago
Franck Royer eb39add5ff
Fix typo 3 years ago
Franck Royer 6e6dc320b4
Alice event loop now handles the creation of new swaps 3 years ago
Franck Royer 15eb9a2fe4
Remove punish test
The punish test needs re-work due to the fact that Alice runs continuously

Currently focusing on the CLI (Bob), so we can re-introduce this test
once we want to ensure that nectar (Alice) punishes.
3 years ago
Franck Royer 3bc8b58b6a
Remove Bob restart tests after communication
The test do not work without acks as we stop the event loop as soon
as a message is considered as "sent" when actually the event loop
and swarm may not have yet sent the message.

The ack allow to avoid this issue as the message was considered "sent"
only once the other party sent a response. However, the ack brings
other issue so a review needs to be done to select the appropriate
solution.
3 years ago
Franck Royer fd9f633a77
Remove Alice restarts tests
Current focus is on CLI UX. Fair amount of change needs to happen to
cater for Alice (nectar) restart scenarios.
3 years ago
Franck Royer bfc19d5628
Remove acknowledgements processing
We are aware of issues of timeouts when waiting for acknowledgements.
Also, to properly supports acks in a multiple swap context, we need to
revert to doing event processing on the behaviour so that we can link
leverage the `RequestResponse` libp2p behaviour and link the messages
requests ids to swap ids when receiving an ack or response.

Acks are usefully for specific scenarios where we queue a message on the
behaviour to be sent, save as sent in the DB but crash before the
message is actually sent. With acks we are able to resume the swap,
without ack, the swap will abort (refund).
3 years ago
Franck Royer cc8b855117
Make it possible to clone a handle
This will be used for new swaps.
3 years ago
Franck Royer 1b2be804ed
Remove unnecessary channels
`alice::swap::run_until` will be called once the execution setup is
done. The steps before are directly handled by the event loop,
hence no channels are needed for said steps: connection established,
swap request/response & execution setup.
3 years ago
Franck Royer f5ca5faabf
Process execution setup failure similarly to other failures
By merging it in the failure event of the root behaviour.
3 years ago
Franck Royer 4ade5df0e5
Remove unnecessary impl block 3 years ago
Franck Royer 60e0b9382c
Introduced from float API for Monero quantities 3 years ago
Franck Royer b5b990257a
Move `Behaviour` in dedicated module 3 years ago
Franck Royer 87be9aeb2a
Prepare separation of event loop initialisation to swap initialisation
As for Alice, the event loop will be started with the program and will
be the one starting swaps (`run_until`) based on libp2p events (swap
request).
3 years ago
Franck Royer 530b9b2ea8
Remove possible mix up of timelocks when using `State0::new` 3 years ago
Franck Royer f35ed436ce
Allow `EventLoop` to hold a database ready to pass to `alice::Buider`
The `EventLoop` will use the `Builder` interface to instantiate a
`Swap` upon receiving a `SwapRequest` and successfully doing an
execution setup.
Before this change, the `EventLoop` would have to hold the path to the
db and re-open the db everytime it wants to construct a swap.

With this change, we can open the DB once and then hold a
`Arc<Database>` in the `EventLoop` and pass it to new `Swap`s structs.
3 years ago
Franck Royer 39a46baa2c
Preemptively box cancel tx to avoid size difference in enum 3 years ago
Franck Royer 69363e43a3
Preemptively box encrypted signature to avoid size difference in enum 3 years ago
Franck Royer fd084b764d
Move generation of keys inside `State0::new`
The event loop will now use this function so I want to simplify its
usage to avoid having to instantiate too many items to use it.
3 years ago
Franck Royer 788445964a
Move main.rs to cli.rs to prepare for nectar binary 3 years ago
Franck Royer 311ba74cd6
Remove sell-xmr from CLI 3 years ago
Daniel Karzel 0a0bce1552 Rename temporary wallet to blockchain monitoring wallet 3 years ago
Daniel Karzel 1e29433bd2 Open or create temporary Monero wallet upon wallet initialization 3 years ago
Daniel Karzel dac4443bbd Add functionality to open monero wallet through rpc 3 years ago
Daniel Karzel 62605a318a Add CreateWallet trait to expose create_wallet 3 years ago
Daniel Karzel 53fcd9224c Give finding the refund tx priority over waiting for the punish transaction to be finalized.
This was introduced due to a CI run, where Bob included tx_refund, but Alice had waited until T2 had expired,
and then went for punishing Bob instead of refunding.
Weirdly, Alice's punich transaction did not fail in that scenario.
3 years ago
Daniel Karzel 86290649e7 work in review comments 3 years ago
Daniel Karzel c930ad84a4 Add --force flag for cancel and refund 3 years ago
Daniel Karzel 02f8eb7f18 Add test for cancel/refund before timelock expired 3 years ago
Daniel Karzel 2d5d70d856 Timeout for Alice waiting for ack for sending transfer proof
If dialing Bob fails Alice waits for the acknowledgement of the transfer proof indefinitely.
The timout prevents her execution from hanging.
Added a ToDo to re-visit the ack receivers. They don't add value at the moment and should be removed.
3 years ago
Daniel Karzel c9adbde5d5 Add test for Bob's manual cancel and refund 3 years ago
Daniel Karzel ad2aefc2a5 Refund Command 3 years ago
Daniel Karzel 0600a7048e Cancel command 3 years ago
Franck Royer dee8c1e335
Remove scopes 3 years ago
Franck Royer a48823a665
Re-organise Alice state to be more coherent with the msg sequence 3 years ago
Franck Royer eefb1b3b16
Use event_process = false for Bob
As we do not process the event, we can just implement the needed `From`
traits.
3 years ago
Franck Royer a7b89e2fe4
Use event_process = false for Alice
As we do not process the event, we can just implement the needed `From`
traits.
3 years ago
Franck Royer 554ae6c00e
Remove Request Response types
These are actually not needed and forces us to cater for variants when
processing requests and responses.
3 years ago
Franck Royer 5a5a1c05f7
Set appropriate name to codec 3 years ago
Franck Royer a11e894b31
Prepend all libp2p protocols with "comit" 3 years ago
Franck Royer cfc5cb5206
Remove dead code and combine swap request & one shot codecs 3 years ago
Franck Royer fc2d8d3861
Rename alice::Message0 to Message0
There is now only one message0
3 years ago